implement (unpolished) solution for #1446, based on suggested use of eth1 hash
This commit is contained in:
parent
f1bf0bf85b
commit
2186c45f84
|
@ -1113,6 +1113,9 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash,
|
||||||
eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=len(deposits)),
|
eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=len(deposits)),
|
||||||
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
|
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
|
||||||
)
|
)
|
||||||
|
# Set the initial RANDAO mixes to hashes seeded by the Eth1 hash, to limit deposit ordering committee bias.
|
||||||
|
for i in range(MIN_SEED_LOOKAHEAD + 1):
|
||||||
|
state.randao_mixes[EPOCHS_PER_HISTORICAL_VECTOR - i - 1] = hash(eth1_block_hash + int_to_bytes(i, 8))
|
||||||
|
|
||||||
# Process deposits
|
# Process deposits
|
||||||
leaves = list(map(lambda deposit: deposit.data, deposits))
|
leaves = list(map(lambda deposit: deposit.data, deposits))
|
||||||
|
|
|
@ -19,17 +19,23 @@ def build_mock_validator(spec, i: int, balance: int):
|
||||||
def create_genesis_state(spec, num_validators):
|
def create_genesis_state(spec, num_validators):
|
||||||
deposit_root = b'\x42' * 32
|
deposit_root = b'\x42' * 32
|
||||||
|
|
||||||
|
eth1_block_hash = b'\xda' * 32
|
||||||
state = spec.BeaconState(
|
state = spec.BeaconState(
|
||||||
genesis_time=0,
|
genesis_time=0,
|
||||||
eth1_deposit_index=num_validators,
|
eth1_deposit_index=num_validators,
|
||||||
eth1_data=spec.Eth1Data(
|
eth1_data=spec.Eth1Data(
|
||||||
deposit_root=deposit_root,
|
deposit_root=deposit_root,
|
||||||
deposit_count=num_validators,
|
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())),
|
latest_block_header=spec.BeaconBlockHeader(body_root=spec.hash_tree_root(spec.BeaconBlockBody())),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set the initial RANDAO mixes to hashes seeded by the Eth1 hash, to limit deposit ordering committee bias.
|
||||||
|
for i in range(spec.MIN_SEED_LOOKAHEAD + 1):
|
||||||
|
state.randao_mixes[spec.EPOCHS_PER_HISTORICAL_VECTOR - i - 1] = \
|
||||||
|
spec.hash(eth1_block_hash + spec.int_to_bytes(i, 8))
|
||||||
|
|
||||||
# We "hack" in the initial validators,
|
# We "hack" in the initial validators,
|
||||||
# as it is much faster than creating and processing genesis deposits for every single test case.
|
# as it is much faster than creating and processing genesis deposits for every single test case.
|
||||||
state.balances = [spec.MAX_EFFECTIVE_BALANCE] * num_validators
|
state.balances = [spec.MAX_EFFECTIVE_BALANCE] * num_validators
|
||||||
|
|
Loading…
Reference in New Issue