From 1788d27dfe7ab1e2906cb3f629c008b6ece5c0e5 Mon Sep 17 00:00:00 2001 From: jangko Date: Sun, 6 Aug 2023 14:55:11 +0700 Subject: [PATCH] add ttd passed field to chain config --- nimbus/common/common.nim | 2 +- nimbus/common/hardforks.nim | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index 2f48b210d..aa462abd1 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -181,7 +181,7 @@ proc getTd(com: CommonRef, blockHash: Hash256): Option[DifficultyInt] = proc needTdForHardForkDetermination(com: CommonRef): bool = let t = com.forkTransitionTable.mergeForkTransitionThreshold - t.blockNumber.isNone and t.ttd.isSome + t.ttdPassed.isNone and t.blockNumber.isNone and t.ttd.isSome proc getTdIfNecessary(com: CommonRef, blockHash: Hash256): Option[DifficultyInt] = if needTdForHardForkDetermination(com): diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index 5f58c313a..6e475b9d5 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.nim @@ -62,6 +62,7 @@ type MergeForkTransitionThreshold* = object blockNumber*: Option[BlockNumber] ttd*: Option[DifficultyInt] + ttdPassed*: Option[bool] ForkTransitionTable* = object blockNumberThresholds*: array[Frontier..GrayGlacier, Option[BlockNumber]] @@ -132,9 +133,11 @@ func isGTETransitionThreshold*(map: ForkTransitionTable, forkDeterminer: ForkDet map.blockNumberThresholds[fork].isSome and forkDeterminer.blockNumber >= map.blockNumberThresholds[fork].get elif fork == MergeFork: # MergeFork is a special case that can use either block number or ttd; - # block number takes precedence. + # ttdPassed > block number > ttd takes precedence. let t = map.mergeForkTransitionThreshold - if t.blockNumber.isSome: + if t.ttdPassed.isSome: + t.ttdPassed.get + elif t.blockNumber.isSome: forkDeterminer.blockNumber >= t.blockNumber.get elif t.ttd.isSome and forkDeterminer.td.isSome: forkDeterminer.td.get >= t.ttd.get @@ -172,6 +175,7 @@ type clique* : CliqueOptions terminalTotalDifficulty*: Option[UInt256] + terminalTotalDifficultyPassed*: Option[bool] consensusType* {.dontSerialize.} : ConsensusType @@ -215,7 +219,11 @@ const func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold = - MergeForkTransitionThreshold(blockNumber: conf.mergeForkBlock, ttd: conf.terminalTotalDifficulty) + MergeForkTransitionThreshold( + blockNumber: conf.mergeForkBlock, + ttd: conf.terminalTotalDifficulty, + ttdPassed: conf.terminalTotalDifficultyPassed + ) proc toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable = # We used to auto-generate this code from a list of @@ -258,7 +266,8 @@ proc populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable) conf.mergeForkBlock = t.mergeForkTransitionThreshold.blockNumber conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd - + conf.terminalTotalDifficultyPassed = t.mergeForkTransitionThreshold.ttdPassed + conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai] conf.cancunTime = t.timeThresholds[HardFork.Cancun]