Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Implement trace replay block transactions trace option #1886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
fbab702
Factorise metrics code for KeyValueStorage database
AbdelStark Jul 9, 2019
4037f74
Rename class
AbdelStark Jul 9, 2019
237405f
Merge remote-tracking branch 'upstream/master'
AbdelStark Jul 9, 2019
9c41365
Merge remote-tracking branch 'upstream/master'
AbdelStark Jul 11, 2019
8a973b0
Merge remote-tracking branch 'upstream/master'
AbdelStark Jul 11, 2019
3699d76
Merge remote-tracking branch 'upstream/master'
AbdelStark Jul 12, 2019
74f154f
Merge remote-tracking branch 'upstream/master'
AbdelStark Jul 12, 2019
73e90c0
Merge remote-tracking branch 'upstream/master'
AbdelStark Aug 5, 2019
08cc7ca
[PAN-2995] Make account.getAddress() return an Optional<Address>
AbdelStark Aug 5, 2019
15f90ea
fix Jenkins failure
AbdelStark Aug 5, 2019
a9e0327
Merge remote-tracking branch 'upstream/master'
AbdelStark Aug 6, 2019
e5dc3fa
fix failing test
AbdelStark Aug 6, 2019
e2bb261
fix failing test
AbdelStark Aug 6, 2019
727cede
Revert "fix failing test"
AbdelStark Aug 6, 2019
093b170
Revert "fix failing test"
AbdelStark Aug 6, 2019
f6ff898
Revert "fix Jenkins failure"
AbdelStark Aug 6, 2019
8ac0dc6
Revert "[PAN-2995] Make account.getAddress() return an Optional<Addre…
AbdelStark Aug 6, 2019
60fea80
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 7, 2019
d44b955
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 8, 2019
cc2677f
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 9, 2019
f616a41
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 22, 2019
c7297be
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 22, 2019
4caed2c
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 23, 2019
e3d8da6
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 23, 2019
ea6f798
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 26, 2019
c81600c
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 26, 2019
5454265
init trace_replayBlockTransactions
AbdelStark Aug 26, 2019
756f52b
Revert "init trace_replayBlockTransactions"
AbdelStark Aug 27, 2019
03ee39b
Revert "Revert "init trace_replayBlockTransactions""
AbdelStark Aug 27, 2019
2f6e055
Update TraceReplayBlockTransactions.java
AbdelStark Aug 27, 2019
d8a7614
Merge remote-tracking branch 'upstream/master' into develop
AbdelStark Aug 27, 2019
055c672
Check request parameters
AbdelStark Aug 27, 2019
fb08604
Update TraceReplayBlockTransactions.java
AbdelStark Aug 27, 2019
bcda14a
implement trace_replayBlockTransactions
AbdelStark Aug 27, 2019
9e2cde2
remove comments
AbdelStark Aug 27, 2019
49955f8
add final modifier for method parameters
AbdelStark Aug 27, 2019
a6b2fe0
fix unit tests
AbdelStark Aug 28, 2019
93cf8fe
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Aug 28, 2019
08473b3
remove useless log
AbdelStark Aug 28, 2019
158d29a
transform address from stack (Bytes32) to an Address
AbdelStark Aug 28, 2019
e038703
trace_replayBlockTransactions new features
AbdelStark Aug 28, 2019
044805a
fix unit tests
AbdelStark Aug 28, 2019
6300a18
Update FlatTrace.java
AbdelStark Aug 28, 2019
da91962
pretty format JSON file
AbdelStark Aug 28, 2019
86510a2
handle smart contract deployments
AbdelStark Aug 28, 2019
082b237
handle smart contract deployment
AbdelStark Aug 29, 2019
d58e8ec
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Aug 29, 2019
4ca0c36
introduce FlatTraceGenerator
AbdelStark Aug 29, 2019
1f9b60b
refactoring
AbdelStark Aug 29, 2019
fe1f891
spotless apply
AbdelStark Aug 30, 2019
f5b1fc7
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Aug 30, 2019
cbddee0
update tests to compare Json node tree independently of the order
AbdelStark Aug 30, 2019
c3b86c8
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 3, 2019
c93685d
fix unit tests
AbdelStark Sep 3, 2019
10680b0
spotless apply
AbdelStark Sep 3, 2019
e736716
introduce SELFDESTRUCT
AbdelStark Sep 3, 2019
7aa80e7
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 3, 2019
4841e66
set result to null when suicide type
AbdelStark Sep 3, 2019
6dd19fb
remove result field, use builder only
AbdelStark Sep 3, 2019
f1878ef
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 4, 2019
025eb42
re-enable tracing tests
AbdelStark Sep 4, 2019
5babade
implement gas used computation
AbdelStark Sep 4, 2019
96f2e7d
get self destruct refund balance from message frame
AbdelStark Sep 4, 2019
dc70ffc
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 5, 2019
978dcc7
give access to `ProtocolSchedule` to get `GasCalculator`
AbdelStark Sep 5, 2019
34880a2
fix gas used computation for subtrace (1 level deep)
AbdelStark Sep 5, 2019
ac1a598
fix input, use all memory and not only first element
AbdelStark Sep 5, 2019
4ea752b
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 5, 2019
a250cde
fix trace addresses
AbdelStark Sep 6, 2019
d472e97
debug log
AbdelStark Sep 6, 2019
88ee6aa
remove some tests files
AbdelStark Sep 6, 2019
2857e22
Revert "remove some tests files"
AbdelStark Sep 6, 2019
8f1ae06
debug jenkins
AbdelStark Sep 9, 2019
c3d41e1
out instead of err
AbdelStark Sep 9, 2019
eb52fb6
spotless apply
AbdelStark Sep 9, 2019
dddf2d3
add debug info
AbdelStark Sep 9, 2019
f1d9ba7
remove static modifier for blockchainSetupUtil field
AbdelStark Sep 9, 2019
efa3337
remove unused field
AbdelStark Sep 9, 2019
74ff428
add javadoc for gasCalculator parameter
AbdelStark Sep 9, 2019
30861e8
Merge remote-tracking branch 'upstream/master' into feature/pie-1805-…
AbdelStark Sep 10, 2019
4888ade
fix PR review comments
AbdelStark Sep 10, 2019
dfb404b
add javadoc for Trace interface
AbdelStark Sep 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,8 @@ public boolean equals(final Object obj) {
public String toString() {
return Long.toString(value);
}

public String toHexString() {
return String.format("0x%s", Long.toHexString(value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/
package tech.pegasys.pantheon.ethereum.debug;

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.vm.ExceptionalHaltReason;
import tech.pegasys.pantheon.util.bytes.Bytes32;
import tech.pegasys.pantheon.util.bytes.BytesValue;
Expand All @@ -36,6 +38,7 @@ public class TraceFrame {
private final Optional<Bytes32[]> memory;
private final Optional<Map<UInt256, UInt256>> storage;
private final Optional<BytesValue> revertReason;
private final Optional<Map<Address, Wei>> maybeRefunds;

public TraceFrame(
final int pc,
Expand All @@ -47,7 +50,8 @@ public TraceFrame(
final Optional<Bytes32[]> stack,
final Optional<Bytes32[]> memory,
final Optional<Map<UInt256, UInt256>> storage,
final Optional<BytesValue> revertReason) {
final Optional<BytesValue> revertReason,
final Optional<Map<Address, Wei>> maybeRefunds) {
this.pc = pc;
this.opcode = opcode;
this.gasRemaining = gasRemaining;
Expand All @@ -58,6 +62,32 @@ public TraceFrame(
this.memory = memory;
this.storage = storage;
this.revertReason = revertReason;
this.maybeRefunds = maybeRefunds;
}

public TraceFrame(
final int pc,
final String opcode,
final Gas gasRemaining,
final Optional<Gas> gasCost,
final int depth,
final EnumSet<ExceptionalHaltReason> exceptionalHaltReasons,
final Optional<Bytes32[]> stack,
final Optional<Bytes32[]> memory,
final Optional<Map<UInt256, UInt256>> storage,
final Optional<BytesValue> revertReason) {
this(
pc,
opcode,
gasRemaining,
gasCost,
depth,
exceptionalHaltReasons,
stack,
memory,
storage,
revertReason,
Optional.empty());
}

public TraceFrame(
Expand Down Expand Up @@ -123,6 +153,10 @@ public Optional<BytesValue> getRevertReason() {
return revertReason;
}

public Optional<Map<Address, Wei>> getMaybeRefunds() {
return maybeRefunds;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.mainnet.MainnetBlockProcessor.TransactionReceiptFactory;
import tech.pegasys.pantheon.ethereum.vm.EVM;
import tech.pegasys.pantheon.ethereum.vm.GasCalculator;

/** A protocol specification. */
public class ProtocolSpec<C> {

private final String name;
private final EVM evm;

private final GasCalculator gasCalculator;

private final TransactionValidator transactionValidator;

private final TransactionProcessor transactionProcessor;
Expand Down Expand Up @@ -76,6 +79,7 @@ public class ProtocolSpec<C> {
* @param miningBeneficiaryCalculator determines to whom mining proceeds are paid
* @param precompileContractRegistry all the pre-compiled contracts added
* @param skipZeroBlockRewards should rewards be skipped if it is zero
* @param gasCalculator the gas calculator to use.
*/
public ProtocolSpec(
final String name,
Expand All @@ -94,7 +98,8 @@ public ProtocolSpec(
final Wei blockReward,
final MiningBeneficiaryCalculator miningBeneficiaryCalculator,
final PrecompileContractRegistry precompileContractRegistry,
final boolean skipZeroBlockRewards) {
final boolean skipZeroBlockRewards,
final GasCalculator gasCalculator) {
this.name = name;
this.evm = evm;
this.transactionValidator = transactionValidator;
Expand All @@ -112,6 +117,7 @@ public ProtocolSpec(
this.miningBeneficiaryCalculator = miningBeneficiaryCalculator;
this.precompileContractRegistry = precompileContractRegistry;
this.skipZeroBlockRewards = skipZeroBlockRewards;
this.gasCalculator = gasCalculator;
}

/**
Expand Down Expand Up @@ -259,6 +265,15 @@ public PrecompileContractRegistry getPrecompileContractRegistry() {
return precompileContractRegistry;
}

/**
* Returns the gasCalculator used in this specification.
*
* @return the gas calculator
*/
public GasCalculator getGasCalculator() {
return gasCalculator;
}

public void setTransactionFilter(final TransactionFilter transactionFilter) {
transactionValidator.setTransactionFilter(transactionFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ public ProtocolSpec<T> build(final ProtocolSchedule<T> protocolSchedule) {
blockReward,
miningBeneficiaryCalculator,
precompileContractRegistry,
skipZeroBlockRewards);
skipZeroBlockRewards,
gasCalculator);
}

public interface TransactionProcessorBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

import static tech.pegasys.pantheon.util.uint.UInt256.U_32;

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.core.Gas;
import tech.pegasys.pantheon.ethereum.core.Wei;
import tech.pegasys.pantheon.ethereum.debug.TraceFrame;
import tech.pegasys.pantheon.ethereum.debug.TraceOptions;
import tech.pegasys.pantheon.ethereum.vm.ehalt.ExceptionalHaltException;
Expand Down Expand Up @@ -56,7 +58,8 @@ public void traceExecution(
executeOperation.execute();
} finally {
final Optional<Map<UInt256, UInt256>> storage = captureStorage(frame);

final Optional<Map<Address, Wei>> maybeRefunds =
frame.getRefunds().isEmpty() ? Optional.empty() : Optional.of(frame.getRefunds());
traceFrames.add(
new TraceFrame(
pc,
Expand All @@ -68,7 +71,8 @@ public void traceExecution(
stack,
memory,
storage,
frame.getRevertReason()));
frame.getRevertReason(),
maybeRefunds));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

import java.util.Deque;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
Expand Down Expand Up @@ -202,6 +204,7 @@ public enum Type {
private final LogSeries logs;
private Gas gasRefund;
private final Set<Address> selfDestructs;
private final Map<Address, Wei> refunds;

// Execution Environment fields.
private final Address recipient;
Expand Down Expand Up @@ -271,6 +274,7 @@ private MessageFrame(
this.logs = LogSeries.empty();
this.gasRefund = Gas.ZERO;
this.selfDestructs = new HashSet<>();
this.refunds = new HashMap<>();
this.recipient = recipient;
this.originator = originator;
this.contract = contract;
Expand Down Expand Up @@ -654,6 +658,25 @@ public Set<Address> getSelfDestructs() {
return selfDestructs;
}

/**
* Add refund to the refunds map if not already present.
*
* @param beneficiary the beneficiary of the refund.
* @param amount the amount of the refund.
*/
public void addRefund(final Address beneficiary, final Wei amount) {
refunds.put(beneficiary, amount);
}

/**
* Returns the refunds map.
*
* @return the refunds map
*/
public Map<Address, Wei> getRefunds() {
return refunds;
}

/**
* Returns the current blockchain.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public void execute(final MessageFrame frame) {
frame.getWorldState().getOrCreate(Words.toAddress(frame.popStackItem()));

recipient.incrementBalance(account.getBalance());

// add refund in message frame
frame.addRefund(recipient.getAddress(), account.getBalance());

account.setBalance(Wei.ZERO);

frame.setState(MessageFrame.State.CODE_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.NetServices;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.NetVersion;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.RpcModules;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.TraceReplayBlockTransactions;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.TxPoolPantheonStatistics;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.TxPoolPantheonTransactions;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.Web3ClientVersion;
Expand Down Expand Up @@ -334,6 +335,20 @@ blockchainQueries, new TransactionTracer(blockReplay), parameter),
new AdminChangeLogLevel(parameter));
}

if (rpcApis.contains(RpcApis.TRACE)) {
addMethods(
enabledMethods,
new TraceReplayBlockTransactions(
parameter,
new BlockTracer(
new BlockReplay(
protocolSchedule,
blockchainQueries.getBlockchain(),
blockchainQueries.getWorldStateArchive())),
blockchainQueries,
protocolSchedule));
}

final boolean eea = rpcApis.contains(RpcApis.EEA);
final boolean priv = rpcApis.contains(RpcApis.PRIV);
if (eea || priv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class RpcApis {
public static final RpcApi EEA = new RpcApi("EEA");
public static final RpcApi PRIV = new RpcApi("PRIV");
public static final RpcApi TX_POOL = new RpcApi("TXPOOL");
public static final RpcApi TRACE = new RpcApi("TRACE");

public static final List<RpcApi> DEFAULT_JSON_RPC_APIS = Arrays.asList(ETH, NET, WEB3);

Expand All @@ -52,6 +53,8 @@ public static Optional<RpcApi> valueOf(final String name) {
return Optional.of(PRIV);
} else if (name.equals(TX_POOL.getCliValue())) {
return Optional.of(TX_POOL);
} else if (name.equals(TRACE.getCliValue())) {
return Optional.of(TRACE);
} else {
return Optional.empty();
}
Expand Down
Loading