Skip to content

Commit

Permalink
Merge branch 'main' into jh/dev-node-debug-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe authored Jul 16, 2024
2 parents bd065bc + dbc04c1 commit 9a7de92
Show file tree
Hide file tree
Showing 10 changed files with 364 additions and 71 deletions.
1 change: 1 addition & 0 deletions builder/src/bin/permissioned-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ async fn main() -> anyhow::Result<()> {
private_staking_key: private_staking_key.clone(),
private_state_key,
state_peers: opt.state_peers,
config_peers: None,
catchup_backoff: Default::default(),
};

Expand Down
3 changes: 3 additions & 0 deletions scripts/build-docker-images
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ for ARCH in "amd64" "arm64"; do
done
done

mkdir -p ${WORKDIR}/docker/scripts
cp -v docker/scripts/sequencer-awssecretsmanager.sh ${WORKDIR}/docker/scripts

# Copy the dev-node launch script
mkdir -p ${WORKDIR}/scripts
cp -v scripts/launch-dev-node-with-postgres ${WORKDIR}/scripts
Expand Down
3 changes: 3 additions & 0 deletions scripts/build-docker-images-native
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ for binary in "orchestrator" "cdn-broker" "cdn-marshal" "cdn-whitelist" "sequenc
fi
done

mkdir -p ${WORKDIR}/docker/scripts
cp -v docker/scripts/sequencer-awssecretsmanager.sh ${WORKDIR}/docker/scripts

# Copy the dev-node launch script
mkdir -p ${WORKDIR}/scripts
cp -v scripts/launch-dev-node-with-postgres ${WORKDIR}/scripts
Expand Down
87 changes: 68 additions & 19 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 Expand Up @@ -1059,6 +1051,7 @@ mod test {
metrics::NoMetrics,
node_implementation::{ConsensusTime, NodeType},
},
ValidatorConfig,
};
use jf_merkle_tree::prelude::{MerkleProof, Sha3Node};
use portpicker::pick_unused_port;
Expand All @@ -1071,7 +1064,8 @@ mod test {
use vbs::version::Version;

use self::{
data_source::testing::TestableSequencerDataSource, sql::DataSource as SqlDataSource,
data_source::{testing::TestableSequencerDataSource, PublicHotShotConfig},
sql::DataSource as SqlDataSource,
};
use super::*;
use crate::{
Expand Down Expand Up @@ -1672,4 +1666,59 @@ mod test {
.unwrap();
assert_eq!(chain, new_chain);
}

#[async_std::test]
async fn test_fetch_config() {
setup_logging();
setup_backtrace();

let port = pick_unused_port().expect("No ports free");
let url: surf_disco::Url = format!("http://localhost:{port}").parse().unwrap();
let client: Client<ServerError, SequencerVersion> = Client::new(url.clone());

let options = Options::with_port(port).config(Default::default());
let anvil = Anvil::new().spawn();
let l1 = anvil.endpoint().parse().unwrap();
let network_config = TestConfigBuilder::default().l1_url(l1).build();
let config = TestNetworkConfigBuilder::default()
.api_config(options)
.network_config(network_config)
.build();
let network = TestNetwork::new(config).await;
client.connect(None).await;

// Fetch a network config from the API server. The first peer URL is bogus, to test the
// failure/retry case.
let peers = StatePeers::<SequencerVersion>::from_urls(
vec!["https://notarealnode.network".parse().unwrap(), url],
Default::default(),
);

// Fetch the config from node 1, a different node than the one running the service.
let validator = ValidatorConfig::generated_from_seed_indexed([0; 32], 1, 1, false);
let mut config = peers.fetch_config(validator.clone()).await;

// Check the node-specific information in the recovered config is correct.
assert_eq!(config.node_index, 1);
assert_eq!(
config.config.my_own_validator_config.public_key,
validator.public_key
);
assert_eq!(
config.config.my_own_validator_config.private_key,
validator.private_key
);

// Check the public information is also correct (with respect to the node that actually
// served the config, for public keys).
config.config.my_own_validator_config =
ValidatorConfig::generated_from_seed_indexed([0; 32], 0, 1, true);
pretty_assertions::assert_eq!(
serde_json::to_value(PublicHotShotConfig::from(config.config)).unwrap(),
serde_json::to_value(PublicHotShotConfig::from(
network.cfg.hotshot_config().clone()
))
.unwrap()
);
}
}
Loading

0 comments on commit 9a7de92

Please sign in to comment.