Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation trace get #3436

Merged
merged 33 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
902da85
added test for trace_transaction
kjazgar Sep 2, 2021
f6c8702
Changed trace_transaction and added test for it.
kjazgar Sep 9, 2021
3906714
add tests
MarekM25 Sep 9, 2021
2595e37
add multi call tests
MarekM25 Sep 9, 2021
0ab560e
Merge branch 'trace_transaction_fixes' into changes_in_trace_module
kjazgar Sep 9, 2021
d4d48c6
add reward calculator to TraceRpcModuleTests
MarekM25 Sep 9, 2021
173bed4
Merge branch 'trace_transaction_fixes' into changes_in_trace_module
kjazgar Sep 9, 2021
5e15799
And fix :)
MarekM25 Sep 9, 2021
a3c1163
build fixes
MarekM25 Sep 9, 2021
1d222e7
Merge branch 'trace_transaction_fixes' into changes_in_trace_module
kjazgar Sep 9, 2021
522bfda
Changes in TraceTx.
kjazgar Sep 10, 2021
9fe8971
Merge remote-tracking branch 'origin/master' into changes_in_trace_mo…
kjazgar Sep 10, 2021
777804a
small refactoring
kjazgar Sep 10, 2021
e3dcd69
Changed TraceTx as not to return a SingleOrDefault value.
kjazgar Sep 10, 2021
6284525
Deleted unnecessary part.
kjazgar Sep 10, 2021
4742619
Fixed test.
kjazgar Sep 13, 2021
50a0e8e
Implemented trace_callMany and added test.
kjazgar Sep 14, 2021
786d7aa
Implemented trace_get and added test.
kjazgar Sep 14, 2021
283d167
Changed params in trace_callMany.
kjazgar Sep 15, 2021
7015aad
fix
kjazgar Sep 15, 2021
d2eeb66
Changed parameters, added class.
kjazgar Sep 15, 2021
40390fe
fix
kjazgar Sep 15, 2021
5e301a2
Changed parameters in trace_callMany - test.
kjazgar Sep 16, 2021
99225c6
Merge branch 'implementation_trace_callMany' into implementation_trac…
kjazgar Sep 16, 2021
5a3994d
Changes in trace_get - test.
kjazgar Sep 16, 2021
892e4c6
Changes in trace_get.
kjazgar Sep 17, 2021
e2be58b
Changed parameter type in trace_get.
kjazgar Sep 17, 2021
accd501
Added error field to txTrace - test.
kjazgar Sep 20, 2021
55785ae
Deleted unnecessary part.
kjazgar Sep 20, 2021
15f5c73
Implementation of trace_get.
kjazgar Sep 21, 2021
cfa9b8a
Deleted unnecessary parts.
kjazgar Sep 21, 2021
8463f1a
Deleted unnecessary part.
kjazgar Sep 21, 2021
0667474
Added tests for trace_replayTransaction.
kjazgar Oct 6, 2021
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 @@ -14,6 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Crypto;
Expand Down Expand Up @@ -60,10 +61,10 @@ public ParityLikeBlockTracer(ParityTraceTypes types, TxTraceFilter? traceFilter,

public override void ReportReward(Address author, string rewardType, UInt256 rewardValue)
{
ParityLikeTxTrace rewardTrace = TxTraces.LastOrDefault();
if (rewardTrace == null)
ParityLikeTxTrace rewardTrace = TxTraces.LastOrDefault();
if (rewardTrace == null)
return;

rewardTrace.Action = new ParityTraceAction();
rewardTrace.Action.RewardType = rewardType;
rewardTrace.Action.Value = rewardValue;
Expand All @@ -72,6 +73,8 @@ public override void ReportReward(Address author, string rewardType, UInt256 rew
rewardTrace.Action.TraceAddress = new int[] { };
rewardTrace.Action.Type = "reward";
rewardTrace.Action.Result = null;


}

public override void StartNewBlockTrace(Block block)
Expand Down
106 changes: 93 additions & 13 deletions src/Nethermind/Nethermind.JsonRpc.Test/Modules/TraceRpcModuleTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface ITraceRpcModule : IRpcModule
ResultWrapper<ParityTxTraceFromStore[]> trace_block([JsonRpcParameter(ExampleValue = "latest")] BlockParameter numberOrTag);

[JsonRpcMethod(Description = "", IsImplemented = false, IsSharable = false)]
ResultWrapper<ParityTxTraceFromStore[]> trace_get(Keccak txHash, int[] positions);
ResultWrapper<ParityTxTraceFromStore[]> trace_get(Keccak txHash, long[] positions);

[JsonRpcMethod(Description = "", IsImplemented = true,
IsSharable = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ public ParityTxTraceFromReplay(ParityLikeTxTrace txTrace, bool includeTransactio
TransactionHash = includeTransactionHash ? txTrace.TransactionHash : null;
}

public ParityTxTraceFromReplay(IReadOnlyCollection<ParityLikeTxTrace> txTraces, bool includeTransactionHash = false)
{
foreach (ParityLikeTxTrace txTrace in txTraces)
{
Output = txTrace.Output;
VmTrace = txTrace.VmTrace;
Action = txTrace.Action;
StateChanges = txTrace.StateChanges;
TransactionHash = includeTransactionHash ? txTrace.TransactionHash : null;
}

}

public byte[] Output { get; set; }

public Keccak TransactionHash { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public static ParityTxTraceFromStore[] FromTxTrace(ParityLikeTxTrace txTrace)
AddActionsRecursively(results, txTrace, txTrace.Action);
return results.ToArray();
}

public static ParityTxTraceFromStore[] FromTxTrace(IReadOnlyCollection<ParityLikeTxTrace> txTrace)
{
List<ParityTxTraceFromStore> results = new();
foreach (ParityLikeTxTrace tx in txTrace)
{
AddActionsRecursively(results, tx, tx.Action);
}

return results.ToArray();

}

private static void AddActionsRecursively(List<ParityTxTraceFromStore> results, ParityLikeTxTrace txTrace, ParityTraceAction txTraceAction)
{
Expand Down
32 changes: 23 additions & 9 deletions src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
using MathNet.Numerics.Distributions;
Expand Down Expand Up @@ -129,7 +130,7 @@ public ResultWrapper<ParityTxTraceFromReplay> trace_replayTransaction(Keccak txH

Block block = blockSearch.Object;

ParityLikeTxTrace txTrace = TraceTx(block, txHash, GetParityTypes(traceTypes));
IReadOnlyCollection<ParityLikeTxTrace> txTrace = TraceTx(block, txHash, GetParityTypes(traceTypes));
return ResultWrapper<ParityTxTraceFromReplay>.Success(new ParityTxTraceFromReplay(txTrace));
}

Expand Down Expand Up @@ -189,9 +190,21 @@ public ResultWrapper<ParityTxTraceFromStore[]> trace_block(BlockParameter blockP
return ResultWrapper<ParityTxTraceFromStore[]>.Success(txTraces.SelectMany(ParityTxTraceFromStore.FromTxTrace).ToArray());
}

public ResultWrapper<ParityTxTraceFromStore[]> trace_get(Keccak txHash, int[] positions)
public ResultWrapper<ParityTxTraceFromStore[]> trace_get(Keccak txHash, long[] positions)
{
throw new NotImplementedException();
ResultWrapper<ParityTxTraceFromStore[]> traceTransaction = trace_transaction(txHash);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consideration - not sure if implement - keep small cache of recently traced transactions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukaszRozmej agree with you, but firstly I think we need to correct trace bugs like:
#3422
#3034
#3312
#3298


List<ParityTxTraceFromStore> traces = new();
foreach (long t in positions)
{
if (traceTransaction.Data.Length > t+1)
{
ParityTxTraceFromStore tr = traceTransaction.Data[t+1];
traces.Add(tr);
}
}

return ResultWrapper<ParityTxTraceFromStore[]>.Success(traces.ToArray());
}

public ResultWrapper<ParityTxTraceFromStore[]> trace_transaction(Keccak txHash)
Expand All @@ -207,10 +220,10 @@ public ResultWrapper<ParityTxTraceFromStore[]> trace_transaction(Keccak txHash)
{
return ResultWrapper<ParityTxTraceFromStore[]>.Fail(blockSearch);
}

Block block = blockSearch.Object;

ParityLikeTxTrace txTrace = TraceTx(block, txHash, ParityTraceTypes.Trace);
IReadOnlyCollection<ParityLikeTxTrace> txTrace = TraceTx(block, txHash, ParityTraceTypes.Trace);
return ResultWrapper<ParityTxTraceFromStore[]>.Success(ParityTxTraceFromStore.FromTxTrace(txTrace));
}

Expand All @@ -224,16 +237,17 @@ private IReadOnlyCollection<ParityLikeTxTrace> TraceBlock(Block block, ParityTra

return listener.BuildResult();
}

private ParityLikeTxTrace TraceTx(Block block, Keccak txHash, ParityTraceTypes traceTypes)
private IReadOnlyCollection<ParityLikeTxTrace> TraceTx(Block block, Keccak txHash, ParityTraceTypes traceTypes)
{
using CancellationTokenSource cancellationTokenSource = new(_cancellationTokenTimeout);
CancellationToken cancellationToken = cancellationTokenSource.Token;

ParityLikeBlockTracer listener = new(txHash, traceTypes);
_tracer.Trace(block, listener.WithCancellation(cancellationToken));

return listener.BuildResult().SingleOrDefault();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the tests to trace_replayTransactions with Trace and Rewards flags?

return listener.BuildResult();
}

}
}