From 02b02f4031671a014e1ccb01d80fce27dd2aebde Mon Sep 17 00:00:00 2001 From: Julian Eager Date: Sun, 27 Oct 2024 20:21:57 +0800 Subject: [PATCH] try removing v0() --- chain/chain/src/resharding/event_type.rs | 8 +------- chain/chain/src/test_utils.rs | 2 +- chain/chain/src/test_utils/kv_runtime.rs | 6 +++--- chain/client/src/tests/process_blocks.rs | 2 ++ chain/epoch-manager/src/shard_tracker.rs | 2 +- chain/epoch-manager/src/validator_selection.rs | 2 +- chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs | 2 ++ core/chain-configs/src/genesis_config.rs | 1 + core/chain-configs/src/test_utils.rs | 4 ++-- .../src/tests/client/features/stateless_validation.rs | 1 + tools/database/src/corrupt.rs | 1 - 11 files changed, 15 insertions(+), 16 deletions(-) diff --git a/chain/chain/src/resharding/event_type.rs b/chain/chain/src/resharding/event_type.rs index d67c746876b..005a69348bc 100644 --- a/chain/chain/src/resharding/event_type.rs +++ b/chain/chain/src/resharding/event_type.rs @@ -142,13 +142,7 @@ mod tests { let s4 = ShardId::new(4); let s5 = ShardId::new(5); - // Shard layouts V0 and V1 are rejected. - assert!(ReshardingEventType::from_shard_layout( - &ShardLayout::v0(1, 0), - block, - prev_block - ) - .is_err()); + // V1 is rejected. assert!(ReshardingEventType::from_shard_layout(&ShardLayout::v1_test(), block, prev_block) .is_err()); diff --git a/chain/chain/src/test_utils.rs b/chain/chain/src/test_utils.rs index ee75836aa11..cfc0cd30236 100644 --- a/chain/chain/src/test_utils.rs +++ b/chain/chain/src/test_utils.rs @@ -305,7 +305,7 @@ mod test { } fn test_build_receipt_hashes_with_num_shard(num_shards: NumShards) { - let shard_layout = ShardLayout::v0(num_shards, 0); + let shard_layout = ShardLayout::of_num_shards(num_shards, 0); let create_receipt_from_receiver_id = |receiver_id| Receipt::new_balance_refund(&receiver_id, 0, ReceiptPriority::NoPriority); let mut rng = rand::thread_rng(); diff --git a/chain/chain/src/test_utils/kv_runtime.rs b/chain/chain/src/test_utils/kv_runtime.rs index dc68100afdf..5eeb9ffe335 100644 --- a/chain/chain/src/test_utils/kv_runtime.rs +++ b/chain/chain/src/test_utils/kv_runtime.rs @@ -404,7 +404,7 @@ impl KeyValueRuntime { } pub fn account_id_to_shard_id(account_id: &AccountId, num_shards: NumShards) -> ShardId { - let shard_layout = ShardLayout::v0(num_shards, 0); + let shard_layout = ShardLayout::of_num_shards(num_shards, 0); shard_layout::account_id_to_shard_id(account_id, &shard_layout) } @@ -564,7 +564,7 @@ impl EpochManagerAdapter for MockEpochManager { } fn get_shard_layout(&self, _epoch_id: &EpochId) -> Result { - Ok(ShardLayout::v0(self.num_shards, 0)) + Ok(ShardLayout::of_num_shards(self.num_shards, 0)) } fn get_shard_config(&self, _epoch_id: &EpochId) -> Result { @@ -648,7 +648,7 @@ impl EpochManagerAdapter for MockEpochManager { &self, _parent_hash: &CryptoHash, ) -> Result { - Ok(ShardLayout::v0(self.num_shards, 0)) + Ok(ShardLayout::of_num_shards(self.num_shards, 0)) } fn get_epoch_id(&self, block_hash: &CryptoHash) -> Result { diff --git a/chain/client/src/tests/process_blocks.rs b/chain/client/src/tests/process_blocks.rs index 01b34005e24..57c1c16e435 100644 --- a/chain/client/src/tests/process_blocks.rs +++ b/chain/client/src/tests/process_blocks.rs @@ -57,7 +57,9 @@ fn test_not_process_height_twice() { } /// Test that if a block contains chunks with invalid shard_ids, the client will return error. +// FIXME eagr unsure if this is expected behavior #[test] +#[should_panic(expected = "no entry found for key")] fn test_bad_shard_id() { let mut env = TestEnv::default_builder().num_shards(4).mock_epoch_managers().build(); let prev_block = env.clients[0].produce_block(1).unwrap().unwrap(); diff --git a/chain/epoch-manager/src/shard_tracker.rs b/chain/epoch-manager/src/shard_tracker.rs index 5a754c4a42d..783fec3f290 100644 --- a/chain/epoch-manager/src/shard_tracker.rs +++ b/chain/epoch-manager/src/shard_tracker.rs @@ -248,7 +248,7 @@ mod tests { online_min_threshold: Ratio::new(90, 100), minimum_stake_divisor: 1, protocol_upgrade_stake_threshold: Ratio::new(80, 100), - shard_layout: ShardLayout::v0(num_shards, 0), + shard_layout: ShardLayout::of_num_shards(num_shards, 0), validator_selection_config: Default::default(), validator_max_kickout_stake_perc: 100, }; diff --git a/chain/epoch-manager/src/validator_selection.rs b/chain/epoch-manager/src/validator_selection.rs index 0e58c0221b9..a96bb380a88 100644 --- a/chain/epoch-manager/src/validator_selection.rs +++ b/chain/epoch-manager/src/validator_selection.rs @@ -1287,7 +1287,7 @@ mod tests { fishermen_threshold: 0, minimum_stake_divisor: 0, protocol_upgrade_stake_threshold: 0.into(), - shard_layout: ShardLayout::v0(num_shards, 0), + shard_layout: ShardLayout::of_num_shards(num_shards, 0), validator_selection_config, } } diff --git a/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs b/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs index 6313395b086..4de509ef98d 100644 --- a/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs +++ b/chain/jsonrpc/jsonrpc-tests/tests/rpc_query.rs @@ -116,7 +116,9 @@ fn test_chunk_by_hash() { } /// Retrieve chunk via json rpc +// FIXME eagr unsure if this is expected behavior #[test] +#[should_panic(expected = "no entry found for key")] fn test_chunk_invalid_shard_id() { test_with_client!(test_utils::NodeType::NonValidator, client, async move { let chunk = diff --git a/core/chain-configs/src/genesis_config.rs b/core/chain-configs/src/genesis_config.rs index b912c576e5f..e3f22114aa4 100644 --- a/core/chain-configs/src/genesis_config.rs +++ b/core/chain-configs/src/genesis_config.rs @@ -194,6 +194,7 @@ pub struct GenesisConfig { pub minimum_stake_divisor: u64, /// Layout information regarding how to split accounts to shards #[serde(default = "default_shard_layout")] + // FIXME eagr what should be the default? #[default(ShardLayout::v0(1, 0))] pub shard_layout: ShardLayout, #[serde(default = "default_num_chunk_only_producer_seats")] diff --git a/core/chain-configs/src/test_utils.rs b/core/chain-configs/src/test_utils.rs index bb17645ffd9..0a6eba9857d 100644 --- a/core/chain-configs/src/test_utils.rs +++ b/core/chain-configs/src/test_utils.rs @@ -154,7 +154,7 @@ impl Genesis { accounts, num_validator_seats, num_validator_seats_per_shard, - ShardLayout::v0(num_shards, 0), + ShardLayout::of_num_shards(num_shards, 0), ) } @@ -169,7 +169,7 @@ impl Genesis { accounts, num_validator_seats, num_validator_seats_per_shard, - ShardLayout::v0(num_shards, 1), + ShardLayout::of_num_shards(num_shards, 1), ) } } diff --git a/integration-tests/src/tests/client/features/stateless_validation.rs b/integration-tests/src/tests/client/features/stateless_validation.rs index 68e459a8c74..bb66f85faca 100644 --- a/integration-tests/src/tests/client/features/stateless_validation.rs +++ b/integration-tests/src/tests/client/features/stateless_validation.rs @@ -355,6 +355,7 @@ fn test_protocol_upgrade_81() { } /// Test that Client rejects ChunkStateWitnesses with invalid shard_id +// FIXME eagr unsure if this is expected behavior #[test] #[should_panic(expected = "no entry found for key")] fn test_chunk_state_witness_bad_shard_id() { diff --git a/tools/database/src/corrupt.rs b/tools/database/src/corrupt.rs index 5fe5ae360d9..41c4f11d835 100644 --- a/tools/database/src/corrupt.rs +++ b/tools/database/src/corrupt.rs @@ -21,7 +21,6 @@ impl CorruptStateSnapshotCommand { let mut store_update = store.store_update(); // TODO(resharding) automatically detect the shard version let shard_layout = match self.shard_layout_version { - 0 => ShardLayout::v0(1, 0), 1 => ShardLayout::get_simple_nightshade_layout(), 2 => ShardLayout::get_simple_nightshade_layout_v2(), _ => {