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

Allow executing smart contract functions in arbitrarily sized batches #1560

Merged
merged 2 commits into from
Mar 13, 2019

Conversation

goodsoft
Copy link
Contributor

Motivation

There are a lot of getBalanceOf token function calls during indexing blockchain. Each of them is sent as a separate JSONRPC request, which creates a lot of unnecessary overhead and clogs archive node workers, which could otherwise be busy performing other JSONRPC queries.

Moreover, function name is used as the id parameter of JSONRPC queries, which doesn't allow us to simply put multiple requests into one batch.

Changelog

  • Change EthereumJSONRPC.execute_contract_functions to accept a list of arbitrary function calls and return a list of results.
  • Handle id field generation in the EthereumJSONRPC package instead of leaking implementation details to Explorer.SmartContract.Reader.
  • Change Token.BalanceReader.get_balance_of to accept a list of parameter sets and return a list of balances.
  • Make one batch request instead of launching multiple concurrent tasks in Indexer.TokenBalances.fetch_token_balances_from_blockchain

Notes

  • Protocol details of calling smart contract functions is now fully encapsulated in EthereumJSONRPC package.
  • SmartContract.Reader.query_contract is left for backwards compatibility with other existing applications of smart contract requests, but can be fully deprecated at some later time.

@ghost ghost assigned goodsoft Mar 13, 2019
@ghost ghost added the in progress label Mar 13, 2019
@goodsoft goodsoft force-pushed the gs-batch-token-balance-requests branch from 8d7312f to d6f81ad Compare March 13, 2019 13:38
@goodsoft goodsoft added ready for review This PR is ready for reviews. and removed in progress labels Mar 13, 2019
@coveralls
Copy link

coveralls commented Mar 13, 2019

Pull Request Test Coverage Report for Build 6ed15908-5ac3-4a1b-942c-2bc9ba88278a

  • 32 of 34 (94.12%) changed or added relevant lines in 6 files are covered.
  • 8 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+1.3%) to 84.285%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex 19 21 90.48%
Files with Coverage Reduction New Missed Lines %
apps/indexer/lib/indexer/block/catchup/fetcher.ex 1 66.67%
apps/indexer/lib/indexer/token/fetcher.ex 1 78.57%
apps/indexer/lib/indexer/internal_transaction/fetcher.ex 2 88.89%
apps/indexer/lib/indexer/token_balance/fetcher.ex 2 87.1%
apps/indexer/lib/indexer/block/fetcher.ex 2 91.67%
Totals Coverage Status
Change from base Build a793f1e3-4805-4ca3-8fb6-904597ec40de: 1.3%
Covered Lines: 4280
Relevant Lines: 5078

💛 - Coveralls

Copy link
Contributor

@ayrat555 ayrat555 left a comment

Choose a reason for hiding this comment

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

I think there are some other not batched methods. We should check it. Great work!

@ghost ghost assigned vbaranov Mar 13, 2019
@ghost ghost added the in progress label Mar 13, 2019
# Problem

There are a lot of `getBalanceOf` token function calls during indexing
blockchain. Each of them is sent as a separate JSONRPC request, which
creates a lot of unnecessary overhead and clogs archive node workers, which
could otherwise be busy performing other JSONRPC queries.

Moreover, function name is used as the `id` parameter of JSONRPC queries,
which doesn't allow us to simply put multiple requests into one batch.

# Solution

* Change `EthereumJSONRPC.execute_contract_functions` to accept a list of
arbitrary function calls and return a list of results.
* Handle `id` field generation in the `EthereumJSONRPC` package instead of
leaking implementation details to `Explorer.SmartContract.Reader`.
* Change `Token.BalanceReader.get_balance_of` to accept a list of parameter
sets and return a list of balances.
* Make one batch request instead of launching multiple concurrent tasks in
`Indexer.TokenBalances.fetch_token_balances_from_blockchain`

# Notes

* Protocol details of calling smart contract functions is now fully
encapsulated in `EthereumJSONRPC` package.
* `SmartContract.Reader.query_contract` is left for backwards compatibility
with other existing applications of smart contract requests, but can be
fully deprecated at some later time.
@goodsoft goodsoft force-pushed the gs-batch-token-balance-requests branch from 2938b8c to 65547b5 Compare March 13, 2019 16:27
@goodsoft goodsoft force-pushed the gs-batch-token-balance-requests branch from 65547b5 to 3060264 Compare March 13, 2019 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants