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:
Dustin Brody 2019-09-05 19:52:34 +00:00 committed by Jacek Sieka
parent 31db5d3a62
commit f882c92a42
7 changed files with 22 additions and 26 deletions

View File

@ -216,12 +216,11 @@ proc fromBytes*[T](R: type BlsValue[T], bytes: openarray[byte]): R =
# default-initialized BlsValue without raising an exception # default-initialized BlsValue without raising an exception
# TODO don't use exceptions for parsing, ever. Handle deserialization issues # TODO don't use exceptions for parsing, ever. Handle deserialization issues
# sanely, always. # sanely, always.
const allZeroes = T() when defined(ssz_testing):
if bytes == allZeroes.getBytes(): R(kind: OpaqueBlob, blob: toArray(result.blob.len, bytes))
R(kind: Real)
else: else:
when defined(ssz_testing): if bytes.allIt(it == 0):
R(kind: OpaqueBlob, blob: toArray(result.blob.len, bytes)) R(kind: Real)
else: else:
R(kind: Real, blsValue: init(T, bytes)) R(kind: Real, blsValue: init(T, bytes))

View File

@ -251,7 +251,7 @@ type
voluntary_exits*: seq[VoluntaryExit] voluntary_exits*: seq[VoluntaryExit]
transfers*: seq[Transfer] 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 BeaconState* = object
# Versioning # Versioning
genesis_time*: uint64 genesis_time*: uint64
@ -305,7 +305,9 @@ type
current_epoch_attestations*: seq[PendingAttestation] current_epoch_attestations*: seq[PendingAttestation]
# Crosslinks # Crosslinks
previous_crosslinks*: array[SHARD_COUNT, Crosslink] previous_crosslinks*: array[SHARD_COUNT, Crosslink] ##\
## Previous epoch snapshot
current_crosslinks*: array[SHARD_COUNT, Crosslink] current_crosslinks*: array[SHARD_COUNT, Crosslink]
# Finality # Finality

View File

@ -77,9 +77,8 @@ const
# Initial values # 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 GENESIS_SLOT* = 0.Slot
BLS_WITHDRAWAL_PREFIX* = 0'u8 BLS_WITHDRAWAL_PREFIX* = 0'u8
@ -133,9 +132,9 @@ const
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\ MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 ##\
## epochs (25.6 minutes) ## 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_HISTORICAL_VECTOR* = 65536
EPOCHS_PER_SLASHINGS_VECTOR* = 8192 EPOCHS_PER_SLASHINGS_VECTOR* = 8192
HISTORICAL_ROOTS_LIMIT* = 16777216 HISTORICAL_ROOTS_LIMIT* = 16777216
@ -152,7 +151,7 @@ const
# Max operations per block # 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_PROPOSER_SLASHINGS* = 2^4
MAX_ATTESTER_SLASHINGS* = 2^0 MAX_ATTESTER_SLASHINGS* = 2^0
MAX_ATTESTATIONS* = 2^7 MAX_ATTESTATIONS* = 2^7

View File

@ -25,7 +25,7 @@ type
const const
# Misc # 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 # Changed
SHARD_COUNT* {.intdefine.} = 8 SHARD_COUNT* {.intdefine.} = 8
@ -39,6 +39,8 @@ const
# Changed # Changed
SHUFFLE_ROUND_COUNT* = 10 SHUFFLE_ROUND_COUNT* = 10
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99
MIN_GENESIS_TIME* {.intdefine.} = 0
# Constants # Constants
# --------------------------------------------------------------- # ---------------------------------------------------------------
@ -59,10 +61,9 @@ const
# Initial values # 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 # Unchanged
GENESIS_FORK_VERSION* = [0'u8, 0'u8, 0'u8, 0'u8]
GENESIS_SLOT* = 0.Slot GENESIS_SLOT* = 0.Slot
BLS_WITHDRAWAL_PREFIX* = 0'u8 BLS_WITHDRAWAL_PREFIX* = 0'u8
@ -94,9 +95,9 @@ const
MAX_EPOCHS_PER_CROSSLINK* = 4 MAX_EPOCHS_PER_CROSSLINK* = 4
MIN_EPOCHS_TO_INACTIVITY_PENALTY* = 2'u64^2 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 # Changed
EPOCHS_PER_HISTORICAL_VECTOR* = 64 EPOCHS_PER_HISTORICAL_VECTOR* = 64
@ -128,10 +129,6 @@ const
MAX_TRANSFERS* = 0 MAX_TRANSFERS* = 0
MIN_GENESIS_TIME* {.intdefine.} = 0
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT* {.intdefine.} = 99
type type
# Signature domains # Signature domains
# --------------------------------------------------------------- # ---------------------------------------------------------------

View File

@ -304,7 +304,7 @@ func process_crosslinks*(state: var BeaconState, stateCache: var StateCache) =
2'u64 * get_total_balance(state, crosslink_committee): 2'u64 * get_total_balance(state, crosslink_committee):
state.current_crosslinks[shard] = winning_crosslink 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 = func get_base_reward(state: BeaconState, index: ValidatorIndex): Gwei =
let let
total_balance = get_total_active_balance(state) total_balance = get_total_active_balance(state)

View File

@ -66,8 +66,9 @@ proc process_slots*(state: var BeaconState, slot: Slot) =
process_epoch(state) process_epoch(state)
state.slot += 1 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 = proc verifyStateRoot(state: BeaconState, blck: BeaconBlock): bool =
# This is inlined in state_transition(...) in spec.
let state_root = hash_tree_root(state) let state_root = hash_tree_root(state)
if state_root != blck.state_root: if state_root != blck.state_root:
notice "Block: root verification failed", notice "Block: root verification failed",
@ -138,7 +139,7 @@ proc state_transition*(
# Hashed-state transition functions # 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) = func process_slot(state: var HashedBeaconState) =
# Cache state root # Cache state root
let previous_slot_state_root = state.root let previous_slot_state_root = state.root

View File

@ -55,8 +55,6 @@ proc signAttestation*(v: AttachedValidator,
func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot): func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
ValidatorSig = 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) # 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) 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, bls_sign(k, hash_tree_root(compute_epoch_of_slot(slot).uint64).data,