comments-only changes: update a bunch of v0.10.1 spec references to v0.11.0 and explain rationale for extended validation design in code (#847)

This commit is contained in:
tersec 2020-04-01 11:41:39 +00:00 committed by GitHub
parent f811ed63be
commit ea59f2ecf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 20 deletions

View File

@ -984,8 +984,30 @@ proc isValidBeaconBlock*(pool: BlockPool,
# The block is the first block with valid signature received for the proposer # The block is the first block with valid signature received for the proposer
# for the slot, signed_beacon_block.message.slot. # for the slot, signed_beacon_block.message.slot.
#
# While this condition is similar to the proposer slashing condition at
# https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#proposer-slashing
# it's not identical, and this check does not address slashing:
#
# (1) The beacon blocks must be conflicting, i.e. different, for the same
# slot and proposer. This check also catches identical blocks.
#
# (2) By this point in the function, it's not been checked whether they're
# signed yet. As in general, expensive checks should be deferred, this
# would add complexity not directly relevant this function.
#
# (3) As evidenced by point (1), the similarity in the validation condition
# and slashing condition, while not coincidental, aren't similar enough
# to combine, as one or the other might drift.
#
# (4) Furthermore, this function, as much as possible, simply returns a yes
# or no answer, without modifying other state for p2p network interface
# validation. Complicating this interface, for the sake of sharing only
# couple lines of code, wouldn't be worthwhile.
#
# TODO might check unresolved/orphaned blocks too, and this might not see all # TODO might check unresolved/orphaned blocks too, and this might not see all
# blocks at a given slot (though, in theory, those get checked elsewhere). # blocks at a given slot (though, in theory, those get checked elsewhere), or
# adding metrics that count how often these conditions occur.
let slotBlockRef = let slotBlockRef =
getBlockByPreciseSlot(pool, signed_beacon_block.message.slot) getBlockByPreciseSlot(pool, signed_beacon_block.message.slot)
if (not slotBlockRef.isNil) and if (not slotBlockRef.isNil) and

View File

@ -30,7 +30,7 @@ func is_valid_merkle_branch*(leaf: Eth2Digest, branch: openarray[Eth2Digest], de
value = eth2hash(buf) value = eth2hash(buf)
value == root value == root
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#increase_balance # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#increase_balance
func increase_balance*( func increase_balance*(
state: var BeaconState, index: ValidatorIndex, delta: Gwei) = state: var BeaconState, index: ValidatorIndex, delta: Gwei) =
# Increase the validator balance at index ``index`` by ``delta``. # Increase the validator balance at index ``index`` by ``delta``.
@ -272,7 +272,7 @@ func get_initial_beacon_block*(state: BeaconState): SignedBeaconBlock =
# parent_root, randao_reveal, eth1_data, signature, and body automatically # parent_root, randao_reveal, eth1_data, signature, and body automatically
# initialized to default values. # initialized to default values.
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_block_root_at_slot # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#get_block_root_at_slot
func get_block_root_at_slot*(state: BeaconState, func get_block_root_at_slot*(state: BeaconState,
slot: Slot): Eth2Digest = slot: Slot): Eth2Digest =
# Return the block root at a recent ``slot``. # Return the block root at a recent ``slot``.
@ -281,7 +281,7 @@ func get_block_root_at_slot*(state: BeaconState,
doAssert slot < state.slot doAssert slot < state.slot
state.block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT] state.block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_block_root # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#get_block_root
func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest = func get_block_root*(state: BeaconState, epoch: Epoch): Eth2Digest =
# Return the block root at the start of a recent ``epoch``. # Return the block root at the start of a recent ``epoch``.
get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch)) get_block_root_at_slot(state, compute_start_slot_at_epoch(epoch))
@ -557,7 +557,7 @@ func makeAttestationData*(
doAssert slot.compute_epoch_at_slot == current_epoch doAssert slot.compute_epoch_at_slot == current_epoch
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#attestation-data # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#attestation-data
AttestationData( AttestationData(
slot: slot, slot: slot,
index: committee_index, index: committee_index,

View File

@ -359,7 +359,7 @@ type
message*: BeaconBlockHeader message*: BeaconBlockHeader
signature*: ValidatorSig signature*: ValidatorSig
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/validator.md#aggregateandproof # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/validator.md#aggregateandproof
AggregateAndProof* = object AggregateAndProof* = object
aggregator_index*: uint64 aggregator_index*: uint64
aggregate*: Attestation aggregate*: Attestation

View File

@ -147,7 +147,7 @@ func compute_domain*(
result[0..3] = int_to_bytes4(domain_type.uint64) result[0..3] = int_to_bytes4(domain_type.uint64)
result[4..31] = fork_data_root.data[0..27] result[4..31] = fork_data_root.data[0..27]
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#get_domain # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#get_domain
func get_domain*( func get_domain*(
fork: Fork, domain_type: DomainType, epoch: Epoch, genesis_validators_root: Eth2Digest): Domain = fork: Fork, domain_type: DomainType, epoch: Epoch, genesis_validators_root: Eth2Digest): Domain =
## Return the signature domain (fork version concatenated with domain type) ## Return the signature domain (fork version concatenated with domain type)

View File

@ -130,10 +130,17 @@ const
# State vector lengths # State vector lengths
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/mainnet.yaml#L102 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/mainnet.yaml#L105
EPOCHS_PER_HISTORICAL_VECTOR* = 65536
EPOCHS_PER_SLASHINGS_VECTOR* = 8192 EPOCHS_PER_HISTORICAL_VECTOR* = 65536 ##\
HISTORICAL_ROOTS_LIMIT* = 16777216 ## epochs (~0.8 years)
EPOCHS_PER_SLASHINGS_VECTOR* = 8192 ##\
## epochs (~36 days)
HISTORICAL_ROOTS_LIMIT* = 16777216 ##\
## epochs (~26,131 years)
VALIDATOR_REGISTRY_LIMIT* = 1099511627776 VALIDATOR_REGISTRY_LIMIT* = 1099511627776
# Reward and penalty quotients # Reward and penalty quotients
@ -156,7 +163,7 @@ const
# Fork choice # Fork choice
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/mainnet.yaml#L26 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/mainnet.yaml#L32
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
# Validators # Validators

View File

@ -52,7 +52,7 @@ const
# Gwei values # Gwei values
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L52 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L58
# Unchanged # Unchanged
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
@ -117,7 +117,7 @@ const
# Reward and penalty quotients # Reward and penalty quotients
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L117 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L117
BASE_REWARD_FACTOR* = 2'u64^6 BASE_REWARD_FACTOR* = 2'u64^6
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9 WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
@ -127,7 +127,7 @@ const
# Max operations per block # Max operations per block
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L131 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L131
MAX_PROPOSER_SLASHINGS* = 2^4 MAX_PROPOSER_SLASHINGS* = 2^4
MAX_ATTESTER_SLASHINGS* = 2^0 MAX_ATTESTER_SLASHINGS* = 2^0
@ -144,7 +144,7 @@ const
# Validators # Validators
# --------------------------------------------------------------- # ---------------------------------------------------------------
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/configs/minimal.yaml#L32 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/configs/minimal.yaml#L38
# Changed # Changed
ETH1_FOLLOW_DISTANCE* = 16 # blocks ETH1_FOLLOW_DISTANCE* = 16 # blocks

View File

@ -431,7 +431,7 @@ proc process_epoch*(state: var BeaconState) {.nbench.}=
trace "ran process_justification_and_finalization", trace "ran process_justification_and_finalization",
current_epoch = get_current_epoch(state) current_epoch = get_current_epoch(state)
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1 # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#rewards-and-penalties-1
process_rewards_and_penalties(state, per_epoch_cache) process_rewards_and_penalties(state, per_epoch_cache)
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#registry-updates # https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#registry-updates

View File

@ -10,8 +10,8 @@ import
options, nimcrypto, sequtils, math, tables, options, nimcrypto, sequtils, math, tables,
./datatypes, ./digest, ./helpers ./datatypes, ./digest, ./helpers
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#compute_shuffled_index # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#compute_shuffled_index
# https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/beacon-chain.md#compute_committee # https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/beacon-chain.md#compute_committee
func get_shuffled_seq*(seed: Eth2Digest, func get_shuffled_seq*(seed: Eth2Digest,
list_size: uint64, list_size: uint64,
): seq[ValidatorIndex] = ): seq[ValidatorIndex] =

View File

@ -14,7 +14,7 @@ type
## which blocks are valid - in particular, blocks are not valid if they ## which blocks are valid - in particular, blocks are not valid if they
## come from the future as seen from the local clock. ## come from the future as seen from the local clock.
## ##
## https://github.com/ethereum/eth2.0-specs/blob/v0.10.1/specs/phase0/fork-choice.md#fork-choice ## https://github.com/ethereum/eth2.0-specs/blob/v0.11.1/specs/phase0/fork-choice.md#fork-choice
## ##
# TODO replace time in chronos with a proper unit type, then this code can # TODO replace time in chronos with a proper unit type, then this code can
# follow: # follow: