update from phase0/altair v1.1.6 URLs to v1.1.8 spec URLs (#3238)
This commit is contained in:
parent
c4ce59e55b
commit
da017d2ca5
|
@ -15,7 +15,7 @@ import
|
||||||
./spec/[eth2_ssz_serialization, eth2_merkleization]
|
./spec/[eth2_ssz_serialization, eth2_merkleization]
|
||||||
|
|
||||||
type
|
type
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconstate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconstate
|
||||||
# Memory-representation-equivalent to a phase0 BeaconState for in-place SSZ reading and writing
|
# Memory-representation-equivalent to a phase0 BeaconState for in-place SSZ reading and writing
|
||||||
Phase0BeaconStateNoImmutableValidators* = object
|
Phase0BeaconStateNoImmutableValidators* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
|
@ -69,7 +69,7 @@ type
|
||||||
current_justified_checkpoint*: Checkpoint
|
current_justified_checkpoint*: Checkpoint
|
||||||
finalized_checkpoint*: Checkpoint
|
finalized_checkpoint*: Checkpoint
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#beaconstate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#beaconstate
|
||||||
# Memory-representation-equivalent to an Altair BeaconState for in-place SSZ
|
# Memory-representation-equivalent to an Altair BeaconState for in-place SSZ
|
||||||
# reading and writing
|
# reading and writing
|
||||||
AltairBeaconStateNoImmutableValidators* = object
|
AltairBeaconStateNoImmutableValidators* = object
|
||||||
|
|
|
@ -26,7 +26,7 @@ type
|
||||||
## which blocks are valid - in particular, blocks are not valid if they
|
## which blocks are valid - in particular, blocks are not valid if they
|
||||||
## come from the future as seen from the local clock.
|
## come from the future as seen from the local clock.
|
||||||
##
|
##
|
||||||
## https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/fork-choice.md#fork-choice
|
## https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/fork-choice.md#fork-choice
|
||||||
##
|
##
|
||||||
# TODO consider NTP and network-adjusted timestamps as outlined here:
|
# TODO consider NTP and network-adjusted timestamps as outlined here:
|
||||||
# https://ethresear.ch/t/network-adjusted-timestamps/4187
|
# https://ethresear.ch/t/network-adjusted-timestamps/4187
|
||||||
|
@ -39,15 +39,15 @@ type
|
||||||
const
|
const
|
||||||
# Offsets from the start of the slot to when the corresponding message should
|
# Offsets from the start of the slot to when the corresponding message should
|
||||||
# be sent
|
# be sent
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#attesting
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#attesting
|
||||||
attestationSlotOffset* = seconds(SECONDS_PER_SLOT.int) div INTERVALS_PER_SLOT
|
attestationSlotOffset* = seconds(SECONDS_PER_SLOT.int) div INTERVALS_PER_SLOT
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#broadcast-aggregate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-aggregate
|
||||||
aggregateSlotOffset* =
|
aggregateSlotOffset* =
|
||||||
seconds(SECONDS_PER_SLOT.int) * 2 div INTERVALS_PER_SLOT
|
seconds(SECONDS_PER_SLOT.int) * 2 div INTERVALS_PER_SLOT
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#prepare-sync-committee-message
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#prepare-sync-committee-message
|
||||||
syncCommitteeMessageSlotOffset* =
|
syncCommitteeMessageSlotOffset* =
|
||||||
seconds(SECONDS_PER_SLOT.int) div INTERVALS_PER_SLOT
|
seconds(SECONDS_PER_SLOT.int) div INTERVALS_PER_SLOT
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#broadcast-sync-committee-contribution
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#broadcast-sync-committee-contribution
|
||||||
syncContributionSlotOffset* =
|
syncContributionSlotOffset* =
|
||||||
seconds(SECONDS_PER_SLOT.int) * 2 div INTERVALS_PER_SLOT
|
seconds(SECONDS_PER_SLOT.int) * 2 div INTERVALS_PER_SLOT
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ This folder holds the various consensus object pools needed for a blockchain cli
|
||||||
|
|
||||||
Object in those pools have passed the "gossip validation" filter according
|
Object in those pools have passed the "gossip validation" filter according
|
||||||
to specs:
|
to specs:
|
||||||
- blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_block
|
- blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_block
|
||||||
- aggregate attestations: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
- aggregate attestations: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||||
- unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
- unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||||
- voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#voluntary_exit
|
- voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#voluntary_exit
|
||||||
- Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attester_slashing
|
- Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attester_slashing
|
||||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#proposer_slashing
|
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#proposer_slashing
|
||||||
|
|
||||||
After "gossip validation" the consensus objects can be rebroadcasted as they are optimistically good, however for internal processing further verification is needed.
|
After "gossip validation" the consensus objects can be rebroadcasted as they are optimistically good, however for internal processing further verification is needed.
|
||||||
For blocks, this means verifying state transition and all contained cryptographic signatures (instead of just the proposer signature).
|
For blocks, this means verifying state transition and all contained cryptographic signatures (instead of just the proposer signature).
|
||||||
|
|
|
@ -691,7 +691,7 @@ proc getAggregatedAttestation*(pool: var AttestationPool,
|
||||||
index: CommitteeIndex): Option[Attestation] =
|
index: CommitteeIndex): Option[Attestation] =
|
||||||
## Select the attestation that has the most votes going for it in the given
|
## Select the attestation that has the most votes going for it in the given
|
||||||
## slot/index
|
## slot/index
|
||||||
## https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#construct-aggregate
|
## https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#construct-aggregate
|
||||||
let
|
let
|
||||||
candidateIdx = pool.candidateIdx(slot)
|
candidateIdx = pool.candidateIdx(slot)
|
||||||
if candidateIdx.isNone:
|
if candidateIdx.isNone:
|
||||||
|
|
|
@ -130,7 +130,7 @@ func link*(parent, child: BlockRef) =
|
||||||
func get_ancestor*(blck: BlockRef, slot: Slot,
|
func get_ancestor*(blck: BlockRef, slot: Slot,
|
||||||
maxDepth = 100'i64 * 365 * 24 * 60 * 60 div SECONDS_PER_SLOT.int):
|
maxDepth = 100'i64 * 365 * 24 * 60 * 60 div SECONDS_PER_SLOT.int):
|
||||||
BlockRef =
|
BlockRef =
|
||||||
## https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/fork-choice.md#get_ancestor
|
## https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/fork-choice.md#get_ancestor
|
||||||
## Return the most recent block as of the time at `slot` that not more recent
|
## Return the most recent block as of the time at `slot` that not more recent
|
||||||
## than `blck` itself
|
## than `blck` itself
|
||||||
if isNil(blck): return nil
|
if isNil(blck): return nil
|
||||||
|
|
|
@ -22,7 +22,7 @@ export
|
||||||
func count_active_validators*(epochInfo: EpochRef): uint64 =
|
func count_active_validators*(epochInfo: EpochRef): uint64 =
|
||||||
epochInfo.shuffled_active_validator_indices.lenu64
|
epochInfo.shuffled_active_validator_indices.lenu64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||||
func get_committee_count_per_slot*(epochInfo: EpochRef): uint64 =
|
func get_committee_count_per_slot*(epochInfo: EpochRef): uint64 =
|
||||||
get_committee_count_per_slot(count_active_validators(epochInfo))
|
get_committee_count_per_slot(count_active_validators(epochInfo))
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ iterator get_committee_indices*(epochRef: EpochRef): CommitteeIndex =
|
||||||
for i in 0'u64..<get_committee_count_per_slot(epochRef):
|
for i in 0'u64..<get_committee_count_per_slot(epochRef):
|
||||||
yield CommitteeIndex(i)
|
yield CommitteeIndex(i)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||||
iterator get_beacon_committee*(
|
iterator get_beacon_committee*(
|
||||||
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): ValidatorIndex =
|
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): ValidatorIndex =
|
||||||
## Return the beacon committee at ``slot`` for ``index``.
|
## Return the beacon committee at ``slot`` for ``index``.
|
||||||
|
@ -43,7 +43,7 @@ iterator get_beacon_committee*(
|
||||||
committees_per_slot * SLOTS_PER_EPOCH
|
committees_per_slot * SLOTS_PER_EPOCH
|
||||||
): yield idx
|
): yield idx
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||||
func get_beacon_committee*(
|
func get_beacon_committee*(
|
||||||
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): seq[ValidatorIndex] =
|
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): seq[ValidatorIndex] =
|
||||||
## Return the beacon committee at ``slot`` for ``index``.
|
## Return the beacon committee at ``slot`` for ``index``.
|
||||||
|
@ -56,7 +56,7 @@ func get_beacon_committee*(
|
||||||
committees_per_slot * SLOTS_PER_EPOCH
|
committees_per_slot * SLOTS_PER_EPOCH
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||||
func get_beacon_committee_len*(
|
func get_beacon_committee_len*(
|
||||||
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): uint64 =
|
epochRef: EpochRef, slot: Slot, index: CommitteeIndex): uint64 =
|
||||||
## Return the number of members in the beacon committee at ``slot`` for ``index``.
|
## Return the number of members in the beacon committee at ``slot`` for ``index``.
|
||||||
|
@ -70,7 +70,7 @@ func get_beacon_committee_len*(
|
||||||
committees_per_slot * SLOTS_PER_EPOCH
|
committees_per_slot * SLOTS_PER_EPOCH
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_attesting_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||||
iterator get_attesting_indices*(epochRef: EpochRef,
|
iterator get_attesting_indices*(epochRef: EpochRef,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits):
|
bits: CommitteeValidatorsBits):
|
||||||
|
@ -105,7 +105,7 @@ func get_attesting_indices_one*(epochRef: EpochRef,
|
||||||
inc i
|
inc i
|
||||||
res
|
res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_attesting_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||||
func get_attesting_indices*(epochRef: EpochRef,
|
func get_attesting_indices*(epochRef: EpochRef,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits):
|
bits: CommitteeValidatorsBits):
|
||||||
|
@ -114,7 +114,7 @@ func get_attesting_indices*(epochRef: EpochRef,
|
||||||
for idx in get_attesting_indices(epochRef, data, bits):
|
for idx in get_attesting_indices(epochRef, data, bits):
|
||||||
result.add(idx)
|
result.add(idx)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||||
proc is_valid_indexed_attestation*(
|
proc is_valid_indexed_attestation*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
epochRef: EpochRef,
|
epochRef: EpochRef,
|
||||||
|
@ -159,7 +159,7 @@ func makeAttestationData*(
|
||||||
|
|
||||||
doAssert current_epoch == epochRef.epoch
|
doAssert current_epoch == epochRef.epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#attestation-data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#attestation-data
|
||||||
AttestationData(
|
AttestationData(
|
||||||
slot: slot,
|
slot: slot,
|
||||||
index: committee_index.uint64,
|
index: committee_index.uint64,
|
||||||
|
@ -171,7 +171,7 @@ func makeAttestationData*(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#validator-assignments
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#validator-assignments
|
||||||
iterator get_committee_assignments*(
|
iterator get_committee_assignments*(
|
||||||
epochRef: EpochRef, validator_indices: HashSet[ValidatorIndex]):
|
epochRef: EpochRef, validator_indices: HashSet[ValidatorIndex]):
|
||||||
tuple[subcommitteeIdx: CommitteeIndex,
|
tuple[subcommitteeIdx: CommitteeIndex,
|
||||||
|
|
|
@ -298,11 +298,11 @@ template toGaugeValue(x: Quantity): int64 =
|
||||||
# doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY,
|
# doAssert SECONDS_PER_ETH1_BLOCK * cfg.ETH1_FOLLOW_DISTANCE < GENESIS_DELAY,
|
||||||
# "Invalid configuration: GENESIS_DELAY is set too low"
|
# "Invalid configuration: GENESIS_DELAY is set too low"
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#get_eth1_data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#get_eth1_data
|
||||||
func compute_time_at_slot(genesis_time: uint64, slot: Slot): uint64 =
|
func compute_time_at_slot(genesis_time: uint64, slot: Slot): uint64 =
|
||||||
genesis_time + slot * SECONDS_PER_SLOT
|
genesis_time + slot * SECONDS_PER_SLOT
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#get_eth1_data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#get_eth1_data
|
||||||
func voting_period_start_time(state: ForkedHashedBeaconState): uint64 =
|
func voting_period_start_time(state: ForkedHashedBeaconState): uint64 =
|
||||||
let eth1_voting_period_start_slot =
|
let eth1_voting_period_start_slot =
|
||||||
getStateField(state, slot) - getStateField(state, slot) mod
|
getStateField(state, slot) - getStateField(state, slot) mod
|
||||||
|
@ -310,7 +310,7 @@ func voting_period_start_time(state: ForkedHashedBeaconState): uint64 =
|
||||||
compute_time_at_slot(
|
compute_time_at_slot(
|
||||||
getStateField(state, genesis_time), eth1_voting_period_start_slot)
|
getStateField(state, genesis_time), eth1_voting_period_start_slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#get_eth1_data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#get_eth1_data
|
||||||
func is_candidate_block(cfg: RuntimeConfig,
|
func is_candidate_block(cfg: RuntimeConfig,
|
||||||
blk: Eth1Block,
|
blk: Eth1Block,
|
||||||
period_start: uint64): bool =
|
period_start: uint64): bool =
|
||||||
|
@ -782,7 +782,7 @@ template trackFinalizedState*(m: Eth1Monitor,
|
||||||
finalizedStateDepositIndex: uint64): bool =
|
finalizedStateDepositIndex: uint64): bool =
|
||||||
trackFinalizedState(m.depositsChain, finalizedEth1Data, finalizedStateDepositIndex)
|
trackFinalizedState(m.depositsChain, finalizedEth1Data, finalizedStateDepositIndex)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#get_eth1_data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#get_eth1_data
|
||||||
proc getBlockProposalData*(chain: var Eth1Chain,
|
proc getBlockProposalData*(chain: var Eth1Chain,
|
||||||
state: ForkedHashedBeaconState,
|
state: ForkedHashedBeaconState,
|
||||||
finalizedEth1Data: Eth1Data,
|
finalizedEth1Data: Eth1Data,
|
||||||
|
|
|
@ -9,12 +9,12 @@ This folder holds a collection of modules to:
|
||||||
|
|
||||||
Gossip validation is different from consensus verification in particular for blocks.
|
Gossip validation is different from consensus verification in particular for blocks.
|
||||||
|
|
||||||
- Blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_block
|
- Blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_block
|
||||||
- Attestations (aggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
- Attestations (aggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||||
- Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attestation-subnets
|
- Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attestation-subnets
|
||||||
- Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#voluntary_exit
|
- Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#voluntary_exit
|
||||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#proposer_slashing
|
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#proposer_slashing
|
||||||
- Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attester_slashing
|
- Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attester_slashing
|
||||||
|
|
||||||
There are multiple consumers of validated consensus objects:
|
There are multiple consumers of validated consensus objects:
|
||||||
- a `ValidationResult.Accept` output triggers rebroadcasting in libp2p
|
- a `ValidationResult.Accept` output triggers rebroadcasting in libp2p
|
||||||
|
|
|
@ -89,7 +89,7 @@ func check_propagation_slot_range(
|
||||||
let
|
let
|
||||||
pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot()
|
pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#configuration
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#configuration
|
||||||
# The spec value of ATTESTATION_PROPAGATION_SLOT_RANGE is 32, but it can
|
# The spec value of ATTESTATION_PROPAGATION_SLOT_RANGE is 32, but it can
|
||||||
# retransmit attestations on the cusp of being out of spec, and which by
|
# retransmit attestations on the cusp of being out of spec, and which by
|
||||||
# the time they reach their destination might be out of spec.
|
# the time they reach their destination might be out of spec.
|
||||||
|
@ -511,7 +511,7 @@ proc validateAttestation*(
|
||||||
|
|
||||||
return ok((validator_index, sig))
|
return ok((validator_index, sig))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||||
proc validateAggregate*(
|
proc validateAggregate*(
|
||||||
pool: ref AttestationPool,
|
pool: ref AttestationPool,
|
||||||
batchCrypto: ref BatchCrypto,
|
batchCrypto: ref BatchCrypto,
|
||||||
|
@ -848,7 +848,7 @@ proc validateSyncCommitteeMessage*(
|
||||||
|
|
||||||
return ok((positionsInSubcommittee, sig))
|
return ok((positionsInSubcommittee, sig))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#sync_committee_contribution_and_proof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#sync_committee_contribution_and_proof
|
||||||
proc validateContribution*(
|
proc validateContribution*(
|
||||||
dag: ChainDAGRef,
|
dag: ChainDAGRef,
|
||||||
batchCrypto: ref BatchCrypto,
|
batchCrypto: ref BatchCrypto,
|
||||||
|
|
|
@ -165,7 +165,7 @@ type
|
||||||
MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].}
|
MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].}
|
||||||
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].}
|
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].}
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#goodbye
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#goodbye
|
||||||
DisconnectionReason* = enum
|
DisconnectionReason* = enum
|
||||||
# might see other values on the wire!
|
# might see other values on the wire!
|
||||||
ClientShutDown = 1
|
ClientShutDown = 1
|
||||||
|
@ -1790,8 +1790,8 @@ proc getPersistentNetKeys*(rng: var BrHmacDrbgContext,
|
||||||
|
|
||||||
func gossipId(
|
func gossipId(
|
||||||
data: openArray[byte], altairPrefix, topic: string, valid: bool): seq[byte] =
|
data: openArray[byte], altairPrefix, topic: string, valid: bool): seq[byte] =
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#topics-and-messages
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||||
const
|
const
|
||||||
MESSAGE_DOMAIN_INVALID_SNAPPY = [0x00'u8, 0x00, 0x00, 0x00]
|
MESSAGE_DOMAIN_INVALID_SNAPPY = [0x00'u8, 0x00, 0x00, 0x00]
|
||||||
MESSAGE_DOMAIN_VALID_SNAPPY = [0x01'u8, 0x00, 0x00, 0x00]
|
MESSAGE_DOMAIN_VALID_SNAPPY = [0x01'u8, 0x00, 0x00, 0x00]
|
||||||
|
@ -2095,7 +2095,7 @@ proc subscribeAttestationSubnets*(
|
||||||
|
|
||||||
proc unsubscribeAttestationSubnets*(
|
proc unsubscribeAttestationSubnets*(
|
||||||
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
|
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||||
# Nimbus won't score attestation subnets for now; we just rely on block and
|
# Nimbus won't score attestation subnets for now; we just rely on block and
|
||||||
# aggregate which are more stable and reliable
|
# aggregate which are more stable and reliable
|
||||||
|
|
||||||
|
@ -2104,15 +2104,15 @@ proc unsubscribeAttestationSubnets*(
|
||||||
node.unsubscribe(getAttestationTopic(forkDigest, SubnetId(subnet_id)))
|
node.unsubscribe(getAttestationTopic(forkDigest, SubnetId(subnet_id)))
|
||||||
|
|
||||||
proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
|
proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#metadata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#metadata
|
||||||
if node.metadata.attnets == attnets:
|
if node.metadata.attnets == attnets:
|
||||||
return
|
return
|
||||||
|
|
||||||
node.metadata.seq_number += 1
|
node.metadata.seq_number += 1
|
||||||
node.metadata.attnets = attnets
|
node.metadata.attnets = attnets
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attestation-subnet-bitfield
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attestation-subnet-bitfield
|
||||||
let res = node.discovery.updateRecord({
|
let res = node.discovery.updateRecord({
|
||||||
enrAttestationSubnetsField: SSZ.encode(node.metadata.attnets)
|
enrAttestationSubnetsField: SSZ.encode(node.metadata.attnets)
|
||||||
})
|
})
|
||||||
|
@ -2124,7 +2124,7 @@ proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
|
||||||
debug "Stability subnets changed; updated ENR attnets", attnets
|
debug "Stability subnets changed; updated ENR attnets", attnets
|
||||||
|
|
||||||
proc updateSyncnetsMetadata*(node: Eth2Node, syncnets: SyncnetBits) =
|
proc updateSyncnetsMetadata*(node: Eth2Node, syncnets: SyncnetBits) =
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#sync-committee-subnet-stability
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#sync-committee-subnet-stability
|
||||||
if node.metadata.syncnets == syncnets:
|
if node.metadata.syncnets == syncnets:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -2167,7 +2167,7 @@ proc getWallEpoch(node: Eth2Node): Epoch =
|
||||||
proc broadcastAttestation*(node: Eth2Node, subnet_id: SubnetId,
|
proc broadcastAttestation*(node: Eth2Node, subnet_id: SubnetId,
|
||||||
attestation: Attestation) =
|
attestation: Attestation) =
|
||||||
# Regardless of the contents of the attestation,
|
# Regardless of the contents of the attestation,
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#transitioning-the-gossip
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||||
# implies that pre-fork, messages using post-fork digests might be
|
# implies that pre-fork, messages using post-fork digests might be
|
||||||
# ignored, whilst post-fork, there is effectively a seen_ttl-based
|
# ignored, whilst post-fork, there is effectively a seen_ttl-based
|
||||||
# timer unsubscription point that means no new pre-fork-forkdigest
|
# timer unsubscription point that means no new pre-fork-forkdigest
|
||||||
|
|
|
@ -516,7 +516,7 @@ func verifyFinalization(node: BeaconNode, slot: Slot) =
|
||||||
func subnetLog(v: BitArray): string =
|
func subnetLog(v: BitArray): string =
|
||||||
$toSeq(v.oneIndices())
|
$toSeq(v.oneIndices())
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
||||||
proc updateAttestationSubnetHandlers(node: BeaconNode, slot: Slot) =
|
proc updateAttestationSubnetHandlers(node: BeaconNode, slot: Slot) =
|
||||||
if node.gossipState.card == 0:
|
if node.gossipState.card == 0:
|
||||||
# When disconnected, updateGossipState is responsible for all things
|
# When disconnected, updateGossipState is responsible for all things
|
||||||
|
@ -976,7 +976,7 @@ proc installRestHandlers(restServer: RestServerRef, node: BeaconNode) =
|
||||||
restServer.router.installValidatorManagementHandlers(node)
|
restServer.router.installValidatorManagementHandlers(node)
|
||||||
|
|
||||||
proc installMessageValidators(node: BeaconNode) =
|
proc installMessageValidators(node: BeaconNode) =
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||||
# These validators stay around the whole time, regardless of which specific
|
# These validators stay around the whole time, regardless of which specific
|
||||||
# subnets are subscribed to during any given epoch.
|
# subnets are subscribed to during any given epoch.
|
||||||
func toValidationResult(res: ValidationRes): ValidationResult =
|
func toValidationResult(res: ValidationRes): ValidationResult =
|
||||||
|
|
|
@ -162,7 +162,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
DEPOSIT_CONTRACT_ADDRESS:
|
DEPOSIT_CONTRACT_ADDRESS:
|
||||||
$node.dag.cfg.DEPOSIT_CONTRACT_ADDRESS,
|
$node.dag.cfg.DEPOSIT_CONTRACT_ADDRESS,
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#constants
|
||||||
# GENESIS_SLOT
|
# GENESIS_SLOT
|
||||||
# GENESIS_EPOCH
|
# GENESIS_EPOCH
|
||||||
# FAR_FUTURE_EPOCH
|
# FAR_FUTURE_EPOCH
|
||||||
|
@ -196,7 +196,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
"0x" & ncrutils.toHex(
|
"0x" & ncrutils.toHex(
|
||||||
uint32(DOMAIN_AGGREGATE_AND_PROOF).toBytesLE()),
|
uint32(DOMAIN_AGGREGATE_AND_PROOF).toBytesLE()),
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#constants
|
||||||
TIMELY_SOURCE_FLAG_INDEX:
|
TIMELY_SOURCE_FLAG_INDEX:
|
||||||
"0x" & ncrutils.toHex([byte(TIMELY_SOURCE_FLAG_INDEX)]),
|
"0x" & ncrutils.toHex([byte(TIMELY_SOURCE_FLAG_INDEX)]),
|
||||||
TIMELY_TARGET_FLAG_INDEX:
|
TIMELY_TARGET_FLAG_INDEX:
|
||||||
|
@ -226,7 +226,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
uint32(DOMAIN_CONTRIBUTION_AND_PROOF).toBytesLE()),
|
uint32(DOMAIN_CONTRIBUTION_AND_PROOF).toBytesLE()),
|
||||||
# PARTICIPATION_FLAG_WEIGHTS
|
# PARTICIPATION_FLAG_WEIGHTS
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#constants
|
||||||
TARGET_AGGREGATORS_PER_COMMITTEE:
|
TARGET_AGGREGATORS_PER_COMMITTEE:
|
||||||
Base10.toString(TARGET_AGGREGATORS_PER_COMMITTEE),
|
Base10.toString(TARGET_AGGREGATORS_PER_COMMITTEE),
|
||||||
RANDOM_SUBNETS_PER_VALIDATOR:
|
RANDOM_SUBNETS_PER_VALIDATOR:
|
||||||
|
@ -236,7 +236,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
||||||
ATTESTATION_SUBNET_COUNT:
|
ATTESTATION_SUBNET_COUNT:
|
||||||
Base10.toString(uint64(ATTESTATION_SUBNET_COUNT)),
|
Base10.toString(uint64(ATTESTATION_SUBNET_COUNT)),
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#constants
|
||||||
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE:
|
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE:
|
||||||
Base10.toString(uint64(TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE)),
|
Base10.toString(uint64(TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE)),
|
||||||
SYNC_COMMITTEE_SUBNET_COUNT:
|
SYNC_COMMITTEE_SUBNET_COUNT:
|
||||||
|
|
|
@ -18,7 +18,7 @@ import
|
||||||
|
|
||||||
export extras, forks, validator
|
export extras, forks, validator
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#increase_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#increase_balance
|
||||||
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
||||||
balance += delta
|
balance += delta
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func increase_balance*(
|
||||||
if delta != 0: # avoid dirtying the balance cache if not needed
|
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||||
increase_balance(state.balances[index], delta)
|
increase_balance(state.balances[index], delta)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#decrease_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#decrease_balance
|
||||||
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
||||||
balance =
|
balance =
|
||||||
if delta > balance:
|
if delta > balance:
|
||||||
|
@ -43,8 +43,8 @@ func decrease_balance*(
|
||||||
if delta != 0: # avoid dirtying the balance cache if not needed
|
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||||
decrease_balance(state.balances[index], delta)
|
decrease_balance(state.balances[index], delta)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#deposits
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#deposits
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#modified-process_deposit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#modified-process_deposit
|
||||||
func get_validator_from_deposit*(deposit: DepositData):
|
func get_validator_from_deposit*(deposit: DepositData):
|
||||||
Validator =
|
Validator =
|
||||||
let
|
let
|
||||||
|
@ -62,13 +62,13 @@ func get_validator_from_deposit*(deposit: DepositData):
|
||||||
effective_balance: effective_balance
|
effective_balance: effective_balance
|
||||||
)
|
)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_activation_exit_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_activation_exit_epoch
|
||||||
func compute_activation_exit_epoch*(epoch: Epoch): Epoch =
|
func compute_activation_exit_epoch*(epoch: Epoch): Epoch =
|
||||||
## Return the epoch during which validator activations and exits initiated in
|
## Return the epoch during which validator activations and exits initiated in
|
||||||
## ``epoch`` take effect.
|
## ``epoch`` take effect.
|
||||||
epoch + 1 + MAX_SEED_LOOKAHEAD
|
epoch + 1 + MAX_SEED_LOOKAHEAD
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
||||||
func get_validator_churn_limit*(
|
func get_validator_churn_limit*(
|
||||||
cfg: RuntimeConfig, state: ForkyBeaconState, cache: var StateCache):
|
cfg: RuntimeConfig, state: ForkyBeaconState, cache: var StateCache):
|
||||||
uint64 =
|
uint64 =
|
||||||
|
@ -78,7 +78,7 @@ func get_validator_churn_limit*(
|
||||||
count_active_validators(
|
count_active_validators(
|
||||||
state, state.get_current_epoch(), cache) div cfg.CHURN_LIMIT_QUOTIENT)
|
state, state.get_current_epoch(), cache) div cfg.CHURN_LIMIT_QUOTIENT)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#initiate_validator_exit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#initiate_validator_exit
|
||||||
func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,
|
func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||||
index: ValidatorIndex, cache: var StateCache) =
|
index: ValidatorIndex, cache: var StateCache) =
|
||||||
## Initiate the exit of the validator with index ``index``.
|
## Initiate the exit of the validator with index ``index``.
|
||||||
|
@ -119,8 +119,8 @@ func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||||
validator.withdrawable_epoch =
|
validator.withdrawable_epoch =
|
||||||
validator.exit_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
validator.exit_epoch + cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#modified-slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/merge/beacon-chain.md#modified-slash_validator
|
||||||
proc slash_validator*(
|
proc slash_validator*(
|
||||||
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||||
|
@ -188,7 +188,7 @@ proc slash_validator*(
|
||||||
func genesis_time_from_eth1_timestamp*(cfg: RuntimeConfig, eth1_timestamp: uint64): uint64 =
|
func genesis_time_from_eth1_timestamp*(cfg: RuntimeConfig, eth1_timestamp: uint64): uint64 =
|
||||||
eth1_timestamp + cfg.GENESIS_DELAY
|
eth1_timestamp + cfg.GENESIS_DELAY
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#genesis
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#genesis
|
||||||
proc initialize_beacon_state_from_eth1*(
|
proc initialize_beacon_state_from_eth1*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
eth1_block_hash: Eth2Digest,
|
eth1_block_hash: Eth2Digest,
|
||||||
|
@ -290,7 +290,7 @@ proc initialize_hashed_beacon_state_from_eth1*(
|
||||||
cfg, eth1_block_hash, eth1_timestamp, deposits, flags))
|
cfg, eth1_block_hash, eth1_timestamp, deposits, flags))
|
||||||
result.root = hash_tree_root(result.data)
|
result.root = hash_tree_root(result.data)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#genesis-block
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#genesis-block
|
||||||
func get_initial_beacon_block*(state: phase0.HashedBeaconState):
|
func get_initial_beacon_block*(state: phase0.HashedBeaconState):
|
||||||
phase0.TrustedSignedBeaconBlock =
|
phase0.TrustedSignedBeaconBlock =
|
||||||
# The genesis block is implicitly trusted
|
# The genesis block is implicitly trusted
|
||||||
|
@ -302,7 +302,7 @@ func get_initial_beacon_block*(state: phase0.HashedBeaconState):
|
||||||
phase0.TrustedSignedBeaconBlock(
|
phase0.TrustedSignedBeaconBlock(
|
||||||
message: message, root: hash_tree_root(message))
|
message: message, root: hash_tree_root(message))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#initialize-state-for-pure-altair-testnets-and-test-vectors
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#initialize-state-for-pure-altair-testnets-and-test-vectors
|
||||||
func get_initial_beacon_block*(state: altair.HashedBeaconState):
|
func get_initial_beacon_block*(state: altair.HashedBeaconState):
|
||||||
altair.TrustedSignedBeaconBlock =
|
altair.TrustedSignedBeaconBlock =
|
||||||
# The genesis block is implicitly trusted
|
# The genesis block is implicitly trusted
|
||||||
|
@ -331,7 +331,7 @@ func get_initial_beacon_block*(state: ForkedHashedBeaconState):
|
||||||
withState(state):
|
withState(state):
|
||||||
ForkedTrustedSignedBeaconBlock.init(get_initial_beacon_block(state))
|
ForkedTrustedSignedBeaconBlock.init(get_initial_beacon_block(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_block_root_at_slot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_block_root_at_slot
|
||||||
func get_block_root_at_slot*(state: ForkyBeaconState, slot: Slot): Eth2Digest =
|
func get_block_root_at_slot*(state: ForkyBeaconState, slot: Slot): Eth2Digest =
|
||||||
## Return the block root at a recent ``slot``.
|
## Return the block root at a recent ``slot``.
|
||||||
|
|
||||||
|
@ -349,12 +349,12 @@ func get_block_root_at_slot*(state: ForkedHashedBeaconState,
|
||||||
withState(state):
|
withState(state):
|
||||||
get_block_root_at_slot(state.data, slot)
|
get_block_root_at_slot(state.data, slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_block_root
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_block_root
|
||||||
func get_block_root*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
func get_block_root*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
||||||
## Return the block root at the start of a recent ``epoch``.
|
## Return the block root at the start of a recent ``epoch``.
|
||||||
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
||||||
template get_total_balance(
|
template get_total_balance(
|
||||||
state: ForkyBeaconState, validator_indices: untyped): Gwei =
|
state: ForkyBeaconState, validator_indices: untyped): Gwei =
|
||||||
## Return the combined effective balance of the ``indices``.
|
## Return the combined effective balance of the ``indices``.
|
||||||
|
@ -365,13 +365,13 @@ template get_total_balance(
|
||||||
res += state.validators.asSeq()[validator_index].effective_balance
|
res += state.validators.asSeq()[validator_index].effective_balance
|
||||||
max(EFFECTIVE_BALANCE_INCREMENT, res)
|
max(EFFECTIVE_BALANCE_INCREMENT, res)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
|
||||||
func is_eligible_for_activation_queue*(validator: Validator): bool =
|
func is_eligible_for_activation_queue*(validator: Validator): bool =
|
||||||
## Check if ``validator`` is eligible to be placed into the activation queue.
|
## Check if ``validator`` is eligible to be placed into the activation queue.
|
||||||
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
|
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
|
||||||
validator.effective_balance == MAX_EFFECTIVE_BALANCE
|
validator.effective_balance == MAX_EFFECTIVE_BALANCE
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_eligible_for_activation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_eligible_for_activation
|
||||||
func is_eligible_for_activation*(state: ForkyBeaconState, validator: Validator):
|
func is_eligible_for_activation*(state: ForkyBeaconState, validator: Validator):
|
||||||
bool =
|
bool =
|
||||||
## Check if ``validator`` is eligible for activation.
|
## Check if ``validator`` is eligible for activation.
|
||||||
|
@ -381,7 +381,7 @@ func is_eligible_for_activation*(state: ForkyBeaconState, validator: Validator):
|
||||||
# Has not yet been activated
|
# Has not yet been activated
|
||||||
validator.activation_epoch == FAR_FUTURE_EPOCH
|
validator.activation_epoch == FAR_FUTURE_EPOCH
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||||
proc is_valid_indexed_attestation*(
|
proc is_valid_indexed_attestation*(
|
||||||
state: ForkyBeaconState, indexed_attestation: SomeIndexedAttestation,
|
state: ForkyBeaconState, indexed_attestation: SomeIndexedAttestation,
|
||||||
flags: UpdateFlags): Result[void, cstring] =
|
flags: UpdateFlags): Result[void, cstring] =
|
||||||
|
@ -419,7 +419,7 @@ proc is_valid_indexed_attestation*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_attesting_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||||
func get_attesting_indices*(state: ForkyBeaconState,
|
func get_attesting_indices*(state: ForkyBeaconState,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits,
|
bits: CommitteeValidatorsBits,
|
||||||
|
@ -484,8 +484,8 @@ proc is_valid_indexed_attestation*(
|
||||||
|
|
||||||
# Attestation validation
|
# Attestation validation
|
||||||
# ------------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------------
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attestations
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attestations
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||||
|
|
||||||
func check_attestation_slot_target*(data: AttestationData): Result[void, cstring] =
|
func check_attestation_slot_target*(data: AttestationData): Result[void, cstring] =
|
||||||
if not (data.target.epoch == compute_epoch_at_slot(data.slot)):
|
if not (data.target.epoch == compute_epoch_at_slot(data.slot)):
|
||||||
|
@ -524,7 +524,7 @@ func check_attestation_index(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_attestation_participation_flag_indices
|
||||||
func get_attestation_participation_flag_indices(state: altair.BeaconState | merge.BeaconState,
|
func get_attestation_participation_flag_indices(state: altair.BeaconState | merge.BeaconState,
|
||||||
data: AttestationData,
|
data: AttestationData,
|
||||||
inclusion_delay: uint64): seq[int] =
|
inclusion_delay: uint64): seq[int] =
|
||||||
|
@ -558,7 +558,7 @@ func get_attestation_participation_flag_indices(state: altair.BeaconState | merg
|
||||||
# TODO these duplicate some stuff in state_transition_epoch which uses TotalBalances
|
# TODO these duplicate some stuff in state_transition_epoch which uses TotalBalances
|
||||||
# better to centralize around that if feasible
|
# better to centralize around that if feasible
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_total_active_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_active_balance
|
||||||
func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache): Gwei =
|
func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache): Gwei =
|
||||||
## Return the combined effective balance of the active validators.
|
## Return the combined effective balance of the active validators.
|
||||||
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei
|
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei
|
||||||
|
@ -569,7 +569,7 @@ func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache):
|
||||||
get_total_balance(
|
get_total_balance(
|
||||||
state, cache.get_shuffled_active_validator_indices(state, epoch))
|
state, cache.get_shuffled_active_validator_indices(state, epoch))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_base_reward_per_increment
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward_per_increment
|
||||||
func get_base_reward_per_increment_sqrt*(
|
func get_base_reward_per_increment_sqrt*(
|
||||||
total_active_balance_sqrt: uint64): Gwei =
|
total_active_balance_sqrt: uint64): Gwei =
|
||||||
EFFECTIVE_BALANCE_INCREMENT * BASE_REWARD_FACTOR div total_active_balance_sqrt
|
EFFECTIVE_BALANCE_INCREMENT * BASE_REWARD_FACTOR div total_active_balance_sqrt
|
||||||
|
@ -578,7 +578,7 @@ func get_base_reward_per_increment*(
|
||||||
total_active_balance: Gwei): Gwei =
|
total_active_balance: Gwei): Gwei =
|
||||||
get_base_reward_per_increment_sqrt(integer_squareroot(total_active_balance))
|
get_base_reward_per_increment_sqrt(integer_squareroot(total_active_balance))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_base_reward
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
||||||
func get_base_reward(
|
func get_base_reward(
|
||||||
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
||||||
base_reward_per_increment: Gwei): Gwei =
|
base_reward_per_increment: Gwei): Gwei =
|
||||||
|
@ -588,7 +588,7 @@ func get_base_reward(
|
||||||
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
|
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
|
||||||
increments * base_reward_per_increment
|
increments * base_reward_per_increment
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attestations
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attestations
|
||||||
proc check_attestation*(
|
proc check_attestation*(
|
||||||
state: ForkyBeaconState, attestation: SomeAttestation, flags: UpdateFlags,
|
state: ForkyBeaconState, attestation: SomeAttestation, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
|
@ -700,7 +700,7 @@ proc process_attestation*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_next_sync_committee_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee_indices
|
||||||
func get_next_sync_committee_keys(state: altair.BeaconState | merge.BeaconState):
|
func get_next_sync_committee_keys(state: altair.BeaconState | merge.BeaconState):
|
||||||
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
|
array[SYNC_COMMITTEE_SIZE, ValidatorPubKey] =
|
||||||
## Return the sequence of sync committee indices (which may include
|
## Return the sequence of sync committee indices (which may include
|
||||||
|
@ -736,7 +736,7 @@ func get_next_sync_committee_keys(state: altair.BeaconState | merge.BeaconState)
|
||||||
i += 1'u64
|
i += 1'u64
|
||||||
res
|
res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_next_sync_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_next_sync_committee
|
||||||
proc get_next_sync_committee*(state: altair.BeaconState | merge.BeaconState):
|
proc get_next_sync_committee*(state: altair.BeaconState | merge.BeaconState):
|
||||||
SyncCommittee =
|
SyncCommittee =
|
||||||
## Return the *next* sync committee for a given ``state``.
|
## Return the *next* sync committee for a given ``state``.
|
||||||
|
@ -753,7 +753,7 @@ proc get_next_sync_committee*(state: altair.BeaconState | merge.BeaconState):
|
||||||
res.aggregate_pubkey = finish(attestersAgg).toPubKey()
|
res.aggregate_pubkey = finish(attestersAgg).toPubKey()
|
||||||
res
|
res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/fork.md#upgrading-the-state
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/fork.md#upgrading-the-state
|
||||||
func translate_participation(
|
func translate_participation(
|
||||||
state: var altair.BeaconState,
|
state: var altair.BeaconState,
|
||||||
pending_attestations: openArray[phase0.PendingAttestation]) =
|
pending_attestations: openArray[phase0.PendingAttestation]) =
|
||||||
|
|
|
@ -37,7 +37,7 @@ from ssz_serialization/merkleization import GeneralizedIndex
|
||||||
export merkleization.GeneralizedIndex
|
export merkleization.GeneralizedIndex
|
||||||
|
|
||||||
const
|
const
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#incentivization-weights
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#incentivization-weights
|
||||||
TIMELY_SOURCE_WEIGHT* = 14
|
TIMELY_SOURCE_WEIGHT* = 14
|
||||||
TIMELY_TARGET_WEIGHT* = 26
|
TIMELY_TARGET_WEIGHT* = 26
|
||||||
TIMELY_HEAD_WEIGHT* = 14
|
TIMELY_HEAD_WEIGHT* = 14
|
||||||
|
@ -48,7 +48,7 @@ const
|
||||||
PARTICIPATION_FLAG_WEIGHTS* =
|
PARTICIPATION_FLAG_WEIGHTS* =
|
||||||
[TIMELY_SOURCE_WEIGHT, TIMELY_TARGET_WEIGHT, TIMELY_HEAD_WEIGHT]
|
[TIMELY_SOURCE_WEIGHT, TIMELY_TARGET_WEIGHT, TIMELY_HEAD_WEIGHT]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#misc
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#misc
|
||||||
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE* = 16
|
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE* = 16
|
||||||
SYNC_COMMITTEE_SUBNET_COUNT* = 4
|
SYNC_COMMITTEE_SUBNET_COUNT* = 4
|
||||||
|
|
||||||
|
@ -56,12 +56,12 @@ const
|
||||||
FINALIZED_ROOT_INDEX* = 105.GeneralizedIndex
|
FINALIZED_ROOT_INDEX* = 105.GeneralizedIndex
|
||||||
NEXT_SYNC_COMMITTEE_INDEX* = 55.GeneralizedIndex
|
NEXT_SYNC_COMMITTEE_INDEX* = 55.GeneralizedIndex
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#participation-flag-indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#participation-flag-indices
|
||||||
TIMELY_SOURCE_FLAG_INDEX* = 0
|
TIMELY_SOURCE_FLAG_INDEX* = 0
|
||||||
TIMELY_TARGET_FLAG_INDEX* = 1
|
TIMELY_TARGET_FLAG_INDEX* = 1
|
||||||
TIMELY_HEAD_FLAG_INDEX* = 2
|
TIMELY_HEAD_FLAG_INDEX* = 2
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#inactivity-penalties
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#inactivity-penalties
|
||||||
INACTIVITY_SCORE_BIAS* = 4
|
INACTIVITY_SCORE_BIAS* = 4
|
||||||
INACTIVITY_SCORE_RECOVERY_RATE* = 16
|
INACTIVITY_SCORE_RECOVERY_RATE* = 16
|
||||||
|
|
||||||
|
@ -79,10 +79,10 @@ static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
|
||||||
type
|
type
|
||||||
### New types
|
### New types
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#custom-types
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#custom-types
|
||||||
ParticipationFlags* = uint8
|
ParticipationFlags* = uint8
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#syncaggregate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#syncaggregate
|
||||||
SyncAggregate* = object
|
SyncAggregate* = object
|
||||||
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
||||||
sync_committee_signature*: ValidatorSig
|
sync_committee_signature*: ValidatorSig
|
||||||
|
@ -91,12 +91,12 @@ type
|
||||||
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
sync_committee_bits*: BitArray[SYNC_COMMITTEE_SIZE]
|
||||||
sync_committee_signature*: TrustedSig
|
sync_committee_signature*: TrustedSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#synccommittee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#synccommittee
|
||||||
SyncCommittee* = object
|
SyncCommittee* = object
|
||||||
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
|
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
|
||||||
aggregate_pubkey*: ValidatorPubKey
|
aggregate_pubkey*: ValidatorPubKey
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#synccommitteemessage
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#synccommitteemessage
|
||||||
SyncCommitteeMessage* = object
|
SyncCommitteeMessage* = object
|
||||||
slot*: Slot ##\
|
slot*: Slot ##\
|
||||||
## Slot to which this contribution pertains
|
## Slot to which this contribution pertains
|
||||||
|
@ -110,7 +110,7 @@ type
|
||||||
signature*: ValidatorSig ##\
|
signature*: ValidatorSig ##\
|
||||||
## Signature by the validator over the block root of `slot`
|
## Signature by the validator over the block root of `slot`
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#synccommitteecontribution
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#synccommitteecontribution
|
||||||
SyncCommitteeAggregationBits* =
|
SyncCommitteeAggregationBits* =
|
||||||
BitArray[SYNC_SUBCOMMITTEE_SIZE]
|
BitArray[SYNC_SUBCOMMITTEE_SIZE]
|
||||||
|
|
||||||
|
@ -132,18 +132,18 @@ type
|
||||||
signature*: ValidatorSig ##\
|
signature*: ValidatorSig ##\
|
||||||
## Signature by the validator(s) over the block root of `slot`
|
## Signature by the validator(s) over the block root of `slot`
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#contributionandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#contributionandproof
|
||||||
ContributionAndProof* = object
|
ContributionAndProof* = object
|
||||||
aggregator_index*: uint64
|
aggregator_index*: uint64
|
||||||
contribution*: SyncCommitteeContribution
|
contribution*: SyncCommitteeContribution
|
||||||
selection_proof*: ValidatorSig
|
selection_proof*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#signedcontributionandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#signedcontributionandproof
|
||||||
SignedContributionAndProof* = object
|
SignedContributionAndProof* = object
|
||||||
message*: ContributionAndProof
|
message*: ContributionAndProof
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#syncaggregatorselectiondata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#syncaggregatorselectiondata
|
||||||
SyncAggregatorSelectionData* = object
|
SyncAggregatorSelectionData* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
subcommittee_index*: uint64
|
subcommittee_index*: uint64
|
||||||
|
@ -190,7 +190,7 @@ type
|
||||||
previous_max_active_participants*: uint64
|
previous_max_active_participants*: uint64
|
||||||
current_max_active_participants*: uint64
|
current_max_active_participants*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#beaconstate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -280,7 +280,7 @@ type
|
||||||
data*: BeaconState
|
data*: BeaconState
|
||||||
root*: Eth2Digest # hash_tree_root(data)
|
root*: Eth2Digest # hash_tree_root(data)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconblock
|
||||||
BeaconBlock* = object
|
BeaconBlock* = object
|
||||||
## For each slot, a proposer is chosen from the validator pool to propose
|
## For each slot, a proposer is chosen from the validator pool to propose
|
||||||
## a new block. Once the block as been proposed, it is transmitted to
|
## a new block. Once the block as been proposed, it is transmitted to
|
||||||
|
@ -336,7 +336,7 @@ type
|
||||||
state_root*: Eth2Digest ##\
|
state_root*: Eth2Digest ##\
|
||||||
body*: TrustedBeaconBlockBody
|
body*: TrustedBeaconBlockBody
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
eth1_data*: Eth1Data ##\
|
eth1_data*: Eth1Data ##\
|
||||||
|
@ -385,7 +385,7 @@ type
|
||||||
|
|
||||||
SyncnetBits* = BitArray[SYNC_COMMITTEE_SUBNET_COUNT]
|
SyncnetBits* = BitArray[SYNC_COMMITTEE_SUBNET_COUNT]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#metadata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#metadata
|
||||||
MetaData* = object
|
MetaData* = object
|
||||||
seq_number*: uint64
|
seq_number*: uint64
|
||||||
attnets*: AttnetBits
|
attnets*: AttnetBits
|
||||||
|
@ -407,7 +407,7 @@ type
|
||||||
# [New in Altair]
|
# [New in Altair]
|
||||||
sync_aggregate*: TrustedSyncAggregate
|
sync_aggregate*: TrustedSyncAggregate
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signedbeaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||||
SignedBeaconBlock* = object
|
SignedBeaconBlock* = object
|
||||||
message*: BeaconBlock
|
message*: BeaconBlock
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
|
@ -70,7 +70,7 @@ const
|
||||||
MAX_GRAFFITI_SIZE* = 32
|
MAX_GRAFFITI_SIZE* = 32
|
||||||
FAR_FUTURE_SLOT* = (not 0'u64).Slot
|
FAR_FUTURE_SLOT* = (not 0'u64).Slot
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#configuration
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#configuration
|
||||||
MAXIMUM_GOSSIP_CLOCK_DISPARITY* = 500.millis
|
MAXIMUM_GOSSIP_CLOCK_DISPARITY* = 500.millis
|
||||||
|
|
||||||
SLOTS_PER_ETH1_VOTING_PERIOD* =
|
SLOTS_PER_ETH1_VOTING_PERIOD* =
|
||||||
|
@ -79,10 +79,10 @@ const
|
||||||
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
DEPOSIT_CONTRACT_TREE_DEPTH* = 32
|
||||||
BASE_REWARDS_PER_EPOCH* = 4
|
BASE_REWARDS_PER_EPOCH* = 4
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#misc
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#misc
|
||||||
ATTESTATION_SUBNET_COUNT* = 64
|
ATTESTATION_SUBNET_COUNT* = 64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/fork-choice.md#constant
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/fork-choice.md#constant
|
||||||
INTERVALS_PER_SLOT* = 3
|
INTERVALS_PER_SLOT* = 3
|
||||||
|
|
||||||
template maxSize*(n: int) {.pragma.}
|
template maxSize*(n: int) {.pragma.}
|
||||||
|
@ -121,7 +121,7 @@ type
|
||||||
# Domains
|
# Domains
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
DomainType* = enum
|
DomainType* = enum
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#domain-types
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#domain-types
|
||||||
DOMAIN_BEACON_PROPOSER = 0
|
DOMAIN_BEACON_PROPOSER = 0
|
||||||
DOMAIN_BEACON_ATTESTER = 1
|
DOMAIN_BEACON_ATTESTER = 1
|
||||||
DOMAIN_RANDAO = 2
|
DOMAIN_RANDAO = 2
|
||||||
|
@ -130,12 +130,12 @@ type
|
||||||
DOMAIN_SELECTION_PROOF = 5
|
DOMAIN_SELECTION_PROOF = 5
|
||||||
DOMAIN_AGGREGATE_AND_PROOF = 6
|
DOMAIN_AGGREGATE_AND_PROOF = 6
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#domain-types
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#domain-types
|
||||||
DOMAIN_SYNC_COMMITTEE = 7
|
DOMAIN_SYNC_COMMITTEE = 7
|
||||||
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = 8
|
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF = 8
|
||||||
DOMAIN_CONTRIBUTION_AND_PROOF = 9
|
DOMAIN_CONTRIBUTION_AND_PROOF = 9
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#custom-types
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#custom-types
|
||||||
Eth2Domain* = array[32, byte]
|
Eth2Domain* = array[32, byte]
|
||||||
|
|
||||||
# https://github.com/nim-lang/Nim/issues/574 and be consistent across
|
# https://github.com/nim-lang/Nim/issues/574 and be consistent across
|
||||||
|
@ -163,7 +163,7 @@ type
|
||||||
|
|
||||||
Gwei* = uint64
|
Gwei* = uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#proposerslashing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#proposerslashing
|
||||||
ProposerSlashing* = object
|
ProposerSlashing* = object
|
||||||
signed_header_1*: SignedBeaconBlockHeader
|
signed_header_1*: SignedBeaconBlockHeader
|
||||||
signed_header_2*: SignedBeaconBlockHeader
|
signed_header_2*: SignedBeaconBlockHeader
|
||||||
|
@ -175,7 +175,7 @@ type
|
||||||
signed_header_1*: TrustedSignedBeaconBlockHeader
|
signed_header_1*: TrustedSignedBeaconBlockHeader
|
||||||
signed_header_2*: TrustedSignedBeaconBlockHeader
|
signed_header_2*: TrustedSignedBeaconBlockHeader
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attesterslashing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attesterslashing
|
||||||
AttesterSlashing* = object
|
AttesterSlashing* = object
|
||||||
attestation_1*: IndexedAttestation
|
attestation_1*: IndexedAttestation
|
||||||
attestation_2*: IndexedAttestation
|
attestation_2*: IndexedAttestation
|
||||||
|
@ -187,7 +187,7 @@ type
|
||||||
attestation_1*: TrustedIndexedAttestation
|
attestation_1*: TrustedIndexedAttestation
|
||||||
attestation_2*: TrustedIndexedAttestation
|
attestation_2*: TrustedIndexedAttestation
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#indexedattestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#indexedattestation
|
||||||
IndexedAttestation* = object
|
IndexedAttestation* = object
|
||||||
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
|
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
|
@ -203,7 +203,7 @@ type
|
||||||
|
|
||||||
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
|
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attestation
|
||||||
Attestation* = object
|
Attestation* = object
|
||||||
aggregation_bits*: CommitteeValidatorsBits
|
aggregation_bits*: CommitteeValidatorsBits
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
|
@ -224,7 +224,7 @@ type
|
||||||
current_version*: Version
|
current_version*: Version
|
||||||
genesis_validators_root*: Eth2Digest
|
genesis_validators_root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#checkpoint
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#checkpoint
|
||||||
Checkpoint* = object
|
Checkpoint* = object
|
||||||
epoch*: Epoch
|
epoch*: Epoch
|
||||||
root*: Eth2Digest
|
root*: Eth2Digest
|
||||||
|
@ -242,20 +242,20 @@ type
|
||||||
source*: Checkpoint
|
source*: Checkpoint
|
||||||
target*: Checkpoint
|
target*: Checkpoint
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#deposit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#deposit
|
||||||
Deposit* = object
|
Deposit* = object
|
||||||
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest] ##\
|
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest] ##\
|
||||||
## Merkle path to deposit root
|
## Merkle path to deposit root
|
||||||
|
|
||||||
data*: DepositData
|
data*: DepositData
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#depositmessage
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#depositmessage
|
||||||
DepositMessage* = object
|
DepositMessage* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
amount*: Gwei
|
amount*: Gwei
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#depositdata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#depositdata
|
||||||
DepositData* = object
|
DepositData* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
|
@ -264,7 +264,7 @@ type
|
||||||
# if the deposit should be added or not during processing
|
# if the deposit should be added or not during processing
|
||||||
signature*: ValidatorSig # Signing over DepositMessage
|
signature*: ValidatorSig # Signing over DepositMessage
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#voluntaryexit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#voluntaryexit
|
||||||
VoluntaryExit* = object
|
VoluntaryExit* = object
|
||||||
epoch*: Epoch ##\
|
epoch*: Epoch ##\
|
||||||
## Earliest epoch when voluntary exit can be processed
|
## Earliest epoch when voluntary exit can be processed
|
||||||
|
@ -293,7 +293,7 @@ type
|
||||||
pubkey*: CookedPubKey
|
pubkey*: CookedPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#validator
|
||||||
Validator* = object
|
Validator* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ type
|
||||||
withdrawable_epoch*: Epoch ##\
|
withdrawable_epoch*: Epoch ##\
|
||||||
## When validator can withdraw or transfer funds
|
## When validator can withdraw or transfer funds
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#pendingattestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#pendingattestation
|
||||||
PendingAttestation* = object
|
PendingAttestation* = object
|
||||||
aggregation_bits*: CommitteeValidatorsBits
|
aggregation_bits*: CommitteeValidatorsBits
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
|
@ -324,12 +324,12 @@ type
|
||||||
|
|
||||||
proposer_index*: uint64
|
proposer_index*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#historicalbatch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#historicalbatch
|
||||||
HistoricalBatch* = object
|
HistoricalBatch* = object
|
||||||
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||||
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#fork
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#fork
|
||||||
Fork* = object
|
Fork* = object
|
||||||
previous_version*: Version
|
previous_version*: Version
|
||||||
current_version*: Version
|
current_version*: Version
|
||||||
|
@ -337,13 +337,13 @@ type
|
||||||
epoch*: Epoch ##\
|
epoch*: Epoch ##\
|
||||||
## Epoch of latest fork
|
## Epoch of latest fork
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#eth1data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#eth1data
|
||||||
Eth1Data* = object
|
Eth1Data* = object
|
||||||
deposit_root*: Eth2Digest
|
deposit_root*: Eth2Digest
|
||||||
deposit_count*: uint64
|
deposit_count*: uint64
|
||||||
block_hash*: Eth2Digest
|
block_hash*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signedvoluntaryexit
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedvoluntaryexit
|
||||||
SignedVoluntaryExit* = object
|
SignedVoluntaryExit* = object
|
||||||
message*: VoluntaryExit
|
message*: VoluntaryExit
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
@ -352,7 +352,7 @@ type
|
||||||
message*: VoluntaryExit
|
message*: VoluntaryExit
|
||||||
signature*: TrustedSig
|
signature*: TrustedSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconblockheader
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconblockheader
|
||||||
BeaconBlockHeader* = object
|
BeaconBlockHeader* = object
|
||||||
slot*: Slot
|
slot*: Slot
|
||||||
proposer_index*: uint64
|
proposer_index*: uint64
|
||||||
|
@ -360,14 +360,14 @@ type
|
||||||
state_root*: Eth2Digest
|
state_root*: Eth2Digest
|
||||||
body_root*: Eth2Digest
|
body_root*: Eth2Digest
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signingdata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signingdata
|
||||||
SigningData* = object
|
SigningData* = object
|
||||||
object_root*: Eth2Digest
|
object_root*: Eth2Digest
|
||||||
domain*: Eth2Domain
|
domain*: Eth2Domain
|
||||||
|
|
||||||
GraffitiBytes* = distinct array[MAX_GRAFFITI_SIZE, byte]
|
GraffitiBytes* = distinct array[MAX_GRAFFITI_SIZE, byte]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signedbeaconblockheader
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblockheader
|
||||||
SignedBeaconBlockHeader* = object
|
SignedBeaconBlockHeader* = object
|
||||||
message*: BeaconBlockHeader
|
message*: BeaconBlockHeader
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
@ -376,13 +376,13 @@ type
|
||||||
message*: BeaconBlockHeader
|
message*: BeaconBlockHeader
|
||||||
signature*: TrustedSig
|
signature*: TrustedSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregateandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregateandproof
|
||||||
AggregateAndProof* = object
|
AggregateAndProof* = object
|
||||||
aggregator_index*: uint64
|
aggregator_index*: uint64
|
||||||
aggregate*: Attestation
|
aggregate*: Attestation
|
||||||
selection_proof*: ValidatorSig
|
selection_proof*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#signedaggregateandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#signedaggregateandproof
|
||||||
SignedAggregateAndProof* = object
|
SignedAggregateAndProof* = object
|
||||||
message*: AggregateAndProof
|
message*: AggregateAndProof
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
@ -405,7 +405,7 @@ type
|
||||||
branch*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest]
|
branch*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest]
|
||||||
deposit_count*: array[32, byte] # Uint256
|
deposit_count*: array[32, byte] # Uint256
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#validator
|
||||||
ValidatorStatus* = object
|
ValidatorStatus* = object
|
||||||
# This is a validator without the expensive, immutable, append-only parts
|
# This is a validator without the expensive, immutable, append-only parts
|
||||||
# serialized. They're represented in memory to allow in-place SSZ reading
|
# serialized. They're represented in memory to allow in-place SSZ reading
|
||||||
|
@ -431,7 +431,7 @@ type
|
||||||
withdrawable_epoch*: Epoch ##\
|
withdrawable_epoch*: Epoch ##\
|
||||||
## When validator can withdraw or transfer funds
|
## When validator can withdraw or transfer funds
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#eth2-field
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#eth2-field
|
||||||
ENRForkID* = object
|
ENRForkID* = object
|
||||||
fork_digest*: ForkDigest
|
fork_digest*: ForkDigest
|
||||||
next_fork_version*: Version
|
next_fork_version*: Version
|
||||||
|
@ -495,7 +495,7 @@ type
|
||||||
|
|
||||||
flags*: set[RewardFlags]
|
flags*: set[RewardFlags]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
||||||
TotalBalances* = object
|
TotalBalances* = object
|
||||||
# The total effective balance of all active validators during the _current_
|
# The total effective balance of all active validators during the _current_
|
||||||
# epoch.
|
# epoch.
|
||||||
|
|
|
@ -155,7 +155,7 @@ type
|
||||||
data*: BeaconState
|
data*: BeaconState
|
||||||
root*: Eth2Digest # hash_tree_root(data)
|
root*: Eth2Digest # hash_tree_root(data)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconblock
|
||||||
BeaconBlock* = object
|
BeaconBlock* = object
|
||||||
## For each slot, a proposer is chosen from the validator pool to propose
|
## For each slot, a proposer is chosen from the validator pool to propose
|
||||||
## a new block. Once the block as been proposed, it is transmitted to
|
## a new block. Once the block as been proposed, it is transmitted to
|
||||||
|
@ -281,7 +281,7 @@ type
|
||||||
# Execution
|
# Execution
|
||||||
execution_payload*: ExecutionPayload # [New in Merge]
|
execution_payload*: ExecutionPayload # [New in Merge]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signedbeaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||||
SignedBeaconBlock* = object
|
SignedBeaconBlock* = object
|
||||||
message*: BeaconBlock
|
message*: BeaconBlock
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
|
@ -33,7 +33,7 @@ import
|
||||||
json_serialization/types as jsonTypes
|
json_serialization/types as jsonTypes
|
||||||
|
|
||||||
type
|
type
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconstate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconstate
|
||||||
BeaconState* = object
|
BeaconState* = object
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time*: uint64
|
genesis_time*: uint64
|
||||||
|
@ -96,7 +96,7 @@ type
|
||||||
data*: BeaconState
|
data*: BeaconState
|
||||||
root*: Eth2Digest # hash_tree_root(data)
|
root*: Eth2Digest # hash_tree_root(data)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconblock
|
||||||
BeaconBlock* = object
|
BeaconBlock* = object
|
||||||
## For each slot, a proposer is chosen from the validator pool to propose
|
## For each slot, a proposer is chosen from the validator pool to propose
|
||||||
## a new block. Once the block as been proposed, it is transmitted to
|
## a new block. Once the block as been proposed, it is transmitted to
|
||||||
|
@ -115,7 +115,7 @@ type
|
||||||
|
|
||||||
body*: BeaconBlockBody
|
body*: BeaconBlockBody
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#metadata
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#metadata
|
||||||
MetaData* = object
|
MetaData* = object
|
||||||
seq_number*: uint64
|
seq_number*: uint64
|
||||||
attnets*: AttnetBits
|
attnets*: AttnetBits
|
||||||
|
@ -157,7 +157,7 @@ type
|
||||||
state_root*: Eth2Digest ##\
|
state_root*: Eth2Digest ##\
|
||||||
body*: TrustedBeaconBlockBody
|
body*: TrustedBeaconBlockBody
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beaconblockbody
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beaconblockbody
|
||||||
BeaconBlockBody* = object
|
BeaconBlockBody* = object
|
||||||
randao_reveal*: ValidatorSig
|
randao_reveal*: ValidatorSig
|
||||||
eth1_data*: Eth1Data
|
eth1_data*: Eth1Data
|
||||||
|
@ -206,7 +206,7 @@ type
|
||||||
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
||||||
voluntary_exits*: List[TrustedSignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
voluntary_exits*: List[TrustedSignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#signedbeaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||||
SignedBeaconBlock* = object
|
SignedBeaconBlock* = object
|
||||||
message*: BeaconBlock
|
message*: BeaconBlock
|
||||||
signature*: ValidatorSig
|
signature*: ValidatorSig
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
# Serenity hash function / digest
|
# Serenity hash function / digest
|
||||||
#
|
#
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#hash
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#hash
|
||||||
#
|
#
|
||||||
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
||||||
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
||||||
|
|
|
@ -303,7 +303,7 @@ type
|
||||||
DEPOSIT_NETWORK_ID*: uint64
|
DEPOSIT_NETWORK_ID*: uint64
|
||||||
DEPOSIT_CONTRACT_ADDRESS*: Eth1Address
|
DEPOSIT_CONTRACT_ADDRESS*: Eth1Address
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#constants
|
||||||
# GENESIS_SLOT
|
# GENESIS_SLOT
|
||||||
# GENESIS_EPOCH
|
# GENESIS_EPOCH
|
||||||
# FAR_FUTURE_EPOCH
|
# FAR_FUTURE_EPOCH
|
||||||
|
@ -321,7 +321,7 @@ type
|
||||||
DOMAIN_SELECTION_PROOF*: DomainType
|
DOMAIN_SELECTION_PROOF*: DomainType
|
||||||
DOMAIN_AGGREGATE_AND_PROOF*: DomainType
|
DOMAIN_AGGREGATE_AND_PROOF*: DomainType
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#constants
|
||||||
TIMELY_SOURCE_FLAG_INDEX*: byte
|
TIMELY_SOURCE_FLAG_INDEX*: byte
|
||||||
TIMELY_TARGET_FLAG_INDEX*: byte
|
TIMELY_TARGET_FLAG_INDEX*: byte
|
||||||
TIMELY_HEAD_FLAG_INDEX*: byte
|
TIMELY_HEAD_FLAG_INDEX*: byte
|
||||||
|
@ -336,13 +336,13 @@ type
|
||||||
DOMAIN_CONTRIBUTION_AND_PROOF*: DomainType
|
DOMAIN_CONTRIBUTION_AND_PROOF*: DomainType
|
||||||
# PARTICIPATION_FLAG_WEIGHTS
|
# PARTICIPATION_FLAG_WEIGHTS
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#constants
|
||||||
TARGET_AGGREGATORS_PER_COMMITTEE*: uint64
|
TARGET_AGGREGATORS_PER_COMMITTEE*: uint64
|
||||||
RANDOM_SUBNETS_PER_VALIDATOR*: uint64
|
RANDOM_SUBNETS_PER_VALIDATOR*: uint64
|
||||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64
|
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64
|
||||||
ATTESTATION_SUBNET_COUNT*: uint64
|
ATTESTATION_SUBNET_COUNT*: uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#constants
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#constants
|
||||||
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE*: uint64
|
TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE*: uint64
|
||||||
SYNC_COMMITTEE_SUBNET_COUNT*: uint64
|
SYNC_COMMITTEE_SUBNET_COUNT*: uint64
|
||||||
|
|
||||||
|
|
|
@ -470,7 +470,7 @@ func toBeaconBlockFork*(fork: BeaconStateFork): BeaconBlockFork =
|
||||||
of BeaconStateFork.Altair: BeaconBlockFork.Altair
|
of BeaconStateFork.Altair: BeaconBlockFork.Altair
|
||||||
of BeaconStateFork.Merge: BeaconBlockFork.Merge
|
of BeaconStateFork.Merge: BeaconBlockFork.Merge
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_fork_data_root
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_fork_data_root
|
||||||
func compute_fork_data_root*(current_version: Version,
|
func compute_fork_data_root*(current_version: Version,
|
||||||
genesis_validators_root: Eth2Digest): Eth2Digest =
|
genesis_validators_root: Eth2Digest): Eth2Digest =
|
||||||
## Return the 32-byte fork data root for the ``current_version`` and
|
## Return the 32-byte fork data root for the ``current_version`` and
|
||||||
|
@ -482,7 +482,7 @@ func compute_fork_data_root*(current_version: Version,
|
||||||
genesis_validators_root: genesis_validators_root
|
genesis_validators_root: genesis_validators_root
|
||||||
))
|
))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_fork_digest
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_fork_digest
|
||||||
func compute_fork_digest*(current_version: Version,
|
func compute_fork_digest*(current_version: Version,
|
||||||
genesis_validators_root: Eth2Digest): ForkDigest =
|
genesis_validators_root: Eth2Digest): ForkDigest =
|
||||||
## Return the 4-byte fork digest for the ``current_version`` and
|
## Return the 4-byte fork digest for the ``current_version`` and
|
||||||
|
|
|
@ -24,7 +24,7 @@ import
|
||||||
export
|
export
|
||||||
forks, eth2_merkleization, ssz_codec
|
forks, eth2_merkleization, ssz_codec
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#integer_squareroot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#integer_squareroot
|
||||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
## Return the largest integer ``x`` such that ``x**2 <= n``.
|
## Return the largest integer ``x`` such that ``x**2 <= n``.
|
||||||
doAssert n >= 0'u64
|
doAssert n >= 0'u64
|
||||||
|
@ -37,7 +37,7 @@ func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||||
y = (x + n div x) div 2
|
y = (x + n div x) div 2
|
||||||
x
|
x
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_epoch_at_slot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_epoch_at_slot
|
||||||
func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
|
func compute_epoch_at_slot*(slot: Slot|uint64): Epoch =
|
||||||
## Return the epoch number at ``slot``.
|
## Return the epoch number at ``slot``.
|
||||||
(slot div SLOTS_PER_EPOCH).Epoch
|
(slot div SLOTS_PER_EPOCH).Epoch
|
||||||
|
@ -279,7 +279,7 @@ func verify_merkle_multiproof*(
|
||||||
if calc.isErr: return false
|
if calc.isErr: return false
|
||||||
calc.get == root
|
calc.get == root
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_valid_merkle_branch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_valid_merkle_branch
|
||||||
func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openArray[Eth2Digest],
|
func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openArray[Eth2Digest],
|
||||||
depth: int, index: uint64,
|
depth: int, index: uint64,
|
||||||
root: Eth2Digest): bool =
|
root: Eth2Digest): bool =
|
||||||
|
@ -352,19 +352,19 @@ func build_proof*(anchor: object, leaf_index: uint64,
|
||||||
doAssert proof.len == log2trunc(leaf_index)
|
doAssert proof.len == log2trunc(leaf_index)
|
||||||
build_proof_impl(anchor, leaf_index, proof)
|
build_proof_impl(anchor, leaf_index, proof)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#sync-committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#sync-committee
|
||||||
template sync_committee_period*(epoch: Epoch): SyncCommitteePeriod =
|
template sync_committee_period*(epoch: Epoch): SyncCommitteePeriod =
|
||||||
(epoch div EPOCHS_PER_SYNC_COMMITTEE_PERIOD).SyncCommitteePeriod
|
(epoch div EPOCHS_PER_SYNC_COMMITTEE_PERIOD).SyncCommitteePeriod
|
||||||
|
|
||||||
template sync_committee_period*(slot: Slot): SyncCommitteePeriod =
|
template sync_committee_period*(slot: Slot): SyncCommitteePeriod =
|
||||||
sync_committee_period(epoch(slot))
|
sync_committee_period(epoch(slot))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
|
||||||
func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
|
func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
|
||||||
## Return the start slot of ``epoch``.
|
## Return the start slot of ``epoch``.
|
||||||
(epoch * SLOTS_PER_EPOCH).Slot
|
(epoch * SLOTS_PER_EPOCH).Slot
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_active_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_active_validator
|
||||||
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
## Check if ``validator`` is active
|
## Check if ``validator`` is active
|
||||||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
||||||
|
@ -376,7 +376,7 @@ func is_exited_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
func is_withdrawable_validator*(validator: Validator, epoch: Epoch): bool =
|
func is_withdrawable_validator*(validator: Validator, epoch: Epoch): bool =
|
||||||
epoch >= validator.withdrawable_epoch
|
epoch >= validator.withdrawable_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||||
iterator get_active_validator_indices*(state: ForkyBeaconState, epoch: Epoch):
|
iterator get_active_validator_indices*(state: ForkyBeaconState, epoch: Epoch):
|
||||||
ValidatorIndex =
|
ValidatorIndex =
|
||||||
for idx in 0..<state.validators.len:
|
for idx in 0..<state.validators.len:
|
||||||
|
@ -402,18 +402,18 @@ func get_active_validator_indices_len*(
|
||||||
withState(state):
|
withState(state):
|
||||||
get_active_validator_indices_len(state.data, epoch)
|
get_active_validator_indices_len(state.data, epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_current_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_current_epoch
|
||||||
func get_current_epoch*(state: ForkyBeaconState): Epoch =
|
func get_current_epoch*(state: ForkyBeaconState): Epoch =
|
||||||
## Return the current epoch.
|
## Return the current epoch.
|
||||||
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
doAssert state.slot >= GENESIS_SLOT, $state.slot
|
||||||
compute_epoch_at_slot(state.slot)
|
compute_epoch_at_slot(state.slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_current_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_current_epoch
|
||||||
func get_current_epoch*(state: ForkedHashedBeaconState): Epoch =
|
func get_current_epoch*(state: ForkedHashedBeaconState): Epoch =
|
||||||
## Return the current epoch.
|
## Return the current epoch.
|
||||||
withState(state): state.data.slot.epoch
|
withState(state): state.data.slot.epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_randao_mix
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_randao_mix
|
||||||
func get_randao_mix*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
func get_randao_mix*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
||||||
## Returns the randao mix at a recent ``epoch``.
|
## Returns the randao mix at a recent ``epoch``.
|
||||||
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
|
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
|
||||||
|
@ -438,7 +438,7 @@ func uint_to_bytes4*(x: uint64): array[4, byte] =
|
||||||
result[2] = ((x shr 16) and 0xff).byte
|
result[2] = ((x shr 16) and 0xff).byte
|
||||||
result[3] = ((x shr 24) and 0xff).byte
|
result[3] = ((x shr 24) and 0xff).byte
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_domain
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_domain
|
||||||
func compute_domain*(
|
func compute_domain*(
|
||||||
domain_type: DomainType,
|
domain_type: DomainType,
|
||||||
fork_version: Version,
|
fork_version: Version,
|
||||||
|
@ -449,7 +449,7 @@ func compute_domain*(
|
||||||
result[0..3] = uint_to_bytes4(domain_type.uint64)
|
result[0..3] = uint_to_bytes4(domain_type.uint64)
|
||||||
result[4..31] = fork_data_root.data.toOpenArray(0, 27)
|
result[4..31] = fork_data_root.data.toOpenArray(0, 27)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_domain
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_domain
|
||||||
func get_domain*(
|
func get_domain*(
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
domain_type: DomainType,
|
domain_type: DomainType,
|
||||||
|
@ -470,7 +470,7 @@ func get_domain*(
|
||||||
## of a message.
|
## of a message.
|
||||||
get_domain(state.fork, domain_type, epoch, state.genesis_validators_root)
|
get_domain(state.fork, domain_type, epoch, state.genesis_validators_root)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_signing_root
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_signing_root
|
||||||
func compute_signing_root*(ssz_object: auto, domain: Eth2Domain): Eth2Digest =
|
func compute_signing_root*(ssz_object: auto, domain: Eth2Domain): Eth2Digest =
|
||||||
## Return the signing root of an object by calculating the root of the
|
## Return the signing root of an object by calculating the root of the
|
||||||
## object-domain tree.
|
## object-domain tree.
|
||||||
|
@ -480,7 +480,7 @@ func compute_signing_root*(ssz_object: auto, domain: Eth2Domain): Eth2Digest =
|
||||||
)
|
)
|
||||||
hash_tree_root(domain_wrapped_object)
|
hash_tree_root(domain_wrapped_object)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_seed
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_seed
|
||||||
func get_seed*(state: ForkyBeaconState, epoch: Epoch, domain_type: DomainType):
|
func get_seed*(state: ForkyBeaconState, epoch: Epoch, domain_type: DomainType):
|
||||||
Eth2Digest =
|
Eth2Digest =
|
||||||
## Return the seed at ``epoch``.
|
## Return the seed at ``epoch``.
|
||||||
|
@ -498,17 +498,17 @@ func get_seed*(state: ForkyBeaconState, epoch: Epoch, domain_type: DomainType):
|
||||||
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data
|
epoch + EPOCHS_PER_HISTORICAL_VECTOR - MIN_SEED_LOOKAHEAD - 1).data
|
||||||
eth2digest(seed_input)
|
eth2digest(seed_input)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#add_flag
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#add_flag
|
||||||
func add_flag*(flags: ParticipationFlags, flag_index: int): ParticipationFlags =
|
func add_flag*(flags: ParticipationFlags, flag_index: int): ParticipationFlags =
|
||||||
let flag = ParticipationFlags(1'u8 shl flag_index)
|
let flag = ParticipationFlags(1'u8 shl flag_index)
|
||||||
flags or flag
|
flags or flag
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#has_flag
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#has_flag
|
||||||
func has_flag*(flags: ParticipationFlags, flag_index: int): bool =
|
func has_flag*(flags: ParticipationFlags, flag_index: int): bool =
|
||||||
let flag = ParticipationFlags(1'u8 shl flag_index)
|
let flag = ParticipationFlags(1'u8 shl flag_index)
|
||||||
(flags and flag) == flag
|
(flags and flag) == flag
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/sync-protocol.md#get_subtree_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/sync-protocol.md#get_subtree_index
|
||||||
func get_subtree_index*(idx: GeneralizedIndex): uint64 =
|
func get_subtree_index*(idx: GeneralizedIndex): uint64 =
|
||||||
doAssert idx > 0
|
doAssert idx > 0
|
||||||
uint64(idx mod (type(idx)(1) shl log2trunc(idx)))
|
uint64(idx mod (type(idx)(1) shl log2trunc(idx)))
|
||||||
|
|
|
@ -14,14 +14,14 @@ import
|
||||||
export base
|
export base
|
||||||
|
|
||||||
const
|
const
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#topics-and-messages
|
||||||
topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy"
|
topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy"
|
||||||
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy"
|
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy"
|
||||||
topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy"
|
topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy"
|
||||||
topicAttesterSlashingsSuffix* = "attester_slashing/ssz_snappy"
|
topicAttesterSlashingsSuffix* = "attester_slashing/ssz_snappy"
|
||||||
topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz_snappy"
|
topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz_snappy"
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#configuration
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#configuration
|
||||||
MAX_CHUNK_SIZE* = 1 * 1024 * 1024 # bytes
|
MAX_CHUNK_SIZE* = 1 * 1024 * 1024 # bytes
|
||||||
GOSSIP_MAX_SIZE* = 1 * 1024 * 1024 # bytes
|
GOSSIP_MAX_SIZE* = 1 * 1024 * 1024 # bytes
|
||||||
TTFB_TIMEOUT* = 5.seconds
|
TTFB_TIMEOUT* = 5.seconds
|
||||||
|
@ -61,7 +61,7 @@ func getAttesterSlashingsTopic*(forkDigest: ForkDigest): string =
|
||||||
func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
|
func getAggregateAndProofsTopic*(forkDigest: ForkDigest): string =
|
||||||
eth2Prefix(forkDigest) & topicAggregateAndProofsSuffix
|
eth2Prefix(forkDigest) & topicAggregateAndProofsSuffix
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#broadcast-attestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-attestation
|
||||||
func compute_subnet_for_attestation*(
|
func compute_subnet_for_attestation*(
|
||||||
committees_per_slot: uint64, slot: Slot, committee_index: CommitteeIndex):
|
committees_per_slot: uint64, slot: Slot, committee_index: CommitteeIndex):
|
||||||
SubnetId =
|
SubnetId =
|
||||||
|
@ -77,19 +77,19 @@ func compute_subnet_for_attestation*(
|
||||||
(committees_since_epoch_start + committee_index.uint64) mod
|
(committees_since_epoch_start + committee_index.uint64) mod
|
||||||
ATTESTATION_SUBNET_COUNT)
|
ATTESTATION_SUBNET_COUNT)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#broadcast-attestation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-attestation
|
||||||
func getAttestationTopic*(forkDigest: ForkDigest,
|
func getAttestationTopic*(forkDigest: ForkDigest,
|
||||||
subnetId: SubnetId): string =
|
subnetId: SubnetId): string =
|
||||||
## For subscribing and unsubscribing to/from a subnet.
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy"
|
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy"
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||||
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
|
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
|
||||||
subcommitteeIdx: SyncSubcommitteeIndex): string =
|
subcommitteeIdx: SyncSubcommitteeIndex): string =
|
||||||
## For subscribing and unsubscribing to/from a subnet.
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
eth2Prefix(forkDigest) & "sync_committee_" & $(subcommitteeIdx.asUInt8) & "/ssz_snappy"
|
eth2Prefix(forkDigest) & "sync_committee_" & $(subcommitteeIdx.asUInt8) & "/ssz_snappy"
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#topics-and-messages
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||||
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
|
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
|
||||||
## For subscribing and unsubscribing to/from a subnet.
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy"
|
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy"
|
||||||
|
@ -126,7 +126,7 @@ func getDiscoveryForkID*(cfg: RuntimeConfig,
|
||||||
next_fork_version: current_fork_version,
|
next_fork_version: current_fork_version,
|
||||||
next_fork_epoch: FAR_FUTURE_EPOCH)
|
next_fork_epoch: FAR_FUTURE_EPOCH)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/p2p-interface.md#transitioning-the-gossip
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||||
func getTargetGossipState*(
|
func getTargetGossipState*(
|
||||||
epoch, ALTAIR_FORK_EPOCH, MERGE_FORK_EPOCH: Epoch, isBehind: bool):
|
epoch, ALTAIR_FORK_EPOCH, MERGE_FORK_EPOCH: Epoch, isBehind: bool):
|
||||||
set[BeaconStateFork] =
|
set[BeaconStateFork] =
|
||||||
|
|
|
@ -15,7 +15,7 @@ export
|
||||||
toBytesBE
|
toBytesBE
|
||||||
|
|
||||||
const
|
const
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#withdrawal-prefixes
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#withdrawal-prefixes
|
||||||
BLS_WITHDRAWAL_PREFIX*: byte = 0
|
BLS_WITHDRAWAL_PREFIX*: byte = 0
|
||||||
ETH1_ADDRESS_WITHDRAWAL_PREFIX*: byte = 1
|
ETH1_ADDRESS_WITHDRAWAL_PREFIX*: byte = 1
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ func compute_slot_signing_root*(
|
||||||
fork, DOMAIN_SELECTION_PROOF, epoch, genesis_validators_root)
|
fork, DOMAIN_SELECTION_PROOF, epoch, genesis_validators_root)
|
||||||
compute_signing_root(slot, domain)
|
compute_signing_root(slot, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregation-selection
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregation-selection
|
||||||
func get_slot_signature*(
|
func get_slot_signature*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
privkey: ValidatorPrivKey): CookedSig =
|
privkey: ValidatorPrivKey): CookedSig =
|
||||||
|
@ -66,7 +66,7 @@ func compute_epoch_signing_root*(
|
||||||
let domain = get_domain(fork, DOMAIN_RANDAO, epoch, genesis_validators_root)
|
let domain = get_domain(fork, DOMAIN_RANDAO, epoch, genesis_validators_root)
|
||||||
compute_signing_root(epoch, domain)
|
compute_signing_root(epoch, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#randao-reveal
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#randao-reveal
|
||||||
func get_epoch_signature*(
|
func get_epoch_signature*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest, epoch: Epoch,
|
fork: Fork, genesis_validators_root: Eth2Digest, epoch: Epoch,
|
||||||
privkey: ValidatorPrivKey): CookedSig =
|
privkey: ValidatorPrivKey): CookedSig =
|
||||||
|
@ -93,7 +93,7 @@ func compute_block_signing_root*(
|
||||||
fork, DOMAIN_BEACON_PROPOSER, epoch, genesis_validators_root)
|
fork, DOMAIN_BEACON_PROPOSER, epoch, genesis_validators_root)
|
||||||
compute_signing_root(blck, domain)
|
compute_signing_root(blck, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#signature
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#signature
|
||||||
func get_block_signature*(
|
func get_block_signature*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
fork: Fork, genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
root: Eth2Digest, privkey: ValidatorPrivKey): CookedSig =
|
root: Eth2Digest, privkey: ValidatorPrivKey): CookedSig =
|
||||||
|
@ -122,7 +122,7 @@ func compute_aggregate_and_proof_signing_root*(
|
||||||
fork, DOMAIN_AGGREGATE_AND_PROOF, epoch, genesis_validators_root)
|
fork, DOMAIN_AGGREGATE_AND_PROOF, epoch, genesis_validators_root)
|
||||||
compute_signing_root(aggregate_and_proof, domain)
|
compute_signing_root(aggregate_and_proof, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#broadcast-aggregate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-aggregate
|
||||||
func get_aggregate_and_proof_signature*(fork: Fork, genesis_validators_root: Eth2Digest,
|
func get_aggregate_and_proof_signature*(fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
aggregate_and_proof: AggregateAndProof,
|
aggregate_and_proof: AggregateAndProof,
|
||||||
privKey: ValidatorPrivKey): CookedSig =
|
privKey: ValidatorPrivKey): CookedSig =
|
||||||
|
@ -150,7 +150,7 @@ func compute_attestation_signing_root*(
|
||||||
fork, DOMAIN_BEACON_ATTESTER, epoch, genesis_validators_root)
|
fork, DOMAIN_BEACON_ATTESTER, epoch, genesis_validators_root)
|
||||||
compute_signing_root(attestation_data, domain)
|
compute_signing_root(attestation_data, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregate-signature
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregate-signature
|
||||||
func get_attestation_signature*(
|
func get_attestation_signature*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
attestation_data: AttestationData,
|
attestation_data: AttestationData,
|
||||||
|
@ -178,7 +178,7 @@ func compute_deposit_signing_root*(
|
||||||
domain = compute_domain(DOMAIN_DEPOSIT, version)
|
domain = compute_domain(DOMAIN_DEPOSIT, version)
|
||||||
compute_signing_root(deposit_message, domain)
|
compute_signing_root(deposit_message, domain)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#deposits
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#deposits
|
||||||
func get_deposit_signature*(preset: RuntimeConfig,
|
func get_deposit_signature*(preset: RuntimeConfig,
|
||||||
deposit: DepositData,
|
deposit: DepositData,
|
||||||
privkey: ValidatorPrivKey): CookedSig =
|
privkey: ValidatorPrivKey): CookedSig =
|
||||||
|
@ -230,7 +230,7 @@ proc verify_voluntary_exit_signature*(
|
||||||
|
|
||||||
blsVerify(pubkey, signing_root.data, signature)
|
blsVerify(pubkey, signing_root.data, signature)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#prepare-sync-committee-message
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#prepare-sync-committee-message
|
||||||
func compute_sync_committee_message_signing_root*(
|
func compute_sync_committee_message_signing_root*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
slot: Slot, beacon_block_root: Eth2Digest): Eth2Digest =
|
slot: Slot, beacon_block_root: Eth2Digest): Eth2Digest =
|
||||||
|
@ -265,7 +265,7 @@ proc verify_sync_committee_signature*(
|
||||||
|
|
||||||
blsFastAggregateVerify(pubkeys, signing_root.data, signature)
|
blsFastAggregateVerify(pubkeys, signing_root.data, signature)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#aggregation-selection
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#aggregation-selection
|
||||||
func compute_sync_committee_selection_proof_signing_root*(
|
func compute_sync_committee_selection_proof_signing_root*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
slot: Slot, subcommittee_index: uint64): Eth2Digest =
|
slot: Slot, subcommittee_index: uint64): Eth2Digest =
|
||||||
|
@ -296,7 +296,7 @@ proc verify_sync_committee_selection_proof*(
|
||||||
|
|
||||||
blsVerify(pubkey, signing_root.data, signature)
|
blsVerify(pubkey, signing_root.data, signature)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#signature
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#signature
|
||||||
func compute_contribution_and_proof_signing_root*(
|
func compute_contribution_and_proof_signing_root*(
|
||||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||||
msg: ContributionAndProof): Eth2Digest =
|
msg: ContributionAndProof): Eth2Digest =
|
||||||
|
@ -315,7 +315,7 @@ proc get_contribution_and_proof_signature*(
|
||||||
blsSign(privkey, signing_root.data)
|
blsSign(privkey, signing_root.data)
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#aggregation-selection
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#aggregation-selection
|
||||||
proc is_sync_committee_aggregator*(signature: ValidatorSig): bool =
|
proc is_sync_committee_aggregator*(signature: ValidatorSig): bool =
|
||||||
let
|
let
|
||||||
signatureDigest = eth2digest(signature.blob)
|
signatureDigest = eth2digest(signature.blob)
|
||||||
|
|
|
@ -74,7 +74,7 @@ proc aggregateAttesters(
|
||||||
# Aggregation spec requires non-empty collection
|
# Aggregation spec requires non-empty collection
|
||||||
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
|
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
|
||||||
# Eth2 spec requires at least one attesting index in attestation
|
# Eth2 spec requires at least one attesting index in attestation
|
||||||
# - https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
# - https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||||
return err("aggregateAttesters: no attesting indices")
|
return err("aggregateAttesters: no attesting indices")
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
# State transition, as described in
|
# State transition, as described in
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
#
|
#
|
||||||
# The entry point is `state_transition` which is at the bottom of the file!
|
# The entry point is `state_transition` which is at the bottom of the file!
|
||||||
#
|
#
|
||||||
|
@ -55,7 +55,7 @@ export extras, phase0, altair
|
||||||
|
|
||||||
type Foo = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock | merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock
|
type Foo = phase0.SignedBeaconBlock | altair.SignedBeaconBlock | phase0.TrustedSignedBeaconBlock | altair.TrustedSignedBeaconBlock | phase0.SigVerifiedSignedBeaconBlock | altair.SigVerifiedSignedBeaconBlock | merge.TrustedSignedBeaconBlock | merge.SigVerifiedSignedBeaconBlock | merge.SignedBeaconBlock
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verify_block_signature(
|
proc verify_block_signature(
|
||||||
#state: ForkyBeaconState, signed_block: SomeSomeSignedBeaconBlock): bool =
|
#state: ForkyBeaconState, signed_block: SomeSomeSignedBeaconBlock): bool =
|
||||||
state: ForkyBeaconState, signed_block: Foo): bool =
|
state: ForkyBeaconState, signed_block: Foo): bool =
|
||||||
|
@ -77,7 +77,7 @@ proc verify_block_signature(
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verifyStateRoot(state: ForkyBeaconState, blck: phase0.BeaconBlock or phase0.SigVerifiedBeaconBlock or altair.BeaconBlock or altair.SigVerifiedBeaconBlock or merge.BeaconBlock or merge.SigVerifiedBeaconBlock or merge.TrustedBeaconBlock): bool =
|
proc verifyStateRoot(state: ForkyBeaconState, blck: phase0.BeaconBlock or phase0.SigVerifiedBeaconBlock or altair.BeaconBlock or altair.SigVerifiedBeaconBlock or merge.BeaconBlock or merge.SigVerifiedBeaconBlock or merge.TrustedBeaconBlock): bool =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
let state_root = hash_tree_root(state)
|
let state_root = hash_tree_root(state)
|
||||||
|
@ -132,7 +132,7 @@ type
|
||||||
# Hashed-state transition functions
|
# Hashed-state transition functions
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
func process_slot*(
|
func process_slot*(
|
||||||
state: var ForkyBeaconState, pre_state_root: Eth2Digest) =
|
state: var ForkyBeaconState, pre_state_root: Eth2Digest) =
|
||||||
# `process_slot` is the first stage of per-slot processing - it is run for
|
# `process_slot` is the first stage of per-slot processing - it is run for
|
||||||
|
@ -357,7 +357,7 @@ 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.1.6/specs/phase0/validator.md#preparing-for-a-beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#preparing-for-a-beaconblock
|
||||||
template partialBeaconBlock(
|
template partialBeaconBlock(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var phase0.HashedBeaconState,
|
state: var phase0.HashedBeaconState,
|
||||||
|
@ -426,7 +426,7 @@ proc makeBeaconBlock*(
|
||||||
blck.state_root = state.root
|
blck.state_root = state.root
|
||||||
ok(blck)
|
ok(blck)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#preparing-a-beaconblock
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#preparing-a-beaconblock
|
||||||
template partialBeaconBlock(
|
template partialBeaconBlock(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var altair.HashedBeaconState,
|
state: var altair.HashedBeaconState,
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
# State transition - block processing, as described in
|
# State transition - block processing, as described in
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#block-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#block-processing
|
||||||
#
|
#
|
||||||
# The entry point is `process_block` which is at the bottom of this file.
|
# The entry point is `process_block` which is at the bottom of this file.
|
||||||
#
|
#
|
||||||
|
@ -28,7 +28,7 @@ import
|
||||||
|
|
||||||
export extras, phase0, altair
|
export extras, phase0, altair
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#block-header
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#block-header
|
||||||
func process_block_header*(
|
func process_block_header*(
|
||||||
state: var ForkyBeaconState, blck: SomeSomeBeaconBlock, flags: UpdateFlags,
|
state: var ForkyBeaconState, blck: SomeSomeBeaconBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
|
@ -71,7 +71,7 @@ func `xor`[T: array](a, b: T): T =
|
||||||
for i in 0..<result.len:
|
for i in 0..<result.len:
|
||||||
result[i] = a[i] xor b[i]
|
result[i] = a[i] xor b[i]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#randao
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#randao
|
||||||
proc process_randao(
|
proc process_randao(
|
||||||
state: var ForkyBeaconState, body: SomeSomeBeaconBlockBody, flags: UpdateFlags,
|
state: var ForkyBeaconState, body: SomeSomeBeaconBlockBody, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
|
@ -104,7 +104,7 @@ proc process_randao(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#eth1-data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#eth1-data
|
||||||
func process_eth1_data(state: var ForkyBeaconState, body: SomeSomeBeaconBlockBody): Result[void, cstring]=
|
func process_eth1_data(state: var ForkyBeaconState, body: SomeSomeBeaconBlockBody): Result[void, cstring]=
|
||||||
if not state.eth1_data_votes.add body.eth1_data:
|
if not state.eth1_data_votes.add body.eth1_data:
|
||||||
# Count is reset in process_final_updates, so this should never happen
|
# Count is reset in process_final_updates, so this should never happen
|
||||||
|
@ -115,14 +115,14 @@ func process_eth1_data(state: var ForkyBeaconState, body: SomeSomeBeaconBlockBod
|
||||||
state.eth1_data = body.eth1_data
|
state.eth1_data = body.eth1_data
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_slashable_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_slashable_validator
|
||||||
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
||||||
# Check if ``validator`` is slashable.
|
# Check if ``validator`` is slashable.
|
||||||
(not validator.slashed) and
|
(not validator.slashed) and
|
||||||
(validator.activation_epoch <= epoch) and
|
(validator.activation_epoch <= epoch) and
|
||||||
(epoch < validator.withdrawable_epoch)
|
(epoch < validator.withdrawable_epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#proposer-slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#proposer-slashings
|
||||||
proc check_proposer_slashing*(
|
proc check_proposer_slashing*(
|
||||||
state: var ForkyBeaconState, proposer_slashing: SomeProposerSlashing,
|
state: var ForkyBeaconState, proposer_slashing: SomeProposerSlashing,
|
||||||
flags: UpdateFlags):
|
flags: UpdateFlags):
|
||||||
|
@ -171,7 +171,7 @@ proc check_proposer_slashing*(
|
||||||
withState(state):
|
withState(state):
|
||||||
check_proposer_slashing(state.data, proposer_slashing, flags)
|
check_proposer_slashing(state.data, proposer_slashing, flags)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#proposer-slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#proposer-slashings
|
||||||
proc process_proposer_slashing*(
|
proc process_proposer_slashing*(
|
||||||
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||||
proposer_slashing: SomeProposerSlashing, flags: UpdateFlags,
|
proposer_slashing: SomeProposerSlashing, flags: UpdateFlags,
|
||||||
|
@ -184,7 +184,7 @@ proc process_proposer_slashing*(
|
||||||
cache)
|
cache)
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#is_slashable_attestation_data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#is_slashable_attestation_data
|
||||||
func is_slashable_attestation_data(
|
func is_slashable_attestation_data(
|
||||||
data_1: AttestationData, data_2: AttestationData): bool =
|
data_1: AttestationData, data_2: AttestationData): bool =
|
||||||
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
## Check if ``data_1`` and ``data_2`` are slashable according to Casper FFG
|
||||||
|
@ -196,7 +196,7 @@ func is_slashable_attestation_data(
|
||||||
(data_1.source.epoch < data_2.source.epoch and
|
(data_1.source.epoch < data_2.source.epoch and
|
||||||
data_2.target.epoch < data_1.target.epoch)
|
data_2.target.epoch < data_1.target.epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attester-slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attester-slashings
|
||||||
proc check_attester_slashing*(
|
proc check_attester_slashing*(
|
||||||
state: var ForkyBeaconState,
|
state: var ForkyBeaconState,
|
||||||
attester_slashing: SomeAttesterSlashing,
|
attester_slashing: SomeAttesterSlashing,
|
||||||
|
@ -236,7 +236,7 @@ proc check_attester_slashing*(
|
||||||
withState(state):
|
withState(state):
|
||||||
check_attester_slashing(state.data, attester_slashing, flags)
|
check_attester_slashing(state.data, attester_slashing, flags)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attester-slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attester-slashings
|
||||||
proc process_attester_slashing*(
|
proc process_attester_slashing*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var ForkyBeaconState,
|
state: var ForkyBeaconState,
|
||||||
|
@ -322,7 +322,7 @@ proc process_deposit*(cfg: RuntimeConfig,
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#voluntary-exits
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#voluntary-exits
|
||||||
proc check_voluntary_exit*(
|
proc check_voluntary_exit*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: ForkyBeaconState,
|
state: ForkyBeaconState,
|
||||||
|
@ -382,7 +382,7 @@ proc check_voluntary_exit*(
|
||||||
withState(state):
|
withState(state):
|
||||||
check_voluntary_exit(cfg, state.data, signed_voluntary_exit, flags)
|
check_voluntary_exit(cfg, state.data, signed_voluntary_exit, flags)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#voluntary-exits
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#voluntary-exits
|
||||||
proc process_voluntary_exit*(
|
proc process_voluntary_exit*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var ForkyBeaconState,
|
state: var ForkyBeaconState,
|
||||||
|
@ -395,7 +395,7 @@ proc process_voluntary_exit*(
|
||||||
cache)
|
cache)
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#operations
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#operations
|
||||||
proc process_operations(cfg: RuntimeConfig,
|
proc process_operations(cfg: RuntimeConfig,
|
||||||
state: var ForkyBeaconState,
|
state: var ForkyBeaconState,
|
||||||
body: SomeSomeBeaconBlockBody,
|
body: SomeSomeBeaconBlockBody,
|
||||||
|
@ -530,7 +530,7 @@ proc process_execution_payload*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#block-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#block-processing
|
||||||
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
||||||
# copy of datatypes/phase0.nim
|
# copy of datatypes/phase0.nim
|
||||||
type SomePhase0Block =
|
type SomePhase0Block =
|
||||||
|
@ -562,7 +562,7 @@ proc process_block*(
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
err("process_block: Merge state with Phase 0 block")
|
err("process_block: Merge state with Phase 0 block")
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#block-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#block-processing
|
||||||
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
||||||
# copy of datatypes/altair.nim
|
# copy of datatypes/altair.nim
|
||||||
type SomeAltairBlock =
|
type SomeAltairBlock =
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
# State transition - epoch processing, as described in
|
# State transition - epoch processing, as described in
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#epoch-processing and
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#epoch-processing and
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#epoch-processing
|
||||||
#
|
#
|
||||||
# The entry point is `process_epoch`, which is at the bottom of this file.
|
# The entry point is `process_epoch`, which is at the bottom of this file.
|
||||||
#
|
#
|
||||||
|
@ -35,7 +35,7 @@ export extras, phase0, altair
|
||||||
logScope: topics = "consens"
|
logScope: topics = "consens"
|
||||||
|
|
||||||
# Accessors that implement the max condition in `get_total_balance`:
|
# Accessors that implement the max condition in `get_total_balance`:
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
||||||
template current_epoch*(v: TotalBalances): Gwei =
|
template current_epoch*(v: TotalBalances): Gwei =
|
||||||
max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw)
|
max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw)
|
||||||
template previous_epoch*(v: TotalBalances): Gwei =
|
template previous_epoch*(v: TotalBalances): Gwei =
|
||||||
|
@ -167,8 +167,8 @@ func is_eligible_validator*(validator: ParticipationInfo): bool =
|
||||||
# Spec
|
# Spec
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_unslashed_participating_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_unslashed_participating_indices
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_total_balance
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_total_balance
|
||||||
func get_unslashed_participating_balances*(state: altair.BeaconState | merge.BeaconState):
|
func get_unslashed_participating_balances*(state: altair.BeaconState | merge.BeaconState):
|
||||||
UnslashedParticipatingBalances =
|
UnslashedParticipatingBalances =
|
||||||
let
|
let
|
||||||
|
@ -256,7 +256,7 @@ proc process_justification_and_finalization*(state: var phase0.BeaconState,
|
||||||
## state.justification_bits[1:] = state.justification_bits[:-1]
|
## state.justification_bits[1:] = state.justification_bits[:-1]
|
||||||
## state.justification_bits[0] = 0b0
|
## state.justification_bits[0] = 0b0
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#misc
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#misc
|
||||||
const JUSTIFICATION_BITS_LENGTH = 4
|
const JUSTIFICATION_BITS_LENGTH = 4
|
||||||
|
|
||||||
state.justification_bits = (state.justification_bits shl 1) and
|
state.justification_bits = (state.justification_bits shl 1) and
|
||||||
|
@ -331,8 +331,8 @@ proc process_justification_and_finalization*(state: var phase0.BeaconState,
|
||||||
current_epoch = current_epoch,
|
current_epoch = current_epoch,
|
||||||
checkpoint = shortLog(state.finalized_checkpoint)
|
checkpoint = shortLog(state.finalized_checkpoint)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#justification-and-finalization
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||||
# TODO merge these things -- effectively, the phase0 process_justification_and_finalization is mostly a stub in this world
|
# TODO merge these things -- effectively, the phase0 process_justification_and_finalization is mostly a stub in this world
|
||||||
proc weigh_justification_and_finalization(state: var (altair.BeaconState | merge.BeaconState),
|
proc weigh_justification_and_finalization(state: var (altair.BeaconState | merge.BeaconState),
|
||||||
total_active_balance: Gwei,
|
total_active_balance: Gwei,
|
||||||
|
@ -352,7 +352,7 @@ proc weigh_justification_and_finalization(state: var (altair.BeaconState | merge
|
||||||
## state.justification_bits[1:] = state.justification_bits[:-1]
|
## state.justification_bits[1:] = state.justification_bits[:-1]
|
||||||
## state.justification_bits[0] = 0b0
|
## state.justification_bits[0] = 0b0
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#misc
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#misc
|
||||||
const JUSTIFICATION_BITS_LENGTH = 4
|
const JUSTIFICATION_BITS_LENGTH = 4
|
||||||
|
|
||||||
state.justification_bits = (state.justification_bits shl 1) and
|
state.justification_bits = (state.justification_bits shl 1) and
|
||||||
|
@ -445,7 +445,7 @@ proc process_justification_and_finalization*(state: var (altair.BeaconState | me
|
||||||
balances.previous_epoch[TIMELY_TARGET_FLAG_INDEX],
|
balances.previous_epoch[TIMELY_TARGET_FLAG_INDEX],
|
||||||
balances.current_epoch_TIMELY_TARGET, flags)
|
balances.current_epoch_TIMELY_TARGET, flags)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#helpers
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#helpers
|
||||||
func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex,
|
func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex,
|
||||||
total_balance_sqrt: auto): Gwei =
|
total_balance_sqrt: auto): Gwei =
|
||||||
# Spec function recalculates total_balance every time, which creates an
|
# Spec function recalculates total_balance every time, which creates an
|
||||||
|
@ -464,7 +464,7 @@ func is_in_inactivity_leak(finality_delay: uint64): bool =
|
||||||
func get_finality_delay(state: ForkyBeaconState): uint64 =
|
func get_finality_delay(state: ForkyBeaconState): uint64 =
|
||||||
get_previous_epoch(state) - state.finalized_checkpoint.epoch
|
get_previous_epoch(state) - state.finalized_checkpoint.epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
func is_in_inactivity_leak(state: altair.BeaconState | merge.BeaconState): bool =
|
func is_in_inactivity_leak(state: altair.BeaconState | merge.BeaconState): bool =
|
||||||
# TODO remove this, see above
|
# TODO remove this, see above
|
||||||
get_finality_delay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
get_finality_delay(state) > MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
||||||
|
@ -567,7 +567,7 @@ func get_inactivity_penalty_delta*(validator: RewardStatus,
|
||||||
|
|
||||||
delta
|
delta
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_attestation_deltas
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_attestation_deltas
|
||||||
func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) =
|
func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) =
|
||||||
## Update rewards with attestation reward/penalty deltas for each validator.
|
## Update rewards with attestation reward/penalty deltas for each validator.
|
||||||
|
|
||||||
|
@ -611,7 +611,7 @@ func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInf
|
||||||
info.validators[proposer_index].delta.add(
|
info.validators[proposer_index].delta.add(
|
||||||
proposer_delta.get()[1])
|
proposer_delta.get()[1])
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_base_reward
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_base_reward
|
||||||
func get_base_reward_increment(
|
func get_base_reward_increment(
|
||||||
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
state: altair.BeaconState | merge.BeaconState, index: ValidatorIndex,
|
||||||
base_reward_per_increment: Gwei): Gwei =
|
base_reward_per_increment: Gwei): Gwei =
|
||||||
|
@ -621,7 +621,7 @@ func get_base_reward_increment(
|
||||||
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
|
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
|
||||||
increments * base_reward_per_increment
|
increments * base_reward_per_increment
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#get_flag_index_deltas
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#get_flag_index_deltas
|
||||||
iterator get_flag_index_deltas*(
|
iterator get_flag_index_deltas*(
|
||||||
state: altair.BeaconState | merge.BeaconState, flag_index: int,
|
state: altair.BeaconState | merge.BeaconState, flag_index: int,
|
||||||
base_reward_per_increment: Gwei,
|
base_reward_per_increment: Gwei,
|
||||||
|
@ -672,7 +672,7 @@ iterator get_flag_index_deltas*(
|
||||||
else:
|
else:
|
||||||
(vidx, RewardDelta(rewards: 0.Gwei, penalties: 0.Gwei))
|
(vidx, RewardDelta(rewards: 0.Gwei, penalties: 0.Gwei))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#modified-get_inactivity_penalty_deltas
|
||||||
iterator get_inactivity_penalty_deltas*(
|
iterator get_inactivity_penalty_deltas*(
|
||||||
cfg: RuntimeConfig, state: altair.BeaconState, info: altair.EpochInfo):
|
cfg: RuntimeConfig, state: altair.BeaconState, info: altair.EpochInfo):
|
||||||
(ValidatorIndex, Gwei) =
|
(ValidatorIndex, Gwei) =
|
||||||
|
@ -718,7 +718,7 @@ iterator get_inactivity_penalty_deltas*(
|
||||||
state.inactivity_scores[index]
|
state.inactivity_scores[index]
|
||||||
yield (vidx, Gwei(penalty_numerator div penalty_denominator))
|
yield (vidx, Gwei(penalty_numerator div penalty_denominator))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
func process_rewards_and_penalties(
|
func process_rewards_and_penalties(
|
||||||
state: var phase0.BeaconState, info: var phase0.EpochInfo) =
|
state: var phase0.BeaconState, info: var phase0.EpochInfo) =
|
||||||
# No rewards are applied at the end of `GENESIS_EPOCH` because rewards are
|
# No rewards are applied at the end of `GENESIS_EPOCH` because rewards are
|
||||||
|
@ -741,7 +741,7 @@ func process_rewards_and_penalties(
|
||||||
decrease_balance(balance, v.delta.penalties)
|
decrease_balance(balance, v.delta.penalties)
|
||||||
state.balances.asSeq()[idx] = balance
|
state.balances.asSeq()[idx] = balance
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#rewards-and-penalties
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#rewards-and-penalties
|
||||||
func process_rewards_and_penalties(
|
func process_rewards_and_penalties(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
||||||
info: var altair.EpochInfo)
|
info: var altair.EpochInfo)
|
||||||
|
@ -775,7 +775,7 @@ func process_rewards_and_penalties(
|
||||||
decrease_balance(balance, info.validators[index].delta.penalties)
|
decrease_balance(balance, info.validators[index].delta.penalties)
|
||||||
state.balances.asSeq()[index] = balance
|
state.balances.asSeq()[index] = balance
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#registry-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#registry-updates
|
||||||
func process_registry_updates*(
|
func process_registry_updates*(
|
||||||
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache) =
|
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache) =
|
||||||
## Process activation eligibility and ejections
|
## Process activation eligibility and ejections
|
||||||
|
@ -825,8 +825,8 @@ func process_registry_updates*(
|
||||||
state.validators[index].activation_epoch =
|
state.validators[index].activation_epoch =
|
||||||
compute_activation_exit_epoch(get_current_epoch(state))
|
compute_activation_exit_epoch(get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#slashings
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.5/specs/merge/beacon-chain.md#slashings
|
||||||
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
||||||
let
|
let
|
||||||
|
@ -857,7 +857,7 @@ func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
||||||
let penalty = penalty_numerator div total_balance * increment
|
let penalty = penalty_numerator div total_balance * increment
|
||||||
decrease_balance(state, index.ValidatorIndex, penalty)
|
decrease_balance(state, index.ValidatorIndex, penalty)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#eth1-data-votes-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#eth1-data-votes-updates
|
||||||
func process_eth1_data_reset*(state: var ForkyBeaconState) =
|
func process_eth1_data_reset*(state: var ForkyBeaconState) =
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
|
|
||||||
|
@ -865,7 +865,7 @@ func process_eth1_data_reset*(state: var ForkyBeaconState) =
|
||||||
if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
|
if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
|
||||||
state.eth1_data_votes = default(type state.eth1_data_votes)
|
state.eth1_data_votes = default(type state.eth1_data_votes)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#effective-balances-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#effective-balances-updates
|
||||||
func process_effective_balance_updates*(state: var ForkyBeaconState) =
|
func process_effective_balance_updates*(state: var ForkyBeaconState) =
|
||||||
# Update effective balances with hysteresis
|
# Update effective balances with hysteresis
|
||||||
for index in 0..<state.validators.len:
|
for index in 0..<state.validators.len:
|
||||||
|
@ -887,14 +887,14 @@ func process_effective_balance_updates*(state: var ForkyBeaconState) =
|
||||||
if new_effective_balance != effective_balance:
|
if new_effective_balance != effective_balance:
|
||||||
state.validators[index].effective_balance = new_effective_balance
|
state.validators[index].effective_balance = new_effective_balance
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#slashings-balances-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#slashings-balances-updates
|
||||||
func process_slashings_reset*(state: var ForkyBeaconState) =
|
func process_slashings_reset*(state: var ForkyBeaconState) =
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
|
|
||||||
# Reset slashings
|
# Reset slashings
|
||||||
state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei
|
state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#randao-mixes-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#randao-mixes-updates
|
||||||
func process_randao_mixes_reset*(state: var ForkyBeaconState) =
|
func process_randao_mixes_reset*(state: var ForkyBeaconState) =
|
||||||
let
|
let
|
||||||
current_epoch = get_current_epoch(state)
|
current_epoch = get_current_epoch(state)
|
||||||
|
@ -904,7 +904,7 @@ func process_randao_mixes_reset*(state: var ForkyBeaconState) =
|
||||||
state.randao_mixes[next_epoch mod EPOCHS_PER_HISTORICAL_VECTOR] =
|
state.randao_mixes[next_epoch mod EPOCHS_PER_HISTORICAL_VECTOR] =
|
||||||
get_randao_mix(state, current_epoch)
|
get_randao_mix(state, current_epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#historical-roots-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#historical-roots-updates
|
||||||
func process_historical_roots_update*(state: var ForkyBeaconState) =
|
func process_historical_roots_update*(state: var ForkyBeaconState) =
|
||||||
## Set historical root accumulator
|
## Set historical root accumulator
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
|
@ -912,20 +912,20 @@ func process_historical_roots_update*(state: var ForkyBeaconState) =
|
||||||
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0:
|
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0:
|
||||||
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
|
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
|
||||||
# significant additional stack or heap.
|
# significant additional stack or heap.
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#historicalbatch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#historicalbatch
|
||||||
# In response to https://github.com/status-im/nimbus-eth2/issues/921
|
# In response to https://github.com/status-im/nimbus-eth2/issues/921
|
||||||
if not state.historical_roots.add hash_tree_root(
|
if not state.historical_roots.add hash_tree_root(
|
||||||
[hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)]):
|
[hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)]):
|
||||||
raiseAssert "no more room for historical roots, so long and thanks for the fish!"
|
raiseAssert "no more room for historical roots, so long and thanks for the fish!"
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#participation-records-rotation
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#participation-records-rotation
|
||||||
func process_participation_record_updates*(state: var phase0.BeaconState) =
|
func process_participation_record_updates*(state: var phase0.BeaconState) =
|
||||||
# Rotate current/previous epoch attestations - using swap avoids copying all
|
# Rotate current/previous epoch attestations - using swap avoids copying all
|
||||||
# elements using a slow genericSeqAssign
|
# elements using a slow genericSeqAssign
|
||||||
state.previous_epoch_attestations.clear()
|
state.previous_epoch_attestations.clear()
|
||||||
swap(state.previous_epoch_attestations, state.current_epoch_attestations)
|
swap(state.previous_epoch_attestations, state.current_epoch_attestations)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#participation-flags-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#participation-flags-updates
|
||||||
func process_participation_flag_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
func process_participation_flag_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
||||||
state.previous_epoch_participation = state.current_epoch_participation
|
state.previous_epoch_participation = state.current_epoch_participation
|
||||||
|
|
||||||
|
@ -939,14 +939,14 @@ func process_participation_flag_updates*(state: var (altair.BeaconState | merge.
|
||||||
|
|
||||||
state.current_epoch_participation.resetCache()
|
state.current_epoch_participation.resetCache()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#sync-committee-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#sync-committee-updates
|
||||||
proc process_sync_committee_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
proc process_sync_committee_updates*(state: var (altair.BeaconState | merge.BeaconState)) =
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
if next_epoch mod EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
if next_epoch mod EPOCHS_PER_SYNC_COMMITTEE_PERIOD == 0:
|
||||||
state.current_sync_committee = state.next_sync_committee
|
state.current_sync_committee = state.next_sync_committee
|
||||||
state.next_sync_committee = get_next_sync_committee(state)
|
state.next_sync_committee = get_next_sync_committee(state)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#inactivity-scores
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#inactivity-scores
|
||||||
func process_inactivity_updates*(
|
func process_inactivity_updates*(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
||||||
info: altair.EpochInfo) =
|
info: altair.EpochInfo) =
|
||||||
|
@ -980,7 +980,7 @@ func process_inactivity_updates*(
|
||||||
if pre_inactivity_score != inactivity_score:
|
if pre_inactivity_score != inactivity_score:
|
||||||
state.inactivity_scores[index] = inactivity_score
|
state.inactivity_scores[index] = inactivity_score
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#epoch-processing
|
||||||
proc process_epoch*(
|
proc process_epoch*(
|
||||||
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
|
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
|
||||||
cache: var StateCache, info: var phase0.EpochInfo) =
|
cache: var StateCache, info: var phase0.EpochInfo) =
|
||||||
|
@ -1033,7 +1033,7 @@ func init*(
|
||||||
T: type altair.EpochInfo, state: altair.BeaconState | merge.BeaconState): T =
|
T: type altair.EpochInfo, state: altair.BeaconState | merge.BeaconState): T =
|
||||||
init(result, state)
|
init(result, state)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/beacon-chain.md#epoch-processing
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/beacon-chain.md#epoch-processing
|
||||||
proc process_epoch*(
|
proc process_epoch*(
|
||||||
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
cfg: RuntimeConfig, state: var (altair.BeaconState | merge.BeaconState),
|
||||||
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo)
|
flags: UpdateFlags, cache: var StateCache, info: var altair.EpochInfo)
|
||||||
|
@ -1044,7 +1044,7 @@ proc process_epoch*(
|
||||||
|
|
||||||
info.init(state)
|
info.init(state)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#justification-and-finalization
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||||
process_justification_and_finalization(state, info.balances, flags)
|
process_justification_and_finalization(state, info.balances, flags)
|
||||||
|
|
||||||
# state.slot hasn't been incremented yet.
|
# state.slot hasn't been incremented yet.
|
||||||
|
@ -1062,7 +1062,7 @@ proc process_epoch*(
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||||
process_rewards_and_penalties(cfg, state, info)
|
process_rewards_and_penalties(cfg, state, info)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#registry-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#registry-updates
|
||||||
process_registry_updates(cfg, state, cache)
|
process_registry_updates(cfg, state, cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#slashings
|
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#slashings
|
||||||
|
|
|
@ -22,8 +22,8 @@ const
|
||||||
PIVOT_VIEW_SIZE = SEED_SIZE + ROUND_SIZE
|
PIVOT_VIEW_SIZE = SEED_SIZE + ROUND_SIZE
|
||||||
TOTAL_SIZE = PIVOT_VIEW_SIZE + POSITION_WINDOW_SIZE
|
TOTAL_SIZE = PIVOT_VIEW_SIZE + POSITION_WINDOW_SIZE
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_shuffled_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_committee
|
||||||
# Port of https://github.com/protolambda/zrnt/blob/master/eth2/beacon/shuffle.go
|
# Port of https://github.com/protolambda/zrnt/blob/master/eth2/beacon/shuffle.go
|
||||||
# Shuffles or unshuffles, depending on the `dir` (true for shuffling, false for unshuffling
|
# Shuffles or unshuffles, depending on the `dir` (true for shuffling, false for unshuffling
|
||||||
func shuffle_list*(input: var seq[ValidatorIndex], seed: Eth2Digest) =
|
func shuffle_list*(input: var seq[ValidatorIndex], seed: Eth2Digest) =
|
||||||
|
@ -153,13 +153,13 @@ func get_shuffled_active_validator_indices*(
|
||||||
withState(state):
|
withState(state):
|
||||||
cache.get_shuffled_active_validator_indices(state.data, epoch)
|
cache.get_shuffled_active_validator_indices(state.data, epoch)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_active_validator_indices
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||||
func count_active_validators*(state: ForkyBeaconState,
|
func count_active_validators*(state: ForkyBeaconState,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
cache: var StateCache): uint64 =
|
cache: var StateCache): uint64 =
|
||||||
cache.get_shuffled_active_validator_indices(state, epoch).lenu64
|
cache.get_shuffled_active_validator_indices(state, epoch).lenu64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||||
func get_committee_count_per_slot*(num_active_validators: uint64): uint64 =
|
func get_committee_count_per_slot*(num_active_validators: uint64): uint64 =
|
||||||
clamp(
|
clamp(
|
||||||
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
||||||
|
@ -194,7 +194,7 @@ func get_committee_count_per_slot*(state: ForkyBeaconState,
|
||||||
cache: var StateCache): uint64 =
|
cache: var StateCache): uint64 =
|
||||||
get_committee_count_per_slot(state, slot.compute_epoch_at_slot, cache)
|
get_committee_count_per_slot(state, slot.compute_epoch_at_slot, cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_previous_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||||
func get_previous_epoch*(current_epoch: Epoch): Epoch =
|
func get_previous_epoch*(current_epoch: Epoch): Epoch =
|
||||||
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||||
if current_epoch == GENESIS_EPOCH:
|
if current_epoch == GENESIS_EPOCH:
|
||||||
|
@ -207,12 +207,12 @@ func get_previous_epoch*(state: ForkyBeaconState): Epoch =
|
||||||
# Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
# Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||||
get_previous_epoch(get_current_epoch(state))
|
get_previous_epoch(get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_previous_epoch
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||||
func get_previous_epoch*(state: ForkedHashedBeaconState): Epoch =
|
func get_previous_epoch*(state: ForkedHashedBeaconState): Epoch =
|
||||||
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||||
get_previous_epoch(get_current_epoch(state))
|
get_previous_epoch(get_current_epoch(state))
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_committee
|
||||||
func compute_committee_slice*(
|
func compute_committee_slice*(
|
||||||
active_validators, index, count: uint64): Slice[int] =
|
active_validators, index, count: uint64): Slice[int] =
|
||||||
doAssert active_validators <= ValidatorIndex.high.uint64
|
doAssert active_validators <= ValidatorIndex.high.uint64
|
||||||
|
@ -256,7 +256,7 @@ func compute_committee_len*(
|
||||||
|
|
||||||
(slice.b - slice.a + 1).uint64
|
(slice.b - slice.a + 1).uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||||
iterator get_beacon_committee*(
|
iterator get_beacon_committee*(
|
||||||
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
||||||
cache: var StateCache): ValidatorIndex =
|
cache: var StateCache): ValidatorIndex =
|
||||||
|
@ -296,7 +296,7 @@ func get_beacon_committee*(
|
||||||
withState(state):
|
withState(state):
|
||||||
get_beacon_committee(state.data, slot, index, cache)
|
get_beacon_committee(state.data, slot, index, cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||||
func get_beacon_committee_len*(
|
func get_beacon_committee_len*(
|
||||||
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
||||||
cache: var StateCache): uint64 =
|
cache: var StateCache): uint64 =
|
||||||
|
@ -319,7 +319,7 @@ func get_beacon_committee_len*(
|
||||||
withState(state):
|
withState(state):
|
||||||
get_beacon_committee_len(state.data, slot, index, cache)
|
get_beacon_committee_len(state.data, slot, index, cache)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_shuffled_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||||
func compute_shuffled_index*(
|
func compute_shuffled_index*(
|
||||||
index: uint64, index_count: uint64, seed: Eth2Digest): uint64 =
|
index: uint64, index_count: uint64, seed: Eth2Digest): uint64 =
|
||||||
## Return the shuffled index corresponding to ``seed`` (and ``index_count``).
|
## Return the shuffled index corresponding to ``seed`` (and ``index_count``).
|
||||||
|
@ -354,7 +354,7 @@ func compute_shuffled_index*(
|
||||||
|
|
||||||
cur_idx_permuted
|
cur_idx_permuted
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#compute_proposer_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#compute_proposer_index
|
||||||
func compute_proposer_index(state: ForkyBeaconState,
|
func compute_proposer_index(state: ForkyBeaconState,
|
||||||
indices: seq[ValidatorIndex], seed: Eth2Digest): Option[ValidatorIndex] =
|
indices: seq[ValidatorIndex], seed: Eth2Digest): Option[ValidatorIndex] =
|
||||||
## Return from ``indices`` a random index sampled by effective balance.
|
## Return from ``indices`` a random index sampled by effective balance.
|
||||||
|
@ -381,7 +381,7 @@ func compute_proposer_index(state: ForkyBeaconState,
|
||||||
return some(candidate_index)
|
return some(candidate_index)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||||
func get_beacon_proposer_index*(
|
func get_beacon_proposer_index*(
|
||||||
state: ForkyBeaconState, cache: var StateCache, slot: Slot):
|
state: ForkyBeaconState, cache: var StateCache, slot: Slot):
|
||||||
Option[ValidatorIndex] =
|
Option[ValidatorIndex] =
|
||||||
|
@ -420,7 +420,7 @@ func get_beacon_proposer_index*(
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||||
func get_beacon_proposer_index*(state: ForkyBeaconState, cache: var StateCache):
|
func get_beacon_proposer_index*(state: ForkyBeaconState, cache: var StateCache):
|
||||||
Option[ValidatorIndex] =
|
Option[ValidatorIndex] =
|
||||||
get_beacon_proposer_index(state, cache, state.slot)
|
get_beacon_proposer_index(state, cache, state.slot)
|
||||||
|
@ -431,7 +431,7 @@ func get_beacon_proposer_index*(state: ForkedHashedBeaconState,
|
||||||
withState(state):
|
withState(state):
|
||||||
get_beacon_proposer_index(state.data, cache, slot)
|
get_beacon_proposer_index(state.data, cache, slot)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregation-selection
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregation-selection
|
||||||
func is_aggregator*(committee_len: uint64, slot_signature: ValidatorSig): bool =
|
func is_aggregator*(committee_len: uint64, slot_signature: ValidatorSig): bool =
|
||||||
let
|
let
|
||||||
modulo = max(1'u64, committee_len div TARGET_AGGREGATORS_PER_COMMITTEE)
|
modulo = max(1'u64, committee_len div TARGET_AGGREGATORS_PER_COMMITTEE)
|
||||||
|
|
|
@ -64,7 +64,7 @@ type
|
||||||
func hash*(x: AggregatorDuty): Hash =
|
func hash*(x: AggregatorDuty): Hash =
|
||||||
hashAllFields(x)
|
hashAllFields(x)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
||||||
func randomStabilitySubnet*(
|
func randomStabilitySubnet*(
|
||||||
self: ActionTracker, epoch: Epoch): tuple[subnet_id: SubnetId, expiration: Epoch] =
|
self: ActionTracker, epoch: Epoch): tuple[subnet_id: SubnetId, expiration: Epoch] =
|
||||||
(
|
(
|
||||||
|
@ -132,7 +132,7 @@ func updateSlot*(tracker: var ActionTracker, wallSlot: Slot) =
|
||||||
# One stability subnet per known validator
|
# One stability subnet per known validator
|
||||||
static: doAssert RANDOM_SUBNETS_PER_VALIDATOR == 1
|
static: doAssert RANDOM_SUBNETS_PER_VALIDATOR == 1
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
||||||
let expectedSubnets =
|
let expectedSubnets =
|
||||||
min(ATTESTATION_SUBNET_COUNT, tracker.knownValidators.len)
|
min(ATTESTATION_SUBNET_COUNT, tracker.knownValidators.len)
|
||||||
|
|
||||||
|
|
|
@ -620,7 +620,7 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
|
||||||
# We need to run attestations exactly for the slot that we're attesting to.
|
# We need to run attestations exactly for the slot that we're attesting to.
|
||||||
# In case blocks went missing, this means advancing past the latest block
|
# In case blocks went missing, this means advancing past the latest block
|
||||||
# using empty slots as fillers.
|
# using empty slots as fillers.
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#validator-assignments
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#validator-assignments
|
||||||
let
|
let
|
||||||
epochRef = node.dag.getEpochRef(
|
epochRef = node.dag.getEpochRef(
|
||||||
attestationHead.blck, slot.compute_epoch_at_slot())
|
attestationHead.blck, slot.compute_epoch_at_slot())
|
||||||
|
@ -860,7 +860,7 @@ proc makeAggregateAndProof*(
|
||||||
|
|
||||||
# TODO for testing purposes, refactor this into the condition check
|
# TODO for testing purposes, refactor this into the condition check
|
||||||
# and just calculation
|
# and just calculation
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregation-selection
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregation-selection
|
||||||
if not is_aggregator(epochRef, slot, index, slot_signature):
|
if not is_aggregator(epochRef, slot, index, slot_signature):
|
||||||
return none(AggregateAndProof)
|
return none(AggregateAndProof)
|
||||||
|
|
||||||
|
@ -868,8 +868,8 @@ proc makeAggregateAndProof*(
|
||||||
if maybe_slot_attestation.isNone:
|
if maybe_slot_attestation.isNone:
|
||||||
return none(AggregateAndProof)
|
return none(AggregateAndProof)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#construct-aggregate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#construct-aggregate
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#aggregateandproof
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#aggregateandproof
|
||||||
some(AggregateAndProof(
|
some(AggregateAndProof(
|
||||||
aggregator_index: validatorIndex.uint64,
|
aggregator_index: validatorIndex.uint64,
|
||||||
aggregate: maybe_slot_attestation.get,
|
aggregate: maybe_slot_attestation.get,
|
||||||
|
@ -1108,7 +1108,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
|
||||||
|
|
||||||
updateValidatorMetrics(node) # the important stuff is done, update the vanity numbers
|
updateValidatorMetrics(node) # the important stuff is done, update the vanity numbers
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#broadcast-aggregate
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#broadcast-aggregate
|
||||||
# If the validator is selected to aggregate (`is_aggregator`), then they
|
# If the validator is selected to aggregate (`is_aggregator`), then they
|
||||||
# broadcast their best aggregate as a `SignedAggregateAndProof` to the global
|
# broadcast their best aggregate as a `SignedAggregateAndProof` to the global
|
||||||
# aggregate channel (`beacon_aggregate_and_proof`) `2 / INTERVALS_PER_SLOT`
|
# aggregate channel (`beacon_aggregate_and_proof`) `2 / INTERVALS_PER_SLOT`
|
||||||
|
|
|
@ -236,7 +236,7 @@ proc signWithRemoteValidator*(v: AttachedValidator, fork: Fork,
|
||||||
validator = shortLog(v)
|
validator = shortLog(v)
|
||||||
return await v.client.signData(v.pubKey, request)
|
return await v.client.signData(v.pubKey, request)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#signature
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#signature
|
||||||
proc signBlockProposal*(v: AttachedValidator, fork: Fork,
|
proc signBlockProposal*(v: AttachedValidator, fork: Fork,
|
||||||
genesis_validators_root: Eth2Digest, slot: Slot,
|
genesis_validators_root: Eth2Digest, slot: Slot,
|
||||||
blockRoot: Eth2Digest, blck: ForkedBeaconBlock
|
blockRoot: Eth2Digest, blck: ForkedBeaconBlock
|
||||||
|
@ -317,7 +317,7 @@ proc signAggregateAndProof*(v: AttachedValidator,
|
||||||
else:
|
else:
|
||||||
SignatureResult.ok(res.get().toValidatorSig())
|
SignatureResult.ok(res.get().toValidatorSig())
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/altair/validator.md#prepare-sync-committee-message
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/altair/validator.md#prepare-sync-committee-message
|
||||||
proc signSyncCommitteeMessage*(v: AttachedValidator,
|
proc signSyncCommitteeMessage*(v: AttachedValidator,
|
||||||
fork: Fork,
|
fork: Fork,
|
||||||
genesis_validators_root: Eth2Digest,
|
genesis_validators_root: Eth2Digest,
|
||||||
|
@ -385,7 +385,7 @@ proc sign*(v: AttachedValidator, msg: ref SignedContributionAndProof,
|
||||||
res.get().toValidatorSig()
|
res.get().toValidatorSig()
|
||||||
return SignatureResult.ok(msg.signature)
|
return SignatureResult.ok(msg.signature)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#randao-reveal
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#randao-reveal
|
||||||
func genRandaoReveal*(k: ValidatorPrivKey, fork: Fork,
|
func genRandaoReveal*(k: ValidatorPrivKey, fork: Fork,
|
||||||
genesis_validators_root: Eth2Digest,
|
genesis_validators_root: Eth2Digest,
|
||||||
slot: Slot): CookedSig =
|
slot: Slot): CookedSig =
|
||||||
|
|
|
@ -6,10 +6,10 @@ This is a WIP document to explain the attestation flows.
|
||||||
|
|
||||||
It is important to distinguish attestation `validation` from attestation `verification`.
|
It is important to distinguish attestation `validation` from attestation `verification`.
|
||||||
- Attestation `validation` is defined in the P2P specs. Validated attestations can be forwarded on GossipSub.
|
- Attestation `validation` is defined in the P2P specs. Validated attestations can be forwarded on GossipSub.
|
||||||
- Aggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
- Aggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||||
- Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
- Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||||
- Attestation `verification` is defined in the consensus specs. Verified attestations can affect fork choice and may be included in a block.
|
- Attestation `verification` is defined in the consensus specs. Verified attestations can affect fork choice and may be included in a block.
|
||||||
- https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attestations
|
- https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attestations
|
||||||
|
|
||||||
From the specs it seems like gossip attestation `validation` is a superset of consensus attestation `verification`.
|
From the specs it seems like gossip attestation `validation` is a superset of consensus attestation `verification`.
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ These GossipSub topics are used to listen for attestations:
|
||||||
- Unaggregated: `/eth2/{$forkDigest}/beacon_attestation_{subnetIndex}/ssz_snappy`
|
- Unaggregated: `/eth2/{$forkDigest}/beacon_attestation_{subnetIndex}/ssz_snappy`
|
||||||
|
|
||||||
The attestations are then validated by `validateAttestation()` or `validateAggregate()` in either `attestationValidator()` or `aggregateValidator()` according to the P2P specs.
|
The attestations are then validated by `validateAttestation()` or `validateAggregate()` in either `attestationValidator()` or `aggregateValidator()` according to the P2P specs.
|
||||||
- https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
- https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||||
- https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#attestation-subnets
|
- https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#attestation-subnets
|
||||||
|
|
||||||
Finally, valid attestations are added to the local `attestationPool`.
|
Finally, valid attestations are added to the local `attestationPool`.
|
||||||
Attestations are dropped in case of an error.
|
Attestations are dropped in case of an error.
|
||||||
|
|
|
@ -6,10 +6,10 @@ This is a WIP document to explain the beacon block flows.
|
||||||
|
|
||||||
Important distinction:
|
Important distinction:
|
||||||
- We distinguish block `validation` which is defined in the P2P specs:
|
- We distinguish block `validation` which is defined in the P2P specs:
|
||||||
https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_block.
|
https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_block.
|
||||||
A validated block can be forwarded on gossipsub.
|
A validated block can be forwarded on gossipsub.
|
||||||
- and we distinguish `verification` which is defined in consensus specs:
|
- and we distinguish `verification` which is defined in consensus specs:
|
||||||
https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#block-processing
|
https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#block-processing
|
||||||
A block needs to be verified to enter fork choice, the DAG and the BeaconChainDB
|
A block needs to be verified to enter fork choice, the DAG and the BeaconChainDB
|
||||||
|
|
||||||
In particular in terms of costly checks validating a block only requires checking:
|
In particular in terms of costly checks validating a block only requires checking:
|
||||||
|
@ -103,7 +103,7 @@ It is important to note that 3 data structures are sharing the same `AsyncQueue[
|
||||||
Blocks are listened to via the gossipsub topic `/eth2/{$forkDigest}/beacon_block/ssz_snappy` (`topicBeaconBlocks` variable)
|
Blocks are listened to via the gossipsub topic `/eth2/{$forkDigest}/beacon_block/ssz_snappy` (`topicBeaconBlocks` variable)
|
||||||
|
|
||||||
They are then:
|
They are then:
|
||||||
- validated by `blockValidator()` in the Eth2Processor by `validateBeaconBlock()` according to spec https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_block
|
- validated by `blockValidator()` in the Eth2Processor by `validateBeaconBlock()` according to spec https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_block
|
||||||
- Important: P2P validation is not full verification (state transition and internal cryptographic signatures were not checked)
|
- Important: P2P validation is not full verification (state transition and internal cryptographic signatures were not checked)
|
||||||
- enqueued in the shared block queue `AsyncQueue[BlockEntry]` in case of success
|
- enqueued in the shared block queue `AsyncQueue[BlockEntry]` in case of success
|
||||||
- dropped in case of error
|
- dropped in case of error
|
||||||
|
@ -115,7 +115,7 @@ Logs:
|
||||||
|
|
||||||
### Gossip flow out
|
### Gossip flow out
|
||||||
|
|
||||||
- After validation in `blockValidator()` in the Eth2Processor by `validateBeaconBlock()` according to spec https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/p2p-interface.md#beacon_block
|
- After validation in `blockValidator()` in the Eth2Processor by `validateBeaconBlock()` according to spec https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/p2p-interface.md#beacon_block
|
||||||
- Important: P2P validation is not full verification (state transition and internal cryptographic signatures were not checked)
|
- Important: P2P validation is not full verification (state transition and internal cryptographic signatures were not checked)
|
||||||
- We jump into libp2p/protocols/pubsub/pubsub.nim in the method `validate(PubSub, message)`
|
- We jump into libp2p/protocols/pubsub/pubsub.nim in the method `validate(PubSub, message)`
|
||||||
- which was called by `rpcHandler(GossipSub, PubSubPeer, RPCMsg)`
|
- which was called by `rpcHandler(GossipSub, PubSubPeer, RPCMsg)`
|
||||||
|
|
|
@ -40,7 +40,7 @@ type
|
||||||
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#eth1block
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#eth1block
|
||||||
Eth1Block* = object
|
Eth1Block* = object
|
||||||
timestamp*: uint64
|
timestamp*: uint64
|
||||||
deposit_root*: Eth2Digest
|
deposit_root*: Eth2Digest
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
# process_attestation (beaconstate.nim)
|
# process_attestation (beaconstate.nim)
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#attestations
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#attestations
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
|
|
||||||
# process_deposit (beaconstate.nim)
|
# process_deposit (beaconstate.nim)
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/beacon-chain.md#deposits
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/beacon-chain.md#deposits
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
{.used.}
|
{.used.}
|
||||||
|
|
|
@ -166,7 +166,7 @@ func makeAttestationData*(
|
||||||
"Computed epoch was " & $slot.compute_epoch_at_slot &
|
"Computed epoch was " & $slot.compute_epoch_at_slot &
|
||||||
" while the state current_epoch was " & $current_epoch
|
" while the state current_epoch was " & $current_epoch
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.6/specs/phase0/validator.md#attestation-data
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.8/specs/phase0/validator.md#attestation-data
|
||||||
AttestationData(
|
AttestationData(
|
||||||
slot: slot,
|
slot: slot,
|
||||||
index: committee_index.uint64,
|
index: committee_index.uint64,
|
||||||
|
|
Loading…
Reference in New Issue