Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Cargo.lock

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

53 changes: 17 additions & 36 deletions pulsar/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use color_eyre::eyre::{eyre, Report, Result, WrapErr};
use derivative::Derivative;
use serde::{Deserialize, Serialize};
use strum_macros::EnumIter;
use subspace_sdk::chain_spec::create_chain_spec;
use subspace_sdk::farmer::Farmer;
use subspace_sdk::node::{DomainConfigBuilder, DsnBuilder, NetworkBuilder, Node, Role};
use subspace_sdk::{chain_spec, ByteSize, FarmDescription, PublicKey};
use subspace_sdk::node::{DomainConfigBuilder, Node};
use subspace_sdk::{ByteSize, FarmDescription, PublicKey};
use tracing::instrument;

use crate::utils::IntoEyre;
Expand Down Expand Up @@ -44,59 +45,39 @@ pub(crate) struct NodeConfig {
}

impl NodeConfig {
pub async fn build(self, chain: ChainConfig, is_verbose: bool) -> Result<Node> {
pub async fn build(self, chain: ChainConfig, _is_verbose: bool) -> Result<Node> {
let Self { directory, name, advanced: AdvancedNodeSettings { enable_domains, extra } } =
self;

let (mut node, chain_spec) = match chain {
let node = match chain {
ChainConfig::Gemini3h => {
let mut node = Node::gemini_3h()
.network(NetworkBuilder::gemini_3h().name(name))
.dsn(DsnBuilder::gemini_3h())
.sync_from_dsn(true)
.enable_subspace_block_relay(true);
let mut node = Node::gemini_3h(name, directory)?;
if enable_domains {
node = node.domain(Some(DomainConfigBuilder::gemini_3h().configuration()));
node = node.domain(Some(DomainConfigBuilder::gemini_3h().configuration()?));
}
let chain_spec = chain_spec::gemini_3h();
(node, chain_spec)
node
}
ChainConfig::Dev => {
let mut node = Node::dev();
let mut node = Node::dev(directory)?;
if enable_domains {
node = node.domain(Some(
DomainConfigBuilder::dev().role(Role::Authority).configuration(),
));
node = node.domain(Some(DomainConfigBuilder::dev().configuration()?));
}
let chain_spec = chain_spec::dev_config();
(node, chain_spec)
node
}
ChainConfig::DevNet => {
let mut node = Node::devnet()
.network(NetworkBuilder::devnet().name(name))
.dsn(DsnBuilder::devnet())
.sync_from_dsn(true)
.enable_subspace_block_relay(true);
let mut node = Node::devnet(name, directory)?;
if enable_domains {
node = node.domain(Some(DomainConfigBuilder::devnet().configuration()));
node = node.domain(Some(DomainConfigBuilder::devnet().configuration()?));
}
let chain_spec = chain_spec::devnet_config();
(node, chain_spec)
node
}
};

if is_verbose {
node = node.informant_enable_color(true);
}

node = node
.role(Role::Authority)
.impl_version(format!("{}-{}", env!("CARGO_PKG_VERSION"), env!("GIT_HASH")))
.impl_name("Subspace CLI".to_string());
let configuration = node.configuration()?;

crate::utils::apply_extra_options(&node.configuration(), extra)
crate::utils::apply_extra_options(&configuration, extra)
.context("Failed to deserialize node config")?
.build(directory, chain_spec)
.build(create_chain_spec)
.await
.into_eyre()
.wrap_err("Failed to build subspace node")
Expand Down
71 changes: 45 additions & 26 deletions sdk/dsn/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::HashSet;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::path::PathBuf;
use std::sync::{Arc, Weak};

Expand All @@ -14,6 +15,7 @@ use serde::{Deserialize, Serialize};
use subspace_farmer::piece_cache::PieceCache as FarmerPieceCache;
use subspace_farmer::utils::readers_and_pieces::ReadersAndPieces;
use subspace_farmer::KNOWN_PEERS_CACHE_SIZE;
use subspace_networking::libp2p::multiaddr::{Multiaddr as LibP2PMultiAddress, Protocol};
use subspace_networking::utils::strip_peer_id;
use subspace_networking::{
KademliaMode, KnownPeersManager, KnownPeersManagerConfig, PieceByIndexRequest,
Expand All @@ -31,10 +33,28 @@ use super::LocalRecordProvider;
#[derivative(Default)]
#[serde(transparent)]
pub struct ListenAddresses(
#[derivative(Default(
// TODO: get rid of it, once it won't be required by monorepo
value = "vec![\"/ip4/127.0.0.1/tcp/0\".parse().expect(\"Always valid\")]"
))]
#[derivative(Default(value = "vec![
LibP2PMultiAddress::from(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
.with(Protocol::Udp(30533))
.with(Protocol::QuicV1).into(),
LibP2PMultiAddress::from(IpAddr::V6(Ipv6Addr::UNSPECIFIED))
.with(Protocol::Udp(30533))
.with(Protocol::QuicV1).into(),
LibP2PMultiAddress::from(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
.with(Protocol::Tcp(30533)).into(),
LibP2PMultiAddress::from(IpAddr::V6(Ipv6Addr::UNSPECIFIED))
.with(Protocol::Tcp(30533)).into(),
LibP2PMultiAddress::from(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
.with(Protocol::Udp(30433))
.with(Protocol::QuicV1).into(),
LibP2PMultiAddress::from(IpAddr::V6(Ipv6Addr::UNSPECIFIED))
.with(Protocol::Udp(30433))
.with(Protocol::QuicV1).into(),
LibP2PMultiAddress::from(IpAddr::V4(Ipv4Addr::UNSPECIFIED))
.with(Protocol::Tcp(30433)).into(),
LibP2PMultiAddress::from(IpAddr::V6(Ipv6Addr::UNSPECIFIED))
.with(Protocol::Tcp(30433)).into()
]"))]
pub Vec<Multiaddr>,
);

Expand Down Expand Up @@ -81,25 +101,25 @@ pub struct PendingOutConnections(#[derivative(Default(value = "150"))] pub u32);
/// Node DSN builder
#[derive(Debug, Clone, Derivative, Builder, Deserialize, Serialize, PartialEq)]
#[derivative(Default)]
#[builder(pattern = "immutable", build_fn(private, name = "_build"), name = "DsnBuilder")]
#[builder(pattern = "immutable", build_fn(error = "sdk_utils::BuilderError"))]
#[non_exhaustive]
pub struct Dsn {
/// Listen on some address for other nodes
#[builder(default, setter(into))]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub listen_addresses: ListenAddresses,
pub listen_on: ListenAddresses,
/// Boot nodes
#[builder(default)]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub boot_nodes: Vec<MultiaddrWithPeerId>,
pub bootstrap_nodes: Vec<MultiaddrWithPeerId>,
/// Known external addresses
#[builder(setter(into), default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub external_addresses: Vec<Multiaddr>,
/// Reserved nodes
/// Reserved peers
#[builder(default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub reserved_nodes: Vec<Multiaddr>,
pub reserved_peers: Vec<Multiaddr>,
/// Determines whether we allow keeping non-global (private, shared,
/// loopback..) addresses in Kademlia DHT.
#[builder(default)]
Expand All @@ -121,30 +141,27 @@ pub struct Dsn {
#[builder(setter(into), default)]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub pending_out_connections: PendingOutConnections,
/// Defines whether we should run blocking Kademlia bootstrap() operation
/// before other requests.
#[builder(default = "false")]
#[serde(default, skip_serializing_if = "sdk_utils::is_default")]
pub disable_bootstrap_on_start: bool,
}

sdk_utils::generate_builder!(Dsn);

impl DsnBuilder {
/// Dev chain configuration
pub fn dev() -> Self {
Self::new().allow_non_global_addresses_in_dht(true)
Self::default().allow_non_global_addresses_in_dht(true).disable_bootstrap_on_start(true)
}

/// Gemini 3g configuration
pub fn gemini_3h() -> Self {
Self::new().listen_addresses(vec![
"/ip6/::/tcp/30433".parse().expect("hardcoded value is true"),
"/ip4/0.0.0.0/tcp/30433".parse().expect("hardcoded value is true"),
])
Self::default()
}

/// Gemini 3g configuration
pub fn devnet() -> Self {
Self::new().listen_addresses(vec![
"/ip6/::/tcp/30433".parse().expect("hardcoded value is true"),
"/ip4/0.0.0.0/tcp/30433".parse().expect("hardcoded value is true"),
])
Self::default()
}
}

Expand Down Expand Up @@ -225,20 +242,21 @@ impl Dsn {
tracing::debug!(genesis_hash = protocol_version, "Setting DSN protocol version...");

let Self {
listen_addresses,
reserved_nodes,
listen_on,
reserved_peers,
allow_non_global_addresses_in_dht,
in_connections: InConnections(max_established_incoming_connections),
out_connections: OutConnections(max_established_outgoing_connections),
pending_in_connections: PendingInConnections(max_pending_incoming_connections),
pending_out_connections: PendingOutConnections(max_pending_outgoing_connections),
boot_nodes,
bootstrap_nodes,
external_addresses,
disable_bootstrap_on_start,
} = self;

let bootstrap_nodes = boot_nodes.into_iter().map(Into::into).collect::<Vec<_>>();
let bootstrap_nodes = bootstrap_nodes.into_iter().map(Into::into).collect::<Vec<_>>();

let listen_on = listen_addresses.0.into_iter().map(Into::into).collect();
let listen_on = listen_on.0.into_iter().map(Into::into).collect();

let networking_parameters_registry = KnownPeersManager::new(KnownPeersManagerConfig {
path: Some(base_path.join("known_addresses.bin").into_boxed_path()),
Expand Down Expand Up @@ -284,14 +302,15 @@ impl Dsn {
}
}),
],
reserved_peers: reserved_nodes.into_iter().map(Into::into).collect(),
reserved_peers: reserved_peers.into_iter().map(Into::into).collect(),
max_established_incoming_connections,
max_established_outgoing_connections,
max_pending_incoming_connections,
max_pending_outgoing_connections,
bootstrap_addresses: bootstrap_nodes,
kademlia_mode: KademliaMode::Dynamic,
external_addresses: external_addresses.into_iter().map(Into::into).collect(),
disable_bootstrap_on_start,
..default_networking_config
};

Expand Down
6 changes: 5 additions & 1 deletion sdk/farmer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ mod builder {
/// Technical type which stores all
#[derive(Debug, Clone, Derivative, Builder, Serialize, Deserialize)]
#[derivative(Default)]
#[builder(pattern = "immutable", build_fn(private, name = "_build"), name = "Builder")]
#[builder(
pattern = "immutable",
build_fn(private, name = "_build", error = "sdk_utils::BuilderError"),
name = "Builder"
)]
#[non_exhaustive]
pub struct Config {
/// Number of farms that can be plotted concurrently, impacts RAM usage.
Expand Down
Loading