Skip to content

Commit

Permalink
fix(resharding) - fix loading shards when no resharding is scheduled (#…
Browse files Browse the repository at this point in the history
…12808)

The issue was that since `STABLE_PROTOCOL_VERSION` was higher than
what's in mainnet the implementation was including the current shard
layout in the calculation. Additionally the current shard layout is V1
and it has non-unique shard ids which made it seem like there is a
resharding pending.

The fix is to exclude the head shard layout from the calculation.
  • Loading branch information
wacban authored Jan 27, 2025
1 parent 5b17d59 commit 5baf443
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chain/epoch-manager/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,21 @@ pub trait EpochManagerAdapter: Send + Sync {
head_protocol_version: ProtocolVersion,
client_protocol_version: ProtocolVersion,
) -> Result<HashSet<ShardUId>, Error> {
let head_shard_layout = self.get_shard_layout_from_protocol_version(head_protocol_version);
let mut shard_layouts = vec![];
for protocol_version in head_protocol_version + 1..=client_protocol_version {
let shard_layout = self.get_shard_layout_from_protocol_version(protocol_version);
if shard_layout == head_shard_layout {
continue;
}

let last_shard_layout = shard_layouts.last();
if last_shard_layout == None || last_shard_layout != Some(&shard_layout) {
if last_shard_layout != Some(&shard_layout) {
shard_layouts.push(shard_layout);
}
}

let mut result = HashSet::new();
let head_shard_layout = self.get_shard_layout_from_protocol_version(head_protocol_version);
for shard_uid in head_shard_layout.shard_uids() {
let shard_id = shard_uid.shard_id();
for shard_layout in &shard_layouts {
Expand Down
16 changes: 16 additions & 0 deletions chain/epoch-manager/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,22 @@ fn test_get_shard_uids_pending_resharding_none() {
assert_eq!(shard_uids.len(), 0);
}

/// Test there are no ShardUIds pending resharding when there are no planned
/// reshardings in the simple nightshade v3 shard layout that is used in prod.
///
/// This test checks that when then protocol version is changing but the shard
/// layout is not, no shard is pending resharding.
#[test]
fn test_get_shard_uids_pending_resharding_simple_nightshade() {
let v3 = ShardLayout::get_simple_nightshade_layout_v3();
let shard_uids = test_get_shard_uids_pending_resharding_base(&[v3.clone(), v3]);
assert_eq!(shard_uids.len(), 0);

let v4 = ShardLayout::get_simple_nightshade_layout_v4();
let shard_uids = test_get_shard_uids_pending_resharding_base(&[v4.clone(), v4]);
assert_eq!(shard_uids.len(), 0);
}

/// Test that there is only one ShardUId pending resharding during a single
/// resharding.
#[test]
Expand Down

0 comments on commit 5baf443

Please sign in to comment.