Skip to content

Commit

Permalink
Have config/hotshot endpoint return full network config
Browse files Browse the repository at this point in the history
  • Loading branch information
jbearer committed Jul 15, 2024
1 parent 7184e3c commit 94eaec3
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 65 deletions.
28 changes: 10 additions & 18 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ use futures::{
};
use hotshot::types::{Event, SystemContextHandle};
use hotshot_events_service::events_source::{BuilderEvent, EventsSource, EventsStreamer};
use hotshot_orchestrator::config::NetworkConfig;
use hotshot_query_service::data_source::ExtensibleDataSource;
use hotshot_state_prover::service::light_client_genesis_from_stake_table;
use hotshot_types::{
data::ViewNumber, light_client::StateSignatureRequestBody, traits::network::ConnectedNetwork,
HotShotConfig,
};
use jf_merkle_tree::MerkleTreeScheme;
use vbs::version::StaticVersionType;

use self::data_source::{HotShotConfigDataSource, PublicHotShotConfig, StateSignatureDataSource};
use self::data_source::{HotShotConfigDataSource, PublicNetworkConfig, StateSignatureDataSource};
use crate::{
network, persistence::ChainConfigPersistence, state_signature::StateSigner, Node, SeqTypes,
SequencerContext,
Expand All @@ -53,6 +53,7 @@ struct ConsensusState<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver:
state_signer: Arc<StateSigner<Ver>>,
event_streamer: Arc<RwLock<EventsStreamer<SeqTypes>>>,
node_state: NodeState,
config: NetworkConfig<PubKey>,

#[derivative(Debug = "ignore")]
handle: Arc<RwLock<SystemContextHandle<SeqTypes, Node<N, P>>>>,
Expand All @@ -66,6 +67,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver: StaticVersionTyp
state_signer: ctx.state_signer(),
event_streamer: ctx.event_streamer(),
node_state: ctx.node_state(),
config: ctx.config(),
handle: ctx.consensus(),
}
}
Expand Down Expand Up @@ -114,18 +116,8 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver: StaticVersionTyp
&self.consensus.as_ref().get().await.get_ref().node_state
}

async fn hotshot_config(&self) -> HotShotConfig<PubKey> {
self.consensus
.as_ref()
.get()
.await
.get_ref()
.handle
.read()
.await
.hotshot
.config
.clone()
async fn network_config(&self) -> NetworkConfig<PubKey> {
self.consensus.as_ref().get().await.get_ref().config.clone()
}
}

