Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: correct validator count
Browse files Browse the repository at this point in the history
  • Loading branch information
hadjiszs committed Nov 24, 2023
1 parent 1e1135d commit 4b7db93
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
7 changes: 5 additions & 2 deletions crates/topos/src/components/node/services/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ pub(crate) fn spawn_tce_process(
genesis: Genesis,
shutdown: (CancellationToken, mpsc::Sender<()>),
) -> JoinHandle<Result<(), Errors>> {
let validators = genesis.validators().expect("Cannot parse validators");
let tce_params = ReliableBroadcastParams::new(validators.len());

let tce_config = TceConfiguration {
boot_peers: genesis
.boot_peers(Some(topos_p2p::constants::TCE_BOOTNODE_PORT))
.into_iter()
.chain(config.parse_boot_peers())
.collect::<Vec<_>>(),
validators: genesis.validators().expect("Cannot parse validators"),
validators,
auth_key: keys.network.map(AuthKey::PrivateKey),
signing_key: keys.validator.map(AuthKey::PrivateKey),
tce_addr: format!("/ip4/{}", config.libp2p_api_addr.ip()),
tce_local_port: config.libp2p_api_addr.port(),
tce_params: ReliableBroadcastParams::new(genesis.validator_count()),
tce_params,
api_addr: config.grpc_api_addr,
graphql_api_addr: config.graphql_api_addr,
metrics_api_addr: config.metrics_api_addr,
Expand Down
8 changes: 0 additions & 8 deletions crates/topos/src/config/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ impl Genesis {
Ok(Self { path, json })
}

// Considered as being the set of premined addresses for now
// TODO: Parse properly genesis.extraData instead
pub fn validator_count(&self) -> usize {
self.json["genesis"]["alloc"]
.as_object()
.map_or(0, |v| v.len())
}

// TODO: parse directly with serde
pub fn boot_peers(&self, port: Option<u16>) -> Vec<(PeerId, Multiaddr)> {
match self.json["bootnodes"].as_array() {
Expand Down
4 changes: 2 additions & 2 deletions crates/topos/src/config/genesis/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub fn genesis() -> Genesis {

#[rstest]
pub fn test_correct_validator_count(genesis: &Genesis) {
assert_eq!(4, genesis.validator_count());
let validators = genesis.validators().unwrap();
assert_eq!(validators.len(), 4);
}

#[rstest]
Expand All @@ -39,7 +40,6 @@ pub fn test_extract_validators(genesis: &Genesis) {
let third = ValidatorId::from_str("0xb4973cdb10894d1d1547673bd758589034c2bba5").unwrap();
let fourth = ValidatorId::from_str("0xc16d83893cb61872206d4e271b813015d3242d94").unwrap();

assert_eq!(validators.len(), 4);
assert_eq!(validators.get(&first), Some(&first));
assert_eq!(validators.get(&second), Some(&second));
assert_eq!(validators.get(&third), Some(&third));
Expand Down

0 comments on commit 4b7db93

Please sign in to comment.