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:
parent
9c2f43ed0e
commit
cc0dbd5bc0
|
@ -355,6 +355,13 @@ type
|
||||||
defaultValueDesc: "50"
|
defaultValueDesc: "50"
|
||||||
name: "sync-horizon" }: uint64
|
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:
|
of createTestnet:
|
||||||
testnetDepositsFile* {.
|
testnetDepositsFile* {.
|
||||||
desc: "A LaunchPad deposits file for the genesis state validators"
|
desc: "A LaunchPad deposits file for the genesis state validators"
|
||||||
|
|
|
@ -184,21 +184,21 @@ when hasGenesisDetection:
|
||||||
func isGenesisCandidate(m: Eth1Monitor, blk: Eth1Block): bool =
|
func isGenesisCandidate(m: Eth1Monitor, blk: Eth1Block): bool =
|
||||||
m.hasEnoughValidators(blk) and m.isAfterMinGenesisTime(blk)
|
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.}
|
Future[Eth1Block] {.async, gcsafe.}
|
||||||
|
|
||||||
proc signalGenesis(m: Eth1Monitor, genesisState: BeaconStateRef) =
|
func signalGenesis(m: Eth1Monitor, genesisState: BeaconStateRef) =
|
||||||
m.genesisState = genesisState
|
m.genesisState = genesisState
|
||||||
|
|
||||||
if not m.genesisStateFut.isNil:
|
if not m.genesisStateFut.isNil:
|
||||||
m.genesisStateFut.complete()
|
m.genesisStateFut.complete()
|
||||||
m.genesisStateFut = nil
|
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:
|
for i in 0'u64 ..< totalDeposits:
|
||||||
result.add m.db.genesisDeposits.get(i)
|
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",
|
notice "Generating genesis state",
|
||||||
blockNum = eth1Block.number,
|
blockNum = eth1Block.number,
|
||||||
blockHash = eth1Block.voteData.block_hash,
|
blockHash = eth1Block.voteData.block_hash,
|
||||||
|
@ -217,7 +217,7 @@ when hasGenesisDetection:
|
||||||
if eth1Block.activeValidatorsCount != 0:
|
if eth1Block.activeValidatorsCount != 0:
|
||||||
doAssert result.validators.lenu64 == eth1Block.activeValidatorsCount
|
doAssert result.validators.lenu64 == eth1Block.activeValidatorsCount
|
||||||
|
|
||||||
proc produceDerivedData(m: Eth1Monitor, deposit: DepositData) =
|
func produceDerivedData(m: Eth1Monitor, deposit: DepositData) =
|
||||||
let htr = hash_tree_root(deposit)
|
let htr = hash_tree_root(deposit)
|
||||||
|
|
||||||
if verify_deposit_signature(m.cfg, deposit):
|
if verify_deposit_signature(m.cfg, deposit):
|
||||||
|
@ -229,7 +229,7 @@ when hasGenesisDetection:
|
||||||
withdrawal_credentials: deposit.withdrawal_credentials)
|
withdrawal_credentials: deposit.withdrawal_credentials)
|
||||||
m.genesisValidatorKeyToIndex[pubkey] = idx
|
m.genesisValidatorKeyToIndex[pubkey] = idx
|
||||||
|
|
||||||
proc processGenesisDeposit*(m: Eth1Monitor, newDeposit: DepositData) =
|
func processGenesisDeposit*(m: Eth1Monitor, newDeposit: DepositData) =
|
||||||
m.db.genesisDeposits.add newDeposit
|
m.db.genesisDeposits.add newDeposit
|
||||||
m.produceDerivedData(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 =
|
template init[N: static int](T: type DynamicBytes[N, N]): T =
|
||||||
T newSeq[byte](N)
|
T newSeq[byte](N)
|
||||||
|
|
||||||
proc depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
func depositEventsToBlocks(depositsList: JsonNode): seq[Eth1Block] {.
|
||||||
raises: [Defect, CatchableError].} =
|
raises: [Defect, CatchableError].} =
|
||||||
if depositsList.kind != JArray:
|
if depositsList.kind != JArray:
|
||||||
raise newException(CatchableError,
|
raise newException(CatchableError,
|
||||||
|
@ -491,7 +491,7 @@ when hasDepositRootChecks:
|
||||||
awaitWithTimeout(fut, timeout):
|
awaitWithTimeout(fut, timeout):
|
||||||
raise newException(DataProviderTimeout, "Timeout")
|
raise newException(DataProviderTimeout, "Timeout")
|
||||||
|
|
||||||
proc fetchDepositContractData(p: Web3DataProviderRef, blk: Eth1Block):
|
func fetchDepositContractData(p: Web3DataProviderRef, blk: Eth1Block):
|
||||||
Future[DepositContractDataStatus] {.async.} =
|
Future[DepositContractDataStatus] {.async.} =
|
||||||
let
|
let
|
||||||
depositRoot = p.ns.get_deposit_root.call(blockNumber = blk.number)
|
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,
|
newTailBlock = lastBlock.voteData.block_hash,
|
||||||
depositsCount = lastBlock.voteData.deposit_count
|
depositsCount = lastBlock.voteData.deposit_count
|
||||||
|
|
||||||
proc advanceMerkleizer(chain: Eth1Chain,
|
func advanceMerkleizer(chain: Eth1Chain,
|
||||||
merkleizer: var DepositsMerkleizer,
|
merkleizer: var DepositsMerkleizer,
|
||||||
depositIndex: uint64): bool =
|
depositIndex: uint64): bool =
|
||||||
if chain.blocks.len == 0:
|
if chain.blocks.len == 0:
|
||||||
|
@ -610,7 +610,7 @@ proc advanceMerkleizer(chain: Eth1Chain,
|
||||||
|
|
||||||
return merkleizer.getChunkCount == depositIndex
|
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
|
# TODO It's possible to make this faster by performing binary search that
|
||||||
# will locate the blocks holding the `first` and `last` indices.
|
# will locate the blocks holding the `first` and `last` indices.
|
||||||
# TODO There is an assumption here that the requested range will be present
|
# 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:
|
if globalIdx >= first and globalIdx < last:
|
||||||
result.add blk.deposits[i]
|
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
|
# TODO: This can be replaced with a proper binary search in the
|
||||||
# future, but the `algorithm` module currently requires an
|
# future, but the `algorithm` module currently requires an
|
||||||
# `openArray`, which the `deques` module can't provide yet.
|
# `openArray`, which the `deques` module can't provide yet.
|
||||||
|
@ -817,7 +817,7 @@ proc safeCancel(fut: var Future[void]) =
|
||||||
fut.cancel()
|
fut.cancel()
|
||||||
fut = nil
|
fut = nil
|
||||||
|
|
||||||
proc clear(chain: var Eth1Chain) =
|
func clear(chain: var Eth1Chain) =
|
||||||
chain.blocks.clear()
|
chain.blocks.clear()
|
||||||
chain.blocksByHash.clear()
|
chain.blocksByHash.clear()
|
||||||
chain.hasConsensusViolation = false
|
chain.hasConsensusViolation = false
|
||||||
|
@ -844,7 +844,7 @@ proc stop*(m: Eth1Monitor) {.async.} =
|
||||||
const
|
const
|
||||||
votedBlocksSafetyMargin = 50
|
votedBlocksSafetyMargin = 50
|
||||||
|
|
||||||
proc earliestBlockOfInterest(m: Eth1Monitor): Eth1BlockNumber =
|
func earliestBlockOfInterest(m: Eth1Monitor): Eth1BlockNumber =
|
||||||
m.latestEth1BlockNumber - (2 * m.cfg.ETH1_FOLLOW_DISTANCE) - votedBlocksSafetyMargin
|
m.latestEth1BlockNumber - (2 * m.cfg.ETH1_FOLLOW_DISTANCE) - votedBlocksSafetyMargin
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
# letting the default Ctrl+C handler exit is safe, since we only read from
|
||||||
# the db.
|
# 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
|
# Updating the config based on the metadata certainly is not beautiful but it
|
||||||
# works
|
# works
|
||||||
|
|
|
@ -20,7 +20,7 @@ cd Nethermind.Runner
|
||||||
run Nethermind
|
run Nethermind
|
||||||
```
|
```
|
||||||
rm -rf bin/Release/net5.0/nethermind_db
|
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
|
# Verify that Nimbus runs through test vectors
|
||||||
|
|
Loading…
Reference in New Issue