Expand Down Expand Up @@ -314,16 +306,16 @@ impl<
P: SequencerPersistence,
> HotShotConfigDataSource for StorageState<N, P, D, Ver>
{
async fn get_config(&self) -> PublicHotShotConfig {
self.as_ref().hotshot_config().await.into()
async fn get_config(&self) -> PublicNetworkConfig {
self.as_ref().network_config().await.into()
}
}

impl<N: ConnectedNetwork<PubKey>, Ver: StaticVersionType + 'static, P: SequencerPersistence>
HotShotConfigDataSource for ApiState<N, P, Ver>
{
async fn get_config(&self) -> PublicHotShotConfig {
self.hotshot_config().await.into()
async fn get_config(&self) -> PublicNetworkConfig {
self.network_config().await.into()
}
}

Expand Down
217 changes: 176 additions & 41 deletions sequencer/src/api/data_source.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{num::NonZeroUsize, time::Duration};

use anyhow::bail;
use anyhow::{bail, Context};
use async_trait::async_trait;
use committable::Commitment;
use espresso_types::{
Expand All @@ -9,6 +9,9 @@ use espresso_types::{
};
use ethers::prelude::Address;
use futures::future::Future;
use hotshot_orchestrator::config::{
BuilderType, CombinedNetworkConfig, Libp2pConfig, NetworkConfig, RandomBuilderConfig,
};
use hotshot_query_service::{
availability::AvailabilityDataSource,
data_source::{MetricsDataSource, UpdateDataSource, VersionedDataSource},
Expand All @@ -20,7 +23,7 @@ use hotshot_types::{
data::ViewNumber, light_client::StateSignatureRequestBody, traits::network::ConnectedNetwork,
ExecutionType, HotShotConfig, PeerConfig, ValidatorConfig,
};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use tide_disco::Url;
use vbs::version::StaticVersionType;
use vec1::Vec1;
Expand Down Expand Up @@ -97,7 +100,7 @@ pub(crate) trait SubmitDataSource<N: ConnectedNetwork<PubKey>, P: SequencerPersi
}

pub(crate) trait HotShotConfigDataSource {
fn get_config(&self) -> impl Send + Future<Output = PublicHotShotConfig>;
fn get_config(&self) -> impl Send + Future<Output = PublicNetworkConfig>;
}

#[async_trait]
Expand Down Expand Up @@ -162,14 +165,14 @@ impl CatchupDataSource for MetricsDataSource {}
/// This struct defines the public Hotshot validator configuration.
/// Private key and state key pairs are excluded for security reasons.
#[derive(Debug, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicValidatorConfig {
pub public_key: PubKey,
pub stake_value: u64,
pub is_da: bool,
pub private_key: &'static str,
pub state_public_key: String,
pub state_key_pair: &'static str,
public_key: PubKey,
stake_value: u64,
is_da: bool,
private_key: String,
state_public_key: String,
state_key_pair: String,
}

impl From<ValidatorConfig<PubKey>> for PublicValidatorConfig {
Expand All @@ -189,45 +192,45 @@ impl From<ValidatorConfig<PubKey>> for PublicValidatorConfig {
stake_value,
is_da,
state_public_key: state_public_key.to_string(),
private_key: "*****",
state_key_pair: "*****",
private_key: "*****".into(),
state_key_pair: "*****".into(),
}
}
}

/// This struct defines the public Hotshot configuration parameters.
/// Our config module features a GET endpoint accessible via the route `/hotshot` to display the hotshot config parameters.
/// Hotshot config has sensitive information like private keys and such fields are excluded from this struct.
#[derive(Debug, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicHotShotConfig {
pub execution_type: ExecutionType,
pub start_threshold: (u64, u64),
pub num_nodes_with_stake: NonZeroUsize,
pub num_nodes_without_stake: usize,
pub known_nodes_with_stake: Vec<PeerConfig<PubKey>>,
pub known_da_nodes: Vec<PeerConfig<PubKey>>,
pub known_nodes_without_stake: Vec<PubKey>,
pub my_own_validator_config: PublicValidatorConfig,
pub da_staked_committee_size: usize,
pub da_non_staked_committee_size: usize,
pub fixed_leader_for_gpuvid: usize,
pub next_view_timeout: u64,
pub view_sync_timeout: Duration,
pub timeout_ratio: (u64, u64),
pub round_start_delay: u64,
pub start_delay: u64,
pub num_bootstrap: usize,
pub builder_timeout: Duration,
pub data_request_delay: Duration,
pub builder_urls: Vec1<Url>,
pub start_proposing_view: u64,
pub stop_proposing_view: u64,
pub start_voting_view: u64,
pub stop_voting_view: u64,
pub start_proposing_time: u64,
pub stop_proposing_time: u64,
pub start_voting_time: u64,
pub stop_voting_time: u64,
execution_type: ExecutionType,
start_threshold: (u64, u64),
num_nodes_with_stake: NonZeroUsize,
num_nodes_without_stake: usize,
known_nodes_with_stake: Vec<PeerConfig<PubKey>>,
known_da_nodes: Vec<PeerConfig<PubKey>>,
known_nodes_without_stake: Vec<PubKey>,
my_own_validator_config: PublicValidatorConfig,
da_staked_committee_size: usize,
da_non_staked_committee_size: usize,
fixed_leader_for_gpuvid: usize,
next_view_timeout: u64,
view_sync_timeout: Duration,
timeout_ratio: (u64, u64),
round_start_delay: u64,
start_delay: u64,
num_bootstrap: usize,
builder_timeout: Duration,
data_request_delay: Duration,
builder_urls: Vec1<Url>,
start_proposing_view: u64,
stop_proposing_view: u64,
start_voting_view: u64,
stop_voting_view: u64,
start_proposing_time: u64,
stop_proposing_time: u64,
start_voting_time: u64,
stop_voting_time: u64,
}

impl From<HotShotConfig<PubKey>> for PublicHotShotConfig {
Expand Down Expand Up @@ -299,6 +302,138 @@ impl From<HotShotConfig<PubKey>> for PublicHotShotConfig {
}
}

