Skip to content

Commit 7ce4939

Browse files
authored
feat: opPool to allow late api attestations (#7553)
**Motivation** - api attestations could be late but we should allow them to be added to OpPool in that case see #7548 (comment) **Description** - add flag to oppool to specify a priority (api) attestation. This is the same to the way we do attestation validation https://github.com/ChainSafe/lodestar/blob/ca29dbb8edad29e1eb5ac2c576059abcb1c82ec7/packages/beacon-node/src/chain/validation/attestation.ts#L209 - same feature for SyncCommittee part of #7548 --------- Co-authored-by: Tuyen Nguyen <twoeths@users.noreply.github.com>
1 parent 4a35371 commit 7ce4939

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

packages/beacon-node/src/api/impl/beacon/pool/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export function getBeaconPoolApi({
104104
async submitPoolAttestationsV2({signedAttestations}) {
105105
const seenTimestampSec = Date.now() / 1000;
106106
const failures: FailureList = [];
107+
// api attestation has high priority, we allow them to be added to pool even when it's late
108+
// this is to prevent "No aggregated attestation for slot" issue
109+
// see https://github.com/ChainSafe/lodestar/issues/7548
110+
const priority = true;
107111

108112
await Promise.all(
109113
signedAttestations.map(async (attestation, i) => {
@@ -123,7 +127,8 @@ export function getBeaconPoolApi({
123127
attestation,
124128
attDataRootHex,
125129
committeeValidatorIndex,
126-
committeeSize
130+
committeeSize,
131+
priority
127132
);
128133
metrics?.opPool.attestationPoolApiInsertOutcome.inc({insertOutcome});
129134
}
@@ -264,12 +269,15 @@ export function getBeaconPoolApi({
264269
// The same validator can appear multiple times in the sync committee. It can appear multiple times per
265270
// subnet even. First compute on which subnet the signature must be broadcasted to.
266271
const subnets: number[] = [];
272+
// same to api attestation, we allow api SyncCommittee to be added to pool even when it's late
273+
// see https://github.com/ChainSafe/lodestar/issues/7548
274+
const priority = true;
267275

268276
for (const indexInCommittee of indexesInCommittee) {
269277
// Sync committee subnet members are just sequential in the order they appear in SyncCommitteeIndexes array
270278
const subnet = Math.floor(indexInCommittee / SYNC_COMMITTEE_SUBNET_SIZE);
271279
const indexInSubcommittee = indexInCommittee % SYNC_COMMITTEE_SUBNET_SIZE;
272-
chain.syncCommitteeMessagePool.add(subnet, signature, indexInSubcommittee);
280+
chain.syncCommitteeMessagePool.add(subnet, signature, indexInSubcommittee, priority);
273281

274282
// Cheap de-duplication code to avoid using a Set. indexesInCommittee is always sorted
275283
if (subnets.length === 0 || subnets[subnets.length - 1] !== subnet) {

packages/beacon-node/src/chain/opPools/attestationPool.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export class AttestationPool {
110110
attestation: SingleAttestation,
111111
attDataRootHex: RootHex,
112112
committeeValidatorIndex: number,
113-
committeeSize: number
113+
committeeSize: number,
114+
priority?: boolean
114115
): InsertOutcome {
115116
const slot = attestation.data.slot;
116117
const fork = this.config.getForkName(slot);
@@ -121,8 +122,9 @@ export class AttestationPool {
121122
return InsertOutcome.Old;
122123
}
123124

124-
// Reject attestations in the current slot but come to this pool very late
125-
if (this.clock.secFromSlot(slot) > this.cutOffSecFromSlot) {
125+
// Reject gossip attestations in the current slot but come to this pool very late
126+
// for api attestations, we allow them to be added to the pool
127+
if (!priority && this.clock.secFromSlot(slot) > this.cutOffSecFromSlot) {
126128
return InsertOutcome.Late;
127129
}
128130

packages/beacon-node/src/chain/opPools/syncCommitteeMessagePool.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export class SyncCommitteeMessagePool {
6161
}
6262

6363
// TODO: indexInSubcommittee: number should be indicesInSyncCommittee
64-
add(subnet: SubnetID, signature: altair.SyncCommitteeMessage, indexInSubcommittee: number): InsertOutcome {
64+
add(
65+
subnet: SubnetID,
66+
signature: altair.SyncCommitteeMessage,
67+
indexInSubcommittee: number,
68+
priority?: boolean
69+
): InsertOutcome {
6570
const {slot, beaconBlockRoot} = signature;
6671
const rootHex = toRootHex(beaconBlockRoot);
6772
const lowestPermissibleSlot = this.lowestPermissibleSlot;
@@ -72,7 +77,7 @@ export class SyncCommitteeMessagePool {
7277
}
7378

7479
// validator gets SyncCommitteeContribution at 2/3 of slot, it's no use to preaggregate later than that time
75-
if (this.clock.secFromSlot(slot) > this.cutOffSecFromSlot) {
80+
if (!priority && this.clock.secFromSlot(slot) > this.cutOffSecFromSlot) {
7681
return InsertOutcome.Late;
7782
}
7883

0 commit comments

Comments
 (0)