add all missing epoch transition tests (#4269)

This commit is contained in:
tersec 2022-10-28 08:02:33 +00:00 committed by GitHub
parent 48e351d672
commit 0cfc1b776e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 489 additions and 118 deletions

View File

@ -967,6 +967,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Altair - Epoch Processing - Rewards and penalties [Preset: mainnet]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - attestations_some_slashed [Preset: mainnet] OK
+ Rewards and penalties - duplicate_attestation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: mainnet] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: mainnet] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Altair - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
@ -1118,6 +1137,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Bellatrix - Epoch Processing - Rewards and penalties [Preset: mainnet]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - attestations_some_slashed [Preset: mainnet] OK
+ Rewards and penalties - duplicate_attestation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: mainnet] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: mainnet] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Bellatrix - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
@ -1188,6 +1226,22 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Eth1 data reset - eth1_vote_reset [Preset: mainnet] OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
## EF - Capella - Epoch Processing - Full withdrawals [Preset: mainnet]
```diff
+ Full withdrawals - all_withdrawal [Preset: mainnet] OK
+ Full withdrawals - multi_withdrawal [Preset: mainnet] OK
+ Full withdrawals - no_withdrawable_validators [Preset: mainnet] OK
+ Full withdrawals - no_withdrawals_but_some_next_epoch [Preset: mainnet] OK
+ Full withdrawals - random_withdrawals_0 [Preset: mainnet] OK
+ Full withdrawals - random_withdrawals_1 [Preset: mainnet] OK
+ Full withdrawals - random_withdrawals_2 [Preset: mainnet] OK
+ Full withdrawals - random_withdrawals_3 [Preset: mainnet] OK
+ Full withdrawals - single_withdrawal [Preset: mainnet] OK
+ Full withdrawals - withdrawable_epoch_but_0_balance [Preset: mainnet] OK
+ Full withdrawals - withdrawable_epoch_but_0_effective_balance_0_balance [Preset: mainnet] OK
+ Full withdrawals - withdrawable_epoch_but_0_effective_balance_nonzero_balance [Preset: mai OK
```
OK: 12/12 Fail: 0/12 Skip: 0/12
## EF - Capella - Epoch Processing - Historical roots update [Preset: mainnet]
```diff
+ Historical roots update - historical_root_accumulator [Preset: mainnet] OK
@ -1230,6 +1284,28 @@ OK: 19/19 Fail: 0/19 Skip: 0/19
+ Justification & Finalization - balance_threshold_with_exited_validators [Preset: mainnet] OK
```
OK: 10/10 Fail: 0/10 Skip: 0/10
## EF - Capella - Epoch Processing - Partial withdrawals [Preset: mainnet]
```diff
+ Partial withdrawals - random_0 [Preset: mainnet] OK
+ Partial withdrawals - random_1 [Preset: mainnet] OK
+ Partial withdrawals - random_2 [Preset: mainnet] OK
+ Partial withdrawals - random_3 [Preset: mainnet] OK
+ Partial withdrawals - random_4 [Preset: mainnet] OK
+ Partial withdrawals - random_5 [Preset: mainnet] OK
+ Partial withdrawals - success_excess_balance_but_no_max_effective_balance [Preset: mainnet OK
+ Partial withdrawals - success_max_partial_withdrawable [Preset: mainnet] OK
+ Partial withdrawals - success_no_excess_balance [Preset: mainnet] OK
+ Partial withdrawals - success_no_max_effective_balance [Preset: mainnet] OK
+ Partial withdrawals - success_no_withdrawable [Preset: mainnet] OK
+ Partial withdrawals - success_one_partial_withdrawable [Preset: mainnet] OK
+ Partial withdrawals - success_one_partial_withdrawable_active_and_slashed [Preset: mainnet OK
+ Partial withdrawals - success_one_partial_withdrawable_exited [Preset: mainnet] OK
+ Partial withdrawals - success_one_partial_withdrawable_exited_and_slashed [Preset: mainnet OK
+ Partial withdrawals - success_one_partial_withdrawable_in_exit_queue [Preset: mainnet] OK
+ Partial withdrawals - success_one_partial_withdrawable_not_yet_active [Preset: mainnet] OK
+ Partial withdrawals - success_two_partial_withdrawable [Preset: mainnet] OK
```
OK: 18/18 Fail: 0/18 Skip: 0/18
## EF - Capella - Epoch Processing - Participation flag updates [Preset: mainnet]
```diff
+ Participation flag updates - all_zeroed [Preset: mainnet] OK
@ -1264,6 +1340,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Capella - Epoch Processing - Rewards and penalties [Preset: mainnet]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - attestations_some_slashed [Preset: mainnet] OK
+ Rewards and penalties - duplicate_attestation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: mainnet] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: mainnet] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Capella - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
@ -1381,6 +1476,29 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: mainnet] OK
```
OK: 11/11 Fail: 0/11 Skip: 0/11
## EF - Phase 0 - Epoch Processing - Rewards and penalties [Preset: mainnet]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations [Preset: mainnet] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: mainnet] OK
+ Rewards and penalties - attestations_some_slashed [Preset: mainnet] OK
+ Rewards and penalties - duplicate_attestation [Preset: mainnet] OK
+ Rewards and penalties - duplicate_participants_different_attestation_1 [Preset: mainnet] OK
+ Rewards and penalties - duplicate_participants_different_attestation_2 [Preset: mainnet] OK
+ Rewards and penalties - duplicate_participants_different_attestation_3 [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation [Preset: mainnet] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: mainnet] OK
+ Rewards and penalties - full_attestations_random_incorrect_fields [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: mainnet] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: mainnet] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations [Preset: mainnet] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: mainnet] OK
```
OK: 19/19 Fail: 0/19 Skip: 0/19
## EF - Phase 0 - Epoch Processing - Slashings [Preset: mainnet]
```diff
+ Slashings - low_penalty [Preset: mainnet] OK
@ -1688,4 +1806,4 @@ OK: 48/48 Fail: 0/48 Skip: 0/48
OK: 14/14 Fail: 0/14 Skip: 0/14
---TOTAL---
OK: 1459/1466 Fail: 0/1466 Skip: 7/1466
OK: 1553/1560 Fail: 0/1560 Skip: 7/1560

