From 003a4445ac168808d96ca43ba6551adbd5f9230e Mon Sep 17 00:00:00 2001 From: tuyennhv Date: Sat, 9 Dec 2023 15:49:40 +0700 Subject: [PATCH] fix: clone attestations for block inclusion (#6174) --- .../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 f9911275b6ee..00309d322a11 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; } /**