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
8 changes: 7 additions & 1 deletion lean_client/containers/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ pub struct SignedBlock {
}

impl SignedBlock {
pub fn verify_signatures(&self, parent_state: State) -> Result<()> {
/// Verify all XMSS signatures in this signed block.
///
/// Verifies each aggregated attestation proof against the participant
/// validator public keys from parent state.
///
/// Returns `Ok(())` if all signatures are valid, or an error describing the failure.
pub fn verify_signatures(&self, parent_state: &State) -> Result<()> {
let block = &self.block;
let aggregated_attestations = &block.body.attestations;

Expand Down
4 changes: 2 additions & 2 deletions lean_client/containers/tests/test_vectors/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ impl TestRunner {
println!(" Expecting exception: {}", exception);

// Verify signatures - we expect this to fail (return Err)
match signed_block.verify_signatures(anchor_state) {
match signed_block.verify_signatures(&anchor_state) {
Ok(()) => {
println!(
" \x1b[31m✗ FAIL: Signatures verified successfully but should have failed!\x1b[0m\n"
Expand All @@ -734,7 +734,7 @@ impl TestRunner {
}
}

match signed_block.verify_signatures(anchor_state) {
match signed_block.verify_signatures(&anchor_state) {
Ok(()) => {
println!(" ✓ All signatures verified successfully");
println!("\n\x1b[32m✓ PASS\x1b[0m\n");
Expand Down
7 changes: 4 additions & 3 deletions lean_client/fork_choice/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ pub fn on_block(
/// driving the function with synthetic signature placeholders (e.g. spec-test fixtures
/// that ship unsigned blocks).
pub fn verify_and_transition(
parent_state: State,
parent_state: Arc<State>,
signed_block: SignedBlock,
verify_signatures: bool,
) -> Result<State> {
Expand All @@ -699,7 +699,7 @@ pub fn verify_and_transition(
});

if verify_signatures {
signed_block.verify_signatures(parent_state.clone())?;
signed_block.verify_signatures(&parent_state)?;
}
parent_state.state_transition(&signed_block.block)
}
Expand All @@ -714,6 +714,7 @@ pub fn apply_verified_block(
block_root: H256,
) -> Result<()> {
let block = signed_block.block.clone();
let new_state = Arc::new(new_state);

tracing::debug!(
block_slot = block.slot.0,
Expand All @@ -724,7 +725,7 @@ pub fn apply_verified_block(
);

store.blocks.insert(block_root, block.clone());
store.states.insert(block_root, new_state.clone());
store.states.insert(block_root, Arc::clone(&new_state));

METRICS.get().map(|m| {
m.grandine_store_blocks_size.set(store.blocks.len() as i64);
Expand Down
11 changes: 7 additions & 4 deletions lean_client/fork_choice/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{HashMap, HashSet};
use std::sync::Arc;

use anyhow::{Result, anyhow, ensure};
use containers::{
Expand Down Expand Up @@ -64,7 +65,9 @@ pub struct Store {

pub blocks: HashMap<H256, Block>,

pub states: HashMap<H256, State>,
/// States are stored behind `Arc` so the many places that hand out a
/// snapshot of a state instead of deep-copying the whole state.
pub states: HashMap<H256, Arc<State>>,

pub latest_known_attestations: HashMap<u64, AttestationData>,

Expand Down Expand Up @@ -266,7 +269,7 @@ pub fn get_forkchoice_store(
},
states: {
let mut m = HashMap::new();
m.insert(block_root, anchor_state);
m.insert(block_root, Arc::new(anchor_state));
m
},
latest_known_attestations: HashMap::new(),
Expand Down Expand Up @@ -369,7 +372,7 @@ pub fn get_fork_choice_head(
}
}

pub fn get_latest_justified(states: &HashMap<H256, State>) -> Option<&Checkpoint> {
pub fn get_latest_justified(states: &HashMap<H256, Arc<State>>) -> Option<&Checkpoint> {
states
.values()
.map(|state| &state.latest_justified)
Expand Down Expand Up @@ -616,7 +619,7 @@ pub struct BlockProductionInputs {
pub slot: Slot,
pub validator_index: u64,
pub head_root: H256,
pub head_state: State,
pub head_state: Arc<State>,
pub known_block_roots: HashSet<H256>,
/// Joined view of `latest_known_aggregated_payloads` keyed by `data_root`,
/// with the `AttestationData` carried in the value. Entries whose
Expand Down
2 changes: 1 addition & 1 deletion lean_client/http_api/src/test_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async fn run_verify_signatures(
}
};

Json(match signed_block.verify_signatures(anchor_state) {
Json(match signed_block.verify_signatures(&anchor_state) {
Ok(()) => VerifySignaturesResponse {
succeeded: true,
error: None,
Expand Down
2 changes: 1 addition & 1 deletion lean_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ async fn main() -> Result<()> {
// proposer_signature is NOT covered by the hash — verify it
// explicitly so a peer serving a validly-hashed but unsigned
// block cannot become our anchor.
match signed_block.verify_signatures(anchor_state.clone()) {
match signed_block.verify_signatures(&anchor_state) {
Ok(()) => {
info!(
slot = signed_block.block.slot.0,
Expand Down
Loading