-
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
New QueryRunner API #6
Conversation
ef71147
to
820a5d5
Compare
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.
nice, looks good overall! I don't really like the macros do_keys
, do_query
, and query
. I think they make the code less readable and we are not gaining much by having them there. they way it was before, where we explicitly called self.inner.run
with the context seemed fine to me.
820a5d5
to
1a8bdeb
Compare
@matthias-wright changes applied! |
Thanks 🙏 |
LGTM |
Looks good. A couple suggestions to clean up the SyncQueryRunner interface even more. Id like to to keep the interface limited to direct state table access, and not for specific data within them. To do this we could add another function that takes a closure for the tables we need to iter over(just the NodeInfo table)
Then the following functions could be removed from the interface: We can add these functions to a util file, core/types/src/state_queries.rs, that take a SyncQueryRunner as a param and get this data from the provided functions. Things that are already using these functions can import it from there instead. Its a little bit of refactor but I think it stops the pattern we have been doing of adding to the interface to get new specific data from state. Edit: Another idea is to make a QueryRunnerExt trait in types that autoimplements those functions we are removing. Then everywhere else we can just bring this trait into scope. |
core/application/src/query_runner.rs
Outdated
fn get_locked(&self, node: &NodePublicKey) -> HpUfixed<18> { | ||
self.get_node_info_with_pub_key(node, |node_info| node_info.stake.locked) | ||
.unwrap_or(HpUfixed::zero()) | ||
fn get_account_info<F: Clone>( |
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.
fn get_account_info<F: Clone>( | |
#[inline] | |
fn get_account_info<F: Clone>( |
Lets mark all functions that take impl FnOnce
as #[inline] in the implementation to avoid the runtime lookup
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
core/application/src/query_runner.rs
Outdated
fn get_locked_time(&self, node: &NodePublicKey) -> Epoch { | ||
self.get_node_info_with_pub_key(node, |node_info| node_info.stake.locked_until) | ||
.unwrap_or(0) | ||
fn get_node_info<F: Clone>( |
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.
fn get_node_info<F: Clone>( | |
fn get_node_info<T>( |
None of these returns should need to be Clone,
Minor nit: Across all these functions lets rename the generic to T since its the return type of the closure and that is the typical naming convention. F makes me think it is the closure itself
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 can remove Clone
requirement.
Regarding F
-> T
we cannot do that. I posted a message some time ago in our internal Discord channel that with #[infusion::blank]
trait we cannot use T
parameter (probably it injects it somewhere). @daltoncoder if you wish I can change F
to sth else.
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 think he was objecting to F because it's commonly used for function-like bounds so I think it's fine to change it to anything else.
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.
Ah yeah i missed that message about infusion injecting T already. Let me work on getting a fix for that. In the meantime we can keep this F or whatever we want
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.
Changing to V
then!
core/application/src/query_runner.rs
Outdated
fn get_stake_locked_until(&self, node: &NodePublicKey) -> Epoch { | ||
self.get_node_info_with_pub_key(node, |node_info| node_info.stake.stake_locked_until) | ||
.unwrap_or(0) | ||
fn get_client_info(self, pub_key: &ClientPublicKey) -> Option<EthAddress> { |
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: Since this table is mapping ClientKey->EthAddress(AccountAddress) lets rename this function in interface to client_key_to_account_key
+1 for the trait extension pattern for the auto impl utilities, similar to AsyncRead and AsyncReadExt |
Thanks @daltoncoder & @ozwaldorf for the input, I like the idea of trait extension pattern! |
5e2fca8
to
92be2e2
Compare
92be2e2
to
e0224b4
Compare
d2afda0
to
cb8a7d1
Compare
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.
lgtm
cb8a7d1
to
a314e1e
Compare
810ae88
to
6dbf8b6
Compare
No description provided.