From 9c2dfba843c2210df161537f186eb87cb3c18bda Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 20 Mar 2019 10:47:19 +1100 Subject: [PATCH] Operation pool: prune attestations --- eth2/operation_pool/src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/eth2/operation_pool/src/lib.rs b/eth2/operation_pool/src/lib.rs index 93ff74652..4932a7e0a 100644 --- a/eth2/operation_pool/src/lib.rs +++ b/eth2/operation_pool/src/lib.rs @@ -161,8 +161,18 @@ impl OperationPool { .collect() } - pub fn prune_attestations(&self, _finalized_state: &BeaconState, _spec: &ChainSpec) { - // TODO + /// Remove attestations which are too old to be included in a block. + // TODO: we could probably prune other attestations here: + // - ones that are completely covered by attestations included in the state + // - maybe ones invalidated by the confirmation of one fork over another + pub fn prune_attestations(&mut self, finalized_state: &BeaconState, spec: &ChainSpec) { + self.attestations.retain(|_, attestations| { + // All the attestations in this bucket have the same data, so we only need to + // check the first one. + attestations.first().map_or(false, |att| { + finalized_state.slot < att.data.slot + spec.slots_per_epoch + }) + }); } /// Add a deposit to the pool.