In the context of tribute to talk we are relying on token transactions from the wallet but unfortunately it doesn’t work very well at the moment.
How does it work:
- when the user logs in a polling loop starts with a 15 second cycle.
- every iteration the etherscan api is hit for the list of transactions
- every iteration an event chain gets the current block, then queries eth logs for incoming and then outgoing token transactions, then groups transactions per block and then requests block info for every block containing token transactions.
- every iteration all found transactions and token transactions are merged into app db
- refreshing transactions list shortcuts the loop
What is bad about it:
- the condition for querying etherscan and ethlog is odd and rarely true, which is why token transactions don’t always appear in the wallet
- there is a 100000 last blocks limit on token transactions, which is why older token transactions never appear in the wallet
- every time the user logins everything needs to be refetched, there is no persistence
- it is expensive in CPU and network resources
- it relies on 3rd party services
What we should do to improve:
- get rid of the loop entirely as the polling us made unecessary by some existing rpc methods
- persist transactions to avoid requesting everything everytime users logs in
- remember oldest checked block and query whole history iteratively over time
- remember latest checked block to only query from there
- use ethlog filters instead of ethlog and receive new transactions as signals instead of polling
- rely on a signal for new current block to update number of confirmations dynamically in subscriptions
What we need from status-go to be able to do that:
use infura websockets API https://infura.io/docs/ethereum/wss/introduction
on status-react this could transparently use private-rpc-call as it is already the case for other rpc-calls, the callback being called everytime there is some updates from the ws
What will it bring?
- less third party services (no more need for etherscan, and infura not needed in full node mode)
- less bandwidth consumption
- more reactivity for pending/incoming transactions
- more reliability for transactions list
- better performances as some of the work done in this loop is expensive
- code much easier to reason about
- one week 2 go devs (implementation and review)
- one week 2 clojure devs (implementation and review)
- two days QA