status-go icon indicating copy to clipboard operation
status-go copied to clipboard

feat_: implement cached eth client

Open dlipicar opened this issue 1 year ago • 4 comments

Implement local caching for ethclient calls, for the following calls:

  • eth_getBlockByNumber
  • eth_getBlockByHash
  • eth_getUncleByBlockHashAndIndex
  • eth_getTransactionByHash
  • eth_getTransactionReceipt
  • eth_getBalance
  • eth_getTransactionCount

This ensures the activity fetching procedure (or any status-go procedure) will fetch blocks, transactions and transaction receipts no more than once. Users of ethclient can now "carelessly" make calls without considerations for recurrent calls. Moreover, we can now much more easily re-process past blocks when looking for new activity details without an RPC call cost.

Some considerations:

  • We're caching the raw json returned by the node. This prevents potential screw ups due to wrong unmarshaling, differences between chains, etc. This required bringing some go-ethereum/ethclient code up to status-go.
  • We're only caching after a successful unmashaling was performed and all consistency checks pass. That is, only if the ethclient we had before these changes would've succeeded.

There's some unit test and functional test coverage for these changes.

Commits:

  • Actual changes + unit tests
  • Adapting other unit tests to the changes
  • Functional tests

Future improvements:

  • Blocks with details can produce cache for Blocks without details (just take the txHash of each transaction object)
  • Blocks with details might be able to produce cache for each Transaction entry

dlipicar avatar Oct 03 '24 05:10 dlipicar

Jenkins Builds

