Skip to content

Commit

Permalink
refactor: prepare shard update impl for stateless validation (#10187)
Browse files Browse the repository at this point in the history
This is just a refactor, which shouldn't change any behaviour of the
code but prepares it for stateless validation.

We came up with idea that logic contained in `get_apply_chunk_job_*`
method should not depend on Chain that heavily. Here I extract all logic
where Chain is required to `get_apply_chunk_job` only. All remaining
logic is moved to `update_shard.rs`. For better readability, I introduce
more updates:
* "apply_chunk" is mostly replaced with "update_shard" because it is
closer to what actually happens. When new chunk exists, we indeed apply
it. But in two other cases listed in `ShardUpdateReason` enum we only
update validator accounts or process split state info.
* excessive info about blocks and chunks is replaced with exact
`BlockContext` and `ShardUpdateReason` contents which are specific for
all shard updates. Now it should be much more clear which data is
necessary. Note that receipts are passed only when new chunk appears.

chain.rs size is reduced by 250 lines which is good I think.

In the follow-up PRs you can see more refactoring (but less invasive)
and introducing of "shadow" jobs for stateless validation on nightly,
which will in fact call `apply_old_chunk` N times and then
`apply_new_chunk` 1 time. It was impossible to do using previous API.

Nayduck https://nayduck.near.org/#/run/3276

---------

Co-authored-by: Longarithm <[email protected]>
  • Loading branch information
Longarithm and Looogarithm authored Nov 20, 2023
1 parent eb6ced0 commit 88c3efc
Show file tree
Hide file tree
Showing 3 changed files with 525 additions and 417 deletions.
Loading

0 comments on commit 88c3efc

Please sign in to comment.