Skip to content

Commit

Permalink
refactor: replace another instance of continuguous shard ids assumpti…
Browse files Browse the repository at this point in the history
…on (#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
#10230 (comment).
  • Loading branch information
akhi3030 authored Nov 24, 2023
1 parent f6639af commit 7276454
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions genesis-tools/genesis-csv-to-json/src/csv_to_json_configs.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -38,7 +38,8 @@ pub fn csv_to_json_configs(home: &Path, chain_id: String, tracked_shards: Vec<Sh
// Verify that key files exist.
assert!(home.join(NODE_KEY_FILE).as_path().exists(), "Node key file should exist");

if tracked_shards.iter().any(|&shard_id| shard_id >= 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");
}

Expand All @@ -61,10 +62,10 @@ pub fn csv_to_json_configs(home: &Path, chain_id: String, tracked_shards: Vec<Sh
chain_id: chain_id.clone(),
num_block_producer_seats: NUM_BLOCK_PRODUCER_SEATS,
num_block_producer_seats_per_shard: get_num_seats_per_shard(
NUM_SHARDS,
SHARDS.len() as NumShards,
NUM_BLOCK_PRODUCER_SEATS,
),
avg_hidden_validator_seats_per_shard: vec![0; NUM_SHARDS as usize],
avg_hidden_validator_seats_per_shard: SHARDS.iter().map(|_| 0).collect(),
dynamic_resharding: false,
protocol_upgrade_stake_threshold: PROTOCOL_UPGRADE_STAKE_THRESHOLD,
epoch_length: EXPECTED_EPOCH_LENGTH,
Expand Down

0 comments on commit 7276454

Please sign in to comment.