oasisprotocol/oasis-web3-gateway

Only one log returned when querying for multiple topics

andydexscreener opened this issue · 3 comments

When querying logs by multiple topics, results will only return one log, regardless if multiple logs were matched by the query.

I believe this issue will prevent many dapps and indexers from working correctly (or at all) since it doesn't conform to the EVM RPC specs.

Here's a simple script that highlights the issue:

import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider('https://emerald.oasis.dev');

const topic1 = '0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822';
const topic2 = '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1';

(async () => {
  // will match the following transaction:
  // https://explorer.emerald.oasis.dev/tx/0xb24fbcfeb210870aeea7fb0f246635ed81445b66723bad521660eff3cf230cb7/logs

  await provider.getLogs({
    fromBlock: 13662,
    toBlock: 13662,
    topics: [[topic1]],
  })
    .then((logs) => {
      // ✅ RESULT: returns 1 log, logIndex=4
      console.log(logs);
    });

  await provider.getLogs({
    fromBlock: 13662,
    toBlock: 13662,
    topics: [[topic2]],
  })
    .then((logs) => {
      // ✅ RESULT: returns 1 log, logIndex=3
      console.log(logs);
    });

  await provider.getLogs({
    fromBlock: 13662,
    toBlock: 13662,
    topics: [[topic1, topic2]],
  })
    .then((logs) => {
      // ❌ RESULT: returns 1 log, logIndex=3
      // SHOULD RETURN: 2 logs, logIndex=3 + logIndex=4
      console.log(logs);
    });
})();

The code above has been tested on multiple RPC endpoints for other EVM-compatible chains and I can confirm that only Emerald returns inconsistent results.

Although it should be pretty self-explanatory, I'm happy to provider more info if needed.

ptrus commented

Thanks for the report, the specific bug was that at most one log was always returned for getLogs queries without an Address filter. Fix is ready in #143 will comment here once it's also deployed.

ptrus commented

Should be updated now:

curl -X POST --data '{"id": 1, "jsonrpc":"2.0","method": "eth_getLogs","params": [{"topics":[["0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822","0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"]], "fromBlock": "0x355e", "toBlock": "0x355f"}]}' https://emerald.oasis.dev -H "Content-Type: application/json"  | jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "address": "0x34b83026a0b0b81a060bf858ad707276702fbe31",
      "topics": [
        "0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1"
      ],
      "data": "0x000000000000000000000000000000000000000000002d58e28404ebad3ed459000000000000000000000000000000000000000000000a14b23122a69e17f705",
      "blockNumber": "0x355e",
      "transactionHash": "0xb24fbcfeb210870aeea7fb0f246635ed81445b66723bad521660eff3cf230cb7",
      "transactionIndex": "0x1",
      "blockHash": "0x2ad9c7b22cfa2aa8016bde5a7ce4990c237bdc5d6119aca3f5c3b78fd3721ef3",
      "logIndex": "0x3",
      "removed": false
    },
    {
      "address": "0x34b83026a0b0b81a060bf858ad707276702fbe31",
      "topics": [
        "0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822",
        "0x0000000000000000000000007f80093d0759e485239d3010a47b805b6507daae",
        "0x0000000000000000000000009954897ef12fdb2914db1fbc53153c83542f259c"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002086ac351052600000000000000000000000000000000000000000000000000093cf98d3bc4939d4570000000000000000000000000000000000000000000000000000000000000000",
      "blockNumber": "0x355e",
      "transactionHash": "0xb24fbcfeb210870aeea7fb0f246635ed81445b66723bad521660eff3cf230cb7",
      "transactionIndex": "0x1",
      "blockHash": "0x2ad9c7b22cfa2aa8016bde5a7ce4990c237bdc5d6119aca3f5c3b78fd3721ef3",
      "logIndex": "0x4",
      "removed": false
    }
  ]
}

@ptrus Works perfectly. Thank you! 👏