Skip to content

Commit

Permalink
Refactor TxPool: leaner and simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Dec 24, 2024
1 parent 487743f commit 3a3ef7f
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 3,152 deletions.
14 changes: 4 additions & 10 deletions hive_integration/nodocker/engine/engine_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E
chain,
txPool)

# txPool must be informed of active head
# so it can know the latest account state
doAssert txPool.smartHead(chain.latestHeader)

var key: JwtSharedKey
key.fromHex(jwtSecret).isOkOr:
echo "JWT SECRET ERROR: ", error
Expand Down Expand Up @@ -178,14 +174,12 @@ proc peer*(env: EngineEnv): Peer =
proc getTxsInPool*(env: EngineEnv, txHashes: openArray[common.Hash32]): seq[Transaction] =
result = newSeqOfCap[Transaction](txHashes.len)
for txHash in txHashes:
let res = env.txPool.getItem(txHash)
if res.isErr: continue
let item = res.get
if item.reject == txInfoOk:
result.add item.tx
let item = env.txPool.getItem(txHash).valueOr:
continue
result.add item.tx

proc numTxsInPool*(env: EngineEnv): int =
env.txPool.numTxs
env.txPool.len

func version*(env: EngineEnv, time: EthTime): Version =
if env.com.isPragueOrLater(time):
Expand Down
7 changes: 1 addition & 6 deletions hive_integration/nodocker/graphql/graphql_sim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,13 @@ proc main() =
)
chain = ForkedChainRef.init(com)
txPool = TxPoolRef.new(chain)

discard importRlpBlock(blocksFile, com)
let ctx = setupGraphqlContext(com, ethNode, txPool)

var stat: SimStat
let start = getTime()

# txPool must be informed of active head
# so it can know the latest account state
# e.g. "sendRawTransaction Nonce too low" case
doAssert txPool.smartHead(chain.latestHeader)

for fileName in walkDirRec(
caseFolder, yieldFilter = {pcFile,pcLinkToFile}):
if not fileName.endsWith(".json"):
Expand Down
4 changes: 0 additions & 4 deletions hive_integration/nodocker/rpc/test_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,6 @@ proc setupEnv*(taskPool: Taskpool): TestEnv =
let chain = ForkedChainRef.init(com)
let txPool = TxPoolRef.new(chain)

# txPool must be informed of active head
# so it can know the latest account state
doAssert txPool.smartHead(chain.latestHeader)

let rpcServer = setupRpcServer(ethCtx, com, ethNode, txPool, conf, chain)
let rpcClient = newRpcHttpClient()
waitFor rpcClient.connect("127.0.0.1", Port(8545), false)
Expand Down
4 changes: 0 additions & 4 deletions nimbus/beacon/beacon_engine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ proc generateExecutionBundle*(ben: BeaconEngineRef,

pos.setWithdrawals(attrs)

if headBlock.blockHash != xp.head.blockHash:
# reorg
discard xp.smartHead(headBlock)

if pos.timestamp <= headBlock.timestamp:
return err "timestamp must be strictly later than parent"

Expand Down
Loading

0 comments on commit 3a3ef7f

Please sign in to comment.