forked from PegaSysEng/pantheon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block trace RPC methods (PegaSysEng#1088)
Implements debug_traceBlock, debug_traceBlockByHash and debug_traceBlockByNumber methods.
- Loading branch information
1 parent
f65c3d8
commit 35e9a9e
Showing
15 changed files
with
777 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...rc/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugTraceBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Block; | ||
import tech.pegasys.pantheon.ethereum.core.BlockHashFunction; | ||
import tech.pegasys.pantheon.ethereum.debug.TraceOptions; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.TransactionTraceParams; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTrace; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTracer; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.DebugTraceTransactionResult; | ||
import tech.pegasys.pantheon.ethereum.rlp.RLP; | ||
import tech.pegasys.pantheon.ethereum.rlp.RLPException; | ||
import tech.pegasys.pantheon.ethereum.vm.DebugOperationTracer; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.util.Collection; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class DebugTraceBlock implements JsonRpcMethod { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
private final JsonRpcParameter parameters; | ||
private final BlockTracer blockTracer; | ||
private final BlockHashFunction blockHashFunction; | ||
private final BlockchainQueries blockchain; | ||
|
||
public DebugTraceBlock( | ||
final JsonRpcParameter parameters, | ||
final BlockTracer blockTracer, | ||
final BlockHashFunction blockHashFunction, | ||
final BlockchainQueries blockchain) { | ||
this.parameters = parameters; | ||
this.blockTracer = blockTracer; | ||
this.blockHashFunction = blockHashFunction; | ||
this.blockchain = blockchain; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "debug_traceBlock"; | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequest request) { | ||
final String input = parameters.required(request.getParams(), 0, String.class); | ||
final Block block; | ||
try { | ||
block = Block.readFrom(RLP.input(BytesValue.fromHexString(input)), this.blockHashFunction); | ||
} catch (final RLPException e) { | ||
LOG.debug("Failed to parse block RLP", e); | ||
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.INVALID_PARAMS); | ||
} | ||
final TraceOptions traceOptions = | ||
parameters | ||
.optional(request.getParams(), 1, TransactionTraceParams.class) | ||
.map(TransactionTraceParams::traceOptions) | ||
.orElse(TraceOptions.DEFAULT); | ||
|
||
if (this.blockchain.blockByHash(block.getHeader().getParentHash()).isPresent()) { | ||
final Collection<DebugTraceTransactionResult> results = | ||
blockTracer | ||
.trace(block, new DebugOperationTracer(traceOptions)) | ||
.map(BlockTrace::getTransactionTraces) | ||
.map(DebugTraceTransactionResult::of) | ||
.orElse(null); | ||
return new JsonRpcSuccessResponse(request.getId(), results); | ||
} else { | ||
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.PARENT_BLOCK_NOT_FOUND); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...n/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugTraceBlockByHash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
import tech.pegasys.pantheon.ethereum.debug.TraceOptions; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.TransactionTraceParams; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTrace; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTracer; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.DebugTraceTransactionResult; | ||
import tech.pegasys.pantheon.ethereum.vm.DebugOperationTracer; | ||
|
||
import java.util.Collection; | ||
|
||
public class DebugTraceBlockByHash implements JsonRpcMethod { | ||
|
||
private final JsonRpcParameter parameters; | ||
private final BlockTracer blockTracer; | ||
|
||
public DebugTraceBlockByHash(final JsonRpcParameter parameters, final BlockTracer blockTracer) { | ||
this.parameters = parameters; | ||
this.blockTracer = blockTracer; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "debug_traceBlockByHash"; | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequest request) { | ||
final Hash blockHash = parameters.required(request.getParams(), 0, Hash.class); | ||
final TraceOptions traceOptions = | ||
parameters | ||
.optional(request.getParams(), 1, TransactionTraceParams.class) | ||
.map(TransactionTraceParams::traceOptions) | ||
.orElse(TraceOptions.DEFAULT); | ||
|
||
final Collection<DebugTraceTransactionResult> results = | ||
blockTracer | ||
.trace(blockHash, new DebugOperationTracer(traceOptions)) | ||
.map(BlockTrace::getTransactionTraces) | ||
.map(DebugTraceTransactionResult::of) | ||
.orElse(null); | ||
return new JsonRpcSuccessResponse(request.getId(), results); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/DebugTraceBlockByNumber.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
import tech.pegasys.pantheon.ethereum.debug.TraceOptions; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.TransactionTraceParams; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTrace; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.processor.BlockTracer; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; | ||
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.DebugTraceTransactionResult; | ||
import tech.pegasys.pantheon.ethereum.vm.DebugOperationTracer; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public class DebugTraceBlockByNumber implements JsonRpcMethod { | ||
|
||
private final JsonRpcParameter parameters; | ||
private final BlockTracer blockTracer; | ||
private final BlockchainQueries blockchain; | ||
|
||
public DebugTraceBlockByNumber( | ||
final JsonRpcParameter parameters, | ||
final BlockTracer blockTracer, | ||
final BlockchainQueries blockchain) { | ||
this.parameters = parameters; | ||
this.blockTracer = blockTracer; | ||
this.blockchain = blockchain; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "debug_traceBlockByNumber"; | ||
} | ||
|
||
@Override | ||
public JsonRpcResponse response(final JsonRpcRequest request) { | ||
final Long blockNumber = parameters.required(request.getParams(), 0, Long.class); | ||
final Optional<Hash> blockHash = this.blockchain.getBlockHashByNumber(blockNumber); | ||
final TraceOptions traceOptions = | ||
parameters | ||
.optional(request.getParams(), 1, TransactionTraceParams.class) | ||
.map(TransactionTraceParams::traceOptions) | ||
.orElse(TraceOptions.DEFAULT); | ||
|
||
final Collection<DebugTraceTransactionResult> results = | ||
blockHash | ||
.map( | ||
hash -> | ||
blockTracer | ||
.trace(hash, new DebugOperationTracer(traceOptions)) | ||
.map(BlockTrace::getTransactionTraces) | ||
.map(DebugTraceTransactionResult::of)) | ||
.orElse(null) | ||
.get(); | ||
return new JsonRpcSuccessResponse(request.getId(), results); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.