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

Add new tracing API #11100

Merged
merged 25 commits into from
Aug 30, 2023
Merged

Add new tracing API #11100

merged 25 commits into from
Aug 30, 2023

Conversation

fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented Jul 25, 2023

Related Issues

Related: filecoin-project/ref-fvm#1793 and https://github.com/filecoin-project/fvm-pm/issues/613

Relevant PR: filecoin-project/ref-fvm#1823 and filecoin-project/filecoin-ffi#411

Proposed Changes

This PR adds a new tracing API to lotus RPC which should unblock Blockscout/ngram which rely on this feature.

The following two RPC methods will be exported alongside other eth rpc methods:

I used the OpenEthereum/Nethermind/Erigon client version since I liked that API more than what Geth implements and implemented the two required trace methods as listed by Blockscout.

Additional Info

Note that I thought about adding a new lotus config that enables/disables the tracing API, but for now just made it be set any time EnableEthRPC is set.

Test plan

Testing trace_block

curl -s http://localhost:1234/rpc/v1 -X POST -H "Content-Type: application/json" --data '{"method":"trace_block", "params":["3166855"],"id":1,"jsonrpc":"2.0"}'|jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "action": {
        "callType": "call",
        "from": "0xff0000000000000000000000000000000023f918",
        "to": "0xff000000000000000000000000000000001ced62",
        "gas": "0x1741f00",
        "input": "0x868e10c400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000051000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000f285168182004081820d58c0841978f977b7804532f774a39ae2292b76808a8186f6947fd1db444069d8892b19aa56908ef0ec7b40c585ebb96f354bb27b7f9e7b7b04db7a841a7b61e746e52f1f80a5680e39a831e6d361b507df8d2119c98f364b1d62e1e9d76adbe923d50cf913d1e176c0acaf1448a84e74ccaf5c49e0ca886877538d55cbf63fdf84374b57b4ccb9d853e2d366bbb3d51d0d2198688d43d0c134ec3b64252e58d525dc883b5856d9cc18564d008be045be415cd8efb182dee4b65ba5523142ba506b121a0030527b5820fb2947b9765ce0872aaa93d286aa9f188fecf69e70be84f22be9d2bdd5c8ec760000000000000000000000000000",
        "value": "0x0"
      },
      "result": {
        "gasUsed": "0x150bad3",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      },
      "subtraces": 0,
      "traceAddress": [],
      "Type": "call",
      "blockHash": "0x0117cdaea1750423788078050cadfcfcd368c3f39e8359d2e2b3a1ce9049ce73",
      "blockNumber": 3166855,
      "transactionHash": "0xb2407c04381dedb286426d121aff82643a6b6f623f7d39111a6856bf8d2291fd",
      "transactionPosition": 1
    },
    {
      "action": {
        "callType": "call",
        "from": "0xff0000000000000000000000000000000023d0e7",
        "to": "0xff000000000000000000000000000000001d6702",
        "gas": "0x1882fda",
        "input": "0x868e10c400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000051000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000f38518288182004081820d58c08984dd25b82e696b09fbfbe0bfe1b24abb87bed1291024f8fcff5ba6861bfcd36024d541128704bdeadb6390d673709592b7a7fbbd439faa76ae4010397723dca8b71123c3dc7cfd3116b94671a78de14684f502ede8bcd4fa7a1df09d2da5a70c1f503769a68e1e5790200c7a148b797455dfce3f70bb797405dbe346a8570d98edbd9752be5fdc2bbbdce03c7edffaa190a395e2c832549ed1583f5e4c50e1e940faa9756a3e570d7c75903997d2f0b30df58487d17e4b03f5f764a02d07de1a0030527b5820fb2947b9765ce0872aaa93d286aa9f188fecf69e70be84f22be9d2bdd5c8ec7600000000000000000000000000",
        "value": "0x0"
      },
      "result": {
        "gasUsed": "0x1623212",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      },
      "subtraces": 0,
      "traceAddress": [],
      "Type": "call",
      "blockHash": "0x0117cdaea1750423788078050cadfcfcd368c3f39e8359d2e2b3a1ce9049ce73",
      "blockNumber": 3166855,
      "transactionHash": "0x39c961b9d5a2d8c2b37fb7a939eae302d59ac845a710bda099dcd42ae2d52a54",
      "transactionPosition": 2
    },
    {
      "action": {
        "callType": "call",
        "from": "0xff0000000000000000000000000000000000f356",
        "to": "0xff0000000000000000000000000000000000cd1a",
        "gas": "0xbbe9a",
        "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
        "value": "0x29a2241af62c0000"
      },
      "result": {
        "gasUsed": "0x12045b",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      },
      "subtraces": 0,
      "traceAddress": [],
      "Type": "call",
      "blockHash": "0x0117cdaea1750423788078050cadfcfcd368c3f39e8359d2e2b3a1ce9049ce73",
      "blockNumber": 3166855,
      "transactionHash": "0xc8c227a3a581949db0ba5b89a036f2341342b30af328a07218edb6385cd667d4",
      "transactionPosition": 3
    },
    {
      "action": {
        "callType": "call",
        "from": "0xff0000000000000000000000000000000000f356",
        "to": "0xff00000000000000000000000000000000010874",
        "gas": "0xbbe9a",
        "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
        "value": "0x29a2241af62c0000"
      },
      "result": {
        "gasUsed": "0x12045b",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      },
      "subtraces": 0,
      "traceAddress": [],
      "Type": "call",
      "blockHash": "0x0117cdaea1750423788078050cadfcfcd368c3f39e8359d2e2b3a1ce9049ce73",
      "blockNumber": 3166855,
      "transactionHash": "0xba3db829b9e17b2e0d25c239e00305d3a7ba6881851b5cbe8791f4f20d289a35",
      "transactionPosition": 4
    },
    {
      "action": {
        "callType": "call",
        "from": "0xff0000000000000000000000000000000000f356",
        "to": "0xff00000000000000000000000000000000010874",
        "gas": "0xbbe9a",
        "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
        "value": "0x29a2241af62c0000"
      },
      "result": {
        "gasUsed": "0x12045b",
        "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
      },
      "subtraces": 0,
      "traceAddress": [],
      "Type": "call",
      "blockHash": "0x0117cdaea1750423788078050cadfcfcd368c3f39e8359d2e2b3a1ce9049ce73",
      "blockNumber": 3166855,
      "transactionHash": "0xe4e433cb335fb1290d1ace74d42a5f225d9e7f9ddb1e47e799e8b1f9e7d12582",
      "transactionPosition": 5
    },

   ...