impl PublicHotShotConfig {
pub fn into_hotshot_config(
self,
my_own_validator_config: ValidatorConfig<PubKey>,
) -> HotShotConfig<PubKey> {
HotShotConfig {
execution_type: self.execution_type,
start_threshold: self.start_threshold,
num_nodes_with_stake: self.num_nodes_with_stake,
num_nodes_without_stake: self.num_nodes_without_stake,
known_nodes_with_stake: self.known_nodes_with_stake,
known_da_nodes: self.known_da_nodes,
known_nodes_without_stake: self.known_nodes_without_stake,
my_own_validator_config,
da_staked_committee_size: self.da_staked_committee_size,
da_non_staked_committee_size: self.da_non_staked_committee_size,
fixed_leader_for_gpuvid: self.fixed_leader_for_gpuvid,
next_view_timeout: self.next_view_timeout,
view_sync_timeout: self.view_sync_timeout,
timeout_ratio: self.timeout_ratio,
round_start_delay: self.round_start_delay,
start_delay: self.start_delay,
num_bootstrap: self.num_bootstrap,
builder_timeout: self.builder_timeout,
data_request_delay: self.data_request_delay,
builder_urls: self.builder_urls,
start_proposing_view: self.start_proposing_view,
stop_proposing_view: self.stop_proposing_view,
start_voting_view: self.start_voting_view,
stop_voting_view: self.stop_voting_view,
start_proposing_time: self.start_proposing_time,
stop_proposing_time: self.stop_proposing_time,
start_voting_time: self.start_voting_time,
stop_voting_time: self.stop_voting_time,
}
}
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicNetworkConfig {
rounds: usize,
indexed_da: bool,
transactions_per_round: usize,
manual_start_password: Option<String>,
num_bootrap: usize,
next_view_timeout: u64,
view_sync_timeout: Duration,
builder_timeout: Duration,
data_request_delay: Duration,
node_index: u64,
seed: [u8; 32],
transaction_size: usize,
start_delay_seconds: u64,
key_type_name: String,
libp2p_config: Option<Libp2pConfig>,
config: PublicHotShotConfig,
cdn_marshal_address: Option<String>,
combined_network_config: Option<CombinedNetworkConfig>,
commit_sha: String,
builder: BuilderType,
random_builder: Option<RandomBuilderConfig>,
}

impl From<NetworkConfig<PubKey>> for PublicNetworkConfig {
fn from(cfg: NetworkConfig<PubKey>) -> Self {
Self {
rounds: cfg.rounds,
indexed_da: cfg.indexed_da,
transactions_per_round: cfg.transactions_per_round,
manual_start_password: cfg.manual_start_password,
num_bootrap: cfg.num_bootrap,
next_view_timeout: cfg.next_view_timeout,
view_sync_timeout: cfg.view_sync_timeout,
builder_timeout: cfg.builder_timeout,
data_request_delay: cfg.data_request_delay,
node_index: cfg.node_index,
seed: cfg.seed,
transaction_size: cfg.transaction_size,
start_delay_seconds: cfg.start_delay_seconds,
key_type_name: cfg.key_type_name,
libp2p_config: cfg.libp2p_config,
config: cfg.config.into(),
cdn_marshal_address: cfg.cdn_marshal_address,
combined_network_config: cfg.combined_network_config,
commit_sha: cfg.commit_sha,
builder: cfg.builder,
random_builder: cfg.random_builder,
}
}
}

impl PublicNetworkConfig {
pub fn into_network_config(
self,
my_own_validator_config: ValidatorConfig<PubKey>,
) -> anyhow::Result<NetworkConfig<PubKey>> {
let node_index = self
.config
.known_nodes_with_stake
.iter()
.position(|peer| peer.stake_table_entry.stake_key == my_own_validator_config.public_key)
.context(format!(
"the node {} is not in the stake table",
my_own_validator_config.public_key
))? as u64;

Ok(NetworkConfig {
rounds: self.rounds,
indexed_da: self.indexed_da,
transactions_per_round: self.transactions_per_round,
manual_start_password: self.manual_start_password,
num_bootrap: self.num_bootrap,
next_view_timeout: self.next_view_timeout,
view_sync_timeout: self.view_sync_timeout,
builder_timeout: self.builder_timeout,
data_request_delay: self.data_request_delay,
node_index,
seed: self.seed,
transaction_size: self.transaction_size,
start_delay_seconds: self.start_delay_seconds,
key_type_name: self.key_type_name,
libp2p_config: self.libp2p_config,
config: self.config.into_hotshot_config(my_own_validator_config),
cdn_marshal_address: self.cdn_marshal_address,
combined_network_config: self.combined_network_config,
commit_sha: self.commit_sha,
builder: self.builder,
random_builder: self.random_builder,
})
}
}

#[cfg(test)]
pub(crate) mod testing {
use super::{super::Options, *};
Expand Down
Loading

0 comments on commit 94eaec3

Please sign in to comment.