Click to see older builds (112)
:grey_question: Commit :hash: Finished (UTC) Duration Platform Result
:heavy_multiplication_x: eddc603e #1 2024-10-03 05:29:28 ~2 min tests :page_facing_up:log
:heavy_multiplication_x: eddc603e #1 2024-10-03 05:29:53 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: eddc603e #1 2024-10-03 05:31:19 ~4 min ios :package:zip
:heavy_check_mark: eddc603e #1 2024-10-03 05:31:36 ~5 min android :package:aar
:heavy_check_mark: eddc603e #1 2024-10-03 05:31:40 ~4 min linux :package:zip
:heavy_multiplication_x: 95626d41 #2 2024-10-03 20:36:02 ~3 min tests :page_facing_up:log
:heavy_check_mark: 95626d41 #2 2024-10-03 20:36:22 ~3 min ios :package:zip
:heavy_multiplication_x: 95626d41 #2 2024-10-03 20:36:28 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 95626d41 #2 2024-10-03 20:37:09 ~4 min linux :package:zip
:heavy_check_mark: 95626d41 #2 2024-10-03 20:37:52 ~5 min android :package:aar
:heavy_multiplication_x: 1acd4ec2 #3 2024-10-03 20:38:45 ~1 min tests :page_facing_up:log
:heavy_check_mark: 1acd4ec2 #3 2024-10-03 20:39:46 ~2 min linux :package:zip
:heavy_check_mark: 1acd4ec2 #3 2024-10-03 20:39:47 ~1 min android :package:aar
:heavy_check_mark: 1acd4ec2 #3 2024-10-03 20:40:17 ~3 min ios :package:zip
:heavy_multiplication_x: 1acd4ec2 #3 2024-10-03 20:40:33 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 29c38bf4 #4 2024-10-04 11:40:25 ~2 min android :package:aar
:heavy_check_mark: 29c38bf4 #4 2024-10-04 11:40:57 ~2 min linux :package:zip
:heavy_check_mark: 29c38bf4 #4 2024-10-04 11:41:30 ~3 min ios :package:zip
:heavy_multiplication_x: 29c38bf4 #4 2024-10-04 11:41:46 ~3 min tests-rpc :page_facing_up:log
:heavy_multiplication_x: 29c38bf4 #5 2024-10-04 11:50:27 ~1 min tests-rpc :page_facing_up:log
:heavy_check_mark: 29c38bf4 #4 2024-10-04 12:11:23 ~33 min tests :page_facing_up:log
:heavy_multiplication_x: 29c38bf4 #6 2024-10-04 12:57:46 ~1 min tests-rpc :page_facing_up:log
:heavy_check_mark: 29c38bf4 #5 2024-10-04 12:58:22 ~2 min linux :package:zip
:heavy_check_mark: 29c38bf4 #5 2024-10-04 12:58:30 ~2 min android :package:aar
:heavy_check_mark: 29c38bf4 #5 2024-10-04 12:58:35 ~2 min ios :package:zip
:heavy_check_mark: 29c38bf4 #5 2024-10-04 13:27:54 ~32 min tests :page_facing_up:log
:heavy_multiplication_x: 897ac188 #7 2024-10-04 12:59:44 ~1 min tests-rpc :page_facing_up:log
:heavy_check_mark: 897ac188 #6 2024-10-04 13:00:33 ~1 min android :package:aar
:heavy_check_mark: 897ac188 #6 2024-10-04 13:00:56 ~2 min linux :package:zip
:heavy_check_mark: 897ac188 #6 2024-10-04 13:01:59 ~3 min ios :package:zip
:heavy_check_mark: 897ac188 #6 2024-10-04 14:00:58 ~32 min tests :page_facing_up:log
:heavy_multiplication_x: 73a1cf1c #7 2024-10-05 23:40:06 ~1 min tests :page_facing_up:log
:heavy_check_mark: 73a1cf1c #7 2024-10-05 23:40:49 ~2 min android :package:aar
:heavy_check_mark: 73a1cf1c #7 2024-10-05 23:41:00 ~2 min linux :package:zip
:heavy_check_mark: 73a1cf1c #7 2024-10-05 23:41:48 ~3 min ios :package:zip
:heavy_check_mark: 73a1cf1c #8 2024-10-05 23:41:54 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 3b881f71 #9 2024-10-06 00:20:48 ~2 min tests-rpc :page_facing_up:log
:heavy_check_mark: 3b881f71 #8 2024-10-06 00:21:09 ~2 min android :package:aar
:heavy_check_mark: 3b881f71 #8 2024-10-06 00:21:41 ~3 min linux :package:zip
:heavy_check_mark: 3b881f71 #8 2024-10-06 00:22:06 ~3 min ios :package:zip
:heavy_multiplication_x: 3b881f71 #8 2024-10-06 00:50:35 ~31 min tests :page_facing_up:log
:heavy_check_mark: c1ba2150 #9 2024-10-06 03:58:59 ~1 min android :package:aar
:heavy_check_mark: c1ba2150 #9 2024-10-06 03:59:58 ~2 min linux :package:zip
:heavy_check_mark: c1ba2150 #10 2024-10-06 04:01:28 ~3 min tests-rpc :page_facing_up:log
:heavy_multiplication_x: c1ba2150 #9 2024-10-06 04:29:14 ~31 min tests :page_facing_up:log
:heavy_check_mark: fe448bea #10 2024-10-06 04:08:41 ~1 min android :package:aar
:heavy_check_mark: fe448bea #10 2024-10-06 04:09:24 ~2 min linux :package:zip
:heavy_check_mark: fe448bea #11 2024-10-06 04:10:27 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 26909e29 #11 2024-10-06 04:13:29 ~1 min android :package:aar
:heavy_check_mark: 26909e29 #11 2024-10-06 04:14:14 ~2 min linux :package:zip
:heavy_check_mark: 26909e29 #12 2024-10-06 04:15:18 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 26909e29 #10 2024-10-06 05:00:51 ~31 min tests :page_facing_up:log
:heavy_check_mark: 6211418a #12 2024-10-06 13:39:44 ~1 min android :package:aar
:heavy_check_mark: 6211418a #12 2024-10-06 13:40:33 ~2 min linux :package:zip
:heavy_check_mark: 6211418a #14 2024-10-06 13:41:38 ~3 min ios :package:zip
:heavy_check_mark: 6211418a #13 2024-10-06 13:41:48 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 6211418a #11 2024-10-06 14:09:58 ~31 min tests :page_facing_up:log
:heavy_check_mark: 29695156 #13 2024-10-06 13:46:45 ~1 min android :package:aar
:heavy_check_mark: 29695156 #13 2024-10-06 13:47:34 ~2 min linux :package:zip
:heavy_check_mark: 29695156 #14 2024-10-06 13:49:00 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 29695156 #15 2024-10-06 13:50:06 ~5 min ios :package:zip
:heavy_check_mark: 29695156 #12 2024-10-06 14:42:07 ~31 min tests :page_facing_up:log
:heavy_check_mark: 1859aeab #14 2024-10-07 12:39:51 ~2 min android :package:aar
:heavy_check_mark: 1859aeab #14 2024-10-07 12:40:21 ~2 min linux :package:zip
:heavy_check_mark: 1859aeab #15 2024-10-07 12:41:03 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 1859aeab #13 2024-10-07 13:09:46 ~32 min tests :page_facing_up:log
:heavy_multiplication_x: 8c26118a #14 2024-10-07 23:32:08 ~2 min tests :page_facing_up:log
:heavy_check_mark: 8c26118a #15 2024-10-07 23:32:30 ~2 min android :package:aar
:heavy_check_mark: 8c26118a #15 2024-10-07 23:32:46 ~2 min linux :package:zip
:heavy_check_mark: 8c26118a #16 2024-10-07 23:33:31 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 8c26118a #19 2024-10-07 23:33:48 ~3 min ios :package:zip
:heavy_check_mark: 46a59929 #16 2024-10-07 23:39:12 ~1 min android :package:aar
:heavy_multiplication_x: 46a59929 #15 2024-10-07 23:39:27 ~1 min tests :page_facing_up:log
:heavy_check_mark: 46a59929 #16 2024-10-07 23:39:58 ~2 min linux :package:zip
:heavy_check_mark: 46a59929 #20 2024-10-07 23:41:04 ~3 min ios :package:zip
:heavy_check_mark: 46a59929 #17 2024-10-07 23:41:13 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 2fb709e3 #17 2024-10-07 23:51:58 ~1 min android :package:aar
:heavy_check_mark: 2fb709e3 #17 2024-10-07 23:52:49 ~2 min linux :package:zip
:heavy_check_mark: 2fb709e3 #21 2024-10-07 23:53:33 ~3 min ios :package:zip
:heavy_check_mark: 2fb709e3 #18 2024-10-07 23:53:54 ~3 min tests-rpc :page_facing_up:log
:heavy_check_mark: 2fb709e3 #16 2024-10-08 00:22:04 ~31 min tests :page_facing_up:log
:heavy_check_mark: da0a8912 #18 2024-10-08 18:07:27 ~2 min android :package:aar
:heavy_check_mark: da0a8912 #18 2024-10-08 18:07:41 ~2 min linux :package:zip
:heavy_check_mark: da0a8912 #22 2024-10-08 18:08:21 ~3 min ios :package:zip
:heavy_check_mark: da0a8912 #19 2024-10-08 18:10:09 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: da0a8912 #17 2024-10-08 18:37:11 ~32 min tests :page_facing_up:log
:heavy_check_mark: 3a715bc2 #19 2024-10-09 11:43:13 ~2 min android :package:aar
:heavy_check_mark: 3a715bc2 #19 2024-10-09 11:43:33 ~2 min linux :package:zip
:heavy_check_mark: 3a715bc2 #23 2024-10-09 11:44:30 ~3 min ios :package:zip
:heavy_check_mark: 3a715bc2 #20 2024-10-09 11:46:05 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: 3a715bc2 #18 2024-10-09 12:12:46 ~32 min tests :page_facing_up:log
:heavy_check_mark: 3c3e6baa #20 2024-10-09 21:41:23 ~2 min android :package:aar
:heavy_check_mark: 3c3e6baa #20 2024-10-09 21:41:50 ~2 min linux :package:zip
:heavy_check_mark: 3c3e6baa #24 2024-10-09 21:42:27 ~3 min ios :package:zip
:heavy_check_mark: 3c3e6baa #21 2024-10-09 21:44:18 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: 3c3e6baa #19 2024-10-09 22:11:13 ~32 min tests :page_facing_up:log
:heavy_check_mark: 9742b0f8 #21 2024-10-11 18:53:51 ~2 min android :package:aar
:heavy_check_mark: 9742b0f8 #21 2024-10-11 18:53:59 ~3 min linux :package:zip
:heavy_check_mark: 9742b0f8 #25 2024-10-11 18:54:54 ~3 min ios :package:zip
:heavy_check_mark: 9742b0f8 #22 2024-10-11 18:56:30 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: 9742b0f8 #20 2024-10-11 19:23:37 ~32 min tests :page_facing_up:log
:heavy_check_mark: be281613 #26 2024-10-21 22:53:05 ~4 min ios :package:zip
:heavy_check_mark: be281613 #22 2024-10-21 22:53:32 ~4 min linux :package:zip
:heavy_check_mark: be281613 #22 2024-10-21 22:53:53 ~5 min android :package:aar
:heavy_multiplication_x: be281613 #23 2024-10-21 22:54:31 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: be281613 #21 2024-10-21 23:22:49 ~34 min tests :page_facing_up:log
:x: cd9c03a7 #23 2024-10-21 23:07:37 ~10 sec linux :page_facing_up:log
:heavy_check_mark: cd9c03a7 #27 2024-10-21 23:10:15 ~2 min ios :package:zip
:x: cd9c03a7 #24 2024-10-21 23:12:19 ~10 sec linux :page_facing_up:log
:heavy_check_mark: cd9c03a7 #23 2024-10-21 23:13:09 ~5 min android :package:aar
:heavy_multiplication_x: cd9c03a7 #24 2024-10-21 23:13:26 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: cd9c03a7 #22 2024-10-21 23:55:08 ~32 min tests :page_facing_up:log
:grey_question: Commit :hash: Finished (UTC) Duration Platform Result
:heavy_check_mark: 1ff81a2f #24 2024-10-23 16:10:54 ~2 min android :package:aar
:heavy_check_mark: 1ff81a2f #25 2024-10-23 16:11:29 ~3 min linux :package:zip
:heavy_check_mark: 1ff81a2f #28 2024-10-23 16:12:02 ~3 min ios :package:zip
:heavy_check_mark: 1ff81a2f #25 2024-10-23 16:14:26 ~6 min tests-rpc :page_facing_up:log
:heavy_check_mark: 1ff81a2f #23 2024-10-23 16:41:28 ~33 min tests :page_facing_up:log
:heavy_check_mark: cf2c53c8 #26 2024-10-29 01:33:35 ~5 min linux :package:zip
:heavy_check_mark: cf2c53c8 #25 2024-10-29 01:33:48 ~5 min android :package:aar
:heavy_check_mark: cf2c53c8 #1 2024-10-29 01:33:51 ~5 min macos :package:zip
:heavy_check_mark: cf2c53c8 #1 2024-10-29 01:33:51 ~5 min macos :package:zip
:heavy_check_mark: cf2c53c8 #26 2024-10-29 01:34:16 ~5 min tests-rpc :page_facing_up:log
:heavy_check_mark: cf2c53c8 #29 2024-10-29 01:35:50 ~7 min ios :package:zip
:heavy_multiplication_x: cf2c53c8 #1 2024-10-29 01:38:57 ~10 min windows :package:zip
:heavy_check_mark: cf2c53c8 #24 2024-10-29 02:01:52 ~33 min tests :page_facing_up:log
:heavy_multiplication_x: cf2c53c8 #2 2024-10-29 02:01:57 ~10 min windows :package:zip

