collapse `partialBeaconBlock` templates into one (#5386)
Have a single `Forky` template for `partialBeaconBlock` production rather than have several copies that are mostly identical.
This commit is contained in:
parent
0987628c0b
commit
dbb1a63ca9
|
@ -254,6 +254,31 @@ type
|
||||||
capella*: ForkDigest
|
capella*: ForkDigest
|
||||||
deneb*: ForkDigest
|
deneb*: ForkDigest
|
||||||
|
|
||||||
|
template kind*(
|
||||||
|
x: typedesc[
|
||||||
|
phase0.HashedBeaconState]): ConsensusFork =
|
||||||
|
ConsensusFork.Phase0
|
||||||
|
|
||||||
|
template kind*(
|
||||||
|
x: typedesc[
|
||||||
|
altair.HashedBeaconState]): ConsensusFork =
|
||||||
|
ConsensusFork.Altair
|
||||||
|
|
||||||
|
template kind*(
|
||||||
|
x: typedesc[
|
||||||
|
bellatrix.HashedBeaconState]): ConsensusFork =
|
||||||
|
ConsensusFork.Bellatrix
|
||||||
|
|
||||||
|
template kind*(
|
||||||
|
x: typedesc[
|
||||||
|
capella.HashedBeaconState]): ConsensusFork =
|
||||||
|
ConsensusFork.Capella
|
||||||
|
|
||||||
|
template kind*(
|
||||||
|
x: typedesc[
|
||||||
|
deneb.HashedBeaconState]): ConsensusFork =
|
||||||
|
ConsensusFork.Deneb
|
||||||
|
|
||||||
macro getSymbolFromForkModule(fork: static ConsensusFork,
|
macro getSymbolFromForkModule(fork: static ConsensusFork,
|
||||||
symbolName: static string): untyped =
|
symbolName: static string): untyped =
|
||||||
let moduleName = case fork
|
let moduleName = case fork
|
||||||
|
|
|
@ -335,10 +335,9 @@ proc state_transition*(
|
||||||
state_transition_block(
|
state_transition_block(
|
||||||
cfg, state, signedBlock, cache, flags, rollback)
|
cfg, state, signedBlock, cache, flags, rollback)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/validator.md#preparing-for-a-beaconblock
|
|
||||||
template partialBeaconBlock*(
|
template partialBeaconBlock*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var phase0.HashedBeaconState,
|
state: var ForkyHashedBeaconState,
|
||||||
proposer_index: ValidatorIndex,
|
proposer_index: ValidatorIndex,
|
||||||
randao_reveal: ValidatorSig,
|
randao_reveal: ValidatorSig,
|
||||||
eth1_data: Eth1Data,
|
eth1_data: Eth1Data,
|
||||||
|
@ -347,13 +346,16 @@ template partialBeaconBlock*(
|
||||||
deposits: seq[Deposit],
|
deposits: seq[Deposit],
|
||||||
validator_changes: BeaconBlockValidatorChanges,
|
validator_changes: BeaconBlockValidatorChanges,
|
||||||
sync_aggregate: SyncAggregate,
|
sync_aggregate: SyncAggregate,
|
||||||
execution_payload: bellatrix.ExecutionPayloadForSigning):
|
execution_payload: ForkyExecutionPayloadForSigning
|
||||||
phase0.BeaconBlock =
|
): auto =
|
||||||
phase0.BeaconBlock(
|
const consensusFork = typeof(state).kind
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/validator.md#preparing-for-a-beaconblock
|
||||||
|
var res = consensusFork.BeaconBlockType(
|
||||||
slot: state.data.slot,
|
slot: state.data.slot,
|
||||||
proposer_index: proposer_index.uint64,
|
proposer_index: proposer_index.uint64,
|
||||||
parent_root: state.latest_block_root,
|
parent_root: state.latest_block_root,
|
||||||
body: phase0.BeaconBlockBody(
|
body: consensusFork.BeaconBlockBodyType(
|
||||||
randao_reveal: randao_reveal,
|
randao_reveal: randao_reveal,
|
||||||
eth1_data: eth1data,
|
eth1_data: eth1data,
|
||||||
graffiti: graffiti,
|
graffiti: graffiti,
|
||||||
|
@ -363,127 +365,24 @@ template partialBeaconBlock*(
|
||||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
||||||
voluntary_exits: validator_changes.voluntary_exits))
|
voluntary_exits: validator_changes.voluntary_exits))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/validator.md#preparing-a-beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/validator.md#preparing-a-beaconblock
|
||||||
template partialBeaconBlock*(
|
when consensusFork >= ConsensusFork.Altair:
|
||||||
cfg: RuntimeConfig,
|
res.body.sync_aggregate = sync_aggregate
|
||||||
state: var altair.HashedBeaconState,
|
|
||||||
proposer_index: ValidatorIndex,
|
|
||||||
randao_reveal: ValidatorSig,
|
|
||||||
eth1_data: Eth1Data,
|
|
||||||
graffiti: GraffitiBytes,
|
|
||||||
attestations: seq[Attestation],
|
|
||||||
deposits: seq[Deposit],
|
|
||||||
validator_changes: BeaconBlockValidatorChanges,
|
|
||||||
sync_aggregate: SyncAggregate,
|
|
||||||
execution_payload: bellatrix.ExecutionPayloadForSigning):
|
|
||||||
altair.BeaconBlock =
|
|
||||||
altair.BeaconBlock(
|
|
||||||
slot: state.data.slot,
|
|
||||||
proposer_index: proposer_index.uint64,
|
|
||||||
parent_root: state.latest_block_root,
|
|
||||||
body: altair.BeaconBlockBody(
|
|
||||||
randao_reveal: randao_reveal,
|
|
||||||
eth1_data: eth1data,
|
|
||||||
graffiti: graffiti,
|
|
||||||
proposer_slashings: validator_changes.proposer_slashings,
|
|
||||||
attester_slashings: validator_changes.attester_slashings,
|
|
||||||
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
||||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
||||||
voluntary_exits: validator_changes.voluntary_exits,
|
|
||||||
sync_aggregate: sync_aggregate))
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/validator.md#block-proposal
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/validator.md#block-proposal
|
||||||
template partialBeaconBlock*(
|
when consensusFork >= ConsensusFork.Bellatrix:
|
||||||
cfg: RuntimeConfig,
|
res.body.execution_payload = execution_payload.executionPayload
|
||||||
state: var bellatrix.HashedBeaconState,
|
|
||||||
proposer_index: ValidatorIndex,
|
|
||||||
randao_reveal: ValidatorSig,
|
|
||||||
eth1_data: Eth1Data,
|
|
||||||
graffiti: GraffitiBytes,
|
|
||||||
attestations: seq[Attestation],
|
|
||||||
deposits: seq[Deposit],
|
|
||||||
validator_changes: BeaconBlockValidatorChanges,
|
|
||||||
sync_aggregate: SyncAggregate,
|
|
||||||
execution_payload: bellatrix.ExecutionPayloadForSigning):
|
|
||||||
bellatrix.BeaconBlock =
|
|
||||||
bellatrix.BeaconBlock(
|
|
||||||
slot: state.data.slot,
|
|
||||||
proposer_index: proposer_index.uint64,
|
|
||||||
parent_root: state.latest_block_root,
|
|
||||||
body: bellatrix.BeaconBlockBody(
|
|
||||||
randao_reveal: randao_reveal,
|
|
||||||
eth1_data: eth1data,
|
|
||||||
graffiti: graffiti,
|
|
||||||
proposer_slashings: validator_changes.proposer_slashings,
|
|
||||||
attester_slashings: validator_changes.attester_slashings,
|
|
||||||
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
||||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
||||||
voluntary_exits: validator_changes.voluntary_exits,
|
|
||||||
sync_aggregate: sync_aggregate,
|
|
||||||
execution_payload: execution_payload.executionPayload))
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/capella/validator.md#block-proposal
|
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/capella/validator.md#block-proposal
|
||||||
template partialBeaconBlock*(
|
when consensusFork >= ConsensusFork.Capella:
|
||||||
cfg: RuntimeConfig,
|
res.body.bls_to_execution_changes =
|
||||||
state: var capella.HashedBeaconState,
|
validator_changes.bls_to_execution_changes
|
||||||
proposer_index: ValidatorIndex,
|
|
||||||
randao_reveal: ValidatorSig,
|
|
||||||
eth1_data: Eth1Data,
|
|
||||||
graffiti: GraffitiBytes,
|
|
||||||
attestations: seq[Attestation],
|
|
||||||
deposits: seq[Deposit],
|
|
||||||
validator_changes: BeaconBlockValidatorChanges,
|
|
||||||
sync_aggregate: SyncAggregate,
|
|
||||||
execution_payload: capella.ExecutionPayloadForSigning):
|
|
||||||
capella.BeaconBlock =
|
|
||||||
capella.BeaconBlock(
|
|
||||||
slot: state.data.slot,
|
|
||||||
proposer_index: proposer_index.uint64,
|
|
||||||
parent_root: state.latest_block_root,
|
|
||||||
body: capella.BeaconBlockBody(
|
|
||||||
randao_reveal: randao_reveal,
|
|
||||||
eth1_data: eth1data,
|
|
||||||
graffiti: graffiti,
|
|
||||||
proposer_slashings: validator_changes.proposer_slashings,
|
|
||||||
attester_slashings: validator_changes.attester_slashings,
|
|
||||||
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
||||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
||||||
voluntary_exits: validator_changes.voluntary_exits,
|
|
||||||
sync_aggregate: sync_aggregate,
|
|
||||||
execution_payload: execution_payload.executionPayload,
|
|
||||||
bls_to_execution_changes: validator_changes.bls_to_execution_changes))
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/validator.md#constructing-the-beaconblockbody
|
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/deneb/validator.md#constructing-the-beaconblockbody
|
||||||
template partialBeaconBlock*(
|
when consensusFork >= ConsensusFork.Deneb:
|
||||||
cfg: RuntimeConfig,
|
res.body.blob_kzg_commitments = execution_payload.kzgs
|
||||||
state: var deneb.HashedBeaconState,
|
|
||||||
proposer_index: ValidatorIndex,
|
res
|
||||||
randao_reveal: ValidatorSig,
|
|
||||||
eth1_data: Eth1Data,
|
|
||||||
graffiti: GraffitiBytes,
|
|
||||||
attestations: seq[Attestation],
|
|
||||||
deposits: seq[Deposit],
|
|
||||||
validator_changes: BeaconBlockValidatorChanges,
|
|
||||||
sync_aggregate: SyncAggregate,
|
|
||||||
execution_payload: deneb.ExecutionPayloadForSigning):
|
|
||||||
deneb.BeaconBlock =
|
|
||||||
deneb.BeaconBlock(
|
|
||||||
slot: state.data.slot,
|
|
||||||
proposer_index: proposer_index.uint64,
|
|
||||||
parent_root: state.latest_block_root,
|
|
||||||
body: deneb.BeaconBlockBody(
|
|
||||||
randao_reveal: randao_reveal,
|
|
||||||
eth1_data: eth1data,
|
|
||||||
graffiti: graffiti,
|
|
||||||
proposer_slashings: validator_changes.proposer_slashings,
|
|
||||||
attester_slashings: validator_changes.attester_slashings,
|
|
||||||
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
|
||||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits),
|
|
||||||
voluntary_exits: validator_changes.voluntary_exits,
|
|
||||||
sync_aggregate: sync_aggregate,
|
|
||||||
execution_payload: execution_payload.executionPayload,
|
|
||||||
bls_to_execution_changes: validator_changes.bls_to_execution_changes,
|
|
||||||
blob_kzg_commitments: execution_payload.kzgs))
|
|
||||||
|
|
||||||
proc makeBeaconBlock*(
|
proc makeBeaconBlock*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
|
|
Loading…
Reference in New Issue