Search in sources :

Example 1 with ProgramTraceProcessor

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

the class DebugModuleImpl method traceBlock.

@Override
public JsonNode traceBlock(String blockHash, Map<String, String> traceOptions) {
    logger.trace("debug_traceBlockByHash({}, {})", blockHash, traceOptions);
    if (traceOptions != null && !traceOptions.isEmpty()) {
        // TODO: implement the logic that takes into account trace options.
        logger.warn("Received {} trace options. For now trace options are being ignored", traceOptions);
    }
    byte[] bHash = stringHexToByteArray(blockHash);
    Block block = blockStore.getBlockByHash(bHash);
    if (block == null) {
        logger.trace("No block is found for {}", bHash);
        return null;
    }
    Block parent = blockStore.getBlockByHash(block.getParentHash().getBytes());
    ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
    blockExecutor.traceBlock(programTraceProcessor, 0, block, parent.getHeader(), false, false);
    List<Keccak256> txHashes = block.getTransactionsList().stream().map(Transaction::getHash).collect(Collectors.toList());
    return programTraceProcessor.getProgramTracesAsJsonNode(txHashes);
}
Also used : ProgramTraceProcessor(org.ethereum.vm.trace.ProgramTraceProcessor) Block(org.ethereum.core.Block) Keccak256(co.rsk.crypto.Keccak256)

Example 2 with ProgramTraceProcessor

use of org.ethereum.vm.trace.ProgramTraceProcessor 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 3 with ProgramTraceProcessor

use of org.ethereum.vm.trace.ProgramTraceProcessor 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)

Example 4 with ProgramTraceProcessor

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

the class DebugModuleImpl method traceTransaction.

@Override
public JsonNode traceTransaction(String transactionHash, Map<String, String> traceOptions) {
    logger.trace("debug_traceTransaction({}, {})", transactionHash, traceOptions);
    if (traceOptions != null && !traceOptions.isEmpty()) {
        // TODO: implement the logic that takes into account trace options.
        logger.warn("Received {} trace options. For now trace options are being ignored", traceOptions);
    }
    byte[] hash = stringHexToByteArray(transactionHash);
    TransactionInfo txInfo = receiptStore.getInMainChain(hash, blockStore).orElse(null);
    if (txInfo == null) {
        logger.trace("No transaction info for {}", transactionHash);
        return null;
    }
    Block block = blockStore.getBlockByHash(txInfo.getBlockHash());
    Block parent = blockStore.getBlockByHash(block.getParentHash().getBytes());
    Transaction tx = block.getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    ProgramTraceProcessor programTraceProcessor = new ProgramTraceProcessor();
    blockExecutor.traceBlock(programTraceProcessor, 0, block, parent.getHeader(), false, false);
    return programTraceProcessor.getProgramTraceAsJsonNode(tx.getHash());
}
Also used : ProgramTraceProcessor(org.ethereum.vm.trace.ProgramTraceProcessor) Transaction(org.ethereum.core.Transaction) TransactionInfo(org.ethereum.db.TransactionInfo) Block(org.ethereum.core.Block)

Aggregations

Block (org.ethereum.core.Block)4 ProgramTraceProcessor (org.ethereum.vm.trace.ProgramTraceProcessor)4 Transaction (org.ethereum.core.Transaction)3 TransactionInfo (org.ethereum.db.TransactionInfo)3 SummarizedProgramTrace (org.ethereum.vm.trace.SummarizedProgramTrace)2 Keccak256 (co.rsk.crypto.Keccak256)1 ArrayList (java.util.ArrayList)1