add ttd passed field to chain config

This commit is contained in:
jangko 2023-08-06 14:55:11 +07:00
parent 7ec298d49d
commit 1788d27dfe
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 14 additions and 5 deletions

View File

@ -181,7 +181,7 @@ proc getTd(com: CommonRef, blockHash: Hash256): Option[DifficultyInt] =
proc needTdForHardForkDetermination(com: CommonRef): bool = proc needTdForHardForkDetermination(com: CommonRef): bool =
let t = com.forkTransitionTable.mergeForkTransitionThreshold 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] = proc getTdIfNecessary(com: CommonRef, blockHash: Hash256): Option[DifficultyInt] =
if needTdForHardForkDetermination(com): if needTdForHardForkDetermination(com):

View File

@ -62,6 +62,7 @@ type
MergeForkTransitionThreshold* = object MergeForkTransitionThreshold* = object
blockNumber*: Option[BlockNumber] blockNumber*: Option[BlockNumber]
ttd*: Option[DifficultyInt] ttd*: Option[DifficultyInt]
ttdPassed*: Option[bool]
ForkTransitionTable* = object ForkTransitionTable* = object
blockNumberThresholds*: array[Frontier..GrayGlacier, Option[BlockNumber]] 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 map.blockNumberThresholds[fork].isSome and forkDeterminer.blockNumber >= map.blockNumberThresholds[fork].get
elif fork == MergeFork: elif fork == MergeFork:
# MergeFork is a special case that can use either block number or ttd; # 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 let t = map.mergeForkTransitionThreshold
if t.blockNumber.isSome: if t.ttdPassed.isSome:
t.ttdPassed.get
elif t.blockNumber.isSome:
forkDeterminer.blockNumber >= t.blockNumber.get forkDeterminer.blockNumber >= t.blockNumber.get
elif t.ttd.isSome and forkDeterminer.td.isSome: elif t.ttd.isSome and forkDeterminer.td.isSome:
forkDeterminer.td.get >= t.ttd.get forkDeterminer.td.get >= t.ttd.get
@ -172,6 +175,7 @@ type
clique* : CliqueOptions clique* : CliqueOptions
terminalTotalDifficulty*: Option[UInt256] terminalTotalDifficulty*: Option[UInt256]
terminalTotalDifficultyPassed*: Option[bool]
consensusType* consensusType*
{.dontSerialize.} : ConsensusType {.dontSerialize.} : ConsensusType
@ -215,7 +219,11 @@ const
func mergeForkTransitionThreshold*(conf: ChainConfig): MergeForkTransitionThreshold = 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 = proc toForkTransitionTable*(conf: ChainConfig): ForkTransitionTable =
# We used to auto-generate this code from a list of # 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.mergeForkBlock = t.mergeForkTransitionThreshold.blockNumber
conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd
conf.terminalTotalDifficultyPassed = t.mergeForkTransitionThreshold.ttdPassed
conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai] conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai]
conf.cancunTime = t.timeThresholds[HardFork.Cancun] conf.cancunTime = t.timeThresholds[HardFork.Cancun]