Testing trace_replayBlockTransactions

curl -s http://localhost:1234/rpc/v1 -X POST -H "Content-Type: application/json" --data '{"method":"trace_replayBlockTransactions", "params":["3166855", ["trace"]],"id":1,"jsonrpc":"2.0"}'|jq
{
  "jsonrpc": "2.0",
  "result": [
    {
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "stateDiff": null,
      "trace": [
        {
          "action": {
            "callType": "call",
            "from": "0xff0000000000000000000000000000000023f918",
            "to": "0xff000000000000000000000000000000001ced62",
            "gas": "0x1741f00",
            "input": "0x868e10c400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000051000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000f285168182004081820d58c0841978f977b7804532f774a39ae2292b76808a8186f6947fd1db444069d8892b19aa56908ef0ec7b40c585ebb96f354bb27b7f9e7b7b04db7a841a7b61e746e52f1f80a5680e39a831e6d361b507df8d2119c98f364b1d62e1e9d76adbe923d50cf913d1e176c0acaf1448a84e74ccaf5c49e0ca886877538d55cbf63fdf84374b57b4ccb9d853e2d366bbb3d51d0d2198688d43d0c134ec3b64252e58d525dc883b5856d9cc18564d008be045be415cd8efb182dee4b65ba5523142ba506b121a0030527b5820fb2947b9765ce0872aaa93d286aa9f188fecf69e70be84f22be9d2bdd5c8ec760000000000000000000000000000",
            "value": "0x0"
          },
          "result": {
            "gasUsed": "0x150bad3",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
          },
          "subtraces": 0,
          "traceAddress": [],
          "Type": "call"
        }
      ],
      "transactionHash": "0xb2407c04381dedb286426d121aff82643a6b6f623f7d39111a6856bf8d2291fd",
      "vmTrace": null
    },
    {
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "stateDiff": null,
      "trace": [
        {
          "action": {
            "callType": "call",
            "from": "0xff0000000000000000000000000000000023d0e7",
            "to": "0xff000000000000000000000000000000001d6702",
            "gas": "0x1882fda",
            "input": "0x868e10c400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000051000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000f38518288182004081820d58c08984dd25b82e696b09fbfbe0bfe1b24abb87bed1291024f8fcff5ba6861bfcd36024d541128704bdeadb6390d673709592b7a7fbbd439faa76ae4010397723dca8b71123c3dc7cfd3116b94671a78de14684f502ede8bcd4fa7a1df09d2da5a70c1f503769a68e1e5790200c7a148b797455dfce3f70bb797405dbe346a8570d98edbd9752be5fdc2bbbdce03c7edffaa190a395e2c832549ed1583f5e4c50e1e940faa9756a3e570d7c75903997d2f0b30df58487d17e4b03f5f764a02d07de1a0030527b5820fb2947b9765ce0872aaa93d286aa9f188fecf69e70be84f22be9d2bdd5c8ec7600000000000000000000000000",
            "value": "0x0"
          },
          "result": {
            "gasUsed": "0x1623212",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
          },
          "subtraces": 0,
          "traceAddress": [],
          "Type": "call"
        }
      ],
      "transactionHash": "0x39c961b9d5a2d8c2b37fb7a939eae302d59ac845a710bda099dcd42ae2d52a54",
      "vmTrace": null
    },
    {
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "stateDiff": null,
      "trace": [
        {
          "action": {
            "callType": "call",
            "from": "0xff0000000000000000000000000000000000f356",
            "to": "0xff0000000000000000000000000000000000cd1a",
            "gas": "0xbbe9a",
            "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
            "value": "0x29a2241af62c0000"
          },
          "result": {
            "gasUsed": "0x12045b",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
          },
          "subtraces": 0,
          "traceAddress": [],
          "Type": "call"
        }
      ],
      "transactionHash": "0xc8c227a3a581949db0ba5b89a036f2341342b30af328a07218edb6385cd667d4",
      "vmTrace": null
    },
    {
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "stateDiff": null,
      "trace": [
        {
          "action": {
            "callType": "call",
            "from": "0xff0000000000000000000000000000000000f356",
            "to": "0xff00000000000000000000000000000000010874",
            "gas": "0xbbe9a",
            "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
            "value": "0x29a2241af62c0000"
          },
          "result": {
            "gasUsed": "0x12045b",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
          },
          "subtraces": 0,
          "traceAddress": [],
          "Type": "call"
        }
      ],
      "transactionHash": "0xba3db829b9e17b2e0d25c239e00305d3a7ba6881851b5cbe8791f4f20d289a35",
      "vmTrace": null
    },
    {
      "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
      "stateDiff": null,
      "trace": [
        {
          "action": {
            "callType": "call",
            "from": "0xff0000000000000000000000000000000000f356",
            "to": "0xff00000000000000000000000000000000010874",
            "gas": "0xbbe9a",
            "input": "0x868e10c40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000000",
            "value": "0x29a2241af62c0000"
          },
          "result": {
            "gasUsed": "0x12045b",
            "output": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
          },
          "subtraces": 0,
          "traceAddress": [],
          "Type": "call"
        }
      ],
      "transactionHash": "0xe4e433cb335fb1290d1ace74d42a5f225d9e7f9ddb1e47e799e8b1f9e7d12582",
      "vmTrace": null
    },
    ...

Checklist

Before you mark the PR ready for review, please make sure that:

  • Commits have a clear commit message.
  • PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, build, chore, ci, docs, perf, refactor, revert, style, test
    • area, e.g. api, chain, state, market, mempool, multisig, networking, paych, proving, sealing, wallet, deps
  • New features have usage guidelines and / or documentation updates in
  • Tests exist for new functionality or change in behavior
  • CI is green

@fridrik01 fridrik01 force-pushed the traceapi branch 3 times, most recently from 61dcd9c to cb63de6 Compare July 25, 2023 17:11
node/impl/full/trace.go Outdated Show resolved Hide resolved
@fridrik01 fridrik01 force-pushed the traceapi branch 2 times, most recently from 064990a to 0355557 Compare July 27, 2023 17:16
@fridrik01 fridrik01 changed the title [WIP] Add new tracing API Add new tracing API Jul 27, 2023
@fridrik01 fridrik01 marked this pull request as ready for review July 27, 2023 18:15
@fridrik01 fridrik01 requested a review from a team as a code owner July 27, 2023 18:15
@Stebalien
Copy link
Member

From our discussion, we have a few edge cases we need to handle... quite a few. Ideally, we'd handle all of these cases inside the ethereum json-rpc API module in lotus without touching the FVM (except to, maybe, add additional tracing information where necessary). The FVM is otherwise supposed to have no idea that the EVM exists (except for a few hacks that will hopefully go away in the near future).

I hope I included everything... but, to be honest, we'll probably find more edge cases and I likely underspecified a few things.

Native calls

(both from EVM actors and from native actors)

In general (exceptions noted in the EVM section), we need to format native calls in a way that makes sense to Ethereum tooling. That means, if we see a call not on with InvokeEVM method number (use the constant, we need to convert the inputs & outputs into solidity "ABI".

Luckily, we already have a mechanism for this. Specifically, when an EVM actor is invoked with a method number above 1023 that's not frc42(InvokeEVM) (3844450837), the EVM actor hits this fallback method, translates the inputs into Solidity ABI, then translates the outputs from Solidity ABI back into a "native" return value.

Here, we need to:

  1. Translate the call inputs into Solidity ABI, as above.
  2. Translate the outputs into Solidity ABI (reverse of what we're doing in the EVM.

Basically, we want to make native calls look like calls to a contract like our FilecoinFallback test.

Native actor creation

In Filecoin, actor creation happens by sending messages (calling actors):

  1. Actor A calls to the init actor on method 2 (Exec, bad name).
  2. The init actor creates the target actor B then calls it on method 1 (the constructor).

Unfortunately, it's going to be difficult to make this look like an EVM contract creation but we can hack it...

Personally, I'd:

  1. Collapse these two calls into a single "create".
  2. Pretend that it's a CREATE instruction.
  3. Use [0xFE] as the initcode (the parameters). This bytecode is invalid so it'll never be mistaken for an EVM contract.
  4. Drop any return data.

EVM contract creation

With EVM contracts, there's an extra step

  1. EVM contract A calls the EAM (Ethereum Address Manager) on method 2 (create) or 3 (create2).
  2. The EAM calls the init actor on method 3 (Exec4).
  3. The init actor creates the target actor B then calls it on method 1.

In the EVM trace, we need to make these look like CREATE and CREATE2 calls, skipping over the EAM and Init actor.

EVM call special casing

As noted above, there are some exceptions to the rule where we convert "native" calls into "solidity ABI" calls. Specifically, any outbound call from an EVM actor on methods 1-1023. These calls are side-effects from EVM instructions and should be dropped from the trace.

EVM -> EVM calls

As we discussed, we need to handle EVM -> EVM calls:

  1. Normal EVM->EVM calls will look like a call to InvokeEVM (method 3844450837). We just need to decode the parameters/return value. We also need to look at the readonly flag.
  2. The tricky case is DelegateCall. In that case, we need to:
    1. Look for from an EVM actor to itself on InvokeContractDelegate, method 6.
    2. Search backwards in the trace for a call to another actor (A) on method 3 (https://github.com/filecoin-project/builtin-actors/blob/a77674d65d42dc3547ed2753d5e8c729971920ef/actors/evm/src/lib.rs#L64).
    3. Treat this as a delegate call to actor A.

@fridrik01 fridrik01 marked this pull request as draft July 31, 2023 17:29
@fridrik01
Copy link
Contributor Author

@Stebalien for the EVM -> EVM calls specifically for 2) regarding DelegateCall, when you mention that we need to "search backwards in the trace for a call to another actor (A) on method 3" does that mean we need to look up the call hierarchy or could should this be in a previous subcall at the same level (probably the latter since that is the only thing I see in the traces but just wanted to confirm) ?

@Stebalien
Copy link
Member

Same level and it should be the adjacent call. Really, I'd memoize the last call on method 3 when handling calls from the EVM.

@fridrik01 fridrik01 force-pushed the traceapi branch 2 times, most recently from fd52be7 to f48463d Compare August 8, 2023 16:26
@fridrik01 fridrik01 marked this pull request as ready for review August 8, 2023 17:30
@arajasek
Copy link
Contributor

@fridrik01 Did you consider simply adding this into the existing "EthAPI"? This seems to fundamentally be a restatement of existing Lotus APIs like StateReplay etc., except Eth-friendly, and we've put those kinds of methods in the EthAPI so far.

I might be missing something.

@fridrik01
Copy link
Contributor Author

@fridrik01 Did you consider simply adding this into the existing "EthAPI"? This seems to fundamentally be a restatement of existing Lotus APIs like StateReplay etc., except Eth-friendly, and we've put those kinds of methods in the EthAPI so far.

I might be missing something.

Yes, I think I started actually with the implementation first in the EthAPI but soon refactored it to keep them separate as its very tracing specific and introduces multiple types which would add complexity to an already huge file (it would blow up to 3K+ LOC with this PR).

@arajasek
Copy link
Contributor

@fridrik01 Did you consider simply adding this into the existing "EthAPI"? This seems to fundamentally be a restatement of existing Lotus APIs like StateReplay etc., except Eth-friendly, and we've put those kinds of methods in the EthAPI so far.
I might be missing something.

Yes, I think I started actually with the implementation first in the EthAPI but soon refactored it to keep them separate as its very tracing specific and introduces multiple types which would add complexity to an already huge file (it would blow up to 3K+ LOC with this PR).

Hmm, so I definitely agree that that file is quite large already. Would you be open to doing the following:

  • A prefactor that introduces a new eth_util.go file that just contains all the helpers. We can also move any types in the eth.go file to eth_types.go in this refactor.
  • Introducing these methods in the EthAPI, with the large helpers put in eth_util.go (or even some eth_trace.go file?

I do think we should avoid adding a new module if we can.

@fridrik01 fridrik01 force-pushed the traceapi branch 2 times, most recently from 1d6c3ad to 0843d8c Compare August 16, 2023 21:58
@fridrik01
Copy link
Contributor Author

@arajasek I removed the module and refactored the eth.go so that now it almost exclusively has only the interface methods. I moved the trace related code to eth_trace.go, event related code to eth_event.go and helper/util functions to eth_utils.go. This does make this PR way large, but the relevant code for review is in the two Trace methods in eth.go and then all of eth_trace.go.

Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

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

Partial review

api/api_full.go Outdated Show resolved Hide resolved
node/impl/full/eth.go Outdated Show resolved Hide resolved
node/impl/full/eth.go Outdated Show resolved Hide resolved
node/impl/full/eth.go Outdated Show resolved Hide resolved
node/impl/full/eth.go Outdated Show resolved Hide resolved
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Initial pass. I'll continue tomorrow.

node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
node/impl/full/trace.go Outdated Show resolved Hide resolved
@Stebalien
Copy link
Member

Writing down what we discussed in the sync: We need to make everything "look" like an Ethereum call/transaction. This means:

  1. Finding everything that is an Ethereum call/transaction/contract-creation, and correctly decoding parameters/return values.
  2. Finding everything that isn't an Ethereum call/transaction/contract-creation (i.e., all "native Filecoin" calls), and encoding the parameters & return value as a "solidity ABI" call.

Concretely:

  1. If it's a call to the InvokeEVM method (on any actor), decode the input/output as bytes. To do this, you'll need to look at the codec in the trace:
    1. If the codec is 0, treat it as empty bytes.
    2. If the codec is multicodec.DagCbor or multicodec.Cbor, decode it as a cbor byte array.
    3. If the codec is multicodec.Raw, treat it as raw bytes.
    4. Otherwise.... error. We don't support anything else right now.
  2. If it's a call to CreateExternal on the EAM, decode the input (params) as described above in (InvokeEVM) and treat it as a contract creation (CREATE, not CREATE2). However, you'll need to decode the return value specially:
    1. If the call is successful (exit code 0), the return value is the address of the created actor, plus some other stuff. I think we can just ignore that return value, but I'm not sure what other EVM implementations use. They may treat the new actor's EVM address as the return value?
    2. If it's a failure , the return value is bytes (decoded as in InvokeEVM). This return value is an error message and, again, we'll need to look at other Ethereum clients to figure out how to handle it.
  3. Otherwise, handle calls as described in Add new tracing API #11100 (comment) (it looks like you're already doing this, but I'll do an in-depth review pass on that now).

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Modulo one comment, this looks mergable (as long as we make it clear that it's still experimental and has some missing features).

node/impl/full/eth_trace.go Outdated Show resolved Hide resolved
@Stebalien
Copy link
Member

@fridrik01 could you file issues for the remaining parts:

  1. Support failures while creating contracts.
  2. Support sub-calls from "native" contract constructors.
  3. Support tracing messages that create native actors (e.g., f1 accounts) when they're reverted at the top level. This case will require adding IDs to traces.

@fridrik01
Copy link
Contributor Author

Updated the CHANGELOG and added this as a highly experimental feature

@BlocksOnAChain
Copy link
Contributor

@fridrik01 can we merge this one now, since we created follow-up tasks from our TO-DOs?

Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

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

Okay this LGTM

@arajasek arajasek merged commit d71d647 into master Aug 30, 2023
@arajasek arajasek deleted the traceapi branch August 30, 2023 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants