Skip to content

Commit

Permalink
skip validator config private key
Browse files Browse the repository at this point in the history
  • Loading branch information
imabdulbasit committed May 17, 2024
1 parent 90d3b28 commit a4d4be5
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 14 deletions.
8 changes: 4 additions & 4 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use self::data_source::{HotShotConfigDataSource, StateSignatureDataSource};
use self::data_source::{HotShotConfigDataSource, MyHotShotConfig, StateSignatureDataSource};
use crate::{
network,
persistence::SequencerPersistence,
state::{BlockMerkleTree, FeeAccountProof},
state_signature::StateSigner,
Node, NodeState, PubKey, SeqTypes, SequencerContext, Transaction,
Node, NodeState, SeqTypes, SequencerContext, Transaction,
};
use anyhow::Context;
use async_once_cell::Lazy;
Expand All @@ -20,7 +20,7 @@ use futures::{
use hotshot::types::{Event, SystemContextHandle};
use hotshot_events_service::events_source::{BuilderEvent, EventsSource, EventsStreamer};
use hotshot_query_service::data_source::ExtensibleDataSource;
use hotshot_types::{data::ViewNumber, light_client::StateSignatureRequestBody, HotShotConfig};
use hotshot_types::{data::ViewNumber, light_client::StateSignatureRequestBody};
use jf_merkle_tree::MerkleTreeScheme;
use serde::{Deserialize, Serialize};
use std::pin::Pin;
Expand Down Expand Up @@ -246,7 +246,7 @@ impl<
P: SequencerPersistence,
> HotShotConfigDataSource for StorageState<N, P, D, Ver>
{
async fn get_config(&self) -> anyhow::Result<Option<HotShotConfig<PubKey>>> {
async fn get_config(&self) -> anyhow::Result<Option<MyHotShotConfig>> {
self.inner().get_config().await
}
}
Expand Down
75 changes: 71 additions & 4 deletions sequencer/src/api/data_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ use hotshot_query_service::{
node::NodeDataSource,
status::StatusDataSource,
};
use hotshot_types::{data::ViewNumber, light_client::StateSignatureRequestBody, HotShotConfig};
use hotshot_types::{
data::ViewNumber, light_client::StateSignatureRequestBody, HotShotConfig, ValidatorConfig,
};
use serde::ser::SerializeStruct;
use serde::Serialize;
use tide_disco::Url;
use vbs::version::StaticVersionType;

Expand Down Expand Up @@ -85,9 +89,7 @@ pub(crate) trait SubmitDataSource<N: network::Type, P: SequencerPersistence> {
}

pub(crate) trait HotShotConfigDataSource {
fn get_config(
&self,
) -> impl Send + Future<Output = anyhow::Result<Option<HotShotConfig<PubKey>>>>;
fn get_config(&self) -> impl Send + Future<Output = anyhow::Result<Option<MyHotShotConfig>>>;
}

#[async_trait]
Expand Down Expand Up @@ -140,6 +142,71 @@ pub(crate) trait CatchupDataSource {

impl CatchupDataSource for MetricsDataSource {}

pub struct MyHotShotConfig(HotShotConfig<PubKey>);

impl MyHotShotConfig {
pub fn new(c: HotShotConfig<PubKey>) -> Self {
Self(c)
}
}
pub struct MyValidatorConfig<'a>(&'a ValidatorConfig<PubKey>);

impl<'a> Serialize for MyValidatorConfig<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("MyValidatorConfig", 3)?;

state.serialize_field("public_key", &self.0.public_key)?;
state.serialize_field("stake_value", &self.0.stake_value)?;
state.serialize_field("is_da", &self.0.is_da)?;

state.end()
}
}

