diff --git a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim index de6b4d0f5..a4c42cca2 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim @@ -91,7 +91,6 @@ func getGenesis*(ws: WDBaseSpec, param: NetworkParams) = # Remove PoW altogether param.genesis.difficulty = 0.u256 param.config.terminalTotalDifficulty = some(0.u256) - param.config.clique = CliqueOptions() param.genesis.extraData = @[] # Add some accounts to withdraw to with unconditional SSTOREs diff --git a/nimbus.nimble b/nimbus.nimble index 4d160a3ae..c3cc624ae 100644 --- a/nimbus.nimble +++ b/nimbus.nimble @@ -16,7 +16,7 @@ skipDirs = @["tests", "examples"] # we can't have the result of a custom task in the "bin" var - https://github.com/nim-lang/nimble/issues/542 # bin = @["build/nimbus"] -requires "nim >= 1.2.0", +requires "nim >= 1.6.0", "bncurve", "chronicles", "chronos", diff --git a/nimbus/common/chain_config.nim b/nimbus/common/chain_config.nim index 91763404d..a73a87f95 100644 --- a/nimbus/common/chain_config.nim +++ b/nimbus/common/chain_config.nim @@ -71,7 +71,6 @@ NetworkParams.useDefaultReaderIn JGenesis GenesisAccount.useDefaultReaderIn JGenesis derefType(Genesis).useDefaultReaderIn JGenesis derefType(ChainConfig).useDefaultReaderIn JGenesis -CliqueOptions.useDefaultReaderIn JGenesis # ------------------------------------------------------------------------------ # Private helper functions @@ -149,7 +148,7 @@ func decodePrealloc*(data: seq[byte]): GenesisAlloc result[tup.address] = tup.account # borrowed from `lexer.hexCharValue()` :) -proc fromHex(c: char): int = +func fromHex(c: char): int = case c of '0'..'9': ord(c) - ord('0') of 'a'..'f': ord(c) - ord('a') + 10 @@ -294,7 +293,7 @@ macro fillArrayOfTimeBasedForkOptionals(conf, tmp: typed): untyped = # Public functions # ------------------------------------------------------------------------------ -proc toHardFork*(map: ForkTransitionTable, forkDeterminer: ForkDeterminationInfo): HardFork = +func toHardFork*(map: ForkTransitionTable, forkDeterminer: ForkDeterminationInfo): HardFork = for fork in countdown(HardFork.high, HardFork.low): if isGTETransitionThreshold(map, forkDeterminer, fork): return fork @@ -437,7 +436,7 @@ proc parseGenesisAlloc*(data: string, ga: var GenesisAlloc): bool return true -proc chainConfigForNetwork*(id: NetworkId): ChainConfig = +func chainConfigForNetwork*(id: NetworkId): ChainConfig = # For some public networks, NetworkId and ChainId value are identical # but that is not always the case @@ -514,7 +513,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig = else: ChainConfig() -proc genesisBlockForNetwork*(id: NetworkId): Genesis +func genesisBlockForNetwork*(id: NetworkId): Genesis {.gcsafe, raises: [ValueError, RlpError].} = result = case id of MainNet: @@ -545,21 +544,21 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis else: Genesis() -proc networkParams*(id: NetworkId): NetworkParams +func networkParams*(id: NetworkId): NetworkParams {.gcsafe, raises: [ValueError, RlpError].} = result.genesis = genesisBlockForNetwork(id) result.config = chainConfigForNetwork(id) -proc `==`*(a, b: ChainId): bool = +func `==`*(a, b: ChainId): bool = a.uint64 == b.uint64 -proc `==`*(a, b: Genesis): bool = +func `==`*(a, b: Genesis): bool = if a.isNil and b.isNil: return true if a.isNil and not b.isNil: return false if not a.isNil and b.isNil: return false a[] == b[] -proc `==`*(a, b: ChainConfig): bool = +func `==`*(a, b: ChainConfig): bool = if a.isNil and b.isNil: return true if a.isNil and not b.isNil: return false if not a.isNil and b.isNil: return false diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index 030ddefa8..9d7fa4793 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -67,7 +67,7 @@ type # current hard fork, updated after calling `hardForkTransition` currentFork: HardFork - # one of POW/POA/POS, updated after calling `hardForkTransition` + # one of POW/POS, updated after calling `hardForkTransition` consensusType: ConsensusType syncReqNewHead: SyncReqNewHeadCB @@ -108,10 +108,6 @@ proc hardForkTransition*( com: CommonRef, forkDeterminer: ForkDeterminationInfo) {.gcsafe, raises: [].} -func cliquePeriod*(com: CommonRef): EthTime - -func cliqueEpoch*(com: CommonRef): int - # ------------------------------------------------------------------------------ # Private helper functions # ------------------------------------------------------------------------------ @@ -295,7 +291,7 @@ proc hardForkTransition( ## When consensus type already transitioned to POS, ## the storage can choose not to store TD anymore, ## at that time, TD is no longer needed to find a fork - ## TD only needed during transition from POW/POA to POS. + ## TD only needed during transition from POW to POS. ## Same thing happen before London block, TD can be ignored. let fork = com.toHardFork(forkDeterminer) @@ -451,17 +447,6 @@ func ttd*(com: CommonRef): Option[DifficultyInt] = func ttdPassed*(com: CommonRef): bool = com.config.terminalTotalDifficultyPassed.get(false) -# if you messing with clique period and -# and epoch, it likely will fail clique verification -# at epoch * blocknumber -func cliquePeriod*(com: CommonRef): EthTime = - if com.config.clique.period.isSome: - return EthTime com.config.clique.period.get() - -func cliqueEpoch*(com: CommonRef): int = - if com.config.clique.epoch.isSome: - return com.config.clique.epoch.get() - func pruneHistory*(com: CommonRef): bool = com.pruneHistory @@ -470,8 +455,8 @@ func pruneHistory*(com: CommonRef): bool = # because some client do not make distinction # between them. # And popular networks such as MainNet -# Goerli add more confusion to this -# by not make distinction too in their value. +# add more confusion to this +# by not making a distinction in their value. func chainId*(com: CommonRef): ChainId = com.config.chainId diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index c2fe5fe03..3c1880899 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.nim @@ -53,10 +53,6 @@ const firstTimeBasedFork* = Shanghai type - CliqueOptions* = object - epoch* : Option[int] - period*: Option[int] - MergeForkTransitionThreshold* = object blockNumber*: Option[BlockNumber] ttd*: Option[DifficultyInt] @@ -97,15 +93,11 @@ func forkDeterminationInfo*(n: BlockNumber): ForkDeterminationInfo = func forkDeterminationInfo*(n: BlockNumber, t: EthTime): ForkDeterminationInfo = ForkDeterminationInfo(blockNumber: n, time: some(t), td: none[DifficultyInt]()) -# FIXME: Is this called anywhere? -func forkDeterminationInfoIncludingTd*(n: BlockNumber, t: EthTime, td: DifficultyInt): ForkDeterminationInfo = - ForkDeterminationInfo(blockNumber: n, time: some(t), td: some(td)) - func forkDeterminationInfo*(header: BlockHeader): ForkDeterminationInfo = # FIXME-Adam-mightAlsoNeedTTD? forkDeterminationInfo(header.blockNumber, header.timestamp) -proc adjustForNextBlock*(n: BlockNumber): BlockNumber = +func adjustForNextBlock*(n: BlockNumber): BlockNumber = n + 1 func adjustForNextBlock*(t: EthTime): EthTime = @@ -181,7 +173,6 @@ type cancunTime* : Option[EthTime] pragueTime* : Option[EthTime] - clique* : CliqueOptions terminalTotalDifficulty*: Option[UInt256] terminalTotalDifficultyPassed*: Option[bool] consensusType* @@ -251,7 +242,7 @@ func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThresh ttdPassed: conf.terminalTotalDifficultyPassed ) -proc toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable = +func toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable = # We used to auto-generate this code from a list of # field names, but it doesn't seem worthwhile anymore # (now that there's irregularity due to block-based vs @@ -275,7 +266,7 @@ proc toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable = result.timeThresholds[Cancun] = conf.cancunTime result.timeThresholds[Prague] = conf.pragueTime -proc populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable) = +func populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable) = conf.homesteadBlock = t.blockNumberThresholds[HardFork.Homestead] conf.daoForkBlock = t.blockNumberThresholds[HardFork.DAOFork] conf.eip150Block = t.blockNumberThresholds[HardFork.Tangerine] diff --git a/nimbus/core/pow.nim b/nimbus/core/pow.nim index 845e2843c..9a96d12a5 100644 --- a/nimbus/core/pow.nim +++ b/nimbus/core/pow.nim @@ -34,9 +34,9 @@ type ## might be more useful for testing and debugging than for production. blockNumber*: BlockNumber miningHash*: Hash256 - nonce*: BlockNonce + nonce: BlockNonce mixDigest*: Hash256 - difficulty*: DifficultyInt + difficulty: DifficultyInt PowHeader = object ##\ ## Stolen from `p2p/validate.MiningHeader` @@ -57,7 +57,6 @@ type PowRef* = ref object of RootObj ##\ ## PoW context descriptor lightByEpoch: PowCacheRef ## PoW cache indexed by epoch - nonceAttempts: uint64 ## Unsuccessful tests in last mining process # You should only create one instance of the RNG per application / library # Ref is used so that it can be shared between components @@ -207,10 +206,6 @@ func dumpPowSpecs*(specs: PowSpecs): string = ## Text representation of `PowSpecs` argument object specs.rlpTextEncode -func dumpPowSpecs*(header: BlockHeader): string = - ## Variant of `dumpPowSpecs()` - header.getPowSpecs.dumpPowSpecs - func undumpPowSpecs*(data: string): PowSpecs {.raises: [CatchableError].} = ## Recover `PowSpecs` object from text representation diff --git a/nimbus/db/storage_types.nim b/nimbus/db/storage_types.nim index 1cf756e05..18749a39c 100644 --- a/nimbus/db/storage_types.nim +++ b/nimbus/db/storage_types.nim @@ -38,99 +38,94 @@ type data*: array[33, byte] dataEndPos*: uint8 # the last populated position in the data -proc genericHashKey*(h: Hash256): DbKey {.inline.} = +func genericHashKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(genericHash) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc blockHashToScoreKey*(h: Hash256): DbKey {.inline.} = +func blockHashToScoreKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(blockHashToScore) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc transactionHashToBlockKey*(h: Hash256): DbKey {.inline.} = +func transactionHashToBlockKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(transactionHashToBlock) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc blockNumberToHashKey*(u: BlockNumber): DbKey {.inline.} = +func blockNumberToHashKey*(u: BlockNumber): DbKey {.inline.} = result.data[0] = byte ord(blockNumberToHash) doAssert sizeof(u) <= 32 copyMem(addr result.data[1], unsafeAddr u, sizeof(u)) result.dataEndPos = uint8 sizeof(u) -proc canonicalHeadHashKey*(): DbKey {.inline.} = +func canonicalHeadHashKey*(): DbKey {.inline.} = result.data[0] = byte ord(canonicalHeadHash) result.dataEndPos = 1 -proc slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} = +func slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} = doAssert(h.len == 32) result.data[0] = byte ord(slotHashToSlot) result.data[1 .. 32] = h result.dataEndPos = uint8 32 -proc contractHashKey*(h: Hash256): DbKey {.inline.} = +func contractHashKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(contractHash) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc cliqueSnapshotKey*(h: Hash256): DbKey {.inline.} = - result.data[0] = byte ord(cliqueSnapshot) - result.data[1 .. 32] = h.data - result.dataEndPos = uint8 32 - -proc transitionStatusKey*(): DbKey = +func transitionStatusKey*(): DbKey = # ETH-2 Transition Status result.data[0] = byte ord(transitionStatus) result.dataEndPos = uint8 1 -proc safeHashKey*(): DbKey {.inline.} = +func safeHashKey*(): DbKey {.inline.} = result.data[0] = byte ord(safeHash) result.dataEndPos = uint8 1 -proc finalizedHashKey*(): DbKey {.inline.} = +func finalizedHashKey*(): DbKey {.inline.} = result.data[0] = byte ord(finalizedHash) result.dataEndPos = uint8 1 -proc skeletonProgressKey*(): DbKey {.inline.} = +func skeletonProgressKey*(): DbKey {.inline.} = result.data[0] = byte ord(skeletonProgress) result.dataEndPos = 1 -proc skeletonBlockHashToNumberKey*(h: Hash256): DbKey {.inline.} = +func skeletonBlockHashToNumberKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(skeletonBlockHashToNumber) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc skeletonHeaderKey*(u: BlockNumber): DbKey {.inline.} = +func skeletonHeaderKey*(u: BlockNumber): DbKey {.inline.} = result.data[0] = byte ord(skeletonHeader) doAssert sizeof(u) <= 32 copyMem(addr result.data[1], unsafeAddr u, sizeof(u)) result.dataEndPos = uint8 sizeof(u) -proc skeletonBodyKey*(h: Hash256): DbKey {.inline.} = +func skeletonBodyKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(skeletonBody) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 -proc snapSyncAccountKey*(h: openArray[byte]): DbKey {.inline.} = +func snapSyncAccountKey*(h: openArray[byte]): DbKey {.inline.} = doAssert(h.len == 32) result.data[0] = byte ord(snapSyncAccount) result.data[1 .. 32] = h result.dataEndPos = uint8 sizeof(h) -proc snapSyncStorageSlotKey*(h: openArray[byte]): DbKey {.inline.} = +func snapSyncStorageSlotKey*(h: openArray[byte]): DbKey {.inline.} = doAssert(h.len == 32) result.data[0] = byte ord(snapSyncStorageSlot) result.data[1 .. 32] = h result.dataEndPos = uint8 sizeof(h) -proc snapSyncStateRootKey*(h: openArray[byte]): DbKey {.inline.} = +func snapSyncStateRootKey*(h: openArray[byte]): DbKey {.inline.} = doAssert(h.len == 32) result.data[0] = byte ord(snapSyncStateRoot) result.data[1 .. 32] = h result.dataEndPos = uint8 sizeof(h) -proc blockHashToBlockWitnessKey*(h: Hash256): DbKey {.inline.} = +func blockHashToBlockWitnessKey*(h: Hash256): DbKey {.inline.} = result.data[0] = byte ord(blockHashToBlockWitness) result.data[1 .. 32] = h.data result.dataEndPos = uint8 32 @@ -138,6 +133,6 @@ proc blockHashToBlockWitnessKey*(h: Hash256): DbKey {.inline.} = template toOpenArray*(k: DbKey): openArray[byte] = k.data.toOpenArray(0, int(k.dataEndPos)) -proc `==`*(a, b: DbKey): bool {.inline.} = +func `==`*(a, b: DbKey): bool {.inline.} = a.toOpenArray == b.toOpenArray