Skip to content

Commit dead5e9

Browse files
authored
fix(p2p): remove legacy step field from BlocksByRange request (lambdaclass#365)
## Summary - Drop the legacy phase-0 `step: u64` field from `BlocksByRangeRequest`. The leanSpec container has only `(start_slot, count)`; `step` was deprecated in Altair and explicitly omitted from the lean spec. - Without this fix, SSZ decode requires 24 bytes while peers (and the ethereum/hive lean simulator) send the spec-compliant 16-byte encoding, so every inbound BlocksByRange request fails to decode before reaching the handler. - Remove the now-dead `step == 0` validation and simplify `canonical_blocks_by_range` to walk contiguous slots; update the existing unit test to the new signature. ## Test plan - [x] `cargo test -p ethlambda-p2p` - [x] Verified against hive's `reqresp/blocks_by_range` suite: all 4 tests pass (previously hung at fixture timeout because the SSZ decode error prevented any response).
1 parent c5705af commit dead5e9

2 files changed

Lines changed: 7 additions & 22 deletions

File tree

crates/net/p2p/src/req_resp/handlers.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ async fn handle_blocks_by_range_request(
156156
%peer,
157157
start_slot = request.start_slot,
158158
count = request.count,
159-
step = request.step,
160159
"Received BlocksByRange request"
161160
);
162161

163-
if request.step == 0 || request.count == 0 || request.count > MAX_REQUEST_BLOCKS {
162+
if request.count == 0 || request.count > MAX_REQUEST_BLOCKS {
164163
let response = Response::error(
165164
ResponseCode::INVALID_REQUEST,
166165
error_message("invalid BlocksByRange request"),
@@ -169,18 +168,12 @@ async fn handle_blocks_by_range_request(
169168
return;
170169
}
171170

172-
let blocks = canonical_blocks_by_range(
173-
&server.store,
174-
request.start_slot,
175-
request.count,
176-
request.step,
177-
);
171+
let blocks = canonical_blocks_by_range(&server.store, request.start_slot, request.count);
178172

179173
info!(
180174
%peer,
181175
start_slot = request.start_slot,
182176
count = request.count,
183-
step = request.step,
184177
found = blocks.len(),
185178
"Responding to BlocksByRange request"
186179
);
@@ -189,19 +182,13 @@ async fn handle_blocks_by_range_request(
189182
server.swarm_handle.send_response(channel, response);
190183
}
191184

192-
fn canonical_blocks_by_range(
193-
store: &Store,
194-
start_slot: u64,
195-
count: u64,
196-
step: u64,
197-
) -> Vec<SignedBlock> {
185+
fn canonical_blocks_by_range(store: &Store, start_slot: u64, count: u64) -> Vec<SignedBlock> {
198186
if count == 0 {
199187
return Vec::new();
200188
}
201189

202190
let Some(end_slot) = count
203191
.checked_sub(1)
204-
.and_then(|value| value.checked_mul(step))
205192
.and_then(|last_offset| start_slot.checked_add(last_offset))
206193
else {
207194
return Vec::new();
@@ -219,16 +206,15 @@ fn canonical_blocks_by_range(
219206
break;
220207
}
221208

222-
if header.slot <= end_slot && (header.slot - start_slot).is_multiple_of(step) {
209+
if header.slot <= end_slot {
223210
roots_by_slot.insert(header.slot, current_root);
224211
}
225212

226213
current_root = header.parent_root;
227214
}
228215

229-
(0..count)
230-
.filter_map(|index| {
231-
let slot = start_slot.checked_add(index.checked_mul(step)?)?;
216+
(start_slot..=end_slot)
217+
.filter_map(|slot| {
232218
let root = roots_by_slot.get(&slot)?;
233219
store.get_signed_block(root)
234220
})
@@ -460,7 +446,7 @@ mod tests {
460446
store.insert_signed_block(root_4, block_4);
461447
store.update_checkpoints(ForkCheckpoints::head_only(root_4));
462448

463-
let blocks = canonical_blocks_by_range(&store, 1, 4, 1);
449+
let blocks = canonical_blocks_by_range(&store, 1, 4);
464450
let slots: Vec<_> = blocks.iter().map(|block| block.message.slot).collect();
465451
let roots: Vec<_> = blocks
466452
.iter()

crates/net/p2p/src/req_resp/messages.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,4 @@ pub struct BlocksByRootRequest {
136136
pub struct BlocksByRangeRequest {
137137
pub start_slot: u64,
138138
pub count: u64,
139-
pub step: u64,
140139
}

0 commit comments

Comments
 (0)