From aa5a2d0eb9537f614a1dbdf9820e75455fc5f1b9 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 5 Oct 2023 16:19:35 +1300 Subject: [PATCH] Silencing unecessary warning when handling sync committee messages (#7577) --- .../SyncCommitteeMessagePool.java | 16 ++++++++--- .../SyncCommitteeMessagePoolTest.java | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePool.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePool.java index b7c640fac09..11f7b9cddd3 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePool.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePool.java @@ -25,6 +25,8 @@ import java.util.Objects; import java.util.Optional; import java.util.TreeMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes32; import tech.pegasys.teku.bls.BLS; import tech.pegasys.teku.bls.BLSSignature; @@ -40,6 +42,9 @@ import tech.pegasys.teku.statetransition.validation.InternalValidationResult; public class SyncCommitteeMessagePool implements SlotEventsChannel { + + private static final Logger LOG = LogManager.getLogger(); + private final Subscribers> subscribers = Subscribers.create(true); @@ -175,11 +180,14 @@ private static class ContributionData { public void add(final IntSet participationIndices, final BLSSignature signature) { IntIterator iterator = participationIndices.iterator(); while (iterator.hasNext()) { - int index = iterator.nextInt(); - if (!this.participationIndices.add(index)) { - throw new IllegalStateException("Already added " + index); + final int index = iterator.nextInt(); + if (this.participationIndices.add(index)) { + this.signatures.add(signature); + } else { + LOG.trace( + "Ignoring already aggregated signature from subcommittee participant index = {}", + index); } - this.signatures.add(signature); } } diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePoolTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePoolTest.java index ccf394eeedc..7ee21306e61 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePoolTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/synccommittee/SyncCommitteeMessagePoolTest.java @@ -246,6 +246,34 @@ void shouldIncludeRemoteMessageInContributionOnlyOnReceivedSubnet() { assertThat(pool.createContribution(slot, blockRoot, 5)).isEmpty(); } + @Test + public void + shouldNotAggregateSignaturesFromRepeatedMessagesWhenSameSubcommitteeParticipationId() { + final SyncCommitteeMessage syncCommitteeMessage = + dataStructureUtil.randomSyncCommitteeMessage(); + + final ValidatableSyncCommitteeMessage message = + ValidatableSyncCommitteeMessage.fromNetwork(syncCommitteeMessage, 1); + message.setSubcommitteeAssignments( + SyncSubcommitteeAssignments.builder().addAssignment(1, 1).build()); + + addValidRemote(message); + // Duplicated message, should not aggregate signature a second time + addValidRemote(message); + + final BLSSignature signature = message.getMessage().getSignature(); + // Single signature expected on aggregate + final BLSSignature expectedAggregate = BLS.aggregate(List.of(signature)); + + final UInt64 slot = message.getSlot(); + final Bytes32 blockRoot = message.getBeaconBlockRoot(); + + final Optional contribution = + pool.createContribution(slot, blockRoot, 1); + assertThat(contribution).isPresent(); + assertThat(contribution.orElseThrow().getSignature()).isEqualTo(expectedAggregate); + } + @Test void shouldAggregateSignatureMultipleTimesWhenValidatorInSameSubcommitteeMultipleTimes() { final ValidatableSyncCommitteeMessage message =