Add subscribe/unsubscribe RPCs. Add session, sessionManager, and serve JSON RPC (without HTTP). #66

Merged
moodyjon merged 16 commits from blockchain_rpc2 into master 2022-10-04 16:05:06 +02:00
2 changed files with 19 additions and 9 deletions
Showing only changes of commit 5f068341e3 - Show all commits

View file

@ -65,6 +65,13 @@ func min[Ord constraints.Ordered](x, y Ord) Ord {
return y
}
func max[Ord constraints.Ordered](x, y Ord) Ord {
if x > y {
return x
}
return y
}
type BlockHeaderElectrum struct {
Version uint32 `json:"version"`
PrevBlockHash string `json:"prev_block_hash"`

View file

@ -119,6 +119,7 @@ type sessionManager struct {
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
sessionsWait sync.WaitGroup
sessionsMax int
sessionTimeout time.Duration
manageTicker *time.Ticker
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
db *db.ReadOnlyDBColumnFamily
chain *chaincfg.Params
// headerSubs are sessions subscribed via 'blockchain.headers.subscribe'
@ -132,6 +133,7 @@ func newSessionManager(db *db.ReadOnlyDBColumnFamily, chain *chaincfg.Params, se
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
sessions: make(sessionMap),
sessionsMax: sessionsMax,
sessionTimeout: time.Duration(sessionTimeout) * time.Second,
manageTicker: time.NewTicker(time.Duration(max(5, sessionTimeout/20)) * time.Second),
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
db: db,
chain: chain,
headerSubs: make(sessionMap),
@ -156,6 +158,7 @@ func (sm *sessionManager) stop() {
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
}
func (sm *sessionManager) manage() {
for {
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
sm.sessionsMut.Lock()
for _, sess := range sm.sessions {
if time.Since(sess.lastRecv) > sm.sessionTimeout {
@ -164,9 +167,9 @@ func (sm *sessionManager) manage() {
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
}
}
sm.sessionsMut.Unlock()
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
dur, _ := time.ParseDuration("10s")
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
time.AfterFunc(dur, func() { sm.manage() })
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
// Wait for next management clock tick.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
<-sm.manageTicker.C
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
}
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
}
func (sm *sessionManager) addSession(conn net.Conn) *session {

moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.
moodyjon commented 2022-09-28 17:13:03 +02:00 (Migrated from github.com)
Review

This is one of the biggest obstacles to limiting the number of go-routines. I have to call ServeCodec() in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.

This is one of the biggest obstacles to limiting the number of go-routines. I have to call `ServeCodec()` in a new go-routine in order to allow more than one session at a time, and I don't know how to control/track this routine.
jeffreypicard commented 2022-10-03 12:59:12 +02:00 (Migrated from github.com)
Review

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?

Interesting way to keep this running forever, I think it spawns a new goroutine every time, it might be better to just use this in an intfinite loop with a sleep, and maybe parametarize the polling time?
moodyjon commented 2022-10-03 20:40:01 +02:00 (Migrated from github.com)
Review

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.

Using Ticker object now. The Ticker.Reset() method can be used in unit tests to adjust frequency up/down.