Skip to content

Conversation

@dlipicar
Copy link
Contributor

@dlipicar dlipicar commented Oct 8, 2025

This PR introduces the following changes, in separate commits:

  1. Improved multistandardbalance
  • The result storage is now always reported as a balance change, for other modules to react to
  • It's now able to trigger non-full fetches (some networks, some accounts, some result types) inbetween the full periodical fetches.
  • Full/Non-full fetches can be triggered externally
  • The controller now triggers a non-full fetch for the relevant chains/accounts on pending transaction completion.
  1. Introduce tokenbalances package
  • It's intended to replace the whole reader in a future PR
  • For now it serves as an adapter layer for asset (native/erc20) balance operations, to handle interaction with multistandardbalance
  1. Replace duplicate balance-fetching capabilities from reader and token.Manager with tokenbalances
  • token.Manager is now only in charge of the token lists
  • reader consumes the balances from tokenbalances, since it no longer has a need to trigger fetches.
  1. Allow overriding the multicall contract address through config params for functional-tests usage. Deploy multicall3 in Anvil for functional tests.

  2. unit test fixes

A follow-up PR will bring the full removal of reader and changes to the API. This PR was intended to keep the app functional with no API (methods/events) changes.

@status-im-auto
Copy link
Member

status-im-auto commented Oct 8, 2025

Jenkins Builds

