From 93051adce855bcbba130f9339e861ce6161b63ab Mon Sep 17 00:00:00 2001 From: Theodore Schnepper Date: Wed, 2 Oct 2024 07:53:44 -0600 Subject: [PATCH] Add logic to populate initial node identity from stake table 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. --- .../node_validator/v0/create_node_validator_api.rs | 7 +------ node-metrics/src/service/data_state/mod.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/node-metrics/src/api/node_validator/v0/create_node_validator_api.rs b/node-metrics/src/api/node_validator/v0/create_node_validator_api.rs index 210dc805b..08c9271ff 100644 --- a/node-metrics/src/api/node_validator/v0/create_node_validator_api.rs +++ b/node-metrics/src/api/node_validator/v0/create_node_validator_api.rs @@ -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)); diff --git a/node-metrics/src/service/data_state/mod.rs b/node-metrics/src/service/data_state/mod.rs index 20668150f..79b256796 100644 --- a/node-metrics/src/service/data_state/mod.rs +++ b/node-metrics/src/service/data_state/mod.rs @@ -46,8 +46,17 @@ impl DataState { latest_blocks: CircularBuffer>, latest_voters: CircularBuffer>, stake_table: StakeTable, - node_identity: Vec, ) -> 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,