Skip to content

Commit 1eb342e

Browse files
committed
eth/catalyst: move txpool.Sync from fcu into simulated beacon
1 parent c372214 commit 1eb342e

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

eth/catalyst/api.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update engine.ForkchoiceStateV1, pa
184184
return engine.STATUS_INVALID, engine.InvalidParams.With(errors.New("forkChoiceUpdateV1 called post-shanghai"))
185185
}
186186
}
187-
return api.forkchoiceUpdated(update, payloadAttributes, engine.PayloadV1, false)
187+
return api.forkchoiceUpdated(update, payloadAttributes, engine.PayloadV1)
188188
}
189189

190190
// ForkchoiceUpdatedV2 is equivalent to V1 with the addition of withdrawals in the payload
@@ -207,7 +207,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV2(update engine.ForkchoiceStateV1, pa
207207
return engine.STATUS_INVALID, engine.UnsupportedFork.With(errors.New("forkchoiceUpdatedV2 must only be called with paris and shanghai payloads"))
208208
}
209209
}
210-
return api.forkchoiceUpdated(update, params, engine.PayloadV2, false)
210+
return api.forkchoiceUpdated(update, params, engine.PayloadV2)
211211
}
212212

213213
// ForkchoiceUpdatedV3 is equivalent to V2 with the addition of parent beacon block root
@@ -228,10 +228,10 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV3(update engine.ForkchoiceStateV1, pa
228228
// hash, even if params are wrong. To do this we need to split up
229229
// forkchoiceUpdate into a function that only updates the head and then a
230230
// function that kicks off block construction.
231-
return api.forkchoiceUpdated(update, params, engine.PayloadV3, false)
231+
return api.forkchoiceUpdated(update, params, engine.PayloadV3)
232232
}
233233

234-
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion, simulatorMode bool) (engine.ForkChoiceResponse, error) {
234+
func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payloadAttributes *engine.PayloadAttributes, payloadVersion engine.PayloadVersion) (engine.ForkChoiceResponse, error) {
235235
api.forkchoiceLock.Lock()
236236
defer api.forkchoiceLock.Unlock()
237237

@@ -374,19 +374,6 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
374374
if api.localBlocks.has(id) {
375375
return valid(&id), nil
376376
}
377-
// If the beacon chain is ran by a simulator, then transaction insertion,
378-
// block insertion and block production will happen without any timing
379-
// delay between them. This will cause flaky simulator executions due to
380-
// the transaction pool running its internal reset operation on a back-
381-
// ground thread. To avoid the racey behavior - in simulator mode - the
382-
// pool will be explicitly blocked on its reset before continuing to the
383-
// block production below.
384-
if simulatorMode {
385-
if err := api.eth.TxPool().Sync(); err != nil {
386-
log.Error("Failed to sync transaction pool", "err", err)
387-
return valid(nil), engine.InvalidPayloadAttributes.With(err)
388-
}
389-
}
390377
payload, err := api.eth.Miner().BuildPayload(args)
391378
if err != nil {
392379
log.Error("Failed to build payload", "err", err)

eth/catalyst/simulated_beacon.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"crypto/rand"
2121
"crypto/sha256"
2222
"errors"
23+
"fmt"
2324
"math/big"
2425
"sync"
2526
"time"
@@ -163,6 +164,16 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
163164
c.setCurrentState(header.Hash(), *finalizedHash)
164165
}
165166

167+
// Because transaction insertion, block insertion and block production will
168+
// happen without any timing delay between them in simulator mode and the
169+
// transaction pool will be running its internal reset operation on a
170+
// background thread, flaky executions can happen. To avoid the racey
171+
// behavior, the pool will be explicitly blocked on its reset before
172+
// continuing to the block production below.
173+
if err := c.eth.APIBackend.TxPool().Sync(); err != nil {
174+
return fmt.Errorf("failed to sync txpool: %w", err)
175+
}
176+
166177
var random [32]byte
167178
rand.Read(random[:])
168179
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
@@ -171,7 +182,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
171182
Withdrawals: withdrawals,
172183
Random: random,
173184
BeaconRoot: &common.Hash{},
174-
}, engine.PayloadV3, true)
185+
}, engine.PayloadV3)
175186
if err != nil {
176187
return err
177188
}

0 commit comments

Comments
 (0)