more spec changes
This commit is contained in:
parent
7cf13c22f0
commit
74cb86ec21
|
@ -180,7 +180,7 @@ proc makeAttestation(node: BeaconNode,
|
||||||
var attestation = Attestation(
|
var attestation = Attestation(
|
||||||
data: attestationData,
|
data: attestationData,
|
||||||
aggregate_signature: validatorSignature,
|
aggregate_signature: validatorSignature,
|
||||||
participation_bitfield: participationBitfield)
|
aggregation_bitfield: participationBitfield)
|
||||||
|
|
||||||
await node.network.broadcast(topicAttestations, attestation)
|
await node.network.broadcast(topicAttestations, attestation)
|
||||||
|
|
||||||
|
@ -384,7 +384,7 @@ proc processBlocks*(node: BeaconNode) =
|
||||||
|
|
||||||
node.network.subscribe(topicAttestations) do (a: Attestation):
|
node.network.subscribe(topicAttestations) do (a: Attestation):
|
||||||
let participants = get_attestation_participants(
|
let participants = get_attestation_participants(
|
||||||
node.beaconState, a.data, a.participation_bitfield).
|
node.beaconState, a.data, a.aggregation_bitfield).
|
||||||
mapIt(shortValidatorKey(node, it))
|
mapIt(shortValidatorKey(node, it))
|
||||||
|
|
||||||
info "Attestation received", slot = a.data.slot,
|
info "Attestation received", slot = a.data.slot,
|
||||||
|
|
|
@ -46,13 +46,13 @@ proc combine*(tgt: var Attestation, src: Attestation, flags: UpdateFlags) =
|
||||||
|
|
||||||
assert tgt.data == src.data
|
assert tgt.data == src.data
|
||||||
|
|
||||||
for i in 0 ..< tgt.participation_bitfield.len:
|
for i in 0 ..< tgt.aggregation_bitfield.len:
|
||||||
# TODO:
|
# TODO:
|
||||||
# when BLS signatures are combined, we must ensure that
|
# when BLS signatures are combined, we must ensure that
|
||||||
# the same participant key is not included on both sides
|
# the same participant key is not included on both sides
|
||||||
tgt.participation_bitfield[i] =
|
tgt.aggregation_bitfield[i] =
|
||||||
tgt.participation_bitfield[i] or
|
tgt.aggregation_bitfield[i] or
|
||||||
src.participation_bitfield[i]
|
src.aggregation_bitfield[i]
|
||||||
|
|
||||||
if skipValidation notin flags:
|
if skipValidation notin flags:
|
||||||
tgt.aggregate_signature.combine(src.aggregate_signature)
|
tgt.aggregate_signature.combine(src.aggregate_signature)
|
||||||
|
@ -194,7 +194,7 @@ func getAttestationVoteCount(pool: AttestationPool, current_slot: int): CountTab
|
||||||
for attestation in pool.attestations[slot]:
|
for attestation in pool.attestations[slot]:
|
||||||
if attestation.isSome:
|
if attestation.isSome:
|
||||||
# Increase the block attestation counts by the number of validators aggregated
|
# Increase the block attestation counts by the number of validators aggregated
|
||||||
let voteCount = attestation.get.participation_bitfield.getVoteCount()
|
let voteCount = attestation.get.aggregation_bitfield.getVoteCount()
|
||||||
result.inc(attestation.get.data.beacon_block_root, voteCount)
|
result.inc(attestation.get.data.beacon_block_root, voteCount)
|
||||||
|
|
||||||
proc lmdGhost*(
|
proc lmdGhost*(
|
||||||
|
|
|
@ -373,7 +373,7 @@ proc checkAttestation*(
|
||||||
|
|
||||||
let
|
let
|
||||||
participants = get_attestation_participants(
|
participants = get_attestation_participants(
|
||||||
state, attestation.data, attestation.participation_bitfield)
|
state, attestation.data, attestation.aggregation_bitfield)
|
||||||
group_public_key = bls_aggregate_pubkeys(
|
group_public_key = bls_aggregate_pubkeys(
|
||||||
participants.mapIt(state.validator_registry[it].pubkey))
|
participants.mapIt(state.validator_registry[it].pubkey))
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,6 @@
|
||||||
# The latest version can be seen here:
|
# The latest version can be seen here:
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/master/specs/beacon-chain.md
|
# https://github.com/ethereum/eth2.0-specs/blob/master/specs/beacon-chain.md
|
||||||
#
|
#
|
||||||
# How wrong the code is:
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/compare/8116562049ed80ad1823dd62e98a7483ddf1546c...master
|
|
||||||
#
|
|
||||||
# These datatypes are used as specifications for serialization - thus should not
|
# These datatypes are used as specifications for serialization - thus should not
|
||||||
# be altered outside of what the spec says. Likewise, they should not be made
|
# be altered outside of what the spec says. Likewise, they should not be made
|
||||||
# `ref` - this can be achieved by wrapping them in higher-level
|
# `ref` - this can be achieved by wrapping them in higher-level
|
||||||
|
@ -78,6 +75,7 @@ const
|
||||||
MAX_WITHDRAWALS_PER_EPOCH* = 4 # withdrawals
|
MAX_WITHDRAWALS_PER_EPOCH* = 4 # withdrawals
|
||||||
|
|
||||||
# Deposit contract
|
# Deposit contract
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md
|
||||||
DEPOSIT_CONTRACT_TREE_DEPTH* = 2^5
|
DEPOSIT_CONTRACT_TREE_DEPTH* = 2^5
|
||||||
|
|
||||||
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
||||||
|
@ -93,6 +91,7 @@ const
|
||||||
## processing is done
|
## processing is done
|
||||||
|
|
||||||
# Initial values
|
# Initial values
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#initial-values
|
||||||
GENESIS_FORK_VERSION* = 0'u64
|
GENESIS_FORK_VERSION* = 0'u64
|
||||||
GENESIS_SLOT* = 2'u64^63
|
GENESIS_SLOT* = 2'u64^63
|
||||||
GENESIS_EPOCH* = GENESIS_SLOT div EPOCH_LENGTH # slot_to_epoch(GENESIS_SLOT)
|
GENESIS_EPOCH* = GENESIS_SLOT div EPOCH_LENGTH # slot_to_epoch(GENESIS_SLOT)
|
||||||
|
@ -103,6 +102,7 @@ const
|
||||||
BLS_WITHDRAWAL_PREFIX_BYTE* = 0'u8
|
BLS_WITHDRAWAL_PREFIX_BYTE* = 0'u8
|
||||||
|
|
||||||
# Time parameters
|
# Time parameters
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#time-parameters
|
||||||
SLOT_DURATION* = 6'u64 ## \
|
SLOT_DURATION* = 6'u64 ## \
|
||||||
## TODO consistent time unit across projects, similar to C++ chrono?
|
## TODO consistent time unit across projects, similar to C++ chrono?
|
||||||
|
|
||||||
|
@ -127,18 +127,19 @@ const
|
||||||
ETH1_DATA_VOTING_PERIOD* = 2'u64^4 ##\
|
ETH1_DATA_VOTING_PERIOD* = 2'u64^4 ##\
|
||||||
## epochs (~1.7 hours)
|
## epochs (~1.7 hours)
|
||||||
|
|
||||||
MIN_VALIDATOR_WITHDRAWAL_TIME* = 2'u64^8 ##\
|
MIN_VALIDATOR_WITHDRAWAL_EPOCHS* = 2'u64^8 ##\
|
||||||
## epochs (~27 hours)
|
## epochs (~27 hours)
|
||||||
|
|
||||||
# State list lengths
|
# State list lengths
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#state-list-lengths
|
||||||
LATEST_BLOCK_ROOTS_LENGTH* = 2'u64^13
|
LATEST_BLOCK_ROOTS_LENGTH* = 2'u64^13
|
||||||
LATEST_RANDAO_MIXES_LENGTH* = 2'u64^13
|
LATEST_RANDAO_MIXES_LENGTH* = 2'u64^13
|
||||||
LATEST_INDEX_ROOTS_LENGTH* = 2'u64^13
|
LATEST_INDEX_ROOTS_LENGTH* = 2'u64^13
|
||||||
LATEST_PENALIZED_EXIT_LENGTH* = 8192 # epochs
|
LATEST_PENALIZED_EXIT_LENGTH* = 8192 # epochs
|
||||||
|
|
||||||
# Reward and penalty quotients
|
# Reward and penalty quotients
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#reward-and-penalty-quotients
|
||||||
BASE_REWARD_QUOTIENT* = 2'u64^10 ##\
|
BASE_REWARD_QUOTIENT* = 2'u64^5 ##\
|
||||||
## The `BASE_REWARD_QUOTIENT` parameter dictates the per-epoch reward. It
|
## The `BASE_REWARD_QUOTIENT` parameter dictates the per-epoch reward. It
|
||||||
## corresponds to ~2.54% annual interest assuming 10 million participating
|
## corresponds to ~2.54% annual interest assuming 10 million participating
|
||||||
## ETH in every epoch.
|
## ETH in every epoch.
|
||||||
|
@ -147,11 +148,13 @@ const
|
||||||
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^24
|
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^24
|
||||||
|
|
||||||
# Status flags
|
# Status flags
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#status-flags
|
||||||
# Could model this with enum, but following spec closely here
|
# Could model this with enum, but following spec closely here
|
||||||
INITIATED_EXIT* = 1'u64
|
INITIATED_EXIT* = 1'u64
|
||||||
WITHDRAWABLE* = 2'u64
|
WITHDRAWABLE* = 2'u64
|
||||||
|
|
||||||
# Max operations per block
|
# Max operations per block
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#max-operations-per-block
|
||||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||||
MAX_ATTESTER_SLASHINGS* = 2^0
|
MAX_ATTESTER_SLASHINGS* = 2^0
|
||||||
MAX_ATTESTATIONS* = 2^7
|
MAX_ATTESTATIONS* = 2^7
|
||||||
|
@ -163,7 +166,7 @@ type
|
||||||
SlotNumber* = uint64
|
SlotNumber* = uint64
|
||||||
EpochNumber* = uint64
|
EpochNumber* = uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/core/0_beacon-chain.md#proposerslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#proposerslashing
|
||||||
ProposerSlashing* = object
|
ProposerSlashing* = object
|
||||||
proposer_index*: ValidatorIndex
|
proposer_index*: ValidatorIndex
|
||||||
proposal_data_1*: ProposalSignedData
|
proposal_data_1*: ProposalSignedData
|
||||||
|
@ -171,38 +174,40 @@ type
|
||||||
proposal_data_2*: ProposalSignedData
|
proposal_data_2*: ProposalSignedData
|
||||||
proposal_signature_2*: ValidatorSig
|
proposal_signature_2*: ValidatorSig
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/core/0_beacon-chain.md#attesterslashing
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#attesterslashing
|
||||||
AttesterSlashing* = object
|
AttesterSlashing* = object
|
||||||
slashable_attestation_1*: SlashableAttestation ## \
|
slashable_attestation_1*: SlashableAttestation ## \
|
||||||
## First batch of votes
|
## First batch of votes
|
||||||
slashable_attestation_2*: SlashableAttestation ## \
|
slashable_attestation_2*: SlashableAttestation ## \
|
||||||
## Second batch of votes
|
## Second batch of votes
|
||||||
|
|
||||||
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/core/0_beacon-chain.md#slashableattestation
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#slashableattestation
|
||||||
SlashableAttestation* = object
|
SlashableAttestation* = object
|
||||||
validator_indices*: seq[uint64] ##\
|
validator_indices*: seq[uint64] ##\
|
||||||
## Validator indices
|
## Validator indices
|
||||||
|
|
||||||
custody_bitfield*: seq[byte] ##\
|
|
||||||
## Custody bitfield
|
|
||||||
|
|
||||||
data*: AttestationData ## \
|
data*: AttestationData ## \
|
||||||
## Attestation data
|
## Attestation data
|
||||||
|
|
||||||
|
custody_bitfield*: seq[byte] ##\
|
||||||
|
## Custody bitfield
|
||||||
|
|
||||||
aggregate_signature*: ValidatorSig ## \
|
aggregate_signature*: ValidatorSig ## \
|
||||||
## Aggregate signature
|
## Aggregate signature
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#attestation
|
||||||
Attestation* = object
|
Attestation* = object
|
||||||
data*: AttestationData
|
aggregation_bitfield*: seq[byte] ##\
|
||||||
participation_bitfield*: seq[byte] ##\
|
|
||||||
## The attesters that are represented in the aggregate signature - each
|
## The attesters that are represented in the aggregate signature - each
|
||||||
## bit represents an index in `ShardCommittee.committee`
|
## bit represents an index in `ShardCommittee.committee`
|
||||||
|
|
||||||
|
data*: AttestationData
|
||||||
custody_bitfield*: seq[byte] ##\
|
custody_bitfield*: seq[byte] ##\
|
||||||
## Custody bitfield
|
## Custody bitfield
|
||||||
aggregate_signature*: ValidatorSig ##\
|
aggregate_signature*: ValidatorSig ##\
|
||||||
## Aggregate signature of the validators in `custody_bitfield`
|
## Aggregate signature of the validators in `custody_bitfield`
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#attestationdata
|
||||||
AttestationData* = object
|
AttestationData* = object
|
||||||
slot*: uint64
|
slot*: uint64
|
||||||
shard*: uint64
|
shard*: uint64
|
||||||
|
@ -224,10 +229,12 @@ type
|
||||||
justified_block_root*: Eth2Digest ##\
|
justified_block_root*: Eth2Digest ##\
|
||||||
## Hash of last justified beacon block
|
## Hash of last justified beacon block
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#attestationdata
|
||||||
AttestationDataAndCustodyBit* = object
|
AttestationDataAndCustodyBit* = object
|
||||||
data*: AttestationData
|
data*: AttestationData
|
||||||
custody_bit: bool
|
custody_bit: bool
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#deposit
|
||||||
Deposit* = object
|
Deposit* = object
|
||||||
branch*: seq[Eth2Digest] ##\
|
branch*: seq[Eth2Digest] ##\
|
||||||
## Branch in the deposit tree
|
## Branch in the deposit tree
|
||||||
|
@ -238,11 +245,13 @@ type
|
||||||
deposit_data*: DepositData ##\
|
deposit_data*: DepositData ##\
|
||||||
## Data
|
## Data
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#depositdata
|
||||||
DepositData* = object
|
DepositData* = object
|
||||||
amount*: uint64 ## Value in Gwei
|
amount*: uint64 ## Value in Gwei
|
||||||
timestamp*: uint64 # Timestamp from deposit contract
|
timestamp*: uint64 # Timestamp from deposit contract
|
||||||
deposit_input*: DepositInput
|
deposit_input*: DepositInput
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v0.1/specs/core/0_beacon-chain.md#depositinput
|
||||||
DepositInput* = object
|
DepositInput* = object
|
||||||
pubkey*: ValidatorPubKey
|
pubkey*: ValidatorPubKey
|
||||||
withdrawal_credentials*: Eth2Digest
|
withdrawal_credentials*: Eth2Digest
|
||||||
|
|
|
@ -273,7 +273,7 @@ proc processAttestations(
|
||||||
state.latest_attestations.add blck.body.attestations.mapIt(
|
state.latest_attestations.add blck.body.attestations.mapIt(
|
||||||
PendingAttestation(
|
PendingAttestation(
|
||||||
data: it.data,
|
data: it.data,
|
||||||
participation_bitfield: it.participation_bitfield,
|
participation_bitfield: it.aggregation_bitfield,
|
||||||
custody_bitfield: it.custody_bitfield,
|
custody_bitfield: it.custody_bitfield,
|
||||||
slot_included: state.slot,
|
slot_included: state.slot,
|
||||||
)
|
)
|
||||||
|
|
|
@ -212,6 +212,6 @@ proc makeAttestation*(
|
||||||
|
|
||||||
Attestation(
|
Attestation(
|
||||||
data: data,
|
data: data,
|
||||||
participation_bitfield: participation_bitfield,
|
aggregation_bitfield: participation_bitfield,
|
||||||
aggregate_signature: sig
|
aggregate_signature: sig
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue