mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
eth/catalyst: refactor simulated beacon
This commit is contained in:
parent
2e96810a68
commit
191d466528
1 changed files with 10 additions and 13 deletions
|
|
@ -54,23 +54,14 @@ func (a *simulatedBeaconAPI) loop() {
|
|||
)
|
||||
defer newTxsSub.Unsubscribe()
|
||||
defer newWxsSub.Unsubscribe()
|
||||
|
||||
// commit is a non-blocking method to initate Commit() on the simulator.
|
||||
commit := func() {
|
||||
select {
|
||||
case doCommit <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
// a background thread which signals to the simulator when to commit
|
||||
// based on messages over doCommit.
|
||||
go func() {
|
||||
for _ = range doCommit {
|
||||
a.sim.Commit()
|
||||
a.sim.eth.TxPool().Sync()
|
||||
executable, _ := a.sim.eth.TxPool().Stats()
|
||||
if executable != 0 {
|
||||
commit()
|
||||
if executable, _ := a.sim.eth.TxPool().Stats(); executable > 0 {
|
||||
a.sim.Commit()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
|
@ -81,9 +72,15 @@ func (a *simulatedBeaconAPI) loop() {
|
|||
close(doCommit)
|
||||
return
|
||||
case <-newWxs:
|
||||
commit()
|
||||
select {
|
||||
case doCommit <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
case <-newTxs:
|
||||
commit()
|
||||
select {
|
||||
case doCommit <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue