The Status module that consumes go-ethereum https://status.im
Go to file
Roman Volosovskyi a92a95cf83
status-im/status-react#9203 Faster tx fetching with less request
*** How it worked before this PR on multiaccount creation:
- On multiacc creation we scanned chain for eth and erc20 transfers. For
  each address of a new empty multiaccount this scan required
  1. two `eth_getBalance` requests to find out that there is no any
     balance change between zero and the last block, for eth transfers
  2. and `chain-size/100000` (currently ~100) `eth_getLogs` requests,
     for erc20 transfers
- For some reason we scanned an address of the chat account as well, and
  also accounts were not deduplicated. So even for an empty multiacc we
  scanned chain twice for each chat and main wallet addresses, in result
  app had to execute about 400 requests.
- As mentioned above, `eth_getBalance` requests were used to check if
  there were any eth transfers, and that caused empty history in case
  if user already used all available eth (so that both zero and latest
  blocks show 0 eth for an address). There might have been transactions
  but we wouldn't fetch/show them.
- There was no upper limit for the number of rpc requests during the
  scan, so it could require indefinite number of requests; the scanning
  algorithm was written so that we persisted the whole history of
  transactions or tried to scan form the beginning again in case of
  failure, giving up only after 10 minutes of failures. In result
  addresses with sufficient number of transactions would never be fully
  scanned and during these 10 minutes app could use gigabytes of
  internet data.
- Failures were caused by `eth_getBlockByNumber`/`eth_getBlockByHash`
  requests. These requests return significantly bigger responses than
  `eth_getBalance`/`eth_transactionsCount` and it is likely that
  execution of thousands of them in parallel caused failures for
  accounts with hundreds of transactions. Even for an account with 12k
  we could successfully determine blocks with transaction in a few
  minutes using `eth_getBalance` requests, but `eth_getBlock...`
  couldn't be processed for this acc.
- There was no caching for for `eth_getBalance` requests, and this
  caused in average 3-4 times more such requests than is needed.

*** How it works now on multiaccount creation:
- On multiacc creation we scan chain for last ~30 eth transactions and
  then check erc20 in the range where these eth transactions were found.
  For an empty address in multiacc this means:
  1. two `eth_getBalance` transactions to determine that there was no
     balance change between zero and the last block; two
     `eth_transactionsCount` requests to determine there are no outgoing
     transactions for this address; total 4 requests for eth transfers
  2. 20 `eth_getLogs` for erc20 transfers. This number can be lowered,
     but that's not a big deal
- Deduplication of addresses is added and also we don't scan chat
  account, so a new multiacc requires ~25 (we also request latest block
  number and probably execute a few other calls) request to determine
  that multiacc is empty (comparing to ~400 before)
- In case if address contains transactions we:
  1. determine the range which contains 20-25 outgoing eth/erc20
     transactions. This usually requires up to 10 `eth_transactionCount`
     requests
  2. then we scan chain for eth transfers using `eth_getBalance` and
     `eth_transactionCount` (for double checking zero balances)
  3. we make sure that we do not scan db for more than 30 blocks with
     transfers. That's important for accounts with mostly incoming
     transactions, because the range found on the first step might
     contain any number of incoming transfers, but only 20-25 outgoing
     transactions
  4. when we found ~30 blocks in a given range, we update initial
     range `from` block using the oldest found block
  5. and now we scan db for erc20transfers using `eth_getLogs`
     `oldest-found-eth-block`-`latest-block`, we make not more than 20 calls
  6. when all blocks which contain incoming/outgoing transfers for a
     given address are found, we save these blocks to db and mark that
     transfers from these blocks are still to be fetched
  7. Then we select latest ~30 (the number can be adjusted) blocks from
     these which were found and fetch transfers, this requires 3-4
     requests per transfer.
  8. we persist scanned range so that we know were to start next time
  9. we dispatch an event which tells client that transactions are found
  10. client fetches latest 20 transfers
- when user presses "fetch more" button we check if app's db contains next
  20 transfers, if not we scan chain again and return transfers after

small fixes
2020-01-23 10:36:11 +02:00
.dependabot Move to monorepo structure (#1684) 2019-11-21 17:19:22 +01:00
.github Move to monorepo structure (#1684) 2019-11-21 17:19:22 +01:00
.vscode Add go.formatFlags to VS Code settings 2020-01-16 13:18:36 +01:00
_assets use more descriptive names for systemd services 2020-01-08 14:51:26 +01:00
account Working Nimbus branch with geth keystore 2020-01-20 13:15:17 +01:00
api status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
appdatabase status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
build/bin add .gitkeep to build/bin so it always exists 2019-03-05 14:22:00 +01:00
cmd Split shhext into shhext and wakuext (#1803) 2020-01-20 21:56:06 +01:00
config update readme with new PGConfig location 2020-01-08 14:51:26 +01:00
contracts Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
db Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
discovery Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
eth-node Add support for request messages by topics (#1805) 2020-01-21 08:11:24 +01:00
exportlogs Upgrade geth to 1.9.5 and Whisper (#1617) 2019-10-04 17:21:24 +02:00
extkeys Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
lib Use eth-node `keystore` for `generator.go` 2020-01-06 15:45:31 +01:00
logutils Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
mailserver Add support for request messages by topics (#1805) 2020-01-21 08:11:24 +01:00
metrics Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
mobile Nimbus node support 2020-01-20 13:15:17 +01:00
multiaccounts status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
node Split shhext into shhext and wakuext (#1803) 2020-01-20 21:56:06 +01:00
notifier Notifier package to interact with gorush notifications (#910) 2018-05-08 16:30:03 +02:00
params Fix waku tests & contact ens (#1802) 2020-01-17 13:39:09 +01:00
peers Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
profiling Add profiling with pprof (#754) 2018-03-23 14:58:40 +01:00
protocol Fix ens names and contact (#1810) 2020-01-23 09:24:28 +01:00
rpc Nimbus node support 2020-01-20 13:15:17 +01:00
rtt rewrite mailserver systemd setup to a Makefile 2019-12-04 13:44:05 +01:00
services status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
signal Split shhext into shhext and wakuext (#1803) 2020-01-20 21:56:06 +01:00
sqlite Add persistent datasync, use single database and handle negotiated filters (#1580) 2019-08-27 14:04:15 +02:00
static Make shhext and protocol work with Waku (#1777) 2020-01-13 20:17:30 +01:00
t status-im/status-react#9203 Faster tx fetching with less request 2020-01-23 10:36:11 +02:00
timesource Nimbus node support 2020-01-20 13:15:17 +01:00
transactions Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
vendor Fix ens names and contact (#1810) 2020-01-23 09:24:28 +01:00
waku Add support for request messages by topics (#1805) 2020-01-21 08:11:24 +01:00
whisper Split shhext into shhext and wakuext (#1803) 2020-01-20 21:56:06 +01:00
.codeclimate.yml add multi-account support (#1500) 2019-07-24 20:59:15 +02:00
.dockerignore Ignore *.test files from all folders (#635) 2018-02-08 14:23:08 +02:00
.gitignore Create a home submodule for Eth node bridges- Rename StatusBackend to GethStatusBackend 2019-11-27 17:02:09 +01:00
.golangci.yml Use goimports instead of gofmt 2020-01-06 10:17:23 +01:00
.travis.yml migrate to go 1.12 and go modules 2019-06-12 13:12:00 +02:00
BOOTNODE.md allow running systemd service as root 2020-01-02 10:36:13 +01:00
CONTRIBUTING.md Move CONTRIBUTING.md to top level (#798) 2018-04-04 12:51:05 +02:00
LICENSE.md Create LICENSE.md 2016-09-21 10:00:29 +08:00
MAILSERVER.md allow running systemd service as root 2020-01-02 10:36:13 +01:00
Makefile Nimbus node support 2020-01-20 13:15:17 +01:00
README.md Update Travis badge in README to point to develop branch (only) 2019-12-06 10:11:42 +01:00
RELEASING.md update RELEASING docs links to CI (#1506) 2019-06-28 10:37:34 +02:00
VERSION Fix ens names and contact (#1810) 2020-01-23 09:24:28 +01:00
go.mod Nimbus node support 2020-01-20 13:15:17 +01:00
go.sum Nimbus node support 2020-01-20 13:15:17 +01:00