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

feat: rpc: correct eth_subscribe implementation #10027

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented Jan 16, 2023

Related Issues

Depends on filecoin-project/go-jsonrpc#88
Closes #9985
Closes filecoin-project/ref-fvm#1573

Proposed Changes

  • Change eth_subscribe impl to use reverse calls (really reverse notifs)
  • Implement eth_subscribe on gateway

Additional Info

Not tested at all; Would be great to at least test lotus+lotus-gateway setup, and look at what is sent in wireshark to make sure everything looks as it should. Adding an itest would be nice to

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

Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

Generally looks good, just one nit. Needs to be rebased, and linter is mad.

This definitely needs to be tested, ideally by the FVM team to make sure it does exactly what they need.

gateway/eth_sub.go Show resolved Hide resolved
@magik6k magik6k force-pushed the feat/correct-eth-sub branch 2 times, most recently from 0dab83f to 6c996e4 Compare January 26, 2023 13:19
@magik6k
Copy link
Contributor Author

magik6k commented Jan 26, 2023

Traffic in wireshark when running TestEthSubscribeLogs:

{"jsonrpc":"2.0","id":102,"method":"Filecoin.EthSubscribe","params":["logs",null],"meta":{"SpanContext":"AAD/3PUFamHzn4lX3Evo7UYKARoCPUWfo4xSAgA="}}
{"jsonrpc":"2.0","result":[163,236,233,188,93,133,64,147,171,71,130,223,17,202,42,182,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"id":102}

[...]


{
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": [
      163,
      236,
      233,
      188,
      93,
      133,
      64,
      147,
      171,
      71,
      130,
      223,
      17,
      202,
      42,
      182,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ],
    "result": [
      {
        "address": "0x9368ba4dae7ff759e526b38a1c02845a4d2718d4",
        "data": "0x0000000000000000000000000000000000000000000000001122334455667788",
        "topics": [
          "0x0000000000000000000000000000000000000000000000000000000000001111",
          "0x0000000000000000000000000000000000000000000000000000000000002222",
          "0x0000000000000000000000000000000000000000000000000000000000003333",
          "0x0000000000000000000000000000000000000000000000000000000000004444"
        ],
        "removed": false,
        "logIndex": "0x0",
        "transactionIndex": "0x0",
        "transactionHash": "0x499dbc6c61a9b2d4d3264dccd77a89e7e3ebedd2b3b42198732dfb87c0a375d5",
        "blockHash": "0x89b263b06f68bd359987a104cfe971f3ee4fb70015aa8907458a0e1ac9a59633",
        "blockNumber": "0x14"
      }
    ]
  },
  "meta": {
    "SpanContext": "AABTEMy3JW4E5GV73I6sMawSAeGtKt+e7STXAgA="
  }
}

Looks like subscription is serialized wrong

@magik6k
Copy link
Contributor Author

magik6k commented Jan 26, 2023

After fixes:

> {"jsonrpc":"2.0","id":102,"method":"Filecoin.EthSubscribe","params":["logs",null],"meta":{"SpanContext":"AABGzUNOJLBw6Y09XpOghlbJAbiLhXGnf1MVAgA="}}

< {"jsonrpc":"2.0","result":"0x9c77aa24a49a4782b4bb7cf5214d6a1600000000000000000000000000000000","id":102}

< {
  "jsonrpc": "2.0",
  "method": "eth_subscription",
  "params": {
    "subscription": "0x9c77aa24a49a4782b4bb7cf5214d6a1600000000000000000000000000000000",
    "result": [
      {
        "address": "0x410531eece3fbea8cb2431296079e88d3d8d9046",
        "data": "0x0000000000000000000000000000000000000000000000001122334455667788",
        "topics": [
          "0x0000000000000000000000000000000000000000000000000000000000001111",
          "0x0000000000000000000000000000000000000000000000000000000000002222",
          "0x0000000000000000000000000000000000000000000000000000000000003333",
          "0x0000000000000000000000000000000000000000000000000000000000004444"
        ],
        "removed": false,
        "logIndex": "0x0",
        "transactionIndex": "0x0",
        "transactionHash": "0x990710e978fdd35c2f741c3b386afb36df63c20af4af6609cd02a7dbf129e1cf",
        "blockHash": "0xc6e3f3f6ebf4540adf7c3dd83e795049b86fab1e53a0a79b72a5a44e422452a9",
        "blockNumber": "0x14"
      }
    ]
  },
  "meta": {
    "SpanContext": "AAASn23DHS9YWgrzxeiuxjv/ARcw/kvgBtX5AgA="
  }
}

I don't know enough about eth filters, so someone more familiar should have a look, but to me this looks about right.

@magik6k magik6k marked this pull request as ready for review January 26, 2023 15:03
@iand
Copy link
Contributor

iand commented Jan 26, 2023

The output looks good to me. It needs testing against a client library.

var h EthSubscriptionID
err := h.UnmarshalJSON([]byte(hash))

require.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we use require.Nil here instead of require.NoErrror? Looks like we've done this a bunch in the new eth stuff.

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.

Add proper eth subscribe support
4 participants