diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/PooledAttestationWithData.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/PooledAttestationWithData.java index f29b6d7ce70..27e1e7b6754 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/PooledAttestationWithData.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/PooledAttestationWithData.java @@ -21,9 +21,9 @@ public record PooledAttestationWithData(AttestationData data, PooledAttestation public Attestation toAttestation(final AttestationSchema attestationSchema) { return attestationSchema.create( - pooledAttestation.bits().getAggregationBits(), + pooledAttestation.bits().getAggregationSszBits(), data, pooledAttestation.aggregatedSignature(), - pooledAttestation.bits()::getCommitteeBits); + pooledAttestation.bits()::getCommitteeSszBits); } } diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBits.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBits.java index 3132c7971d7..a6db2e46af6 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBits.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBits.java @@ -69,9 +69,9 @@ static AttestationBits of( boolean isSuperSetOf(AttestationBits other); - SszBitlist getAggregationBits(); + SszBitlist getAggregationSszBits(); - SszBitvector getCommitteeBits(); + SszBitvector getCommitteeSszBits(); Int2IntMap getCommitteesSize(); diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectra.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectra.java index d57aed91431..f26d276b351 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectra.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectra.java @@ -39,8 +39,8 @@ class AttestationBitsElectra implements AttestationBits { private Int2ObjectMap committeeAggregationBitsMap; private BitSet committeeBits; - private SszBitlist cachedAggregationBits = null; - private SszBitvector cachedCommitteeBits = null; + private SszBitlist cachedAggregationSszBits = null; + private SszBitvector cachedCommitteeSszBits = null; AttestationBitsElectra( final SszBitlist initialAggregationBits, @@ -249,9 +249,9 @@ private boolean isSuperSetOf( } @Override - public SszBitlist getAggregationBits() { - if (cachedAggregationBits != null) { - return cachedAggregationBits; + public SszBitlist getAggregationSszBits() { + if (cachedAggregationSszBits != null) { + return cachedAggregationSszBits; } final List committeeIndicesInOrder = new ArrayList<>(); for (int i = committeeBits.nextSetBit(0); i >= 0; i = committeeBits.nextSetBit(i + 1)) { @@ -279,24 +279,24 @@ public SszBitlist getAggregationBits() { } currentOffset += committeeSize; } - cachedAggregationBits = + cachedAggregationSszBits = aggregationBitsSchema.wrapBitSet(totalBitlistSize, combinedAggregationBits); - return cachedAggregationBits; + return cachedAggregationSszBits; } @Override - public SszBitvector getCommitteeBits() { - if (cachedCommitteeBits == null) { - cachedCommitteeBits = + public SszBitvector getCommitteeSszBits() { + if (cachedCommitteeSszBits == null) { + cachedCommitteeSszBits = committeeBitsSchema.wrapBitSet( committeeBitsSchema.getLength(), (BitSet) this.committeeBits.clone()); } - return cachedCommitteeBits; + return cachedCommitteeSszBits; } private void invalidateCache() { - this.cachedAggregationBits = null; - this.cachedCommitteeBits = null; + this.cachedAggregationSszBits = null; + this.cachedCommitteeSszBits = null; } @Override @@ -359,7 +359,7 @@ public String toString() { .add("committeeBits", committeeBits.cardinality()) .add("committeeAggregationBitsMap", totalSetBits) .add("committeesSize", committeesSize.size()) - .add("cached", cachedAggregationBits != null || cachedCommitteeBits != null) + .add("sszBitsCached", cachedAggregationSszBits != null || cachedCommitteeSszBits != null) .toString(); } diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsPhase0.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsPhase0.java index f23ded66f54..d713b381a08 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsPhase0.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsPhase0.java @@ -66,12 +66,12 @@ public boolean isSuperSetOf(final AttestationBits other) { } @Override - public SszBitlist getAggregationBits() { + public SszBitlist getAggregationSszBits() { return aggregationBits; } @Override - public SszBitvector getCommitteeBits() { + public SszBitvector getCommitteeSszBits() { throw new IllegalStateException("Committee bits not available in phase0"); } diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java index f0095fc985f..0a4d1259b44 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupTest.java @@ -444,10 +444,10 @@ private PooledAttestation createPooledAttestation( private Attestation toAttestation(final PooledAttestation pooledAttestation) { return attestationSchema.create( - pooledAttestation.bits().getAggregationBits(), + pooledAttestation.bits().getAggregationSszBits(), attestationData, pooledAttestation.aggregatedSignature(), - pooledAttestation.bits()::getCommitteeBits); + pooledAttestation.bits()::getCommitteeSszBits); } private PooledAttestationWithData toPooledAttestationWithData( diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupV2Test.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupV2Test.java index b33e6ee4548..19e01b9bcae 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupV2Test.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/MatchingDataAttestationGroupV2Test.java @@ -770,12 +770,13 @@ private List validatorBitToValidatorIndex(final int... validatorBits) { private List validatorBitToValidatorIndex(final AttestationBits bits) { if (!bits.requiresCommitteeBits()) { - return validatorBitToValidatorIndex(bits.getAggregationBits().getAllSetBits().toIntArray()); + return validatorBitToValidatorIndex( + bits.getAggregationSszBits().getAllSetBits().toIntArray()); } // only 2 committees are supported assertThat(committeeSizes.keySet()).isEqualTo(Set.of(0, 1)); - final IntList committeeBits = bits.getCommitteeBits().getAllSetBits(); + final IntList committeeBits = bits.getCommitteeSszBits().getAllSetBits(); assertThat(committeeBits.size()).isLessThanOrEqualTo(2); final List result = new ArrayList<>(); @@ -784,14 +785,18 @@ private List validatorBitToValidatorIndex(final AttestationBits bits) { result.addAll( validatorBitToValidatorIndex( Optional.of(0), - bits.getAggregationBits().getAsBitSet(0, committeeSizes.get(0)).stream().toArray())); + bits.getAggregationSszBits().getAsBitSet(0, committeeSizes.get(0)).stream() + .toArray())); offset = committeeSizes.get(0); } if (committeeBits.contains(1)) { result.addAll( validatorBitToValidatorIndex( Optional.of(1), - bits.getAggregationBits().getAsBitSet(offset, committeeSizes.get(1) + offset).stream() + bits + .getAggregationSszBits() + .getAsBitSet(offset, committeeSizes.get(1) + offset) + .stream() .toArray())); } @@ -800,10 +805,10 @@ private List validatorBitToValidatorIndex(final AttestationBits bits) { private Attestation toAttestation(final PooledAttestation pooledAttestation) { return attestationSchema.create( - pooledAttestation.bits().getAggregationBits(), + pooledAttestation.bits().getAggregationSszBits(), attestationData, pooledAttestation.aggregatedSignature(), - pooledAttestation.bits()::getCommitteeBits); // Supplier for committee bits + pooledAttestation.bits()::getCommitteeSszBits); // Supplier for committee bits } private PooledAttestationWithData toPooledAttestationWithData( diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectraTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectraTest.java index 588a8ab1864..8d8e8975d6e 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectraTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/attestation/utils/AttestationBitsElectraTest.java @@ -74,9 +74,9 @@ void aggregateFromEmpty() { assertThat(aggregator.aggregateWith(attestation)).isTrue(); - assertThat(aggregator.getCommitteeBits().streamAllSetBits()).containsExactly(1); + assertThat(aggregator.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); - assertThat(aggregator.getAggregationBits().streamAllSetBits()).containsExactly(1, 2); + assertThat(aggregator.getAggregationSszBits().streamAllSetBits()).containsExactly(1, 2); } @Test @@ -117,8 +117,8 @@ void aggregateOnSameCommittee() { 111 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 1, 2); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(0, 1, 2); } @Test @@ -142,8 +142,8 @@ void aggregateOnMultipleOverlappingCommitteeBits() { 11|110 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 1, 2, 3); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(0, 1, 2, 3); } @Test @@ -167,8 +167,8 @@ void aggregateOnMultipleOverlappingCommitteeBitsVariation() { 11|111|0001 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1, 2); - assertThat(attestation.getAggregationBits().streamAllSetBits()) + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1, 2); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) .containsExactly(0, 1, 2, 3, 4, 8); } @@ -190,8 +190,8 @@ void cannotAggregateOnMultipleOverlappingCommitteeBitsButWithSomeOfAggregationOv // check remained untouched - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 2); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(0, 2); } @Test @@ -219,8 +219,9 @@ void aggregateOnMultipleOverlappingCommitteeBitsButWithSomeOfAggregationOverlapp 11|110|0001 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1, 2); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 1, 2, 3, 8); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1, 2); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) + .containsExactly(0, 1, 2, 3, 8); } @Test @@ -245,8 +246,8 @@ void aggregateSingleAttestationFillUp() { 10|101 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 2, 4); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(0, 2, 4); } @Test @@ -275,8 +276,8 @@ void aggregateSingleAttestationFillUp() { 11|110|0001 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(2); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 1, 3); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(2); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(0, 1, 3); } @Test @@ -300,8 +301,9 @@ void aggregateOnMultipleDisjointedCommitteeBits() { 10|100|1101 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 1, 2); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(0, 2, 5, 6, 8); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 1, 2); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) + .containsExactly(0, 2, 5, 6, 8); } @Test @@ -325,8 +327,8 @@ void aggregateOnMultipleDisjointedCommitteeBitsVariation() { 01|0001 <- bits */ - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(0, 2); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactly(1, 5); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(0, 2); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()).containsExactly(1, 5); } @Test @@ -398,8 +400,8 @@ void bigAggregation() { 000000000000001000000000000000000000000000000000001\ """); - assertThat(attestation.getCommitteeBits()).isEqualTo(result.getCommitteeBits()); - assertThat(attestation.getAggregationBits()).isEqualTo(result.getAggregationBits()); + assertThat(attestation.getCommitteeSszBits()).isEqualTo(result.getCommitteeSszBits()); + assertThat(attestation.getAggregationSszBits()).isEqualTo(result.getAggregationSszBits()); } @Test @@ -412,8 +414,8 @@ void orIntoEmptyAggregator() { bits.or(otherAttestation); - assertThat(bits.getCommitteeBits().streamAllSetBits()).containsExactly(1); - assertThat(bits.getAggregationBits().streamAllSetBits()).containsExactly(2); + assertThat(bits.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); + assertThat(bits.getAggregationSszBits().streamAllSetBits()).containsExactly(2); } @Test @@ -424,8 +426,10 @@ void orWithNewCommittee() { attestation.or(otherAttestation); - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactlyInAnyOrder(1, 4); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()) + .containsExactlyInAnyOrder(0, 1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) + .containsExactlyInAnyOrder(1, 4); } @Test @@ -437,8 +441,9 @@ void orWithExistingCommitteeAddNewBits() { attestation.or(otherAttestation); - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 2); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) + .containsExactlyInAnyOrder(0, 2); } @Test @@ -449,8 +454,8 @@ void orWithExistingCommitteeOverlapAndNewBits() { attestation.or(otherAttestation); - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(1); - assertThat(attestation.getAggregationBits().streamAllSetBits()) + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) .containsExactlyInAnyOrder(0, 1, 2); } @@ -462,8 +467,9 @@ void orWithStrictSubsetAttestation() { attestation.or(otherAttestation); - assertThat(attestation.getCommitteeBits().streamAllSetBits()).containsExactly(1); - assertThat(attestation.getAggregationBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 2); + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()).containsExactly(1); + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) + .containsExactlyInAnyOrder(0, 2); } @Test @@ -474,9 +480,9 @@ void orWithMultipleCommitteesMixedNewAndExisting() { attestation.or(otherAttestation); - assertThat(attestation.getCommitteeBits().streamAllSetBits()) + assertThat(attestation.getCommitteeSszBits().streamAllSetBits()) .containsExactlyInAnyOrder(0, 1, 2); - assertThat(attestation.getAggregationBits().streamAllSetBits()) + assertThat(attestation.getAggregationSszBits().streamAllSetBits()) .containsExactlyInAnyOrder(0, 3, 4, 7); } @@ -488,12 +494,13 @@ void orAggregatorWithAggregator() { att1Data.or(att2Data); - assertThat(att1Data.getCommitteeBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1); - assertThat(att1Data.getAggregationBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1, 2); + assertThat(att1Data.getCommitteeSszBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1); + assertThat(att1Data.getAggregationSszBits().streamAllSetBits()) + .containsExactlyInAnyOrder(0, 1, 2); // aggregator2 should remain unchanged - assertThat(att2Data.getCommitteeBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1); - assertThat(att2Data.getAggregationBits().streamAllSetBits()).containsExactlyInAnyOrder(1, 2); + assertThat(att2Data.getCommitteeSszBits().streamAllSetBits()).containsExactlyInAnyOrder(0, 1); + assertThat(att2Data.getAggregationSszBits().streamAllSetBits()).containsExactlyInAnyOrder(1, 2); } @Test @@ -513,10 +520,10 @@ void isSuperSetOf_nonPooledAttestation() { final Attestation other = attestationSchema.create( - otherAttestation.getAggregationBits(), + otherAttestation.getAggregationSszBits(), attestationData, dataStructureUtil.randomSignature(), - otherAttestation::getCommitteeBits); + otherAttestation::getCommitteeSszBits); assertThat(attestation.isSuperSetOf(other)).isTrue(); } @@ -631,22 +638,22 @@ void isSuperSetOf6() { } @Test - void getAggregationBits_shouldBeConsistent_singleCommittee() { + void getAggregationSszBits_shouldBeConsistent_singleCommittee() { final AttestationBits attestation = createAttestationBits(List.of(0), 0); - assertThat(attestation.getAggregationBits().size()).isEqualTo(committeeSizes.get(0)); + assertThat(attestation.getAggregationSszBits().size()).isEqualTo(committeeSizes.get(0)); - assertThat(attestation.getAggregationBits()).isEqualTo(attestation.getAggregationBits()); + assertThat(attestation.getAggregationSszBits()).isEqualTo(attestation.getAggregationSszBits()); } @Test - void getAggregationBits_shouldBeConsistent_multiCommittee() { + void getAggregationSszBits_shouldBeConsistent_multiCommittee() { final AttestationBits attestation = createAttestationBits(List.of(0, 1), 0, 3); - assertThat(attestation.getAggregationBits().size()) + assertThat(attestation.getAggregationSszBits().size()) .isEqualTo(committeeSizes.get(0) + committeeSizes.get(1)); - assertThat(attestation.getAggregationBits()).isEqualTo(attestation.getAggregationBits()); + assertThat(attestation.getAggregationSszBits()).isEqualTo(attestation.getAggregationSszBits()); } @Test @@ -656,15 +663,16 @@ void copy_shouldNotModifyOriginal() { final AttestationBits copy = attestation.copy(); - assertThat(copy.getCommitteeBits()).isEqualTo(attestation.getCommitteeBits()); - assertThat(copy.getAggregationBits()).isEqualTo(attestation.getAggregationBits()); + assertThat(copy.getCommitteeSszBits()).isEqualTo(attestation.getCommitteeSszBits()); + assertThat(copy.getAggregationSszBits()).isEqualTo(attestation.getAggregationSszBits()); assertThat(copy).isNotSameAs(attestation); assertThat(copy.aggregateWith(createAttestationBits(List.of(1), 1))).isTrue(); // the original should not be modified - assertThat(attestation.getCommitteeBits()).isEqualTo(sameAttestation.getCommitteeBits()); - assertThat(attestation.getAggregationBits()).isEqualTo(sameAttestation.getAggregationBits()); + assertThat(attestation.getCommitteeSszBits()).isEqualTo(sameAttestation.getCommitteeSszBits()); + assertThat(attestation.getAggregationSszBits()) + .isEqualTo(sameAttestation.getAggregationSszBits()); } @Test diff --git a/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java b/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java index 2fdf5dc4c22..ef20c8036fa 100644 --- a/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java +++ b/ethereum/statetransition/src/testFixtures/java/tech/pegasys/teku/statetransition/attestation/AggregatorUtil.java @@ -55,9 +55,9 @@ public static Attestation aggregateAttestations( return firstAttestation .getSchema() .create( - aggregateBits.getAggregationBits(), + aggregateBits.getAggregationSszBits(), firstAttestation.getData(), BLS.aggregate(signatures), - aggregateBits::getCommitteeBits); + aggregateBits::getCommitteeSszBits); } }