deposit root to Eth1Data transition
This commit is contained in:
parent
c788d72857
commit
476052b314
|
@ -205,7 +205,7 @@ proc proposeBlock(node: BeaconNode,
|
|||
slot: slot,
|
||||
parent_root: node.headBlockRoot,
|
||||
randao_reveal: randaoReveal,
|
||||
deposit_root: node.mainchainMonitor.getBeaconBlockRef(),
|
||||
eth1_data: node.mainchainMonitor.getBeaconBlockRef(),
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
body: blockBody)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ proc start*(m: var MainchainMonitor) =
|
|||
# interface and keep an always-up-to-date receipt reference here
|
||||
discard
|
||||
|
||||
proc getBeaconBlockRef*(m: MainchainMonitor): Eth2Digest =
|
||||
proc getBeaconBlockRef*(m: MainchainMonitor): Eth1Data =
|
||||
# This should be a simple accessor for the reference kept above
|
||||
discard
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ func process_penalties_and_exits(state: var BeaconState) =
|
|||
func get_initial_beacon_state*(
|
||||
initial_validator_deposits: openArray[Deposit],
|
||||
genesis_time: uint64,
|
||||
latest_deposit_root: Eth2Digest,
|
||||
latest_eth1_data: Eth1Data,
|
||||
flags: UpdateFlags = {}): BeaconState =
|
||||
## BeaconState constructor
|
||||
##
|
||||
|
@ -238,7 +238,7 @@ func get_initial_beacon_state*(
|
|||
finalized_slot: GENESIS_SLOT,
|
||||
|
||||
# Deposit root
|
||||
latest_deposit_root: latest_deposit_root,
|
||||
latest_eth1_data: latest_eth1_data,
|
||||
)
|
||||
|
||||
# Process initial deposits
|
||||
|
|
|
@ -271,7 +271,7 @@ type
|
|||
randao_reveal*: Eth2Digest ##\
|
||||
## Proposer RANDAO reveal
|
||||
|
||||
deposit_root*: Eth2Digest
|
||||
eth1_data*: Eth1Data
|
||||
|
||||
signature*: ValidatorSig ##\
|
||||
## Proposer signature
|
||||
|
@ -353,8 +353,8 @@ type
|
|||
latest_attestations*: seq[PendingAttestationRecord]
|
||||
batched_block_roots*: seq[Eth2Digest]
|
||||
|
||||
latest_deposit_root*: Eth2Digest
|
||||
deposit_roots*: seq[DepositRootVote]
|
||||
latest_eth1_data*: Eth1Data
|
||||
eth1_data_votes*: seq[Eth1DataVote]
|
||||
|
||||
Validator* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
|
@ -424,8 +424,15 @@ type
|
|||
slot*: uint64 ##\
|
||||
## When
|
||||
|
||||
DepositRootVote* = object
|
||||
deposit_root*: Eth2Digest
|
||||
Eth1Data* = object
|
||||
deposit_root*: Eth2Digest ##\
|
||||
## Data being voted for
|
||||
|
||||
vote_count*: Eth2Digest ##\
|
||||
## Vote count
|
||||
|
||||
Eth1DataVote* = object
|
||||
eth1_data*: Eth1Data
|
||||
vote_count*: uint64 # Vote count
|
||||
|
||||
PendingAttestationRecord* = object
|
||||
|
|
|
@ -101,15 +101,15 @@ func processRandao(
|
|||
return true
|
||||
|
||||
func processDepositRoot(state: var BeaconState, blck: BeaconBlock) =
|
||||
## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#deposit-root
|
||||
## https://github.com/ethereum/eth2.0-specs/blob/master/specs/core/0_beacon-chain.md#eth1-data
|
||||
|
||||
for x in state.deposit_roots.mitems():
|
||||
if blck.deposit_root == x.deposit_root:
|
||||
for x in state.eth1_data_votes.mitems():
|
||||
if blck.eth1_data == x.eth1_data:
|
||||
x.vote_count += 1
|
||||
return
|
||||
|
||||
state.deposit_roots.add DepositRootVote(
|
||||
deposit_root: blck.deposit_root,
|
||||
state.eth1_data_votes.add Eth1DataVote(
|
||||
eth1_data: blck.eth1_data,
|
||||
vote_count: 1
|
||||
)
|
||||
|
||||
|
@ -573,13 +573,13 @@ func processEpoch(state: var BeaconState) =
|
|||
func total_balance_sac(shard_committee: ShardCommittee): uint64 =
|
||||
sum_effective_balances(statePtr[], shard_committee.committee)
|
||||
|
||||
block: # Deposit roots
|
||||
block: # Eth1 data
|
||||
if state.slot mod ETH1_DATA_VOTING_PERIOD == 0:
|
||||
for x in state.deposit_roots:
|
||||
for x in state.eth1_data_votes:
|
||||
if x.vote_count * 2 >= ETH1_DATA_VOTING_PERIOD:
|
||||
state.latest_deposit_root = x.deposit_root
|
||||
state.latest_eth1_data = x.eth1_data
|
||||
break
|
||||
state.deposit_roots = @[]
|
||||
state.eth1_data_votes = @[]
|
||||
|
||||
block: # Justification
|
||||
state.previous_justified_slot = state.justified_slot
|
||||
|
|
|
@ -32,7 +32,7 @@ proc obtainTrustedStateSnapshot*(db: BeaconChainDB): Future[BeaconState] {.async
|
|||
proc createStateSnapshot*(startup: ChainStartupData, outFile: string) =
|
||||
let initialState = get_initial_beacon_state(startup.validatorDeposits,
|
||||
startup.genesisTime,
|
||||
Eth2Digest(), {})
|
||||
Eth1Data(), {})
|
||||
|
||||
var vr: Validator
|
||||
Json.saveFile(outFile, initialState, pretty = true)
|
||||
|
|
|
@ -27,7 +27,7 @@ proc transition(
|
|||
let
|
||||
flags = if validate: {} else: {skipValidation}
|
||||
genesisState = get_initial_beacon_state(
|
||||
makeInitialDeposits(validators, flags), 0, Eth2Digest(), flags)
|
||||
makeInitialDeposits(validators, flags), 0, Eth1Data(), flags)
|
||||
genesisBlock = makeGenesisBlock(genesisState)
|
||||
|
||||
var
|
||||
|
|
|
@ -14,5 +14,5 @@ import
|
|||
suite "Beacon state":
|
||||
test "Smoke test get_initial_beacon_state":
|
||||
let state = get_initial_beacon_state(
|
||||
makeInitialDeposits(EPOCH_LENGTH, {}), 0, Eth2Digest(), {})
|
||||
makeInitialDeposits(EPOCH_LENGTH, {}), 0, Eth1Data(), {})
|
||||
check: state.validator_registry.len == EPOCH_LENGTH
|
||||
|
|
|
@ -19,7 +19,7 @@ suite "Block processing":
|
|||
# Genesis state with minimal number of deposits
|
||||
# TODO bls verification is a bit of a bottleneck here
|
||||
genesisState = get_initial_beacon_state(
|
||||
makeInitialDeposits(), 0, Eth2Digest(), {})
|
||||
makeInitialDeposits(), 0, Eth1Data(), {})
|
||||
genesisBlock = makeGenesisBlock(genesisState)
|
||||
|
||||
test "Passes from genesis state, no block":
|
||||
|
|
|
@ -115,7 +115,7 @@ proc addBlock*(
|
|||
parent_root: previous_block_root,
|
||||
state_root: Eth2Digest(), # we need the new state first
|
||||
randao_reveal: hackReveal(proposer),
|
||||
deposit_root: Eth2Digest(), # TODO
|
||||
eth1_data: Eth1Data(), # TODO
|
||||
signature: ValidatorSig(), # we need the rest of the block first!
|
||||
body: body
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue