Skip to content

Commit

Permalink
Add logic to populate initial node identity from stake table (#2099)
Browse files Browse the repository at this point in the history
It was noticed that the initial list of node identities does not consider the public
keys listed in the stake table.  This can easily be demonstrated by launching the
`node-metrics` binary with `ESPRESSO_NODE_VALIDATOR_STAKE_TABLE_SOURCE_BASE_URL`
and `ESPRESSO_NODE_VALIDATOR_LEAF_STREAM_SOURCE_BASE_URL` populated, but missing
`ESPRESSO_NODE_VALIDATOR_INITIAL_NODE_PUBLIC_BASE_URLS`.

In this case the list of node identities will be empty, and the information coming down
to consuming clients will be missing all node identities.

The fix is to modify the `DataState` structure so that it is initially populated with
information from the passed in stake table.
  • Loading branch information
Ayiga authored Oct 3, 2024
1 parent c87b7a3 commit a619d1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,7 @@ pub async fn create_node_validator_processing(
.await
.map_err(CreateNodeValidatorProcessingError::FailedToGetStakeTable)?;

let data_state = DataState::new(
Default::default(),
Default::default(),
stake_table,
Default::default(),
);
let data_state = DataState::new(Default::default(), Default::default(), stake_table);

let data_state = Arc::new(RwLock::new(data_state));
let client_thread_state = Arc::new(RwLock::new(client_thread_state));
Expand Down
11 changes: 10 additions & 1 deletion node-metrics/src/service/data_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ impl DataState {
latest_blocks: CircularBuffer<MAX_HISTORY, BlockDetail<SeqTypes>>,
latest_voters: CircularBuffer<MAX_HISTORY, BitVec<u16>>,
stake_table: StakeTable<BLSPubKey, StateVerKey, CircuitField>,
node_identity: Vec<NodeIdentity>,
) -> Self {
let node_identity = {
let stake_table_iter_result = stake_table.try_iter(SnapshotVersion::Head);
match stake_table_iter_result {
Ok(into_iter) => into_iter
.map(|(key, _, _)| NodeIdentity::from_public_key(key))
.collect(),
Err(_) => vec![],
}
};

Self {
latest_blocks,
latest_voters,
Expand Down

0 comments on commit a619d1a

Please sign in to comment.