update spec ref URLs (#3979)
This commit is contained in:
parent
44ea08240c
commit
8274d5373b
|
@ -15,7 +15,7 @@ import
|
|||
./spec/[eth2_ssz_serialization, eth2_merkleization]
|
||||
|
||||
type
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconstate
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconstate
|
||||
# Memory-representation-equivalent to a phase0 BeaconState for in-place SSZ reading and writing
|
||||
Phase0BeaconStateNoImmutableValidators* = object
|
||||
# Versioning
|
||||
|
|
|
@ -6,10 +6,10 @@ Object in those pools have passed the "gossip validation" filter according
|
|||
to specs:
|
||||
- blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block
|
||||
- aggregate attestations: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||
- unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||
- voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
- Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attester_slashing
|
||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#proposer_slashing
|
||||
- unaggregated attestation: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||
- voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
- Attester slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attester_slashing
|
||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/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.
|
||||
For blocks, this means verifying state transition and all contained cryptographic signatures (instead of just the proposer signature).
|
||||
|
|
|
@ -1952,7 +1952,7 @@ proc aggregateAll*(
|
|||
# Aggregation spec requires non-empty collection
|
||||
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
|
||||
# Eth2 spec requires at least one attesting index in attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
return err("aggregate: no attesting keys")
|
||||
|
||||
let
|
||||
|
|
|
@ -97,7 +97,7 @@ proc runForkchoiceUpdated*(
|
|||
# block hash provided by this event is stubbed with
|
||||
# `0x0000000000000000000000000000000000000000000000000000000000000000`."
|
||||
# and
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/validator.md#executionpayload
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/bellatrix/validator.md#executionpayload
|
||||
# notes "`finalized_block_hash` is the hash of the latest finalized execution
|
||||
# payload (`Hash32()` if none yet finalized)"
|
||||
doAssert not headBlockRoot.isZero
|
||||
|
|
|
@ -28,7 +28,7 @@ logScope: topics = "spec_cache"
|
|||
func count_active_validators*(epochInfo: EpochRef): uint64 =
|
||||
epochInfo.shuffled_active_validator_indices.lenu64
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||
func get_committee_count_per_slot*(epochInfo: EpochRef): uint64 =
|
||||
get_committee_count_per_slot(count_active_validators(epochInfo))
|
||||
|
||||
|
@ -41,7 +41,7 @@ func get_committee_index*(epochRef: EpochRef, index: uint64):
|
|||
Result[CommitteeIndex, cstring] =
|
||||
check_attestation_index(index, get_committee_count_per_slot(epochRef))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
iterator get_beacon_committee*(
|
||||
epochRef: EpochRef, slot: Slot, committee_index: CommitteeIndex):
|
||||
(int, ValidatorIndex) =
|
||||
|
@ -54,7 +54,7 @@ iterator get_beacon_committee*(
|
|||
committees_per_slot * SLOTS_PER_EPOCH
|
||||
): yield (index_in_committee, idx)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
func get_beacon_committee*(
|
||||
epochRef: EpochRef, slot: Slot, committee_index: CommitteeIndex):
|
||||
seq[ValidatorIndex] =
|
||||
|
@ -67,7 +67,7 @@ func get_beacon_committee*(
|
|||
committees_per_slot * SLOTS_PER_EPOCH
|
||||
)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
func get_beacon_committee_len*(
|
||||
epochRef: EpochRef, slot: Slot, committee_index: CommitteeIndex): uint64 =
|
||||
## Return the number of members in the beacon committee at ``slot`` for ``index``.
|
||||
|
@ -79,7 +79,7 @@ func get_beacon_committee_len*(
|
|||
committees_per_slot * SLOTS_PER_EPOCH
|
||||
)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
iterator get_attesting_indices*(epochRef: EpochRef,
|
||||
slot: Slot,
|
||||
committee_index: CommitteeIndex,
|
||||
|
@ -142,7 +142,7 @@ func get_attesting_indices_one*(epochRef: EpochRef,
|
|||
res = some(validator_index)
|
||||
res
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
func get_attesting_indices*(epochRef: EpochRef,
|
||||
slot: Slot,
|
||||
committee_index: CommitteeIndex,
|
||||
|
@ -152,7 +152,7 @@ func get_attesting_indices*(epochRef: EpochRef,
|
|||
for idx in get_attesting_indices(epochRef, slot, committee_index, bits):
|
||||
result.add(idx)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
proc is_valid_indexed_attestation*(
|
||||
fork: Fork, genesis_validators_root: Eth2Digest,
|
||||
epochRef: EpochRef,
|
||||
|
|
|
@ -10,7 +10,7 @@ when (NimMajor, NimMinor) < (1, 4):
|
|||
else:
|
||||
{.push raises: [].}
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/utils/merkle_minimal.py
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/utils/merkle_minimal.py
|
||||
|
||||
# Merkle tree helpers
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -11,10 +11,10 @@ Gossip validation is different from consensus verification in particular for blo
|
|||
|
||||
- Blocks: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block
|
||||
- Attestations (aggregated): https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||
- Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attestation-subnets
|
||||
- Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#proposer_slashing
|
||||
- Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attester_slashing
|
||||
- Attestations (unaggregated): https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestation-subnets
|
||||
- Voluntary exits: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
- Proposer slashings: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#proposer_slashing
|
||||
- Attester slashing: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attester_slashing
|
||||
|
||||
There are multiple consumers of validated consensus objects:
|
||||
- a `ValidationResult.Accept` output triggers rebroadcasting in libp2p
|
||||
|
|
|
@ -96,7 +96,7 @@ func check_propagation_slot_range(
|
|||
let
|
||||
pastSlot = (wallTime - MAXIMUM_GOSSIP_CLOCK_DISPARITY).toSlot()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#configuration
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#configuration
|
||||
# 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
|
||||
# the time they reach their destination might be out of spec.
|
||||
|
@ -182,7 +182,7 @@ template validateBeaconBlockBellatrix(
|
|||
parent: BlockRef): untyped =
|
||||
discard
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
template validateBeaconBlockBellatrix(
|
||||
signed_beacon_block: bellatrix.SignedBeaconBlock,
|
||||
parent: BlockRef): untyped =
|
||||
|
@ -222,7 +222,7 @@ template validateBeaconBlockBellatrix(
|
|||
return errReject("BeaconBlock: execution payload would build on optimistic parent")
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/p2p-interface.md#beacon_block
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
proc validateBeaconBlock*(
|
||||
dag: ChainDAGRef, quarantine: ref Quarantine,
|
||||
signed_beacon_block: phase0.SignedBeaconBlock | altair.SignedBeaconBlock |
|
||||
|
@ -301,7 +301,7 @@ proc validateBeaconBlock*(
|
|||
if signed_beacon_block.message.parent_root in quarantine[].unviable:
|
||||
quarantine[].addUnviable(signed_beacon_block.root)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/bellatrix/p2p-interface.md#beacon_block
|
||||
# `is_execution_enabled(state, block.body)` check, but unlike in
|
||||
# validateBeaconBlockBellatrix() don't have parent BlockRef.
|
||||
if signed_beacon_block.message.is_execution_block or
|
||||
|
@ -761,7 +761,7 @@ proc validateAggregate*(
|
|||
|
||||
return ok((attesting_indices, sig))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attester_slashing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attester_slashing
|
||||
proc validateAttesterSlashing*(
|
||||
pool: ExitPool, attester_slashing: AttesterSlashing):
|
||||
Result[void, ValidationError] =
|
||||
|
@ -784,7 +784,7 @@ proc validateAttesterSlashing*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#proposer_slashing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#proposer_slashing
|
||||
proc validateProposerSlashing*(
|
||||
pool: ExitPool, proposer_slashing: ProposerSlashing):
|
||||
Result[void, ValidationError] =
|
||||
|
@ -807,7 +807,7 @@ proc validateProposerSlashing*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#voluntary_exit
|
||||
proc validateVoluntaryExit*(
|
||||
pool: ExitPool, signed_voluntary_exit: SignedVoluntaryExit):
|
||||
Result[void, ValidationError] =
|
||||
|
@ -837,7 +837,7 @@ proc validateVoluntaryExit*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#sync_committee_subnet_id
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#sync_committee_subnet_id
|
||||
proc validateSyncCommitteeMessage*(
|
||||
dag: ChainDAGRef,
|
||||
batchCrypto: ref BatchCrypto,
|
||||
|
|
|
@ -171,7 +171,7 @@ type
|
|||
MounterProc* = proc(network: Eth2Node) {.gcsafe, raises: [Defect, CatchableError].}
|
||||
MessageContentPrinter* = proc(msg: pointer): string {.gcsafe, raises: [Defect].}
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#goodbye
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#goodbye
|
||||
DisconnectionReason* = enum
|
||||
# might see other values on the wire!
|
||||
ClientShutDown = 1
|
||||
|
@ -2128,8 +2128,8 @@ proc getPersistentNetKeys*(
|
|||
|
||||
func gossipId(
|
||||
data: openArray[byte], altairPrefix, topic: string): seq[byte] =
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#topics-and-messages
|
||||
const
|
||||
MESSAGE_DOMAIN_INVALID_SNAPPY = [0x00'u8, 0x00, 0x00, 0x00]
|
||||
MESSAGE_DOMAIN_VALID_SNAPPY = [0x01'u8, 0x00, 0x00, 0x00]
|
||||
|
@ -2414,7 +2414,7 @@ proc broadcast(node: Eth2Node, topic: string, msg: auto):
|
|||
|
||||
proc subscribeAttestationSubnets*(
|
||||
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||
# Nimbus won't score attestation subnets for now, we just rely on block and
|
||||
# aggregate which are more stable and reliable
|
||||
|
||||
|
@ -2425,7 +2425,7 @@ proc subscribeAttestationSubnets*(
|
|||
|
||||
proc unsubscribeAttestationSubnets*(
|
||||
node: Eth2Node, subnets: AttnetBits, forkDigest: ForkDigest) =
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestations-and-aggregation
|
||||
# Nimbus won't score attestation subnets for now; we just rely on block and
|
||||
# aggregate which are more stable and reliable
|
||||
|
||||
|
@ -2434,7 +2434,7 @@ proc unsubscribeAttestationSubnets*(
|
|||
node.unsubscribe(getAttestationTopic(forkDigest, SubnetId(subnet_id)))
|
||||
|
||||
proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#metadata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#metadata
|
||||
if node.metadata.attnets == attnets:
|
||||
return
|
||||
|
||||
|
@ -2442,7 +2442,7 @@ proc updateStabilitySubnetMetadata*(node: Eth2Node, attnets: AttnetBits) =
|
|||
node.metadata.attnets = attnets
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/validator.md#phase-0-attestation-subnet-stability
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attestation-subnet-bitfield
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestation-subnet-bitfield
|
||||
let res = node.discovery.updateRecord({
|
||||
enrAttestationSubnetsField: SSZ.encode(node.metadata.attnets)
|
||||
})
|
||||
|
@ -2495,7 +2495,7 @@ proc broadcastAttestation*(
|
|||
node: Eth2Node, subnet_id: SubnetId, attestation: Attestation):
|
||||
Future[SendResult] =
|
||||
# Regardless of the contents of the attestation,
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||
# implies that pre-fork, messages using post-fork digests might be
|
||||
# ignored, whilst post-fork, there is effectively a seen_ttl-based
|
||||
# timer unsubscription point that means no new pre-fork-forkdigest
|
||||
|
|
|
@ -22,7 +22,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
cachedConfigSpec =
|
||||
RestApiResponse.prepareJsonResponse(
|
||||
(
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/phase0.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/phase0.yaml
|
||||
MAX_COMMITTEES_PER_SLOT:
|
||||
Base10.toString(MAX_COMMITTEES_PER_SLOT),
|
||||
TARGET_COMMITTEE_SIZE:
|
||||
|
@ -90,7 +90,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
MAX_VOLUNTARY_EXITS:
|
||||
Base10.toString(MAX_VOLUNTARY_EXITS),
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/altair.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/altair.yaml
|
||||
INACTIVITY_PENALTY_QUOTIENT_ALTAIR:
|
||||
Base10.toString(INACTIVITY_PENALTY_QUOTIENT_ALTAIR),
|
||||
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR:
|
||||
|
@ -106,7 +106,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
UPDATE_TIMEOUT:
|
||||
Base10.toString(UPDATE_TIMEOUT),
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/bellatrix.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/bellatrix.yaml
|
||||
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX:
|
||||
Base10.toString(INACTIVITY_PENALTY_QUOTIENT_BELLATRIX),
|
||||
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX:
|
||||
|
@ -186,7 +186,7 @@ proc installConfigApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|||
DEPOSIT_CONTRACT_ADDRESS:
|
||||
$cfg.DEPOSIT_CONTRACT_ADDRESS,
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#constants
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#constants
|
||||
# GENESIS_SLOT
|
||||
# GENESIS_EPOCH
|
||||
# FAR_FUTURE_EPOCH
|
||||
|
|
|
@ -190,7 +190,7 @@ func slotOrZero*(time: BeaconTime): Slot =
|
|||
if exSlot.afterGenesis: exSlot.slot
|
||||
else: Slot(0)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_epoch_at_slot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_epoch_at_slot
|
||||
func epoch*(slot: Slot): Epoch = # aka compute_epoch_at_slot
|
||||
## Return the epoch number at ``slot``.
|
||||
if slot == FAR_FUTURE_SLOT: FAR_FUTURE_EPOCH
|
||||
|
@ -204,14 +204,14 @@ func since_epoch_start*(slot: Slot): uint64 = # aka compute_slots_since_epoch_st
|
|||
template is_epoch*(slot: Slot): bool =
|
||||
slot.since_epoch_start == 0
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
|
||||
func start_slot*(epoch: Epoch): Slot = # aka compute_start_slot_at_epoch
|
||||
## Return the start slot of ``epoch``.
|
||||
const maxEpoch = Epoch(FAR_FUTURE_SLOT div SLOTS_PER_EPOCH)
|
||||
if epoch >= maxEpoch: FAR_FUTURE_SLOT
|
||||
else: Slot(epoch * SLOTS_PER_EPOCH)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||
func get_previous_epoch*(current_epoch: Epoch): Epoch =
|
||||
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||
if current_epoch == GENESIS_EPOCH:
|
||||
|
|
|
@ -21,7 +21,7 @@ import
|
|||
|
||||
export extras, forks, validator
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#increase_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#increase_balance
|
||||
func increase_balance*(balance: var Gwei, delta: Gwei) =
|
||||
balance += delta
|
||||
|
||||
|
@ -31,7 +31,7 @@ func increase_balance*(
|
|||
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||
increase_balance(state.balances.mitem(index), delta)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#decrease_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#decrease_balance
|
||||
func decrease_balance*(balance: var Gwei, delta: Gwei) =
|
||||
balance =
|
||||
if delta > balance:
|
||||
|
@ -46,7 +46,7 @@ func decrease_balance*(
|
|||
if delta != 0: # avoid dirtying the balance cache if not needed
|
||||
decrease_balance(state.balances.mitem(index), delta)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#deposits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#deposits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-process_deposit
|
||||
func get_validator_from_deposit*(deposit: DepositData):
|
||||
Validator =
|
||||
|
@ -65,13 +65,13 @@ func get_validator_from_deposit*(deposit: DepositData):
|
|||
effective_balance: effective_balance
|
||||
)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_activation_exit_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_activation_exit_epoch
|
||||
func compute_activation_exit_epoch*(epoch: Epoch): Epoch =
|
||||
## Return the epoch during which validator activations and exits initiated in
|
||||
## ``epoch`` take effect.
|
||||
epoch + 1 + MAX_SEED_LOOKAHEAD
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
||||
func get_validator_churn_limit*(
|
||||
cfg: RuntimeConfig, state: ForkyBeaconState, cache: var StateCache):
|
||||
uint64 =
|
||||
|
@ -81,7 +81,7 @@ func get_validator_churn_limit*(
|
|||
count_active_validators(
|
||||
state, state.get_current_epoch(), cache) div cfg.CHURN_LIMIT_QUOTIENT)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#initiate_validator_exit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#initiate_validator_exit
|
||||
func initiate_validator_exit*(
|
||||
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||
index: ValidatorIndex, cache: var StateCache): Result[void, cstring] =
|
||||
|
@ -130,7 +130,7 @@ func initiate_validator_exit*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||
func get_slashing_penalty*(state: ForkyBeaconState,
|
||||
|
@ -146,13 +146,13 @@ func get_slashing_penalty*(state: ForkyBeaconState,
|
|||
else:
|
||||
{.fatal: "invalid BeaconState type".}
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||
func get_whistleblower_reward*(validator_effective_balance: Gwei): Gwei =
|
||||
validator_effective_balance div WHISTLEBLOWER_REWARD_QUOTIENT
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||
func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): Gwei =
|
||||
|
@ -163,7 +163,7 @@ func get_proposer_reward(state: ForkyBeaconState, whistleblower_reward: Gwei): G
|
|||
else:
|
||||
{.fatal: "invalid BeaconState type".}
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#modified-slash_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||
proc slash_validator*(
|
||||
|
@ -218,7 +218,7 @@ proc slash_validator*(
|
|||
func genesis_time_from_eth1_timestamp*(cfg: RuntimeConfig, eth1_timestamp: uint64): uint64 =
|
||||
eth1_timestamp + cfg.GENESIS_DELAY
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#genesis
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#genesis
|
||||
proc initialize_beacon_state_from_eth1*(
|
||||
cfg: RuntimeConfig,
|
||||
eth1_block_hash: Eth2Digest,
|
||||
|
@ -320,7 +320,7 @@ proc initialize_hashed_beacon_state_from_eth1*(
|
|||
cfg, eth1_block_hash, eth1_timestamp, deposits, flags))
|
||||
result.root = hash_tree_root(result.data)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#genesis-block
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#genesis-block
|
||||
func get_initial_beacon_block*(state: phase0.HashedBeaconState):
|
||||
phase0.TrustedSignedBeaconBlock =
|
||||
# The genesis block is implicitly trusted
|
||||
|
@ -361,7 +361,7 @@ func get_initial_beacon_block*(state: ForkedHashedBeaconState):
|
|||
withState(state):
|
||||
ForkedTrustedSignedBeaconBlock.init(get_initial_beacon_block(state))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_block_root_at_slot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_block_root_at_slot
|
||||
func get_block_root_at_slot*(state: ForkyBeaconState, slot: Slot): Eth2Digest =
|
||||
## Return the block root at a recent ``slot``.
|
||||
|
||||
|
@ -379,7 +379,7 @@ func get_block_root_at_slot*(
|
|||
withState(state):
|
||||
get_block_root_at_slot(state.data, slot)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_block_root
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_block_root
|
||||
func get_block_root*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
||||
## Return the block root at the start of a recent ``epoch``.
|
||||
get_block_root_at_slot(state, epoch.start_slot())
|
||||
|
@ -389,7 +389,7 @@ func get_block_root*(state: ForkedHashedBeaconState, epoch: Epoch): Eth2Digest =
|
|||
withState(state):
|
||||
get_block_root(state.data, epoch)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_total_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_total_balance
|
||||
template get_total_balance(
|
||||
state: ForkyBeaconState, validator_indices: untyped): Gwei =
|
||||
## Return the combined effective balance of the ``indices``.
|
||||
|
@ -400,13 +400,13 @@ template get_total_balance(
|
|||
res += state.validators[validator_index].effective_balance
|
||||
max(EFFECTIVE_BALANCE_INCREMENT, res)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_eligible_for_activation_queue
|
||||
func is_eligible_for_activation_queue*(validator: Validator): bool =
|
||||
## Check if ``validator`` is eligible to be placed into the activation queue.
|
||||
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
|
||||
validator.effective_balance == MAX_EFFECTIVE_BALANCE
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_eligible_for_activation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_eligible_for_activation
|
||||
func is_eligible_for_activation*(
|
||||
state: ForkyBeaconState, validator: Validator): bool =
|
||||
## Check if ``validator`` is eligible for activation.
|
||||
|
@ -416,7 +416,7 @@ func is_eligible_for_activation*(
|
|||
# Has not yet been activated
|
||||
validator.activation_epoch == FAR_FUTURE_EPOCH
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
proc is_valid_indexed_attestation*(
|
||||
state: ForkyBeaconState, indexed_attestation: SomeIndexedAttestation,
|
||||
flags: UpdateFlags): Result[void, cstring] =
|
||||
|
@ -454,7 +454,7 @@ proc is_valid_indexed_attestation*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_attesting_indices
|
||||
func get_attesting_indices*(state: ForkyBeaconState,
|
||||
data: AttestationData,
|
||||
bits: CommitteeValidatorsBits,
|
||||
|
@ -519,8 +519,8 @@ proc is_valid_indexed_attestation*(
|
|||
|
||||
# Attestation validation
|
||||
# ------------------------------------------------------------------------------------------
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attestations
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attestations
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||
|
||||
func check_attestation_slot_target*(data: AttestationData): Result[Slot, cstring] =
|
||||
if not (data.target.epoch == epoch(data.slot)):
|
||||
|
@ -596,7 +596,7 @@ func get_attestation_participation_flag_indices(state: altair.BeaconState | bell
|
|||
# TODO these duplicate some stuff in state_transition_epoch which uses TotalBalances
|
||||
# better to centralize around that if feasible
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_total_active_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_total_active_balance
|
||||
func get_total_active_balance*(state: ForkyBeaconState, cache: var StateCache): Gwei =
|
||||
## Return the combined effective balance of the active validators.
|
||||
# Note: ``get_total_balance`` returns ``EFFECTIVE_BALANCE_INCREMENT`` Gwei
|
||||
|
@ -626,7 +626,7 @@ func get_base_reward(
|
|||
state.validators[index].effective_balance div EFFECTIVE_BALANCE_INCREMENT
|
||||
increments * base_reward_per_increment
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attestations
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attestations
|
||||
proc check_attestation*(
|
||||
state: ForkyBeaconState, attestation: SomeAttestation, flags: UpdateFlags,
|
||||
cache: var StateCache): Result[void, cstring] =
|
||||
|
|
|
@ -96,7 +96,7 @@ export
|
|||
|
||||
# API
|
||||
# ----------------------------------------------------------------------
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#bls-signatures
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#bls-signatures
|
||||
|
||||
func toPubKey*(privkey: ValidatorPrivKey): CookedPubKey =
|
||||
## Derive a public key from a private key
|
||||
|
@ -204,7 +204,7 @@ func finish*(agg: AggregateSignature): CookedSig {.inline.} =
|
|||
sig.finish(agg)
|
||||
CookedSig(sig)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#bls-signatures
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#bls-signatures
|
||||
func blsVerify*(
|
||||
pubkey: CookedPubKey, message: openArray[byte],
|
||||
signature: CookedSig): bool =
|
||||
|
@ -217,7 +217,7 @@ func blsVerify*(
|
|||
## to enforce correct usage.
|
||||
PublicKey(pubkey).verify(message, blscurve.Signature(signature))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#bls-signatures
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#bls-signatures
|
||||
proc blsVerify*(
|
||||
pubkey: ValidatorPubKey, message: openArray[byte],
|
||||
signature: CookedSig): bool =
|
||||
|
|
|
@ -54,7 +54,7 @@ const
|
|||
# The first member (`genesis_time`) is 32, subsequent members +1 each.
|
||||
# If there are ever more than 32 members in `BeaconState`, indices change!
|
||||
# `FINALIZED_ROOT_INDEX` is one layer deeper, i.e., `52 * 2 + 1`.
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/ssz/merkle-proofs.md
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/ssz/merkle-proofs.md
|
||||
FINALIZED_ROOT_INDEX* = 105.GeneralizedIndex # `finalized_checkpoint` > `root`
|
||||
CURRENT_SYNC_COMMITTEE_INDEX* = 54.GeneralizedIndex # `current_sync_committee`
|
||||
NEXT_SYNC_COMMITTEE_INDEX* = 55.GeneralizedIndex # `next_sync_committee`
|
||||
|
@ -333,7 +333,7 @@ type
|
|||
data*: BeaconState
|
||||
root*: Eth2Digest # hash_tree_root(data)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconblock
|
||||
BeaconBlock* = object
|
||||
## 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
|
||||
|
@ -439,7 +439,7 @@ type
|
|||
|
||||
SyncnetBits* = BitArray[SYNC_COMMITTEE_SUBNET_COUNT]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#metadata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#metadata
|
||||
MetaData* = object
|
||||
seq_number*: uint64
|
||||
attnets*: AttnetBits
|
||||
|
@ -461,7 +461,7 @@ type
|
|||
# [New in Altair]
|
||||
sync_aggregate*: TrustedSyncAggregate
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
SignedBeaconBlock* = object
|
||||
message*: BeaconBlock
|
||||
signature*: ValidatorSig
|
||||
|
|
|
@ -85,7 +85,7 @@ const
|
|||
ZERO_HASH* = Eth2Digest()
|
||||
MAX_GRAFFITI_SIZE* = 32
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#configuration
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#configuration
|
||||
MAXIMUM_GOSSIP_CLOCK_DISPARITY* = 500.millis
|
||||
|
||||
SLOTS_PER_ETH1_VOTING_PERIOD* =
|
||||
|
@ -136,7 +136,7 @@ type
|
|||
# ---------------------------------------------------------------
|
||||
DomainType* = distinct array[4, byte]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#custom-types
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#custom-types
|
||||
Eth2Domain* = array[32, byte]
|
||||
|
||||
ValidatorIndex* = distinct uint32
|
||||
|
@ -183,7 +183,7 @@ type
|
|||
# SSZ / hashing purposes
|
||||
JustificationBits* = distinct uint8
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#proposerslashing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#proposerslashing
|
||||
ProposerSlashing* = object
|
||||
signed_header_1*: SignedBeaconBlockHeader
|
||||
signed_header_2*: SignedBeaconBlockHeader
|
||||
|
@ -195,7 +195,7 @@ type
|
|||
signed_header_1*: TrustedSignedBeaconBlockHeader
|
||||
signed_header_2*: TrustedSignedBeaconBlockHeader
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attesterslashing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attesterslashing
|
||||
AttesterSlashing* = object
|
||||
attestation_1*: IndexedAttestation
|
||||
attestation_2*: IndexedAttestation
|
||||
|
@ -207,7 +207,7 @@ type
|
|||
attestation_1*: TrustedIndexedAttestation
|
||||
attestation_2*: TrustedIndexedAttestation
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#indexedattestation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#indexedattestation
|
||||
IndexedAttestation* = object
|
||||
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||
data*: AttestationData
|
||||
|
@ -223,7 +223,7 @@ type
|
|||
|
||||
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attestation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attestation
|
||||
Attestation* = object
|
||||
aggregation_bits*: CommitteeValidatorsBits
|
||||
data*: AttestationData
|
||||
|
@ -239,17 +239,17 @@ type
|
|||
|
||||
ForkDigest* = distinct array[4, byte]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#forkdata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#forkdata
|
||||
ForkData* = object
|
||||
current_version*: Version
|
||||
genesis_validators_root*: Eth2Digest
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#checkpoint
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#checkpoint
|
||||
Checkpoint* = object
|
||||
epoch*: Epoch
|
||||
root*: Eth2Digest
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#AttestationData
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#AttestationData
|
||||
AttestationData* = object
|
||||
slot*: Slot
|
||||
|
||||
|
@ -262,20 +262,20 @@ type
|
|||
source*: Checkpoint
|
||||
target*: Checkpoint
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#deposit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#deposit
|
||||
Deposit* = object
|
||||
proof*: array[DEPOSIT_CONTRACT_TREE_DEPTH + 1, Eth2Digest]
|
||||
## Merkle path to deposit root
|
||||
|
||||
data*: DepositData
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#depositmessage
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#depositmessage
|
||||
DepositMessage* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
withdrawal_credentials*: Eth2Digest
|
||||
amount*: Gwei
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#depositdata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#depositdata
|
||||
DepositData* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
withdrawal_credentials*: Eth2Digest
|
||||
|
@ -284,7 +284,7 @@ type
|
|||
# if the deposit should be added or not during processing
|
||||
signature*: ValidatorSig # Signing over DepositMessage
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#voluntaryexit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#voluntaryexit
|
||||
VoluntaryExit* = object
|
||||
epoch*: Epoch
|
||||
## Earliest epoch when voluntary exit can be processed
|
||||
|
@ -312,7 +312,7 @@ type
|
|||
pubkey*: CookedPubKey
|
||||
withdrawal_credentials*: Eth2Digest
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#validator
|
||||
Validator* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
|
||||
|
@ -334,7 +334,7 @@ type
|
|||
withdrawable_epoch*: Epoch
|
||||
## When validator can withdraw or transfer funds
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#pendingattestation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#pendingattestation
|
||||
PendingAttestation* = object
|
||||
aggregation_bits*: CommitteeValidatorsBits
|
||||
data*: AttestationData
|
||||
|
@ -343,12 +343,12 @@ type
|
|||
|
||||
proposer_index*: uint64 # `ValidatorIndex` after validation
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#historicalbatch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#historicalbatch
|
||||
HistoricalBatch* = object
|
||||
block_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||
state_roots* : array[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#fork
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#fork
|
||||
Fork* = object
|
||||
previous_version*: Version
|
||||
current_version*: Version
|
||||
|
@ -356,13 +356,13 @@ type
|
|||
epoch*: Epoch
|
||||
## Epoch of latest fork
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#eth1data
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#eth1data
|
||||
Eth1Data* = object
|
||||
deposit_root*: Eth2Digest
|
||||
deposit_count*: uint64
|
||||
block_hash*: Eth2Digest
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signedvoluntaryexit
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signedvoluntaryexit
|
||||
SignedVoluntaryExit* = object
|
||||
message*: VoluntaryExit
|
||||
signature*: ValidatorSig
|
||||
|
@ -371,7 +371,7 @@ type
|
|||
message*: VoluntaryExit
|
||||
signature*: TrustedSig
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconblockheader
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconblockheader
|
||||
BeaconBlockHeader* = object
|
||||
slot*: Slot
|
||||
proposer_index*: uint64 # `ValidatorIndex` after validation
|
||||
|
@ -379,14 +379,14 @@ type
|
|||
state_root*: Eth2Digest
|
||||
body_root*: Eth2Digest
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signingdata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signingdata
|
||||
SigningData* = object
|
||||
object_root*: Eth2Digest
|
||||
domain*: Eth2Domain
|
||||
|
||||
GraffitiBytes* = distinct array[MAX_GRAFFITI_SIZE, byte]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signedbeaconblockheader
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signedbeaconblockheader
|
||||
SignedBeaconBlockHeader* = object
|
||||
message*: BeaconBlockHeader
|
||||
signature*: ValidatorSig
|
||||
|
@ -418,12 +418,12 @@ type
|
|||
sync_committees*: Table[SyncCommitteePeriod, SyncCommitteeCache]
|
||||
|
||||
# This matches the mutable state of the Solidity deposit contract
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/solidity_deposit_contract/deposit_contract.sol
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/solidity_deposit_contract/deposit_contract.sol
|
||||
DepositContractState* = object
|
||||
branch*: array[DEPOSIT_CONTRACT_TREE_DEPTH, Eth2Digest]
|
||||
deposit_count*: array[32, byte] # Uint256
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#validator
|
||||
ValidatorStatus* = object
|
||||
# This is a validator without the expensive, immutable, append-only parts
|
||||
# serialized. They're represented in memory to allow in-place SSZ reading
|
||||
|
@ -449,7 +449,7 @@ type
|
|||
withdrawable_epoch*: Epoch
|
||||
## When validator can withdraw or transfer funds
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#eth2-field
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#eth2-field
|
||||
ENRForkID* = object
|
||||
fork_digest*: ForkDigest
|
||||
next_fork_version*: Version
|
||||
|
@ -514,7 +514,7 @@ type
|
|||
flags*: set[RewardFlags]
|
||||
|
||||
const
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#domain-types
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#domain-types
|
||||
DOMAIN_BEACON_PROPOSER* = DomainType([byte 0x00, 0x00, 0x00, 0x00])
|
||||
DOMAIN_BEACON_ATTESTER* = DomainType([byte 0x01, 0x00, 0x00, 0x00])
|
||||
DOMAIN_RANDAO* = DomainType([byte 0x02, 0x00, 0x00, 0x00])
|
||||
|
|
|
@ -164,7 +164,7 @@ type
|
|||
data*: BeaconState
|
||||
root*: Eth2Digest # hash_tree_root(data)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconblock
|
||||
BeaconBlock* = object
|
||||
## 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
|
||||
|
@ -290,7 +290,7 @@ type
|
|||
# Execution
|
||||
execution_payload*: ExecutionPayload # [New in Bellatrix]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
SignedBeaconBlock* = object
|
||||
message*: BeaconBlock
|
||||
signature*: ValidatorSig
|
||||
|
|
|
@ -25,7 +25,7 @@ import
|
|||
export base
|
||||
|
||||
type
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconstate
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconstate
|
||||
BeaconState* = object
|
||||
# Versioning
|
||||
genesis_time*: uint64
|
||||
|
@ -75,7 +75,7 @@ type
|
|||
current_justified_checkpoint*: Checkpoint
|
||||
finalized_checkpoint*: Checkpoint
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_total_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_total_balance
|
||||
TotalBalances* = object
|
||||
# The total effective balance of all active validators during the _current_
|
||||
# epoch.
|
||||
|
@ -112,7 +112,7 @@ type
|
|||
data*: BeaconState
|
||||
root*: Eth2Digest # hash_tree_root(data)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconblock
|
||||
BeaconBlock* = object
|
||||
## 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
|
||||
|
@ -131,7 +131,7 @@ type
|
|||
|
||||
body*: BeaconBlockBody
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#metadata
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#metadata
|
||||
MetaData* = object
|
||||
seq_number*: uint64
|
||||
attnets*: AttnetBits
|
||||
|
@ -173,7 +173,7 @@ type
|
|||
state_root*: Eth2Digest
|
||||
body*: TrustedBeaconBlockBody
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beaconblockbody
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beaconblockbody
|
||||
BeaconBlockBody* = object
|
||||
randao_reveal*: ValidatorSig
|
||||
eth1_data*: Eth1Data
|
||||
|
@ -222,7 +222,7 @@ type
|
|||
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
||||
voluntary_exits*: List[TrustedSignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#signedbeaconblock
|
||||
SignedBeaconBlock* = object
|
||||
message*: BeaconBlock
|
||||
signature*: ValidatorSig
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
# Serenity hash function / digest
|
||||
#
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#hash
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#hash
|
||||
#
|
||||
# In Phase 0 the beacon chain is deployed with SHA256 (SHA2-256).
|
||||
# Note that is is different from Keccak256 (often mistakenly called SHA3-256)
|
||||
|
|
|
@ -257,7 +257,7 @@ type
|
|||
of BeaconBlockFork.Bellatrix: bellatrixBody*: bellatrix.BeaconBlockBody
|
||||
|
||||
RestSpec* = object
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/phase0.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/phase0.yaml
|
||||
MAX_COMMITTEES_PER_SLOT*: uint64
|
||||
TARGET_COMMITTEE_SIZE*: uint64
|
||||
MAX_VALIDATORS_PER_COMMITTEE*: uint64
|
||||
|
@ -292,7 +292,7 @@ type
|
|||
MAX_DEPOSITS*: uint64
|
||||
MAX_VOLUNTARY_EXITS*: uint64
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/altair.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/altair.yaml
|
||||
INACTIVITY_PENALTY_QUOTIENT_ALTAIR*: uint64
|
||||
MIN_SLASHING_PENALTY_QUOTIENT_ALTAIR*: uint64
|
||||
PROPORTIONAL_SLASHING_MULTIPLIER_ALTAIR*: uint64
|
||||
|
@ -301,7 +301,7 @@ type
|
|||
MIN_SYNC_COMMITTEE_PARTICIPANTS*: uint64
|
||||
UPDATE_TIMEOUT*: uint64
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/bellatrix.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/bellatrix.yaml
|
||||
INACTIVITY_PENALTY_QUOTIENT_BELLATRIX*: uint64
|
||||
MIN_SLASHING_PENALTY_QUOTIENT_BELLATRIX*: uint64
|
||||
PROPORTIONAL_SLASHING_MULTIPLIER_BELLATRIX*: uint64
|
||||
|
@ -343,7 +343,7 @@ type
|
|||
DEPOSIT_NETWORK_ID*: uint64
|
||||
DEPOSIT_CONTRACT_ADDRESS*: Eth1Address
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#constants
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#constants
|
||||
# GENESIS_SLOT
|
||||
# GENESIS_EPOCH
|
||||
# FAR_FUTURE_EPOCH
|
||||
|
|
|
@ -648,7 +648,7 @@ func toBeaconBlockFork*(fork: BeaconStateFork): BeaconBlockFork =
|
|||
of BeaconStateFork.Altair: BeaconBlockFork.Altair
|
||||
of BeaconStateFork.Bellatrix: BeaconBlockFork.Bellatrix
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_fork_data_root
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_fork_data_root
|
||||
func compute_fork_data_root*(current_version: Version,
|
||||
genesis_validators_root: Eth2Digest): Eth2Digest =
|
||||
## Return the 32-byte fork data root for the ``current_version`` and
|
||||
|
@ -660,7 +660,7 @@ func compute_fork_data_root*(current_version: Version,
|
|||
genesis_validators_root: genesis_validators_root
|
||||
))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_fork_digest
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_fork_digest
|
||||
func compute_fork_digest*(current_version: Version,
|
||||
genesis_validators_root: Eth2Digest): ForkDigest =
|
||||
## Return the 4-byte fork digest for the ``current_version`` and
|
||||
|
|
|
@ -43,7 +43,7 @@ func shortLog*(v: FinalityCheckpoints): auto =
|
|||
|
||||
chronicles.formatIt FinalityCheckpoints: it.shortLog
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#integer_squareroot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#integer_squareroot
|
||||
func integer_squareroot*(n: SomeInteger): SomeInteger =
|
||||
## Return the largest integer ``x`` such that ``x**2 <= n``.
|
||||
doAssert n >= 0'u64
|
||||
|
@ -56,7 +56,7 @@ func integer_squareroot*(n: SomeInteger): SomeInteger =
|
|||
y = (x + n div x) div 2
|
||||
x
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_active_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_active_validator
|
||||
func is_active_validator*(validator: Validator, epoch: Epoch): bool =
|
||||
## Check if ``validator`` is active
|
||||
validator.activation_epoch <= epoch and epoch < validator.exit_epoch
|
||||
|
@ -68,7 +68,7 @@ func is_exited_validator*(validator: Validator, epoch: Epoch): bool =
|
|||
func is_withdrawable_validator*(validator: Validator, epoch: Epoch): bool =
|
||||
epoch >= validator.withdrawable_epoch
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||
iterator get_active_validator_indices*(state: ForkyBeaconState, epoch: Epoch):
|
||||
ValidatorIndex =
|
||||
for vidx in state.validators.vindices:
|
||||
|
@ -94,23 +94,23 @@ func get_active_validator_indices_len*(
|
|||
withState(state):
|
||||
get_active_validator_indices_len(state.data, epoch)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_current_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_current_epoch
|
||||
func get_current_epoch*(state: ForkyBeaconState): Epoch =
|
||||
## Return the current epoch.
|
||||
state.slot.epoch
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_current_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_current_epoch
|
||||
func get_current_epoch*(state: ForkedHashedBeaconState): Epoch =
|
||||
## Return the current epoch.
|
||||
withState(state): get_current_epoch(state.data)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_previous_epoch
|
||||
func get_previous_epoch*(
|
||||
state: ForkyBeaconState | ForkedHashedBeaconState): Epoch =
|
||||
## Return the previous epoch (unless the current epoch is ``GENESIS_EPOCH``).
|
||||
get_previous_epoch(get_current_epoch(state))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_randao_mix
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_randao_mix
|
||||
func get_randao_mix*(state: ForkyBeaconState, epoch: Epoch): Eth2Digest =
|
||||
## Returns the randao mix at a recent ``epoch``.
|
||||
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
|
||||
|
@ -126,7 +126,7 @@ func uint_to_bytes*(x: uint32): array[4, byte] = toBytesLE(x)
|
|||
func uint_to_bytes*(x: uint16): array[2, byte] = toBytesLE(x)
|
||||
func uint_to_bytes*(x: uint8): array[1, byte] = toBytesLE(x)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_domain
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_domain
|
||||
func compute_domain*(
|
||||
domain_type: DomainType,
|
||||
fork_version: Version,
|
||||
|
@ -141,7 +141,7 @@ func compute_domain*(
|
|||
result[0..3] = domain_type.data
|
||||
result[4..31] = fork_data_root.data.toOpenArray(0, 27)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_domain
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_domain
|
||||
func get_domain*(
|
||||
fork: Fork,
|
||||
domain_type: DomainType,
|
||||
|
@ -162,7 +162,7 @@ func get_domain*(
|
|||
## of a message.
|
||||
get_domain(state.fork, domain_type, epoch, state.genesis_validators_root)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_signing_root
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_signing_root
|
||||
func compute_signing_root*(ssz_object: auto, domain: Eth2Domain): Eth2Digest =
|
||||
## Return the signing root of an object by calculating the root of the
|
||||
## object-domain tree.
|
||||
|
@ -172,7 +172,7 @@ func compute_signing_root*(ssz_object: auto, domain: Eth2Domain): Eth2Digest =
|
|||
)
|
||||
hash_tree_root(domain_wrapped_object)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_seed
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_seed
|
||||
func get_seed*(state: ForkyBeaconState, epoch: Epoch, domain_type: DomainType):
|
||||
Eth2Digest =
|
||||
## Return the seed at ``epoch``.
|
||||
|
|
|
@ -21,20 +21,20 @@ import
|
|||
export base
|
||||
|
||||
const
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#topics-and-messages
|
||||
topicBeaconBlocksSuffix* = "beacon_block/ssz_snappy"
|
||||
topicVoluntaryExitsSuffix* = "voluntary_exit/ssz_snappy"
|
||||
topicProposerSlashingsSuffix* = "proposer_slashing/ssz_snappy"
|
||||
topicAttesterSlashingsSuffix* = "attester_slashing/ssz_snappy"
|
||||
topicAggregateAndProofsSuffix* = "beacon_aggregate_and_proof/ssz_snappy"
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#configuration
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#configuration
|
||||
MAX_CHUNK_SIZE* = 1 * 1024 * 1024 # bytes
|
||||
GOSSIP_MAX_SIZE* = 1 * 1024 * 1024 # bytes
|
||||
TTFB_TIMEOUT* = 5.seconds
|
||||
RESP_TIMEOUT* = 10.seconds
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/p2p-interface.md#configuration
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/bellatrix/p2p-interface.md#configuration
|
||||
GOSSIP_MAX_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
|
||||
MAX_CHUNK_SIZE_BELLATRIX* = 10 * 1024 * 1024 # bytes
|
||||
|
||||
|
@ -89,13 +89,13 @@ func getAttestationTopic*(forkDigest: ForkDigest,
|
|||
## For subscribing and unsubscribing to/from a subnet.
|
||||
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz_snappy"
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#topics-and-messages
|
||||
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
|
||||
subcommitteeIdx: SyncSubcommitteeIndex): string =
|
||||
## For subscribing and unsubscribing to/from a subnet.
|
||||
eth2Prefix(forkDigest) & "sync_committee_" & $subcommitteeIdx & "/ssz_snappy"
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#topics-and-messages
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#topics-and-messages
|
||||
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
|
||||
## For subscribing and unsubscribing to/from a subnet.
|
||||
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof/ssz_snappy"
|
||||
|
@ -142,7 +142,7 @@ func getDiscoveryForkID*(cfg: RuntimeConfig,
|
|||
next_fork_version: current_fork_version,
|
||||
next_fork_epoch: FAR_FUTURE_EPOCH)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/altair/p2p-interface.md#transitioning-the-gossip
|
||||
type GossipState* = set[BeaconStateFork]
|
||||
func getTargetGossipState*(
|
||||
epoch, ALTAIR_FORK_EPOCH, BELLATRIX_FORK_EPOCH: Epoch, isBehind: bool):
|
||||
|
|
|
@ -15,7 +15,7 @@ import
|
|||
stew/[byteutils], stint, web3/[ethtypes]
|
||||
|
||||
const
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#withdrawal-prefixes
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#withdrawal-prefixes
|
||||
BLS_WITHDRAWAL_PREFIX*: byte = 0
|
||||
ETH1_ADDRESS_WITHDRAWAL_PREFIX*: byte = 1
|
||||
|
||||
|
@ -483,7 +483,7 @@ template name*(cfg: RuntimeConfig): string =
|
|||
else:
|
||||
const_preset
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#configuration
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#configuration
|
||||
func MIN_EPOCHS_FOR_BLOCK_REQUESTS*(cfg: RuntimeConfig): uint64 =
|
||||
cfg.MIN_VALIDATOR_WITHDRAWABILITY_DELAY + cfg.CHURN_LIMIT_QUOTIENT div 2
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Mainnet preset - Altair
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/altair.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/altair.yaml
|
||||
const
|
||||
# Updated penalty values
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Mainnet preset - Bellatrix
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/bellatrix.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/bellatrix.yaml
|
||||
const
|
||||
# Updated penalty values
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Mainnet preset - Phase0
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/mainnet/phase0.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/mainnet/phase0.yaml
|
||||
|
||||
const
|
||||
#
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Minimal preset - Altair
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/minimal/altair.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/minimal/altair.yaml
|
||||
const
|
||||
# Updated penalty values
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Minimal preset - Bellatrix
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/minimal/bellatrix.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/minimal/bellatrix.yaml
|
||||
const
|
||||
# Updated penalty values
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Minimal preset - Phase0
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/presets/minimal/phase0.yaml
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/presets/minimal/phase0.yaml
|
||||
|
||||
const
|
||||
#
|
||||
|
|
|
@ -184,7 +184,7 @@ func compute_deposit_signing_root*(
|
|||
domain = compute_domain(DOMAIN_DEPOSIT, version)
|
||||
compute_signing_root(deposit_message, domain)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#deposits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#deposits
|
||||
func get_deposit_signature*(preset: RuntimeConfig,
|
||||
deposit: DepositData,
|
||||
privkey: ValidatorPrivKey): CookedSig =
|
||||
|
|
|
@ -77,7 +77,7 @@ proc aggregateAttesters(
|
|||
# Aggregation spec requires non-empty collection
|
||||
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
|
||||
# Eth2 spec requires at least one attesting index in attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
return err("aggregateAttesters: no attesting indices")
|
||||
|
||||
let
|
||||
|
@ -106,7 +106,7 @@ proc aggregateAttesters(
|
|||
# Aggregation spec requires non-empty collection
|
||||
# - https://tools.ietf.org/html/draft-irtf-cfrg-bls-signature-04
|
||||
# Eth2 spec requires at least one attesting index in attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
# - https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_valid_indexed_attestation
|
||||
return err("aggregateAttesters: no attesting indices")
|
||||
|
||||
var attestersAgg{.noinit.}: AggregatePublicKey
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
# State transition, as described in
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
#
|
||||
# The entry point is `state_transition` which is at the bottom of the file!
|
||||
#
|
||||
|
@ -54,7 +54,7 @@ import
|
|||
|
||||
export results, extras, phase0, altair, bellatrix
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
proc verify_block_signature(
|
||||
state: ForkyBeaconState, signed_block: SomeForkySignedBeaconBlock):
|
||||
Result[void, cstring] =
|
||||
|
@ -71,7 +71,7 @@ proc verify_block_signature(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
func verifyStateRoot(
|
||||
state: ForkyBeaconState, blck: ForkyBeaconBlock | ForkySigVerifiedBeaconBlock):
|
||||
Result[void, cstring] =
|
||||
|
@ -100,7 +100,7 @@ func noRollback*() =
|
|||
# Hashed-state transition functions
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
func process_slot*(
|
||||
state: var ForkyBeaconState, pre_state_root: Eth2Digest) =
|
||||
# `process_slot` is the first stage of per-slot processing - it is run for
|
||||
|
@ -125,7 +125,7 @@ func clear_epoch_from_cache(cache: var StateCache, epoch: Epoch) =
|
|||
for slot in epoch.slots():
|
||||
cache.beacon_proposer_indices.del slot
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||
proc advance_slot(
|
||||
cfg: RuntimeConfig,
|
||||
state: var ForkyBeaconState, previous_slot_state_root: Eth2Digest,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
# State transition - block processing, as described in
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#block-processing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#block-processing
|
||||
#
|
||||
# The entry point is `process_block` which is at the bottom of this file.
|
||||
#
|
||||
|
@ -31,7 +31,7 @@ import
|
|||
|
||||
export extras, phase0, altair
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#block-header
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#block-header
|
||||
func process_block_header*(
|
||||
state: var ForkyBeaconState, blck: SomeForkyBeaconBlock, flags: UpdateFlags,
|
||||
cache: var StateCache): Result[void, cstring] =
|
||||
|
@ -74,7 +74,7 @@ func `xor`[T: array](a, b: T): T =
|
|||
for i in 0..<result.len:
|
||||
result[i] = a[i] xor b[i]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#randao
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#randao
|
||||
proc process_randao(
|
||||
state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody, flags: UpdateFlags,
|
||||
cache: var StateCache): Result[void, cstring] =
|
||||
|
@ -107,7 +107,7 @@ proc process_randao(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#eth1-data
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#eth1-data
|
||||
func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBody): Result[void, cstring]=
|
||||
if not state.eth1_data_votes.add body.eth1_data:
|
||||
# Count is reset in process_final_updates, so this should never happen
|
||||
|
@ -118,14 +118,14 @@ func process_eth1_data(state: var ForkyBeaconState, body: SomeForkyBeaconBlockBo
|
|||
state.eth1_data = body.eth1_data
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_slashable_validator
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_slashable_validator
|
||||
func is_slashable_validator(validator: Validator, epoch: Epoch): bool =
|
||||
# Check if ``validator`` is slashable.
|
||||
(not validator.slashed) and
|
||||
(validator.activation_epoch <= epoch) and
|
||||
(epoch < validator.withdrawable_epoch)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#proposer-slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#proposer-slashings
|
||||
proc check_proposer_slashing*(
|
||||
state: ForkyBeaconState, proposer_slashing: SomeProposerSlashing,
|
||||
flags: UpdateFlags):
|
||||
|
@ -174,7 +174,7 @@ proc check_proposer_slashing*(
|
|||
withState(state):
|
||||
check_proposer_slashing(state.data, proposer_slashing, flags)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#proposer-slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#proposer-slashings
|
||||
proc process_proposer_slashing*(
|
||||
cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||
proposer_slashing: SomeProposerSlashing, flags: UpdateFlags,
|
||||
|
@ -184,7 +184,7 @@ proc process_proposer_slashing*(
|
|||
? slash_validator(cfg, state, proposer_index, cache)
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#is_slashable_attestation_data
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#is_slashable_attestation_data
|
||||
func is_slashable_attestation_data(
|
||||
data_1: AttestationData, data_2: AttestationData): bool =
|
||||
## 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_2.target.epoch < data_1.target.epoch)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attester-slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attester-slashings
|
||||
proc check_attester_slashing*(
|
||||
state: ForkyBeaconState,
|
||||
attester_slashing: SomeAttesterSlashing,
|
||||
|
@ -238,7 +238,7 @@ proc check_attester_slashing*(
|
|||
withState(state):
|
||||
check_attester_slashing(state.data, attester_slashing, flags)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attester-slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attester-slashings
|
||||
proc process_attester_slashing*(
|
||||
cfg: RuntimeConfig,
|
||||
state: var ForkyBeaconState,
|
||||
|
@ -321,7 +321,7 @@ proc process_deposit*(cfg: RuntimeConfig,
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#voluntary-exits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#voluntary-exits
|
||||
proc check_voluntary_exit*(
|
||||
cfg: RuntimeConfig,
|
||||
state: ForkyBeaconState,
|
||||
|
@ -370,7 +370,7 @@ proc check_voluntary_exit*(
|
|||
withState(state):
|
||||
check_voluntary_exit(cfg, state.data, signed_voluntary_exit, flags)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#voluntary-exits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#voluntary-exits
|
||||
proc process_voluntary_exit*(
|
||||
cfg: RuntimeConfig,
|
||||
state: var ForkyBeaconState,
|
||||
|
@ -382,7 +382,7 @@ proc process_voluntary_exit*(
|
|||
? initiate_validator_exit(cfg, state, exited_validator, cache)
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#operations
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#operations
|
||||
proc process_operations(cfg: RuntimeConfig,
|
||||
state: var ForkyBeaconState,
|
||||
body: SomeForkyBeaconBlockBody,
|
||||
|
@ -525,7 +525,7 @@ proc process_execution_payload*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#block-processing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#block-processing
|
||||
# TODO workaround for https://github.com/nim-lang/Nim/issues/18095
|
||||
# copy of datatypes/phase0.nim
|
||||
type SomePhase0Block =
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
# State transition - epoch processing, as described in
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#epoch-processing and
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#epoch-processing and
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#epoch-processing
|
||||
#
|
||||
# The entry point is `process_epoch`, which is at the bottom of this file.
|
||||
|
@ -38,7 +38,7 @@ export extras, phase0, altair
|
|||
logScope: topics = "consens"
|
||||
|
||||
# Accessors that implement the max condition in `get_total_balance`:
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_total_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_total_balance
|
||||
template current_epoch*(v: TotalBalances): Gwei =
|
||||
max(EFFECTIVE_BALANCE_INCREMENT, v.current_epoch_raw)
|
||||
template previous_epoch*(v: TotalBalances): Gwei =
|
||||
|
@ -153,7 +153,7 @@ func process_attestations*(
|
|||
if v.flags.contains RewardFlags.isPreviousEpochHeadAttester:
|
||||
info.balances.previous_epoch_head_attesters_raw += validator_balance
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#helpers
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#helpers
|
||||
# get_eligible_validator_indices
|
||||
func is_eligible_validator*(validator: RewardStatus): bool =
|
||||
validator.flags.contains(RewardFlags.isActiveInPreviousEpoch) or
|
||||
|
@ -171,7 +171,7 @@ func is_eligible_validator*(validator: ParticipationInfo): bool =
|
|||
# --------------------------------------------------------
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#get_unslashed_participating_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_total_balance
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_total_balance
|
||||
func get_unslashed_participating_balances*(
|
||||
state: altair.BeaconState | bellatrix.BeaconState
|
||||
): UnslashedParticipatingBalances =
|
||||
|
@ -238,7 +238,7 @@ func is_unslashed_participating_index(
|
|||
has_flag(epoch_participation[].item(validator_index), flag_index) and
|
||||
not state.validators[validator_index].slashed
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
type FinalityState = object
|
||||
slot: Slot
|
||||
current_epoch_ancestor_root: Eth2Digest
|
||||
|
@ -306,7 +306,7 @@ proc weigh_justification_and_finalization(
|
|||
## state.justification_bits[1:] = state.justification_bits[:-1]
|
||||
## state.justification_bits[0] = 0b0
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#misc
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#misc
|
||||
const JUSTIFICATION_BITS_LENGTH = 4
|
||||
|
||||
state.justification_bits = JustificationBits(
|
||||
|
@ -382,7 +382,7 @@ proc weigh_justification_and_finalization(
|
|||
current_epoch = current_epoch,
|
||||
checkpoint = shortLog(state.finalized_checkpoint)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
proc process_justification_and_finalization*(
|
||||
state: var phase0.BeaconState,
|
||||
balances: TotalBalances, flags: UpdateFlags = {}) =
|
||||
|
@ -456,7 +456,7 @@ proc compute_unrealized_finality*(
|
|||
justified: finalityState.current_justified_checkpoint,
|
||||
finalized: finalityState.finalized_checkpoint)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#helpers
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#helpers
|
||||
func get_base_reward_sqrt*(state: phase0.BeaconState, index: ValidatorIndex,
|
||||
total_balance_sqrt: auto): Gwei =
|
||||
# Spec function recalculates total_balance every time, which creates an
|
||||
|
@ -504,7 +504,7 @@ func get_attestation_component_delta(is_unslashed_attester: bool,
|
|||
else:
|
||||
RewardDelta(penalties: base_reward)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#components-of-attestation-deltas
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#components-of-attestation-deltas
|
||||
func get_source_delta*(validator: RewardStatus,
|
||||
base_reward: uint64,
|
||||
balances: TotalBalances,
|
||||
|
@ -582,7 +582,7 @@ func get_inactivity_penalty_delta*(validator: RewardStatus,
|
|||
|
||||
delta
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_attestation_deltas
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_attestation_deltas
|
||||
func get_attestation_deltas(state: phase0.BeaconState, info: var phase0.EpochInfo) =
|
||||
## Update rewards with attestation reward/penalty deltas for each validator.
|
||||
|
||||
|
@ -747,7 +747,7 @@ iterator get_inactivity_penalty_deltas*(
|
|||
state.inactivity_scores[vidx]
|
||||
yield (vidx, Gwei(penalty_numerator div penalty_denominator))
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#rewards-and-penalties-1
|
||||
func process_rewards_and_penalties(
|
||||
state: var phase0.BeaconState, info: var phase0.EpochInfo) =
|
||||
# No rewards are applied at the end of `GENESIS_EPOCH` because rewards are
|
||||
|
@ -805,7 +805,7 @@ func process_rewards_and_penalties(
|
|||
decrease_balance(balance, info.validators[vidx].delta.penalties)
|
||||
state.balances.asSeq()[vidx] = balance
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#registry-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#registry-updates
|
||||
func process_registry_updates*(
|
||||
cfg: RuntimeConfig, state: var ForkyBeaconState, cache: var StateCache):
|
||||
Result[void, cstring] =
|
||||
|
@ -858,7 +858,7 @@ func process_registry_updates*(
|
|||
|
||||
ok()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#slashings
|
||||
func get_adjusted_total_slashing_balance*(
|
||||
|
@ -876,14 +876,14 @@ func get_adjusted_total_slashing_balance*(
|
|||
{.fatal: "process_slashings: incorrect BeaconState type".}
|
||||
min(sum(state.slashings.data) * multiplier, total_balance)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#slashings
|
||||
func slashing_penalty_applies*(validator: Validator, epoch: Epoch): bool =
|
||||
validator.slashed and
|
||||
epoch + EPOCHS_PER_SLASHINGS_VECTOR div 2 == validator.withdrawable_epoch
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#slashings
|
||||
func get_slashing_penalty*(validator: Validator,
|
||||
|
@ -895,7 +895,7 @@ func get_slashing_penalty*(validator: Validator,
|
|||
adjusted_total_slashing_balance
|
||||
penalty_numerator div total_balance * increment
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/altair/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/bellatrix/beacon-chain.md#slashings
|
||||
func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
||||
|
@ -911,7 +911,7 @@ func process_slashings*(state: var ForkyBeaconState, total_balance: Gwei) =
|
|||
validator[], adjusted_total_slashing_balance, total_balance)
|
||||
decrease_balance(state, vidx, penalty)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#eth1-data-votes-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#eth1-data-votes-updates
|
||||
func process_eth1_data_reset*(state: var ForkyBeaconState) =
|
||||
let next_epoch = get_current_epoch(state) + 1
|
||||
|
||||
|
@ -919,7 +919,7 @@ func process_eth1_data_reset*(state: var ForkyBeaconState) =
|
|||
if next_epoch mod EPOCHS_PER_ETH1_VOTING_PERIOD == 0:
|
||||
state.eth1_data_votes = default(type state.eth1_data_votes)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#effective-balances-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#effective-balances-updates
|
||||
func process_effective_balance_updates*(state: var ForkyBeaconState) =
|
||||
# Update effective balances with hysteresis
|
||||
for vidx in state.validators.vindices:
|
||||
|
@ -941,14 +941,14 @@ func process_effective_balance_updates*(state: var ForkyBeaconState) =
|
|||
if new_effective_balance != effective_balance:
|
||||
state.validators.mitem(vidx).effective_balance = new_effective_balance
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings-balances-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings-balances-updates
|
||||
func process_slashings_reset*(state: var ForkyBeaconState) =
|
||||
let next_epoch = get_current_epoch(state) + 1
|
||||
|
||||
# Reset slashings
|
||||
state.slashings[int(next_epoch mod EPOCHS_PER_SLASHINGS_VECTOR)] = 0.Gwei
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#randao-mixes-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#randao-mixes-updates
|
||||
func process_randao_mixes_reset*(state: var ForkyBeaconState) =
|
||||
let
|
||||
current_epoch = get_current_epoch(state)
|
||||
|
@ -961,12 +961,12 @@ func process_randao_mixes_reset*(state: var ForkyBeaconState) =
|
|||
func compute_historical_root*(state: var ForkyBeaconState): Eth2Digest =
|
||||
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
|
||||
# significant additional stack or heap.
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#historicalbatch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#historicalbatch
|
||||
# In response to https://github.com/status-im/nimbus-eth2/issues/921
|
||||
hash_tree_root([
|
||||
hash_tree_root(state.block_roots), hash_tree_root(state.state_roots)])
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#historical-roots-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#historical-roots-updates
|
||||
func process_historical_roots_update*(state: var ForkyBeaconState) =
|
||||
## Set historical root accumulator
|
||||
let next_epoch = get_current_epoch(state) + 1
|
||||
|
@ -974,12 +974,12 @@ func process_historical_roots_update*(state: var ForkyBeaconState) =
|
|||
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0:
|
||||
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
|
||||
# significant additional stack or heap.
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#historicalbatch
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#historicalbatch
|
||||
# In response to https://github.com/status-im/nimbus-eth2/issues/921
|
||||
if not state.historical_roots.add state.compute_historical_root():
|
||||
raiseAssert "no more room for historical roots, so long and thanks for the fish!"
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#participation-records-rotation
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#participation-records-rotation
|
||||
func process_participation_record_updates*(state: var phase0.BeaconState) =
|
||||
# Rotate current/previous epoch attestations - using swap avoids copying all
|
||||
# elements using a slow genericSeqAssign
|
||||
|
@ -1043,7 +1043,7 @@ func process_inactivity_updates*(
|
|||
if pre_inactivity_score != inactivity_score:
|
||||
state.inactivity_scores[index] = inactivity_score
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#epoch-processing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#epoch-processing
|
||||
proc process_epoch*(
|
||||
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,
|
||||
cache: var StateCache, info: var phase0.EpochInfo): Result[void, cstring] =
|
||||
|
@ -1110,7 +1110,7 @@ proc process_epoch*(
|
|||
|
||||
info.init(state)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#justification-and-finalization
|
||||
process_justification_and_finalization(state, info.balances, flags)
|
||||
|
||||
# state.slot hasn't been incremented yet.
|
||||
|
@ -1125,13 +1125,13 @@ proc process_epoch*(
|
|||
|
||||
process_inactivity_updates(cfg, state, info) # [New in Altair]
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#process_rewards_and_penalties
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#process_rewards_and_penalties
|
||||
process_rewards_and_penalties(cfg, state, info)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#registry-updates
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#registry-updates
|
||||
? process_registry_updates(cfg, state, cache)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#slashings
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#slashings
|
||||
process_slashings(state, info.balances.current_epoch)
|
||||
|
||||
process_eth1_data_reset(state)
|
||||
|
|
|
@ -25,8 +25,8 @@ const
|
|||
PIVOT_VIEW_SIZE = SEED_SIZE + ROUND_SIZE
|
||||
TOTAL_SIZE = PIVOT_VIEW_SIZE + POSITION_WINDOW_SIZE
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_committee
|
||||
# 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
|
||||
func shuffle_list*(input: var seq[ValidatorIndex], seed: Eth2Digest) =
|
||||
|
@ -156,13 +156,13 @@ func get_shuffled_active_validator_indices*(
|
|||
withState(state):
|
||||
cache.get_shuffled_active_validator_indices(state.data, epoch)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_active_validator_indices
|
||||
func count_active_validators*(state: ForkyBeaconState,
|
||||
epoch: Epoch,
|
||||
cache: var StateCache): uint64 =
|
||||
cache.get_shuffled_active_validator_indices(state, epoch).lenu64
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_committee_count_per_slot
|
||||
func get_committee_count_per_slot*(num_active_validators: uint64): uint64 =
|
||||
clamp(
|
||||
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
||||
|
@ -187,7 +187,7 @@ iterator get_committee_indices*(committee_count_per_slot: uint64): CommitteeInde
|
|||
let committee_index = CommitteeIndex.init(idx).expect("value clamped")
|
||||
yield committee_index
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_committee
|
||||
func compute_committee_slice*(
|
||||
active_validators, index, count: uint64): Slice[int] =
|
||||
doAssert active_validators <= ValidatorIndex.high.uint64
|
||||
|
@ -233,7 +233,7 @@ func compute_committee_len*(
|
|||
|
||||
(slice.b - slice.a + 1).uint64
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
iterator get_beacon_committee*(
|
||||
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
||||
cache: var StateCache): (int, ValidatorIndex) =
|
||||
|
@ -273,7 +273,7 @@ func get_beacon_committee*(
|
|||
withState(state):
|
||||
get_beacon_committee(state.data, slot, index, cache)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_committee
|
||||
func get_beacon_committee_len*(
|
||||
state: ForkyBeaconState, slot: Slot, index: CommitteeIndex,
|
||||
cache: var StateCache): uint64 =
|
||||
|
@ -296,7 +296,7 @@ func get_beacon_committee_len*(
|
|||
withState(state):
|
||||
get_beacon_committee_len(state.data, slot, index, cache)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_shuffled_index
|
||||
func compute_shuffled_index*(
|
||||
index: uint64, index_count: uint64, seed: Eth2Digest): uint64 =
|
||||
## Return the shuffled index corresponding to ``seed`` (and ``index_count``).
|
||||
|
@ -331,7 +331,7 @@ func compute_shuffled_index*(
|
|||
|
||||
cur_idx_permuted
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#compute_proposer_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#compute_proposer_index
|
||||
func compute_proposer_index(state: ForkyBeaconState,
|
||||
indices: seq[ValidatorIndex], seed: Eth2Digest): Option[ValidatorIndex] =
|
||||
## Return from ``indices`` a random index sampled by effective balance.
|
||||
|
@ -358,7 +358,7 @@ func compute_proposer_index(state: ForkyBeaconState,
|
|||
return some(candidate_index)
|
||||
i += 1
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||
func get_beacon_proposer_index*(
|
||||
state: ForkyBeaconState, cache: var StateCache, slot: Slot):
|
||||
Option[ValidatorIndex] =
|
||||
|
@ -396,7 +396,7 @@ func get_beacon_proposer_index*(
|
|||
|
||||
return res
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#get_beacon_proposer_index
|
||||
func get_beacon_proposer_index*(state: ForkyBeaconState, cache: var StateCache):
|
||||
Option[ValidatorIndex] =
|
||||
get_beacon_proposer_index(state, cache, state.slot)
|
||||
|
|
|
@ -29,7 +29,7 @@ func compute_weak_subjectivity_period(
|
|||
SAFETY_DECAY * validator_count div (2 * 100 * cfg.MIN_PER_EPOCH_CHURN_LIMIT)
|
||||
return weak_subjectivity_period
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/weak-subjectivity.md#checking-for-stale-weak-subjectivity-checkpoint
|
||||
func is_within_weak_subjectivity_period*(cfg: RuntimeConfig, current_slot: Slot,
|
||||
ws_state: ForkedHashedBeaconState,
|
||||
ws_checkpoint: Checkpoint): bool =
|
||||
|
|
|
@ -302,7 +302,7 @@ p2pProtocol BeaconSync(version = 1,
|
|||
|
||||
if startSlot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH:
|
||||
# "Clients MAY limit the number of blocks in the response."
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beaconblocksbyrange
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beaconblocksbyrange
|
||||
debug "Block range v1 request for post-altair range",
|
||||
peer, startSlot, reqCount, reqStep
|
||||
return
|
||||
|
@ -392,7 +392,7 @@ p2pProtocol BeaconSync(version = 1,
|
|||
if blockRef.slot.epoch >= dag.cfg.ALTAIR_FORK_EPOCH:
|
||||
# Skipping this block should be fine because the spec says:
|
||||
# "Clients MAY limit the number of blocks in the response."
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beaconblocksbyroot
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#beaconblocksbyroot
|
||||
#
|
||||
# Also, our response would be indistinguishable from a node
|
||||
# that have been synced exactly to the altair transition slot.
|
||||
|
|
|
@ -7,9 +7,9 @@ This is a WIP document to explain the attestation flows.
|
|||
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.
|
||||
- Aggregated: https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||
- Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#beacon_attestation_subnet_id
|
||||
- Unaggregated: https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/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.
|
||||
- https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#attestations
|
||||
- https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#attestations
|
||||
|
||||
From the specs it seems like gossip attestation `validation` is a superset of consensus attestation `verification`.
|
||||
|
||||
|
@ -52,7 +52,7 @@ These GossipSub topics are used to listen for attestations:
|
|||
|
||||
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.10/specs/phase0/p2p-interface.md#beacon_aggregate_and_proof
|
||||
- https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/p2p-interface.md#attestation-subnets
|
||||
- https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/p2p-interface.md#attestation-subnets
|
||||
|
||||
Finally, valid attestations are added to the local `attestationPool`.
|
||||
Attestations are dropped in case of an error.
|
||||
|
|
|
@ -9,7 +9,7 @@ Important distinction:
|
|||
https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#beacon_block.
|
||||
A validated block can be forwarded on gossipsub.
|
||||
- and we distinguish `verification` which is defined in consensus specs:
|
||||
https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#block-processing
|
||||
https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#block-processing
|
||||
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:
|
||||
|
|
|
@ -16,7 +16,7 @@ import
|
|||
# Routines for mocking blocks
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/test/helpers/block.py#L26-L35
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/test/helpers/block.py#L26-L35
|
||||
func apply_randao_reveal(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
|
||||
doAssert state.slot <= blck.message.slot
|
||||
let
|
||||
|
@ -29,7 +29,7 @@ func apply_randao_reveal(state: ForkyBeaconState, blck: var ForkySignedBeaconBlo
|
|||
blck.message.slot.epoch,
|
||||
privkey).toValidatorSig()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/test/helpers/block.py#L38-L54
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/test/helpers/block.py#L38-L54
|
||||
func sign_block(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
|
||||
let
|
||||
proposer_index = blck.message.proposer_index.ValidatorIndex
|
||||
|
@ -43,7 +43,7 @@ func sign_block(state: ForkyBeaconState, blck: var ForkySignedBeaconBlock) =
|
|||
blck.root,
|
||||
privkey).toValidatorSig()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/test/helpers/block.py#L75-L104
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/test/helpers/block.py#L75-L104
|
||||
proc mockBlock*(
|
||||
state: ForkedHashedBeaconState,
|
||||
slot: Slot,
|
||||
|
@ -83,7 +83,7 @@ proc mockBlock*(
|
|||
|
||||
sign_block(state.data, blck)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/test/helpers/block.py#L107-L108
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/test/helpers/block.py#L107-L108
|
||||
proc mockBlockForNextSlot*(
|
||||
state: ForkedHashedBeaconState): ForkedSignedBeaconBlock =
|
||||
## Mock a BeaconBlock for the next slot
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
# process_deposit (beaconstate.nim)
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/specs/phase0/beacon-chain.md#deposits
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/specs/phase0/beacon-chain.md#deposits
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
{.used.}
|
||||
|
|
|
@ -22,7 +22,7 @@ const
|
|||
MockPrivKeys* = MockPrivKeysT()
|
||||
MockPubKeys* = MockPubKeysT()
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.1/tests/core/pyspec/eth2spec/test/helpers/keys.py
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.2.0-rc.2/tests/core/pyspec/eth2spec/test/helpers/keys.py
|
||||
func `[]`*(_: MockPrivKeysT, index: ValidatorIndex): ValidatorPrivKey =
|
||||
# 0 is not a valid BLS private key - 1000 helps interop with rust BLS library,
|
||||
# lighthouse. EF tests use 1 instead of 1000.
|
||||
|
|
Loading…
Reference in New Issue