rm unused ForkedTrustedBeaconBlock; add some Electra overloads to consensus_object_pools; Electra BeaconBlock gossip support (#5965)
This commit is contained in:
parent
f65c1121d2
commit
fef831d92a
|
@ -483,7 +483,8 @@ func init(
|
|||
func init(
|
||||
T: type AttestationCache,
|
||||
state: altair.HashedBeaconState | bellatrix.HashedBeaconState |
|
||||
capella.HashedBeaconState | deneb.HashedBeaconState,
|
||||
capella.HashedBeaconState | deneb.HashedBeaconState |
|
||||
electra.HashedBeaconState,
|
||||
cache: var StateCache): T =
|
||||
# Load attestations that are scheduled for being given rewards for
|
||||
let
|
||||
|
|
|
@ -73,7 +73,8 @@ func init*(
|
|||
T: type BlockRef, root: Eth2Digest, executionValid: bool,
|
||||
blck: bellatrix.SomeBeaconBlock | bellatrix.TrustedBeaconBlock |
|
||||
capella.SomeBeaconBlock | capella.TrustedBeaconBlock |
|
||||
deneb.SomeBeaconBlock | deneb.TrustedBeaconBlock): BlockRef =
|
||||
deneb.SomeBeaconBlock | deneb.TrustedBeaconBlock |
|
||||
electra.SomeBeaconBlock | electra.TrustedBeaconBlock): BlockRef =
|
||||
BlockRef.init(
|
||||
root, Opt.some Eth2Digest(blck.body.execution_payload.block_hash),
|
||||
executionValid =
|
||||
|
|
|
@ -293,10 +293,11 @@ type
|
|||
OnBellatrixBlockAdded* = OnBlockAdded[bellatrix.TrustedSignedBeaconBlock]
|
||||
OnCapellaBlockAdded* = OnBlockAdded[capella.TrustedSignedBeaconBlock]
|
||||
OnDenebBlockAdded* = OnBlockAdded[deneb.TrustedSignedBeaconBlock]
|
||||
OnElectraBlockAdded* = OnBlockAdded[electra.TrustedSignedBeaconBlock]
|
||||
|
||||
OnForkyBlockAdded* =
|
||||
OnPhase0BlockAdded | OnAltairBlockAdded | OnBellatrixBlockAdded |
|
||||
OnCapellaBlockAdded | OnDenebBlockAdded
|
||||
OnCapellaBlockAdded | OnDenebBlockAdded | OnElectraBlockAdded
|
||||
|
||||
HeadChangeInfoObject* = object
|
||||
slot*: Slot
|
||||
|
|
|
@ -328,7 +328,7 @@ proc newExecutionPayload*(
|
|||
proc getExecutionValidity(
|
||||
elManager: ELManager,
|
||||
blck: bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock |
|
||||
deneb.SignedBeaconBlock):
|
||||
deneb.SignedBeaconBlock | electra.SignedBeaconBlock):
|
||||
Future[NewPayloadStatus] {.async: (raises: [CancelledError]).} =
|
||||
if not blck.message.is_execution_block:
|
||||
return NewPayloadStatus.valid # vacuously
|
||||
|
@ -361,9 +361,10 @@ proc getExecutionValidity(
|
|||
blck = shortLog(blck)
|
||||
return NewPayloadStatus.noResponse
|
||||
|
||||
proc checkBloblessSignature(self: BlockProcessor,
|
||||
signed_beacon_block: deneb.SignedBeaconBlock):
|
||||
Result[void, cstring] =
|
||||
proc checkBloblessSignature(
|
||||
self: BlockProcessor,
|
||||
signed_beacon_block: deneb.SignedBeaconBlock | electra.SignedBeaconBlock):
|
||||
Result[void, cstring] =
|
||||
let dag = self.consensusManager.dag
|
||||
let parent = dag.getBlockRef(signed_beacon_block.message.parent_root).valueOr:
|
||||
return err("checkBloblessSignature called with orphan block")
|
||||
|
|
|
@ -268,7 +268,8 @@ template validateBeaconBlockBellatrix(
|
|||
signed_beacon_block:
|
||||
bellatrix.SignedBeaconBlock |
|
||||
capella.SignedBeaconBlock |
|
||||
deneb.SignedBeaconBlock,
|
||||
deneb.SignedBeaconBlock |
|
||||
electra.SignedBeaconBlock,
|
||||
parent: BlockRef): untyped =
|
||||
# If the execution is enabled for the block -- i.e.
|
||||
# is_execution_enabled(state, block.body) then validate the following:
|
||||
|
|
|
@ -830,7 +830,7 @@ template gossipMaxSize(T: untyped): uint32 =
|
|||
when isFixedSize(T):
|
||||
fixedPortionSize(T).uint32
|
||||
elif T is bellatrix.SignedBeaconBlock or T is capella.SignedBeaconBlock or
|
||||
T is deneb.SignedBeaconBlock:
|
||||
T is deneb.SignedBeaconBlock or T is electra.SignedBeaconBlock:
|
||||
GOSSIP_MAX_SIZE
|
||||
# TODO https://github.com/status-im/nim-ssz-serialization/issues/20 for
|
||||
# Attestation, AttesterSlashing, and SignedAggregateAndProof, which all
|
||||
|
@ -2637,6 +2637,12 @@ proc broadcastBeaconBlock*(
|
|||
let topic = getBeaconBlocksTopic(node.forkDigests.deneb)
|
||||
node.broadcast(topic, blck)
|
||||
|
||||
proc broadcastBeaconBlock*(
|
||||
node: Eth2Node, blck: electra.SignedBeaconBlock):
|
||||
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
|
||||
let topic = getBeaconBlocksTopic(node.forkDigests.electra)
|
||||
node.broadcast(topic, blck)
|
||||
|
||||
proc broadcastBlobSidecar*(
|
||||
node: Eth2Node, subnet_id: BlobId, blob: deneb.BlobSidecar):
|
||||
Future[SendResult] {.async: (raises: [CancelledError], raw: true).} =
|
||||
|
|
|
@ -275,6 +275,7 @@ when const_preset == "gnosis":
|
|||
doAssert network.cfg.BELLATRIX_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.CAPELLA_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
|
||||
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
|
||||
|
||||
elif const_preset == "mainnet":
|
||||
|
@ -340,6 +341,7 @@ elif const_preset == "mainnet":
|
|||
doAssert network.cfg.BELLATRIX_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.CAPELLA_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.DENEB_FORK_EPOCH < FAR_FUTURE_EPOCH
|
||||
doAssert network.cfg.ELECTRA_FORK_EPOCH == FAR_FUTURE_EPOCH
|
||||
static: doAssert ConsensusFork.high == ConsensusFork.Deneb
|
||||
|
||||
proc getMetadataForNetwork*(networkName: string): Eth2NetworkMetadata =
|
||||
|
|
|
@ -84,8 +84,8 @@ func get_validator_churn_limit*(
|
|||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/deneb/beacon-chain.md#new-get_validator_activation_churn_limit
|
||||
func get_validator_activation_churn_limit*(
|
||||
cfg: RuntimeConfig, state: deneb.BeaconState, cache: var StateCache):
|
||||
uint64 =
|
||||
cfg: RuntimeConfig, state: deneb.BeaconState | electra.BeaconState,
|
||||
cache: var StateCache): uint64 =
|
||||
## Return the validator activation churn limit for the current epoch.
|
||||
min(
|
||||
cfg.MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT,
|
||||
|
@ -154,7 +154,7 @@ func get_slashing_penalty*(state: ForkyBeaconState,
|
|||
elif state is altair.BeaconState:
|
||||
validator_effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR
|
||||
elif state is bellatrix.BeaconState or state is capella.BeaconState or
|
||||
state is deneb.BeaconState:
|
||||
state is deneb.BeaconState or state is electra.BeaconState:
|
||||
validator_effective_balance div MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX
|
||||
else:
|
||||
{.fatal: "invalid BeaconState type".}
|
||||
|
@ -172,7 +172,8 @@ func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): G
|
|||
when state is phase0.BeaconState:
|
||||
whistleblower_reward div PROPOSER_REWARD_QUOTIENT
|
||||
elif state is altair.BeaconState or state is bellatrix.BeaconState or
|
||||
state is capella.BeaconState or state is deneb.BeaconState:
|
||||
state is capella.BeaconState or state is deneb.BeaconState or
|
||||
state is electra.BeaconState:
|
||||
whistleblower_reward * PROPOSER_WEIGHT div WEIGHT_DENOMINATOR
|
||||
else:
|
||||
{.fatal: "invalid BeaconState type".}
|
||||
|
@ -292,6 +293,20 @@ func get_initial_beacon_block*(state: deneb.HashedBeaconState):
|
|||
deneb.TrustedSignedBeaconBlock(
|
||||
message: message, root: hash_tree_root(message))
|
||||
|
||||
from ./datatypes/electra import HashedBeaconState, TrustedSignedBeaconBlock
|
||||
|
||||
# TODO spec link here when it exists
|
||||
func get_initial_beacon_block*(state: electra.HashedBeaconState):
|
||||
electra.TrustedSignedBeaconBlock =
|
||||
# The genesis block is implicitly trusted
|
||||
let message = electra.TrustedBeaconBlock(
|
||||
slot: state.data.slot,
|
||||
state_root: state.root)
|
||||
# parent_root, randao_reveal, eth1_data, signature, and body automatically
|
||||
# initialized to default values.
|
||||
electra.TrustedSignedBeaconBlock(
|
||||
message: message, root: hash_tree_root(message))
|
||||
|
||||
func get_initial_beacon_block*(state: ForkedHashedBeaconState):
|
||||
ForkedTrustedSignedBeaconBlock =
|
||||
withState(state):
|
||||
|
@ -549,7 +564,7 @@ func get_attestation_participation_flag_indices(
|
|||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/deneb/beacon-chain.md#modified-get_attestation_participation_flag_indices
|
||||
func get_attestation_participation_flag_indices(
|
||||
state: deneb.BeaconState,
|
||||
state: deneb.BeaconState | electra.BeaconState,
|
||||
data: AttestationData, inclusion_delay: uint64): set[TimelyFlag] =
|
||||
## Return the flag indices that are satisfied by an attestation.
|
||||
let justified_checkpoint =
|
||||
|
@ -613,7 +628,7 @@ func get_base_reward_per_increment*(
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/altair/beacon-chain.md#get_base_reward
|
||||
func get_base_reward(
|
||||
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
|
||||
deneb.BeaconState,
|
||||
deneb.BeaconState | electra.BeaconState,
|
||||
index: ValidatorIndex, base_reward_per_increment: Gwei): Gwei =
|
||||
## Return the base reward for the validator defined by ``index`` with respect
|
||||
## to the current ``state``.
|
||||
|
@ -658,7 +673,8 @@ proc check_attestation*(
|
|||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
|
||||
proc check_bls_to_execution_change*(
|
||||
genesisFork: Fork, state: capella.BeaconState | deneb.BeaconState,
|
||||
genesisFork: Fork,
|
||||
state: capella.BeaconState | deneb.BeaconState | electra.BeaconState,
|
||||
signed_address_change: SignedBLSToExecutionChange, flags: UpdateFlags):
|
||||
Result[void, cstring] =
|
||||
let address_change = signed_address_change.message
|
||||
|
@ -746,7 +762,8 @@ proc process_attestation*(
|
|||
else:
|
||||
addPendingAttestation(state.previous_epoch_attestations)
|
||||
elif state is altair.BeaconState or state is bellatrix.BeaconState or
|
||||
state is capella.BeaconState or state is deneb.BeaconState:
|
||||
state is capella.BeaconState or state is deneb.BeaconState or
|
||||
state is electra.BeaconState:
|
||||
template updateParticipationFlags(epoch_participation: untyped) =
|
||||
let proposer_reward = get_proposer_reward(
|
||||
state, attestation, base_reward_per_increment, cache, epoch_participation)
|
||||
|
@ -765,7 +782,7 @@ proc process_attestation*(
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/altair/beacon-chain.md#get_next_sync_committee_indices
|
||||
func get_next_sync_committee_keys(
|
||||
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
|
||||
deneb.BeaconState):
|
||||
deneb.BeaconState | electra.BeaconState):
|
||||
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
|
||||
## Return the sequence of sync committee indices, with possible duplicates,
|
||||
## for the next sync committee.
|
||||
|
@ -825,7 +842,8 @@ func is_partially_withdrawable_validator(
|
|||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/capella/beacon-chain.md#new-get_expected_withdrawals
|
||||
func get_expected_withdrawals*(
|
||||
state: capella.BeaconState | deneb.BeaconState): seq[Withdrawal] =
|
||||
state: capella.BeaconState | deneb.BeaconState | electra.BeaconState):
|
||||
seq[Withdrawal] =
|
||||
let
|
||||
epoch = get_current_epoch(state)
|
||||
num_validators = lenu64(state.validators)
|
||||
|
@ -862,7 +880,7 @@ func get_expected_withdrawals*(
|
|||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.7/specs/altair/beacon-chain.md#get_next_sync_committee
|
||||
func get_next_sync_committee*(
|
||||
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
|
||||
deneb.BeaconState):
|
||||
deneb.BeaconState | electra.BeaconState):
|
||||
SyncCommittee =
|
||||
## Return the next sync committee, with possible pubkey duplicates.
|
||||
var res: SyncCommittee
|
||||
|
@ -1436,7 +1454,7 @@ func latest_block_root*(state: ForkedHashedBeaconState): Eth2Digest =
|
|||
|
||||
func get_sync_committee_cache*(
|
||||
state: altair.BeaconState | bellatrix.BeaconState | capella.BeaconState |
|
||||
deneb.BeaconState,
|
||||
deneb.BeaconState | electra.BeaconState,
|
||||
cache: var StateCache): SyncCommitteeCache =
|
||||
let period = state.slot.sync_committee_period()
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import
|
|||
std/[json, tables],
|
||||
stew/base10, web3/primitives, httputils,
|
||||
".."/forks,
|
||||
".."/datatypes/[phase0, altair, bellatrix, deneb],
|
||||
".."/datatypes/[phase0, altair, bellatrix, deneb, electra],
|
||||
".."/mev/[capella_mev, deneb_mev]
|
||||
|
||||
from ".."/datatypes/capella import BeaconBlockBody
|
||||
|
@ -331,6 +331,11 @@ type
|
|||
kzg_proofs*: deneb.KzgProofs
|
||||
blobs*: deneb.Blobs
|
||||
|
||||
ElectraSignedBlockContents* = object
|
||||
signed_block*: electra.SignedBeaconBlock
|
||||
kzg_proofs*: deneb.KzgProofs
|
||||
blobs*: deneb.Blobs
|
||||
|
||||
RestPublishedSignedBlockContents* = object
|
||||
case kind*: ConsensusFork
|
||||
of ConsensusFork.Phase0: phase0Data*: phase0.SignedBeaconBlock
|
||||
|
@ -689,6 +694,12 @@ func init*(t: typedesc[RestPublishedSignedBlockContents],
|
|||
)
|
||||
)
|
||||
|
||||
func init*(t: typedesc[RestPublishedSignedBlockContents],
|
||||
contents: electra.BeaconBlock, root: Eth2Digest,
|
||||
signature: ValidatorSig): RestPublishedSignedBlockContents =
|
||||
debugRaiseAssert "init*(t: typedesc[RestPublishedSignedBlockContents],"
|
||||
default(RestPublishedSignedBlockContents)
|
||||
|
||||
func init*(t: typedesc[StateIdent], v: StateIdentType): StateIdent =
|
||||
StateIdent(kind: StateQueryKind.Named, value: v)
|
||||
|
||||
|
|
|
@ -186,14 +186,6 @@ type
|
|||
of ConsensusFork.Capella: capellaData*: capella_mev.BlindedBeaconBlock
|
||||
of ConsensusFork.Deneb: denebData*: deneb_mev.BlindedBeaconBlock
|
||||
|
||||
ForkedTrustedBeaconBlock* = object
|
||||
case kind*: ConsensusFork
|
||||
of ConsensusFork.Phase0: phase0Data*: phase0.TrustedBeaconBlock
|
||||
of ConsensusFork.Altair: altairData*: altair.TrustedBeaconBlock
|
||||
of ConsensusFork.Bellatrix: bellatrixData*: bellatrix.TrustedBeaconBlock
|
||||
of ConsensusFork.Capella: capellaData*: capella.TrustedBeaconBlock
|
||||
of ConsensusFork.Deneb: denebData*: deneb.TrustedBeaconBlock
|
||||
|
||||
ForkySignedBeaconBlock* =
|
||||
phase0.SignedBeaconBlock |
|
||||
altair.SignedBeaconBlock |
|
||||
|
@ -604,15 +596,6 @@ template init*(T: type ForkedBeaconBlock, blck: capella.BeaconBlock): T =
|
|||
template init*(T: type ForkedBeaconBlock, blck: deneb.BeaconBlock): T =
|
||||
T(kind: ConsensusFork.Deneb, denebData: blck)
|
||||
|
||||
template init*(T: type ForkedTrustedBeaconBlock, blck: phase0.TrustedBeaconBlock): T =
|
||||
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
||||
template init*(T: type ForkedTrustedBeaconBlock, blck: altair.TrustedBeaconBlock): T =
|
||||
T(kind: ConsensusFork.Altair, altairData: blck)
|
||||
template init*(T: type ForkedTrustedBeaconBlock, blck: bellatrix.TrustedBeaconBlock): T =
|
||||
T(kind: ConsensusFork.Bellatrix, bellatrixData: blck)
|
||||
template init*(T: type ForkedTrustedBeaconBlock, blck: capella.TrustedBeaconBlock): T =
|
||||
T(kind: ConsensusFork.Capella, capellaData: blck)
|
||||
|
||||
template init*(T: type ForkedSignedBeaconBlock, blck: phase0.SignedBeaconBlock): T =
|
||||
T(kind: ConsensusFork.Phase0, phase0Data: blck)
|
||||
template init*(T: type ForkedSignedBeaconBlock, blck: altair.SignedBeaconBlock): T =
|
||||
|
|
Loading…
Reference in New Issue