Remove chain_desc.nim and ChainRef usage from hive simulator (#3105)

This commit is contained in:
andri lim 2025-02-25 15:18:44 +07:00 committed by GitHub
parent bd473f95f4
commit b4226b66e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 82 deletions

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -9,10 +9,9 @@
# according to those terms.
import
./chain/[chain_desc, persist_blocks, forked_chain]
./chain/[persist_blocks, forked_chain]
export
chain_desc,
persist_blocks,
forked_chain

View File

@ -1,70 +0,0 @@
# Nimbus
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
{.push raises: [].}
import
../../common/common
export
common
type
ChainRef* = ref object of RootRef
com: CommonRef
## common block chain configuration
## used throughout entire app
extraValidation: bool ##\
## Trigger extra validation, currently within `persistBlocks()`
## function only.
# ------------------------------------------------------------------------------
# Public constructors
# ------------------------------------------------------------------------------
func newChain*(com: CommonRef,
extraValidation: bool = true): ChainRef =
## Constructor for the `Chain` descriptor object.
## The argument `extraValidation` enables extra block
## chain validation if set `true`.
ChainRef(
com: com,
extraValidation: extraValidation
)
# ------------------------------------------------------------------------------
# Public `Chain` getters
# ------------------------------------------------------------------------------
func db*(c: ChainRef): CoreDbRef =
## Getter
c.com.db
func com*(c: ChainRef): CommonRef =
## Getter
c.com
func extraValidation*(c: ChainRef): bool =
## Getter
c.extraValidation
# ------------------------------------------------------------------------------
# Public `Chain` setters
# ------------------------------------------------------------------------------
func `extraValidation=`*(c: ChainRef; extraValidation: bool) =
## Setter. If set `true`, the assignment value `extraValidation` enables
## extra block chain validation.
c.extraValidation = extraValidation
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------

View File

@ -19,7 +19,6 @@ import
evm/types,
core/dao,
core/validate,
core/chain/chain_desc,
core/executor/calculate_reward,
core/executor/process_transaction,
core/executor/process_block
@ -71,26 +70,26 @@ proc processBlock(
ok()
proc getVmState(c: ChainRef, header: Header, txFrame: CoreDbTxRef):
proc getVmState(com: CommonRef, header: Header, txFrame: CoreDbTxRef):
Result[BaseVMState, string] =
let
parent = ?txFrame.getBlockHeader(header.parentHash)
vmState = BaseVMState()
vmState.init(parent, header, c.com, txFrame, storeSlotHash = false)
vmState.init(parent, header, com, txFrame, storeSlotHash = false)
return ok(vmState)
# A stripped down version of persistBlocks without validation
# intended to accepts invalid block
proc setBlock*(c: ChainRef; blk: Block): Result[void, string] =
proc setBlock*(com: CommonRef; blk: Block): Result[void, string] =
template header: Header = blk.header
let txFrame = c.db.baseTxFrame().txFrameBegin()
let txFrame = com.db.baseTxFrame().txFrameBegin()
# Needed for figuring out whether KVT cleanup is due (see at the end)
let
vmState = ? c.getVmState(header, txFrame)
vmState = ? com.getVmState(header, txFrame)
? vmState.processBlock(blk)
? txFrame.persistHeaderAndSetHead(header, c.com.startOfHistory)
? txFrame.persistHeaderAndSetHead(header, com.startOfHistory)
txFrame.persistTransactions(header.number, header.txRoot, blk.transactions)
txFrame.persistReceipts(header.receiptsRoot, vmState.receipts)
@ -104,12 +103,12 @@ proc setBlock*(c: ChainRef; blk: Block): Result[void, string] =
# the parent state of the first block (as registered in `headers[0]`) was
# the canonical state before updating. So this state will be saved with
# `persistent()` together with the respective block number.
c.db.persist(txFrame)
com.db.persist(txFrame)
# update currentBlock *after* we persist it
# so the rpc return consistent result
# between eth_blockNumber and eth_syncing
c.com.syncCurrent = header.number
com.syncCurrent = header.number
ok()