XinFinOrg / XDPoSChain

Customer centric, Hybrid & Interoperable XinFin Network
https://www.xinfin.org
GNU Lesser General Public License v3.0
50 stars 59 forks source link

support for golang tracers + add golang callTracer #558

Open wgr523 opened 3 weeks ago

wgr523 commented 3 weeks ago

Proposed changes

support for golang tracers + add golang callTracer

Types of changes

What types of changes does your code introduce to XDC network? Put an in the boxes that apply

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

wgr523 commented 3 weeks ago

This PR's XXX_legacy.js tracers are not completely equal to XXX.js tracers before this PR. Shall we make XXX_legacy.js equal to prior XXX.js?

s1na commented 3 weeks ago

This PR's XXX_legacy.js tracers are not completely equal to XXX.js tracers before this PR. Shall we make XXX_legacy.js equal to prior XXX.js?

Can you post the diff?

wgr523 commented 2 weeks ago

This PR's XXX_legacy.js tracers are not completely equal to XXX.js tracers before this PR. Shall we make XXX_legacy.js equal to prior XXX.js?

Can you post the diff?

Sure. The diff by running diff call_tracer_legacy.js call_tracer_dev-upgrade.js -u where call_tracer_dev-upgrade.js is the one before this PR:

diff call_tracer_legacy.js call_tracer_dev-upgrade.js -u
--- call_tracer_legacy.js   2024-06-19 22:56:44.000000000 +0800
+++ call_tracer_dev-upgrade.js  2024-06-19 22:57:58.000000000 +0800
@@ -61,14 +61,7 @@
            if (this.callstack[left-1].calls === undefined) {
                this.callstack[left-1].calls = [];
            }
-           this.callstack[left-1].calls.push({
-               type:    op,
-               from:    toHex(log.contract.getAddress()),
-               to:      toHex(toAddress(log.stack.peek(0).toString(16))),
-               gasIn:   log.getGas(),
-               gasCost: log.getCost(),
-               value:   '0x' + db.getBalance(log.contract.getAddress()).toString(16)
-           });
+           this.callstack[left-1].calls.push({type: op});
            return
        }
        // If a new method invocation is being done, add to the call stack
@@ -139,12 +132,13 @@
                // If the call was a contract call, retrieve the gas usage and output
                if (call.gas !== undefined) {
                    call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost + call.gas - log.getGas()).toString(16);
-               }
-               var ret = log.stack.peek(0);
-               if (!ret.equals(0)) {
-                   call.output = toHex(log.memory.slice(call.outOff, call.outOff + call.outLen));
-               } else if (call.error === undefined) {
-                   call.error = "internal failure"; // TODO(karalabe): surface these faults somehow
+
+                   var ret = log.stack.peek(0);
+                   if (!ret.equals(0)) {
+                       call.output = toHex(log.memory.slice(call.outOff, call.outOff + call.outLen));
+                   } else if (call.error === undefined) {
+                       call.error = "internal failure"; // TODO(karalabe): surface these faults somehow
+                   }
                }
                delete call.gasIn; delete call.gasCost;
                delete call.outOff; delete call.outLen;
@@ -214,7 +208,7 @@
        } else if (ctx.error !== undefined) {
            result.error = ctx.error;
        }
-       if (result.error !== undefined && (result.error !== "execution reverted" || result.output ==="0x")) {
+       if (result.error !== undefined) {
            delete result.output;
        }
        return this.finalize(result);

For other tracers, legacy tracer and dev-upgrade tracer are the same.

s1na commented 2 weeks ago

The diff by running diff call_tracer_legacy.js call_tracer_dev-upgrade.js -u where call_tracer_dev-upgrade.js is the one before this PR

between those two files call_tracer_legacy.js seems more correct.

wgr523 commented 2 weeks ago

The diff by running diff call_tracer_legacy.js call_tracer_dev-upgrade.js -u where call_tracer_dev-upgrade.js is the one before this PR

between those two files call_tracer_legacy.js seems more correct.

So I guess call_tracer_legacy.js is already ready in this PR. No further change is needed.