Click to see older builds (66)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ f78e7ad #1 2025-10-08 21:05:07 ~3 min macos/status-go 📦zip
✔️ f78e7ad #1 2025-10-08 21:05:42 ~3 min linux/status-go 📦zip
✖️ f78e7ad #1 2025-10-08 21:09:10 ~7 min tests 📄log
✔️ f78e7ad #1 2025-10-08 21:10:12 ~8 min windows/status-go 📦zip
✔️ f78e7ad #1 2025-10-08 21:13:16 ~11 min linux/nwaku 📦zip
✖️ f78e7ad #1 2025-10-08 21:14:07 ~12 min tests-rpc 📄log
✔️ b70f238 #2 2025-10-09 12:22:01 ~3 min macos/status-go 📦zip
✔️ b70f238 #2 2025-10-09 12:22:38 ~4 min linux/status-go 📦zip
✖️ b70f238 #2 2025-10-09 12:24:11 ~5 min tests 📄log
✔️ b70f238 #2 2025-10-09 12:26:13 ~7 min windows/status-go 📦zip
✔️ b70f238 #2 2025-10-09 12:29:45 ~11 min linux/nwaku 📦zip
✖️ b70f238 #2 2025-10-09 12:30:46 ~12 min tests-rpc 📄log
✔️ ee2ad09 #3 2025-10-09 16:16:23 ~3 min linux/status-go 📦zip
✔️ ee2ad09 #3 2025-10-09 16:16:26 ~3 min macos/status-go 📦zip
✔️ ee2ad09 #3 2025-10-09 16:21:13 ~8 min windows/status-go 📦zip
✖️ ee2ad09 #3 2025-10-09 16:22:28 ~9 min tests 📄log
✔️ ee2ad09 #3 2025-10-09 16:23:34 ~11 min linux/nwaku 📦zip
✖️ ee2ad09 #3 2025-10-09 16:25:58 ~13 min tests-rpc 📄log
✔️ e5aa814 #4 2025-10-09 16:49:07 ~3 min macos/status-go 📦zip
✔️ e5aa814 #4 2025-10-09 16:50:04 ~4 min linux/status-go 📦zip
✖️ e5aa814 #4 2025-10-09 16:51:15 ~5 min tests 📄log
✔️ e5aa814 #4 2025-10-09 16:53:13 ~7 min windows/status-go 📦zip
✖️ e5aa814 #4 2025-10-09 16:56:36 ~10 min tests-rpc 📄log
✔️ e5aa814 #4 2025-10-09 16:58:43 ~12 min linux/nwaku 📦zip
✔️ e908841 #5 2025-10-09 17:50:07 ~3 min linux/status-go 📦zip
✔️ e908841 #5 2025-10-09 17:51:29 ~5 min macos/status-go 📦zip
✖️ e908841 #5 2025-10-09 17:51:56 ~5 min tests 📄log
✔️ e908841 #5 2025-10-09 17:54:15 ~7 min windows/status-go 📦zip
✔️ e908841 #5 2025-10-09 17:56:55 ~10 min linux/nwaku 📦zip
✖️ e908841 #5 2025-10-09 17:57:11 ~10 min tests-rpc 📄log
✔️ f1b139c #6 2025-10-09 18:19:37 ~3 min macos/status-go 📦zip
✔️ f1b139c #6 2025-10-09 18:20:09 ~3 min linux/status-go 📦zip
✖️ f1b139c #6 2025-10-09 18:21:50 ~5 min tests 📄log
✔️ f1b139c #6 2025-10-09 18:22:43 ~6 min windows/status-go 📦zip
✖️ f1b139c #6 2025-10-09 18:27:07 ~10 min tests-rpc 📄log
✔️ f1b139c #6 2025-10-09 18:27:24 ~11 min linux/nwaku 📦zip
✔️ 3f50b1f #7 2025-10-09 19:35:52 ~3 min macos/status-go 📦zip
✔️ 3f50b1f #7 2025-10-09 19:36:03 ~3 min linux/status-go 📦zip
✖️ 3f50b1f #7 2025-10-09 19:37:47 ~5 min tests 📄log
✔️ 3f50b1f #7 2025-10-09 19:39:43 ~7 min windows/status-go 📦zip
✔️ 3f50b1f #7 2025-10-09 19:42:48 ~10 min linux/nwaku 📦zip
✖️ 3f50b1f #7 2025-10-09 19:42:59 ~10 min tests-rpc 📄log
✔️ 4c80472 #8 2025-10-09 19:53:37 ~3 min macos/status-go 📦zip
✔️ 4c80472 #8 2025-10-09 19:53:55 ~3 min linux/status-go 📦zip
✖️ 4c80472 #8 2025-10-09 19:55:43 ~5 min tests 📄log
✔️ 4c80472 #8 2025-10-09 19:57:16 ~6 min windows/status-go 📦zip
✔️ 4c80472 #8 2025-10-09 20:01:39 ~11 min linux/nwaku 📦zip
✔️ 4c80472 #8 2025-10-09 20:02:26 ~12 min tests-rpc 📄log
✔️ 0e9005c #9 2025-10-09 19:58:12 ~3 min macos/status-go 📦zip
✔️ 0e9005c #9 2025-10-09 19:58:22 ~3 min linux/status-go 📦zip
✖️ 0e9005c #9 2025-10-09 20:01:21 ~5 min tests 📄log
✔️ 0e9005c #9 2025-10-09 20:04:49 ~7 min windows/status-go 📦zip
✔️ 0e9005c #9 2025-10-09 20:12:29 ~10 min linux/nwaku 📦zip
✔️ 0e9005c #9 2025-10-09 20:13:08 ~10 min tests-rpc 📄log
✔️ a08ecc2 #10 2025-10-10 13:54:46 ~3 min linux/status-go 📦zip
✔️ a08ecc2 #10 2025-10-10 13:55:04 ~4 min macos/status-go 📦zip
✔️ a08ecc2 #10 2025-10-10 13:57:43 ~6 min windows/status-go 📦zip
✔️ a08ecc2 #10 2025-10-10 14:02:15 ~11 min linux/nwaku 📦zip
✔️ a08ecc2 #10 2025-10-10 14:02:25 ~11 min tests-rpc 📄log
✔️ a08ecc2 #10 2025-10-10 14:20:40 ~29 min tests 📄log
✔️ 4bea5d1 #11 2025-10-10 13:59:43 ~3 min macos/status-go 📦zip
✔️ 4bea5d1 #11 2025-10-10 14:02:08 ~6 min linux/status-go 📦zip
✔️ 4bea5d1 #11 2025-10-10 14:05:11 ~7 min windows/status-go 📦zip
✔️ 31a7bc6 #12 2025-10-10 14:05:55 ~3 min macos/status-go 📦zip
✔️ 31a7bc6 #12 2025-10-10 14:06:09 ~3 min linux/status-go 📦zip
✔️ 31a7bc6 #11 2025-10-10 14:14:11 ~11 min linux/nwaku 📦zip
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 3f9f480 #13 2025-10-10 14:09:24 ~3 min macos/status-go 📦zip
✔️ 3f9f480 #13 2025-10-10 14:09:49 ~3 min linux/status-go 📦zip
✔️ 3f9f480 #12 2025-10-10 14:12:15 ~7 min windows/status-go 📦zip
✔️ 3f9f480 #12 2025-10-10 14:14:04 ~11 min tests-rpc 📄log
✔️ 3f9f480 #12 2025-10-10 14:25:33 ~11 min linux/nwaku 📦zip
✔️ 3f9f480 #11 2025-10-10 14:48:45 ~27 min tests 📄log
✔️ 19f7f81 #14 2025-10-14 20:09:13 ~3 min macos/status-go 📦zip
✔️ 19f7f81 #14 2025-10-14 20:09:26 ~3 min linux/status-go 📦zip
✔️ 19f7f81 #13 2025-10-14 20:13:23 ~7 min windows/status-go 📦zip
✔️ 19f7f81 #13 2025-10-14 20:17:11 ~11 min linux/nwaku 📦zip
✔️ 19f7f81 #13 2025-10-14 20:17:27 ~11 min tests-rpc 📄log
✔️ 19f7f81 #12 2025-10-14 20:33:03 ~27 min tests 📄log

