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

Fix get_all_balances returning zero objects count in fullnode #4828

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tomxey
Copy link
Contributor

@tomxey tomxey commented Jan 16, 2025

Description of change

Implement filtering of balances returned by get_all_balances to omit coins with zero objects count.

The most probable root cause of the issue was described here: #4349 (comment)

Links to any relevant issues

#4349

Type of change

  • Bug fix (a non-breaking change which fixes an issue)

How the change has been tested

cargo test --package=iota-indexer --profile=simulator --features shared_test_runtime
cargo nextest run --package=iota-json-rpc-tests

Change checklist

Tick the boxes that are relevant to your changes, and delete any items that are not.

  • I have followed the contribution guidelines for this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that new and existing unit tests pass locally with my changes

@tomxey tomxey self-assigned this Jan 16, 2025
Copy link

vercel bot commented Jan 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
apps-backend ❌ Failed (Inspect) Jan 16, 2025 1:57pm
apps-ui-kit ❌ Failed (Inspect) Jan 16, 2025 1:57pm
rebased-explorer ❌ Failed (Inspect) Jan 16, 2025 1:57pm
wallet-dashboard ❌ Failed (Inspect) Jan 16, 2025 1:57pm

@@ -1367,6 +1367,15 @@ impl IndexStore {
})
})
.await
.map(|balances_map| {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this part to 100%, but wouldn't that mean we never cache entries with 0 balance, and therefore with every lookup we have expensive DB lookups now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The filtering is done at the very end, so it's not affecting the process of reading from and filling the cache.

We are storing the 0 balance entries in cache just like before.

@tomxey tomxey requested a review from muXxer January 17, 2025 10:00
Copy link
Contributor

@kodemartin kodemartin left a comment

Choose a reason for hiding this comment

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

lgtm 🎈

Comment on lines +1370 to +1377
.map(|balances_map| {
Arc::new(
(*balances_map)
.clone()
.into_iter()
.filter(|(_, TotalBalance { num_coins, .. })| *num_coins > 0)
.collect::<HashMap<_, _>>(),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It would save the reallocation, and reconstruction of the map

Suggested change
.map(|balances_map| {
Arc::new(
(*balances_map)
.clone()
.into_iter()
.filter(|(_, TotalBalance { num_coins, .. })| *num_coins > 0)
.collect::<HashMap<_, _>>(),
)
.map(|mut balances_map| {
Arc::make_mut(&mut balances_map)
.retain(|_, TotalBalance { num_coins, .. }| *num_coins > 0);
balances_map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
infrastructure Issues related to the Infrastructure Team sc-platform Issues related to the Smart Contract Platform group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants