Restrict blop pool from re-including attestations
This commit is contained in:
parent
64507950dd
commit
c2b6f949c0
@ -48,7 +48,8 @@ test_cases:
|
|||||||
- slot: 63
|
- slot: 63
|
||||||
num_validators: 1003
|
num_validators: 1003
|
||||||
num_previous_epoch_attestations: 0
|
num_previous_epoch_attestations: 0
|
||||||
num_current_epoch_attestations: 10
|
# slots_per_epoch - attestation_inclusion_delay - skip_slots
|
||||||
|
num_current_epoch_attestations: 57
|
||||||
slashed_validators: [11, 12, 13, 14, 42]
|
slashed_validators: [11, 12, 13, 14, 42]
|
||||||
exited_validators: []
|
exited_validators: []
|
||||||
exit_initiated_validators: [50]
|
exit_initiated_validators: [50]
|
||||||
|
@ -172,6 +172,8 @@ impl OperationPool {
|
|||||||
|| key.domain_bytes_match(&curr_domain_bytes)
|
|| key.domain_bytes_match(&curr_domain_bytes)
|
||||||
})
|
})
|
||||||
.flat_map(|(_, attestations)| attestations)
|
.flat_map(|(_, attestations)| attestations)
|
||||||
|
// That are not superseded by an attestation included in the state...
|
||||||
|
.filter(|attestation| !superior_attestation_exists_in_state(state, attestation))
|
||||||
// That are valid...
|
// That are valid...
|
||||||
.filter(|attestation| validate_attestation(state, attestation, spec).is_ok())
|
.filter(|attestation| validate_attestation(state, attestation, spec).is_ok())
|
||||||
// Scored by the number of new attestations they introduce (descending)
|
// Scored by the number of new attestations they introduce (descending)
|
||||||
@ -462,6 +464,31 @@ impl OperationPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the state already contains a `PendingAttestation` that is superior to the
|
||||||
|
/// given `attestation`.
|
||||||
|
///
|
||||||
|
/// A validator has nothing to gain from re-including an attestation and it adds load to the
|
||||||
|
/// network.
|
||||||
|
///
|
||||||
|
/// An existing `PendingAttestation` is superior to an existing `attestation` if:
|
||||||
|
///
|
||||||
|
/// - Their `AttestationData` is equal.
|
||||||
|
/// - `attestation` does not contain any signatures that `PendingAttestation` does not have.
|
||||||
|
fn superior_attestation_exists_in_state(state: &BeaconState, attestation: &Attestation) -> bool {
|
||||||
|
state
|
||||||
|
.current_epoch_attestations
|
||||||
|
.iter()
|
||||||
|
.chain(state.previous_epoch_attestations.iter())
|
||||||
|
.any(|existing_attestation| {
|
||||||
|
let bitfield = &attestation.aggregation_bitfield;
|
||||||
|
let existing_bitfield = &existing_attestation.aggregation_bitfield;
|
||||||
|
|
||||||
|
existing_attestation.data == attestation.data
|
||||||
|
&& bitfield.intersection(existing_bitfield).num_set_bits()
|
||||||
|
== bitfield.num_set_bits()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Filter up to a maximum number of operations out of an iterator.
|
/// Filter up to a maximum number of operations out of an iterator.
|
||||||
fn filter_limit_operations<'a, T: 'a, I, F>(operations: I, filter: F, limit: u64) -> Vec<T>
|
fn filter_limit_operations<'a, T: 'a, I, F>(operations: I, filter: F, limit: u64) -> Vec<T>
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user