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

change(rpc): Update getaddressbalance RPC to return received field #9295

Draft
wants to merge 6 commits into
base: db-format-upgrade-trait
Choose a base branch
from

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Feb 24, 2025

Motivation

Updates the getaddressbalance RPC to accept either a single address string or a list of them to match zcashd, and adds the received field on the method's response.

This PR is still a draft as it will need an acceptance test.

Depends-On: #9263

Will close #8452.

Solution

  • Bumps db format version for address balances to include a received field, and adds an in-place format upgrade,
  • Parses single address strings passed to RPC methods accepting AddressStrings as a Vec with one item, and
  • Adds the received field to the getaddressbalance RPC output.

Tests

This PR still needs an acceptance test for the db format upgrade.
The changes to the RPC should be covered by existing snapshot tests.

PR Checklist

  • The PR name is suitable for the release notes.
  • The solution is tested.
  • The documentation is up to date.
  • The PR has a priority label.
  • If the PR shouldn't be in the release notes, it has the
    C-exclude-from-changelog label.

@arya2 arya2 added S-blocked Status: Blocked on other tasks A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes P-Medium ⚡ labels Feb 24, 2025
@arya2 arya2 self-assigned this Feb 24, 2025
Copy link
Contributor

mergify bot commented Feb 24, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🔴 ⛓️ Depends-On Requirements

This rule is failing.

Requirement based on the presence of Depends-On in the body of the pull request


let mut address_balance_location = AddressBalanceLocation::new(address_location);
*address_balance_location.balance_mut() = balance;
*address_balance_location.received_mut() = received;

address_balance_location
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't fully reviewed this yet, but one thing I'm not sure about: don't we need to jump through hoops to make sure everything works during a database upgrade? Won't this code break trying to read values in the old format, or am I missing something?

Copy link
Contributor Author

@arya2 arya2 Feb 24, 2025

Choose a reason for hiding this comment

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

Won't this code break trying to read values in the old format, or am I missing something?

The FromDisk impl for AddressBalanceLocation uses received_bytes.try_into().unwrap_or_default() to read the received bytes or default to 0 if it's in the old format.

(Unfortunately I don't think there's a good way to make the old code work with the new data format)

@mpguerra mpguerra linked an issue Feb 25, 2025 that may be closed by this pull request
@arya2 arya2 force-pushed the db-format-upgrade-trait branch from 55b3602 to deff106 Compare February 25, 2025 19:25
@arya2 arya2 force-pushed the update-getaddressbalance branch from 944f8be to 65fcd68 Compare February 25, 2025 19:29
- Adds received balances to non-finalized state, and
- Applies the partial chain received balance change to the finalized received balance when reading address balances.
Comment on lines +41 to +45
// Return early if there are no blocks in the state and the database is empty.
// Note: The caller should (and as of this writing, does) return early if the database is empty anyway.
if initial_tip_height.is_min() {
return Ok(());
}
Copy link
Contributor Author

@arya2 arya2 Feb 26, 2025

Choose a reason for hiding this comment

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

This condition is checking if the state contains only the genesis block, not if it's entirely empty.

Suggested change
// Return early if there are no blocks in the state and the database is empty.
// Note: The caller should (and as of this writing, does) return early if the database is empty anyway.
if initial_tip_height.is_min() {
return Ok(());
}

@mpguerra mpguerra removed this from the Zebra Ready for zcashd Deprecation milestone Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes P-Medium ⚡ S-blocked Status: Blocked on other tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update getaddressbalance RPC method for block explorer usage
3 participants