Also bumps Confutils to allow setting the hidden --web3-mode param
(to allow testing the eth1 syncing without validators)
This commit is contained in:
Zahary Karadjov 2021-01-29 23:21:44 +02:00 committed by zah
parent 490e4c7666
commit fa99c3b417
9 changed files with 39 additions and 28 deletions

View File

@ -42,7 +42,7 @@ type
## between different versions of the client and accidentally using an old
## database.
backend: KvStoreRef
preset: RuntimePreset
preset*: RuntimePreset
genesisDeposits*: DepositsSeq
checkpoint*: proc() {.gcsafe.}

View File

@ -72,3 +72,7 @@ template findIt*(s: openArray, predicate: untyped): int =
proc currentSlot*(node: BeaconNode): Slot =
node.beaconClock.now.slotOrZero
template runtimePreset*(node: BeaconNode): RuntimePreset =
node.db.preset

View File

@ -47,9 +47,9 @@ type
test = "Test a web3 provider"
Web3Mode* {.pure.} = enum
auto = "Enabled only when validators are attached"
enabled = "Always enabled"
disabled = "Always disabled"
auto # Enabled only when validators are attached
enabled # Always enabled
disabled # Always disabled
DoppelgangerProtectionMode* {.pure.} = enum
dontcheck
@ -177,8 +177,6 @@ type
desc: "SSZ file specifying a recent finalized block"
name: "finalized-checkpoint-block" }: Option[InputFile]
runtimePreset* {.hidden.}: RuntimePreset
nodeName* {.
defaultValue: ""
desc: "A name for this node that will appear in the logs. " &

View File

@ -49,7 +49,6 @@ type
timestamp*: Eth1BlockTimestamp
deposits*: seq[DepositData]
voteData*: Eth1Data
voteDataVerified*: bool
when hasGenesisDetection:
activeValidatorsCount*: uint64
@ -61,6 +60,8 @@ type
blocksByHash: Table[BlockHash, Eth1Block]
finalizedBlockHash: Eth2Digest
finalizedDepositsMerkleizer: DepositsMerkleizer
hasConsensusViolation: bool
## The local chain contradicts the observed consensus on the network
Eth1MonitorState = enum
Initialized
@ -541,6 +542,7 @@ proc pruneOldBlocks(chain: var Eth1Chain, depositIndex: uint64) =
lastBlock = blk
if chain.finalizedDepositsMerkleizer.getChunkCount > initialChunks:
chain.finalizedBlockHash = lastBlock.voteData.block_hash
chain.db.putEth2FinalizedTo DepositContractSnapshot(
eth1Block: lastBlock.voteData.block_hash,
depositContractState: chain.finalizedDepositsMerkleizer.toDepositContractState)
@ -624,7 +626,6 @@ proc trackFinalizedState*(chain: var Eth1Chain,
let matchingBlock = chain.lowerBound(finalizedEth1Data.deposit_count)
result = if matchingBlock != nil:
if matchingBlock.voteData.deposit_root == finalizedEth1Data.deposit_root:
matchingBlock.voteDataVerified = true
true
else:
error "Corrupted deposits history detected",
@ -632,6 +633,7 @@ proc trackFinalizedState*(chain: var Eth1Chain,
taretDepositsCount = finalizedEth1Data.deposit_count,
ourDepositsRoot = matchingBlock.voteData.deposit_root,
targetDepositsRoot = finalizedEth1Data.deposit_root
chain.hasConsensusViolation = true
false
else:
error "The Eth1 chain is in inconsistent state",
@ -639,6 +641,7 @@ proc trackFinalizedState*(chain: var Eth1Chain,
checkpointDeposits = finalizedEth1Data.deposit_count,
localChainStart = shortLog(chain.blocks.peekFirst),
localChainEnd = shortLog(chain.blocks.peekLast)
chain.hasConsensusViolation = true
false
if result:
@ -787,6 +790,7 @@ proc safeCancel(fut: var Future[void]) =
proc clear(chain: var Eth1Chain) =
chain.blocks.clear()
chain.blocksByHash.clear()
chain.hasConsensusViolation = false
proc resetState(m: Eth1Monitor) {.async.} =
safeCancel m.runFut
@ -907,8 +911,6 @@ proc syncBlockRange(m: Eth1Monitor,
of DepositRootIncorrect, DepositCountIncorrect:
raise newException(CorruptDataProvider,
"The deposit log events disagree with the deposit contract state")
of VerifiedCorrect:
lastBlock.voteDataVerified = true
else:
discard
@ -1057,6 +1059,9 @@ proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
await m.stop()
return
if m.eth1Chain.hasConsensusViolation:
raise newException(CorruptDataProvider, "Eth1 chain contradicts Eth2 consensus")
await m.eth1Progress.wait()
m.eth1Progress.clear()

View File

@ -75,6 +75,7 @@ func enrForkIdFromState(state: BeaconState): ENRForkID =
next_fork_epoch: FAR_FUTURE_EPOCH)
proc init*(T: type BeaconNode,
runtimePreset: RuntimePreset,
rng: ref BrHmacDrbgContext,
conf: BeaconNodeConf,
depositContractAddress: Eth1Address,
@ -83,7 +84,7 @@ proc init*(T: type BeaconNode,
genesisStateContents: ref string,
genesisDepositsSnapshotContents: ref string): Future[BeaconNode] {.async.} =
let
db = BeaconChainDB.init(conf.runtimePreset, conf.databaseDir)
db = BeaconChainDB.init(runtimePreset, conf.databaseDir)
var
genesisState, checkpointState: ref BeaconState
@ -143,7 +144,7 @@ proc init*(T: type BeaconNode,
# TODO Could move this to a separate "GenesisMonitor" process or task
# that would do only this - see Paul's proposal for this.
let eth1MonitorRes = await Eth1Monitor.init(
conf.runtimePreset,
runtimePreset,
db,
conf.web3Url,
depositContractAddress,
@ -209,7 +210,7 @@ proc init*(T: type BeaconNode,
let
chainDagFlags = if conf.verifyFinalization: {verifyFinalization}
else: {}
chainDag = ChainDAGRef.init(conf.runtimePreset, db, chainDagFlags)
chainDag = ChainDAGRef.init(runtimePreset, db, chainDagFlags)
beaconClock = BeaconClock.init(chainDag.headState.data.data)
quarantine = QuarantineRef.init(rng)
databaseGenesisValidatorsRoot =
@ -257,7 +258,7 @@ proc init*(T: type BeaconNode,
let genesisDepositsSnapshot = SSZ.decode(genesisDepositsSnapshotContents[],
DepositContractSnapshot)
eth1Monitor = Eth1Monitor.init(
conf.runtimePreset,
runtimePreset,
db,
conf.web3Url,
depositContractAddress,
@ -1440,6 +1441,7 @@ programMain:
eth1Network: Option[Eth1Network]
depositContractAddress: Option[Eth1Address]
depositContractDeployedAt: Option[BlockHashOrNumber]
runtimePreset: RuntimePreset
setupStdoutLogging(config.logLevel)
@ -1473,7 +1475,7 @@ programMain:
if config.eth2Network.isSome:
let metadata = getMetadataForNetwork(config.eth2Network.get)
config.runtimePreset = metadata.runtimePreset
runtimePreset = metadata.runtimePreset
if config.cmd == noCommand:
for node in metadata.bootstrapNodes:
@ -1489,7 +1491,7 @@ programMain:
depositContractDeployedAt = some metadata.depositContractDeployedAt
eth1Network = metadata.eth1Network
else:
config.runtimePreset = defaultRuntimePreset
runtimePreset = defaultRuntimePreset
when const_preset == "mainnet":
if config.cmd == noCommand:
depositContractAddress = some mainnetMetadata.depositContractAddress
@ -1533,7 +1535,7 @@ programMain:
else: (waitFor getEth1BlockHash(config.web3Url, blockId("latest"))).asEth2Digest
var
initialState = initialize_beacon_state_from_eth1(
config.runtimePreset, eth1Hash, startTime, deposits, {skipBlsValidation})
runtimePreset, eth1Hash, startTime, deposits, {skipBlsValidation})
# https://github.com/ethereum/eth2.0-pm/tree/6e41fcf383ebeb5125938850d8e9b4e9888389b4/interop/mocked_start#create-genesis-state
initialState.genesis_time = startTime
@ -1594,7 +1596,9 @@ programMain:
# letting the default Ctrl+C handler exit is safe, since we only read from
# the db.
var node = waitFor BeaconNode.init(
rng, config,
runtimePreset,
rng,
config,
depositContractAddress.get,
depositContractDeployedAt.get,
eth1Network,
@ -1663,7 +1667,7 @@ programMain:
quit QuitFailure
let deposits = generateDeposits(
config.runtimePreset,
runtimePreset,
rng[],
seed,
walletPath.wallet.nextAccount,
@ -1682,7 +1686,7 @@ programMain:
config.outValidatorsDir / "deposit_data-" & $epochTime() & ".json"
let launchPadDeposits =
mapIt(deposits.value, LaunchPadDeposit.init(config.runtimePreset, it))
mapIt(deposits.value, LaunchPadDeposit.init(runtimePreset, it))
Json.saveFile(depositDataPath, launchPadDeposits)
echo "Deposit data written to \"", depositDataPath, "\""

View File

@ -176,7 +176,7 @@ proc installBeaconApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
genesis_time: node.chainDag.headState.data.data.genesis_time,
genesis_validators_root:
node.chainDag.headState.data.data.genesis_validators_root,
genesis_fork_version: node.config.runtimePreset.GENESIS_FORK_VERSION
genesis_fork_version: node.runtimePreset.GENESIS_FORK_VERSION
)
rpcServer.rpc("get_v1_beacon_states_root") do (stateId: string) -> Eth2Digest:

View File

@ -39,13 +39,13 @@ proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
"CHURN_LIMIT_QUOTIENT": $CHURN_LIMIT_QUOTIENT,
"SHUFFLE_ROUND_COUNT": $SHUFFLE_ROUND_COUNT,
"MIN_GENESIS_ACTIVE_VALIDATOR_COUNT":
$node.config.runtimePreset.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
"MIN_GENESIS_TIME": $node.config.runtimePreset.MIN_GENESIS_TIME,
$node.runtimePreset.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT,
"MIN_GENESIS_TIME": $node.runtimePreset.MIN_GENESIS_TIME,
"HYSTERESIS_QUOTIENT": $HYSTERESIS_QUOTIENT,
"HYSTERESIS_DOWNWARD_MULTIPLIER": $HYSTERESIS_DOWNWARD_MULTIPLIER,
"HYSTERESIS_UPWARD_MULTIPLIER": $HYSTERESIS_UPWARD_MULTIPLIER,
"SAFE_SLOTS_TO_UPDATE_JUSTIFIED": $SAFE_SLOTS_TO_UPDATE_JUSTIFIED,
"ETH1_FOLLOW_DISTANCE": $node.config.runtimePreset.ETH1_FOLLOW_DISTANCE,
"ETH1_FOLLOW_DISTANCE": $node.runtimePreset.ETH1_FOLLOW_DISTANCE,
"TARGET_AGGREGATORS_PER_COMMITTEE": $TARGET_AGGREGATORS_PER_COMMITTEE,
"RANDOM_SUBNETS_PER_VALIDATOR": $RANDOM_SUBNETS_PER_VALIDATOR,
"EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION":
@ -59,9 +59,9 @@ proc installConfigApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
"EJECTION_BALANCE": $EJECTION_BALANCE,
"EFFECTIVE_BALANCE_INCREMENT": $EFFECTIVE_BALANCE_INCREMENT,
"GENESIS_FORK_VERSION":
"0x" & $node.config.runtimePreset.GENESIS_FORK_VERSION,
"0x" & $node.runtimePreset.GENESIS_FORK_VERSION,
"BLS_WITHDRAWAL_PREFIX": "0x" & ncrutils.toHex([BLS_WITHDRAWAL_PREFIX]),
"GENESIS_DELAY": $node.config.runtimePreset.GENESIS_DELAY,
"GENESIS_DELAY": $node.runtimePreset.GENESIS_DELAY,
"SECONDS_PER_SLOT": $SECONDS_PER_SLOT,
"MIN_ATTESTATION_INCLUSION_DELAY": $MIN_ATTESTATION_INCLUSION_DELAY,
"SLOTS_PER_EPOCH": $SLOTS_PER_EPOCH,

View File

@ -261,7 +261,7 @@ proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
assign(poolPtr.tmpState, poolPtr.headState)
makeBeaconBlock(
node.config.runtimePreset,
node.runtimePreset,
hashedState,
validator_index,
head.root,

@ -1 +1 @@
Subproject commit 5d8d1ea648884a460518e7819be2d406e3a4ab0f
Subproject commit cfa95661913b0ff8b1609e3954894f8ab31bbf3e