-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
There was a problem hiding this 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?
There was a problem hiding this 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
.
crates/rpc/Cargo.toml
Outdated
@@ -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} |
There was a problem hiding this comment.
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?
crates/store/src/state.rs
Outdated
// 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?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thank you!
GetAccountStates
endpointGetAccountProofs
endpoint
There was a problem hiding this 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.
proto/responses.proto
Outdated
/// Values of all account storage slots (max 255). | ||
bytes storage_header = 2; |
There was a problem hiding this comment.
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 ///
.
proto/responses.proto
Outdated
/// State header for public accounts. Filled only if `include_headers` flag is set to `true`. | ||
optional AccountStateHeader state_header = 4; |
There was a problem hiding this comment.
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.
proto/responses.proto
Outdated
// List of account state infos for the requested account keys. | ||
repeated AccountProofsResponse account_state_infos = 2; |
There was a problem hiding this comment.
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).
crates/rpc/src/server/api.rs
Outdated
|
||
#[instrument( | ||
target = "miden-rpc", | ||
name = "rpc:get_account_states", |
There was a problem hiding this comment.
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
.
crates/store/src/server/api.rs
Outdated
@@ -475,6 +477,35 @@ impl api_server::Api for StoreApi { | |||
Ok(Response::new(GetBlockByNumberResponse { block })) | |||
} | |||
|
|||
#[instrument( | |||
target = "miden-store", | |||
name = "store:get_account_state", |
There was a problem hiding this comment.
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
.
crates/store/src/state.rs
Outdated
pub async fn get_account_states( | ||
&self, | ||
account_ids: HashSet<AccountId>, | ||
include_headers: bool, | ||
) -> Result<(BlockNumber, Vec<AccountProofsResponse>), DatabaseError> { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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!
crates/store/src/state.rs
Outdated
let inner_state = self.inner.read().await; | ||
|
||
let state_headers = if !include_headers { | ||
HashMap::<AccountId, AccountStateHeader>::default() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
# Conflicts: # CHANGELOG.md
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.