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
1 change: 1 addition & 0 deletions lean_client/fork_choice/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ fn process_block_internal(
"Store justified checkpoint updated!"
);
store.latest_justified = new_state.latest_justified.clone();
store.justified_ever_updated = true;
METRICS.get().map(|metrics| {
let Some(slot) = new_state.latest_justified.slot.0.try_into().ok() else {
warn!("unable to set latest_justified slot in metrics");
Expand Down
8 changes: 8 additions & 0 deletions lean_client/fork_choice/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ pub struct Store {

pub latest_finalized: Checkpoint,

/// Set to `true` the first time `on_block` drives a justified checkpoint
/// update beyond the initial anchor value. Validator duties (attestation,
/// block proposal) must not run while this is `false` — the store's
/// `latest_justified` is still the placeholder anchor checkpoint and using
/// it as an attestation source would produce wrong source checkpoints.
pub justified_ever_updated: bool,

pub blocks: HashMap<H256, Block>,

pub states: HashMap<H256, State>,
Expand Down Expand Up @@ -209,6 +216,7 @@ pub fn get_forkchoice_store(
safe_target: block_root,
latest_justified,
latest_finalized,
justified_ever_updated: false,
blocks: [(block_root, block)].into(),
states: [(block_root, anchor_state)].into(),
latest_known_attestations: HashMap::new(),
Expand Down
16 changes: 14 additions & 2 deletions lean_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,8 +997,20 @@ async fn main() -> Result<()> {
let _ = sender.send(result);
}
ValidatorChainMessage::BuildAttestationData { slot, sender } => {
let result = store.read().produce_attestation_data(slot);
let _ = sender.send(result);
let store_read = store.read();
if !store_read.justified_ever_updated {
warn!(
slot = slot.0,
"Skipping attestation: justified checkpoint has not yet \
advanced from anchor — node is not ready to attest"
);
let _ = sender.send(Err(anyhow::anyhow!(
"not ready: justified checkpoint has not advanced from anchor value"
)));
} else {
let result = store_read.produce_attestation_data(slot);
let _ = sender.send(result);
}
}
}
}
Expand Down
Loading