implement terminal-total-difficulty-override; keep kintsugi TTDs consistent (#3118)

* implement terminal-total-difficulty-override; keep TTD consistent for m2 scripts/docs

* use Option[uint64] instead of uint64
This commit is contained in:
tersec 2021-11-25 10:53:31 +00:00 committed by GitHub
parent 9c2f43ed0e
commit cc0dbd5bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 15 deletions

View File

@ -355,6 +355,13 @@ type
defaultValueDesc: "50"
name: "sync-horizon" }: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/client-settings.md#override-terminal-total-difficulty
terminalTotalDifficultyOverride* {.
hidden
desc: "Override pre-configured TERMINAL_TOTAL_DIFFICULTY parameter"
name: "terminal-total-difficulty-override"
}: Option[uint64]
of createTestnet:
testnetDepositsFile* {.
desc: "A LaunchPad deposits file for the genesis state validators"

View File

@ -184,21 +184,21 @@ when hasGenesisDetection:
func isGenesisCandidate(m: Eth1Monitor, blk: Eth1Block): bool =
m.hasEnoughValidators(blk) and m.isAfterMinGenesisTime(blk)
proc findGenesisBlockInRange(m: Eth1Monitor, startBlock, endBlock: Eth1Block):
func findGenesisBlockInRange(m: Eth1Monitor, startBlock, endBlock: Eth1Block):
Future[Eth1Block] {.async, gcsafe.}
proc signalGenesis(m: Eth1Monitor, genesisState: BeaconStateRef) =
func signalGenesis(m: Eth1Monitor, genesisState: BeaconStateRef) =
m.genesisState = genesisState
if not m.genesisStateFut.isNil:
m.genesisStateFut.complete()
m.genesisStateFut = nil
proc allGenesisDepositsUpTo(m: Eth1Monitor, totalDeposits: uint64): seq[DepositData] =
func allGenesisDepositsUpTo(m: Eth1Monitor, totalDeposits: uint64): seq[DepositData] =
for i in 0'u64 ..< totalDeposits:
result.add m.db.genesisDeposits.get(i)
proc createGenesisState(m: Eth1Monitor, eth1Block: Eth1Block): BeaconStateRef =
func createGenesisState(m: Eth1Monitor, eth1Block: Eth1Block): BeaconStateRef =
notice "Generating genesis state",
blockNum = eth1Block.number,
blockHash = eth1Block.voteData.block_hash,
@ -217,7 +217,7 @@ when hasGenesisDetection:
if eth1Block.activeValidatorsCount != 0:
doAssert result.validators.lenu64 == eth1Block.activeValidatorsCount
proc produceDerivedData(m: Eth1Monitor, deposit: DepositData) =
func produceDerivedData(m: Eth1Monitor, deposit: DepositData) =
let htr = hash_tree_root(deposit)
if verify_deposit_signature(m.cfg, deposit):
@ -229,7 +229,7 @@ when hasGenesisDetection:
withdrawal_credentials: deposit.withdrawal_credentials)
m.genesisValidatorKeyToIndex[pubkey] = idx
proc processGenesisDeposit*(m: Eth1Monitor, newDeposit: DepositData) =
func processGenesisDeposit*(m: Eth1Monitor, newDeposit: DepositData) =
m.db.genesisDeposits.add newDeposit
m.produceDerivedData(newDeposit)
@ -420,7 +420,7 @@ template readJsonField(j: JsonNode, fieldName: string, ValueType: type): untyped
template init[N: static int](T: type DynamicBytes[N, N]): T =
T newSeq[byte](N)
proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
func depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
raises: [Defect, CatchableError].} =
if depositsList.kind != JArray:
raise newException(CatchableError,
@ -491,7 +491,7 @@ when hasDepositRootChecks:
awaitWithTimeout(fut, timeout):
raise newException(DataProviderTimeout, "Timeout")
proc fetchDepositContractData(p: Web3DataProviderRef, blk: Eth1Block):
func fetchDepositContractData(p: Web3DataProviderRef, blk: Eth1Block):
Future[DepositContractDataStatus] {.async.} =
let
depositRoot = p.ns.get_deposit_root.call(blockNumber = blk.number)
@ -584,7 +584,7 @@ proc pruneOldBlocks(chain: var Eth1Chain, depositIndex: uint64) =
newTailBlock = lastBlock.voteData.block_hash,
depositsCount = lastBlock.voteData.deposit_count
proc advanceMerkleizer(chain: Eth1Chain,
func advanceMerkleizer(chain: Eth1Chain,
merkleizer: var DepositsMerkleizer,
depositIndex: uint64): bool =
if chain.blocks.len == 0:
@ -610,7 +610,7 @@ proc advanceMerkleizer(chain: Eth1Chain,
return merkleizer.getChunkCount == depositIndex
proc getDepositsRange(chain: Eth1Chain, first, last: uint64): seq[DepositData] =
func getDepositsRange(chain: Eth1Chain, first, last: uint64): seq[DepositData] =
# TODO It's possible to make this faster by performing binary search that
# will locate the blocks holding the `first` and `last` indices.
# TODO There is an assumption here that the requested range will be present
@ -629,7 +629,7 @@ proc getDepositsRange(chain: Eth1Chain, first, last: uint64): seq[DepositData] =
if globalIdx >= first and globalIdx < last:
result.add blk.deposits[i]
proc lowerBound(chain: Eth1Chain, depositCount: uint64): Eth1Block =
func lowerBound(chain: Eth1Chain, depositCount: uint64): Eth1Block =
# TODO: This can be replaced with a proper binary search in the
# future, but the `algorithm` module currently requires an
# `openArray`, which the `deques` module can't provide yet.
@ -817,7 +817,7 @@ proc safeCancel(fut: var Future[void]) =
fut.cancel()
fut = nil
proc clear(chain: var Eth1Chain) =
func clear(chain: var Eth1Chain) =
chain.blocks.clear()
chain.blocksByHash.clear()
chain.hasConsensusViolation = false
@ -844,7 +844,7 @@ proc stop*(m: Eth1Monitor) {.async.} =
const
votedBlocksSafetyMargin = 50
proc earliestBlockOfInterest(m: Eth1Monitor): Eth1BlockNumber =
func earliestBlockOfInterest(m: Eth1Monitor): Eth1BlockNumber =
m.latestEth1BlockNumber - (2 * m.cfg.ETH1_FOLLOW_DISTANCE) - votedBlocksSafetyMargin

View File

@ -1505,7 +1505,12 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref BrHmacDrbgContext) {.r
# letting the default Ctrl+C handler exit is safe, since we only read from
# the db.
let metadata = config.loadEth2Network()
var metadata = config.loadEth2Network()
# https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/client-settings.md#override-terminal-total-difficulty
if config.terminalTotalDifficultyOverride.isSome:
metadata.cfg.TERMINAL_TOTAL_DIFFICULTY =
config.terminalTotalDifficultyOverride.get.u256
# Updating the config based on the metadata certainly is not beautiful but it
# works

View File

@ -20,7 +20,7 @@ cd Nethermind.Runner
run Nethermind
```
rm -rf bin/Release/net5.0/nethermind_db
dotnet run -c Release -- --config themerge_kintsugi_m2 --Merge.TerminalTotalDifficulty 100
dotnet run -c Release -- --config themerge_kintsugi_m2 --Merge.TerminalTotalDifficulty 0
```
# Verify that Nimbus runs through test vectors