eth/catalyst: refactor simulated beacon

This commit is contained in:
Martin Holst Swende 2024-08-19 14:41:00 +02:00
parent 2e96810a68
commit 191d466528
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -54,23 +54,14 @@ func (a *simulatedBeaconAPI) loop() {
) )
defer newTxsSub.Unsubscribe() defer newTxsSub.Unsubscribe()
defer newWxsSub.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 // a background thread which signals to the simulator when to commit
// based on messages over doCommit. // based on messages over doCommit.
go func() { go func() {
for _ = range doCommit { for _ = range doCommit {
a.sim.Commit() a.sim.Commit()
a.sim.eth.TxPool().Sync() a.sim.eth.TxPool().Sync()
executable, _ := a.sim.eth.TxPool().Stats() if executable, _ := a.sim.eth.TxPool().Stats(); executable > 0 {
if executable != 0 { a.sim.Commit()
commit()
} }
} }
}() }()
@ -81,9 +72,15 @@ func (a *simulatedBeaconAPI) loop() {
close(doCommit) close(doCommit)
return return
case <-newWxs: case <-newWxs:
commit() select {
case doCommit <- struct{}{}:
default:
}
case <-newTxs: case <-newTxs:
commit() select {
case doCommit <- struct{}{}:
default:
}
} }
} }
} }