Skip to content

Commit c467ca4

Browse files
authored
Use is_future_epoch in BLS to execution change gossip (#5600)
1 parent b87f78f commit c467ca4

2 files changed

Lines changed: 92 additions & 5 deletions

File tree

specs/capella/p2p-interface.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,7 @@ def validate_bls_to_execution_change_gossip(
220220
raise GossipIgnore("already seen BLS to execution change for this validator")
221221

222222
# [IGNORE] The current epoch is at or after the Capella fork epoch
223-
# (where current_epoch is defined by the current wall-clock time)
224-
time_since_genesis_ms = current_time_ms - store.genesis_time * 1000
225-
current_slot = Slot(time_since_genesis_ms // SLOT_DURATION_MS)
226-
current_epoch = compute_epoch_at_slot(current_slot)
227-
if current_epoch < CAPELLA_FORK_EPOCH:
223+
if is_future_epoch(store, CAPELLA_FORK_EPOCH, current_time_ms):
228224
raise GossipIgnore("current epoch is pre-capella")
229225

230226
state = store.block_states[get_head(store).root]

tests/core/pyspec/eth_consensus_specs/test/capella/networking/test_gossip_bls_to_execution_change.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,97 @@ def test_gossip_bls_to_execution_change__ignore_pre_capella(spec, state):
112112
)
113113

114114

115+
@with_phases([CAPELLA])
116+
@spec_configured_state_test({"CAPELLA_FORK_EPOCH": 1})
117+
def test_gossip_bls_to_execution_change__ignore_before_clock_disparity(spec, state):
118+
"""
119+
Test that a `bls_to_execution_change` is ignored immediately before the
120+
Capella fork epoch's clock-disparity window opens.
121+
"""
122+
yield "topic", "meta", "bls_to_execution_change"
123+
yield "state", state
124+
125+
store, signed_anchor = get_store_from_state(spec, state)
126+
yield get_filename(signed_anchor), signed_anchor
127+
yield "blocks", "meta", [{"block": get_filename(signed_anchor)}]
128+
129+
seen = get_seen(spec)
130+
signed_bls_to_execution_change = get_signed_bls_to_execution_change(spec, state)
131+
capella_fork_time_ms = get_capella_fork_time_ms(spec, store)
132+
current_time_ms = capella_fork_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY - 1
133+
134+
yield get_filename(signed_bls_to_execution_change), signed_bls_to_execution_change
135+
yield "current_time_ms", "meta", int(current_time_ms)
136+
137+
result, reason = run_validate_gossip(
138+
spec,
139+
seen=seen,
140+
store=store,
141+
signed_bls_to_execution_change=signed_bls_to_execution_change,
142+
current_time_ms=current_time_ms,
143+
)
144+
assert result == "ignore"
145+
assert reason == "current epoch is pre-capella"
146+
147+
yield (
148+
"messages",
149+
"meta",
150+
[
151+
{
152+
"offset_ms": 0,
153+
"message": get_filename(signed_bls_to_execution_change),
154+
"expected": "ignore",
155+
"reason": reason,
156+
}
157+
],
158+
)
159+
160+
161+
@with_phases([CAPELLA])
162+
@spec_configured_state_test({"CAPELLA_FORK_EPOCH": 1})
163+
def test_gossip_bls_to_execution_change__valid_at_clock_disparity(spec, state):
164+
"""
165+
Test that a `bls_to_execution_change` is valid when the Capella fork epoch's
166+
clock-disparity window opens while the head state is still in the previous epoch.
167+
"""
168+
yield "topic", "meta", "bls_to_execution_change"
169+
yield "state", state
170+
171+
store, signed_anchor = get_store_from_state(spec, state)
172+
yield get_filename(signed_anchor), signed_anchor
173+
yield "blocks", "meta", [{"block": get_filename(signed_anchor)}]
174+
175+
seen = get_seen(spec)
176+
signed_bls_to_execution_change = get_signed_bls_to_execution_change(spec, state)
177+
capella_fork_time_ms = get_capella_fork_time_ms(spec, store)
178+
current_time_ms = capella_fork_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY
179+
180+
yield get_filename(signed_bls_to_execution_change), signed_bls_to_execution_change
181+
yield "current_time_ms", "meta", int(current_time_ms)
182+
183+
result, reason = run_validate_gossip(
184+
spec,
185+
seen=seen,
186+
store=store,
187+
signed_bls_to_execution_change=signed_bls_to_execution_change,
188+
current_time_ms=current_time_ms,
189+
)
190+
assert result == "valid"
191+
assert reason is None
192+
193+
yield (
194+
"messages",
195+
"meta",
196+
[
197+
{
198+
"offset_ms": 0,
199+
"message": get_filename(signed_bls_to_execution_change),
200+
"expected": "valid",
201+
}
202+
],
203+
)
204+
205+
115206
@with_capella_and_later
116207
@spec_configured_state_test({"CAPELLA_FORK_EPOCH": 0}, activate_at_genesis=True)
117208
def test_gossip_bls_to_execution_change__ignore_already_seen(spec, state):

0 commit comments

Comments
 (0)