Restore compilation with custom presets (#1309)
This also assigns precise types to the constants in the minimal and mainnet presets in order to reduce the chance of compilation errors when custom presets are used (previously, only the custom presets have precisely assigned types for the constants).
This commit is contained in:
parent
b01be646cf
commit
0be77f9cbc
|
@ -218,6 +218,11 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
|
|||
+ simple object fields OK
|
||||
```
|
||||
OK: 3/3 Fail: 0/3 Skip: 0/3
|
||||
## Spec datatypes
|
||||
```diff
|
||||
+ Graffiti bytes OK
|
||||
```
|
||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||
## Spec helpers
|
||||
```diff
|
||||
+ integer_squareroot OK
|
||||
|
@ -267,4 +272,4 @@ OK: 8/8 Fail: 0/8 Skip: 0/8
|
|||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||
|
||||
---TOTAL---
|
||||
OK: 157/165 Fail: 0/165 Skip: 8/165
|
||||
OK: 158/166 Fail: 0/166 Skip: 8/166
|
||||
|
|
|
@ -23,7 +23,7 @@ func is_aggregator(state: BeaconState, slot: Slot, index: CommitteeIndex,
|
|||
slot_signature: ValidatorSig, cache: var StateCache): bool =
|
||||
let
|
||||
committee = get_beacon_committee(state, slot, index, cache)
|
||||
modulo = max(1, len(committee) div TARGET_AGGREGATORS_PER_COMMITTEE).uint64
|
||||
modulo = max(1'u64, len(committee).uint64 div TARGET_AGGREGATORS_PER_COMMITTEE)
|
||||
bytes_to_int(eth2digest(slot_signature.toRaw()).data[0..7]) mod modulo == 0
|
||||
|
||||
proc aggregate_attestations*(
|
||||
|
|
|
@ -501,7 +501,7 @@ proc getAttestationsForBlock*(pool: AttestationPool,
|
|||
|
||||
result.add(attestation)
|
||||
|
||||
if result.len >= MAX_ATTESTATIONS:
|
||||
if result.len >= MAX_ATTESTATIONS.int:
|
||||
debug "getAttestationsForBlock: returning early after hitting MAX_ATTESTATIONS",
|
||||
attestationSlot = newBlockSlot - 1
|
||||
return
|
||||
|
|
|
@ -728,7 +728,7 @@ proc installDebugApiHandlers(rpcServer: RpcServer, node: BeaconNode) =
|
|||
settingSym = ident($presetValue)
|
||||
settingKey = newLit(toLowerAscii($presetValue))
|
||||
let f = quote do:
|
||||
res[`settingKey`] = %`settingSym`
|
||||
res[`settingKey`] = %(presets.`settingSym`)
|
||||
yield f
|
||||
|
||||
for field, value in fieldPairs(node.config.runtimePreset):
|
||||
|
|
|
@ -113,12 +113,10 @@ func compute_activation_exit_epoch(epoch: Epoch): Epoch =
|
|||
epoch + 1 + MAX_SEED_LOOKAHEAD
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_validator_churn_limit
|
||||
func get_validator_churn_limit(state: BeaconState, cache: var StateCache):
|
||||
uint64 =
|
||||
func get_validator_churn_limit(state: BeaconState, cache: var StateCache): uint64 =
|
||||
# Return the validator churn limit for the current epoch.
|
||||
max(MIN_PER_EPOCH_CHURN_LIMIT,
|
||||
len(cache.shuffled_active_validator_indices) div
|
||||
CHURN_LIMIT_QUOTIENT).uint64
|
||||
len(cache.shuffled_active_validator_indices).uint64 div CHURN_LIMIT_QUOTIENT)
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#initiate_validator_exit
|
||||
func initiate_validator_exit*(state: var BeaconState,
|
||||
|
@ -222,7 +220,7 @@ proc initialize_beacon_state_from_eth1*(
|
|||
# validators - there needs to be at least one member in each committee -
|
||||
# good to know for testing, though arguably the system is not that useful at
|
||||
# at that point :)
|
||||
doAssert deposits.len >= SLOTS_PER_EPOCH
|
||||
doAssert deposits.len >= SLOTS_PER_EPOCH.int
|
||||
|
||||
var state = BeaconStateRef(
|
||||
fork: Fork(
|
||||
|
@ -481,7 +479,7 @@ func get_indexed_attestation*(state: BeaconState, attestation: Attestation,
|
|||
|
||||
IndexedAttestation(
|
||||
attesting_indices:
|
||||
List[uint64, MAX_VALIDATORS_PER_COMMITTEE].init(
|
||||
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE].init(
|
||||
sorted(mapIt(attesting_indices.toSeq, it.uint64), system.cmp)),
|
||||
data: attestation.data,
|
||||
signature: attestation.signature
|
||||
|
@ -497,7 +495,7 @@ func get_indexed_attestation*(state: BeaconState, attestation: TrustedAttestatio
|
|||
|
||||
TrustedIndexedAttestation(
|
||||
attesting_indices:
|
||||
List[uint64, MAX_VALIDATORS_PER_COMMITTEE].init(
|
||||
List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE].init(
|
||||
sorted(mapIt(attesting_indices.toSeq, it.uint64), system.cmp)),
|
||||
data: attestation.data,
|
||||
signature: attestation.signature
|
||||
|
|
|
@ -51,7 +51,7 @@ const
|
|||
## Spec version we're aiming to be compatible with, right now
|
||||
|
||||
GENESIS_SLOT* = Slot(0)
|
||||
GENESIS_EPOCH* = (GENESIS_SLOT.int div SLOTS_PER_EPOCH).Epoch ##\
|
||||
GENESIS_EPOCH* = (GENESIS_SLOT.uint64 div SLOTS_PER_EPOCH).Epoch ##\
|
||||
## compute_epoch_at_slot(GENESIS_SLOT)
|
||||
|
||||
FAR_FUTURE_EPOCH* = (not 0'u64).Epoch # 2^64 - 1 in spec
|
||||
|
@ -123,17 +123,17 @@ type
|
|||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#indexedattestation
|
||||
IndexedAttestation* = object
|
||||
# TODO ValidatorIndex, but that doesn't serialize properly
|
||||
attesting_indices*: List[uint64, MAX_VALIDATORS_PER_COMMITTEE]
|
||||
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||
data*: AttestationData
|
||||
signature*: ValidatorSig
|
||||
|
||||
TrustedIndexedAttestation* = object
|
||||
# TODO ValidatorIndex, but that doesn't serialize properly
|
||||
attesting_indices*: List[uint64, MAX_VALIDATORS_PER_COMMITTEE]
|
||||
attesting_indices*: List[uint64, Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||
data*: AttestationData
|
||||
signature*: TrustedSig
|
||||
|
||||
CommitteeValidatorsBits* = BitList[MAX_VALIDATORS_PER_COMMITTEE]
|
||||
CommitteeValidatorsBits* = BitList[Limit MAX_VALIDATORS_PER_COMMITTEE]
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#attestation
|
||||
Attestation* = object
|
||||
|
@ -266,11 +266,11 @@ type
|
|||
graffiti*: GraffitiBytes
|
||||
|
||||
# Operations
|
||||
proposer_slashings*: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS]
|
||||
attester_slashings*: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS]
|
||||
attestations*: List[Attestation, MAX_ATTESTATIONS]
|
||||
deposits*: List[Deposit, MAX_DEPOSITS]
|
||||
voluntary_exits*: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
|
||||
proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
|
||||
attester_slashings*: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
|
||||
attestations*: List[Attestation, Limit MAX_ATTESTATIONS]
|
||||
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
||||
voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
||||
|
||||
TrustedBeaconBlockBody* = object
|
||||
randao_reveal*: TrustedSig
|
||||
|
@ -278,11 +278,11 @@ type
|
|||
graffiti*: GraffitiBytes
|
||||
|
||||
# Operations
|
||||
proposer_slashings*: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS]
|
||||
attester_slashings*: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS]
|
||||
attestations*: List[TrustedAttestation, MAX_ATTESTATIONS]
|
||||
deposits*: List[Deposit, MAX_DEPOSITS]
|
||||
voluntary_exits*: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
|
||||
proposer_slashings*: List[ProposerSlashing, Limit MAX_PROPOSER_SLASHINGS]
|
||||
attester_slashings*: List[AttesterSlashing, Limit MAX_ATTESTER_SLASHINGS]
|
||||
attestations*: List[TrustedAttestation, Limit MAX_ATTESTATIONS]
|
||||
deposits*: List[Deposit, Limit MAX_DEPOSITS]
|
||||
voluntary_exits*: List[SignedVoluntaryExit, Limit MAX_VOLUNTARY_EXITS]
|
||||
|
||||
SomeSignedBeaconBlock* = SignedBeaconBlock | TrustedSignedBeaconBlock
|
||||
SomeBeaconBlock* = BeaconBlock | TrustedBeaconBlock
|
||||
|
@ -302,34 +302,34 @@ type
|
|||
latest_block_header*: BeaconBlockHeader ##\
|
||||
## `latest_block_header.state_root == ZERO_HASH` temporarily
|
||||
|
||||
block_roots*: HashArray[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
||||
block_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest] ##\
|
||||
## Needed to process attestations, older to newer
|
||||
|
||||
state_roots*: HashArray[SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||
historical_roots*: HashList[Eth2Digest, HISTORICAL_ROOTS_LIMIT]
|
||||
state_roots*: HashArray[Limit SLOTS_PER_HISTORICAL_ROOT, Eth2Digest]
|
||||
historical_roots*: HashList[Eth2Digest, Limit HISTORICAL_ROOTS_LIMIT]
|
||||
|
||||
# Eth1
|
||||
eth1_data*: Eth1Data
|
||||
eth1_data_votes*:
|
||||
HashList[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH]
|
||||
HashList[Eth1Data, Limit(EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH)]
|
||||
eth1_deposit_index*: uint64
|
||||
|
||||
# Registry
|
||||
validators*: HashList[Validator, VALIDATOR_REGISTRY_LIMIT]
|
||||
balances*: HashList[uint64, VALIDATOR_REGISTRY_LIMIT]
|
||||
validators*: HashList[Validator, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||
balances*: HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]
|
||||
|
||||
# Randomness
|
||||
randao_mixes*: HashArray[EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
||||
randao_mixes*: HashArray[Limit EPOCHS_PER_HISTORICAL_VECTOR, Eth2Digest]
|
||||
|
||||
# Slashings
|
||||
slashings*: HashArray[int64(EPOCHS_PER_SLASHINGS_VECTOR), uint64] ##\
|
||||
slashings*: HashArray[Limit EPOCHS_PER_SLASHINGS_VECTOR, uint64] ##\
|
||||
## Per-epoch sums of slashed effective balances
|
||||
|
||||
# Attestations
|
||||
previous_epoch_attestations*:
|
||||
HashList[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH]
|
||||
HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)]
|
||||
current_epoch_attestations*:
|
||||
HashList[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH]
|
||||
HashList[PendingAttestation, Limit(MAX_ATTESTATIONS * SLOTS_PER_EPOCH)]
|
||||
|
||||
# Finality
|
||||
justification_bits*: uint8 ##\
|
||||
|
|
|
@ -65,8 +65,7 @@ func get_active_validator_indices*(state: BeaconState, epoch: Epoch):
|
|||
result.add idx.ValidatorIndex
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_committee_count_at_slot
|
||||
func get_committee_count_at_slot*(num_active_validators: auto):
|
||||
uint64 =
|
||||
func get_committee_count_at_slot*(num_active_validators: Slot): uint64 =
|
||||
clamp(
|
||||
num_active_validators div SLOTS_PER_EPOCH div TARGET_COMMITTEE_SIZE,
|
||||
1, MAX_COMMITTEES_PER_SLOT).uint64
|
||||
|
@ -80,7 +79,7 @@ func get_committee_count_at_slot*(state: BeaconState, slot: Slot): uint64 =
|
|||
# CommitteeIndex return type here.
|
||||
let epoch = compute_epoch_at_slot(slot)
|
||||
let active_validator_indices = get_active_validator_indices(state, epoch)
|
||||
result = get_committee_count_at_slot(len(active_validator_indices))
|
||||
result = get_committee_count_at_slot(len(active_validator_indices).uint64.Slot)
|
||||
|
||||
# Otherwise, get_beacon_committee(...) cannot access some committees.
|
||||
doAssert (SLOTS_PER_EPOCH * MAX_COMMITTEES_PER_SLOT).uint64 >= result
|
||||
|
@ -94,8 +93,8 @@ func get_current_epoch*(state: BeaconState): Epoch =
|
|||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#get_randao_mix
|
||||
func get_randao_mix*(state: BeaconState,
|
||||
epoch: Epoch): Eth2Digest =
|
||||
## Returns the randao mix at a recent ``epoch``.
|
||||
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
|
||||
## Returns the randao mix at a recent ``epoch``.
|
||||
state.randao_mixes[epoch mod EPOCHS_PER_HISTORICAL_VECTOR]
|
||||
|
||||
func bytes_to_int*(data: openarray[byte]): uint64 =
|
||||
doAssert data.len == 8
|
||||
|
|
|
@ -70,7 +70,7 @@ func compute_subnet_for_attestation*(
|
|||
let
|
||||
slots_since_epoch_start = attestation.data.slot mod SLOTS_PER_EPOCH
|
||||
committees_since_epoch_start =
|
||||
get_committee_count_at_slot(num_active_validators) * slots_since_epoch_start
|
||||
get_committee_count_at_slot(num_active_validators.Slot) * slots_since_epoch_start
|
||||
|
||||
(committees_since_epoch_start + attestation.data.index) mod ATTESTATION_SUBNET_COUNT
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
type
|
||||
PresetValue* {.pure.} = enum
|
||||
BASE_REWARD_FACTOR
|
||||
BLS_WITHDRAWAL_PREFIX
|
||||
CHURN_LIMIT_QUOTIENT
|
||||
DEPOSIT_CONTRACT_ADDRESS
|
||||
DOMAIN_AGGREGATE_AND_PROOF
|
||||
DOMAIN_BEACON_ATTESTER
|
||||
DOMAIN_BEACON_PROPOSER
|
||||
DOMAIN_DEPOSIT
|
||||
DOMAIN_RANDAO
|
||||
DOMAIN_SELECTION_PROOF
|
||||
DOMAIN_VOLUNTARY_EXIT
|
||||
EFFECTIVE_BALANCE_INCREMENT
|
||||
EJECTION_BALANCE
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD
|
||||
EPOCHS_PER_HISTORICAL_VECTOR
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION
|
||||
EPOCHS_PER_SLASHINGS_VECTOR
|
||||
ETH1_FOLLOW_DISTANCE
|
||||
GENESIS_FORK_VERSION
|
||||
GENESIS_DELAY
|
||||
HISTORICAL_ROOTS_LIMIT
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER
|
||||
HYSTERESIS_QUOTIENT
|
||||
HYSTERESIS_UPWARD_MULTIPLIER
|
||||
INACTIVITY_PENALTY_QUOTIENT
|
||||
MAX_ATTESTATIONS
|
||||
MAX_ATTESTER_SLASHINGS
|
||||
MAX_COMMITTEES_PER_SLOT
|
||||
MAX_DEPOSITS
|
||||
MAX_EFFECTIVE_BALANCE
|
||||
MAX_EPOCHS_PER_CROSSLINK
|
||||
MAX_PROPOSER_SLASHINGS
|
||||
MAX_SEED_LOOKAHEAD
|
||||
MAX_VALIDATORS_PER_COMMITTEE
|
||||
MAX_VOLUNTARY_EXITS
|
||||
MIN_ATTESTATION_INCLUSION_DELAY
|
||||
MIN_DEPOSIT_AMOUNT
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||
MIN_GENESIS_TIME
|
||||
MIN_PER_EPOCH_CHURN_LIMIT
|
||||
MIN_SEED_LOOKAHEAD
|
||||
MIN_SLASHING_PENALTY_QUOTIENT
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||
PROPOSER_REWARD_QUOTIENT
|
||||
RANDOM_SUBNETS_PER_VALIDATOR
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED
|
||||
SECONDS_PER_ETH1_BLOCK
|
||||
SECONDS_PER_SLOT
|
||||
SHARD_COMMITTEE_PERIOD
|
||||
SHUFFLE_ROUND_COUNT
|
||||
SLOTS_PER_EPOCH
|
||||
SLOTS_PER_HISTORICAL_ROOT
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE
|
||||
TARGET_COMMITTEE_SIZE
|
||||
VALIDATOR_REGISTRY_LIMIT
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT
|
||||
|
|
@ -1,77 +1,18 @@
|
|||
import
|
||||
macros, strutils, parseutils, tables,
|
||||
stew/endians2
|
||||
stew/endians2,
|
||||
preset_values
|
||||
|
||||
{.push raises: [Defect].}
|
||||
|
||||
export
|
||||
toBytesBE
|
||||
PresetValue, toBytesBE
|
||||
|
||||
type
|
||||
Slot* = distinct uint64
|
||||
Epoch* = distinct uint64
|
||||
Version* = distinct array[4, byte]
|
||||
|
||||
PresetValue* {.pure.} = enum
|
||||
BASE_REWARD_FACTOR
|
||||
BLS_WITHDRAWAL_PREFIX
|
||||
CHURN_LIMIT_QUOTIENT
|
||||
DEPOSIT_CONTRACT_ADDRESS
|
||||
DOMAIN_AGGREGATE_AND_PROOF
|
||||
DOMAIN_BEACON_ATTESTER
|
||||
DOMAIN_BEACON_PROPOSER
|
||||
DOMAIN_DEPOSIT
|
||||
DOMAIN_RANDAO
|
||||
DOMAIN_SELECTION_PROOF
|
||||
DOMAIN_VOLUNTARY_EXIT
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE
|
||||
EFFECTIVE_BALANCE_INCREMENT
|
||||
EJECTION_BALANCE
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD
|
||||
EPOCHS_PER_HISTORICAL_VECTOR
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION
|
||||
EPOCHS_PER_SLASHINGS_VECTOR
|
||||
ETH1_FOLLOW_DISTANCE
|
||||
GENESIS_FORK_VERSION
|
||||
GENESIS_DELAY
|
||||
HISTORICAL_ROOTS_LIMIT
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER
|
||||
HYSTERESIS_QUOTIENT
|
||||
HYSTERESIS_UPWARD_MULTIPLIER
|
||||
INACTIVITY_PENALTY_QUOTIENT
|
||||
MAX_ATTESTATIONS
|
||||
MAX_ATTESTER_SLASHINGS
|
||||
MAX_COMMITTEES_PER_SLOT
|
||||
MAX_DEPOSITS
|
||||
MAX_EFFECTIVE_BALANCE
|
||||
MAX_EPOCHS_PER_CROSSLINK
|
||||
MAX_PROPOSER_SLASHINGS
|
||||
MAX_SEED_LOOKAHEAD
|
||||
MAX_VALIDATORS_PER_COMMITTEE
|
||||
MAX_VOLUNTARY_EXITS
|
||||
MIN_ATTESTATION_INCLUSION_DELAY
|
||||
MIN_DEPOSIT_AMOUNT
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY
|
||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
|
||||
MIN_GENESIS_TIME
|
||||
MIN_PER_EPOCH_CHURN_LIMIT
|
||||
MIN_SEED_LOOKAHEAD
|
||||
MIN_SLASHING_PENALTY_QUOTIENT
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||
PROPOSER_REWARD_QUOTIENT
|
||||
RANDOM_SUBNETS_PER_VALIDATOR
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED
|
||||
SECONDS_PER_ETH1_BLOCK
|
||||
SECONDS_PER_SLOT
|
||||
SHARD_COMMITTEE_PERIOD
|
||||
SHUFFLE_ROUND_COUNT
|
||||
SLOTS_PER_EPOCH
|
||||
SLOTS_PER_HISTORICAL_ROOT
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE
|
||||
TARGET_COMMITTEE_SIZE
|
||||
VALIDATOR_REGISTRY_LIMIT
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT
|
||||
|
||||
RuntimePreset* = object
|
||||
GENESIS_FORK_VERSION*: Version
|
||||
GENESIS_DELAY*: uint64
|
||||
|
@ -132,10 +73,6 @@ func parse*(T: type uint64, input: string): T
|
|||
template parse*(T: type byte, input: string): T =
|
||||
byte parse(uint64, input)
|
||||
|
||||
template parse*(T: type int, input: string): T =
|
||||
# TODO: remove this
|
||||
int parse(uint64, input)
|
||||
|
||||
proc parse*(T: type Version, input: string): T
|
||||
{.raises: [ValueError, Defect].} =
|
||||
Version toBytesBE(uint32 parse(uint64, input))
|
||||
|
@ -215,12 +152,14 @@ else:
|
|||
return
|
||||
|
||||
for name, value in preset.values:
|
||||
var value = string value
|
||||
if presetValueTypes.hasKey(name):
|
||||
let typ = presetValueTypes[name]
|
||||
value = typ & "(" & value & ")"
|
||||
|
||||
result.add parseStmt("const $1* {.intdefine.} = $2" % [$name, value])
|
||||
let
|
||||
typ = getType(name)
|
||||
value = if typ in ["int64", "uint64", "byte"]: typ & "(" & value & ")"
|
||||
else: "parse(" & typ & ", \"" & value & "\")"
|
||||
try:
|
||||
result.add parseStmt("const $1* {.intdefine.} = $2" % [$name, value])
|
||||
except ValueError:
|
||||
doAssert false, "All values in the presets are printable"
|
||||
|
||||
if preset.missingValues.card > 0:
|
||||
warning "Missing constants in preset: " & $preset.missingValues
|
||||
|
|
|
@ -18,9 +18,9 @@ const
|
|||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L6
|
||||
|
||||
MAX_COMMITTEES_PER_SLOT* {.intdefine.} = 64
|
||||
MAX_COMMITTEES_PER_SLOT* {.intdefine.}: uint64 = 64
|
||||
|
||||
TARGET_COMMITTEE_SIZE* = 128 ##\
|
||||
TARGET_COMMITTEE_SIZE*: uint64 = 128 ##\
|
||||
## Number of validators in the committee attesting to one shard
|
||||
## Per spec:
|
||||
## For the safety of crosslinks `TARGET_COMMITTEE_SIZE` exceeds
|
||||
|
@ -31,46 +31,46 @@ const
|
|||
## with a Verifiable Delay Function (VDF) will improve committee robustness
|
||||
## and lower the safe minimum committee size.)
|
||||
|
||||
MAX_VALIDATORS_PER_COMMITTEE* = 2048 ##\
|
||||
MAX_VALIDATORS_PER_COMMITTEE*: uint64 = 2048 ##\
|
||||
## votes
|
||||
|
||||
MIN_PER_EPOCH_CHURN_LIMIT* = 4
|
||||
CHURN_LIMIT_QUOTIENT* = 2^16
|
||||
SHUFFLE_ROUND_COUNT* = 90
|
||||
MIN_PER_EPOCH_CHURN_LIMIT*: uint64 = 4
|
||||
CHURN_LIMIT_QUOTIENT*: uint64 = 2'u64 ^ 16
|
||||
SHUFFLE_ROUND_COUNT*: uint64 = 90
|
||||
|
||||
HYSTERESIS_QUOTIENT* = 4
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
|
||||
HYSTERESIS_UPWARD_MULTIPLIER* = 5
|
||||
HYSTERESIS_QUOTIENT*: uint64 = 4
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER*: uint64 = 1
|
||||
HYSTERESIS_UPWARD_MULTIPLIER*: uint64 = 5
|
||||
|
||||
# Gwei values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L58
|
||||
|
||||
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9 ##\
|
||||
MIN_DEPOSIT_AMOUNT*: uint64 = 2'u64^0 * 10'u64^9 ##\
|
||||
## Minimum amounth of ETH that can be deposited in one call - deposits can
|
||||
## be used either to top up an existing validator or commit to a new one
|
||||
|
||||
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9 ##\
|
||||
MAX_EFFECTIVE_BALANCE*: uint64 = 2'u64^5 * 10'u64^9 ##\
|
||||
## Maximum amounth of ETH that can be deposited in one call
|
||||
|
||||
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9 ##\
|
||||
EJECTION_BALANCE*: uint64 = 2'u64^4 * 10'u64^9 ##\
|
||||
## Once the balance of a validator drops below this, it will be ejected from
|
||||
## the validator pool
|
||||
|
||||
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
|
||||
EFFECTIVE_BALANCE_INCREMENT*: uint64 = 2'u64^0 * 10'u64^9
|
||||
|
||||
# Initial values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L70
|
||||
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||
BLS_WITHDRAWAL_PREFIX*: byte = 0
|
||||
|
||||
# Time parameters
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L77
|
||||
SECONDS_PER_SLOT* {.intdefine.} = 12'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 12x faster slots
|
||||
SECONDS_PER_SLOT* {.intdefine.}: uint64 = 12'u64 # Compile with -d:SECONDS_PER_SLOT=1 for 12x faster slots
|
||||
## TODO consistent time unit across projects, similar to C++ chrono?
|
||||
|
||||
MIN_ATTESTATION_INCLUSION_DELAY* = 1 ##\
|
||||
MIN_ATTESTATION_INCLUSION_DELAY*: uint64 = 1 ##\
|
||||
## (12 seconds)
|
||||
## Number of slots that attestations stay in the attestation
|
||||
## pool before being added to a block.
|
||||
|
@ -82,118 +82,118 @@ const
|
|||
## wait towards the end of the slot and still have time to publish the
|
||||
## attestation.
|
||||
|
||||
SLOTS_PER_EPOCH* {.intdefine.} = 32 ##\
|
||||
SLOTS_PER_EPOCH* {.intdefine.}: uint64 = 32 ##\
|
||||
## (~6.4 minutes)
|
||||
## slots that make up an epoch, at the end of which more heavy
|
||||
## processing is done
|
||||
## Compile with -d:SLOTS_PER_EPOCH=4 for shorter epochs
|
||||
|
||||
MIN_SEED_LOOKAHEAD* = 1 ##\
|
||||
MIN_SEED_LOOKAHEAD*: uint64 = 1 ##\
|
||||
## epochs (~6.4 minutes)
|
||||
|
||||
MAX_SEED_LOOKAHEAD* = 4 ##\
|
||||
MAX_SEED_LOOKAHEAD*: uint64 = 4 ##\
|
||||
## epochs (~25.6 minutes)
|
||||
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD* = 32 ##\
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD*: uint64 = 32 ##\
|
||||
## epochs (~3.4 hours)
|
||||
|
||||
SLOTS_PER_HISTORICAL_ROOT* = 8192 ##\
|
||||
SLOTS_PER_HISTORICAL_ROOT*: uint64 = 8192 ##\
|
||||
## slots (13 hours)
|
||||
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8 ##\
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY*: uint64 = 2'u64^8 ##\
|
||||
## epochs (~27 hours)
|
||||
|
||||
SHARD_COMMITTEE_PERIOD* = 256 # epochs (~27 hours)
|
||||
SHARD_COMMITTEE_PERIOD*: uint64 = 256 # epochs (~27 hours)
|
||||
|
||||
MAX_EPOCHS_PER_CROSSLINK* = 2'u64^6 ##\
|
||||
MAX_EPOCHS_PER_CROSSLINK*: uint64 = 2'u64^6 ##\
|
||||
## epochs (~7 hours)
|
||||
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY*: uint64 = 2'u64^2 ##\
|
||||
## epochs (25.6 minutes)
|
||||
|
||||
# State vector lengths
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L105
|
||||
|
||||
EPOCHS_PER_HISTORICAL_VECTOR* = 65536 ##\
|
||||
EPOCHS_PER_HISTORICAL_VECTOR*: uint64 = 65536 ##\
|
||||
## epochs (~0.8 years)
|
||||
|
||||
EPOCHS_PER_SLASHINGS_VECTOR* = 8192 ##\
|
||||
EPOCHS_PER_SLASHINGS_VECTOR*: uint64 = 8192 ##\
|
||||
## epochs (~36 days)
|
||||
|
||||
HISTORICAL_ROOTS_LIMIT* = 16777216 ##\
|
||||
HISTORICAL_ROOTS_LIMIT*: uint64 = 16777216 ##\
|
||||
## epochs (~26,131 years)
|
||||
|
||||
VALIDATOR_REGISTRY_LIMIT* = 1099511627776
|
||||
VALIDATOR_REGISTRY_LIMIT*: uint64 = 1099511627776'u64
|
||||
|
||||
# Reward and penalty quotients
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L117
|
||||
BASE_REWARD_FACTOR* = 2'u64^6
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
|
||||
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^24
|
||||
MIN_SLASHING_PENALTY_QUOTIENT* = 32 # 2^5
|
||||
BASE_REWARD_FACTOR*: uint64 = 2'u64^6
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT*: uint64 = 2'u64^9
|
||||
PROPOSER_REWARD_QUOTIENT*: uint64 = 2'u64^3
|
||||
INACTIVITY_PENALTY_QUOTIENT*: uint64 = 2'u64^24
|
||||
MIN_SLASHING_PENALTY_QUOTIENT*: uint64 = 32 # 2^5
|
||||
|
||||
# Max operations per block
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L131
|
||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||
MAX_ATTESTER_SLASHINGS* = 2^1
|
||||
MAX_ATTESTATIONS* = 2^7
|
||||
MAX_DEPOSITS* = 2^4
|
||||
MAX_VOLUNTARY_EXITS* = 2^4
|
||||
MAX_PROPOSER_SLASHINGS*: uint64 = 2'u64 ^ 4
|
||||
MAX_ATTESTER_SLASHINGS*: uint64 = 2'u64 ^ 1
|
||||
MAX_ATTESTATIONS*: uint64 = 2'u64 ^ 7
|
||||
MAX_DEPOSITS*: uint64 = 2'u64 ^ 4
|
||||
MAX_VOLUNTARY_EXITS*: uint64 = 2'u64 ^ 4
|
||||
|
||||
# Fork choice
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L32
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 8 # 96 seconds
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED*: uint64 = 8 # 96 seconds
|
||||
|
||||
# Validators
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L38
|
||||
ETH1_FOLLOW_DISTANCE* {.intdefine.} = 1024 # blocks ~ 4 hours
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
||||
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION* = 256 # epochs ~ 27 hours
|
||||
SECONDS_PER_ETH1_BLOCK* {.intdefine.} = 14 # (estimate from Eth1 mainnet)
|
||||
ETH1_FOLLOW_DISTANCE* {.intdefine.}: uint64 = 1024 # blocks ~ 4 hours
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE*: uint64 = 16 # validators
|
||||
RANDOM_SUBNETS_PER_VALIDATOR*: uint64 = 1 # subnet
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64 = 256 # epochs ~ 27 hours
|
||||
SECONDS_PER_ETH1_BLOCK* {.intdefine.}: uint64 = 14 # (estimate from Eth1 mainnet)
|
||||
|
||||
# Phase 1: Upgrade from Phase 0
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L161
|
||||
PHASE_1_FORK_VERSION* = 1
|
||||
PHASE_1_GENESIS_SLOT* = 32 # [STUB]
|
||||
INITIAL_ACTIVE_SHARDS* = 64
|
||||
PHASE_1_FORK_VERSION*: uint64 = 1
|
||||
PHASE_1_GENESIS_SLOT*: uint64 = 32 # [STUB]
|
||||
INITIAL_ACTIVE_SHARDS*: uint64 = 64
|
||||
|
||||
# Phase 1: General
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L168
|
||||
MAX_SHARDS* = 1024
|
||||
ONLINE_PERIOD* = 8 # epochs (~51 min)
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||
LIGHT_CLIENT_COMMITTEE_PERIOD* = 256 # epochs (~27 hours)
|
||||
SHARD_BLOCK_CHUNK_SIZE* = 262144
|
||||
MAX_SHARD_BLOCK_CHUNKS* = 4
|
||||
TARGET_SHARD_BLOCK_SIZE* = 196608
|
||||
MAX_SHARD_BLOCKS_PER_ATTESTATION* = 12
|
||||
MAX_GASPRICE* = 16384 # Gwei
|
||||
MIN_GASPRICE* = 8 # Gwei
|
||||
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
||||
MAX_SHARDS*: uint64 = 1024
|
||||
ONLINE_PERIOD*: uint64 = 8 # epochs (~51 min)
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE*: uint64 = 128
|
||||
LIGHT_CLIENT_COMMITTEE_PERIOD*: uint64 = 256 # epochs (~27 hours)
|
||||
SHARD_BLOCK_CHUNK_SIZE*: uint64 = 262144
|
||||
MAX_SHARD_BLOCK_CHUNKS*: uint64 = 4
|
||||
TARGET_SHARD_BLOCK_SIZE*: uint64 = 196608
|
||||
MAX_SHARD_BLOCKS_PER_ATTESTATION*: uint64 = 12
|
||||
MAX_GASPRICE*: uint64 = 16384 # Gwei
|
||||
MIN_GASPRICE*: uint64 = 8 # Gwei
|
||||
GASPRICE_ADJUSTMENT_COEFFICIENT*: uint64 = 8
|
||||
|
||||
# Phase 1: Custody game
|
||||
# ---------------------------------------------------------------
|
||||
# Time parameters
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L199
|
||||
RANDAO_PENALTY_EPOCHS* = 2 # epochs (12.8 minutes)
|
||||
EPOCHS_PER_CUSTODY_PERIOD* = 2048 # epochs (~9 days)
|
||||
MAX_REVEAL_LATENESS_DECREMENT* = 128 # epochs (~14 hours)
|
||||
RANDAO_PENALTY_EPOCHS*: uint64 = 2 # epochs (12.8 minutes)
|
||||
EPOCHS_PER_CUSTODY_PERIOD*: uint64 = 2048 # epochs (~9 days)
|
||||
MAX_REVEAL_LATENESS_DECREMENT*: uint64 = 128 # epochs (~14 hours)
|
||||
|
||||
# Max operations
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L211
|
||||
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||
MAX_CUSTODY_SLASHINGS* = 1
|
||||
MAX_CUSTODY_KEY_REVEALS*: uint64 = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS*: uint64 = 1
|
||||
MAX_CUSTODY_SLASHINGS*: uint64 = 1
|
||||
|
||||
# Reward and penalty quotients
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/mainnet.yaml#L217
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||
MINOR_REWARD_QUOTIENT* = 256
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE*: uint64 = 2
|
||||
MINOR_REWARD_QUOTIENT*: uint64 = 256
|
||||
|
|
|
@ -19,37 +19,37 @@ const
|
|||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L4
|
||||
|
||||
# Changed
|
||||
MAX_COMMITTEES_PER_SLOT* = 4
|
||||
TARGET_COMMITTEE_SIZE* = 4
|
||||
MAX_COMMITTEES_PER_SLOT*: uint64 = 4
|
||||
TARGET_COMMITTEE_SIZE*: uint64 = 4
|
||||
|
||||
# Unchanged
|
||||
MAX_VALIDATORS_PER_COMMITTEE* = 2048
|
||||
MIN_PER_EPOCH_CHURN_LIMIT* = 4
|
||||
CHURN_LIMIT_QUOTIENT* = 2^16
|
||||
MAX_VALIDATORS_PER_COMMITTEE*: uint64 = 2048
|
||||
MIN_PER_EPOCH_CHURN_LIMIT*: uint64 = 4
|
||||
CHURN_LIMIT_QUOTIENT*: uint64 = 2'u64 ^ 16
|
||||
|
||||
# Changed
|
||||
SHUFFLE_ROUND_COUNT* = 10
|
||||
SHUFFLE_ROUND_COUNT*: uint64 = 10
|
||||
|
||||
# Unchanged
|
||||
HYSTERESIS_QUOTIENT* = 4
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER* = 1
|
||||
HYSTERESIS_UPWARD_MULTIPLIER* = 5
|
||||
HYSTERESIS_QUOTIENT*: uint64 = 4
|
||||
HYSTERESIS_DOWNWARD_MULTIPLIER*: uint64 = 1
|
||||
HYSTERESIS_UPWARD_MULTIPLIER*: uint64 = 5
|
||||
|
||||
# Gwei values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L58
|
||||
|
||||
# Unchanged
|
||||
MIN_DEPOSIT_AMOUNT* = 2'u64^0 * 10'u64^9
|
||||
MAX_EFFECTIVE_BALANCE* = 2'u64^5 * 10'u64^9
|
||||
EJECTION_BALANCE* = 2'u64^4 * 10'u64^9
|
||||
EFFECTIVE_BALANCE_INCREMENT* = 2'u64^0 * 10'u64^9
|
||||
MIN_DEPOSIT_AMOUNT*: uint64 = 2'u64^0 * 10'u64^9
|
||||
MAX_EFFECTIVE_BALANCE*: uint64 = 2'u64^5 * 10'u64^9
|
||||
EJECTION_BALANCE*: uint64 = 2'u64^4 * 10'u64^9
|
||||
EFFECTIVE_BALANCE_INCREMENT*: uint64 = 2'u64^0 * 10'u64^9
|
||||
|
||||
# Initial values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L70
|
||||
|
||||
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||
BLS_WITHDRAWAL_PREFIX*: byte = 0
|
||||
|
||||
# Time parameters
|
||||
# ---------------------------------------------------------------
|
||||
|
@ -58,122 +58,122 @@ const
|
|||
# reasonable warning time for genesis
|
||||
|
||||
# Unchanged
|
||||
SECONDS_PER_SLOT*{.intdefine.} = 6'u64
|
||||
SECONDS_PER_SLOT*{.intdefine.}: uint64 = 6
|
||||
|
||||
# Unchanged
|
||||
MIN_ATTESTATION_INCLUSION_DELAY* = 1
|
||||
MIN_ATTESTATION_INCLUSION_DELAY*: uint64 = 1
|
||||
|
||||
# Changed
|
||||
SLOTS_PER_EPOCH* {.intdefine.} = 8
|
||||
SLOTS_PER_EPOCH* {.intdefine.}: uint64 = 8
|
||||
|
||||
# Unchanged
|
||||
MIN_SEED_LOOKAHEAD* = 1
|
||||
MAX_SEED_LOOKAHEAD* = 4
|
||||
MIN_SEED_LOOKAHEAD*: uint64 = 1
|
||||
MAX_SEED_LOOKAHEAD*: uint64 = 4
|
||||
|
||||
# Changed
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD* = 4
|
||||
SLOTS_PER_HISTORICAL_ROOT* = 64
|
||||
EPOCHS_PER_ETH1_VOTING_PERIOD*: uint64 = 4
|
||||
SLOTS_PER_HISTORICAL_ROOT*: uint64 = 64
|
||||
|
||||
# Unchanged
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY* = 2'u64^8
|
||||
MIN_VALIDATOR_WITHDRAWABILITY_DELAY*: uint64 = 2'u64^8
|
||||
|
||||
SHARD_COMMITTEE_PERIOD* = 64 # epochs
|
||||
SHARD_COMMITTEE_PERIOD*: uint64 = 64 # epochs
|
||||
|
||||
# Unchanged
|
||||
MAX_EPOCHS_PER_CROSSLINK* = 4
|
||||
MAX_EPOCHS_PER_CROSSLINK*: uint64 = 4
|
||||
|
||||
# Changed
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY*: uint64 = 2'u64^2
|
||||
|
||||
# State vector lengths
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L105
|
||||
|
||||
# Changed
|
||||
EPOCHS_PER_HISTORICAL_VECTOR* = 64
|
||||
EPOCHS_PER_SLASHINGS_VECTOR* = 64
|
||||
EPOCHS_PER_HISTORICAL_VECTOR*: uint64 = 64
|
||||
EPOCHS_PER_SLASHINGS_VECTOR*: uint64 = 64
|
||||
|
||||
# Unchanged
|
||||
HISTORICAL_ROOTS_LIMIT* = 16777216
|
||||
VALIDATOR_REGISTRY_LIMIT* = 1099511627776
|
||||
HISTORICAL_ROOTS_LIMIT*: uint64 = 16777216
|
||||
VALIDATOR_REGISTRY_LIMIT*: uint64 = 1099511627776'u64
|
||||
|
||||
# Reward and penalty quotients
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L117
|
||||
|
||||
BASE_REWARD_FACTOR* = 2'u64^6
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT* = 2'u64^9
|
||||
PROPOSER_REWARD_QUOTIENT* = 2'u64^3
|
||||
INACTIVITY_PENALTY_QUOTIENT* = 2'u64^24
|
||||
MIN_SLASHING_PENALTY_QUOTIENT* = 32 # 2^5
|
||||
BASE_REWARD_FACTOR*: uint64 = 2'u64^6
|
||||
WHISTLEBLOWER_REWARD_QUOTIENT*: uint64 = 2'u64^9
|
||||
PROPOSER_REWARD_QUOTIENT*: uint64 = 2'u64^3
|
||||
INACTIVITY_PENALTY_QUOTIENT*: uint64 = 2'u64^24
|
||||
MIN_SLASHING_PENALTY_QUOTIENT*: uint64 = 32 # 2^5
|
||||
|
||||
# Max operations per block
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L131
|
||||
|
||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||
MAX_ATTESTER_SLASHINGS* = 2^1
|
||||
MAX_ATTESTATIONS* = 2^7
|
||||
MAX_DEPOSITS* = 2^4
|
||||
MAX_VOLUNTARY_EXITS* = 2^4
|
||||
MAX_PROPOSER_SLASHINGS*: uint64 = 2'u64 ^ 4
|
||||
MAX_ATTESTER_SLASHINGS*: uint64 = 2'u64 ^ 1
|
||||
MAX_ATTESTATIONS*: uint64 = 2'u64 ^ 7
|
||||
MAX_DEPOSITS*: uint64 = 2'u64 ^ 4
|
||||
MAX_VOLUNTARY_EXITS*: uint64 = 2'u64 ^ 4
|
||||
|
||||
# Fork choice
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L32
|
||||
|
||||
# Changed
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED* = 2
|
||||
SAFE_SLOTS_TO_UPDATE_JUSTIFIED*: uint64 = 2
|
||||
|
||||
# Validators
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L38
|
||||
|
||||
# Changed
|
||||
ETH1_FOLLOW_DISTANCE* {.intdefine.} = 16 # blocks
|
||||
ETH1_FOLLOW_DISTANCE* {.intdefine.}: uint64 = 16 # blocks
|
||||
|
||||
# Unchanged
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE* = 16 # validators
|
||||
RANDOM_SUBNETS_PER_VALIDATOR* = 1 # subnet
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION* = 256 # epochs ~ 27 hours
|
||||
SECONDS_PER_ETH1_BLOCK* {.intdefine.} = 14 # estimate from Eth1 mainnet)
|
||||
TARGET_AGGREGATORS_PER_COMMITTEE*: uint64 = 16 # validators
|
||||
RANDOM_SUBNETS_PER_VALIDATOR*: uint64 = 1 # subnet
|
||||
EPOCHS_PER_RANDOM_SUBNET_SUBSCRIPTION*: uint64 = 256 # epochs ~ 27 hours
|
||||
SECONDS_PER_ETH1_BLOCK* {.intdefine.}: uint64 = 14 # estimate from Eth1 mainnet)
|
||||
|
||||
# Phase 1: Upgrade from Phase 0
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L161
|
||||
PHASE_1_FORK_VERSION* = 16777217
|
||||
PHASE_1_GENESIS_SLOT* = 8
|
||||
INITIAL_ACTIVE_SHARDS* = 4
|
||||
PHASE_1_FORK_VERSION*: uint64 = 16777217
|
||||
PHASE_1_GENESIS_SLOT*: uint64 = 8
|
||||
INITIAL_ACTIVE_SHARDS*: uint64 = 4
|
||||
|
||||
# Phase 1: General
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L171
|
||||
MAX_SHARDS* = 8
|
||||
ONLINE_PERIOD* = 8 # epochs ~ 51 minutes
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE* = 128
|
||||
LIGHT_CLIENT_COMMITTEE_PERIOD* = 256 # epochs
|
||||
SHARD_BLOCK_CHUNK_SIZE* = 262144
|
||||
MAX_SHARD_BLOCK_CHUNKS* = 4
|
||||
TARGET_SHARD_BLOCK_SIZE* = 196608
|
||||
MAX_SHARD_BLOCKS_PER_ATTESTATION* = 12
|
||||
MAX_GASPRICE* = 16384 # Gwei
|
||||
MIN_GASPRICE* = 8 # Gwei
|
||||
GASPRICE_ADJUSTMENT_COEFFICIENT* = 8
|
||||
MAX_SHARDS*: uint64 = 8
|
||||
ONLINE_PERIOD*: uint64 = 8 # epochs ~ 51 minutes
|
||||
LIGHT_CLIENT_COMMITTEE_SIZE*: uint64 = 128
|
||||
LIGHT_CLIENT_COMMITTEE_PERIOD*: uint64 = 256 # epochs
|
||||
SHARD_BLOCK_CHUNK_SIZE*: uint64 = 262144
|
||||
MAX_SHARD_BLOCK_CHUNKS*: uint64 = 4
|
||||
TARGET_SHARD_BLOCK_SIZE*: uint64 = 196608
|
||||
MAX_SHARD_BLOCKS_PER_ATTESTATION*: uint64 = 12
|
||||
MAX_GASPRICE*: uint64 = 16384 # Gwei
|
||||
MIN_GASPRICE*: uint64 = 8 # Gwei
|
||||
GASPRICE_ADJUSTMENT_COEFFICIENT*: uint64 = 8
|
||||
|
||||
# Phase 1 - Custody game
|
||||
# ---------------------------------------------------------------
|
||||
# Time parameters
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L202
|
||||
RANDAO_PENALTY_EPOCHS* = 2
|
||||
EPOCHS_PER_CUSTODY_PERIOD* = 2048
|
||||
MAX_REVEAL_LATENESS_DECREMENT* = 128
|
||||
RANDAO_PENALTY_EPOCHS*: uint64 = 2
|
||||
EPOCHS_PER_CUSTODY_PERIOD*: uint64 = 2048
|
||||
MAX_REVEAL_LATENESS_DECREMENT*: uint64 = 128
|
||||
|
||||
# Max operations
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L214
|
||||
MAX_CUSTODY_KEY_REVEALS* = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS* = 1
|
||||
MAX_CUSTODY_SLASHINGS* = 1
|
||||
MAX_CUSTODY_KEY_REVEALS*: uint64 = 256
|
||||
MAX_EARLY_DERIVED_SECRET_REVEALS*: uint64 = 1
|
||||
MAX_CUSTODY_SLASHINGS*: uint64 = 1
|
||||
|
||||
# Reward and penalty quotients
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/configs/minimal.yaml#L220
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE* = 2
|
||||
MINOR_REWARD_QUOTIENT* = 256
|
||||
EARLY_DERIVED_SECRET_REVEAL_SLOT_REWARD_MULTIPLE*: uint64 = 2
|
||||
MINOR_REWARD_QUOTIENT*: uint64 = 256
|
||||
|
|
|
@ -293,8 +293,8 @@ proc makeBeaconBlock*(
|
|||
randao_reveal: randao_reveal,
|
||||
eth1_data: eth1data,
|
||||
graffiti: graffiti,
|
||||
attestations: List[Attestation, MAX_ATTESTATIONS](attestations),
|
||||
deposits: List[Deposit, MAX_DEPOSITS](deposits)))
|
||||
attestations: List[Attestation, Limit MAX_ATTESTATIONS](attestations),
|
||||
deposits: List[Deposit, Limit MAX_DEPOSITS](deposits)))
|
||||
|
||||
let ok = process_block(preset, state.data, blck, {skipBlsValidation}, cache)
|
||||
|
||||
|
|
|
@ -289,9 +289,9 @@ proc process_operations(preset: RuntimePreset,
|
|||
# Verify that outstanding deposits are processed up to the maximum number of
|
||||
# deposits
|
||||
let
|
||||
num_deposits = len(body.deposits).int64
|
||||
num_deposits = uint64 len(body.deposits)
|
||||
req_deposits = min(MAX_DEPOSITS,
|
||||
state.eth1_data.deposit_count.int64 - state.eth1_deposit_index.int64)
|
||||
state.eth1_data.deposit_count - state.eth1_deposit_index)
|
||||
if not (num_deposits == req_deposits):
|
||||
return err("incorrect number of deposits")
|
||||
|
||||
|
|
|
@ -488,7 +488,7 @@ func process_final_updates*(state: var BeaconState) {.nbench.}=
|
|||
get_randao_mix(state, current_epoch)
|
||||
|
||||
# Set historical root accumulator
|
||||
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH).uint64 == 0:
|
||||
if next_epoch mod (SLOTS_PER_HISTORICAL_ROOT div SLOTS_PER_EPOCH) == 0:
|
||||
# Equivalent to hash_tree_root(foo: HistoricalBatch), but without using
|
||||
# significant additional stack or heap.
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.12.1/specs/phase0/beacon-chain.md#historicalbatch
|
||||
|
|
|
@ -46,7 +46,7 @@ func get_shuffled_seq*(seed: Eth2Digest,
|
|||
pivot_buffer[0..31] = seed.data
|
||||
source_buffer[0..31] = seed.data
|
||||
|
||||
for round in 0 ..< SHUFFLE_ROUND_COUNT:
|
||||
for round in 0 ..< SHUFFLE_ROUND_COUNT.int:
|
||||
let round_bytes1 = int_to_bytes1(round)[0]
|
||||
pivot_buffer[32] = round_bytes1
|
||||
source_buffer[32] = round_bytes1
|
||||
|
@ -142,7 +142,7 @@ func get_beacon_committee*(
|
|||
|
||||
try:
|
||||
let committee_count = get_committee_count_at_slot(
|
||||
cache.shuffled_active_validator_indices[epoch].len)
|
||||
cache.shuffled_active_validator_indices[epoch].len.uint64.Slot)
|
||||
compute_committee(
|
||||
cache.shuffled_active_validator_indices[epoch],
|
||||
get_seed(state, epoch, DOMAIN_BEACON_ATTESTER),
|
||||
|
|
|
@ -70,7 +70,7 @@ proc `[]`[T, U, V](s: openArray[T], x: HSlice[U, V]) {.error:
|
|||
|
||||
template checkForForbiddenBits(ResulType: type,
|
||||
input: openarray[byte],
|
||||
expectedBits: static int) =
|
||||
expectedBits: static int64) =
|
||||
## This checks if the input contains any bits set above the maximum
|
||||
## sized allowed. We only need to check the last byte to verify this:
|
||||
const bitsInLastByte = (expectedBits mod 8)
|
||||
|
|
|
@ -278,7 +278,7 @@ func bitListHashTreeRoot(merkleizer: var SszChunksMerkleizer, x: BitSeq): Eth2Di
|
|||
let contentsHash = merkleizer.getFinalHash
|
||||
mixInLength contentsHash, x.len
|
||||
|
||||
func maxChunksCount(T: type, maxLen: int64): int64 =
|
||||
func maxChunksCount(T: type, maxLen: Limit): Limit =
|
||||
when T is BitList|BitArray:
|
||||
(maxLen + bitsPerChunk - 1) div bitsPerChunk
|
||||
elif T is array|List:
|
||||
|
@ -306,7 +306,7 @@ func hashTreeRootAux[T](x: T): Eth2Digest =
|
|||
pos += sizeof(E)
|
||||
else:
|
||||
trs "FIXED TYPE; USE CHUNK STREAM"
|
||||
var markleizer = createMerkleizer(maxChunksCount(T, x.len))
|
||||
var markleizer = createMerkleizer(maxChunksCount(T, Limit x.len))
|
||||
chunkedHashTreeRootForBasicTypes(markleizer, x)
|
||||
elif T is BitArray:
|
||||
hashTreeRootAux(x.bytes)
|
||||
|
@ -314,7 +314,7 @@ func hashTreeRootAux[T](x: T): Eth2Digest =
|
|||
trs "MERKLEIZING FIELDS"
|
||||
const totalFields = when T is array: len(x)
|
||||
else: totalSerializedFields(T)
|
||||
merkleizeFields(totalFields):
|
||||
merkleizeFields(Limit totalFields):
|
||||
x.enumerateSubFields(f):
|
||||
addField f
|
||||
#elif isCaseObject(T):
|
||||
|
|
|
@ -55,12 +55,12 @@ template chunkIdx*(T: type, dataIdx: int64): int64 =
|
|||
# Given a data index, which chunk does it belong to?
|
||||
dataIdx div dataPerChunk(T)
|
||||
|
||||
template maxChunkIdx*(T: type, maxLen: int64): int64 =
|
||||
template maxChunkIdx*(T: type, maxLen: Limit): int64 =
|
||||
# Given a number of data items, how many chunks are needed?
|
||||
# TODO compiler bug:
|
||||
# beacon_chain/ssz/types.nim(75, 53) Error: cannot generate code for: maxLen
|
||||
# nextPow2(chunkIdx(T, maxLen + dataPerChunk(T) - 1).uint64).int64
|
||||
nextPow2Int64(chunkIdx(T, maxLen + dataPerChunk(T) - 1))
|
||||
nextPow2Int64(chunkIdx(T, maxLen.int64 + dataPerChunk(T) - 1))
|
||||
|
||||
template layer*(vIdx: int64): int =
|
||||
## Layer 0 = layer at which the root hash is
|
||||
|
|
|
@ -47,7 +47,7 @@ type
|
|||
blockRoot: Eth2Digest
|
||||
slot: Slot
|
||||
|
||||
BlockRootsList* = List[Eth2Digest, MAX_REQUESTED_BLOCKS]
|
||||
BlockRootsList* = List[Eth2Digest, Limit MAX_REQUESTED_BLOCKS]
|
||||
|
||||
proc shortLog*(s: StatusMsg): auto =
|
||||
(
|
||||
|
|
|
@ -244,7 +244,7 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||
|
||||
if slot == 0: # TODO this means if the parameter is missing (its optional)
|
||||
for i in 0 ..< SLOTS_PER_EPOCH:
|
||||
forSlot((compute_start_slot_at_epoch(epoch.Epoch).int + i).Slot, result)
|
||||
forSlot(compute_start_slot_at_epoch(epoch.Epoch) + i, result)
|
||||
else:
|
||||
forSlot(slot.Slot, result)
|
||||
|
||||
|
@ -372,7 +372,7 @@ proc installValidatorApiHandlers*(rpcServer: RpcServer, node: BeaconNode) =
|
|||
let head = node.doChecksAndGetCurrentHead(epoch)
|
||||
|
||||
for i in 0 ..< SLOTS_PER_EPOCH:
|
||||
let currSlot = (compute_start_slot_at_epoch(epoch).int + i).Slot
|
||||
let currSlot = compute_start_slot_at_epoch(epoch) + i
|
||||
let proposer = node.blockPool.getProposer(head, currSlot)
|
||||
if proposer.isSome():
|
||||
result.add((public_key: proposer.get()[1], slot: currSlot))
|
||||
|
|
|
@ -40,7 +40,7 @@ func verifyConsensus*(state: BeaconState, attesterRatio: auto) =
|
|||
if current_epoch >= 4:
|
||||
doAssert state.finalized_checkpoint.epoch + 2 >= current_epoch
|
||||
|
||||
proc loadGenesis*(validators: int, validate: bool): ref HashedBeaconState =
|
||||
proc loadGenesis*(validators: Natural, validate: bool): ref HashedBeaconState =
|
||||
let fn = &"genesim_{const_preset}_{validators}_{SPEC_VERSION}.ssz"
|
||||
let res = (ref HashedBeaconState)()
|
||||
if fileExists(fn):
|
||||
|
@ -62,7 +62,7 @@ proc loadGenesis*(validators: int, validate: bool): ref HashedBeaconState =
|
|||
echo "Preparing validators..."
|
||||
let
|
||||
flags = if validate: {} else: {skipBlsValidation}
|
||||
deposits = makeInitialDeposits(validators, flags)
|
||||
deposits = makeInitialDeposits(validators.uint64, flags)
|
||||
|
||||
echo "Generating Genesis..."
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
|||
validators = SLOTS_PER_EPOCH * 100, # One per shard is minimum
|
||||
json_interval = SLOTS_PER_EPOCH,
|
||||
write_last_json = false,
|
||||
prefix = 0,
|
||||
prefix: int = 0,
|
||||
attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.73,
|
||||
validate = true):
|
||||
let
|
||||
|
|
|
@ -16,4 +16,4 @@ suiteReport "Beacon state" & preset():
|
|||
timedTest "Smoke test initialize_beacon_state_from_eth1" & preset():
|
||||
let state = initialize_beacon_state_from_eth1(
|
||||
defaultRuntimePreset, Eth2Digest(), 0, makeInitialDeposits(SLOTS_PER_EPOCH, {}), {})
|
||||
check: state.validators.len == SLOTS_PER_EPOCH
|
||||
check: state.validators.len == SLOTS_PER_EPOCH.int
|
||||
|
|
|
@ -100,11 +100,11 @@ proc makeTestDB*(tailState: BeaconState, tailBlock: SignedBeaconBlock): BeaconCh
|
|||
result = init(BeaconChainDB, kvStore MemStoreRef.init())
|
||||
BlockPool.preInit(result, tailState, tailBlock)
|
||||
|
||||
proc makeTestDB*(validators: int): BeaconChainDB =
|
||||
proc makeTestDB*(validators: Natural): BeaconChainDB =
|
||||
let
|
||||
genState = initialize_beacon_state_from_eth1(
|
||||
defaultRuntimePreset, Eth2Digest(), 0,
|
||||
makeInitialDeposits(validators, flags = {skipBlsValidation}),
|
||||
makeInitialDeposits(validators.uint64, flags = {skipBlsValidation}),
|
||||
{skipBlsValidation})
|
||||
genBlock = get_initial_beacon_block(genState[])
|
||||
makeTestDB(genState[], genBlock)
|
||||
|
|
Loading…
Reference in New Issue