-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] Generate Hive Test Fixtures #3374
base: dev
Are you sure you want to change the base?
Changes from 4 commits
7cc5a3f
5ad19e5
b13695e
9ef9b43
7844e82
276dd6f
3ca6ead
f0165a4
b2bddce
068d7b1
70f5e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Mainnet config | ||
|
||
# Extends the mainnet preset | ||
PRESET_BASE: 'mainnet' | ||
|
||
# Free-form short name of the network that this configuration applies to - known | ||
# canonical network names include: | ||
# * 'mainnet' - there can be only one | ||
# * 'prater' - testnet | ||
# Must match the regex: [a-z0-9\-] | ||
CONFIG_NAME: 'hive' | ||
|
||
# Transition | ||
# --------------------------------------------------------------- | ||
# Estimated on Sept 15, 2022 | ||
TERMINAL_TOTAL_DIFFICULTY: 58750000000000000000000 | ||
# By default, don't use these params | ||
TERMINAL_BLOCK_HASH: 0x0000000000000000000000000000000000000000000000000000000000000000 | ||
TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH: 18446744073709551615 | ||
|
||
|
||
|
||
# Genesis | ||
# --------------------------------------------------------------- | ||
# `2**14` (= 16,384) | ||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 16384 | ||
# Dec 1, 2020, 12pm UTC | ||
MIN_GENESIS_TIME: 1606824000 | ||
# Mainnet initial fork version, recommend altering for testnets | ||
GENESIS_FORK_VERSION: 0x0000000a | ||
# 604800 seconds (7 days) | ||
GENESIS_DELAY: 604800 | ||
|
||
|
||
# Forking | ||
# --------------------------------------------------------------- | ||
# Some forks are disabled for now: | ||
# - These may be re-assigned to another fork-version later | ||
# - Temporarily set to max uint64 value: 2**64 - 1 | ||
|
||
# Altair | ||
ALTAIR_FORK_VERSION: 0x0100000a | ||
ALTAIR_FORK_EPOCH: 74240 # Oct 27, 2021, 10:56:23am UTC | ||
# Bellatrix | ||
BELLATRIX_FORK_VERSION: 0x0200000a | ||
BELLATRIX_FORK_EPOCH: 144896 # Sept 6, 2022, 11:34:47am UTC | ||
# Capella | ||
CAPELLA_FORK_VERSION: 0x0300000a | ||
CAPELLA_FORK_EPOCH: 194048 # April 12, 2023, 10:27:35pm UTC | ||
# Deneb | ||
DENEB_FORK_VERSION: 0x0400000a | ||
DENEB_FORK_EPOCH: 18446744073709551615 | ||
|
||
|
||
|
||
|
||
# Time parameters | ||
# --------------------------------------------------------------- | ||
# 12 seconds | ||
SECONDS_PER_SLOT: 12 | ||
# 14 (estimate from Eth1 mainnet) | ||
SECONDS_PER_ETH1_BLOCK: 14 | ||
# 2**8 (= 256) epochs ~27 hours | ||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256 | ||
# 2**8 (= 256) epochs ~27 hours | ||
SHARD_COMMITTEE_PERIOD: 256 | ||
# 2**11 (= 2,048) Eth1 blocks ~8 hours | ||
ETH1_FOLLOW_DISTANCE: 2048 | ||
|
||
|
||
# Validator cycle | ||
# --------------------------------------------------------------- | ||
# 2**2 (= 4) | ||
INACTIVITY_SCORE_BIAS: 4 | ||
# 2**4 (= 16) | ||
INACTIVITY_SCORE_RECOVERY_RATE: 16 | ||
# 2**4 * 10**9 (= 16,000,000,000) Gwei | ||
EJECTION_BALANCE: 16000000000 | ||
# 2**2 (= 4) | ||
MIN_PER_EPOCH_CHURN_LIMIT: 4 | ||
# 2**16 (= 65,536) | ||
CHURN_LIMIT_QUOTIENT: 65536 | ||
|
||
|
||
# Fork choice | ||
# --------------------------------------------------------------- | ||
# 40% | ||
PROPOSER_SCORE_BOOST: 40 | ||
|
||
# Deposit contract | ||
# --------------------------------------------------------------- | ||
# Ethereum PoW Mainnet | ||
DEPOSIT_CHAIN_ID: 1 | ||
DEPOSIT_NETWORK_ID: 1 | ||
DEPOSIT_CONTRACT_ADDRESS: 0x00000000219ab540356cBB839Cbe05303d7705Fa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from eth2spec.test.helpers.hive import StateID, VerifyBeaconStateV2 | ||
from eth2spec.test.context import ( | ||
with_capella_and_later, | ||
spec_state_test, | ||
hive_state, | ||
) | ||
from eth2spec.test.helpers.state import ( | ||
state_transition_and_sign_block, | ||
next_slot, | ||
) | ||
from eth2spec.test.helpers.block import ( | ||
build_empty_block_for_next_slot, | ||
) | ||
from eth2spec.test.helpers.withdrawals import ( | ||
prepare_expected_withdrawals, | ||
) | ||
|
||
|
||
def _perform_valid_withdrawal(spec, state): | ||
fully_withdrawable_indices, partial_withdrawals_indices = prepare_expected_withdrawals( | ||
spec, state, num_partial_withdrawals=spec.MAX_WITHDRAWALS_PER_PAYLOAD * 2, | ||
num_full_withdrawals=spec.MAX_WITHDRAWALS_PER_PAYLOAD * 2) | ||
|
||
next_slot(spec, state) | ||
pre_next_withdrawal_index = state.next_withdrawal_index | ||
|
||
expected_withdrawals = spec.get_expected_withdrawals(state) | ||
|
||
pre_state = state.copy() | ||
|
||
# Block 1 | ||
block = build_empty_block_for_next_slot(spec, state) | ||
signed_block_1 = state_transition_and_sign_block(spec, state, block) | ||
|
||
withdrawn_indices = [withdrawal.validator_index for withdrawal in expected_withdrawals] | ||
fully_withdrawable_indices = list(set(fully_withdrawable_indices).difference(set(withdrawn_indices))) | ||
partial_withdrawals_indices = list(set(partial_withdrawals_indices).difference(set(withdrawn_indices))) | ||
assert state.next_withdrawal_index == pre_next_withdrawal_index + spec.MAX_WITHDRAWALS_PER_PAYLOAD | ||
|
||
withdrawn_indices = [withdrawal.validator_index for withdrawal in expected_withdrawals] | ||
fully_withdrawable_indices = list(set(fully_withdrawable_indices).difference(set(withdrawn_indices))) | ||
partial_withdrawals_indices = list(set(partial_withdrawals_indices).difference(set(withdrawn_indices))) | ||
assert state.next_withdrawal_index == pre_next_withdrawal_index + spec.MAX_WITHDRAWALS_PER_PAYLOAD | ||
|
||
return pre_state, signed_block_1, pre_next_withdrawal_index | ||
|
||
|
||
@with_capella_and_later | ||
@spec_state_test | ||
@hive_state | ||
def test_debug_beacon_state_v2(spec, state): | ||
_, signed_block_1, pre_next_withdrawal_index = (_perform_valid_withdrawal(spec, state)) | ||
|
||
# Block 2 | ||
block = build_empty_block_for_next_slot(spec, state) | ||
signed_block_2 = state_transition_and_sign_block(spec, state, block) | ||
|
||
assert state.next_withdrawal_index == pre_next_withdrawal_index + spec.MAX_WITHDRAWALS_PER_PAYLOAD * 2 | ||
yield 'blocks', [signed_block_1, signed_block_2] | ||
yield 'post', state | ||
|
||
yield 'hive', [ | ||
( | ||
VerifyBeaconStateV2(id=StateID.Head()). | ||
state_root(signed_block_2.message.state_root) | ||
), | ||
( | ||
VerifyBeaconStateV2(id=StateID.Slot(signed_block_2.message.slot)). | ||
state_root(signed_block_2.message.state_root) | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from ruamel.yaml import YAML | ||
from dataclasses import dataclass, field | ||
from typing import Dict | ||
yaml = YAML() | ||
|
||
|
||
class StateID(str): | ||
|
||
@classmethod | ||
def Root(cls, root): | ||
return cls(f"root:{root.hex()}") | ||
|
||
@classmethod | ||
def Slot(cls, slot): | ||
return cls(f"slot:{slot}") | ||
|
||
@classmethod | ||
def Head(cls): | ||
return cls("head") | ||
|
||
@classmethod | ||
def Genesis(cls): | ||
return cls("genesis") | ||
|
||
@classmethod | ||
def Finalized(cls): | ||
return cls("finalized") | ||
|
||
@classmethod | ||
def Justified(cls): | ||
return cls("justified") | ||
|
||
|
||
@dataclass(kw_only=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! :) Also removed the |
||
class VerifyBeaconStateV2: | ||
method: str = "BeaconStateV2" | ||
id: StateID | ||
fields: Dict = field(default_factory=dict) | ||
|
||
def __post_init__(self): | ||
self.id = str(self.id) | ||
|
||
def state_root(self, state_root): | ||
self.fields["state_root"] = state_root.hex() | ||
return self | ||
|
||
|
||
yaml.register_class(VerifyBeaconStateV2) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Sanity tests | ||
|
||
The aim of the sanity tests is to set a base-line on what really needs to pass, i.e. the essentials. | ||
|
||
There are two handlers, documented individually: | ||
- [`slots`](./slots.md): transitions of one or more slots (and epoch transitions within) | ||
- [`blocks`](./blocks.md): transitions triggered by one or more blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a small modification in
setup.py
for this change to work: It was failing because there is no hive kzg setup, so I addedEQUIVALENT_KZG_SETUPS
map to re-utilize the existing mainnet kzg setup.