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

New QueryRunner API #6

Merged
merged 27 commits into from
Dec 27, 2023
Merged

New QueryRunner API #6

merged 27 commits into from
Dec 27, 2023

Conversation

bidzyyys
Copy link
Contributor

No description provided.

@bidzyyys bidzyyys self-assigned this Dec 15, 2023
@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from ef71147 to 820a5d5 Compare December 15, 2023 15:24
Copy link
Collaborator

@matthias-wright matthias-wright left a 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.

@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from 820a5d5 to 1a8bdeb Compare December 18, 2023 12:18
@bidzyyys
Copy link
Contributor Author

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.

@matthias-wright changes applied!

@matthias-wright
Copy link
Collaborator

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.

@matthias-wright changes applied!

Thanks 🙏

@kckeiks
Copy link
Collaborator

kckeiks commented Dec 18, 2023

LGTM

@daltoncoder
Copy link
Member

daltoncoder commented Dec 18, 2023

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)
We would add this this to the interface:

    pub fn get_node_table_iter(&self) -> KeyIterator<NodeIndex> {
        self.inner.run(|ctx| self.node_table.get(&ctx).keys())
    }    pub fn get_node_table_iter(&self) -> KeyIterator<NodeIndex> {
        self.inner.run(|ctx| self.node_table.get(&ctx).keys())
    }

Then the following functions could be removed from the interface:
get_chain_id
get_committee_members
get_current_epoch
get_epoch_info
get_current_latencies
get_genesis_committee
get_last_block
get_node_registry
get_staking_amount
is_valid_node

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.

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>(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

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

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>(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

@bidzyyys bidzyyys Dec 19, 2023

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.

Copy link
Collaborator

@kckeiks kckeiks Dec 19, 2023

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.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changing to V then!

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> {
Copy link
Member

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

@ozwaldorf
Copy link
Member

ozwaldorf commented Dec 18, 2023

+1 for the trait extension pattern for the auto impl utilities, similar to AsyncRead and AsyncReadExt

@bidzyyys
Copy link
Contributor Author

Thanks @daltoncoder & @ozwaldorf for the input, I like the idea of trait extension pattern!

@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch 2 times, most recently from 5e2fca8 to 92be2e2 Compare December 20, 2023 08:38
@bidzyyys bidzyyys requested a review from daltoncoder December 20, 2023 08:38
@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from 92be2e2 to e0224b4 Compare December 21, 2023 11:53
@bidzyyys bidzyyys marked this pull request as ready for review December 21, 2023 15:17
core/interfaces/src/application.rs Outdated Show resolved Hide resolved
core/interfaces/src/application.rs Outdated Show resolved Hide resolved
core/interfaces/src/application.rs Outdated Show resolved Hide resolved
core/consensus/src/consensus.rs Outdated Show resolved Hide resolved
@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from d2afda0 to cb8a7d1 Compare December 21, 2023 19:41
Copy link
Member

@ozwaldorf ozwaldorf left a comment

Choose a reason for hiding this comment

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

lgtm

@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from cb8a7d1 to a314e1e Compare December 22, 2023 08:24
@bidzyyys bidzyyys requested a review from ozwaldorf December 22, 2023 08:26
@bidzyyys bidzyyys force-pushed the feature/new_query_runner branch from 810ae88 to 6dbf8b6 Compare December 27, 2023 11:06
@bidzyyys bidzyyys merged commit 74c25cc into main Dec 27, 2023
@bidzyyys bidzyyys deleted the feature/new_query_runner branch December 27, 2023 14:43
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.

5 participants