aragon.js icon indicating copy to clipboard operation
aragon.js copied to clipboard

API: optimize past log fetching

Open sohkai opened this issue 6 years ago • 1 comments

We currently request most past contract logs through 'allEvents', as this is the simplest way to make sure we get all relevant logs for a contract in a single JSON-RPC call.

However, this avoids two potential sources of optimizations around Ethereum's bloom filters:

  1. Topic filters by event signature
  2. Topic filters by indexed parameters

(See how events topics are created in web3.js 1.x).

It would most likely improve past log performance if we allowed developers to declare what event signatures they actually cared about and send JSON-RPC requests to only fetch those events. Web3.js doesn't have a great API for specifying multiple event signatures, outside of 'allEvents', so we'd need to create our own topic signatures and provide them to the API based on the available events in the contract ABI.

This is really only a problem with past logs, where we may be looking through millions of blocks. For new subscriptions, we should be able to keep using 'allEvents'.

sohkai avatar Aug 27 '19 10:08 sohkai

Would it make sense to generate all the topics for event signatures/indexed parameters automatically based on the contract ABI, and then store that into an object that gets accessed inside the API call depending on the event names supplied?

Foo(uint indexed age, uint indexed height):

{
  "Foo(uint, uint)": [
    "0x15e8835e008c...",
    "0x36383cc9cfb...",
    "0x048dd4d5794..."
   ],
}

A benefit of this approach is that we could expose this mapping to the user as well outside the API. Could we also just specify the starting block for search to be the one where the contract is deployed?

corydickson avatar Oct 14 '19 21:10 corydickson