From 3ae7cd975cc99f12b7a656c44ac6ac284db4fcd3 Mon Sep 17 00:00:00 2001 From: Tuyen Nguyen Date: Sat, 9 Dec 2023 15:01:43 +0700 Subject: [PATCH] fix: clone attestations for block inclusion --- .../src/chain/opPools/aggregatedAttestationPool.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts b/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts index f9911275b6e..00309d322a1 100644 --- a/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts +++ b/packages/beacon-node/src/chain/opPools/aggregatedAttestationPool.ts @@ -166,10 +166,16 @@ export class AggregatedAttestationPool { } } - return attestationsByScore - .sort((a, b) => b.score - a.score) - .slice(0, MAX_ATTESTATIONS) - .map((attestation) => attestation.attestation); + const sortedAttestationsByScore = attestationsByScore.sort((a, b) => b.score - a.score); + const attestationsForBlock: phase0.Attestation[] = []; + for (const [i, attestationWithScore] of sortedAttestationsByScore.entries()) { + if (i >= MAX_ATTESTATIONS) { + break; + } + // attestations could be modified in this op pool, so we need to clone for block + attestationsForBlock.push(ssz.phase0.Attestation.clone(attestationWithScore.attestation)); + } + return attestationsForBlock; } /**