Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed May 30, 2024
1 parent 8b6fedd commit 50fda0d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,45 +393,6 @@ void bigAggregation() {
.isEqualTo(result.getAttestation().getAggregationBits());
}

@Test
void asd() {
committeeSizes = new Int2IntOpenHashMap();
IntStream.range(0, 64).forEach(i -> committeeSizes.put(i, 600));

List<Integer> committee1 =
IntStream.range(0, 64).mapToObj(__ -> dataStructureUtil.randomPositiveInt(64)).toList();
int[] aggregation1 =
IntStream.range(0, 600).map(__ -> dataStructureUtil.randomPositiveInt(600)).toArray();

List<Integer> committee2 =
IntStream.range(0, 64).mapToObj(__ -> dataStructureUtil.randomPositiveInt(64)).toList();
int[] aggregation2 =
IntStream.range(0, 600).map(__ -> dataStructureUtil.randomPositiveInt(600)).toArray();

ValidatableAttestation asd = createAttestation(committee1, aggregation1);

committee2 = committee1.subList(0, committee1.size() - 1);

ValidatableAttestation asd2 = createAttestation(committee2, aggregation2);
final AttestationBitsAggregator aggregator = AttestationBitsAggregator.of(asd);

long now = System.currentTimeMillis();
for (int i = 0; i < 100000; i++) {
aggregator.or(asd2.getAttestation());
}
long finalTime = System.currentTimeMillis() - now;
System.out.println("time: " + finalTime + " ms - ops per millisecond: " + 100000f / finalTime);

// now = System.currentTimeMillis();
// for(int i = 0; i < 10000; i++) {
//
// asd2.getAttestation().getAggregationBits().or(asd.getAttestation().getAggregationBits());
// }
// finalTime = System.currentTimeMillis() - now;
// System.out.println("time: " + finalTime + " ms - ops per millisecond: " + 10000f /
// finalTime);
}

@Test
void isSuperSetOf1() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,14 @@ default SszBitlistT empty() {

SszBitlistT ofBits(int size, int... setBitIndices);

/**
* Creates a SszBitlist by wrapping a given bitSet. This is an optimized constructor that DOES NOT
* clone the bitSet. It used in aggregating attestation pool. DO NOT MUTATE the after the
* wrapping!! SszBitlist is supposed to be immutable.
*
* @param size size of the SszBitlist
* @param bitSet data backing the ssz
* @return SszBitlist instance
*/
SszBitlistT wrapBitSet(int size, BitSet bitSet);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,28 @@ void testWrapBitSet(SszBitlist bitlist1) {
assertThat(bitlist2.sszSerialize()).isEqualTo(bitlist1.sszSerialize());
}

@Test
void wrapBitSet_shouldDropBitsIfBitSetIsLarger() {
final BitSet bitSet = new BitSet(100);
bitSet.set(99);
assertThat(bitSet.stream().count()).isEqualTo(1);

final SszBitlist sszBitlist = schema.wrapBitSet(10, bitSet);
final SszBitlist expectedSszBitlist = schema.ofBits(10);

assertThat(sszBitlist).isEqualTo(expectedSszBitlist);
assertThat(sszBitlist.hashCode()).isEqualTo(expectedSszBitlist.hashCode());
assertThat(sszBitlist.hashTreeRoot()).isEqualTo(expectedSszBitlist.hashTreeRoot());
assertThat(sszBitlist.sszSerialize()).isEqualTo(expectedSszBitlist.sszSerialize());
}

@Test
void wrapBitSet_shouldThrowIfSizeIsLargerThanSchemaMaxLength() {
assertThatThrownBy(
() -> schema.wrapBitSet(Math.toIntExact(schema.getMaxLength() + 1), new BitSet()))
.isInstanceOf(IllegalArgumentException.class);
}

@ParameterizedTest
@MethodSource("bitlistArgs")
void testTreeRoundtrip(SszBitlist bitlist1) {
Expand Down

0 comments on commit 50fda0d

Please sign in to comment.