Skip to content

Commit

Permalink
Fix smartHead usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Sep 2, 2024
1 parent 4067c84 commit 45574f7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion hive_integration/nodocker/engine/engine_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E

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

var key: JwtSharedKey
key.fromHex(jwtSecret).isOkOr:
Expand Down
3 changes: 2 additions & 1 deletion hive_integration/nodocker/graphql/graphql_sim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ proc main() =
# so it can know the latest account state
# e.g. "sendRawTransaction Nonce too low" case
let head = com.db.getCanonicalHead()
doAssert txPool.smartHead(head)
let chainRef = newForkedChain(com, head)
doAssert txPool.smartHead(head, chainRef)

for fileName in walkDirRec(
caseFolder, yieldFilter = {pcFile,pcLinkToFile}):
Expand Down
6 changes: 3 additions & 3 deletions hive_integration/nodocker/rpc/test_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ proc setupEnv*(): TestEnv =

manageAccounts(ethCtx, conf)

let chainRef = newChain(com)
let head = com.db.getCanonicalHead()
let chainRef = newForkedChain(com, head)
let txPool = TxPoolRef.new(com)

# txPool must be informed of active head
# so it can know the latest account state
let head = com.db.getCanonicalHead()
doAssert txPool.smartHead(head)
doAssert txPool.smartHead(head, chainRef)

let rpcServer = setupRpcServer(ethCtx, com, ethNode, txPool, conf)
let rpcClient = newRpcHttpClient()
Expand Down
2 changes: 1 addition & 1 deletion nimbus/beacon/beacon_engine.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ proc generatePayload*(ben: BeaconEngineRef,

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

if pos.timestamp <= headBlock.timestamp:
return err "timestamp must be strictly later than parent"
Expand Down
8 changes: 1 addition & 7 deletions nimbus/nimbus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,8 @@ proc basicServices(nimbus: NimbusNode,
# so it can know the latest account state
# e.g. sender nonce, etc
let head = com.db.getCanonicalHead()
doAssert nimbus.txPool.smartHead(head)

# chainRef: some name to avoid module-name/filed/function misunderstandings
nimbus.chainRef = newForkedChain(com, head)
#if conf.verifyFrom.isSome:
# let verifyFrom = conf.verifyFrom.get()
# nimbus.chainRef.extraValidation = 0 < verifyFrom
# nimbus.chainRef.verifyFrom = verifyFrom
doAssert nimbus.txPool.smartHead(head, nimbus.chainRef)

nimbus.beaconEngine = BeaconEngineRef.new(nimbus.txPool, nimbus.chainRef)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_ledger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type
nonce : uint64
chainId : ChainId
xp : TxPoolRef
chain : ChainRef
chain : ForkedChainRef

# ------------------------------------------------------------------------------
# Helpers
Expand Down Expand Up @@ -110,7 +110,7 @@ proc initEnv(): TestEnv =
nonce : 0'u64,
chainId : conf.networkParams.config.chainId,
xp : TxPoolRef.new(com),
chain : newChain(com),
chain : newForkedChain(com, com.genesisHeader),
)

func makeTx(
Expand Down Expand Up @@ -140,8 +140,8 @@ func initAddr(z: int): EthAddress =
const L = sizeof(result)
result[L-sizeof(uint32)..^1] = toBytesBE(z.uint32)

proc importBlocks(env: TestEnv; blk: EthBlock) =
env.chain.persistBlocks([blk]).isOkOr:
proc importBlock(env: TestEnv; blk: EthBlock) =
env.chain.importBlock(blk).isOkOr:
raiseAssert "persistBlocks() failed at block #" &
$blk.header.number & " msg: " & error

Expand Down Expand Up @@ -333,9 +333,9 @@ proc runLedgerTransactionTests(noisy = true) =
uncles: blk.uncles,
withdrawals: Opt.some(newSeq[Withdrawal]())
)
env.importBlocks(EthBlock.init(blk.header, body))
env.importBlock(EthBlock.init(blk.header, body))

check env.xp.smartHead(blk.header)
check env.xp.smartHead(blk.header, env.chain)
for tx in body.transactions:
env.txs.add tx

Expand Down

0 comments on commit 45574f7

Please sign in to comment.