fix network sim (#389)
* fix network sim * mark BeaconState, state list/vector lengths, misc values, get_base_reward(...), verifyStateRoot(...), and process_slot(...) as 0.8.3; update minimal/mainnet config initial values to 0.8.3 by removing GENESIS_FORK_VERSION
This commit is contained in:
parent
31db5d3a62
commit
f882c92a42
|
@ -216,12 +216,11 @@ proc fromBytes*[T](R: type BlsValue[T], bytes: openarray[byte]): R =
|
|||
# default-initialized BlsValue without raising an exception
|
||||
# TODO don't use exceptions for parsing, ever. Handle deserialization issues
|
||||
# sanely, always.
|
||||
const allZeroes = T()
|
||||
if bytes == allZeroes.getBytes():
|
||||
R(kind: Real)
|
||||
else:
|
||||
when defined(ssz_testing):
|
||||
R(kind: OpaqueBlob, blob: toArray(result.blob.len, bytes))
|
||||
else:
|
||||
if bytes.allIt(it == 0):
|
||||
R(kind: Real)
|
||||
else:
|
||||
R(kind: Real, blsValue: init(T, bytes))
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ type
|
|||
voluntary_exits*: seq[VoluntaryExit]
|
||||
transfers*: seq[Transfer]
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beaconstate
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#beaconstate
|
||||
BeaconState* = object
|
||||
# Versioning
|
||||
genesis_time*: uint64
|
||||
|
@ -305,7 +305,9 @@ type
|
|||
current_epoch_attestations*: seq[PendingAttestation]
|
||||
|
||||
# Crosslinks
|
||||
previous_crosslinks*: array[SHARD_COUNT, Crosslink]
|
||||
previous_crosslinks*: array[SHARD_COUNT, Crosslink] ##\
|
||||
## Previous epoch snapshot
|
||||
|
||||
current_crosslinks*: array[SHARD_COUNT, Crosslink]
|
||||
|
||||
# Finality
|
||||
|
|
|
@ -77,9 +77,8 @@ const
|
|||
|
||||
# Initial values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/configs/constant_presets/mainnet.yaml#L44
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/configs/mainnet.yaml#L45
|
||||
|
||||
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
|
||||
GENESIS_SLOT* = 0.Slot
|
||||
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||
|
||||
|
@ -133,9 +132,9 @@ const
|
|||
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
|
||||
## epochs (25.6 minutes)
|
||||
|
||||
# State list lengths
|
||||
# State vector lengths
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#state-list-lengths
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/configs/mainnet.yaml#L81
|
||||
EPOCHS_PER_HISTORICAL_VECTOR* = 65536
|
||||
EPOCHS_PER_SLASHINGS_VECTOR* = 8192
|
||||
HISTORICAL_ROOTS_LIMIT* = 16777216
|
||||
|
@ -152,7 +151,7 @@ const
|
|||
|
||||
# Max operations per block
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#max-operations-per-block
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#max-operations-per-block
|
||||
MAX_PROPOSER_SLASHINGS* = 2^4
|
||||
MAX_ATTESTER_SLASHINGS* = 2^0
|
||||
MAX_ATTESTATIONS* = 2^7
|
||||
|
|
|
@ -25,7 +25,7 @@ type
|
|||
const
|
||||
# Misc
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#misc
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/configs/minimal.yaml#L4
|
||||
|
||||
# Changed
|
||||
SHARD_COUNT* {.intdefine.} = 8
|
||||
|
@ -39,6 +39,8 @@ const
|
|||
|
||||
# Changed
|
||||
SHUFFLE_ROUND_COUNT* = 10
|
||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99
|
||||
MIN_GENESIS_TIME* {.intdefine.} = 0
|
||||
|
||||
# Constants
|
||||
# ---------------------------------------------------------------
|
||||
|
@ -59,10 +61,9 @@ const
|
|||
|
||||
# Initial values
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/configs/constant_presets/minimal.yaml#L43
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/configs/minimal.yaml#L44
|
||||
|
||||
# Unchanged
|
||||
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
|
||||
GENESIS_SLOT* = 0.Slot
|
||||
BLS_WITHDRAWAL_PREFIX* = 0'u8
|
||||
|
||||
|
@ -94,9 +95,9 @@ const
|
|||
MAX_EPOCHS_PER_CROSSLINK* = 4
|
||||
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2
|
||||
|
||||
# State list lengths
|
||||
# State vector lengths
|
||||
# ---------------------------------------------------------------
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#state-list-lengths
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/configs/minimal.yaml#L79
|
||||
|
||||
# Changed
|
||||
EPOCHS_PER_HISTORICAL_VECTOR* = 64
|
||||
|
@ -128,10 +129,6 @@ const
|
|||
MAX_TRANSFERS* = 0
|
||||
|
||||
|
||||
MIN_GENESIS_TIME* {.intdefine.} = 0
|
||||
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99
|
||||
|
||||
|
||||
type
|
||||
# Signature domains
|
||||
# ---------------------------------------------------------------
|
||||
|
|
|
@ -304,7 +304,7 @@ func process_crosslinks*(state: var BeaconState, stateCache: var StateCache) =
|
|||
2'u64 * get_total_balance(state, crosslink_committee):
|
||||
state.current_crosslinks[shard] = winning_crosslink
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#rewards-and-penalties-1
|
||||
func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei =
|
||||
let
|
||||
total_balance = get_total_active_balance(state)
|
||||
|
|
|
@ -66,8 +66,9 @@ proc process_slots*(state: var BeaconState, slot: Slot) =
|
|||
process_epoch(state)
|
||||
state.slot += 1
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.6.3/specs/core/0_beacon-chain.md#state-root-verification
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
||||
proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool =
|
||||
# This is inlined in state_transition(...) in spec.
|
||||
let state_root = hash_tree_root(state)
|
||||
if state_root != blck.state_root:
|
||||
notice "Block: root verification failed",
|
||||
|
@ -138,7 +139,7 @@ proc state_transition*(
|
|||
# Hashed-state transition functions
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.7.1/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.8.3/specs/core/0_beacon-chain.md#beacon-chain-state-transition-function
|
||||
func process_slot(state: var HashedBeaconState) =
|
||||
# Cache state root
|
||||
let previous_slot_state_root = state.root
|
||||
|
|
|
@ -55,8 +55,6 @@ proc signAttestation*(v: AttachedValidator,
|
|||
|
||||
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
|
||||
ValidatorSig =
|
||||
# https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#randao
|
||||
|
||||
# Off-by-one? I often get slot == state.slot but the check was "doAssert slot > state.slot" (Mamy)
|
||||
doAssert slot >= state.slot, "input slot: " & $shortLog(slot) & " - beacon state slot: " & $shortLog(state.slot)
|
||||
bls_sign(k, hash_tree_root(compute_epoch_of_slot(slot).uint64).data,
|
||||
|
|
Loading…
Reference in New Issue