-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BeaconState enum with default state builder fn
- Loading branch information
1 parent
ca95473
commit d173e20
Showing
3 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
# Minimal preset | ||
|
||
|
||
# Misc | ||
# --------------------------------------------------------------- | ||
|
||
# [customized] Just 4 committees for slot for testing purposes | ||
MAX_COMMITTEES_PER_SLOT: 4 | ||
# [customized] unsecure, but fast | ||
TARGET_COMMITTEE_SIZE: 4 | ||
# 2**11 (= 2,048) | ||
MAX_VALIDATORS_PER_COMMITTEE: 2048 | ||
# 2**2 (= 4) | ||
MIN_PER_EPOCH_CHURN_LIMIT: 4 | ||
# 2**16 (= 65,536) | ||
CHURN_LIMIT_QUOTIENT: 65536 | ||
# [customized] Faster, but unsecure. | ||
SHUFFLE_ROUND_COUNT: 10 | ||
# [customized] | ||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 64 | ||
# Jan 3, 2020 | ||
MIN_GENESIS_TIME: 1578009600 | ||
# 4 | ||
HYSTERESIS_QUOTIENT: 4 | ||
# 1 (minus 0.25) | ||
HYSTERESIS_DOWNWARD_MULTIPLIER: 1 | ||
# 5 (plus 1.25) | ||
HYSTERESIS_UPWARD_MULTIPLIER: 5 | ||
|
||
|
||
|
||
# Fork Choice | ||
# --------------------------------------------------------------- | ||
# 2**1 (= 1) | ||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED: 2 | ||
|
||
|
||
# Validator | ||
# --------------------------------------------------------------- | ||
# [customized] process deposits more quickly, but insecure | ||
ETH1_FOLLOW_DISTANCE: 16 | ||
# 2**4 (= 16) | ||
TARGET_AGGREGATORS_PER_COMMITTEE: 16 | ||
# 2**0 (= 1) | ||
RANDOM_SUBNETS_PER_VALIDATOR: 1 | ||
# 2**8 (= 256) | ||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION: 256 | ||
# 14 (estimate from Eth1 mainnet) | ||
SECONDS_PER_ETH1_BLOCK: 14 | ||
|
||
|
||
# Deposit contract | ||
# --------------------------------------------------------------- | ||
# Ethereum Goerli testnet | ||
DEPOSIT_CHAIN_ID: 5 | ||
DEPOSIT_NETWORK_ID: 5 | ||
# **TBD** | ||
DEPOSIT_CONTRACT_ADDRESS: 0x1234567890123456789012345678901234567890 | ||
|
||
|
||
# Gwei values | ||
# --------------------------------------------------------------- | ||
# 2**0 * 10**9 (= 1,000,000,000) Gwei | ||
MIN_DEPOSIT_AMOUNT: 1000000000 | ||
# 2**5 * 10**9 (= 32,000,000,000) Gwei | ||
MAX_EFFECTIVE_BALANCE: 32000000000 | ||
# 2**4 * 10**9 (= 16,000,000,000) Gwei | ||
EJECTION_BALANCE: 16000000000 | ||
# 2**0 * 10**9 (= 1,000,000,000) Gwei | ||
EFFECTIVE_BALANCE_INCREMENT: 1000000000 | ||
|
||
|
||
# Initial values | ||
# --------------------------------------------------------------- | ||
# Highest byte set to 0x01 to avoid collisions with mainnet versioning | ||
GENESIS_FORK_VERSION: 0x00000001 | ||
BLS_WITHDRAWAL_PREFIX: 0x00 | ||
|
||
|
||
# Time parameters | ||
# --------------------------------------------------------------- | ||
# [customized] Faster to spin up testnets, but does not give validator reasonable warning time for genesis | ||
GENESIS_DELAY: 300 | ||
# [customized] Faster for testing purposes | ||
SECONDS_PER_SLOT: 6 | ||
# 2**0 (= 1) slots 6 seconds | ||
MIN_ATTESTATION_INCLUSION_DELAY: 1 | ||
# [customized] fast epochs | ||
SLOTS_PER_EPOCH: 8 | ||
# 2**0 (= 1) epochs | ||
MIN_SEED_LOOKAHEAD: 1 | ||
# 2**2 (= 4) epochs | ||
MAX_SEED_LOOKAHEAD: 4 | ||
# [customized] higher frequency new deposits from eth1 for testing | ||
EPOCHS_PER_ETH1_VOTING_PERIOD: 4 | ||
# [customized] smaller state | ||
SLOTS_PER_HISTORICAL_ROOT: 64 | ||
# 2**8 (= 256) epochs | ||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY: 256 | ||
# [customized] higher frequency of committee turnover and faster time to acceptable voluntary exit | ||
SHARD_COMMITTEE_PERIOD: 64 | ||
# [customized] fast catchup crosslinks | ||
MAX_EPOCHS_PER_CROSSLINK: 4 | ||
# 2**2 (= 4) epochs | ||
MIN_EPOCHS_TO_INACTIVITY_PENALTY: 4 | ||
|
||
|
||
# State vector lengths | ||
# --------------------------------------------------------------- | ||
# [customized] smaller state | ||
EPOCHS_PER_HISTORICAL_VECTOR: 64 | ||
# [customized] smaller state | ||
EPOCHS_PER_SLASHINGS_VECTOR: 64 | ||
# 2**24 (= 16,777,216) historical roots | ||
HISTORICAL_ROOTS_LIMIT: 16777216 | ||
# 2**40 (= 1,099,511,627,776) validator spots | ||
VALIDATOR_REGISTRY_LIMIT: 1099511627776 | ||
|
||
|
||
# Reward and penalty quotients | ||
# --------------------------------------------------------------- | ||
# 2**6 (= 64) | ||
BASE_REWARD_FACTOR: 64 | ||
# 2**9 (= 512) | ||
WHISTLEBLOWER_REWARD_QUOTIENT: 512 | ||
# 2**3 (= 8) | ||
PROPOSER_REWARD_QUOTIENT: 8 | ||
# 2**24 (= 16,777,216) | ||
INACTIVITY_PENALTY_QUOTIENT: 16777216 | ||
# 2**5 (= 32) | ||
MIN_SLASHING_PENALTY_QUOTIENT: 32 | ||
|
||
|
||
# Max operations per block | ||
# --------------------------------------------------------------- | ||
# 2**4 (= 16) | ||
MAX_PROPOSER_SLASHINGS: 16 | ||
# 2**1 (= 2) | ||
MAX_ATTESTER_SLASHINGS: 2 | ||
# 2**7 (= 128) | ||
MAX_ATTESTATIONS: 128 | ||
# 2**4 (= 16) | ||
MAX_DEPOSITS: 16 | ||
# 2**4 (= 16) | ||
MAX_VOLUNTARY_EXITS: 16 | ||
|
||
|
||
# Signature domains | ||
# --------------------------------------------------------------- | ||
DOMAIN_BEACON_PROPOSER: 0x00000000 | ||
DOMAIN_BEACON_ATTESTER: 0x01000000 | ||
DOMAIN_RANDAO: 0x02000000 | ||
DOMAIN_DEPOSIT: 0x03000000 | ||
DOMAIN_VOLUNTARY_EXIT: 0x04000000 | ||
DOMAIN_SELECTION_PROOF: 0x05000000 | ||
DOMAIN_AGGREGATE_AND_PROOF: 0x06000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from enum import auto, Enum | ||
|
||
|
||
class BeaconState(Enum): | ||
DEFAULT = auto() | ||
|
||
|
||
# NOTE: when network_config is specifiable, it needs to be an arg here | ||
def default_builder(): | ||
from eth2spec.config.config_util import prepare_config | ||
prepare_config('config', 'minimal') | ||
|
||
from eth2spec.phase0.spec import initialize_beacon_state_from_eth1 | ||
from eth2spec.test.helpers.deposits import prepare_genesis_deposits | ||
|
||
import eth2fastspec as spec | ||
|
||
deposits, deposit_root, _ = prepare_genesis_deposits( | ||
spec, spec.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT, spec.MAX_EFFECTIVE_BALANCE, signed=True) | ||
|
||
eth1_block_hash = b'\x12' * 32 | ||
eth1_timestamp = spec.MIN_GENESIS_TIME | ||
state = initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits) | ||
|
||
os.makedirs(os.path.dirname(path), exist_ok=True) | ||
with open(path, 'wb') as w: | ||
state.serialize(w) | ||
|
||
return state | ||
|
||
|
||
BEACON_STATE_BUILDERS = { | ||
BeaconState.DEFAULT: default_builder | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters