Skip to content

Commit c8d7ab7

Browse files
committed
fix(operation-pool): include only chain-matching attestations
1 parent 73c5fc0 commit c8d7ab7

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • crates/common/operation_pool/src

crates/common/operation_pool/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ impl OperationPool {
219219
let target_epoch = compute_epoch_at_slot(key.slot);
220220
(target_epoch == current_epoch || target_epoch == previous_epoch)
221221
&& key.slot + MIN_ATTESTATION_INCLUSION_DELAY <= state.slot
222+
&& attestations
223+
.get(*key)
224+
.and_then(|group| group.first())
225+
.is_some_and(|attestation| attestation_matches_state(attestation, state))
222226
})
223227
.collect();
224228
keys.sort_by_key(|key| std::cmp::Reverse(key.slot));
@@ -273,6 +277,25 @@ impl OperationPool {
273277
}
274278
}
275279

280+
fn attestation_matches_state(attestation: &Attestation, state: &BeaconState) -> bool {
281+
let data = &attestation.data;
282+
let target_epoch = compute_epoch_at_slot(data.slot);
283+
let expected_source = if target_epoch == state.get_current_epoch() {
284+
state.current_justified_checkpoint
285+
} else {
286+
state.previous_justified_checkpoint
287+
};
288+
289+
data.target.epoch == target_epoch
290+
&& data.source == expected_source
291+
&& state
292+
.get_block_root(target_epoch)
293+
.is_ok_and(|target_root| data.target.root == target_root)
294+
&& state
295+
.get_block_root_at_slot(data.slot)
296+
.is_ok_and(|block_root| data.beacon_block_root == block_root)
297+
}
298+
276299
/// Aggregate non-overlapping votes from the same attestation group.
277300
fn aggregate_attestation_group(group: &[Attestation]) -> Option<Attestation> {
278301
let mut aggregate = group.first()?.clone();

0 commit comments

Comments
 (0)