impl Serialize for MyHotShotConfig {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let mut state = serializer.serialize_struct("HotShotConfig", 20)?;
let config = &self.0;
state.serialize_field("execution_type", &config.execution_type)?;
state.serialize_field("start_threshold", &config.start_threshold)?;
state.serialize_field("num_nodes_with_stake", &config.num_nodes_with_stake)?;
state.serialize_field("num_nodes_without_stake", &config.num_nodes_without_stake)?;
state.serialize_field("known_nodes_with_stake", &config.known_nodes_with_stake)?;
state.serialize_field("known_da_nodes", &config.known_da_nodes)?;
state.serialize_field(
"known_nodes_without_stake",
&config.known_nodes_without_stake,
)?;

let validator_confg = MyValidatorConfig(&config.my_own_validator_config);

state.serialize_field("my_own_validator_config", &validator_confg)?;
state.serialize_field("da_staked_committee_size", &config.da_staked_committee_size)?;
state.serialize_field(
"da_non_staked_committee_size",
&config.da_non_staked_committee_size,
)?;
state.serialize_field("fixed_leader_for_gpuvid", &config.fixed_leader_for_gpuvid)?;
state.serialize_field("next_view_timeout", &config.next_view_timeout)?;
state.serialize_field("view_sync_timeout", &config.view_sync_timeout)?;
state.serialize_field("timeout_ratio", &config.timeout_ratio)?;
state.serialize_field("round_start_delay", &config.round_start_delay)?;
state.serialize_field("start_delay", &config.start_delay)?;
state.serialize_field("num_bootstrap", &config.num_bootstrap)?;
state.serialize_field("builder_timeout", &config.builder_timeout)?;
state.serialize_field("data_request_delay", &config.data_request_delay)?;
state.serialize_field("builder_url", &config.builder_url)?;

state.end()
}
}

#[cfg(test)]
pub(crate) mod testing {
use super::super::Options;
Expand Down
12 changes: 7 additions & 5 deletions sequencer/src/api/sql.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use super::{
data_source::{CatchupDataSource, HotShotConfigDataSource, Provider, SequencerDataSource},
data_source::{
CatchupDataSource, HotShotConfigDataSource, MyHotShotConfig, Provider, SequencerDataSource,
},
AccountQueryData, BlocksFrontier,
};
use crate::{
persistence::{sql::Options, SequencerPersistence},
state::{BlockMerkleTree, FeeAccountProof, FeeMerkleTree},
PubKey, SeqTypes,
SeqTypes,
};
use anyhow::{bail, Context};
use async_trait::async_trait;
Expand All @@ -17,7 +19,7 @@ use hotshot_query_service::{
},
merklized_state::{MerklizedStateDataSource, Snapshot},
};
use hotshot_types::{data::ViewNumber, HotShotConfig};
use hotshot_types::data::ViewNumber;
use jf_merkle_tree::{prelude::MerkleNode, MerkleTreeScheme};

pub type DataSource = SqlDataSource<SeqTypes, Provider>;
Expand Down Expand Up @@ -97,11 +99,11 @@ impl CatchupDataSource for DataSource {
}

impl HotShotConfigDataSource for DataSource {
async fn get_config(&self) -> anyhow::Result<Option<HotShotConfig<PubKey>>> {
async fn get_config(&self) -> anyhow::Result<Option<MyHotShotConfig>> {
(*self.storage().await)
.load_config()
.await
.map(|res| res.map(|network_config| network_config.config))
.map(|res| res.map(|network_config| MyHotShotConfig::new(network_config.config)))
}
}

Expand Down
5 changes: 4 additions & 1 deletion sequencer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,16 @@ where
if let Some(catchup) = modules.catchup {
http_opt = http_opt.catchup(catchup);
}

if let Some(hotshot_events) = modules.hotshot_events {
http_opt = http_opt.hotshot_events(hotshot_events);
}
if let Some(explorer) = modules.explorer {
http_opt = http_opt.explorer(explorer);
}

if let Some(config) = modules.config {
http_opt = http_opt.config(config);
}
http_opt
.serve(
move |metrics| {
Expand Down
3 changes: 3 additions & 0 deletions sequencer/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ impl ModuleArgs {
SequencerModule::Status(m) => curr = m.add(&mut modules.status, &mut provided)?,
SequencerModule::State(m) => curr = m.add(&mut modules.state, &mut provided)?,
SequencerModule::Catchup(m) => curr = m.add(&mut modules.catchup, &mut provided)?,
SequencerModule::Config(m) => curr = m.add(&mut modules.config, &mut provided)?,
SequencerModule::HotshotEvents(m) => {
curr = m.add(&mut modules.hotshot_events, &mut provided)?
}
Expand Down Expand Up @@ -393,6 +394,7 @@ enum SequencerModule {
///
/// This module requires the http module to be started.
Catchup(Module<api::options::Catchup>),
Config(Module<api::options::Config>),
/// Run the merklized state API module.
///
/// This module requires the http and storage-sql modules to be started.
Expand All @@ -417,6 +419,7 @@ pub struct Modules {
pub status: Option<api::options::Status>,
pub state: Option<api::options::State>,
pub catchup: Option<api::options::Catchup>,
pub config: Option<api::options::Config>,
pub hotshot_events: Option<api::options::HotshotEvents>,
pub explorer: Option<api::options::Explorer>,
}

0 comments on commit a4d4be5

Please sign in to comment.