mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-04 00:05:22 +00:00
221e6c9e2f
* Nimbus folder environment update details: * Integrated `CoreDbRef` for the sources in the `nimbus` sub-folder. * The `nimbus` program does not compile yet as it needs the updates in the parallel `stateless` sub-folder. * Stateless environment update details: * Integrated `CoreDbRef` for the sources in the `stateless` sub-folder. * The `nimbus` program compiles now. * Premix environment update details: * Integrated `CoreDbRef` for the sources in the `premix` sub-folder. * Fluffy environment update details: * Integrated `CoreDbRef` for the sources in the `fluffy` sub-folder. * Tools environment update details: * Integrated `CoreDbRef` for the sources in the `tools` sub-folder. * Nodocker environment update details: * Integrated `CoreDbRef` for the sources in the `hive_integration/nodocker` sub-folder. * Tests environment update details: * Integrated `CoreDbRef` for the sources in the `tests` sub-folder. * The unit tests compile and run cleanly now. * Generalise `CoreDbRef` to any `select_backend` supported database why: Generalisation was just missed due to overcoming some compiler oddity which was tied to rocksdb for testing. * Suppress compiler warning for `newChainDB()` why: Warning was added to this function which must be wrapped so that any `CatchableError` is re-raised as `Defect`. * Split off persistent `CoreDbRef` constructor into separate file why: This allows to compile a memory only database version without linking the backend library. * Use memory `CoreDbRef` database by default detail: Persistent DB constructor needs to import `db/core_db/persistent why: Most tests use memory DB anyway. This avoids linking `-lrocksdb` or any other backend by default. * fix `toLegacyBackend()` availability check why: got garbled after memory/persistent split. * Clarify raw access to MPT for snap sync handler why: Logically, `kvt` is not the raw access for the hexary trie (although this holds for the legacy database)
134 lines
4.3 KiB
Nim
134 lines
4.3 KiB
Nim
# Nimbus
|
|
# Copyright (c) 2018 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,
|
|
../../utils/utils,
|
|
../pow,
|
|
../clique
|
|
|
|
export
|
|
common
|
|
|
|
type
|
|
ChainRef* = ref object of RootRef
|
|
com: CommonRef
|
|
## common block chain configuration
|
|
## used throughout entire app
|
|
|
|
validateBlock: bool ##\
|
|
## If turn off, `persistBlocks` will always return
|
|
## ValidationResult.OK and disable extraValidation too.
|
|
|
|
extraValidation: bool ##\
|
|
## Trigger extra validation, currently within `persistBlocks()`
|
|
## function only.
|
|
|
|
verifyFrom: BlockNumber ##\
|
|
## First block to when `extraValidation` will be applied (only
|
|
## effective if `extraValidation` is true.)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Private constructor helper
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc initChain(c: ChainRef; com: CommonRef; extraValidation: bool) =
|
|
## Constructor for the `Chain` descriptor object.
|
|
c.com = com
|
|
|
|
c.validateBlock = true
|
|
c.extraValidation = extraValidation
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public constructors
|
|
# ------------------------------------------------------------------------------
|
|
|
|
proc newChain*(com: CommonRef, extraValidation: bool): ChainRef =
|
|
## Constructor for the `Chain` descriptor object.
|
|
## The argument `extraValidation` enables extra block
|
|
## chain validation if set `true`.
|
|
new result
|
|
result.initChain(com, extraValidation)
|
|
|
|
proc newChain*(com: CommonRef): ChainRef =
|
|
## Constructor for the `Chain` descriptor object. All sub-object descriptors
|
|
## are initialised with defaults. So is extra block chain validation
|
|
## * `enabled` for PoA networks (such as Goerli)
|
|
## * `disabled` for non-PaA networks
|
|
new result
|
|
result.initChain(com, com.consensus == ConsensusType.POA)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public `Chain` getters
|
|
# ------------------------------------------------------------------------------
|
|
proc clique*(c: ChainRef): Clique =
|
|
## Getter
|
|
c.com.poa
|
|
|
|
proc pow*(c: ChainRef): PowRef =
|
|
## Getter
|
|
c.com.pow
|
|
|
|
proc db*(c: ChainRef): CoreDbRef =
|
|
## Getter
|
|
c.com.db
|
|
|
|
proc com*(c: ChainRef): CommonRef =
|
|
## Getter
|
|
c.com
|
|
|
|
proc validateBlock*(c: ChainRef): bool =
|
|
## Getter
|
|
c.validateBlock
|
|
|
|
proc extraValidation*(c: ChainRef): bool =
|
|
## Getter
|
|
c.extraValidation
|
|
|
|
proc verifyFrom*(c: ChainRef): BlockNumber =
|
|
## Getter
|
|
c.verifyFrom
|
|
|
|
proc currentBlock*(c: ChainRef): BlockHeader
|
|
{.gcsafe, raises: [CatchableError].} =
|
|
## currentBlock retrieves the current head block of the canonical chain.
|
|
## Ideally the block should be retrieved from the blockchain's internal cache.
|
|
## but now it's enough to retrieve it from database
|
|
c.db.getCanonicalHead()
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# Public `Chain` setters
|
|
# ------------------------------------------------------------------------------
|
|
proc `validateBlock=`*(c: ChainRef; validateBlock: bool) =
|
|
## Setter. If set `true`, the assignment value `validateBlock` enables
|
|
## block execution, else it will always return ValidationResult.OK
|
|
c.validateBlock = validateBlock
|
|
|
|
proc `extraValidation=`*(c: ChainRef; extraValidation: bool) =
|
|
## Setter. If set `true`, the assignment value `extraValidation` enables
|
|
## extra block chain validation.
|
|
c.extraValidation = extraValidation
|
|
|
|
proc `verifyFrom=`*(c: ChainRef; verifyFrom: BlockNumber) =
|
|
## Setter. The assignment value `verifyFrom` defines the first block where
|
|
## validation should start if the `Clique` field `extraValidation` was set
|
|
## `true`.
|
|
c.verifyFrom = verifyFrom
|
|
|
|
proc `verifyFrom=`*(c: ChainRef; verifyFrom: uint64) =
|
|
## Variant of `verifyFrom=`
|
|
c.verifyFrom = verifyFrom.u256
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# End
|
|
# ------------------------------------------------------------------------------
|