Skip to content

Commit

Permalink
move public config structs to types crate
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed Mar 4, 2025
1 parent 4771ff5 commit f36dc48
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 271 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ surf-disco = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
vbs = { workspace = true }
serde_json = { workspace = true }
12 changes: 5 additions & 7 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use data_source::{CatchupDataSource, StakeTableDataSource, SubmitDataSource};
use derivative::Derivative;
use espresso_types::{
retain_accounts, v0::traits::SequencerPersistence, v0_99::ChainConfig, AccountQueryData,
BlockMerkleTree, FeeAccount, FeeAccountProof, FeeMerkleTree, NodeState, PubKey, Transaction,
ValidatedState,
BlockMerkleTree, FeeAccount, FeeAccountProof, FeeMerkleTree, NodeState, PubKey,
PublicNetworkConfig, Transaction, ValidatedState,
};
use futures::{
future::{BoxFuture, Future, FutureExt},
Expand Down Expand Up @@ -36,9 +36,7 @@ use jf_merkle_tree::MerkleTreeScheme;
use std::pin::Pin;
use std::sync::Arc;

use self::data_source::{
HotShotConfigDataSource, NodeStateDataSource, PublicNetworkConfig, StateSignatureDataSource,
};
use self::data_source::{HotShotConfigDataSource, NodeStateDataSource, StateSignatureDataSource};
use crate::{
catchup::CatchupStorage, context::Consensus, state_signature::StateSigner, SeqTypes,
SequencerApiVersion, SequencerContext,
Expand Down Expand Up @@ -1564,6 +1562,7 @@ mod test {
use std::{collections::BTreeMap, time::Duration};
use tokio::time::sleep;

use espresso_types::PublicHotShotConfig;
use espresso_types::{
traits::NullEventConsumer,
v0_1::{UpgradeMode, ViewBasedUpgrade},
Expand Down Expand Up @@ -1599,8 +1598,7 @@ mod test {
use vbs::version::{StaticVersion, StaticVersionType, Version};

use self::{
data_source::{testing::TestableSequencerDataSource, PublicHotShotConfig},
options::HotshotEvents,
data_source::testing::TestableSequencerDataSource, options::HotshotEvents,
sql::DataSource as SqlDataSource,
};
use super::*;
Expand Down
256 changes: 3 additions & 253 deletions sequencer/src/api/data_source.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::{num::NonZeroUsize, time::Duration};

use anyhow::Context;
use async_trait::async_trait;
use committable::Commitment;
use espresso_types::PublicNetworkConfig;
use espresso_types::{
v0::traits::{PersistenceOptions, SequencerPersistence},
v0_99::ChainConfig,
Expand All @@ -16,20 +15,14 @@ use hotshot_query_service::{
node::NodeDataSource,
status::StatusDataSource,
};
use hotshot_types::traits::node_implementation::NodeType;
use hotshot_types::{
data::ViewNumber,
light_client::StateSignatureRequestBody,
network::NetworkConfig,
traits::{network::ConnectedNetwork, node_implementation::Versions},
HotShotConfig, PeerConfig, ValidatorConfig,
};
use hotshot_types::{
network::{BuilderType, CombinedNetworkConfig, Libp2pConfig, RandomBuilderConfig},
traits::node_implementation::NodeType,
PeerConfig,
};
use serde::{Deserialize, Serialize};
use tide_disco::Url;
use vec1::Vec1;

use super::{
fs,
Expand Down Expand Up @@ -186,249 +179,6 @@ pub(crate) trait CatchupDataSource: Sync {
) -> impl Send + Future<Output = anyhow::Result<ChainConfig>>;
}

/// This struct defines the public Hotshot validator configuration.
/// Private key and state key pairs are excluded for security reasons.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PublicValidatorConfig {
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 {
fn from(v: ValidatorConfig<PubKey>) -> Self {
let ValidatorConfig::<PubKey> {
public_key,
private_key: _,
stake_value,
state_key_pair,
is_da,
} = v;

let state_public_key = state_key_pair.ver_key();

Self {
public_key,
stake_value,
is_da,
state_public_key: state_public_key.to_string(),
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(Clone, Debug, Deserialize, Serialize)]
pub struct PublicHotShotConfig {
start_threshold: (u64, u64),
num_nodes_with_stake: NonZeroUsize,
known_nodes_with_stake: Vec<PeerConfig<PubKey>>,
known_da_nodes: Vec<PeerConfig<PubKey>>,
da_staked_committee_size: usize,
fixed_leader_for_gpuvid: usize,
next_view_timeout: u64,
view_sync_timeout: Duration,
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,
epoch_height: u64,
epoch_start_block: u64,
}

impl From<HotShotConfig<PubKey>> for PublicHotShotConfig {
fn from(v: HotShotConfig<PubKey>) -> Self {
// Destructure all fields from HotShotConfig to return an error
// if new fields are added to HotShotConfig. This makes sure that we handle
// all fields appropriately and do not miss any updates.
let HotShotConfig::<PubKey> {
start_threshold,
num_nodes_with_stake,
known_nodes_with_stake,
known_da_nodes,
da_staked_committee_size,
fixed_leader_for_gpuvid,
next_view_timeout,
view_sync_timeout,
num_bootstrap,
builder_timeout,
data_request_delay,
builder_urls,
start_proposing_view,
stop_proposing_view,
start_voting_view,
stop_voting_view,
start_proposing_time,
stop_proposing_time,
start_voting_time,
stop_voting_time,
epoch_height,
epoch_start_block,
} = v;

Self {
start_threshold,
num_nodes_with_stake,
known_nodes_with_stake,
known_da_nodes,
da_staked_committee_size,
fixed_leader_for_gpuvid,
next_view_timeout,
view_sync_timeout,
num_bootstrap,
builder_timeout,
data_request_delay,
builder_urls,
start_proposing_view,
stop_proposing_view,
start_voting_view,
stop_voting_view,
start_proposing_time,
stop_proposing_time,
start_voting_time,
stop_voting_time,
epoch_height,
epoch_start_block,
}
}
}

impl PublicHotShotConfig {
pub fn into_hotshot_config(self) -> HotShotConfig<PubKey> {
HotShotConfig {
start_threshold: self.start_threshold,
num_nodes_with_stake: self.num_nodes_with_stake,
known_nodes_with_stake: self.known_nodes_with_stake,
known_da_nodes: self.known_da_nodes,
da_staked_committee_size: self.da_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,
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,
epoch_height: self.epoch_height,
epoch_start_block: self.epoch_start_block,
}
}
}

#[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,
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: Some("*****".into()),
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,
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,
key_type_name: self.key_type_name,
libp2p_config: self.libp2p_config,
config: self.config.into_hotshot_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,
public_keys: Vec::new(),
})
}
}

#[cfg(any(test, feature = "testing"))]
pub mod testing {
use super::{super::Options, *};
Expand Down
7 changes: 3 additions & 4 deletions sequencer/src/catchup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use async_trait::async_trait;
use committable::Commitment;
use committable::Committable;
use espresso_types::traits::SequencerPersistence;
use espresso_types::PublicNetworkConfig;
use espresso_types::{
v0::traits::StateCatchup, v0_99::ChainConfig, BackoffParams, BlockMerkleTree, FeeAccount,
FeeAccountProof, FeeMerkleCommitment, FeeMerkleTree, Leaf2, NodeState,
Expand All @@ -31,10 +32,8 @@ use tokio::time::timeout;
use url::Url;
use vbs::version::StaticVersionType;

use crate::{
api::{data_source::PublicNetworkConfig, BlocksFrontier},
PubKey,
};
use crate::api::BlocksFrontier;
use crate::PubKey;

// This newtype is probably not worth having. It's only used to be able to log
// URLs before doing requests.
Expand Down
1 change: 1 addition & 0 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ tower-service = { version = "0.3", default-features = false }
tracing = { workspace = true }
url = { workspace = true }
vbs = { workspace = true }
vec1 = { workspace = true }

[dev-dependencies]
espresso-types = { path = ".", features = [ "testing" ] }
Expand Down
3 changes: 3 additions & 0 deletions types/src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ reexport_unchanged_types!(
TimeBasedUpgrade,
ViewBasedUpgrade,
BlockSize,
PublicHotShotConfig,
PublicNetworkConfig,
PublicValidatorConfig
);

pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
Expand Down
Loading

0 comments on commit f36dc48

Please sign in to comment.