Skip to content

Commit

Permalink
fix(vn/ui): committee bucket information
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 14, 2023
1 parent ac8ddb9 commit e707f17
Show file tree
Hide file tree
Showing 44 changed files with 711 additions and 490 deletions.
59 changes: 41 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion applications/tari_indexer_web_ui/src/utils/json_rpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function getCommsStats() {
return await jsonRpc('get_comms_stats');
}
async function getAllVns(epoch: number) {
return await jsonRpc('get_all_vns', epoch);
return await jsonRpc('get_network_validators', {epoch});
}
async function getConnections() {
return await jsonRpc('get_connections');
Expand Down
1 change: 1 addition & 0 deletions applications/tari_validator_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ clap = { version = "3.2.5", features = ["env"] }
config = "0.13.0"
futures = { version = "^0.3.1" }
include_dir = "0.7.2"
indexmap = "2.0.0"
json5 = "0.2.2"
libsqlite3-sys = { version = "0.25", features = ["bundled"] }
lmdb-zero = "0.4.4"
Expand Down
70 changes: 70 additions & 0 deletions applications/tari_validator_node/src/json_rpc/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use axum_jrpc::{
JsonRpcExtractor,
JsonRpcResponse,
};
use indexmap::IndexMap;
use log::*;
use serde::Serialize;
use serde_json::{self as json, json};
Expand All @@ -54,10 +55,12 @@ use tari_state_store_sqlite::SqliteStateStore;
use tari_validator_node_client::types::{
AddPeerRequest,
AddPeerResponse,
CommitteeShardInfo,
DryRunTransactionFinalizeResult,
GetCommitteeRequest,
GetEpochManagerStatsResponse,
GetIdentityResponse,
GetNetworkCommitteeResponse,
GetRecentTransactionsResponse,
GetShardKey,
GetStateRequest,
Expand Down Expand Up @@ -533,10 +536,29 @@ impl JsonRpcHandlers {
),
)
})?;
let committee_shard = if is_valid {
self.epoch_manager
.get_local_committee_shard(current_epoch)
.await
.map(Some)
.map_err(|err| {
JsonRpcResponse::error(
answer_id,
JsonRpcError::new(
JsonRpcErrorReason::InternalError,
format!("Could not get committee shard:{}", err),
json::Value::Null,
),
)
})?
} else {
None
};
let response = GetEpochManagerStatsResponse {
current_epoch,
current_block_height,
is_valid,
committee_shard,
};
Ok(JsonRpcResponse::success(answer_id, response))
}
Expand Down Expand Up @@ -637,6 +659,54 @@ impl JsonRpcHandlers {
}
}

pub async fn get_network_committees(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let current_epoch = self
.epoch_manager
.current_epoch()
.await
.map_err(internal_error(answer_id))?;
let num_committees = self
.epoch_manager
.get_num_committees(current_epoch)
.await
.map_err(internal_error(answer_id))?;

let mut validators = self
.epoch_manager
.get_all_validator_nodes(current_epoch)
.await
.map_err(internal_error(answer_id))?;

validators.sort_by(|vn_a, vn_b| vn_b.committee_bucket.cmp(&vn_a.committee_bucket));
// Group by bucket, IndexMap used to preserve ordering
let mut validators_per_bucket = IndexMap::with_capacity(validators.len());
for validator in validators {
validators_per_bucket
.entry(
validator
.committee_bucket
.expect("validator committee bucket must have been populated within valid epoch"),
)
.or_insert_with(Vec::new)
.push(validator);
}

let committees = validators_per_bucket
.into_iter()
.map(|(bucket, validators)| CommitteeShardInfo {
bucket,
shard_range: bucket.to_shard_range(num_committees),
validators,
})
.collect();

Ok(JsonRpcResponse::success(answer_id, GetNetworkCommitteeResponse {
current_epoch,
committees,
}))
}

pub async fn get_all_vns(&self, value: JsonRpcExtractor) -> JrpcResult {
let answer_id = value.get_answer_id();
let epoch: u64 = value.parse_params()?;
Expand Down
1 change: 1 addition & 0 deletions applications/tari_validator_node/src/json_rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ async fn handler(Extension(handlers): Extension<Arc<JsonRpcHandlers>>, value: Js
"get_shard_key" => handlers.get_shard_key(value).await,
"get_committee" => handlers.get_committee(value).await,
"get_all_vns" => handlers.get_all_vns(value).await,
"get_network_committees" => handlers.get_network_committees(value).await,
"get_fees" => handlers.get_validator_fees(value).await,
// Comms
"add_peer" => handlers.add_peer(value).await,
Expand Down
18 changes: 17 additions & 1 deletion applications/tari_validator_node_web_ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion applications/tari_validator_node_web_ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
]
},
"devDependencies": {
"@types/mermaid": "^9.2.0"
"@types/mermaid": "^9.2.0",
"prettier": "3.0.1"
}
}
Loading

0 comments on commit e707f17

Please sign in to comment.