status-im-auto avatar Oct 03 '24 05:10 status-im-auto

Codecov Report

:x: Patch coverage is 66.06852% with 208 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 47.76%. Comparing base (153c5db) to head (cf2c53c). :warning: Report is 622 commits behind head on develop.

Files with missing lines Patch % Lines
rpc/chain/ethclient/cached_eth_client.go 55.50% 54 Missing and 35 partials :warning:
rpc/chain/ethclient/db.go 71.53% 42 Missing and 36 partials :warning:
rpc/chain/ethclient/types.go 68.42% 9 Missing and 9 partials :warning:
services/eth/private_api.go 0.00% 12 Missing :warning:
rpc/chain/ethclient/signer.go 26.66% 10 Missing and 1 partial :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5907      +/-   ##
===========================================
+ Coverage    47.10%   47.76%   +0.65%     
===========================================
  Files          848      854       +6     
  Lines       139564   140249     +685     
===========================================
+ Hits         65744    66988    +1244     
+ Misses       66107    65385     -722     
- Partials      7713     7876     +163     
Flag Coverage Δ
functional 10.35% <32.46%> (?)
unit 47.22% <67.05%> (+0.11%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
appdatabase/database.go 71.07% <100.00%> (+0.52%) :arrow_up:
node/get_status_node.go 52.83% <100.00%> (+1.33%) :arrow_up:
rpc/chain/ethclient/db_chain.go 100.00% <100.00%> (ø)
rpc/client.go 66.66% <100.00%> (+2.31%) :arrow_up:
t/helpers/db.go 68.62% <100.00%> (+6.72%) :arrow_up:
rpc/chain/ethclient/signer.go 26.66% <26.66%> (ø)
services/eth/private_api.go 23.45% <0.00%> (ø)
rpc/chain/ethclient/types.go 68.42% <68.42%> (ø)
rpc/chain/ethclient/db.go 71.53% <71.53%> (ø)
rpc/chain/ethclient/cached_eth_client.go 55.50% <55.50%> (ø)

... and 75 files with indirect coverage changes

codecov-commenter avatar Oct 03 '24 05:10 codecov-commenter

:heavy_check_mark: status-go/prs/tests/PR-5907#10 :small_blue_diamond: ~31 min :small_blue_diamond: 26909e29 :small_blue_diamond: :package: tests package

status-im-auto avatar Oct 06 '24 05:10 status-im-auto

:heavy_check_mark: status-go/prs/tests/PR-5907#13 :small_blue_diamond: ~32 min :small_blue_diamond: 1859aeab :small_blue_diamond: :package: tests package

status-im-auto avatar Oct 07 '24 13:10 status-im-auto