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

Optimize from_block(0) to the latest block we've queried #30

Open
stephenctw opened this issue Mar 11, 2024 · 2 comments
Open

Optimize from_block(0) to the latest block we've queried #30

stephenctw opened this issue Mar 11, 2024 · 2 comments
Assignees

Comments

@stephenctw
Copy link
Contributor

We should probably change this from_block(0) to the latest block we've queried. I suggest the following. Since there are many calls, and the only public method is pub async fn fetch_from_root:

creates a new field in struct StateReader called last_queried_block.
in fetch_from_root, query the current latest block, and save it in a local variable latest_block.
pass this queried latest_block to all nested functions, since the latest block may change while we're querying along the chain of function calls. Change all the queries to_block to use latest_block.
change all requests to query from to use self.last_queried_block.
after finishing querying the state fetch_from_root updates self.last_queried_block  to latest_block  before returning.
We might have to change &self to &mut self, or use a Mutex. Both makes a lot of sense, since with this change fetch_from_root calls have to be mutually exclusive. With mutex, we'd need to acquire the lock before we do anything, and only release it once we finish everything. The &mut self approach accomplishes the same thing at the type system level (but now we won't be able to share pointers to StateReader ). I think I prefer the &mut self approach.

@GCdePaula
Copy link
Collaborator

I'm rereading my comment, and I think I misunderstood how the fetch logic works.

Let's think more about it, but I think my suggestion might not work, and we might have to have to query from genesis like you're doing.

@stephenctw
Copy link
Contributor Author

stephenctw commented Mar 11, 2024

Yeah, I may have read your comment too quickly as well. The state is built from scratch every fetch from the root tournament. We may not cache this last_queried_block, but still genesis block 0 is crazy, it should be a relative genesis block to the tournament and allow users to configure it dynamically.

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

No branches or pull requests

2 participants