@dlipicar dlipicar force-pushed the feat/clean-up-balance-fetching-from-token-manager branch 10 times, most recently from 31a7bc6 to 3f9f480 Compare October 10, 2025 14:02
@dlipicar dlipicar marked this pull request as ready for review October 10, 2025 14:25
@dlipicar dlipicar requested a review from a team as a code owner October 10, 2025 14:25
Copy link
Contributor

@fbarbu15 fbarbu15 left a comment

Choose a reason for hiding this comment

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

Test part LGTM
Although for the smart contract I cannot give my approval since I don't have enough experience there

c.stopCh = nil
}

c.stopWalletEventsWatcher()
Copy link
Contributor

Choose a reason for hiding this comment

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

Stop() can be guarded by mutex since it closing and nilling channel, to make this change non-interrupted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh this point keeps coming up, I'll deal with it soon, I promise!
Start and Stop is, at the moment, only expected to be called when the app starts and ends, respectively, we don't expect race conditions to happen.

I feel it would be healthier for our services to be prepared for start and stop calls at any point during the application lifetime, it's just not a requirement at the moment. I'll apply this change to all services when I work on this improvement.


ret := make(map[AccountAddress]map[ContractAddress]*big.Int)

for result := range resultsCh {
Copy link
Contributor

Choose a reason for hiding this comment

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

For loop does not check for context cancellation

Copy link
Contributor Author

@dlipicar dlipicar Oct 14, 2025

Choose a reason for hiding this comment

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

context cancellation causes context.Canceled to be sent for every pending job, after which the channel is closed, at which point this loop exits.


for {
select {
case <-c.stopCh:
Copy link
Contributor

Choose a reason for hiding this comment

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

from fetcher.go

  // jobResultsCh is closed when all results have been sent, causing the
  // loop to exit and the goroutine to end.

So maybe, If stopCh stops the goroutine, we should still read everything from the channel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm yeah, closing stopCh should cancel the ctx we pass to FetchBalances. I guess it's not super critical now since stopCh is only called when the app closes, but it's not proper to leave the Fetcher running in the background when the controller stops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh wait it does!

		go func() {
			defer gocommon.LogOnPanic()
			defer cancel()

			for {
				select {
				case <-c.stopCh:
					return
				case result, ok := <-resultsCh:
					if !ok {
						return
					}
					c.handleFetchResult(ctx, chainID, result)
				}
			}
		}()

closing stopCh ends the goroutine, which causes cancel() to be called.

Copy link
Contributor Author

@dlipicar dlipicar Oct 14, 2025

Choose a reason for hiding this comment

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

I don't think we're interested in any remaining results if we stop the controller, it's not a super critical operation we're dealing with here. If it were, calling Stop() should block until the operation is complete.

}

r.triggerReloadIfRecent(event.NewState.FetchedAt, event.Key.Account, true)
r.refreshBalanceCache(context.TODO(), []uint64{event.Key.ChainID}, []common.Address{event.Key.Account})
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what is the plan with contexts?

For now maybe add a context with 60sec timeout?

Copy link
Contributor Author

@dlipicar dlipicar Oct 14, 2025

Choose a reason for hiding this comment

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

The ctx basically does nothing here, since no balances are getting "fetched", only read from cache. The plan is to remove reader.go completely soon and let tokenbalances provide the API that will get balances from the cache :D

Copy link
Contributor

@friofry friofry left a comment

Choose a reason for hiding this comment

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

Looks good to me! Nice solution!

Added a few comments

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 77.41117% with 89 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.45%. Comparing base (c0f75d6) to head (19f7f81).
⚠️ Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
api/protocol_adaptors.go 6.25% 30 Missing ⚠️
services/wallet/tokenbalances/fetcher.go 68.85% 13 Missing and 6 partials ⚠️
services/wallet/api.go 15.00% 17 Missing ⚠️
services/wallet/reader.go 77.50% 8 Missing and 1 partial ⚠️
services/wallet/multistandardbalance/controller.go 95.59% 5 Missing and 2 partials ⚠️
...llet/tokenbalances/storage_multistandardbalance.go 76.00% 4 Missing and 2 partials ⚠️
node/get_status_node.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6991      +/-   ##
===========================================
+ Coverage    55.11%   59.45%   +4.34%     
===========================================
  Files          820      822       +2     
  Lines       116628   116494     -134     
===========================================
+ Hits         64275    69257    +4982     
+ Misses       45548    40146    -5402     
- Partials      6805     7091     +286     
Flag Coverage Δ
functional 35.26% <71.06%> (?)
unit 54.98% <46.19%> (-0.13%) ⬇️

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

Files with missing lines Coverage Δ
api/defaults.go 74.66% <100.00%> (+9.81%) ⬆️
api/geth_backend.go 52.80% <100.00%> (+3.42%) ⬆️
params/config.go 85.27% <100.00%> (+9.49%) ⬆️
protocol/requests/create_account.go 36.84% <ø> (ø)
...es/wallet/multistandardbalance/controller_fetch.go 71.42% <100.00%> (ø)
services/wallet/multistandardbalance/fetcher.go 78.57% <100.00%> (+54.76%) ⬆️
...ices/wallet/multistandardbalance/storage_memory.go 100.00% <100.00%> (ø)
services/wallet/router/router.go 59.77% <100.00%> (+11.71%) ⬆️
services/wallet/router/router_helper.go 47.90% <100.00%> (+14.40%) ⬆️
services/wallet/service.go 76.92% <100.00%> (+0.55%) ⬆️
... and 8 more

... and 202 files with indirect coverage changes

Copy link
Contributor

@siddarthkay siddarthkay left a comment

Choose a reason for hiding this comment

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

changes in tests-functional/Dockerfile looks okay from devops POV

@dlipicar dlipicar merged commit 0ac383b into develop Oct 15, 2025
21 checks passed
@dlipicar dlipicar deleted the feat/clean-up-balance-fetching-from-token-manager branch October 15, 2025 13:05
AYAHASSAN287 pushed a commit that referenced this pull request Oct 20, 2025
* feat: improvemets to multistandardbalance controller

* feat: introduce tokenbalances package

* chore: replace balance fetching capabilities from reader and token manager with tokenbalances

* feat: allow overriding multicall3 contract address

* chore: fix tests

* chore: pr comments
AYAHASSAN287 pushed a commit that referenced this pull request Oct 20, 2025
* feat: improvemets to multistandardbalance controller

* feat: introduce tokenbalances package

* chore: replace balance fetching capabilities from reader and token manager with tokenbalances

* feat: allow overriding multicall3 contract address

* chore: fix tests

* chore: pr comments
romanzac pushed a commit that referenced this pull request Nov 6, 2025
* feat: improvemets to multistandardbalance controller

* feat: introduce tokenbalances package

* chore: replace balance fetching capabilities from reader and token manager with tokenbalances

* feat: allow overriding multicall3 contract address

* chore: fix tests

* chore: pr comments
romanzac added a commit that referenced this pull request Nov 14, 2025
* test: First draft for settings wrappers and test file added

* test: Making changes in test env & add tests

* test: Add new test

* feat: improve blockchainstate

* feat: replace old transfer detection algorithm with multistandardbalance and transferdetector

* build: add Android x86_64 support to Makefile (#6990)

- Sets MOBILE_GOARCH to amd64 when ARCH is x86_64
- Sets ANDROID_CLANG_TARGET to x86_64-linux-android<API>

* ci: use official base docker image for builds

Referenced issue:
* status-im/infra-ci#188

* test: community chats (#6987)

* test: community chats

* test: community chats review

* test: Adding node tests

* test: contact verification (#6997)

* chore: point go.mod to original go-ethereum repo

* chore: drop usage of non-multichain ethclient methods in rpc chain client

* chore: drop usage of non-multichain ethclient methods in community tokens service

* chore: drop usage of non-multichain ethclient methods in fees manager

* chore: adapt to new geth logger

* chore: remove unused log_parser code

* chore: replace custom NoSign parameter from bind.TransactOpts

* chore: update SingleRequestCodec to go-ethereum upstream

* chore: use `go-waku` with upstream `go-ethereum` (#6978)

* chore: upgrade go-waku and go-discover

* chore: make vendor

* feat: go-waku v0.10.0

* chore: fix tests

* chore: bump go-waku and go-discover (#6983)

* refactor: use common Migrate function

- Use sqlite.Migrate in protocol to remove logic duplication.

- Remove legacy ad-hoc migration fix. It is now safe to assume that no
  users are running versions old enough to require this workaround.

* refactor: move pubkeys utils from protocol to crypto package

These utils are generic enough to be moved to crypto package.

* fix: Crash on uninitialized filterManager

Not sure if this will only hide the root cause because the proper flow on pairing is unknown to me. But from what I've seen Waku is only started after login. While `subscribe` and `unsubscribe` is used in the pairing flow as well.

* test: Add new tests

* test: Adding wrappers &tests

* test: Add positive & negative tests

* test: Added backup tests

* feat: clean up balance fetching from token manager (#6991)

* feat: improvemets to multistandardbalance controller

* feat: introduce tokenbalances package

* chore: replace balance fetching capabilities from reader and token manager with tokenbalances

* feat: allow overriding multicall3 contract address

* chore: fix tests

* chore: pr comments

* fix(scripts): branch_version_generated use current base branch (#7007)

* fix: goimports configuration (#7004)

* fix: goimports only 1 local package

* fix: vscode settings goimports

* fix: un-gitignore IDEA code styles

* feat: goland code styles

* fix: remove generate_handlers nolint comment

* chore: lint-fix all files

* feat: local timesource (#7003)

* feat: local timesource

* fix: nwaku

* fix: rebase issues

* feat(benchmark): threads and goroutines count (#7006)

* feat: added numThreads to expvars

* test: added num of threads and goroutines to benchmarks

* fix: issues

* chore: cleanup chain client and transactor (#7008)

* chore: make rpc.Client implement EthClientGetter

* chore: remove unused types

* chore: cleanup unused methods and use interface instead of rpc Client

* chore: cleanup transactor

* chore: move pendingtxtracker to separate package

* chore: fix tests

* test: add all APIs tests

* test: Apply linters

* fix: reduce test variants to shorten test durations

* fix: lints

* fix: remove print statements for debug-only purpose

* fix: use logger when necessary

* chore: use `go-waku` with upstream `go-ethereum` (#6978)

* chore: upgrade go-waku and go-discover

* chore: make vendor

* feat: go-waku v0.10.0

* chore: bump go-waku and go-discover (#6983)

* feat: clean up balance fetching from token manager (#6991)

* feat: improvemets to multistandardbalance controller

* feat: introduce tokenbalances package

* chore: replace balance fetching capabilities from reader and token manager with tokenbalances

* feat: allow overriding multicall3 contract address

* chore: fix tests

* chore: pr comments

* fix: rebase on develop
- remove unused imports

* fix: wait longer for backend in Jenkins

* test: look for potential problems beyond failing tests

* test: test_check_node_config_params

* test: service context behavior

* test: revert wakuext service name

* fix: test_news_feed_enabled

* fix: test_news_notifications_enabled

* fix: test_toggle_news_notifications_enabled

* fix: test_toggle_news_rss_enabled

* fix: test_set_valid_backup_path

* fix: wait 40s for backend in Jenkins

* fix: remove unused function

* fix: test_last_tokens_update_advances_after_updating_token_preferences

* test: temporary fix for
- test_delete_exemptions_invalid_id

* test: temporary fix for
- test_notifications_set_global_mentions_rejects_wrong_types_and_preserves_value

* test: race condition fix for
- test_update_keycard_uid_success

* test: return to the original timeout value

* fix: remove redundant deepcopy

* fix: remove line without effect in
- test_full_migrate_flow

* fix: change to skip annotation

* fix: improve assertions

* fix: remove ExemptionsDefaults related code

* fix: uncomment
- test_notifications_set_group_chats_invalid_values

* fix: remove Go code for
- NotificationsSetGlobalMentions
- DeleteExemptions

* fix: commented out tests
- test_notifications_set_global_mentions_rejects_wrong_types_and_preserves_value
- test_delete_exemptions_invalid_id

* fix: naming and test clarity

* fix: remove redundant news feed tests

* fix: regroup tests

* fix: re-run stuck codecov tests

---------

Co-authored-by: Dario Gabriel Lipicar <[email protected]>
Co-authored-by: Mag. <[email protected]>
Co-authored-by: markoburcul <[email protected]>
Co-authored-by: fbarbu15 <[email protected]>
Co-authored-by: Patryk Osmaczko <[email protected]>
Co-authored-by: Igor Sirotin <[email protected]>
Co-authored-by: Alex Jbanca <[email protected]>
Co-authored-by: Roman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants