Skip to content

Commit

Permalink
Skip checking known participants when publishing ContributionAndProof (
Browse files Browse the repository at this point in the history
…#4097)

* Skip checking known participants when publishing ContributionAndProof

* chore: merge if statements
  • Loading branch information
twoeths authored Jun 8, 2022
1 parent 719d936 commit a3e286f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/lodestar/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ export function getValidatorApi({chain, config, logger, metrics, network, sync}:
// TODO: Validate in batch
const {syncCommitteeParticipants} = await validateSyncCommitteeGossipContributionAndProof(
chain,
contributionAndProof
contributionAndProof,
true // skip known participants check
);
chain.syncContributionAndProofPool.add(contributionAndProof.message, syncCommitteeParticipants);
await network.gossip.publishContributionAndProof(contributionAndProof);
Expand Down
19 changes: 10 additions & 9 deletions packages/lodestar/src/chain/validation/aggregateAndProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ export async function validateGossipAggregateAndProof(
// [IGNORE] The aggregate is the first valid aggregate received for the aggregator with
// index aggregate_and_proof.aggregator_index for the epoch aggregate.data.target.epoch.
const aggregatorIndex = aggregateAndProof.aggregatorIndex;
if (!skipValidationKnownAttesters) {
if (chain.seenAggregators.isKnown(targetEpoch, aggregatorIndex)) {
throw new AttestationError(GossipAction.IGNORE, {
code: AttestationErrorCode.AGGREGATOR_ALREADY_KNOWN,
targetEpoch,
aggregatorIndex,
});
}
if (chain.seenAggregators.isKnown(targetEpoch, aggregatorIndex)) {
throw new AttestationError(GossipAction.IGNORE, {
code: AttestationErrorCode.AGGREGATOR_ALREADY_KNOWN,
targetEpoch,
aggregatorIndex,
});
}

// _[IGNORE]_ A valid aggregate attestation defined by `hash_tree_root(aggregate.data)` whose `aggregation_bits`
// is a non-strict superset has _not_ already been seen.
if (chain.seenAggregatedAttestations.isKnown(targetEpoch, attDataRoot, aggregationBits)) {
if (
!skipValidationKnownAttesters &&
chain.seenAggregatedAttestations.isKnown(targetEpoch, attDataRoot, aggregationBits)
) {
throw new AttestationError(GossipAction.IGNORE, {
code: AttestationErrorCode.ATTESTERS_ALREADY_KNOWN,
targetEpoch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
*/
export async function validateSyncCommitteeGossipContributionAndProof(
chain: IBeaconChain,
signedContributionAndProof: altair.SignedContributionAndProof
signedContributionAndProof: altair.SignedContributionAndProof,
skipValidationKnownParticipants = false
): Promise<{syncCommitteeParticipants: number}> {
const contributionAndProof = signedContributionAndProof.message;
const {contribution, aggregatorIndex} = contributionAndProof;
Expand All @@ -37,7 +38,7 @@ export async function validateSyncCommitteeGossipContributionAndProof(

// _[IGNORE]_ A valid sync committee contribution with equal `slot`, `beacon_block_root` and `subcommittee_index` whose
// `aggregation_bits` is non-strict superset has _not_ already been seen.
if (chain.seenContributionAndProof.participantsKnown(contribution)) {
if (!skipValidationKnownParticipants && chain.seenContributionAndProof.participantsKnown(contribution)) {
throw new SyncCommitteeError(GossipAction.IGNORE, {
code: SyncCommitteeErrorCode.SYNC_COMMITTEE_PARTICIPANTS_ALREADY_KNOWN,
});
Expand Down

0 comments on commit a3e286f

Please sign in to comment.