Skip to content

Commit

Permalink
fix test with DebugDataDumper
Browse files Browse the repository at this point in the history
  • Loading branch information
zilm13 committed Oct 22, 2024
1 parent ab9b341 commit 056cc34
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,7 @@ private BlockImportResult importBlockAndState(
}
case INVALID -> {
LOG.error("sidecars validation result: {}", dataAndValidationResult::toLogString);
if (!dataAndValidationResult.data().isEmpty()
&& dataAndValidationResult.data().getFirst() instanceof BlobSidecar) {
debugDataDumper.saveInvalidBlobSidecars(
(List<BlobSidecar>) dataAndValidationResult.data(), block);
}
debugDataDumper.saveInvalidSidecars(dataAndValidationResult.data(), block);
return BlockImportResult.failedDataAvailabilityCheckInvalid(
dataAndValidationResult.cause());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.function.Supplier;
import org.apache.tuweni.bytes.Bytes;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;

public interface DebugDataDumper {
Expand Down Expand Up @@ -46,8 +45,7 @@ public void saveInvalidBlock(
final Optional<Throwable> failureCause) {}

@Override
public void saveInvalidBlobSidecars(
final List<BlobSidecar> blobSidecars, final SignedBeaconBlock block) {}
public void saveInvalidSidecars(final List<?> sidecars, final SignedBeaconBlock block) {}
};

void saveGossipMessageDecodingError(
Expand All @@ -65,5 +63,5 @@ void saveGossipRejectedMessage(
void saveInvalidBlock(
SignedBeaconBlock block, String failureReason, Optional<Throwable> failureCause);

void saveInvalidBlobSidecars(List<BlobSidecar> blobSidecars, SignedBeaconBlock block);
void saveInvalidSidecars(List<?> sidecars, SignedBeaconBlock block);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar;
import tech.pegasys.teku.spec.datastructures.blobs.versions.eip7594.DataColumnSidecar;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;

public class DebugDataFileDumper implements DebugDataDumper {
Expand All @@ -44,6 +45,8 @@ public class DebugDataFileDumper implements DebugDataDumper {
private static final String REJECTED_SUB_DIR = "rejected";
private static final String INVALID_BLOCK_DIR = "invalid_blocks";
private static final String INVALID_BLOB_SIDECARS_DIR = "invalid_blob_sidecars";
// TODO: dump other
private static final String INVALID_DATA_COLUMN_SIDECARS_DIR = "invalid_blob_sidecars";

private boolean enabled;
private final Path directory;
Expand Down Expand Up @@ -141,9 +144,8 @@ public void saveInvalidBlock(
}

@Override
public void saveInvalidBlobSidecars(
final List<BlobSidecar> blobSidecars, final SignedBeaconBlock block) {
if (!enabled) {
public void saveInvalidSidecars(final List<?> sidecars, final SignedBeaconBlock block) {
if (!enabled || sidecars.isEmpty()) {
return;
}
final String kzgCommitmentsFileName =
Expand All @@ -153,18 +155,39 @@ public void saveInvalidBlobSidecars(
"kzg commitments",
Path.of(INVALID_BLOB_SIDECARS_DIR).resolve(kzgCommitmentsFileName),
block.getMessage().getBody().getOptionalBlobKzgCommitments().orElseThrow().sszSerialize());
blobSidecars.forEach(
blobSidecar -> {
final UInt64 slot = blobSidecar.getSlot();
final Bytes32 blockRoot = blobSidecar.getBlockRoot();
final UInt64 index = blobSidecar.getIndex();
final String fileName =
String.format("%s_%s_%s.ssz", slot, blockRoot.toUnprefixedHexString(), index);
saveBytesToFile(
"blob sidecar",
Path.of(INVALID_BLOB_SIDECARS_DIR).resolve(fileName),
blobSidecar.sszSerialize());
});
switch (sidecars.getFirst()) {
case BlobSidecar __ -> {
sidecars.forEach(
sidecar -> {
final BlobSidecar blobSidecar = (BlobSidecar) sidecar;
final UInt64 slot = blobSidecar.getSlot();
final Bytes32 blockRoot = blobSidecar.getBlockRoot();
final UInt64 index = blobSidecar.getIndex();
final String fileName =
String.format("%s_%s_%s.ssz", slot, blockRoot.toUnprefixedHexString(), index);
saveBytesToFile(
"blob sidecar",
Path.of(INVALID_BLOB_SIDECARS_DIR).resolve(fileName),
blobSidecar.sszSerialize());
});
}
case DataColumnSidecar __ -> {
sidecars.forEach(
sidecar -> {
final DataColumnSidecar blobSidecar = (DataColumnSidecar) sidecar;
final UInt64 slot = blobSidecar.getSlot();
final Bytes32 blockRoot = blobSidecar.getBlockRoot();
final UInt64 index = blobSidecar.getIndex();
final String fileName =
String.format("%s_%s_%s.ssz", slot, blockRoot.toUnprefixedHexString(), index);
saveBytesToFile(
"data column sidecar",
Path.of(INVALID_DATA_COLUMN_SIDECARS_DIR).resolve(fileName),
blobSidecar.sszSerialize());
});
}
default -> throw new RuntimeException("Unknown sidecar type: " + sidecars.getFirst());
}
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void onBlock_shouldFailIfBlobsAreInvalid() {
verify(blobSidecarManager).createAvailabilityChecker(blockAndState.getBlock());
verify(blobSidecarsAvailabilityChecker).initiateDataAvailabilityCheck();
verify(blobSidecarsAvailabilityChecker).getAvailabilityCheckResult();
verify(debugDataDumper).saveInvalidBlobSidecars(blobSidecars, blockAndState.getBlock());
verify(debugDataDumper).saveInvalidSidecars(blobSidecars, blockAndState.getBlock());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void saveInvalidBlobSidecars_shouldSaveToFiles(@TempDir final Path tempDir) {
final DebugDataFileDumper dumper = new DebugDataFileDumper(tempDir);
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock();
final List<BlobSidecar> blobSidecars = dataStructureUtil.randomBlobSidecarsForBlock(block);
dumper.saveInvalidBlobSidecars(blobSidecars, block);
dumper.saveInvalidSidecars(blobSidecars, block);

final String kzgCommitmentsFileName =
String.format(
Expand Down

0 comments on commit 056cc34

Please sign in to comment.