Skip to content

Commit

Permalink
resharding: verify proof (near#12485)
Browse files Browse the repository at this point in the history
Completes the resharding validation flow on the chunk validator side.

The code replaces `MainTransition::ShardLayoutChange` with actual logic.
The whole preparation is needed to call `let new_root =
trie.retain_split_shard(&boundary_account, retain_mode)?;`, to verify it
against state root provided in transition.

The main complexity is to introduce implicit transition for resharding
to the right place - after applying last chunk in old shard layout,
potentially missing, and before applying first chunk in the new layout.
To do that, I needed to modify `get_state_witness_block_range` once
again, and to make it readable, I rewrote it using `TraversalPosition`.
The point of that is to change all parameters of the loop at once,
instead of changing them one-by-one in the loop. Then, I generate
`ImplicitTransitionParams` right in the loop. Finally, this allows to
insert resharding transition before jumping to the previous block hash
and child shard id, if needed. Note that this flow happens in reverse to
chain flow.

Also unfortunately this is not triggered on production tests, because
when nodes track all shards, the condition `if let Ok(prev_chunk_extra)
= chain.get_chunk_extra(prev_block_hash, &shard_uid) { ... }` is
triggered - if latest chunk extra is already computed, we skip
unnecessary validations. So for now I checked the correctness by
commenting this path and running tests locally.
  • Loading branch information
Longarithm authored Nov 23, 2024
1 parent cc3cbc6 commit af6559a
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 160 deletions.
8 changes: 1 addition & 7 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3740,19 +3740,13 @@ impl Chain {
self.shard_tracker.care_about_shard(me.as_ref(), prev_hash, shard_id, true);
let cares_about_shard_next_epoch =
self.shard_tracker.will_care_about_shard(me.as_ref(), prev_hash, shard_id, true);
let will_shard_layout_change = self.epoch_manager.will_shard_layout_change(prev_hash)?;
let should_apply_chunk = get_should_apply_chunk(
mode,
cares_about_shard_this_epoch,
cares_about_shard_next_epoch,
);
let shard_uid = self.epoch_manager.shard_id_to_uid(shard_id, epoch_id)?;
Ok(ShardContext {
shard_uid,
cares_about_shard_this_epoch,
will_shard_layout_change,
should_apply_chunk,
})
Ok(ShardContext { shard_uid, should_apply_chunk })
}

/// This method returns the closure that is responsible for updating a shard.
Expand Down
Loading

0 comments on commit af6559a

Please sign in to comment.