More fixes
This commit is contained in:
parent
df64eeefa0
commit
55f042aa71
|
@ -929,7 +929,7 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex:
|
||||||
i = 0
|
i = 0
|
||||||
while True:
|
while True:
|
||||||
candidate_index = first_committee[(current_epoch + i) % len(first_committee)]
|
candidate_index = first_committee[(current_epoch + i) % len(first_committee)]
|
||||||
random_byte = hash(generate_seed(state, epoch) + int_to_bytes8(i // 32))[i % 32]
|
random_byte = hash(generate_seed(state, current_epoch) + int_to_bytes8(i // 32))[i % 32]
|
||||||
effective_balance = state.validator_registry[candidate_index].effective_balance
|
effective_balance = state.validator_registry[candidate_index].effective_balance
|
||||||
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte:
|
||||||
return candidate_index
|
return candidate_index
|
||||||
|
@ -2011,7 +2011,7 @@ def process_transfer(state: BeaconState, transfer: Transfer) -> None:
|
||||||
assert (
|
assert (
|
||||||
state.validator_registry[transfer.sender].activation_eligibility_epoch == FAR_FUTURE_EPOCH or
|
state.validator_registry[transfer.sender].activation_eligibility_epoch == FAR_FUTURE_EPOCH or
|
||||||
get_current_epoch(state) >= state.validator_registry[transfer.sender].withdrawable_epoch or
|
get_current_epoch(state) >= state.validator_registry[transfer.sender].withdrawable_epoch or
|
||||||
transfer.amount + transfer.fee + MAX_EFFECTIVE_BALANCE <= get_balance(state, transfer.sender)
|
transfer.amount + transfer.fee + MAX_EFFECTIVE_BALANCE <= state.balances[transfer.sender]
|
||||||
)
|
)
|
||||||
# Verify that the pubkey is valid
|
# Verify that the pubkey is valid
|
||||||
assert (
|
assert (
|
||||||
|
|
|
@ -28,6 +28,7 @@ from eth2spec.phase0.spec import (
|
||||||
get_active_validator_indices,
|
get_active_validator_indices,
|
||||||
get_attesting_indices,
|
get_attesting_indices,
|
||||||
get_block_root,
|
get_block_root,
|
||||||
|
get_block_root_at_slot,
|
||||||
get_crosslink_committees_at_slot,
|
get_crosslink_committees_at_slot,
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
get_domain,
|
get_domain,
|
||||||
|
@ -51,9 +52,11 @@ privkeys = [i + 1 for i in range(1000)]
|
||||||
pubkeys = [bls.privtopub(privkey) for privkey in privkeys]
|
pubkeys = [bls.privtopub(privkey) for privkey in privkeys]
|
||||||
pubkey_to_privkey = {pubkey: privkey for privkey, pubkey in zip(privkeys, pubkeys)}
|
pubkey_to_privkey = {pubkey: privkey for privkey, pubkey in zip(privkeys, pubkeys)}
|
||||||
|
|
||||||
|
|
||||||
def get_balance(state, index):
|
def get_balance(state, index):
|
||||||
return state.balances[index]
|
return state.balances[index]
|
||||||
|
|
||||||
|
|
||||||
def set_bitfield_bit(bitfield, i):
|
def set_bitfield_bit(bitfield, i):
|
||||||
"""
|
"""
|
||||||
Set the bit in ``bitfield`` at position ``i`` to ``1``.
|
Set the bit in ``bitfield`` at position ``i`` to ``1``.
|
||||||
|
@ -151,16 +154,16 @@ def build_attestation_data(state, slot, shard):
|
||||||
if slot == state.slot:
|
if slot == state.slot:
|
||||||
block_root = build_empty_block_for_next_slot(state).previous_block_root
|
block_root = build_empty_block_for_next_slot(state).previous_block_root
|
||||||
else:
|
else:
|
||||||
block_root = get_block_root(state, slot)
|
block_root = get_block_root_at_slot(state, slot)
|
||||||
|
|
||||||
current_epoch_start_slot = get_epoch_start_slot(get_current_epoch(state))
|
current_epoch_start_slot = get_epoch_start_slot(get_current_epoch(state))
|
||||||
if slot < current_epoch_start_slot:
|
if slot < current_epoch_start_slot:
|
||||||
print(slot)
|
print(slot)
|
||||||
epoch_boundary_root = get_block_root(state, get_epoch_start_slot(get_previous_epoch(state)))
|
epoch_boundary_root = get_block_root(state, get_previous_epoch(state))
|
||||||
elif slot == current_epoch_start_slot:
|
elif slot == current_epoch_start_slot:
|
||||||
epoch_boundary_root = block_root
|
epoch_boundary_root = block_root
|
||||||
else:
|
else:
|
||||||
epoch_boundary_root = get_block_root(state, current_epoch_start_slot)
|
epoch_boundary_root = get_block_root(state, get_current_epoch(state))
|
||||||
|
|
||||||
if slot < current_epoch_start_slot:
|
if slot < current_epoch_start_slot:
|
||||||
justified_epoch = state.previous_justified_epoch
|
justified_epoch = state.previous_justified_epoch
|
||||||
|
|
|
@ -9,6 +9,7 @@ from eth2spec.utils.minimal_ssz import signing_root
|
||||||
from eth2spec.phase0.spec import (
|
from eth2spec.phase0.spec import (
|
||||||
# constants
|
# constants
|
||||||
ZERO_HASH,
|
ZERO_HASH,
|
||||||
|
SLOTS_PER_HISTORICAL_ROOT,
|
||||||
# SSZ
|
# SSZ
|
||||||
Deposit,
|
Deposit,
|
||||||
Transfer,
|
Transfer,
|
||||||
|
@ -17,9 +18,9 @@ from eth2spec.phase0.spec import (
|
||||||
get_active_validator_indices,
|
get_active_validator_indices,
|
||||||
get_beacon_proposer_index,
|
get_beacon_proposer_index,
|
||||||
get_block_root,
|
get_block_root,
|
||||||
|
get_block_root_at_slot,
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
get_domain,
|
get_domain,
|
||||||
get_state_root,
|
|
||||||
advance_slot,
|
advance_slot,
|
||||||
cache_state,
|
cache_state,
|
||||||
slot_to_epoch,
|
slot_to_epoch,
|
||||||
|
@ -48,6 +49,13 @@ from .helpers import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_state_root(state, slot) -> bytes:
|
||||||
|
"""
|
||||||
|
Return the state root at a recent ``slot``.
|
||||||
|
"""
|
||||||
|
assert slot < state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT
|
||||||
|
return state.latest_state_roots[slot % SLOTS_PER_HISTORICAL_ROOT]
|
||||||
|
|
||||||
# mark entire file as 'sanity'
|
# mark entire file as 'sanity'
|
||||||
pytestmark = pytest.mark.sanity
|
pytestmark = pytest.mark.sanity
|
||||||
|
|
||||||
|
@ -94,7 +102,7 @@ def test_empty_block_transition(state):
|
||||||
state_transition(test_state, block)
|
state_transition(test_state, block)
|
||||||
|
|
||||||
assert len(test_state.eth1_data_votes) == len(state.eth1_data_votes) + 1
|
assert len(test_state.eth1_data_votes) == len(state.eth1_data_votes) + 1
|
||||||
assert get_block_root(test_state, state.slot) == block.previous_block_root
|
assert get_block_root_at_slot(test_state, state.slot) == block.previous_block_root
|
||||||
|
|
||||||
return state, [block], test_state
|
return state, [block], test_state
|
||||||
|
|
||||||
|
@ -108,7 +116,7 @@ def test_skipped_slots(state):
|
||||||
|
|
||||||
assert test_state.slot == block.slot
|
assert test_state.slot == block.slot
|
||||||
for slot in range(state.slot, test_state.slot):
|
for slot in range(state.slot, test_state.slot):
|
||||||
assert get_block_root(test_state, slot) == block.previous_block_root
|
assert get_block_root_at_slot(test_state, slot) == block.previous_block_root
|
||||||
|
|
||||||
return state, [block], test_state
|
return state, [block], test_state
|
||||||
|
|
||||||
|
@ -122,7 +130,7 @@ def test_empty_epoch_transition(state):
|
||||||
|
|
||||||
assert test_state.slot == block.slot
|
assert test_state.slot == block.slot
|
||||||
for slot in range(state.slot, test_state.slot):
|
for slot in range(state.slot, test_state.slot):
|
||||||
assert get_block_root(test_state, slot) == block.previous_block_root
|
assert get_block_root_at_slot(test_state, slot) == block.previous_block_root
|
||||||
|
|
||||||
return state, [block], test_state
|
return state, [block], test_state
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ from build.phase0.spec import (
|
||||||
VoluntaryExit,
|
VoluntaryExit,
|
||||||
# functions
|
# functions
|
||||||
get_block_root,
|
get_block_root,
|
||||||
|
get_block_root_at_slot,
|
||||||
get_current_epoch,
|
get_current_epoch,
|
||||||
get_domain,
|
get_domain,
|
||||||
get_empty_block,
|
get_empty_block,
|
||||||
|
@ -141,7 +142,7 @@ def build_attestation_data(state, slot, shard):
|
||||||
if epoch_start_slot == slot:
|
if epoch_start_slot == slot:
|
||||||
epoch_boundary_root = block_root
|
epoch_boundary_root = block_root
|
||||||
else:
|
else:
|
||||||
get_block_root(state, epoch_start_slot)
|
get_block_root(state, get_current_epoch(state))
|
||||||
|
|
||||||
if slot < epoch_start_slot:
|
if slot < epoch_start_slot:
|
||||||
justified_block_root = state.previous_justified_root
|
justified_block_root = state.previous_justified_root
|
||||||
|
|
Loading…
Reference in New Issue