Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/net/rpc/src/beacon/ptc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn aggregate_pool(
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::{RecordingNetwork, gloas_beacon_block};
use crate::test_utils::{RecordingNetwork, gloas_beacon_block, slot_root};
use axum::{body::Body, http::Request};
use ethlambda_state_transition::beacon::{
constants::DOMAIN_PTC_ATTESTER,
Expand Down Expand Up @@ -571,7 +571,7 @@ mod tests {
// Distinct roots per slot, so a `dependent_root` read from the wrong
// slot shows up.
for slot in 0..inner.block_roots.len() {
inner.block_roots[slot] = H256::repeat_byte(slot as u8 + 1);
inner.block_roots[slot] = slot_root(slot as u64);
}
for index in 0..preset::PTC_WINDOW_LENGTH {
inner.ptc_window[index] = vec![index as u64; preset::PTC_SIZE]
Expand Down Expand Up @@ -739,7 +739,7 @@ mod tests {
let expected = if dependent_slot >= head_slot {
head_root
} else {
H256::repeat_byte(dependent_slot as u8 + 1)
slot_root(dependent_slot)
};
assert_eq!(json["dependent_root"], format!("{expected:?}"));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/net/rpc/src/beacon/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ fn payload_present_index(
#[cfg(test)]
mod tests {
use super::*;
use crate::test_utils::{beacon_store_at, idle_engine};
use crate::test_utils::{beacon_store_at, idle_engine, slot_root};
use axum::{
body::Body,
http::{Request, StatusCode},
Expand All @@ -893,7 +893,7 @@ mod tests {
};
fulu.proposer_lookahead = lookahead.try_into().unwrap();
for slot in 0..fulu.block_roots.len() {
fulu.block_roots[slot] = H256::repeat_byte(slot as u8 + 1);
fulu.block_roots[slot] = slot_root(slot as u64);
}
state
}
Expand Down
13 changes: 13 additions & 0 deletions crates/net/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,19 @@ pub(crate) mod test_utils {
Some(client.expect("building a client opens no connection"))
}

/// A block root of its own for every `slot`, never the zero hash: `slot + 1`
/// in the last eight bytes, big-endian.
///
/// For filling a state's `block_roots` so a root read from the wrong slot
/// shows up. `H256::repeat_byte(slot as u8 + 1)` cannot do that: the window
/// is `SLOTS_PER_HISTORICAL_ROOT` long, more slots than a byte counts, so it
/// overflows at slot 255 (a panic in debug, repeating roots in release).
pub(crate) fn slot_root(slot: u64) -> H256 {
let mut root = [0; 32];
root[24..].copy_from_slice(&(slot + 1).to_be_bytes());
H256(root)
}

/// A beacon store whose anchor, and so head, is `state`, under a block at
/// the state's slot. Returns the store and that block's root.
///
Expand Down
Loading