Skip to content

Commit

Permalink
attestation pool dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Feb 17, 2025
1 parent 6e33e4e commit bd37ec8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package tech.pegasys.teku.statetransition.attestation;

import it.unimi.dsi.fastutil.ints.Int2IntMap;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -172,6 +174,11 @@ private Optional<Int2IntMap> getCommitteesSizeUsingTheState(

@Override
public synchronized void onSlot(final UInt64 slot) {
System.out.println("slot: " + slot);
if (getSize() > 100_000) {
System.out.println("dumping");
dumpAttestations();
}
if (slot.compareTo(ATTESTATION_RETENTION_SLOTS) <= 0) {
return;
}
Expand Down Expand Up @@ -267,6 +274,28 @@ public synchronized SszList<Attestation> getAttestationsForBlock(
.collect(attestationsSchema.collector());
}

private synchronized void dumpAttestations() {
try (FileWriter fos =
new FileWriter("/tmp/attestations_" + dataHashBySlot.firstKey() + ".multi_ssz")) {
dataHashBySlot.descendingMap().values().stream()
.flatMap(Collection::stream)
.map(attestationGroupByDataHash::get)
.filter(Objects::nonNull)
.flatMap(MatchingDataAttestationGroup::streamAttestations)
.forEach(
attestation -> {
try {
fos.write(attestation.sszSerialize().toHexString());
fos.write("\n");
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (IOException e) {
System.out.println("An error occurred.");
}
}

public synchronized List<Attestation> getAttestations(
final Optional<UInt64> maybeSlot, final Optional<UInt64> maybeCommitteeIndex) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public boolean add(final ValidatableAttestation attestation) {
.add(attestation);
}

public Stream<Attestation> streamAttestations() {
return attestationsByValidatorCount.values().stream()
.flatMap(Set::stream)
.map(ValidatableAttestation::getUnconvertedAttestation);
}

/**
* Iterates through the aggregation of attestations in this group. The iterator attempts to create
* the minimum number of attestations that include all attestations in the group.
Expand Down

0 comments on commit bd37ec8

Please sign in to comment.