From 191d4665288444ee473d8fd97410ad43268ef1fb Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 19 Aug 2024 14:41:00 +0200 Subject: [PATCH] eth/catalyst: refactor simulated beacon --- eth/catalyst/simulated_beacon_api.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/eth/catalyst/simulated_beacon_api.go b/eth/catalyst/simulated_beacon_api.go index 3877fcb226..20cf8325ba 100644 --- a/eth/catalyst/simulated_beacon_api.go +++ b/eth/catalyst/simulated_beacon_api.go @@ -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: + } } } }