don't require attached validator for blinded block BN endpoint (#4313)

This commit is contained in:
tersec 2022-11-10 20:18:08 +00:00 committed by GitHub
parent 48994f67d3
commit 04cbea754b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 32 deletions

View File

@ -212,8 +212,7 @@ type
eth1_deposit_index*: uint64
# Registry
#validators*: HashList[ValidatorStatus, Limit VALIDATOR_REGISTRY_LIMIT]
validators*: HashList[Validator, Limit VALIDATOR_REGISTRY_LIMIT]
validators*: HashList[ValidatorStatus, Limit VALIDATOR_REGISTRY_LIMIT]
balances*: HashList[Gwei, Limit VALIDATOR_REGISTRY_LIMIT]
# Randomness

View File

@ -763,7 +763,7 @@ func forkDigests(node: BeaconNode): auto =
node.dag.forkDigests.capella]
forkDigestsArray
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/validator.md#phase-0-attestation-subnet-stability
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/validator.md#phase-0-attestation-subnet-stability
proc updateAttestationSubnetHandlers(node: BeaconNode, slot: Slot) =
if node.gossipState.card == 0:
# When disconnected, updateGossipState is responsible for all things

View File

@ -33,7 +33,7 @@ func increase_balance*(
if delta != 0: # avoid dirtying the balance cache if not needed
increase_balance(state.balances.mitem(index), delta)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#decrease_balance
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/phase0/beacon-chain.md#decrease_balance
func decrease_balance*(balance: var Gwei, delta: Gwei) =
balance =
if delta > balance:
@ -151,7 +151,7 @@ func get_slashing_penalty*(state: ForkyBeaconState,
{.fatal: "invalid BeaconState type".}
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/beacon-chain.md#modified-slash_validator
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#modified-slash_validator
func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei =
validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT

View File

@ -141,7 +141,7 @@ type
message*: ContributionAndProof
signature*: ValidatorSig
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/validator.md#syncaggregatorselectiondata
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/altair/validator.md#syncaggregatorselectiondata
SyncAggregatorSelectionData* = object
slot*: Slot
subcommittee_index*: uint64 # `SyncSubcommitteeIndex` after validation

View File

@ -354,7 +354,7 @@ func is_execution_enabled*(
capella.SigVerifiedBeaconBlockBody): bool =
is_merge_transition_block(state, body) or is_merge_transition_complete(state)
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/bellatrix/beacon-chain.md#compute_timestamp_at_slot
func compute_timestamp_at_slot*(state: ForkyBeaconState, slot: Slot): uint64 =
# Note: This function is unsafe with respect to overflows and underflows.
let slots_since_genesis = slot - GENESIS_SLOT

View File

@ -181,7 +181,8 @@ func maybeUpgradeStateToBellatrix(
bellatrixData: bellatrix.HashedBeaconState(
root: hash_tree_root(newState[]), data: newState[]))[]
from ./datatypes/capella import HashedBeaconState
from ./datatypes/capella import
ExecutionPayload, HashedBeaconState, asSigVerified
func maybeUpgradeStateToCapella(
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
@ -322,7 +323,7 @@ template partialBeaconBlock(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload): phase0.BeaconBlock =
execution_payload: bellatrix.ExecutionPayload): phase0.BeaconBlock =
phase0.BeaconBlock(
slot: state.data.slot,
proposer_index: proposer_index.uint64,
@ -348,7 +349,7 @@ proc makeBeaconBlock*(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload,
execution_payload: bellatrix.ExecutionPayload,
rollback: RollbackHashedProc[phase0.HashedBeaconState],
cache: var StateCache,
# TODO:
@ -391,7 +392,7 @@ template partialBeaconBlock(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload): altair.BeaconBlock =
execution_payload: bellatrix.ExecutionPayload): altair.BeaconBlock =
altair.BeaconBlock(
slot: state.data.slot,
proposer_index: proposer_index.uint64,
@ -418,7 +419,7 @@ proc makeBeaconBlock*(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload,
execution_payload: bellatrix.ExecutionPayload,
rollback: RollbackHashedProc[altair.HashedBeaconState],
cache: var StateCache,
# TODO:
@ -462,7 +463,7 @@ template partialBeaconBlock(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload): bellatrix.BeaconBlock =
execution_payload: bellatrix.ExecutionPayload): bellatrix.BeaconBlock =
bellatrix.BeaconBlock(
slot: state.data.slot,
proposer_index: proposer_index.uint64,
@ -490,7 +491,7 @@ proc makeBeaconBlock*(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
execution_payload: ExecutionPayload,
execution_payload: bellatrix.ExecutionPayload,
rollback: RollbackHashedProc[bellatrix.HashedBeaconState],
cache: var StateCache,
# TODO:
@ -532,7 +533,7 @@ proc makeBeaconBlock*(
deposits: seq[Deposit],
exits: BeaconBlockExits,
sync_aggregate: SyncAggregate,
executionPayload: ExecutionPayload,
executionPayload: bellatrix.ExecutionPayload,
rollback: RollbackForkedHashedProc,
cache: var StateCache,
# TODO:

View File

@ -626,7 +626,7 @@ proc getBlindedBeaconBlock[T](
forkedBlock, executionPayloadHeader))
proc getBlindedBlockParts(
node: BeaconNode, head: BlockRef, validator: AttachedValidator,
node: BeaconNode, head: BlockRef, pubkey: ValidatorPubKey,
slot: Slot, randao: ValidatorSig, validator_index: ValidatorIndex):
Future[Result[(bellatrix.ExecutionPayloadHeader, ForkedBeaconBlock), string]]
{.async.} =
@ -636,7 +636,7 @@ proc getBlindedBlockParts(
try:
awaitWithTimeout(
node.getBlindedExecutionPayload(
slot, executionBlockRoot, validator.pubkey),
slot, executionBlockRoot, pubkey),
BUILDER_PROPOSAL_DELAY_TOLERANCE):
Result[bellatrix.ExecutionPayloadHeader, string].err(
"getBlindedExecutionPayload timed out")
@ -685,7 +685,7 @@ proc proposeBlockMEV(
randao: ValidatorSig, validator_index: ValidatorIndex):
Future[Opt[BlockRef]] {.async.} =
let blindedBlockParts = await getBlindedBlockParts(
node, head, validator, slot, randao, validator_index)
node, head, validator.pubkey, slot, randao, validator_index)
if blindedBlockParts.isErr:
# Not signed yet, fine to try to fall back on EL
beacon_block_builder_missed_with_fallback.inc()
@ -739,7 +739,7 @@ proc makeBlindedBeaconBlockForHeadAndSlot*(
## signed by a validator. A blinded block is a block with only a transactions
## root, rather than a full transactions list.
let
validator =
pubkey =
# Relevant state for knowledge of validators
withState(node.dag.headState):
if distinctBase(validator_index) >= forkyState.data.validators.lenu64:
@ -749,19 +749,10 @@ proc makeBlindedBeaconBlockForHeadAndSlot*(
validators_len = forkyState.data.validators.len
return err("Invalid validator index")
let pubkey = forkyState.data.validators.item(validator_index).pubkey
if pubkey notin node.attachedValidators.validators:
debug "makeBlindedBeaconBlockForHeadAndSlot: validator pubkey unknown",
head = shortLog(head),
validator_index,
validators_len = forkyState.data.validators.len,
pubkey = shortLog(pubkey)
return err("Validator pubkey unknown")
node.attachedValidators.validators[pubkey]
forkyState.data.validators.item(validator_index).pubkey
blindedBlockParts = await getBlindedBlockParts(
node, head, validator, slot, randao_reveal, validator_index)
node, head, pubkey, slot, randao_reveal, validator_index)
if blindedBlockParts.isErr:
# Don't try EL fallback -- VC specifically requested a blinded block
return err("Unable to create blinded block")

View File

@ -70,8 +70,9 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
var
cfg = defaultRuntimeConfig
cfg.ALTAIR_FORK_EPOCH = 32.Slot.epoch
cfg.BELLATRIX_FORK_EPOCH = 96.Slot.epoch
cfg.ALTAIR_FORK_EPOCH = 1.Epoch
cfg.BELLATRIX_FORK_EPOCH = 2.Epoch
cfg.CAPELLA_FORK_EPOCH = FAR_FUTURE_EPOCH
echo "Starting simulation..."