Search in sources :

Example 11 with TraceOptions

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;
}
Also used : ArrayNodeWrapper(org.hyperledger.besu.ethereum.api.util.ArrayNodeWrapper) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions)

Example 12 with TraceOptions

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();
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) Test(org.junit.Test)

Example 13 with TraceOptions

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);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) UInt256(org.apache.tuweni.units.bigints.UInt256) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) Test(org.junit.Test)

Example 14 with TraceOptions

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);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) UInt256(org.apache.tuweni.units.bigints.UInt256) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame) Test(org.junit.Test)

Example 15 with TraceOptions

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()));
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Account(org.hyperledger.besu.evm.account.Account) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) ImmutableDebugAccountAtResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableDebugAccountAtResult) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Supplier(java.util.function.Supplier) Quantity(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity) Objects(java.util.Objects) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) BlockParameterOrBlockHash(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) Optional(java.util.Optional) Collections(java.util.Collections) Hash(org.hyperledger.besu.datatypes.Hash) BlockTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer) Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Objects(java.util.Objects) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Aggregations

TraceOptions (org.hyperledger.besu.ethereum.debug.TraceOptions)17 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)9 DebugOperationTracer (org.hyperledger.besu.ethereum.vm.DebugOperationTracer)7 Test (org.junit.Test)7 Hash (org.hyperledger.besu.datatypes.Hash)5 BlockTrace (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace)5 Optional (java.util.Optional)4 UInt256 (org.apache.tuweni.units.bigints.UInt256)4 DebugTraceTransactionResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugTraceTransactionResult)4 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)4 List (java.util.List)3 Supplier (java.util.function.Supplier)3 RpcMethod (org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod)3 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)3 BlockTracer (org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer)3 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)3 BlockchainQueries (org.hyperledger.besu.ethereum.api.query.BlockchainQueries)3 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)3 Transaction (org.hyperledger.besu.ethereum.core.Transaction)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2