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

Conversation

AbdelStark
Copy link
Contributor

@AbdelStark AbdelStark commented Aug 27, 2019

PR description

  • iterate through TraceFrame and transform to parity style
  • create FlatTraces from aggregated TraceFrames included in TransactionTrace object
  • detect CALL opcode to retrieve contract address required in parity format
  • detect RETURN opcode to close a subtrace
  • use https://github.com/mbaxter/json-rpc-test-cases to generate test cases

Fixed Issue(s)

- introduce `MonitorableKeyValueStorage`
- factorise code
- remove metrics instanciation in `RocksDbKeyValueStorage` and `ColumnarRocksDbKeyValueStorage`
This reverts commit e2bb261.
This reverts commit e5dc3fa.
@AbdelStark AbdelStark closed this Sep 9, 2019
@AbdelStark AbdelStark reopened this Sep 9, 2019
Copy link
Contributor

@shemnon shemnon left a comment

Choose a reason for hiding this comment

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

There are several classes that have both setter methods and a builder. I wouldn't expect both. Either the object is mutable and setters are used or the object is immutable and a builder is used.


public interface Trace {
@FunctionalInterface
interface ResultWriter {
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: why an interface in an interface? I would expect just one interface TraceResultWriter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trace interface is the common type for FlatTrace and the other types of traces we will add for vmTrace and stateDiff options. So i'll keep Trace interface but as you suggest i'll move ResultWriterto a separate file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that make sense ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the future is to cover vm traces and state diffs then I think it is worth some Javadoc indicating what this interface represents and the intended implementations. Right now it looks like a marker interface (like Serializable) and I don't think that is clear without documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree. i'll do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

? traceFrame.getMemory().get()[0].toString()
: "0x"));
ctx.markAsReturned();
continueToPollContexts = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't use a sentinel boolean I would just use a break statement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// find last non returned transactionTrace
while (continueToPollContexts && (ctx = tracesContexts.pollLast()) != null) {
polledContexts.addFirst(ctx);
if (!ctx.isReturned()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a guard block instead of a nested if would read better since the if covers the rest of the while block.

Suggested change
if (!ctx.isReturned()) {
if (ctx.isReturned()) {
continue;
}

Then remove the matching brace and un indent the block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion. Done.


final long gasCost = cumulativeGasCost.longValue();
// retrieve the previous transactionTrace context
Optional.ofNullable(tracesContexts.peekLast())
Copy link
Contributor

Choose a reason for hiding this comment

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

This use of optional feels a bit clunky and creates an extra optional object. Would this work better?

    if (!traceContexts.isEmpty()) {
        FlatTrace.Context previousContext = traceContexts.peekLast();
        // increment sub traces counter of previous transactionTrace
        previousContext.getBuilder().incSubTraces();
        // set gas cost of previous transactionTrace
        previousContext
            .getBuilder()
            .getResultBuilder()
            .orElse(Result.builder())
            .gasUsed(Gas.of(gasCost).toHexString());
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@AbdelStark
Copy link
Contributor Author

There are several classes that have both setter methods and a builder. I wouldn't expect both. Either the object is mutable and setters are used or the object is immutable and a builder is used.

You right, i have removed setters and use only builders.

@AbdelStark AbdelStark merged commit 8dffdcd into PegaSysEng:master Sep 10, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants