Search in sources :

Example 1 with SummarizedProgramTrace

use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.

the class TraceModuleImpl method traceTransaction.

@Override
public JsonNode traceTransaction(String transactionHash) throws Exception {
    logger.trace("trace_transaction({})", transactionHash);
    byte[] hash = stringHexToByteArray(transactionHash);
    TransactionInfo txInfo = this.receiptStore.getInMainChain(hash, this.blockStore).orElse(null);
    if (txInfo == null) {
        logger.trace("No transaction info for {}", transactionHash);
        return null;
    }
    Block block = this.blockchain.getBlockByHash(txInfo.getBlockHash());
    Block parent = this.blockchain.getBlockByHash(block.getParentHash().getBytes());
    Transaction tx = block.getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
    this.blockExecutor.traceBlock(programTraceProcessor, VmConfig.LIGHT_TRACE, block, parent.getHeader(), false, false);
    SummarizedProgramTrace programTrace = (SummarizedProgramTrace) programTraceProcessor.getProgramTrace(tx.getHash());
    if (programTrace == null) {
        return null;
    }
    List<TransactionTrace> traces = TraceTransformer.toTraces(programTrace, txInfo, block.getNumber());
    return OBJECT_MAPPER.valueToTree(traces);
}
Also used : ProgramTraceProcessor(org.ethereum.vm.trace.ProgramTraceProcessor) Transaction(org.ethereum.core.Transaction) TransactionInfo(org.ethereum.db.TransactionInfo) Block(org.ethereum.core.Block) SummarizedProgramTrace(org.ethereum.vm.trace.SummarizedProgramTrace)

Example 2 with SummarizedProgramTrace

use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.

the class TransactionExecutor method extractTrace.

/**
 * This extracts the trace to an object in memory.
 * Refer to {@link org.ethereum.vm.VMUtils#saveProgramTraceFile} for a way to saving the trace to a file.
 */
public void extractTrace(ProgramTraceProcessor programTraceProcessor) {
    if (program != null) {
        // TODO improve this settings; the trace should already have the values
        ProgramTrace trace = program.getTrace().result(result.getHReturn()).error(result.getException()).revert(result.isRevert());
        programTraceProcessor.processProgramTrace(trace, tx.getHash());
    } else {
        TransferInvoke invoke = new TransferInvoke(DataWord.valueOf(tx.getSender().getBytes()), DataWord.valueOf(tx.getReceiveAddress().getBytes()), 0L, DataWord.valueOf(tx.getValue().getBytes()));
        SummarizedProgramTrace trace = new SummarizedProgramTrace(invoke);
        if (this.subtraces != null) {
            for (ProgramSubtrace subtrace : this.subtraces) {
                trace.addSubTrace(subtrace);
            }
        }
        programTraceProcessor.processProgramTrace(trace, tx.getHash());
    }
}
Also used : SummarizedProgramTrace(org.ethereum.vm.trace.SummarizedProgramTrace) ProgramTrace(org.ethereum.vm.trace.ProgramTrace) ProgramSubtrace(co.rsk.rpc.modules.trace.ProgramSubtrace) TransferInvoke(org.ethereum.vm.program.invoke.TransferInvoke) SummarizedProgramTrace(org.ethereum.vm.trace.SummarizedProgramTrace)

Example 3 with SummarizedProgramTrace

use of org.ethereum.vm.trace.SummarizedProgramTrace in project rskj by rsksmart.

the class TraceModuleImpl method traceBlock.

@Override
public JsonNode traceBlock(String blockArgument) throws Exception {
    logger.trace("trace_block({})", blockArgument);
    Block block = this.getByJsonArgument(blockArgument);
    if (block == null) {
        logger.trace("No block for {}", blockArgument);
        return null;
    }
    Block parent = this.blockchain.getBlockByHash(block.getParentHash().getBytes());
    List<TransactionTrace> blockTraces = new ArrayList<>();
    if (block.getNumber() != 0) {
        ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
        this.blockExecutor.traceBlock(programTraceProcessor, VmConfig.LIGHT_TRACE, block, parent.getHeader(), false, false);
        for (Transaction tx : block.getTransactionsList()) {
            TransactionInfo txInfo = receiptStore.getInMainChain(tx.getHash().getBytes(), this.blockStore).orElse(null);
            Objects.requireNonNull(txInfo);
            txInfo.setTransaction(tx);
            SummarizedProgramTrace programTrace = (SummarizedProgramTrace) programTraceProcessor.getProgramTrace(tx.getHash());
            if (programTrace == null) {
                return null;
            }
            List<TransactionTrace> traces = TraceTransformer.toTraces(programTrace, txInfo, block.getNumber());
            blockTraces.addAll(traces);
        }
    }
    return OBJECT_MAPPER.valueToTree(blockTraces);
}
Also used : ProgramTraceProcessor(org.ethereum.vm.trace.ProgramTraceProcessor) Transaction(org.ethereum.core.Transaction) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) SummarizedProgramTrace(org.ethereum.vm.trace.SummarizedProgramTrace)

Aggregations

SummarizedProgramTrace (org.ethereum.vm.trace.SummarizedProgramTrace)3 Block (org.ethereum.core.Block)2 Transaction (org.ethereum.core.Transaction)2 TransactionInfo (org.ethereum.db.TransactionInfo)2 ProgramTraceProcessor (org.ethereum.vm.trace.ProgramTraceProcessor)2 ProgramSubtrace (co.rsk.rpc.modules.trace.ProgramSubtrace)1 ArrayList (java.util.ArrayList)1 TransferInvoke (org.ethereum.vm.program.invoke.TransferInvoke)1 ProgramTrace (org.ethereum.vm.trace.ProgramTrace)1