mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-28 20:00:43 +00:00
Reduce ChainRef usage (#3093)
* Reduce ChainRef usage It's now only used in the hive node, from which it probably also should be removed * lint
This commit is contained in:
parent
a86df054b2
commit
03010dc558
@ -13,11 +13,9 @@
|
|||||||
import
|
import
|
||||||
stew/assign2,
|
stew/assign2,
|
||||||
results,
|
results,
|
||||||
../../evm/state,
|
../../evm/[state, types],
|
||||||
../../evm/types,
|
../../common,
|
||||||
../executor,
|
../[executor, validate],
|
||||||
../validate,
|
|
||||||
./chain_desc,
|
|
||||||
chronicles,
|
chronicles,
|
||||||
stint
|
stint
|
||||||
|
|
||||||
@ -42,7 +40,7 @@ type
|
|||||||
PersistBlockFlags* = set[PersistBlockFlag]
|
PersistBlockFlags* = set[PersistBlockFlag]
|
||||||
|
|
||||||
Persister* = object
|
Persister* = object
|
||||||
c: ChainRef
|
com: CommonRef
|
||||||
flags: PersistBlockFlags
|
flags: PersistBlockFlags
|
||||||
|
|
||||||
vmState: BaseVMState
|
vmState: BaseVMState
|
||||||
@ -64,11 +62,11 @@ proc getVmState(
|
|||||||
if p.vmState == nil:
|
if p.vmState == nil:
|
||||||
let
|
let
|
||||||
vmState = BaseVMState()
|
vmState = BaseVMState()
|
||||||
txFrame = p.c.db.baseTxFrame.txFrameBegin()
|
txFrame = p.com.db.baseTxFrame.txFrameBegin()
|
||||||
parent = ?txFrame.getBlockHeader(header.parentHash)
|
parent = ?txFrame.getBlockHeader(header.parentHash)
|
||||||
|
|
||||||
doAssert txFrame.getSavedStateBlockNumber() == parent.number
|
doAssert txFrame.getSavedStateBlockNumber() == parent.number
|
||||||
vmState.init(parent, header, p.c.com, txFrame, storeSlotHash = storeSlotHash)
|
vmState.init(parent, header, p.com, txFrame, storeSlotHash = storeSlotHash)
|
||||||
p.vmState = vmState
|
p.vmState = vmState
|
||||||
else:
|
else:
|
||||||
if header.number != p.parent.number + 1:
|
if header.number != p.parent.number + 1:
|
||||||
@ -83,8 +81,8 @@ proc dispose*(p: var Persister) =
|
|||||||
p.vmState.ledger.txFrame.dispose()
|
p.vmState.ledger.txFrame.dispose()
|
||||||
p.vmState = nil
|
p.vmState = nil
|
||||||
|
|
||||||
proc init*(T: type Persister, c: ChainRef, flags: PersistBlockFlags): T =
|
proc init*(T: type Persister, com: CommonRef, flags: PersistBlockFlags): T =
|
||||||
T(c: c, flags: flags)
|
T(com: com, flags: flags)
|
||||||
|
|
||||||
proc checkpoint*(p: var Persister): Result[void, string] =
|
proc checkpoint*(p: var Persister): Result[void, string] =
|
||||||
if NoValidation notin p.flags:
|
if NoValidation notin p.flags:
|
||||||
@ -104,9 +102,9 @@ proc checkpoint*(p: var Persister): Result[void, string] =
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Move in-memory state to disk
|
# Move in-memory state to disk
|
||||||
p.c.db.persist(p.vmState.ledger.txFrame)
|
p.com.db.persist(p.vmState.ledger.txFrame)
|
||||||
# Get a new frame since the DB assumes ownership
|
# Get a new frame since the DB assumes ownership
|
||||||
p.vmState.ledger.txFrame = p.c.db.baseTxFrame().txFrameBegin()
|
p.vmState.ledger.txFrame = p.com.db.baseTxFrame().txFrameBegin()
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
@ -114,7 +112,7 @@ proc persistBlock*(p: var Persister, blk: Block): Result[void, string] =
|
|||||||
template header(): Header =
|
template header(): Header =
|
||||||
blk.header
|
blk.header
|
||||||
|
|
||||||
let c = p.c
|
let com = p.com
|
||||||
|
|
||||||
# Full validation means validating the state root at every block and
|
# Full validation means validating the state root at every block and
|
||||||
# performing the more expensive hash computations on the block itself, ie
|
# performing the more expensive hash computations on the block itself, ie
|
||||||
@ -143,7 +141,7 @@ proc persistBlock*(p: var Persister, blk: Block): Result[void, string] =
|
|||||||
# sanity checks should be performed early in the processing pipeline no
|
# sanity checks should be performed early in the processing pipeline no
|
||||||
# matter their provenance.
|
# matter their provenance.
|
||||||
if not skipValidation:
|
if not skipValidation:
|
||||||
?c.com.validateHeaderAndKinship(blk, vmState.parent, txFrame)
|
?com.validateHeaderAndKinship(blk, vmState.parent, txFrame)
|
||||||
|
|
||||||
# Generate receipts for storage or validation but skip them otherwise
|
# Generate receipts for storage or validation but skip them otherwise
|
||||||
?vmState.processBlock(
|
?vmState.processBlock(
|
||||||
@ -151,12 +149,12 @@ proc persistBlock*(p: var Persister, blk: Block): Result[void, string] =
|
|||||||
skipValidation,
|
skipValidation,
|
||||||
skipReceipts = skipValidation and NoPersistReceipts in p.flags,
|
skipReceipts = skipValidation and NoPersistReceipts in p.flags,
|
||||||
skipUncles = NoPersistUncles in p.flags,
|
skipUncles = NoPersistUncles in p.flags,
|
||||||
taskpool = c.com.taskpool,
|
taskpool = com.taskpool,
|
||||||
)
|
)
|
||||||
|
|
||||||
if NoPersistHeader notin p.flags:
|
if NoPersistHeader notin p.flags:
|
||||||
let blockHash = header.blockHash()
|
let blockHash = header.blockHash()
|
||||||
?txFrame.persistHeaderAndSetHead(blockHash, header, c.com.startOfHistory)
|
?txFrame.persistHeaderAndSetHead(blockHash, header, com.startOfHistory)
|
||||||
|
|
||||||
if NoPersistTransactions notin p.flags:
|
if NoPersistTransactions notin p.flags:
|
||||||
txFrame.persistTransactions(header.number, header.txRoot, blk.transactions)
|
txFrame.persistTransactions(header.number, header.txRoot, blk.transactions)
|
||||||
@ -181,14 +179,14 @@ proc persistBlock*(p: var Persister, blk: Block): Result[void, string] =
|
|||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc persistBlocks*(
|
proc persistBlocks*(
|
||||||
c: ChainRef, blocks: openArray[Block], flags: PersistBlockFlags = {}
|
com: CommonRef, blocks: openArray[Block], flags: PersistBlockFlags = {}
|
||||||
): Result[PersistStats, string] =
|
): Result[PersistStats, string] =
|
||||||
# Run the VM here
|
# Run the VM here
|
||||||
if blocks.len == 0:
|
if blocks.len == 0:
|
||||||
debug "Nothing to do"
|
debug "Nothing to do"
|
||||||
return ok(default(PersistStats)) # TODO not nice to return nil
|
return ok(default(PersistStats)) # TODO not nice to return nil
|
||||||
|
|
||||||
var p = Persister.init(c, flags)
|
var p = Persister.init(com, flags)
|
||||||
|
|
||||||
for blk in blocks:
|
for blk in blocks:
|
||||||
p.persistBlock(blk).isOkOr:
|
p.persistBlock(blk).isOkOr:
|
||||||
@ -198,7 +196,7 @@ proc persistBlocks*(
|
|||||||
# update currentBlock *after* we persist it
|
# update currentBlock *after* we persist it
|
||||||
# so the rpc return consistent result
|
# so the rpc return consistent result
|
||||||
# between eth_blockNumber and eth_syncing
|
# between eth_blockNumber and eth_syncing
|
||||||
c.com.syncCurrent = p.parent.number
|
com.syncCurrent = p.parent.number
|
||||||
|
|
||||||
let res = p.checkpoint()
|
let res = p.checkpoint()
|
||||||
p.dispose()
|
p.dispose()
|
||||||
|
@ -98,7 +98,6 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
|
|||||||
|
|
||||||
let
|
let
|
||||||
start = com.db.baseTxFrame().getSavedStateBlockNumber() + 1
|
start = com.db.baseTxFrame().getSavedStateBlockNumber() + 1
|
||||||
chain = com.newChain()
|
|
||||||
(cfg, genesis_validators_root, lastEra1Block, firstSlotAfterMerge) =
|
(cfg, genesis_validators_root, lastEra1Block, firstSlotAfterMerge) =
|
||||||
getMetadata(conf.networkId)
|
getMetadata(conf.networkId)
|
||||||
time0 = Moment.now()
|
time0 = Moment.now()
|
||||||
@ -120,7 +119,7 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
|
|||||||
boolFlag({PersistBlockFlag.NoPersistReceipts}, not conf.storeReceipts) +
|
boolFlag({PersistBlockFlag.NoPersistReceipts}, not conf.storeReceipts) +
|
||||||
boolFlag({PersistBlockFlag.NoPersistSlotHashes}, not conf.storeSlotHashes)
|
boolFlag({PersistBlockFlag.NoPersistSlotHashes}, not conf.storeSlotHashes)
|
||||||
blk: Block
|
blk: Block
|
||||||
persister = Persister.init(chain, flags)
|
persister = Persister.init(com, flags)
|
||||||
cstats: PersistStats # stats at start of chunk
|
cstats: PersistStats # stats at start of chunk
|
||||||
|
|
||||||
defer:
|
defer:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Nimbus
|
# Nimbus
|
||||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
# Copyright (c) 2018-2025 Status Research & Development GmbH
|
||||||
# Licensed under either of
|
# Licensed under either of
|
||||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0)
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
||||||
@ -31,26 +31,6 @@ proc addEthHandlerCapability*(
|
|||||||
protocol.eth,
|
protocol.eth,
|
||||||
EthWireRef.new(chain, txPool, peerPool))
|
EthWireRef.new(chain, txPool, peerPool))
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Public functions: convenience mappings for `snap`
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
when false: # needs to be updated
|
|
||||||
import
|
|
||||||
./snap as handlers_snap
|
|
||||||
|
|
||||||
proc addSnapHandlerCapability*(
|
|
||||||
node: EthereumNode;
|
|
||||||
peerPool: PeerPool;
|
|
||||||
chain = ChainRef(nil);
|
|
||||||
) =
|
|
||||||
## Install `snap` handlers,Passing `chein` as `nil` installs the handler
|
|
||||||
## in minimal/outbound mode.
|
|
||||||
if chain.isNil:
|
|
||||||
node.addCapability protocol.snap
|
|
||||||
else:
|
|
||||||
node.addCapability(protocol.snap, SnapWireRef.init(chain, peerPool))
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -114,7 +114,6 @@ proc test_chainSync*(
|
|||||||
## Store persistent blocks from dump into chain DB
|
## Store persistent blocks from dump into chain DB
|
||||||
let
|
let
|
||||||
sayBlocks = 900'u64
|
sayBlocks = 900'u64
|
||||||
chain = com.newChain()
|
|
||||||
blockOnDb = com.db.baseTxFrame().getSavedStateBlockNumber()
|
blockOnDb = com.db.baseTxFrame().getSavedStateBlockNumber()
|
||||||
lastBlock = max(1, numBlocks).BlockNumber
|
lastBlock = max(1, numBlocks).BlockNumber
|
||||||
|
|
||||||
@ -181,12 +180,12 @@ proc test_chainSync*(
|
|||||||
noisy.startLogging(w[0].header.number)
|
noisy.startLogging(w[0].header.number)
|
||||||
|
|
||||||
noisy.stopLoggingAfter():
|
noisy.stopLoggingAfter():
|
||||||
let runPersistBlocksRc = chain.persistBlocks(w)
|
let runPersistBlocksRc = com.persistBlocks(w)
|
||||||
xCheck runPersistBlocksRc.isOk():
|
xCheck runPersistBlocksRc.isOk():
|
||||||
if noisy:
|
if noisy:
|
||||||
noisy.whisper "***", "Re-run with logging enabled...\n"
|
noisy.whisper "***", "Re-run with logging enabled...\n"
|
||||||
setTraceLevel()
|
setTraceLevel()
|
||||||
discard chain.persistBlocks(w)
|
discard com.persistBlocks(w)
|
||||||
blocks += w.len
|
blocks += w.len
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -211,7 +210,7 @@ proc test_chainSync*(
|
|||||||
sayPerf
|
sayPerf
|
||||||
noisy.whisper "***",
|
noisy.whisper "***",
|
||||||
&"processing {dotsOrSpace}[#{fromBlock:>8},#{(lastBlock-1):>8}]"
|
&"processing {dotsOrSpace}[#{fromBlock:>8},#{(lastBlock-1):>8}]"
|
||||||
let runPersistBlocks1Rc = chain.persistBlocks(blocks1)
|
let runPersistBlocks1Rc = com.persistBlocks(blocks1)
|
||||||
xCheck runPersistBlocks1Rc.isOk()
|
xCheck runPersistBlocks1Rc.isOk()
|
||||||
dotsOrSpace = " "
|
dotsOrSpace = " "
|
||||||
|
|
||||||
@ -227,7 +226,7 @@ proc test_chainSync*(
|
|||||||
noisy.whisper "***",
|
noisy.whisper "***",
|
||||||
&"processing {dotsOrSpace}[#{lastBlock:>8},#{lastBlock:>8}]"
|
&"processing {dotsOrSpace}[#{lastBlock:>8},#{lastBlock:>8}]"
|
||||||
noisy.stopLoggingAfter():
|
noisy.stopLoggingAfter():
|
||||||
let runPersistBlocks0Rc = chain.persistBlocks(blocks0)
|
let runPersistBlocks0Rc = com.persistBlocks(blocks0)
|
||||||
xCheck runPersistBlocks0Rc.isOk()
|
xCheck runPersistBlocks0Rc.isOk()
|
||||||
else:
|
else:
|
||||||
if oldLogAlign:
|
if oldLogAlign:
|
||||||
@ -238,7 +237,7 @@ proc test_chainSync*(
|
|||||||
noisy.whisper "***",
|
noisy.whisper "***",
|
||||||
&"processing {dotsOrSpace}[#{lastBlock:>8},#{toBlock:>8}]"
|
&"processing {dotsOrSpace}[#{lastBlock:>8},#{toBlock:>8}]"
|
||||||
noisy.stopLoggingAfter():
|
noisy.stopLoggingAfter():
|
||||||
let runPersistBlocks9Rc = chain.persistBlocks(blocks9)
|
let runPersistBlocks9Rc = com.persistBlocks(blocks9)
|
||||||
xCheck runPersistBlocks9Rc.isOk()
|
xCheck runPersistBlocks9Rc.isOk()
|
||||||
break
|
break
|
||||||
if not oldLogAlign:
|
if not oldLogAlign:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user