use of org.hyperledger.besu.ethereum.debug.TraceOptions in project besu by hyperledger.
the class TraceBlock method traceBlock.
protected ArrayNodeWrapper traceBlock(final Block block, final Optional<FilterParameter> filterParameter) {
if (block == null) {
return emptyResult();
}
final ArrayNodeWrapper resultArrayNode = new ArrayNodeWrapper(MAPPER.createArrayNode());
blockTracerSupplier.get().trace(block, new DebugOperationTracer(new TraceOptions(false, false, true))).ifPresent(blockTrace -> generateTracesFromTransactionTraceAndBlock(filterParameter, blockTrace.getTransactionTraces(), block, resultArrayNode));
generateRewardsFromBlock(filterParameter, block, resultArrayNode);
return resultArrayNode;
}
use of org.hyperledger.besu.ethereum.debug.TraceOptions in project besu by hyperledger.
the class DebugOperationTracerTest method shouldNotRecordStorageWhenDisabled.
@Test
public void shouldNotRecordStorageWhenDisabled() {
final TraceFrame traceFrame = traceFrame(validMessageFrame(), new TraceOptions(false, false, false));
assertThat(traceFrame.getStorage()).isEmpty();
}
use of org.hyperledger.besu.ethereum.debug.TraceOptions in project besu by hyperledger.
the class DebugOperationTracerTest method shouldCaptureFrameWhenExceptionalHaltOccurs.
@Test
public void shouldCaptureFrameWhenExceptionalHaltOccurs() {
final MessageFrame frame = validMessageFrame();
final Map<UInt256, UInt256> updatedStorage = setupStorageForCapture(frame);
final DebugOperationTracer tracer = new DebugOperationTracer(new TraceOptions(true, true, true));
tracer.traceExecution(frame, () -> new OperationResult(OptionalLong.of(50L), Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS)));
final TraceFrame traceFrame = getOnlyTraceFrame(tracer);
assertThat(traceFrame.getExceptionalHaltReason()).contains(ExceptionalHaltReason.INSUFFICIENT_GAS);
assertThat(traceFrame.getStorage()).contains(updatedStorage);
}
use of org.hyperledger.besu.ethereum.debug.TraceOptions in project besu by hyperledger.
the class DebugOperationTracerTest method shouldRecordStorageWhenEnabled.
@Test
public void shouldRecordStorageWhenEnabled() {
final MessageFrame frame = validMessageFrame();
final Map<UInt256, UInt256> updatedStorage = setupStorageForCapture(frame);
final TraceFrame traceFrame = traceFrame(frame, new TraceOptions(true, false, false));
assertThat(traceFrame.getStorage()).isPresent();
assertThat(traceFrame.getStorage().get()).isEqualTo(updatedStorage);
}
use of org.hyperledger.besu.ethereum.debug.TraceOptions in project besu by hyperledger.
the class DebugAccountAt method resultByBlockHash.
@Override
protected Object resultByBlockHash(final JsonRpcRequestContext requestContext, final Hash blockHash) {
final Integer txIndex = requestContext.getRequiredParameter(1, Integer.class);
final Address address = requestContext.getRequiredParameter(2, Address.class);
Optional<BlockWithMetadata<TransactionWithMetadata, Hash>> block = blockchainQueries.get().blockByHash(blockHash);
if (block.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.BLOCK_NOT_FOUND);
}
List<TransactionWithMetadata> transactions = block.get().getTransactions();
if (transactions.isEmpty() || txIndex < 0 || txIndex > block.get().getTransactions().size()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final Optional<TransactionTrace> transactionTrace = blockTracerSupplier.get().trace(blockHash, new DebugOperationTracer(new TraceOptions(false, true, true))).map(BlockTrace::getTransactionTraces).orElse(Collections.emptyList()).stream().filter(trxTrace -> trxTrace.getTransaction().getHash().equals(transactions.get(txIndex).getTransaction().getHash())).findFirst();
if (transactionTrace.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.TRANSACTION_NOT_FOUND);
}
Optional<Account> account = transactionTrace.get().getTraceFrames().stream().map(traceFrame -> traceFrame.getWorldUpdater().get(address)).filter(Objects::nonNull).filter(a -> a.getAddress().equals(address)).findFirst();
if (account.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.NO_ACCOUNT_FOUND);
}
return debugAccountAtResult(account.get().getCode(), Quantity.create(account.get().getNonce()), Quantity.create(account.get().getBalance()), Quantity.create(account.get().getCodeHash()));
}
Aggregations