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

Implemented GetAccountProofs endpoint #506

Merged
merged 14 commits into from
Oct 4, 2024
Merged

Conversation

polydez
Copy link
Contributor

@polydez polydez commented Sep 26, 2024

Resolves #485

This PR adds GetAccountProofs endpoint which returns latest state headers for given accounts. For public accounts it also returns account and storage headers.

After discussion we considered to lock whole database and in-memory state for the processing of the whole request.

@polydez polydez marked this pull request as ready for review September 26, 2024 10:38
crates/store/src/state.rs Outdated Show resolved Hide resolved
crates/store/src/state.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth 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! Thank you! I left a few small comments inline.

One thing I'm still not sure of is whether GetAccountStates is the right name for this endpoint since we not actually getting account states from it. Maybe GetAccountProofs or GetAccountHeaders would be better?

crates/rpc/src/server/api.rs Outdated Show resolved Hide resolved
proto/account.proto Outdated Show resolved Hide resolved
proto/requests.proto Outdated Show resolved Hide resolved
crates/store/src/state.rs Outdated Show resolved Hide resolved
@polydez polydez requested a review from bobbinth October 2, 2024 06:52
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good! I left one comment inline. Also, let's rename the endpoint to GetAccountProofs.

@@ -15,6 +15,7 @@ repository.workspace = true
directories = { version = "5.0" }
figment = { version = "0.10", features = ["toml", "env"] }
hex = { version = "0.4" }
miden-lib = { workspace = true}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this dependency still needed?

// because changing one of them would lead to inconsistent state.
let inner_state = self.inner.read().await;

let infos = self.db.select_accounts_by_ids(account_ids.iter().copied().collect()).await?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to go to the database only if include_headers is true - right? Otherwise, all the info we need should be already in memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you!

@polydez polydez requested a review from bobbinth October 3, 2024 08:11
@polydez polydez changed the title Implemented GetAccountStates endpoint Implemented GetAccountProofs endpoint Oct 3, 2024
Copy link
Contributor

@bobbinth bobbinth 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! Thank you! I left some small comments inline - once these are addressed, we can merge.

Also, our docs for various endpoints (in README files) are getting out of date. Let's create an issue to update them. In the same issue we can discuss if there is some automated way to generate endpoint docs for rpc/store/block producer components.

Comment on lines 198 to 199
/// Values of all account storage slots (max 255).
bytes storage_header = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this should be just // rather than ///.

Comment on lines 191 to 192
/// State header for public accounts. Filled only if `include_headers` flag is set to `true`.
optional AccountStateHeader state_header = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar nit as the one above.

Comment on lines 180 to 181
// List of account state infos for the requested account keys.
repeated AccountProofsResponse account_state_infos = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the name of the field be account_proofs or something like that? (not sure if state_infos has much meaning in this context).


#[instrument(
target = "miden-rpc",
name = "rpc:get_account_states",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be changed to rpc:get_account_proofs.

@@ -475,6 +477,35 @@ impl api_server::Api for StoreApi {
Ok(Response::new(GetBlockByNumberResponse { block }))
}

#[instrument(
target = "miden-store",
name = "store:get_account_state",
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also be changed to store:get_account_proofs.

Comment on lines 683 to 687
pub async fn get_account_states(
&self,
account_ids: HashSet<AccountId>,
include_headers: bool,
) -> Result<(BlockNumber, Vec<AccountProofsResponse>), DatabaseError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: why pass account_ids as a HashSet rather than a simple Vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to reduce number of conversions but now I think it was better to pass vector here. Thank you!

let inner_state = self.inner.read().await;

let state_headers = if !include_headers {
HashMap::<AccountId, AccountStateHeader>::default()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to use HashMap rather than BTreeMap here? I don't really have a strong preference, but we usually use BTreeMpas everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't have strong preference here. Taking that this map will be pretty small, it shouldn't be any significant difference between them, so I will use BTreeMap here, thanks!

@polydez polydez merged commit a6a12ff into next Oct 4, 2024
8 checks passed
@polydez polydez deleted the polydez-acc-states-endpoint branch October 4, 2024 06:12
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.

3 participants