From 7276454ae8d59302ce3dc13c28a5167bbe22c6af Mon Sep 17 00:00:00 2001 From: Akhilesh Singhania Date: Fri, 24 Nov 2023 18:53:55 +0100 Subject: [PATCH] refactor: replace another instance of continuguous shard ids assumption (#10238) Instead of defining the number of shards and assuming they are contiguous, define a list of shard ids. As future work, we could try putting holes in the shard id list and see what tests / code breaks. Also see https://github.com/near/nearcore/pull/10230#discussion_r1403198617. --- .../src/csv_to_json_configs.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/genesis-tools/genesis-csv-to-json/src/csv_to_json_configs.rs b/genesis-tools/genesis-csv-to-json/src/csv_to_json_configs.rs index 0cd222d74e6..c73b3a7faed 100644 --- a/genesis-tools/genesis-csv-to-json/src/csv_to_json_configs.rs +++ b/genesis-tools/genesis-csv-to-json/src/csv_to_json_configs.rs @@ -1,6 +1,3 @@ -use std::fs::File; -use std::path::Path; - use near_chain_configs::{Genesis, GenesisConfig}; use near_primitives::types::{Balance, NumShards, ShardId}; use near_primitives::utils::get_num_seats_per_shard; @@ -13,9 +10,12 @@ use nearcore::config::{ TRANSACTION_VALIDITY_PERIOD, }; use nearcore::NEAR_BASE; +use std::collections::HashSet; +use std::fs::File; +use std::path::Path; const ACCOUNTS_FILE: &str = "accounts.csv"; -const NUM_SHARDS: NumShards = 8; +const SHARDS: &'static [ShardId] = &[0, 1, 2, 3, 4, 5, 6, 7]; fn verify_total_supply(total_supply: Balance, chain_id: &str) { if chain_id == near_primitives::chains::MAINNET { @@ -38,7 +38,8 @@ pub fn csv_to_json_configs(home: &Path, chain_id: String, tracked_shards: Vec= NUM_SHARDS) { + let shards_set: HashSet<_> = SHARDS.iter().collect(); + if tracked_shards.iter().any(|shard_id| !shards_set.contains(shard_id)) { panic!("Trying to track a shard that does not exist"); } @@ -61,10 +62,10 @@ pub fn csv_to_json_configs(home: &Path, chain_id: String, tracked_shards: Vec