Merge pull request #1447 from ethereum/early-committee-bias

Implement solution for #1446, based on suggested use of eth1 hash
This commit is contained in:
Danny Ryan 2019-10-28 14:10:50 +08:00 committed by GitHub
commit c547c5291d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -1036,6 +1036,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash,
genesis_time=eth1_timestamp - eth1_timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY,
eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=len(deposits)),
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy
)
# Process deposits

View File

@ -19,15 +19,17 @@ def build_mock_validator(spec, i: int, balance: int):
def create_genesis_state(spec, num_validators):
deposit_root = b'\x42' * 32
eth1_block_hash = b'\xda' * 32
state = spec.BeaconState(
genesis_time=0,
eth1_deposit_index=num_validators,
eth1_data=spec.Eth1Data(
deposit_root=deposit_root,
deposit_count=num_validators,
block_hash=spec.Hash(),
block_hash=eth1_block_hash,
),
latest_block_header=spec.BeaconBlockHeader(body_root=spec.hash_tree_root(spec.BeaconBlockBody())),
randao_mixes=[eth1_block_hash] * spec.EPOCHS_PER_HISTORICAL_VECTOR,
)
# We "hack" in the initial validators,

View File

@ -475,6 +475,8 @@ def test_eth1_data_votes_no_consensus(spec, state):
if spec.SLOTS_PER_ETH1_VOTING_PERIOD > 16:
return
pre_eth1_hash = state.eth1_data.block_hash
offset_block = build_empty_block(spec, state, slot=spec.SLOTS_PER_ETH1_VOTING_PERIOD - 1)
sign_block(spec, state, offset_block)
state_transition_and_sign_block(spec, state, offset_block)
@ -494,7 +496,7 @@ def test_eth1_data_votes_no_consensus(spec, state):
blocks.append(block)
assert len(state.eth1_data_votes) == spec.SLOTS_PER_ETH1_VOTING_PERIOD
assert state.eth1_data.block_hash == b'\x00' * 32
assert state.eth1_data.block_hash == pre_eth1_hash
yield 'blocks', blocks
yield 'post', state