diff --git a/crates/aot/src/ledger/query.rs b/crates/aot/src/ledger/query.rs index 0850b826..81076f5f 100644 --- a/crates/aot/src/ledger/query.rs +++ b/crates/aot/src/ledger/query.rs @@ -1,4 +1,11 @@ -use std::{fs::File, io::Write, ops::Deref, path::PathBuf, sync::Arc}; +use std::{ + fs::File, + io::Write, + net::{IpAddr, SocketAddr}, + ops::Deref, + path::PathBuf, + sync::Arc, +}; use anyhow::Result; use axum::{ @@ -21,6 +28,10 @@ pub struct LedgerQuery { /// Port to listen on for incoming messages pub port: u16, + #[arg(long, default_value = "0.0.0.0")] + // IP address to bind to + pub bind: IpAddr, + #[arg(long)] /// When true, the POST /block endpoint will not be available pub readonly: bool, @@ -72,7 +83,7 @@ impl LedgerQuery { .route("/block", post(Self::add_block)) .with_state(Arc::new(state)); - let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", self.port)).await?; + let listener = tokio::net::TcpListener::bind(SocketAddr::new(self.bind, self.port)).await?; tracing::info!("listening on: {:?}", listener.local_addr().unwrap()); axum::serve(listener, app).await?; diff --git a/crates/snot/src/schema/nodes.rs b/crates/snot/src/schema/nodes.rs index 82217e53..52b2f609 100644 --- a/crates/snot/src/schema/nodes.rs +++ b/crates/snot/src/schema/nodes.rs @@ -48,9 +48,6 @@ pub struct Node { // TODO: turn this into an enum with options like `None`, `Additional(usize)`, // `Committee(usize)`, `Named(String)`, `Literal(String)` pub key: Option, - /// The storage ID to use when starting the node. - /// TODO: move this outside of the node. this is a setting for the swarm - pub storage: String, /// Height of ledger to inherit. /// /// * When null, a ledger is created when the node is started. diff --git a/crates/snot/src/testing.rs b/crates/snot/src/testing.rs index 87e6762b..f0a1b769 100644 --- a/crates/snot/src/testing.rs +++ b/crates/snot/src/testing.rs @@ -9,6 +9,7 @@ use tracing::{info, warn}; use crate::{ schema::{ nodes::{ExternalNode, Node}, + storage::FilenameString, ItemDocument, NodeTargets, }, state::GlobalState, @@ -16,6 +17,7 @@ use crate::{ #[derive(Debug, Clone)] pub struct Test { + pub storage_id: FilenameString, pub node_map: BiMap, pub initial_nodes: IndexMap, // TODO: GlobalStorage.storage should maybe be here instead @@ -57,7 +59,15 @@ impl Test { let mut state_lock = state.test.write().await; + let Some(storage_id) = documents.iter().find_map(|s| match s { + ItemDocument::Storage(storage) => Some(storage.id.clone()), + _ => None, + }) else { + bail!("no storage document found in test") + }; + let mut test = Test { + storage_id, node_map: Default::default(), initial_nodes: Default::default(), }; @@ -215,7 +225,16 @@ pub async fn initial_reconcile(state: &GlobalState) -> anyhow::Result<()> { { let test_lock = state.test.read().await; let test = test_lock.as_ref().unwrap(); - let storage_lock = state.storage.read().await; + + // get the numeric storage ID from the string storage ID + let storage_id = { + let storage_lock = state.storage.read().await; + match storage_lock.get_by_right(test.storage_id.as_str()) { + Some(id) => *id, + None => bail!("invalid storage ID specified for node"), + } + }; + let pool_lock = state.pool.read().await; // Lookup agent peers given a node key @@ -264,6 +283,13 @@ pub async fn initial_reconcile(state: &GlobalState) -> anyhow::Result<()> { // this can't really be cleverly optimized into // a single lookup at the moment because we don't treat @local // as a None namespace... + + // TODO: ensure @local is always parsed as None, then we can + // optimize each target in this to be a direct lookup + // instead of walking through each node + + // alternatively, use a more efficient data structure for + // storing node keys test.node_map .iter() .filter(|(k, _)| *k != key && target.matches(k)) @@ -275,11 +301,6 @@ pub async fn initial_reconcile(state: &GlobalState) -> anyhow::Result<()> { let TestNode::Internal(node) = node else { continue; }; - // get the numeric storage ID from the string storage ID - let storage_id = match storage_lock.get_by_right(&node.storage) { - Some(id) => *id, - None => bail!("invalid storage ID specified for node"), - }; // get the internal agent ID from the node key let Some(TestPeer::Internal(id)) = test.node_map.get_by_left(key) else { diff --git a/specs/test-4-validators.yaml b/specs/test-4-validators.yaml index e6b43f81..1f89de1b 100644 --- a/specs/test-4-validators.yaml +++ b/specs/test-4-validators.yaml @@ -26,22 +26,18 @@ nodes: height: 0 validators: [validator/*] peers: [] - storage: base validator/1: key: APrivateKey1zkp2RWGDcde3efb89rjhME1VYA8QMxcxep5DShNBR6n8Yjh height: 0 validators: [validator/*] peers: [] - storage: base validator/2: key: APrivateKey1zkp2GUmKbVsuc1NSj28pa1WTQuZaK5f1DQJAT6vPcHyWokG height: 0 validators: [validator/*] peers: [] - storage: base validator/3: key: APrivateKey1zkpBjpEgLo4arVUkQmcLdKQMiAKGaHAQVVwmF8HQby8vdYs height: 0 validators: [validator/*] peers: [] - storage: base