Skip to content

Commit

Permalink
Adding callTracer tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
asoto-iov committed Nov 21, 2024
1 parent 9c80357 commit 348ecc7
Show file tree
Hide file tree
Showing 15 changed files with 656 additions and 140 deletions.
15 changes: 10 additions & 5 deletions rskj-core/src/main/java/co/rsk/RskContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
import co.rsk.rpc.*;
import co.rsk.rpc.modules.debug.DebugModule;
import co.rsk.rpc.modules.debug.DebugModuleImpl;
import co.rsk.rpc.modules.debug.trace.CallTracer;
import co.rsk.rpc.modules.debug.trace.RskTracer;
import co.rsk.rpc.modules.debug.trace.TraceProvider;
import co.rsk.rpc.modules.debug.trace.call.CallTracer;
import co.rsk.rpc.modules.eth.*;
import co.rsk.rpc.modules.eth.subscribe.BlockHeaderNotificationEmitter;
import co.rsk.rpc.modules.eth.subscribe.LogsNotificationEmitter;
Expand Down Expand Up @@ -107,6 +107,7 @@
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.signature.Secp256k1;
import org.ethereum.datasource.*;
import org.ethereum.db.BlockStore;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.db.ReceiptStore;
import org.ethereum.db.ReceiptStoreImplV2;
Expand Down Expand Up @@ -814,13 +815,17 @@ public synchronized ConfigCapabilities getConfigCapabilities() {

public synchronized DebugModule getDebugModule() {
checkIfNotClosed();
RskTracer rskTracer = new RskTracer(getBlockStore(), getReceiptStore(),
getBlockExecutor(), getWeb3InformationRetriever());

CallTracer callTracer = new CallTracer();
Web3InformationRetriever web3i = getWeb3InformationRetriever();
BlockStore bs = getBlockStore();
BlockExecutor be = getBlockExecutor();
RskTracer rskTracer = new RskTracer(bs, getReceiptStore(),
be, web3i);

CallTracer callTracer = new CallTracer(bs, be, web3i, getReceiptStore(), getBlockchain());
TraceProvider traceProvider = new TraceProvider(Arrays.asList(callTracer, rskTracer));
if (debugModule == null) {
debugModule = new DebugModuleImpl(traceProvider,getNodeMessageHandler(),getTxQuotaChecker());
debugModule = new DebugModuleImpl(traceProvider, getNodeMessageHandler(), getTxQuotaChecker());
}

return debugModule;
Expand Down
9 changes: 4 additions & 5 deletions rskj-core/src/main/java/co/rsk/rpc/Web3DebugModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.fasterxml.jackson.databind.JsonNode;
import org.ethereum.rpc.parameters.DebugTracerParam;

import java.util.Map;

@java.lang.SuppressWarnings("squid:S100")
public interface Web3DebugModule {

Expand All @@ -49,11 +47,12 @@ default JsonNode debug_traceBlockByHash(String blockHash, DebugTracerParam debug
}

default JsonNode debug_traceBlockByNumber(String bnOrId) throws Exception {
return debug_traceBlockByNumber(bnOrId, null);

return debug_traceBlockByNumber(bnOrId, new DebugTracerParam());
}

default JsonNode debug_traceBlockByNumber(String bnOrId, Map<String, String> traceOptions) throws Exception {
return getDebugModule().traceBlockByNumber(bnOrId, traceOptions);
default JsonNode debug_traceBlockByNumber(String bnOrId, DebugTracerParam debugTracerParam) throws Exception {
return getDebugModule().traceBlockByNumber(bnOrId, debugTracerParam.getTraceOptions(), debugTracerParam.getTracerType());
}

default TxQuota debug_accountTransactionQuota(String address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import co.rsk.rpc.modules.debug.trace.TracerType;
import com.fasterxml.jackson.databind.JsonNode;

import java.util.Map;

public interface DebugModule {

String wireProtocolQueueSize();
Expand All @@ -35,9 +33,7 @@ public interface DebugModule {
JsonNode traceBlockByHash(String blockHash, TraceOptions traceOptions, TracerType tracerType) throws Exception;
JsonNode traceBlockByHash(String blockHash) throws Exception;

JsonNode traceBlockByNumber(String bnOrId, Map<String, String> traceOptions) throws Exception;

JsonNode traceBlockByNumber(String bnOrId, Map<String, String> traceOptions, TracerType tracerType) throws Exception;
JsonNode traceBlockByNumber(String bnOrId, TraceOptions traceOptions, TracerType tracerType) throws Exception;

TxQuota accountTransactionQuota(String address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Optional;

public class DebugModuleImpl implements DebugModule {
//this could be configurable
public static final TracerType DEFAULT_TRACER_TYPE = TracerType.RSK_TRACER;
Expand All @@ -57,39 +54,43 @@ public String wireProtocolQueueSize() {

@Override
public TxQuota accountTransactionQuota(String address) {
logger.trace("debug_accountTransactionQuota({})", StringUtils.trim(address));
if (logger.isTraceEnabled()) {
logger.trace("debug_accountTransactionQuota({})", StringUtils.trim(address));
}
RskAddress rskAddress = new RskAddress(address);
return txQuotaChecker.getTxQuota(rskAddress);
}

@Override
public JsonNode traceTransaction(String transactionHash) {
public JsonNode traceTransaction(String transactionHash) throws Exception {
return traceTransaction(transactionHash, new TraceOptions(), null);
}

@Override
public JsonNode traceTransaction(String transactionHash, TraceOptions traceOptions, TracerType tracerType) {
if (tracerType == null) {
tracerType = DEFAULT_TRACER_TYPE;
}
public JsonNode traceTransaction(String transactionHash, TraceOptions traceOptions, TracerType tracerType) throws Exception {
TracerType type = getTracerTypeOrDefault(tracerType);

if (traceOptions == null) {
traceOptions = new TraceOptions();
}
DebugTracer tracer = traceProvider.getTracer(tracerType);
logger.trace("debug_traceTransaction for txHash: {}", StringUtils.trim(transactionHash));
DebugTracer tracer = traceProvider.getTracer(type);
if (logger.isTraceEnabled()) {
logger.trace("debug_traceTransaction for txHash: {}", StringUtils.trim(transactionHash));
}
return tracer.traceTransaction(transactionHash, traceOptions);
}

@Override
public JsonNode traceBlockByHash(String blockHash, TraceOptions traceOptions, TracerType tracerType) {
if (tracerType == null) {
tracerType = DEFAULT_TRACER_TYPE;
}
TracerType type = getTracerTypeOrDefault(tracerType);

if (traceOptions == null) {
traceOptions = new TraceOptions();
}
logger.trace("debug_traceBlockByHash for blockHash: {}", StringUtils.trim(blockHash));
DebugTracer tracer = traceProvider.getTracer(tracerType);
if (logger.isTraceEnabled()) {
logger.trace("debug_traceBlockByHash for blockHash: {}", StringUtils.trim(blockHash));
}
DebugTracer tracer = traceProvider.getTracer(type);
return tracer.traceBlockByHash(blockHash, traceOptions);
}

Expand All @@ -100,35 +101,23 @@ public JsonNode traceBlockByHash(String blockHash) throws Exception {


@Override
public JsonNode traceBlockByNumber(String bnOrId, Map<String, String> traceOptions) throws Exception {
return traceBlockByNumber(bnOrId, traceOptions, DEFAULT_TRACER_TYPE);
}

@Override
public JsonNode traceBlockByNumber(String bnOrId, Map<String, String> traceOptions, TracerType tracerType) throws Exception {
logger.trace("debug_traceBlockByNumber for bnOrId: {}", StringUtils.trim(bnOrId));
DebugTracer tracer = traceProvider.getTracer(tracerType);
TraceOptions options = toTraceOptions(traceOptions);
return tracer.traceBlockByNumber(bnOrId, options);
}

private TraceOptions toTraceOptions(Map<String, String> traceOptions) {
TraceOptions options = new TraceOptions(traceOptions);

if (!options.getUnsupportedOptions().isEmpty()) {
// TODO: implement the logic that takes into account the remaining trace options.
logger.warn("Received {} unsupported trace options", options.getUnsupportedOptions().size());
public JsonNode traceBlockByNumber(String bnOrId, TraceOptions traceOptions, TracerType tracerType) throws Exception {
TracerType type = getTracerTypeOrDefault(tracerType);
if (traceOptions == null) {
traceOptions = new TraceOptions();
}

return options;
if (logger.isTraceEnabled()) {
logger.trace("debug_traceBlockByNumber for bnOrId: {}", StringUtils.trim(bnOrId));
}
DebugTracer tracer = traceProvider.getTracer(type);
return tracer.traceBlockByNumber(bnOrId, traceOptions);
}

private TracerType getTracerType(Map<String, String> options) {
if (options.containsKey("tracer")) {
Optional.ofNullable(TracerType.getTracerType(options.get("tracer")))
.orElseThrow(() -> new IllegalArgumentException("Invalid tracer type: " + options.get("tracer")));
private TracerType getTracerTypeOrDefault(TracerType tracerType) {
//TODO review about this default tracer logic
if (tracerType == null) {
return DEFAULT_TRACER_TYPE;
}
return DEFAULT_TRACER_TYPE;
return tracerType;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.fasterxml.jackson.databind.JsonNode;

public interface DebugTracer {
JsonNode traceTransaction(String transactionHash, TraceOptions traceOptions);
JsonNode traceTransaction(String transactionHash, TraceOptions traceOptions) throws Exception;

JsonNode traceBlockByHash(String blockHash, TraceOptions traceOptions);

Expand Down

This file was deleted.

Loading

0 comments on commit 348ecc7

Please sign in to comment.