refactor executionPayload tests; reduce HashSet creation (#3003)
This commit is contained in:
parent
44d762119c
commit
c0a2f1c98e
|
@ -188,19 +188,6 @@ ConsensusSpecPreset-mainnet
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: mainne OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: mainne OK
|
||||||
+ [Invalid] bad_everything_regular_payload OK
|
|
||||||
+ [Invalid] bad_execution_first_payload OK
|
|
||||||
+ [Invalid] bad_execution_regular_payload OK
|
|
||||||
+ [Invalid] bad_number_regular_payload OK
|
|
||||||
+ [Invalid] bad_parent_hash_regular_payload OK
|
|
||||||
+ [Invalid] bad_random_first_payload OK
|
|
||||||
+ [Invalid] bad_random_regular_payload OK
|
|
||||||
+ [Invalid] bad_timestamp_first_payload OK
|
|
||||||
+ [Invalid] bad_timestamp_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_lower_minus_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_minimum_minus_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_upper_plus_regular_payload OK
|
|
||||||
+ [Invalid] gasused_gaslimit_plus_regular_payload OK
|
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: mainnet] OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: mainnet] OK
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: mainnet] OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: mainnet] OK
|
||||||
|
@ -334,16 +321,6 @@ ConsensusSpecPreset-mainnet
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: mainnet OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: mainnet OK
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: mainne OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: mainne OK
|
||||||
+ [Valid] gaslimit_lower_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_max_first_payload OK
|
|
||||||
+ [Valid] gaslimit_minimum_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_upper_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_zero_first_payload OK
|
|
||||||
+ [Valid] gasused_gaslimit_regular_payload OK
|
|
||||||
+ [Valid] success_first_payload OK
|
|
||||||
+ [Valid] success_first_payload_with_gap_slot OK
|
|
||||||
+ [Valid] success_regular_payload OK
|
|
||||||
+ [Valid] success_regular_payload_with_gap_slot OK
|
|
||||||
+ altair_fork_random_0 OK
|
+ altair_fork_random_0 OK
|
||||||
+ altair_fork_random_1 OK
|
+ altair_fork_random_1 OK
|
||||||
+ altair_fork_random_2 OK
|
+ altair_fork_random_2 OK
|
||||||
|
@ -361,7 +338,7 @@ ConsensusSpecPreset-mainnet
|
||||||
+ fork_random_misc_balances OK
|
+ fork_random_misc_balances OK
|
||||||
+ next_sync_committee_merkle_proof OK
|
+ next_sync_committee_merkle_proof OK
|
||||||
```
|
```
|
||||||
OK: 358/358 Fail: 0/358 Skip: 0/358
|
OK: 335/335 Fail: 0/335 Skip: 0/335
|
||||||
## Attestation
|
## Attestation
|
||||||
```diff
|
```diff
|
||||||
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
|
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
|
||||||
|
@ -1028,6 +1005,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Testing VoluntaryExit OK
|
+ Testing VoluntaryExit OK
|
||||||
```
|
```
|
||||||
OK: 27/27 Fail: 0/27 Skip: 0/27
|
OK: 27/27 Fail: 0/27 Skip: 0/27
|
||||||
|
## Execution Payload
|
||||||
|
```diff
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
|
||||||
|
```
|
||||||
|
OK: 23/23 Fail: 0/23 Skip: 0/23
|
||||||
## Proposer Slashing
|
## Proposer Slashing
|
||||||
```diff
|
```diff
|
||||||
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK
|
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK
|
||||||
|
|
|
@ -190,19 +190,6 @@ ConsensusSpecPreset-minimal
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - same_slot_block_transition [Pr OK
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_same_index [Pre OK
|
||||||
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: minima OK
|
+ [Invalid] Ethereum Foundation - Phase 0 - Sanity - Blocks - zero_block_sig [Preset: minima OK
|
||||||
+ [Invalid] bad_everything_regular_payload OK
|
|
||||||
+ [Invalid] bad_execution_first_payload OK
|
|
||||||
+ [Invalid] bad_execution_regular_payload OK
|
|
||||||
+ [Invalid] bad_number_regular_payload OK
|
|
||||||
+ [Invalid] bad_parent_hash_regular_payload OK
|
|
||||||
+ [Invalid] bad_random_first_payload OK
|
|
||||||
+ [Invalid] bad_random_regular_payload OK
|
|
||||||
+ [Invalid] bad_timestamp_first_payload OK
|
|
||||||
+ [Invalid] bad_timestamp_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_lower_minus_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_minimum_minus_regular_payload OK
|
|
||||||
+ [Invalid] gaslimit_upper_plus_regular_payload OK
|
|
||||||
+ [Invalid] gasused_gaslimit_plus_regular_payload OK
|
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_no_updates_at_genesis [Preset OK
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: minimal] OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_1 [Preset: minimal] OK
|
||||||
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: minimal] OK
|
+ [Valid] Ethereum Foundation - Altair - Finality - finality_rule_2 [Preset: minimal] OK
|
||||||
|
@ -351,20 +338,10 @@ ConsensusSpecPreset-minimal
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: minimal OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - skipped_slots [Preset: minimal OK
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - slash_and_exit_diff_index [Pre OK
|
||||||
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: minima OK
|
+ [Valid] Ethereum Foundation - Phase 0 - Sanity - Blocks - voluntary_exit [Preset: minima OK
|
||||||
+ [Valid] gaslimit_lower_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_max_first_payload OK
|
|
||||||
+ [Valid] gaslimit_minimum_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_upper_regular_payload OK
|
|
||||||
+ [Valid] gaslimit_zero_first_payload OK
|
|
||||||
+ [Valid] gasused_gaslimit_regular_payload OK
|
|
||||||
+ [Valid] success_first_payload OK
|
|
||||||
+ [Valid] success_first_payload_with_gap_slot OK
|
|
||||||
+ [Valid] success_regular_payload OK
|
|
||||||
+ [Valid] success_regular_payload_with_gap_slot OK
|
|
||||||
+ finality_root_merkle_proof OK
|
+ finality_root_merkle_proof OK
|
||||||
+ next_sync_committee_merkle_proof OK
|
+ next_sync_committee_merkle_proof OK
|
||||||
```
|
```
|
||||||
OK: 361/361 Fail: 0/361 Skip: 0/361
|
OK: 338/338 Fail: 0/338 Skip: 0/338
|
||||||
## Attestation
|
## Attestation
|
||||||
```diff
|
```diff
|
||||||
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
|
+ [Invalid] Ethereum Foundation - Altair - Operations - Attestation - after_epoch_slots OK
|
||||||
|
@ -1065,6 +1042,33 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||||
+ Testing VoluntaryExit OK
|
+ Testing VoluntaryExit OK
|
||||||
```
|
```
|
||||||
OK: 27/27 Fail: 0/27 Skip: 0/27
|
OK: 27/27 Fail: 0/27 Skip: 0/27
|
||||||
|
## Execution Payload
|
||||||
|
```diff
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_everything_re OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_fir OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_execution_reg OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_number_regula OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_parent_hash_r OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_first_ OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_random_regula OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_fir OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - bad_timestamp_reg OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_mi OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_pl OK
|
||||||
|
+ [Invalid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_lower_re OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_max_firs OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_minimum_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_upper_re OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gaslimit_zero_fir OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - gasused_gaslimit_ OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_first_pay OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
|
||||||
|
+ [Valid] Ethereum Foundation - Merge - Operations - Execution Payload - success_regular_p OK
|
||||||
|
```
|
||||||
|
OK: 23/23 Fail: 0/23 Skip: 0/23
|
||||||
## Proposer Slashing
|
## Proposer Slashing
|
||||||
```diff
|
```diff
|
||||||
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK
|
+ [Invalid] Ethereum Foundation - Altair - Operations - Proposer Slashing - epochs_are_diffe OK
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard libraries
|
# Standard libraries
|
||||||
std/[deques, sets, intsets],
|
std/[deques, sets],
|
||||||
# Status libraries
|
# Status libraries
|
||||||
chronicles,
|
chronicles,
|
||||||
# Internal
|
# Internal
|
||||||
|
@ -17,7 +17,7 @@ import
|
||||||
../spec/datatypes/[phase0, altair, merge],
|
../spec/datatypes/[phase0, altair, merge],
|
||||||
./blockchain_dag
|
./blockchain_dag
|
||||||
|
|
||||||
export phase0, altair, merge, deques, intsets, sets, blockchain_dag
|
export phase0, altair, merge, deques, sets, blockchain_dag
|
||||||
|
|
||||||
logScope: topics = "exitpool"
|
logScope: topics = "exitpool"
|
||||||
|
|
||||||
|
@ -43,13 +43,13 @@ type
|
||||||
voluntary_exits*: Deque[SignedVoluntaryExit] ## \
|
voluntary_exits*: Deque[SignedVoluntaryExit] ## \
|
||||||
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
|
## Not a function of chain DAG branch; just used as a FIFO queue for blocks
|
||||||
|
|
||||||
prior_seen_attester_slashed_indices*: IntSet ## \
|
prior_seen_attester_slashed_indices*: HashSet[uint64] ## \
|
||||||
## Records attester-slashed indices seen.
|
## Records attester-slashed indices seen.
|
||||||
|
|
||||||
prior_seen_proposer_slashed_indices*: IntSet ## \
|
prior_seen_proposer_slashed_indices*: HashSet[uint64] ## \
|
||||||
## Records proposer-slashed indices seen.
|
## Records proposer-slashed indices seen.
|
||||||
|
|
||||||
prior_seen_voluntary_exit_indices*: IntSet ##\
|
prior_seen_voluntary_exit_indices*: HashSet[uint64] ##\
|
||||||
## Records voluntary exit indices seen.
|
## Records voluntary exit indices seen.
|
||||||
|
|
||||||
dag*: ChainDAGRef
|
dag*: ChainDAGRef
|
||||||
|
@ -79,18 +79,13 @@ func addExitMessage*(subpool: var auto, exitMessage, bound: auto) =
|
||||||
doAssert subpool.lenu64 <= bound
|
doAssert subpool.lenu64 <= bound
|
||||||
|
|
||||||
iterator getValidatorIndices(attester_slashing: AttesterSlashing): uint64 =
|
iterator getValidatorIndices(attester_slashing: AttesterSlashing): uint64 =
|
||||||
# TODO rely on sortedness and do this sans memory allocations, but it's only
|
let attestation_2_indices =
|
||||||
# when producing a beacon block, which is rare bottlenecked elsewhere.
|
toHashSet(attester_slashing.attestation_2.attesting_indices.asSeq)
|
||||||
let
|
|
||||||
attestation_1_indices =
|
|
||||||
attester_slashing.attestation_1.attesting_indices.asSeq
|
|
||||||
attestation_2_indices =
|
|
||||||
attester_slashing.attestation_2.attesting_indices.asSeq
|
|
||||||
attester_slashed_indices =
|
|
||||||
toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices)
|
|
||||||
|
|
||||||
for validator_index in attester_slashed_indices:
|
for validator_index in attester_slashing.attestation_1.attesting_indices.asSeq:
|
||||||
yield validator_index.uint64
|
if validator_index notin attestation_2_indices:
|
||||||
|
continue
|
||||||
|
yield validator_index
|
||||||
|
|
||||||
iterator getValidatorIndices(proposer_slashing: ProposerSlashing): uint64 =
|
iterator getValidatorIndices(proposer_slashing: ProposerSlashing): uint64 =
|
||||||
yield proposer_slashing.signed_header_1.message.proposer_index
|
yield proposer_slashing.signed_header_1.message.proposer_index
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[intsets],
|
std/sequtils,
|
||||||
chronicles,
|
chronicles,
|
||||||
../extras,
|
../extras,
|
||||||
../spec/[helpers, network, signatures, validator],
|
../spec/[helpers, network, signatures, validator],
|
||||||
|
@ -173,9 +173,8 @@ func makeAttestationData*(
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#validator-assignments
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#validator-assignments
|
||||||
iterator get_committee_assignments*(
|
iterator get_committee_assignments*(
|
||||||
epochRef: EpochRef, validator_indices: IntSet):
|
epochRef: EpochRef, validator_indices: HashSet[ValidatorIndex]):
|
||||||
tuple[validatorIndices: IntSet,
|
tuple[committeeIndex: CommitteeIndex,
|
||||||
committeeIndex: CommitteeIndex,
|
|
||||||
subnet_id: SubnetId, slot: Slot] =
|
subnet_id: SubnetId, slot: Slot] =
|
||||||
let
|
let
|
||||||
committees_per_slot = get_committee_count_per_slot(epochRef)
|
committees_per_slot = get_committee_count_per_slot(epochRef)
|
||||||
|
@ -186,12 +185,10 @@ iterator get_committee_assignments*(
|
||||||
for index in 0'u64 ..< committees_per_slot:
|
for index in 0'u64 ..< committees_per_slot:
|
||||||
let
|
let
|
||||||
idx = index.CommitteeIndex
|
idx = index.CommitteeIndex
|
||||||
includedIndices =
|
if anyIt(
|
||||||
toIntSet(get_beacon_committee(epochRef, slot, idx)) *
|
get_beacon_committee(epochRef, slot, idx), it in validator_indices):
|
||||||
validator_indices
|
|
||||||
if includedIndices.len > 0:
|
|
||||||
yield (
|
yield (
|
||||||
includedIndices, idx,
|
idx,
|
||||||
compute_subnet_for_attestation(committees_per_slot, slot, idx),
|
compute_subnet_for_attestation(committees_per_slot, slot, idx),
|
||||||
slot)
|
slot)
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
|
||||||
std/[intsets],
|
|
||||||
# Status
|
# Status
|
||||||
chronicles, chronos, metrics,
|
chronicles, chronos, metrics,
|
||||||
stew/results,
|
stew/results,
|
||||||
|
@ -669,7 +667,7 @@ proc validateAttesterSlashing*(
|
||||||
attestation_2_indices =
|
attestation_2_indices =
|
||||||
attester_slashing.attestation_2.attesting_indices.asSeq
|
attester_slashing.attestation_2.attesting_indices.asSeq
|
||||||
attester_slashed_indices =
|
attester_slashed_indices =
|
||||||
toIntSet(attestation_1_indices) * toIntSet(attestation_2_indices)
|
toHashSet(attestation_1_indices) * toHashSet(attestation_2_indices)
|
||||||
|
|
||||||
if not disjoint(
|
if not disjoint(
|
||||||
attester_slashed_indices, pool.prior_seen_attester_slashed_indices):
|
attester_slashed_indices, pool.prior_seen_attester_slashed_indices):
|
||||||
|
@ -699,7 +697,7 @@ proc validateProposerSlashing*(
|
||||||
# [IGNORE] The proposer slashing is the first valid proposer slashing
|
# [IGNORE] The proposer slashing is the first valid proposer slashing
|
||||||
# received for the proposer with index
|
# received for the proposer with index
|
||||||
# proposer_slashing.signed_header_1.message.proposer_index.
|
# proposer_slashing.signed_header_1.message.proposer_index.
|
||||||
if proposer_slashing.signed_header_1.message.proposer_index.int in
|
if proposer_slashing.signed_header_1.message.proposer_index in
|
||||||
pool.prior_seen_proposer_slashed_indices:
|
pool.prior_seen_proposer_slashed_indices:
|
||||||
return errIgnore(
|
return errIgnore(
|
||||||
"ProposerSlashing: proposer-slashed index already proposer-slashed")
|
"ProposerSlashing: proposer-slashed index already proposer-slashed")
|
||||||
|
@ -711,7 +709,7 @@ proc validateProposerSlashing*(
|
||||||
return err((ValidationResult.Reject, proposer_slashing_validity.error))
|
return err((ValidationResult.Reject, proposer_slashing_validity.error))
|
||||||
|
|
||||||
pool.prior_seen_proposer_slashed_indices.incl(
|
pool.prior_seen_proposer_slashed_indices.incl(
|
||||||
proposer_slashing.signed_header_1.message.proposer_index.int)
|
proposer_slashing.signed_header_1.message.proposer_index)
|
||||||
pool.proposer_slashings.addExitMessage(
|
pool.proposer_slashings.addExitMessage(
|
||||||
proposer_slashing, PROPOSER_SLASHINGS_BOUND)
|
proposer_slashing, PROPOSER_SLASHINGS_BOUND)
|
||||||
ok(true)
|
ok(true)
|
||||||
|
@ -729,7 +727,7 @@ proc validateVoluntaryExit*(
|
||||||
# Given that getStateField(pool.dag.headState, validators) is a seq,
|
# Given that getStateField(pool.dag.headState, validators) is a seq,
|
||||||
# signed_voluntary_exit.message.validator_index.int is already valid, but
|
# signed_voluntary_exit.message.validator_index.int is already valid, but
|
||||||
# check explicitly if one changes that data structure.
|
# check explicitly if one changes that data structure.
|
||||||
if signed_voluntary_exit.message.validator_index.int in
|
if signed_voluntary_exit.message.validator_index in
|
||||||
pool.prior_seen_voluntary_exit_indices:
|
pool.prior_seen_voluntary_exit_indices:
|
||||||
return errIgnore("VoluntaryExit: validator index already voluntarily exited")
|
return errIgnore("VoluntaryExit: validator index already voluntarily exited")
|
||||||
|
|
||||||
|
@ -742,7 +740,7 @@ proc validateVoluntaryExit*(
|
||||||
return err((ValidationResult.Reject, voluntary_exit_validity.error))
|
return err((ValidationResult.Reject, voluntary_exit_validity.error))
|
||||||
|
|
||||||
pool.prior_seen_voluntary_exit_indices.incl(
|
pool.prior_seen_voluntary_exit_indices.incl(
|
||||||
signed_voluntary_exit.message.validator_index.int)
|
signed_voluntary_exit.message.validator_index)
|
||||||
pool.voluntary_exits.addExitMessage(
|
pool.voluntary_exits.addExitMessage(
|
||||||
signed_voluntary_exit, VOLUNTARY_EXITS_BOUND)
|
signed_voluntary_exit, VOLUNTARY_EXITS_BOUND)
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,6 @@
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
# std/[intsets, json, strutils, tables],
|
|
||||||
# stew/byteutils,
|
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[macros, typetraits, sets, hashes],
|
std/[macros, typetraits, sets, hashes],
|
||||||
chronicles,
|
chronicles,
|
||||||
|
|
|
@ -31,7 +31,7 @@ export
|
||||||
json_serialization
|
json_serialization
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[macros, hashes, intsets, strutils, tables, typetraits],
|
std/[macros, hashes, strutils, tables, typetraits],
|
||||||
stew/[assign2, byteutils],
|
stew/[assign2, byteutils],
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos/timer,
|
chronos/timer,
|
||||||
|
@ -694,15 +694,6 @@ template `==`*(x: uint64, y: ValidatorIndex): bool =
|
||||||
template `==`*(x: ValidatorIndex, y: uint64): bool =
|
template `==`*(x: ValidatorIndex, y: uint64): bool =
|
||||||
uint64(x) == y
|
uint64(x) == y
|
||||||
|
|
||||||
# TODO Nim 1.4, but not Nim 1.2, defines a function by this name, which works
|
|
||||||
# only on openArray[int]. They do the same thing, so either's fine, when both
|
|
||||||
# overloads match. The Nim 1.4 stdlib doesn't int-convert but it's a no-op in
|
|
||||||
# its case regardless.
|
|
||||||
func toIntSet*[T](x: openArray[T]): IntSet =
|
|
||||||
result = initIntSet()
|
|
||||||
for item in items(x):
|
|
||||||
result.incl(item.int)
|
|
||||||
|
|
||||||
template `==`*(x, y: CommitteeIndex): bool =
|
template `==`*(x, y: CommitteeIndex): bool =
|
||||||
distinctBase(x) == distinctBase(y)
|
distinctBase(x) == distinctBase(y)
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ import ./base
|
||||||
export base
|
export base
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[macros, intsets, json, strutils, tables],
|
std/[macros, json, strutils, tables],
|
||||||
stew/[assign2, byteutils], chronicles,
|
stew/[assign2, byteutils], chronicles,
|
||||||
json_serialization/types as jsonTypes
|
json_serialization/types as jsonTypes
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[algorithm, intsets, options, sequtils, sets, tables],
|
std/[algorithm, options, sequtils, sets, tables],
|
||||||
chronicles, metrics,
|
chronicles, metrics,
|
||||||
../extras,
|
../extras,
|
||||||
./datatypes/[phase0, altair, merge],
|
./datatypes/[phase0, altair, merge],
|
||||||
|
@ -213,9 +213,10 @@ proc check_attester_slashing*(
|
||||||
|
|
||||||
var slashed_indices: seq[ValidatorIndex]
|
var slashed_indices: seq[ValidatorIndex]
|
||||||
|
|
||||||
for index in sorted(toSeq(intersection(
|
let attesting_indices_2 = toHashSet(attestation_2.attesting_indices.asSeq)
|
||||||
toIntSet(attestation_1.attesting_indices.asSeq),
|
for index in sorted(filterIt(
|
||||||
toIntSet(attestation_2.attesting_indices.asSeq)).items), system.cmp):
|
attestation_1.attesting_indices.asSeq, it in attesting_indices_2),
|
||||||
|
system.cmp):
|
||||||
if is_slashable_validator(
|
if is_slashable_validator(
|
||||||
state.validators.asSeq()[index], get_current_epoch(state)):
|
state.validators.asSeq()[index], get_current_epoch(state)):
|
||||||
slashed_indices.add index.ValidatorIndex
|
slashed_indices.add index.ValidatorIndex
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import
|
import
|
||||||
std/[sequtils, intsets, sets, tables],
|
std/[sequtils, sets, tables],
|
||||||
chronicles,
|
chronicles,
|
||||||
bearssl,
|
bearssl,
|
||||||
eth/p2p/discoveryv5/random2,
|
eth/p2p/discoveryv5/random2,
|
||||||
|
@ -167,14 +167,12 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) =
|
||||||
return
|
return
|
||||||
tracker.lastCalculatedEpoch = epoch
|
tracker.lastCalculatedEpoch = epoch
|
||||||
|
|
||||||
let
|
let validatorIndices = toHashSet(toSeq(tracker.knownValidators.keys()))
|
||||||
validatorIndices = toIntSet(toSeq(tracker.knownValidators.keys()))
|
|
||||||
|
|
||||||
# Update proposals
|
# Update proposals
|
||||||
tracker.proposingSlots[epoch mod 2] = 0
|
tracker.proposingSlots[epoch mod 2] = 0
|
||||||
for i, proposer in epochRef.beacon_proposers:
|
for i, proposer in epochRef.beacon_proposers:
|
||||||
# TODO unsafe int conversion
|
if proposer.isSome and proposer.get() in validatorIndices:
|
||||||
if proposer.isSome and proposer.get().int in validatorIndices:
|
|
||||||
tracker.proposingSlots[epoch mod 2] =
|
tracker.proposingSlots[epoch mod 2] =
|
||||||
tracker.proposingSlots[epoch mod 2] or (1'u32 shl i)
|
tracker.proposingSlots[epoch mod 2] or (1'u32 shl i)
|
||||||
|
|
||||||
|
@ -183,7 +181,7 @@ proc updateActions*(tracker: var ActionTracker, epochRef: EpochRef) =
|
||||||
# The relevant bitmaps are 32 bits each.
|
# The relevant bitmaps are 32 bits each.
|
||||||
static: doAssert SLOTS_PER_EPOCH <= 32
|
static: doAssert SLOTS_PER_EPOCH <= 32
|
||||||
|
|
||||||
for (validatorIndices, committeeIndex, subnet_id, slot) in
|
for (committeeIndex, subnet_id, slot) in
|
||||||
get_committee_assignments(epochRef, validatorIndices):
|
get_committee_assignments(epochRef, validatorIndices):
|
||||||
|
|
||||||
doAssert compute_epoch_at_slot(slot) == epoch
|
doAssert compute_epoch_at_slot(slot) == epoch
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
os, sequtils, sets,
|
std/[os, sequtils, sets],
|
||||||
# Utilities
|
# Utilities
|
||||||
chronicles,
|
chronicles,
|
||||||
unittest2,
|
unittest2,
|
||||||
|
|
|
@ -36,13 +36,6 @@ type
|
||||||
# Some have a signing_root field
|
# Some have a signing_root field
|
||||||
signing_root {.defaultVal: "".}: string
|
signing_root {.defaultVal: "".}: string
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0/specs/phase0/validator.md#eth1block
|
|
||||||
Eth1Block = object
|
|
||||||
timestamp: uint64
|
|
||||||
deposit_root: Eth2Digest
|
|
||||||
deposit_count: uint64
|
|
||||||
# All other eth1 block fields
|
|
||||||
|
|
||||||
# Note this only tracks HashTreeRoot
|
# Note this only tracks HashTreeRoot
|
||||||
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,13 @@ type
|
||||||
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
rewards*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
penalties*: List[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/phase0/validator.md#eth1block
|
||||||
|
Eth1Block* = object
|
||||||
|
timestamp*: uint64
|
||||||
|
deposit_root*: Eth2Digest
|
||||||
|
deposit_count*: uint64
|
||||||
|
# All other eth1 block fields
|
||||||
|
|
||||||
const
|
const
|
||||||
FixturesDir* =
|
FixturesDir* =
|
||||||
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / "vendor" / "nim-eth2-scenarios"
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
./test_fixture_operations,
|
./test_fixture_operations,
|
||||||
./test_fixture_operations_execution_payload,
|
|
||||||
./test_fixture_sanity_blocks,
|
./test_fixture_sanity_blocks,
|
||||||
./test_fixture_sanity_slots,
|
./test_fixture_sanity_slots,
|
||||||
./test_fixture_ssz_consensus_objects,
|
./test_fixture_ssz_consensus_objects,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
os,
|
std/[os, sequtils, sets, strutils],
|
||||||
# Utilities
|
# Utilities
|
||||||
chronicles,
|
chronicles,
|
||||||
unittest2,
|
unittest2,
|
||||||
|
@ -28,12 +28,18 @@ const
|
||||||
OpAttSlashingDir = OpDir/"attester_slashing"
|
OpAttSlashingDir = OpDir/"attester_slashing"
|
||||||
OpBlockHeaderDir = OpDir/"block_header"
|
OpBlockHeaderDir = OpDir/"block_header"
|
||||||
OpDepositsDir = OpDir/"deposit"
|
OpDepositsDir = OpDir/"deposit"
|
||||||
|
OpExecutionPayloadDir = OpDir/"execution_payload"
|
||||||
OpProposerSlashingDir = OpDir/"proposer_slashing"
|
OpProposerSlashingDir = OpDir/"proposer_slashing"
|
||||||
OpSyncAggregateDir = OpDir/"sync_aggregate"
|
OpSyncAggregateDir = OpDir/"sync_aggregate"
|
||||||
OpVoluntaryExitDir = OpDir/"voluntary_exit"
|
OpVoluntaryExitDir = OpDir/"voluntary_exit"
|
||||||
|
|
||||||
baseDescription = "Ethereum Foundation - Merge - Operations - "
|
baseDescription = "Ethereum Foundation - Merge - Operations - "
|
||||||
|
|
||||||
|
doAssert toHashSet(mapIt(toSeq(walkDir(OpDir, relative = false)), it.path)) ==
|
||||||
|
toHashSet([OpAttestationsDir, OpAttSlashingDir, OpBlockHeaderDir,
|
||||||
|
OpDepositsDir, OpExecutionPayloadDir, OpProposerSlashingDir,
|
||||||
|
OpSyncAggregateDir, OpVoluntaryExitDir])
|
||||||
|
|
||||||
proc runTest[T, U](
|
proc runTest[T, U](
|
||||||
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
testSuiteDir: string, testSuiteName: string, applyFile: string,
|
||||||
applyProc: U, identifier: string) =
|
applyProc: U, identifier: string) =
|
||||||
|
@ -116,6 +122,22 @@ suite baseDescription & "Deposit " & preset():
|
||||||
runTest[Deposit, typeof applyDeposit](
|
runTest[Deposit, typeof applyDeposit](
|
||||||
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
OpDepositsDir, "Deposit", "deposit", applyDeposit, path)
|
||||||
|
|
||||||
|
suite baseDescription & "Execution Payload " & preset():
|
||||||
|
for path in walkTests(OpExecutionPayloadDir):
|
||||||
|
proc applyExecutionPayload(
|
||||||
|
preState: var merge.BeaconState, executionPayload: ExecutionPayload):
|
||||||
|
Result[void, cstring] =
|
||||||
|
let payloadValid =
|
||||||
|
readFile(OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml").
|
||||||
|
contains("execution_valid: true")
|
||||||
|
func executePayload(_: ExecutionPayload): bool = payloadValid
|
||||||
|
process_execution_payload(
|
||||||
|
preState, executionPayload, executePayload)
|
||||||
|
|
||||||
|
runTest[ExecutionPayload, typeof applyExecutionPayload](
|
||||||
|
OpExecutionPayloadDir, "Execution Payload", "execution_payload",
|
||||||
|
applyExecutionPayload, path)
|
||||||
|
|
||||||
suite baseDescription & "Proposer Slashing " & preset():
|
suite baseDescription & "Proposer Slashing " & preset():
|
||||||
proc applyProposerSlashing(
|
proc applyProposerSlashing(
|
||||||
preState: var merge.BeaconState, proposerSlashing: ProposerSlashing):
|
preState: var merge.BeaconState, proposerSlashing: ProposerSlashing):
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
# beacon_chain
|
|
||||||
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
||||||
# Licensed and distributed under either of
|
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
||||||
|
|
||||||
{.used.}
|
|
||||||
|
|
||||||
import
|
|
||||||
# Standard library
|
|
||||||
std/os, std/strutils,
|
|
||||||
# Utilities
|
|
||||||
stew/results,
|
|
||||||
# Beacon chain internals
|
|
||||||
../../../beacon_chain/spec/state_transition_block,
|
|
||||||
../../../beacon_chain/spec/datatypes/merge,
|
|
||||||
# Test utilities
|
|
||||||
../../testutil,
|
|
||||||
../fixtures_utils,
|
|
||||||
../../helpers/debug_state
|
|
||||||
|
|
||||||
const OpExecutionPayloadDir = SszTestsDir/const_preset/"merge"/"operations"/"execution_payload"/"pyspec_tests"
|
|
||||||
|
|
||||||
proc runTest(identifier: string) =
|
|
||||||
let testDir = OpExecutionPayloadDir / identifier
|
|
||||||
|
|
||||||
proc `testImpl _ voluntary_exit _ identifier`() =
|
|
||||||
|
|
||||||
let
|
|
||||||
prefix =
|
|
||||||
if existsFile(testDir/"post.ssz_snappy"):
|
|
||||||
"[Valid] "
|
|
||||||
else:
|
|
||||||
"[Invalid] "
|
|
||||||
payloadValid = readFile(
|
|
||||||
testDir/"execution.yaml").contains("execution_valid: true")
|
|
||||||
|
|
||||||
func executePayload(_: ExecutionPayload): bool = payloadValid
|
|
||||||
|
|
||||||
test prefix & identifier:
|
|
||||||
var
|
|
||||||
preState =
|
|
||||||
newClone(parseTest(testDir/"pre.ssz_snappy", SSZ, merge.BeaconState))
|
|
||||||
|
|
||||||
let
|
|
||||||
executionPayload = parseTest(
|
|
||||||
testDir/"execution_payload.ssz_snappy", SSZ, ExecutionPayload)
|
|
||||||
done = process_execution_payload(
|
|
||||||
preState[], executionPayload, executePayload)
|
|
||||||
|
|
||||||
if existsFile(testDir/"post.ssz_snappy"):
|
|
||||||
let postState =
|
|
||||||
newClone(parseTest(testDir/"post.ssz_snappy", SSZ, merge.BeaconState))
|
|
||||||
|
|
||||||
check:
|
|
||||||
done.isOk()
|
|
||||||
preState[].hash_tree_root() == postState[].hash_tree_root()
|
|
||||||
reportDiff(preState, postState)
|
|
||||||
else:
|
|
||||||
check: done.isErr() # No post state = processing should fail
|
|
||||||
|
|
||||||
`testImpl _ voluntary_exit _ identifier`()
|
|
||||||
|
|
||||||
suite "Ethereum Foundation - Merge - Operations - Execution Payload " & preset():
|
|
||||||
for kind, path in walkDir(
|
|
||||||
OpExecutionPayloadDir, relative = true, checkDir = true):
|
|
||||||
runTest(path)
|
|
|
@ -36,13 +36,6 @@ type
|
||||||
# Some have a signing_root field
|
# Some have a signing_root field
|
||||||
signing_root {.defaultVal: "".}: string
|
signing_root {.defaultVal: "".}: string
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.3/specs/phase0/validator.md#eth1block
|
|
||||||
Eth1Block = object
|
|
||||||
timestamp: uint64
|
|
||||||
deposit_root: Eth2Digest
|
|
||||||
deposit_count: uint64
|
|
||||||
# All other eth1 block fields
|
|
||||||
|
|
||||||
# Note this only tracks HashTreeRoot
|
# Note this only tracks HashTreeRoot
|
||||||
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
os, sequtils, sets,
|
std/[os, sequtils, sets],
|
||||||
# Utilities
|
# Utilities
|
||||||
chronicles,
|
chronicles,
|
||||||
unittest2,
|
unittest2,
|
||||||
|
|
|
@ -36,13 +36,6 @@ type
|
||||||
# Some have a signing_root field
|
# Some have a signing_root field
|
||||||
signing_root {.defaultVal: "".}: string
|
signing_root {.defaultVal: "".}: string
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.2/specs/phase0/validator.md#eth1block
|
|
||||||
Eth1Block = object
|
|
||||||
timestamp: uint64
|
|
||||||
deposit_root: Eth2Digest
|
|
||||||
deposit_count: uint64
|
|
||||||
# All other eth1 block fields
|
|
||||||
|
|
||||||
# Note this only tracks HashTreeRoot
|
# Note this only tracks HashTreeRoot
|
||||||
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
# Checking the values against the yaml file is TODO (require more flexible Yaml parser)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
|
||||||
intsets,
|
|
||||||
# Status
|
# Status
|
||||||
chronicles,
|
chronicles,
|
||||||
# Specs
|
# Specs
|
||||||
|
|
Loading…
Reference in New Issue