Add more eth1-related logging
This commit is contained in:
parent
e22248bca1
commit
d232f16b40
|
@ -1,6 +1,6 @@
|
||||||
import
|
import
|
||||||
std/[deques, tables, hashes, options, strformat, strutils],
|
std/[deques, tables, hashes, options, strformat, strutils],
|
||||||
chronos, web3, web3/ethtypes as web3Types, json, chronicles,
|
chronos, web3, web3/ethtypes as web3Types, json, chronicles/timings,
|
||||||
eth/common/eth_types, eth/async_utils,
|
eth/common/eth_types, eth/async_utils,
|
||||||
spec/[datatypes, digest, crypto, beaconstate, helpers],
|
spec/[datatypes, digest, crypto, beaconstate, helpers],
|
||||||
ssz, beacon_chain_db, network_metadata, merkle_minimal, beacon_node_status
|
ssz, beacon_chain_db, network_metadata, merkle_minimal, beacon_node_status
|
||||||
|
@ -154,9 +154,11 @@ func voting_period_start_time*(state: BeaconState): uint64 =
|
||||||
compute_time_at_slot(state, eth1_voting_period_start_slot)
|
compute_time_at_slot(state, eth1_voting_period_start_slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/validator.md#get_eth1_data
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/validator.md#get_eth1_data
|
||||||
func is_candidate_block(preset: RuntimePreset, blk: Eth1Block, period_start: uint64): bool =
|
func is_candidate_block(preset: RuntimePreset,
|
||||||
(blk.timestamp + SECONDS_PER_ETH1_BLOCK.uint64 * preset.ETH1_FOLLOW_DISTANCE <= period_start) and
|
blk: Eth1Block,
|
||||||
(blk.timestamp + SECONDS_PER_ETH1_BLOCK.uint64 * preset.ETH1_FOLLOW_DISTANCE * 2 >= period_start)
|
period_start: uint64): bool =
|
||||||
|
(blk.timestamp + SECONDS_PER_ETH1_BLOCK * preset.ETH1_FOLLOW_DISTANCE <= period_start) and
|
||||||
|
(blk.timestamp + SECONDS_PER_ETH1_BLOCK * preset.ETH1_FOLLOW_DISTANCE * 2 >= period_start)
|
||||||
|
|
||||||
func asEth2Digest*(x: BlockHash): Eth2Digest =
|
func asEth2Digest*(x: BlockHash): Eth2Digest =
|
||||||
Eth2Digest(data: array[32, byte](x))
|
Eth2Digest(data: array[32, byte](x))
|
||||||
|
@ -184,12 +186,10 @@ func makeSuccessorWithoutDeposits(existingBlock: Eth1Block,
|
||||||
deposit_root: existingBlock.voteData.deposit_root),
|
deposit_root: existingBlock.voteData.deposit_root),
|
||||||
activeValidatorsCount: existingBlock.activeValidatorsCount)
|
activeValidatorsCount: existingBlock.activeValidatorsCount)
|
||||||
|
|
||||||
func latestCandidateBlock(eth1Chain: Eth1Chain,
|
func latestCandidateBlock(m: Eth1Monitor, periodStart: uint64): Eth1Block =
|
||||||
preset: RuntimePreset,
|
for i in countdown(m.eth1Chain.blocks.len - 1, 0):
|
||||||
periodStart: uint64): Eth1Block =
|
let blk = m.eth1Chain.blocks[i]
|
||||||
for i in countdown(eth1Chain.blocks.len - 1, 0):
|
if is_candidate_block(m.preset, blk, periodStart):
|
||||||
let blk = eth1Chain.blocks[i]
|
|
||||||
if is_candidate_block(preset, blk, periodStart):
|
|
||||||
return blk
|
return blk
|
||||||
|
|
||||||
func popFirst(eth1Chain: var Eth1Chain) =
|
func popFirst(eth1Chain: var Eth1Chain) =
|
||||||
|
@ -333,7 +333,6 @@ proc getBlockProposalData*(m: Eth1Monitor,
|
||||||
finalizedEth1Data: Eth1Data): BlockProposalEth1Data =
|
finalizedEth1Data: Eth1Data): BlockProposalEth1Data =
|
||||||
var pendingDepositsCount = state.eth1_data.deposit_count -
|
var pendingDepositsCount = state.eth1_data.deposit_count -
|
||||||
state.eth1_deposit_index
|
state.eth1_deposit_index
|
||||||
|
|
||||||
# TODO(zah)
|
# TODO(zah)
|
||||||
# To make block proposal cheaper, we can perform this action more regularly
|
# To make block proposal cheaper, we can perform this action more regularly
|
||||||
# (e.g. in BeaconNode.onSlot). But keep in mind that this action needs to be
|
# (e.g. in BeaconNode.onSlot). But keep in mind that this action needs to be
|
||||||
|
@ -361,27 +360,34 @@ proc getBlockProposalData*(m: Eth1Monitor,
|
||||||
|
|
||||||
var otherVotesCountTable = initCountTable[Eth1Data]()
|
var otherVotesCountTable = initCountTable[Eth1Data]()
|
||||||
for vote in state.eth1_data_votes:
|
for vote in state.eth1_data_votes:
|
||||||
|
let
|
||||||
|
eth1Block = m.eth1Chain.findBlock(vote)
|
||||||
|
isSuccessor = vote.deposit_count >= state.eth1_data.deposit_count
|
||||||
# TODO(zah)
|
# TODO(zah)
|
||||||
# There is a slight deviation from the spec here to deal with the following
|
# There is a slight deviation from the spec here to deal with the following
|
||||||
# problem: the in-memory database of eth1 blocks for a restarted node will
|
# problem: the in-memory database of eth1 blocks for a restarted node will
|
||||||
# be empty which will lead a "no change" vote. To fix this, we'll need to
|
# be empty which will lead a "no change" vote. To fix this, we'll need to
|
||||||
# add rolling persistance for all potentially voted on blocks.
|
# add rolling persistance for all potentially voted on blocks.
|
||||||
let eth1Block = m.eth1Chain.findBlock(vote)
|
isCandidate = (eth1Block == nil or is_candidate_block(m.preset, eth1Block, periodStart))
|
||||||
if (eth1Block == nil or is_candidate_block(m.preset, eth1Block, periodStart)) and
|
|
||||||
vote.deposit_count > state.eth1_data.deposit_count:
|
if isSuccessor and isCandidate:
|
||||||
otherVotesCountTable.inc vote
|
otherVotesCountTable.inc vote
|
||||||
|
else:
|
||||||
|
debug "Ignoring eth1 vote", root = vote.block_hash, isSuccessor, isCandidate
|
||||||
|
|
||||||
if otherVotesCountTable.len > 0:
|
if otherVotesCountTable.len > 0:
|
||||||
let (winningVote, votes) = otherVotesCountTable.largest
|
let (winningVote, votes) = otherVotesCountTable.largest
|
||||||
|
debug "Voting on eth1 head with majority", votes
|
||||||
result.vote = winningVote
|
result.vote = winningVote
|
||||||
if uint64((votes + 1) * 2) > SLOTS_PER_ETH1_VOTING_PERIOD:
|
if uint64((votes + 1) * 2) > SLOTS_PER_ETH1_VOTING_PERIOD:
|
||||||
pendingDepositsCount = winningVote.deposit_count -
|
pendingDepositsCount = winningVote.deposit_count - state.eth1_deposit_index
|
||||||
state.eth1_deposit_index
|
|
||||||
else:
|
else:
|
||||||
let latestBlock = m.eth1Chain.latestCandidateBlock(m.preset, periodStart)
|
let latestBlock = m.latestCandidateBlock(periodStart)
|
||||||
if latestBlock == nil:
|
if latestBlock == nil:
|
||||||
|
debug "No acceptable eth1 votes and no recent candidates. Voting no change"
|
||||||
result.vote = state.eth1_data
|
result.vote = state.eth1_data
|
||||||
else:
|
else:
|
||||||
|
debug "No acceptable eth1 votes. Voting for latest candidate"
|
||||||
result.vote = latestBlock.voteData
|
result.vote = latestBlock.voteData
|
||||||
|
|
||||||
if pendingDepositsCount > 0 and hasLatestDeposits:
|
if pendingDepositsCount > 0 and hasLatestDeposits:
|
||||||
|
@ -586,6 +592,7 @@ proc syncBlockRange(m: Eth1Monitor,
|
||||||
fromBlock = currentBlock,
|
fromBlock = currentBlock,
|
||||||
toBlock = maxBlockNumberRequested
|
toBlock = maxBlockNumberRequested
|
||||||
try:
|
try:
|
||||||
|
debug.logTime "Deposit logs obtained":
|
||||||
depositLogs = await m.dataProvider.ns.getJsonLogs(
|
depositLogs = await m.dataProvider.ns.getJsonLogs(
|
||||||
DepositEvent,
|
DepositEvent,
|
||||||
fromBlock = some blockId(currentBlock),
|
fromBlock = some blockId(currentBlock),
|
||||||
|
@ -597,12 +604,14 @@ proc syncBlockRange(m: Eth1Monitor,
|
||||||
if blocksPerRequest == 0:
|
if blocksPerRequest == 0:
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
debug.logTime "Deposits grouped in blocks":
|
||||||
let eth1Blocks = depositEventsToBlocks(depositLogs)
|
let eth1Blocks = depositEventsToBlocks(depositLogs)
|
||||||
|
|
||||||
for i in 0 ..< eth1Blocks.len:
|
for i in 0 ..< eth1Blocks.len:
|
||||||
# TODO(zah): The DB operations should be executed as a transaction here
|
# TODO(zah): The DB operations should be executed as a transaction here
|
||||||
let blk = eth1Blocks[i]
|
let blk = eth1Blocks[i]
|
||||||
|
|
||||||
|
debug.logTime "Deposits persisted":
|
||||||
for deposit in blk.deposits:
|
for deposit in blk.deposits:
|
||||||
m.db.processDeposit(deposit.data)
|
m.db.processDeposit(deposit.data)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b9a7c6bb0733ce8c76f0ac8c7889c5e48e7c924f
|
Subproject commit b7150d195beff7d018d47a36a2ea19630537cd8b
|
Loading…
Reference in New Issue