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

state-sync: rename current epoch state sync protocol feature #12385

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,7 +2534,7 @@ impl Chain {
}
let header = self.get_block_header(block_hash)?;
let protocol_version = self.epoch_manager.get_epoch_protocol_version(header.epoch_id())?;
if ProtocolFeature::StateSyncHashUpdate.enabled(protocol_version) {
if ProtocolFeature::CurrentEpochStateSync.enabled(protocol_version) {
self.chain_store.get_current_epoch_sync_hash(header.epoch_id())
} else {
// In the first epoch, it doesn't make sense to sync state to the previous epoch.
Expand Down Expand Up @@ -3954,7 +3954,7 @@ impl Chain {
match snapshot_config.state_snapshot_type {
// For every epoch, we snapshot if the next block is the state sync "sync_hash" block
StateSnapshotType::EveryEpoch => {
if !ProtocolFeature::StateSyncHashUpdate.enabled(protocol_version) {
if !ProtocolFeature::CurrentEpochStateSync.enabled(protocol_version) {
if is_epoch_boundary {
// Here we return head.last_block_hash as the prev_hash of the first block of the next epoch
Ok(SnapshotAction::MakeSnapshot(head.last_block_hash))
Expand Down
4 changes: 2 additions & 2 deletions core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub enum ProtocolFeature {
/// should no longer be the first block of the epoch, but a couple blocks after that in order
/// to sync the current epoch's state. This is not strictly a protocol feature, but is included
/// here to coordinate among nodes
StateSyncHashUpdate,
CurrentEpochStateSync,
}

impl ProtocolFeature {
Expand Down Expand Up @@ -259,7 +259,7 @@ impl ProtocolFeature {
// TODO(#11201): When stabilizing this feature in mainnet, also remove the temporary code
// that always enables this for mocknet (see config_mocknet function).
ProtocolFeature::ShuffleShardAssignments => 143,
ProtocolFeature::StateSyncHashUpdate => 144,
ProtocolFeature::CurrentEpochStateSync => 144,
ProtocolFeature::SimpleNightshadeV4 => 145,
ProtocolFeature::ExcludeContractCodeFromStateWitness => 146,
ProtocolFeature::BandwidthScheduler => 147,
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/sharding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl StateSyncInfo {
shard_layout: &ShardLayout,
shards: &[ShardId],
) -> Result<Self, ShardLayoutError> {
if ProtocolFeature::StateSyncHashUpdate.enabled(protocol_version) {
if ProtocolFeature::CurrentEpochStateSync.enabled(protocol_version) {
Self::new_current_epoch(epoch_first_block, prev_block, shard_layout, shards)
} else {
Self::new_previous_epoch(epoch_first_block, prev_block, shard_layout, shards)
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,7 +2190,7 @@ fn test_sync_hash_validity() {
let block_hash = *header.hash();
let valid = env.clients[0].chain.check_sync_hash_validity(&block_hash).unwrap();
println!("height {} -> {}", i, valid);
if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION) {
if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
// This assumes that all shards have new chunks in every block, which should be true
// with TestEnv::produce_block()
assert_eq!(valid, (i % epoch_length) == 3);
Expand Down Expand Up @@ -3732,7 +3732,7 @@ mod contract_precompilation_tests {
start_height,
);

let sync_height = if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION) {
let sync_height = if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
// `height` is one more than the start of the epoch. Produce two more blocks with chunks,
// and then one more than that so the node will generate the neede snapshot.
produce_blocks_from_height(&mut env, 3, height) - 2
Expand Down Expand Up @@ -3846,7 +3846,7 @@ mod contract_precompilation_tests {
height,
);

let sync_height = if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION) {
let sync_height = if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
// `height` is one more than the start of the epoch. Produce two more blocks with chunks,
// and then one more than that so the node will generate the neede snapshot.
produce_blocks_from_height(&mut env, 3, height) - 2
Expand Down Expand Up @@ -3929,7 +3929,7 @@ mod contract_precompilation_tests {
// so if we want to state sync the old way, we produce `EPOCH_LENGTH` + 1 new blocks
// to get to produce the first block of the next epoch. If we want to state sync the new
// way, we produce two more than that, plus one more so that the node will generate the needed snapshot.
let sync_height = if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION) {
let sync_height = if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
produce_blocks_from_height(&mut env, EPOCH_LENGTH + 4, height) - 2
} else {
produce_blocks_from_height(&mut env, EPOCH_LENGTH + 1, height) - 1
Expand Down
30 changes: 15 additions & 15 deletions integration-tests/src/tests/client/sync_state_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ fn test_dump_epoch_missing_chunk_in_last_block() {
// Note that the height to skip here refers to the height at which not to produce chunks for the next block, so really
// one before the block height that will have no chunks. The sync_height is the height of the sync_hash block.
let (start_skipping_chunks, sync_height) =
if ProtocolFeature::StateSyncHashUpdate.enabled(protocol_version) {
if ProtocolFeature::CurrentEpochStateSync.enabled(protocol_version) {
// At the beginning of the epoch, produce one block with chunks and then start skipping chunks.
let start_skipping_chunks = next_epoch_start + 1;
// Then we will skip `num_chunks_missing` chunks, and produce one more with chunks, which will be the sync height.
Expand Down Expand Up @@ -862,13 +862,13 @@ fn test_state_sync_headers() {
};
tracing::info!(epoch_start_height, "got epoch_start_height");

let sync_height = if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION)
{
// here since there's only one block/chunk producer, we assume that no blocks will be missing chunks.
epoch_start_height + 2
} else {
epoch_start_height
};
let sync_height =
if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
// here since there's only one block/chunk producer, we assume that no blocks will be missing chunks.
epoch_start_height + 2
} else {
epoch_start_height
};
let block_id = BlockReference::BlockId(BlockId::Height(sync_height));
let block_view = view_client1.send(GetBlock(block_id).with_span_context()).await;
let Ok(Ok(block_view)) = block_view else {
Expand Down Expand Up @@ -1047,13 +1047,13 @@ fn test_state_sync_headers_no_tracked_shards() {
return ControlFlow::Continue(());
}

let sync_height = if ProtocolFeature::StateSyncHashUpdate.enabled(PROTOCOL_VERSION)
{
// here since there's only one block/chunk producer, we assume that no blocks will be missing chunks.
epoch_start_height + 2
} else {
epoch_start_height
};
let sync_height =
if ProtocolFeature::CurrentEpochStateSync.enabled(PROTOCOL_VERSION) {
// here since there's only one block/chunk producer, we assume that no blocks will be missing chunks.
epoch_start_height + 2
} else {
epoch_start_height
};
let block_id = BlockReference::BlockId(BlockId::Height(sync_height));
let block_view = view_client2.send(GetBlock(block_id).with_span_context()).await;
let Ok(Ok(block_view)) = block_view else {
Expand Down
Loading