Skip to content

Commit f544b1a

Browse files
committed
PR feedback
1 parent a5ed661 commit f544b1a

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

eth/beacon/state_machines/base.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@ def compute_cycle_transitions(
385385
block,
386386
)
387387

388+
# TODO: it's a STUB before we implement compute_per_cycle_transition
389+
crystallized_state = crystallized_state.copy(
390+
last_state_recalc=crystallized_state.last_state_recalc + cls.config.CYCLE_LENGTH
391+
)
392+
388393
if cls.ready_for_dynasty_transition(crystallized_state, block):
389394
crystallized_state = cls.compute_dynasty_transition(
390395
crystallized_state,
@@ -409,10 +414,10 @@ def compute_per_cycle_transition(
409414
# Crosslinks
410415
#
411416
@classmethod
412-
def compute_crosslinks(cls,
413-
crystallized_state: CrystallizedState,
414-
active_state: ActiveState,
415-
block: BaseBeaconBlock) -> Tuple['CrosslinkRecord', ...]:
417+
def update_crosslinks(cls,
418+
crystallized_state: CrystallizedState,
419+
active_state: ActiveState,
420+
block: BaseBeaconBlock) -> Tuple['CrosslinkRecord', ...]:
416421
# TODO
417422
return ()
418423

tests/beacon/state_machines/test_state_machines.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,46 @@ def test_import_block_one(fixture_sm_class,
9595
[ZERO_HASH32] * (sm.config.CYCLE_LENGTH * 2 - 1) + [genesis_block.hash]
9696
)
9797
assert active_state.recent_block_hashes == expect
98+
99+
100+
@pytest.mark.parametrize(
101+
(
102+
'num_validators,cycle_length,min_committee_size,shard_count,'
103+
'block_slot,'
104+
'prev_last_state_recalculation_slot,'
105+
'post_last_state_recalculation_slot'
106+
),
107+
[
108+
(1000, 20, 10, 100, 1, 0, 0), # no cycle transition
109+
(1000, 20, 10, 100, 20, 0, 20), # transition: 0 + cycle_length
110+
(1000, 20, 10, 100, 60, 5, 45), # transition: 5 + 2 * cycle_length
111+
(1000, 20, 10, 100, 61, 45, 45), # no cycle transition
112+
]
113+
)
114+
def test_compute_cycle_transitions(fixture_sm_class,
115+
initial_chaindb,
116+
genesis_block,
117+
genesis_crystallized_state,
118+
genesis_active_state,
119+
block_slot,
120+
prev_last_state_recalculation_slot,
121+
post_last_state_recalculation_slot):
122+
chaindb = initial_chaindb
123+
124+
block_1_shell = genesis_block.copy(
125+
parent_hash=genesis_block.hash,
126+
slot_number=genesis_block.slot_number + 1,
127+
)
128+
129+
sm = fixture_sm_class(chaindb, block_1_shell)
130+
131+
post_crystallized_state, _ = sm.compute_cycle_transitions(
132+
genesis_crystallized_state.copy(
133+
last_state_recalc=prev_last_state_recalculation_slot,
134+
),
135+
genesis_active_state,
136+
genesis_block.copy(
137+
slot_number=block_slot,
138+
)
139+
)
140+
assert post_crystallized_state.last_state_recalc == post_last_state_recalculation_slot

0 commit comments

Comments
 (0)