2019-06-13 23:57:29 +00:00
|
|
|
from eth2spec.test.helpers.block import sign_block
|
|
|
|
|
|
|
|
|
2019-05-15 16:36:32 +00:00
|
|
|
def get_balance(state, index):
|
|
|
|
return state.balances[index]
|
|
|
|
|
|
|
|
|
2019-05-30 20:57:18 +00:00
|
|
|
def next_slot(spec, state):
|
2019-05-15 16:36:32 +00:00
|
|
|
"""
|
|
|
|
Transition to the next slot.
|
|
|
|
"""
|
2019-05-30 20:57:18 +00:00
|
|
|
spec.process_slots(state, state.slot + 1)
|
2019-05-15 16:36:32 +00:00
|
|
|
|
|
|
|
|
2019-05-30 20:57:18 +00:00
|
|
|
def next_epoch(spec, state):
|
2019-05-15 16:36:32 +00:00
|
|
|
"""
|
|
|
|
Transition to the start slot of the next epoch
|
|
|
|
"""
|
|
|
|
slot = state.slot + spec.SLOTS_PER_EPOCH - (state.slot % spec.SLOTS_PER_EPOCH)
|
2019-05-30 20:57:18 +00:00
|
|
|
spec.process_slots(state, slot)
|
2019-05-15 16:36:32 +00:00
|
|
|
|
|
|
|
|
2019-05-30 20:57:18 +00:00
|
|
|
def get_state_root(spec, state, slot) -> bytes:
|
2019-05-15 16:36:32 +00:00
|
|
|
"""
|
|
|
|
Return the state root at a recent ``slot``.
|
|
|
|
"""
|
|
|
|
assert slot < state.slot <= slot + spec.SLOTS_PER_HISTORICAL_ROOT
|
2019-06-09 19:41:21 +00:00
|
|
|
return state.state_roots[slot % spec.SLOTS_PER_HISTORICAL_ROOT]
|
2019-06-13 23:57:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def state_transition_and_sign_block(spec, state, block):
|
|
|
|
"""
|
|
|
|
State transition via the provided ``block``
|
|
|
|
then package the block with the state root and signature.
|
|
|
|
"""
|
|
|
|
spec.state_transition(state, block)
|
|
|
|
block.state_root = state.hash_tree_root()
|
|
|
|
sign_block(spec, state, block)
|