Skip to content

Commit

Permalink
Pass block to data dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 17, 2024
1 parent 1d3037d commit 4247274
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,7 @@ private void reportInvalidBlock(final SignedBeaconBlock block, final BlockImport
return;
}
debugDataDumper.saveInvalidBlockToFile(
block.getSlot(),
block.getRoot(),
block.sszSerialize(),
result.getFailureReason().name(),
result.getFailureCause());
block, result.getFailureReason().name(), result.getFailureCause());
P2P_LOG.onInvalidBlock(
block.getSlot(),
block.getRoot(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.time.TimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;

public class DebugDataDumper {
private static final Logger LOG = LogManager.getLogger();
Expand Down Expand Up @@ -101,17 +102,18 @@ public void saveGossipRejectedMessageToFile(
}

public void saveInvalidBlockToFile(
final UInt64 slot,
final Bytes32 blockRoot,
final Bytes blockSsz,
final SignedBeaconBlock block,
final String failureReason,
final Optional<Throwable> failureCause) {
if (!enabled) {
return;
}
final UInt64 slot = block.getSlot();
final Bytes32 blockRoot = block.getRoot();
final String fileName = String.format("%s_%s.ssz", slot, blockRoot.toUnprefixedHexString());
final boolean success =
saveBytesToFile("invalid block", Path.of(INVALID_BLOCK_DIR).resolve(fileName), blockSsz);
saveBytesToFile(
"invalid block", Path.of(INVALID_BLOCK_DIR).resolve(fileName), block.sszSerialize());
if (success) {
LOG.warn(
"Rejecting invalid block at slot {} with root {} because {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.nio.file.Path;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock;
import tech.pegasys.teku.statetransition.util.DebugDataDumper;

public class NoOpDebugDataDumper extends DebugDataDumper {
Expand All @@ -42,9 +42,7 @@ public void saveGossipRejectedMessageToFile(

@Override
public void saveInvalidBlockToFile(
final UInt64 slot,
final Bytes32 blockRoot,
final Bytes blockSsz,
final SignedBeaconBlock block,
final String failureReason,
final Optional<Throwable> failureCause) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ void onBlock_consensusValidationShouldNotResolveWhenStateTransitionFails()

verify(debugDataDumper)
.saveInvalidBlockToFile(
eq(blockAndState.getSlot()),
eq(blockAndState.getBlock().getRoot()),
eq(blockAndState.getBlock().sszSerialize()),
eq(blockAndState.getBlock()),
eq(FailureReason.FAILED_STATE_TRANSITION.toString()),
eq(Optional.of(blockException)));
verify(blockBroadcastValidator, never()).onConsensusValidationSucceeded();
Expand Down Expand Up @@ -351,8 +349,7 @@ void onBlock_consensusValidationShouldReturnRegardlessExecutionPayloadValidation
payloadStatusSafeFuture.complete(PayloadStatus.invalid(Optional.empty(), Optional.empty()));
assertBlockImportFailure(importResult, FailureReason.FAILED_STATE_TRANSITION);
verify(debugDataDumper)
.saveInvalidBlockToFile(
any(), any(), any(), eq(FailureReason.FAILED_STATE_TRANSITION.toString()), any());
.saveInvalidBlockToFile(any(), eq(FailureReason.FAILED_STATE_TRANSITION.toString()), any());
}

@Test
Expand Down Expand Up @@ -754,9 +751,7 @@ void onBlock_shouldNotOptimisticallyImportInvalidExecutionPayload() {
chainBuilder.generateNextBlock(), FailureReason.FAILED_STATE_TRANSITION);
verify(debugDataDumper)
.saveInvalidBlockToFile(
eq(slotToImport.increment()),
any(),
any(),
eq(chainBuilder.getLatestBlockAndState().getBlock()),
eq(FailureReason.FAILED_STATE_TRANSITION.toString()),
any());
}
Expand Down Expand Up @@ -797,9 +792,7 @@ void onBlock_shouldChangeForkChoiceForLatestValidHashOnInvalidExecutionPayload()
assertThat(forkChoice.processHead(invalidBlock.getSlot())).isCompleted();
verify(debugDataDumper)
.saveInvalidBlockToFile(
eq(invalidBlock.getSlot()),
eq(invalidBlock.getRoot()),
eq(invalidBlock.getBlock().sszSerialize()),
eq(invalidBlock.getBlock()),
eq(FailureReason.FAILED_STATE_TRANSITION.toString()),
any());
assertHeadIsOptimistic(maybeValidBlock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ void saveGossipRejectedMessageToFile_shouldSaveToFile(@TempDir Path tempDir) {
void saveInvalidBlockToFile_shouldSaveToFile(@TempDir Path tempDir) {
final DebugDataDumper manager = new DebugDataDumper(tempDir);
final SignedBeaconBlock block = dataStructureUtil.randomSignedBeaconBlock();
manager.saveInvalidBlockToFile(
block.getSlot(),
block.getRoot(),
block.sszSerialize(),
"reason",
Optional.of(new Throwable()));
manager.saveInvalidBlockToFile(block, "reason", Optional.of(new Throwable()));

final String fileName =
String.format("%s_%s.ssz", block.getSlot(), block.getRoot().toUnprefixedHexString());
Expand Down

0 comments on commit 4247274

Please sign in to comment.