View File

@ -1032,6 +1032,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Altair - Epoch Processing - Rewards and penalties [Preset: minimal]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - attestations_some_slashed [Preset: minimal] OK
+ Rewards and penalties - duplicate_attestation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: minimal] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: minimal] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: minimal] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Altair - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
@ -1198,6 +1217,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Bellatrix - Epoch Processing - Rewards and penalties [Preset: minimal]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - attestations_some_slashed [Preset: minimal] OK
+ Rewards and penalties - duplicate_attestation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: minimal] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: minimal] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: minimal] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Bellatrix - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
@ -1277,6 +1315,22 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Eth1 data reset - eth1_vote_reset [Preset: minimal] OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
## EF - Capella - Epoch Processing - Full withdrawals [Preset: minimal]
```diff
+ Full withdrawals - all_withdrawal [Preset: minimal] OK
+ Full withdrawals - multi_withdrawal [Preset: minimal] OK
+ Full withdrawals - no_withdrawable_validators [Preset: minimal] OK
+ Full withdrawals - no_withdrawals_but_some_next_epoch [Preset: minimal] OK
+ Full withdrawals - random_withdrawals_0 [Preset: minimal] OK
+ Full withdrawals - random_withdrawals_1 [Preset: minimal] OK
+ Full withdrawals - random_withdrawals_2 [Preset: minimal] OK
+ Full withdrawals - random_withdrawals_3 [Preset: minimal] OK
+ Full withdrawals - single_withdrawal [Preset: minimal] OK
+ Full withdrawals - withdrawable_epoch_but_0_balance [Preset: minimal] OK
+ Full withdrawals - withdrawable_epoch_but_0_effective_balance_0_balance [Preset: minimal] OK
+ Full withdrawals - withdrawable_epoch_but_0_effective_balance_nonzero_balance [Preset: min OK
```
OK: 12/12 Fail: 0/12 Skip: 0/12
## EF - Capella - Epoch Processing - Historical roots update [Preset: minimal]
```diff
+ Historical roots update - historical_root_accumulator [Preset: minimal] OK
@ -1319,6 +1373,29 @@ OK: 19/19 Fail: 0/19 Skip: 0/19
+ Justification & Finalization - balance_threshold_with_exited_validators [Preset: minimal] OK
```
OK: 10/10 Fail: 0/10 Skip: 0/10
## EF - Capella - Epoch Processing - Partial withdrawals [Preset: minimal]
```diff
+ Partial withdrawals - random_0 [Preset: minimal] OK
+ Partial withdrawals - random_1 [Preset: minimal] OK
+ Partial withdrawals - random_2 [Preset: minimal] OK
+ Partial withdrawals - random_3 [Preset: minimal] OK
+ Partial withdrawals - random_4 [Preset: minimal] OK
+ Partial withdrawals - random_5 [Preset: minimal] OK
+ Partial withdrawals - success_excess_balance_but_no_max_effective_balance [Preset: minimal OK
+ Partial withdrawals - success_max_partial_withdrawable [Preset: minimal] OK
+ Partial withdrawals - success_max_plus_one_withdrawable [Preset: minimal] OK
+ Partial withdrawals - success_no_excess_balance [Preset: minimal] OK
+ Partial withdrawals - success_no_max_effective_balance [Preset: minimal] OK
+ Partial withdrawals - success_no_withdrawable [Preset: minimal] OK
+ Partial withdrawals - success_one_partial_withdrawable [Preset: minimal] OK
+ Partial withdrawals - success_one_partial_withdrawable_active_and_slashed [Preset: minimal OK
+ Partial withdrawals - success_one_partial_withdrawable_exited [Preset: minimal] OK
+ Partial withdrawals - success_one_partial_withdrawable_exited_and_slashed [Preset: minimal OK
+ Partial withdrawals - success_one_partial_withdrawable_in_exit_queue [Preset: minimal] OK
+ Partial withdrawals - success_one_partial_withdrawable_not_yet_active [Preset: minimal] OK
+ Partial withdrawals - success_two_partial_withdrawable [Preset: minimal] OK
```
OK: 19/19 Fail: 0/19 Skip: 0/19
## EF - Capella - Epoch Processing - Participation flag updates [Preset: minimal]
```diff
+ Participation flag updates - all_zeroed [Preset: minimal] OK
@ -1359,6 +1436,25 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Capella - Epoch Processing - Rewards and penalties [Preset: minimal]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - attestations_some_slashed [Preset: minimal] OK
+ Rewards and penalties - duplicate_attestation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: minimal] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: minimal] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: minimal] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Capella - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
@ -1489,6 +1585,29 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ Registry updates - invalid_large_withdrawable_epoch [Preset: minimal] OK
```
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Phase 0 - Epoch Processing - Rewards and penalties [Preset: minimal]
```diff
+ Rewards and penalties - almost_empty_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_empty_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations [Preset: minimal] OK
+ Rewards and penalties - almost_full_attestations_with_leak [Preset: minimal] OK
+ Rewards and penalties - attestations_some_slashed [Preset: minimal] OK
+ Rewards and penalties - duplicate_attestation [Preset: minimal] OK
+ Rewards and penalties - duplicate_participants_different_attestation_1 [Preset: minimal] OK
+ Rewards and penalties - duplicate_participants_different_attestation_2 [Preset: minimal] OK
+ Rewards and penalties - duplicate_participants_different_attestation_3 [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation [Preset: minimal] OK
+ Rewards and penalties - full_attestation_participation_with_leak [Preset: minimal] OK
+ Rewards and penalties - full_attestations_misc_balances [Preset: minimal] OK
+ Rewards and penalties - full_attestations_one_validaor_one_gwei [Preset: minimal] OK
+ Rewards and penalties - full_attestations_random_incorrect_fields [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_full_attestations_no_rewards [Preset: minimal] OK
+ Rewards and penalties - genesis_epoch_no_attestations_no_penalties [Preset: minimal] OK
+ Rewards and penalties - no_attestations_all_penalties [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations [Preset: minimal] OK
+ Rewards and penalties - random_fill_attestations_with_leak [Preset: minimal] OK
```
OK: 19/19 Fail: 0/19 Skip: 0/19
## EF - Phase 0 - Epoch Processing - Slashings [Preset: minimal]
```diff
+ Slashings - low_penalty [Preset: minimal] OK
@ -1806,4 +1925,4 @@ OK: 52/52 Fail: 0/52 Skip: 0/52
OK: 14/14 Fail: 0/14 Skip: 0/14
---TOTAL---
OK: 1565/1572 Fail: 0/1572 Skip: 7/1572
OK: 1660/1667 Fail: 0/1667 Skip: 7/1667

View File

@ -945,7 +945,7 @@ func upgrade_to_bellatrix*(cfg: RuntimeConfig, pre: altair.BeaconState):
latest_execution_payload_header: default(bellatrix.ExecutionPayloadHeader)
)
# https://github.com/ethereum/consensus-specs/blob/b90436c98837924c3a929652b57b07ac9d3c2254/specs/capella/fork.md#upgrading-the-state
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/fork.md#upgrading-the-state
func upgrade_to_capella*(cfg: RuntimeConfig, pre: bellatrix.BeaconState):
ref capella.BeaconState =
let

View File

@ -28,28 +28,25 @@ import
export json_serialization, base
type
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#custom-types
WithdrawalIndex = uint64
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#withdrawal
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#withdrawal
Withdrawal* = object
index*: WithdrawalIndex
validator_index*: uint64
address*: ExecutionAddress
amount*: Gwei
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#blstoexecutionchange
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#blstoexecutionchange
BLSToExecutionChange* = object
validator_index*: uint64
from_bls_pubkey*: ValidatorPubKey
to_execution_address*: ExecutionAddress
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#signedblstoexecutionchange
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#signedblstoexecutionchange
SignedBLSToExecutionChange* = object
message*: BLSToExecutionChange
signature*: ValidatorSig
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#executionpayload
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#executionpayload
ExecutionPayload* = object
parent_hash*: Eth2Digest
fee_recipient*: ExecutionAddress # 'beneficiary' in the yellow paper
@ -69,7 +66,7 @@ type
transactions*: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD]
withdrawals*: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD] # [New in Capella]
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#executionpayloadheader
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#executionpayloadheader
ExecutionPayloadHeader* = object
parent_hash*: Eth2Digest
fee_recipient*: ExecutionAddress
@ -92,7 +89,7 @@ type
ExecutePayload* = proc(
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [Defect].}
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#beaconstate
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#beaconstate
BeaconState* = object
# Versioning
genesis_time*: uint64
@ -222,7 +219,7 @@ type
state_root*: Eth2Digest
body*: TrustedBeaconBlockBody
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#beaconblockbody
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#beaconblockbody
BeaconBlockBody* = object
randao_reveal*: ValidatorSig
eth1_data*: Eth1Data

View File

@ -10,6 +10,9 @@ type
Epoch* = distinct uint64
SyncCommitteePeriod* = distinct uint64
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#custom-types
WithdrawalIndex* = uint64
DomainType* = distinct array[4, byte]
const
@ -33,7 +36,7 @@ const
DOMAIN_SYNC_COMMITTEE_SELECTION_PROOF* = DomainType([byte 0x08, 0x00, 0x00, 0x00])
DOMAIN_CONTRIBUTION_AND_PROOF* = DomainType([byte 0x09, 0x00, 0x00, 0x00])
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#domain-types
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#domain-types
DOMAIN_BLS_TO_EXECUTION_CHANGE* = DomainType([byte 0x0a, 0x00, 0x00, 0x00])
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/bellatrix/beacon-chain.md#transition-settings

View File

@ -371,7 +371,7 @@ proc verify_builder_signature*(
let signing_root = compute_builder_signing_root(fork, msg)
blsVerify(pubkey, signing_root.data, signature)
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
func compute_bls_to_execution_change_signing_root(
fork: Fork, genesis_validators_root: Eth2Digest,
epoch: Epoch, msg: BLSToExecutionChange): Eth2Digest =

View File

@ -536,7 +536,7 @@ proc process_execution_payload*(
ok()
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#modified-process_execution_payload
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#modified-process_execution_payload
proc process_execution_payload*(
state: var capella.BeaconState, payload: capella.ExecutionPayload,
notify_new_payload: capella.ExecutePayload): Result[void, cstring] =
@ -579,7 +579,7 @@ proc process_execution_payload*(
ok()
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#new-process_bls_to_execution_change
proc process_bls_to_execution_change*(
state: var capella.BeaconState,
signed_address_change: SignedBLSToExecutionChange): Result[void, cstring] =
@ -614,7 +614,7 @@ proc process_bls_to_execution_change*(
ok()
# https://github.com/ethereum/consensus-specs/blob/53b63cedc586c3e1cc2ff737e85c1ed8a3eb45c6/specs/capella/beacon-chain.md#new-process_withdrawals
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#new-process_withdrawals
func process_withdrawals*(
state: var capella.BeaconState, payload: capella.ExecutionPayload):
Result[void, cstring] =

View File

@ -30,7 +30,7 @@ import
./datatypes/[phase0, altair, bellatrix],
"."/[beaconstate, eth2_merkleization, helpers, validator]
from ./datatypes/capella import BeaconState
from ./datatypes/capella import BeaconState, Withdrawal, WithdrawalIndex
export extras, phase0, altair
@ -746,7 +746,7 @@ iterator get_inactivity_penalty_deltas*(
yield (vidx, Gwei(penalty_numerator div penalty_denominator))
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#rewards-and-penalties-1
func process_rewards_and_penalties(
func process_rewards_and_penalties*(
state: var phase0.BeaconState, info: var phase0.EpochInfo) =
# No rewards are applied at the end of `GENESIS_EPOCH` because rewards are
# for work done in the previous epoch
@ -769,7 +769,7 @@ func process_rewards_and_penalties(
state.balances.asSeq()[idx] = balance
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/altair/beacon-chain.md#rewards-and-penalties
func process_rewards_and_penalties(
func process_rewards_and_penalties*(
cfg: RuntimeConfig, state: var (altair.BeaconState | bellatrix.BeaconState | capella.BeaconState),
info: var altair.EpochInfo)
=
@ -1045,6 +1045,83 @@ func process_inactivity_updates*(
if pre_inactivity_score != inactivity_score:
state.inactivity_scores[index] = inactivity_score
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#has_eth1_withdrawal_credential
func has_eth1_withdrawal_credential(validator: Validator): bool =
## Check if ``validator`` has an 0x01 prefixed "eth1" withdrawal credential.
validator.withdrawal_credentials.data[0] == ETH1_ADDRESS_WITHDRAWAL_PREFIX
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#is_fully_withdrawable_validator
func is_fully_withdrawable_validator(
validator: Validator, balance: Gwei, epoch: Epoch): bool =
## Check if ``validator`` is fully withdrawable.
has_eth1_withdrawal_credential(validator) and
validator.withdrawable_epoch <= epoch and balance > 0
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#is_partially_withdrawable_validator
func is_partially_withdrawable_validator(
validator: Validator, balance: Gwei): bool =
## Check if ``validator`` is partially withdrawable.
let
has_max_effective_balance =
validator.effective_balance == MAX_EFFECTIVE_BALANCE
has_excess_balance = balance > MAX_EFFECTIVE_BALANCE
has_eth1_withdrawal_credential(validator) and
has_max_effective_balance and has_excess_balance
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#withdraw_balance
func withdraw_balance(
state: var capella.BeaconState, validator_index: ValidatorIndex,
amount: Gwei) =
# Decrease the validator's balance
decrease_balance(state, validator_index, amount)
# Create a corresponding withdrawal receipt
var withdrawal = Withdrawal(
index: state.next_withdrawal_index,
validator_index: validator_index.uint64,
amount: amount)
withdrawal.address.data[0 .. 19] =
state.validators.item(
validator_index).withdrawal_credentials.data.toOpenArray(12, 31)
state.next_withdrawal_index = WithdrawalIndex(state.next_withdrawal_index + 1)
#TODO TODO don't just discard, check if full
discard state.withdrawal_queue.add(withdrawal)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#full-withdrawals
func process_full_withdrawals*(state: var capella.BeaconState) =
let current_epoch = get_current_epoch(state)
for index in 0 ..< len(state.validators):
let
balance = state.balances.item(index)
validator = state.validators.item(index)
if is_fully_withdrawable_validator(validator, balance, current_epoch):
withdraw_balance(state, ValidatorIndex(index), balance)
# https://github.com/ethereum/consensus-specs/blob/v1.3.0-alpha.0/specs/capella/beacon-chain.md#partial-withdrawals
func process_partial_withdrawals*(state: var capella.BeaconState) =
var partial_withdrawals_count = 0
# Begin where we left off last time
var validator_index = state.next_partial_withdrawal_validator_index
for _ in 0 ..< len(state.validators):
let
balance = state.balances.item(validator_index)
validator = state.validators.item(validator_index)
if is_partially_withdrawable_validator(validator, balance):
withdraw_balance(
state, validator_index.ValidatorIndex, balance - MAX_EFFECTIVE_BALANCE)
partial_withdrawals_count += 1
# Iterate to next validator to check for partial withdrawal
validator_index = (validator_index + 1) mod lenu64(state.validators)
# Exit if performed maximum allowable withdrawals
if partial_withdrawals_count == MAX_PARTIAL_WITHDRAWALS_PER_EPOCH:
break
state.next_partial_withdrawal_validator_index = validator_index
# https://github.com/ethereum/consensus-specs/blob/v1.2.0/specs/phase0/beacon-chain.md#epoch-processing
proc process_epoch*(
cfg: RuntimeConfig, state: var phase0.BeaconState, flags: UpdateFlags,

View File

@ -8,8 +8,6 @@
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
chronicles,
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
@ -20,13 +18,40 @@ import
./test_fixture_rewards,
../../helpers/debug_state
const RootDir = SszTestsDir/const_preset/"altair"/"epoch_processing"
from std/os import
DirSep, dirExists, fileExists, pcDir, walkDir, walkDirRec, `/`
from std/sequtils import mapIt, toSeq
from std/strutils import rsplit
const
RootDir = SszTestsDir/const_preset/"altair"/"epoch_processing"
JustificationFinalizationDir = RootDir/"justification_and_finalization"
InactivityDir = RootDir/"inactivity_updates"
RegistryUpdatesDir = RootDir/"registry_updates"
SlashingsDir = RootDir/"slashings"
Eth1DataResetDir = RootDir/"eth1_data_reset"
EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"
SlashingsResetDir = RootDir/"slashings_reset"
RandaoMixesResetDir = RootDir/"randao_mixes_reset"
HistoricalRootsUpdateDir = RootDir/"historical_roots_update"
ParticipationFlagDir = RootDir/"participation_flag_updates"
SyncCommitteeDir = RootDir/"sync_committee_updates"
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
doAssert (toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) -
toHashSet([SyncCommitteeDir])) ==
toHashSet([
JustificationFinalizationDir, InactivityDir, RegistryUpdatesDir,
SlashingsDir, Eth1DataResetDir, EffectiveBalanceUpdatesDir,
SlashingsResetDir, RandaoMixesResetDir, HistoricalRootsUpdateDir,
ParticipationFlagDir, RewardsAndPenaltiesDir])
template runSuite(
suiteDir, testName: string, transitionProc: untyped): untyped =
suite "EF - Altair - Epoch Processing - " & testName & preset():
for testDir in walkDirRec(suiteDir, yieldFilter = {pcDir}, checkDir = true):
for testDir in walkDirRec(
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
let unitTestName = testDir.rsplit(DirSep, 1)[1]
test testName & " - " & unitTestName & preset():
# BeaconState objects are stored on the heap to avoid stack overflow
@ -46,8 +71,6 @@ template runSuite(
# Justification & Finalization
# ---------------------------------------------------------------
const JustificationFinalizationDir = RootDir/"justification_and_finalization"/"pyspec_tests"
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
let info = altair.EpochInfo.init(state)
process_justification_and_finalization(state, info.balances)
@ -55,8 +78,6 @@ runSuite(JustificationFinalizationDir, "Justification & Finalization"):
# Inactivity updates
# ---------------------------------------------------------------
const InactivityDir = RootDir/"inactivity_updates"/"pyspec_tests"
runSuite(InactivityDir, "Inactivity"):
let info = altair.EpochInfo.init(state)
process_inactivity_updates(cfg, state, info)
@ -64,20 +85,20 @@ runSuite(InactivityDir, "Inactivity"):
# Rewards & Penalties
# ---------------------------------------------------------------
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
var info = altair.EpochInfo.init(state)
process_rewards_and_penalties(cfg, state, info)
Result[void, cstring].ok()
# in test_fixture_rewards
# rest in test_fixture_rewards
# Registry updates
# ---------------------------------------------------------------
const RegistryUpdatesDir = RootDir/"registry_updates"/"pyspec_tests"
runSuite(RegistryUpdatesDir, "Registry updates"):
process_registry_updates(cfg, state, cache)
# Slashings
# ---------------------------------------------------------------
const SlashingsDir = RootDir/"slashings"/"pyspec_tests"
runSuite(SlashingsDir, "Slashings"):
let info = altair.EpochInfo.init(state)
process_slashings(state, info.balances.current_epoch)
@ -85,48 +106,36 @@ runSuite(SlashingsDir, "Slashings"):
# Eth1 data reset
# ---------------------------------------------------------------
const Eth1DataResetDir = RootDir/"eth1_data_reset/"/"pyspec_tests"
runSuite(Eth1DataResetDir, "Eth1 data reset"):
process_eth1_data_reset(state)
Result[void, cstring].ok()
# Effective balance updates
# ---------------------------------------------------------------
const EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"/"pyspec_tests"
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
process_effective_balance_updates(state)
Result[void, cstring].ok()
# Slashings reset
# ---------------------------------------------------------------
const SlashingsResetDir = RootDir/"slashings_reset"/"pyspec_tests"
runSuite(SlashingsResetDir, "Slashings reset"):
process_slashings_reset(state)
Result[void, cstring].ok()
# RANDAO mixes reset
# ---------------------------------------------------------------
const RandaoMixesResetDir = RootDir/"randao_mixes_reset"/"pyspec_tests"
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
process_randao_mixes_reset(state)
Result[void, cstring].ok()
# Historical roots update
# ---------------------------------------------------------------
const HistoricalRootsUpdateDir = RootDir/"historical_roots_update"/"pyspec_tests"
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
process_historical_roots_update(state)
Result[void, cstring].ok()
# Participation flag updates
# ---------------------------------------------------------------
const ParticipationFlagDir = RootDir/"participation_flag_updates"/"pyspec_tests"
runSuite(ParticipationFlagDir, "Participation flag updates"):
process_participation_flag_updates(state)
Result[void, cstring].ok()
@ -135,7 +144,6 @@ runSuite(ParticipationFlagDir, "Participation flag updates"):
# ---------------------------------------------------------------
# These are only for minimal, not mainnet
const SyncCommitteeDir = RootDir/"sync_committee_updates"/"pyspec_tests"
when const_preset == "minimal":
runSuite(SyncCommitteeDir, "Sync committee updates"):
process_sync_committee_updates(state)

View File

@ -8,8 +8,6 @@
{.used.}
import
# Standard library
std/[os, strutils],
# Beacon chain internals
../../../beacon_chain/spec/[beaconstate, presets, state_transition_epoch],
../../../beacon_chain/spec/datatypes/[altair, bellatrix],
@ -19,12 +17,40 @@ import
./test_fixture_rewards,
../../helpers/debug_state
const RootDir = SszTestsDir/const_preset/"bellatrix"/"epoch_processing"
from std/os import
DirSep, dirExists, fileExists, pcDir, walkDir, walkDirRec, `/`
from std/strutils import rsplit
from std/sequtils import mapIt, toSeq
const
RootDir = SszTestsDir/const_preset/"bellatrix"/"epoch_processing"
JustificationFinalizationDir = RootDir/"justification_and_finalization"
InactivityDir = RootDir/"inactivity_updates"
RegistryUpdatesDir = RootDir/"registry_updates"
SlashingsDir = RootDir/"slashings"
Eth1DataResetDir = RootDir/"eth1_data_reset"
EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"
SlashingsResetDir = RootDir/"slashings_reset"
RandaoMixesResetDir = RootDir/"randao_mixes_reset"
HistoricalRootsUpdateDir = RootDir/"historical_roots_update"
ParticipationFlagDir = RootDir/"participation_flag_updates"
SyncCommitteeDir = RootDir/"sync_committee_updates"
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
doAssert (toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) -
toHashSet([SyncCommitteeDir])) ==
toHashSet([
JustificationFinalizationDir, InactivityDir, RegistryUpdatesDir,
SlashingsDir, Eth1DataResetDir, EffectiveBalanceUpdatesDir,
SlashingsResetDir, RandaoMixesResetDir, HistoricalRootsUpdateDir,
ParticipationFlagDir, RewardsAndPenaltiesDir])
template runSuite(
suiteDir, testName: string, transitionProc: untyped): untyped =
suite "EF - Bellatrix - Epoch Processing - " & testName & preset():
for testDir in walkDirRec(suiteDir, yieldFilter = {pcDir}, checkDir = true):
for testDir in walkDirRec(
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
let unitTestName = testDir.rsplit(DirSep, 1)[1]
test testName & " - " & unitTestName & preset():
# BeaconState objects are stored on the heap to avoid stack overflow
@ -44,8 +70,6 @@ template runSuite(
# Justification & Finalization
# ---------------------------------------------------------------
const JustificationFinalizationDir = RootDir/"justification_and_finalization"/"pyspec_tests"
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
let info = altair.EpochInfo.init(state)
process_justification_and_finalization(state, info.balances)
@ -53,8 +77,6 @@ runSuite(JustificationFinalizationDir, "Justification & Finalization"):
# Inactivity updates
# ---------------------------------------------------------------
const InactivityDir = RootDir/"inactivity_updates"/"pyspec_tests"
runSuite(InactivityDir, "Inactivity"):
let info = altair.EpochInfo.init(state)
process_inactivity_updates(cfg, state, info)
@ -62,20 +84,20 @@ runSuite(InactivityDir, "Inactivity"):
# Rewards & Penalties
# ---------------------------------------------------------------
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
var info = altair.EpochInfo.init(state)
process_rewards_and_penalties(cfg, state, info)
Result[void, cstring].ok()
# in test_fixture_rewards
# rest in test_fixture_rewards
# Registry updates
# ---------------------------------------------------------------
const RegistryUpdatesDir = RootDir/"registry_updates"/"pyspec_tests"
runSuite(RegistryUpdatesDir, "Registry updates"):
process_registry_updates(cfg, state, cache)
# Slashings
# ---------------------------------------------------------------
const SlashingsDir = RootDir/"slashings"/"pyspec_tests"
runSuite(SlashingsDir, "Slashings"):
let info = altair.EpochInfo.init(state)
process_slashings(state, info.balances.current_epoch)
@ -83,48 +105,36 @@ runSuite(SlashingsDir, "Slashings"):
# Eth1 data reset
# ---------------------------------------------------------------
const Eth1DataResetDir = RootDir/"eth1_data_reset/"/"pyspec_tests"
runSuite(Eth1DataResetDir, "Eth1 data reset"):
process_eth1_data_reset(state)
Result[void, cstring].ok()
# Effective balance updates
# ---------------------------------------------------------------
const EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"/"pyspec_tests"
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
process_effective_balance_updates(state)
Result[void, cstring].ok()
# Slashings reset
# ---------------------------------------------------------------
const SlashingsResetDir = RootDir/"slashings_reset"/"pyspec_tests"
runSuite(SlashingsResetDir, "Slashings reset"):
process_slashings_reset(state)
Result[void, cstring].ok()
# RANDAO mixes reset
# ---------------------------------------------------------------
const RandaoMixesResetDir = RootDir/"randao_mixes_reset"/"pyspec_tests"
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
process_randao_mixes_reset(state)
Result[void, cstring].ok()
# Historical roots update
# ---------------------------------------------------------------
const HistoricalRootsUpdateDir = RootDir/"historical_roots_update"/"pyspec_tests"
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
process_historical_roots_update(state)
Result[void, cstring].ok()
# Participation flag updates
# ---------------------------------------------------------------
const ParticipationFlagDir = RootDir/"participation_flag_updates"/"pyspec_tests"
runSuite(ParticipationFlagDir, "Participation flag updates"):
process_participation_flag_updates(state)
Result[void, cstring].ok()
@ -133,7 +143,6 @@ runSuite(ParticipationFlagDir, "Participation flag updates"):
# ---------------------------------------------------------------
# These are only for minimal, not mainnet
const SyncCommitteeDir = RootDir/"sync_committee_updates"/"pyspec_tests"
when const_preset == "minimal":
runSuite(SyncCommitteeDir, "Sync committee updates"):
process_sync_committee_updates(state)

View File

@ -8,8 +8,6 @@
{.used.}
import
# Standard library
std/[os, strutils],
# Status internals
chronicles,
# Beacon chain internals
@ -21,12 +19,43 @@ import
./test_fixture_rewards,
../../helpers/debug_state
const RootDir = SszTestsDir/const_preset/"capella"/"epoch_processing"
from std/os import
DirSep, dirExists, fileExists, pcDir, walkDir, walkDirRec, `/`
from std/sequtils import mapIt, toSeq
from std/strutils import rsplit
const
RootDir = SszTestsDir/const_preset/"capella"/"epoch_processing"
JustificationFinalizationDir = RootDir/"justification_and_finalization"
InactivityDir = RootDir/"inactivity_updates"
RegistryUpdatesDir = RootDir/"registry_updates"
SlashingsDir = RootDir/"slashings"
Eth1DataResetDir = RootDir/"eth1_data_reset"
EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"
SlashingsResetDir = RootDir/"slashings_reset"
RandaoMixesResetDir = RootDir/"randao_mixes_reset"
HistoricalRootsUpdateDir = RootDir/"historical_roots_update"
ParticipationFlagDir = RootDir/"participation_flag_updates"
SyncCommitteeDir = RootDir/"sync_committee_updates"
FullWithdrawalsDir = RootDir/"full_withdrawals"
PartialWithdrawalsDir = RootDir/"partial_withdrawals"
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
doAssert (toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) -
toHashSet([SyncCommitteeDir])) ==
toHashSet([
JustificationFinalizationDir, InactivityDir, RegistryUpdatesDir,
SlashingsDir, Eth1DataResetDir, EffectiveBalanceUpdatesDir,
SlashingsResetDir, RandaoMixesResetDir, HistoricalRootsUpdateDir,
ParticipationFlagDir, FullWithDrawalsDir,
PartialWithdrawalsDir, RewardsAndPenaltiesDir])
template runSuite(
suiteDir, testName: string, transitionProc: untyped): untyped =
suite "EF - Capella - Epoch Processing - " & testName & preset():
for testDir in walkDirRec(suiteDir, yieldFilter = {pcDir}, checkDir = true):
for testDir in walkDirRec(
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
let unitTestName = testDir.rsplit(DirSep, 1)[1]
test testName & " - " & unitTestName & preset():
# BeaconState objects are stored on the heap to avoid stack overflow
@ -46,8 +75,6 @@ template runSuite(
# Justification & Finalization
# ---------------------------------------------------------------
const JustificationFinalizationDir = RootDir/"justification_and_finalization"/"pyspec_tests"
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
let info = altair.EpochInfo.init(state)
process_justification_and_finalization(state, info.balances)
@ -55,8 +82,6 @@ runSuite(JustificationFinalizationDir, "Justification & Finalization"):
# Inactivity updates
# ---------------------------------------------------------------
const InactivityDir = RootDir/"inactivity_updates"/"pyspec_tests"
runSuite(InactivityDir, "Inactivity"):
let info = altair.EpochInfo.init(state)
process_inactivity_updates(cfg, state, info)
@ -64,20 +89,20 @@ runSuite(InactivityDir, "Inactivity"):
# Rewards & Penalties
# ---------------------------------------------------------------
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
var info = altair.EpochInfo.init(state)
process_rewards_and_penalties(cfg, state, info)
Result[void, cstring].ok()
# in test_fixture_rewards
# rest in test_fixture_rewards
# Registry updates
# ---------------------------------------------------------------
const RegistryUpdatesDir = RootDir/"registry_updates"/"pyspec_tests"
runSuite(RegistryUpdatesDir, "Registry updates"):
process_registry_updates(cfg, state, cache)
# Slashings
# ---------------------------------------------------------------
const SlashingsDir = RootDir/"slashings"/"pyspec_tests"
runSuite(SlashingsDir, "Slashings"):
let info = altair.EpochInfo.init(state)
process_slashings(state, info.balances.current_epoch)
@ -85,48 +110,36 @@ runSuite(SlashingsDir, "Slashings"):
# Eth1 data reset
# ---------------------------------------------------------------
const Eth1DataResetDir = RootDir/"eth1_data_reset/"/"pyspec_tests"
runSuite(Eth1DataResetDir, "Eth1 data reset"):
process_eth1_data_reset(state)
Result[void, cstring].ok()
# Effective balance updates
# ---------------------------------------------------------------
const EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"/"pyspec_tests"
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
process_effective_balance_updates(state)
Result[void, cstring].ok()
# Slashings reset
# ---------------------------------------------------------------
const SlashingsResetDir = RootDir/"slashings_reset"/"pyspec_tests"
runSuite(SlashingsResetDir, "Slashings reset"):
process_slashings_reset(state)
Result[void, cstring].ok()
# RANDAO mixes reset
# ---------------------------------------------------------------
const RandaoMixesResetDir = RootDir/"randao_mixes_reset"/"pyspec_tests"
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
process_randao_mixes_reset(state)
Result[void, cstring].ok()
# Historical roots update
# ---------------------------------------------------------------
const HistoricalRootsUpdateDir = RootDir/"historical_roots_update"/"pyspec_tests"
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
process_historical_roots_update(state)
Result[void, cstring].ok()
# Participation flag updates
# ---------------------------------------------------------------
const ParticipationFlagDir = RootDir/"participation_flag_updates"/"pyspec_tests"
runSuite(ParticipationFlagDir, "Participation flag updates"):
process_participation_flag_updates(state)
Result[void, cstring].ok()
@ -135,10 +148,21 @@ runSuite(ParticipationFlagDir, "Participation flag updates"):
# ---------------------------------------------------------------
# These are only for minimal, not mainnet
const SyncCommitteeDir = RootDir/"sync_committee_updates"/"pyspec_tests"
when const_preset == "minimal":
runSuite(SyncCommitteeDir, "Sync committee updates"):
process_sync_committee_updates(state)
Result[void, cstring].ok()
else:
doAssert not dirExists(SyncCommitteeDir)
# Full withdrawals
# ---------------------------------------------------------------
runSuite(FullWithdrawalsDir, "Full withdrawals"):
process_full_withdrawals(state)
Result[void, cstring].ok()
# Partial withdrawals
# ---------------------------------------------------------------
runSuite(PartialWithdrawalsDir, "Partial withdrawals"):
process_partial_withdrawals(state)
Result[void, cstring].ok()

View File

@ -8,8 +8,6 @@
{.used.}
import
# Standard library
os, strutils,
# Beacon chain internals
chronicles,
../../../beacon_chain/spec/state_transition_epoch,
@ -20,11 +18,35 @@ import
./test_fixture_rewards,
../../helpers/debug_state
const RootDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"
from std/os import DirSep, fileExists, pcDir, walkDir, walkDirRec, `/`
from std/sequtils import mapIt, toSeq
from std/strutils import rsplit
const
RootDir = SszTestsDir/const_preset/"phase0"/"epoch_processing"
JustificationFinalizationDir = RootDir/"justification_and_finalization"
RegistryUpdatesDir = RootDir/"registry_updates"
SlashingsDir = RootDir/"slashings"
Eth1DataResetDir = RootDir/"eth1_data_reset"
EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"
SlashingsResetDir = RootDir/"slashings_reset"
RandaoMixesResetDir = RootDir/"randao_mixes_reset"
HistoricalRootsUpdateDir = RootDir/"historical_roots_update"
RewardsAndPenaltiesDir = RootDir/"rewards_and_penalties"
ParticipationRecordsDir = RootDir/"participation_record_updates"
doAssert toHashSet(mapIt(toSeq(walkDir(RootDir, relative = false)), it.path)) ==
toHashSet([
JustificationFinalizationDir, RegistryUpdatesDir, SlashingsDir,
Eth1DataResetDir, EffectiveBalanceUpdatesDir, SlashingsResetDir,
RandaoMixesResetDir, HistoricalRootsUpdateDir, ParticipationRecordsDir,
RewardsAndPenaltiesDir])
template runSuite(suiteDir, testName: string, transitionProc: untyped): untyped =
suite "EF - Phase 0 - Epoch Processing - " & testName & preset():
for testDir in walkDirRec(suiteDir, yieldFilter = {pcDir}, checkDir = true):
for testDir in walkDirRec(
suiteDir / "pyspec_tests", yieldFilter = {pcDir}, checkDir = true):
let unitTestName = testDir.rsplit(DirSep, 1)[1]
test testName & " - " & unitTestName & preset():
@ -47,8 +69,6 @@ template runSuite(suiteDir, testName: string, transitionProc: untyped): untyped
# Justification & Finalization
# ---------------------------------------------------------------
const JustificationFinalizationDir = RootDir/"justification_and_finalization"/"pyspec_tests"
runSuite(JustificationFinalizationDir, "Justification & Finalization"):
info.process_attestations(state, cache)
process_justification_and_finalization(state, info.balances)
@ -56,20 +76,23 @@ runSuite(JustificationFinalizationDir, "Justification & Finalization"):
# Rewards & Penalties
# ---------------------------------------------------------------
runSuite(RewardsAndPenaltiesDir, "Rewards and penalties"):
var info: phase0.EpochInfo
var cache: StateCache
info.init(state)
info.process_attestations(state, cache)
process_rewards_and_penalties(state, info)
Result[void, cstring].ok()
# in test_fixture_rewards
# rest in test_fixture_rewards
# Registry updates
# ---------------------------------------------------------------
const RegistryUpdatesDir = RootDir/"registry_updates"/"pyspec_tests"
runSuite(RegistryUpdatesDir, "Registry updates"):
process_registry_updates(cfg, state, cache)
# Slashings
# ---------------------------------------------------------------
const SlashingsDir = RootDir/"slashings"/"pyspec_tests"
runSuite(SlashingsDir, "Slashings"):
info.process_attestations(state, cache)
process_slashings(state, info.balances.current_epoch)
@ -77,33 +100,26 @@ runSuite(SlashingsDir, "Slashings"):
# Final updates
# ---------------------------------------------------------------
const Eth1DataResetDir = RootDir/"eth1_data_reset/"/"pyspec_tests"
runSuite(Eth1DataResetDir, "Eth1 data reset"):
process_eth1_data_reset(state)
Result[void, cstring].ok()
const EffectiveBalanceUpdatesDir = RootDir/"effective_balance_updates"/"pyspec_tests"
runSuite(EffectiveBalanceUpdatesDir, "Effective balance updates"):
process_effective_balance_updates(state)
Result[void, cstring].ok()
const SlashingsResetDir = RootDir/"slashings_reset"/"pyspec_tests"
runSuite(SlashingsResetDir, "Slashings reset"):
process_slashings_reset(state)
Result[void, cstring].ok()
const RandaoMixesResetDir = RootDir/"randao_mixes_reset"/"pyspec_tests"
runSuite(RandaoMixesResetDir, "RANDAO mixes reset"):
process_randao_mixes_reset(state)
Result[void, cstring].ok()
const HistoricalRootsUpdateDir = RootDir/"historical_roots_update"/"pyspec_tests"
runSuite(HistoricalRootsUpdateDir, "Historical roots update"):
process_historical_roots_update(state)
Result[void, cstring].ok()
const ParticipationRecordsDir = RootDir/"participation_record_updates"/"pyspec_tests"
runSuite(ParticipationRecordsDir, "Participation record updates"):
process_participation_record_updates(state)
Result[void, cstring].ok()