Skip to content

Commit 285f609

Browse files
authored
Merge pull request #5 from ABlockOfficial/enable_domain_resolution
Enabling domain resolution on Raft addresses
2 parents 4de3d09 + 1ca1a45 commit 285f609

16 files changed

+530
-144
lines changed

Cargo.lock

Lines changed: 180 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ tracing = "0.1.13"
4141
tracing-subscriber = "0.2.3"
4242
tracing-futures = "0.2.3"
4343
warp = { version = "0.3.1", features = ["tls"] }
44+
url = "2.4.1"
45+
trust-dns-resolver = "0.23.2"
4446

4547
[features]
4648
mock = []

src/active_raft.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::configurations::NodeSpec;
21
use crate::db_utils::{SimpleDb, SimpleDbError};
32
use crate::raft::{
43
CommitReceiver, RaftCmd, RaftCmdSender, RaftCommit, RaftCommitData, RaftData,
@@ -39,7 +38,7 @@ impl ActiveRaft {
3938
/// Create ActiveRaft, need to spawn the raft loop to use raft.
4039
pub fn new(
4140
node_idx: usize,
42-
node_specs: &[NodeSpec],
41+
node_specs: &[SocketAddr],
4342
use_raft: bool,
4443
tick_timeout_duration: Duration,
4544
raft_db: SimpleDb,
@@ -50,7 +49,7 @@ impl ActiveRaft {
5049
let peer_addr_vec: Vec<(u64, SocketAddr)> = peers
5150
.iter()
5251
.zip(node_specs.iter())
53-
.map(|(idx, spec)| (*idx, spec.address))
52+
.map(|(idx, spec)| (*idx, spec.clone()))
5453
.filter(|(idx, _)| use_raft || *idx == peer_id)
5554
.collect();
5655

src/bin/node/compute.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ fn load_settings(matches: &clap::ArgMatches) -> config::Config {
209209
.unwrap();
210210
settings.set_default("compute_api_port", 3002).unwrap();
211211
settings.set_default("compute_api_use_tls", true).unwrap();
212+
212213
settings.set_default("jurisdiction", "US").unwrap();
213214
settings.set_default("compute_node_idx", 0).unwrap();
214215
settings.set_default("compute_raft", 0).unwrap();
@@ -229,6 +230,7 @@ fn load_settings(matches: &clap::ArgMatches) -> config::Config {
229230
settings
230231
.merge(config::File::with_name(setting_file))
231232
.unwrap();
233+
232234
settings
233235
.merge(config::File::with_name(intial_block_setting_file))
234236
.unwrap();

src/bin/node_settings_local_raft_1.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ address = "127.0.0.1:12340"
4040
[[user_nodes]]
4141
address = "127.0.0.1:12360"
4242

43-
[[user_nodes]]
44-
address = "127.0.0.1:12361"
43+
#[[user_nodes]]
44+
#"address"="127.0.0.1:12361"

src/compute.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::raft::RaftCommit;
1616
use crate::threaded_call::{ThreadedCallChannel, ThreadedCallSender};
1717
use crate::tracked_utxo::TrackedUtxoSet;
1818
use crate::utils::{
19-
apply_mining_tx, check_druid_participants, create_item_asset_tx_from_sig,
19+
apply_mining_tx, check_druid_participants, create_item_asset_tx_from_sig, create_socket_addr,
2020
format_parition_pow_address, generate_pow_random_num, to_api_keys, to_route_pow_infos,
2121
validate_pow_block, validate_pow_for_address, ApiKeys, LocalEvent, LocalEventChannel,
2222
LocalEventSender, ResponseResult, RoutesPoWInfo, StringError,
@@ -175,16 +175,26 @@ impl ComputeNode {
175175
/// * `config` - ComputeNodeConfig for the current compute node containing compute nodes and storage nodes
176176
/// * `extra` - additional parameter for construction
177177
pub async fn new(config: ComputeNodeConfig, mut extra: ExtraNodeParams) -> Result<Self> {
178-
let addr = config
178+
let raw_addr = config
179179
.compute_nodes
180180
.get(config.compute_node_idx)
181-
.ok_or(ComputeError::ConfigError("Invalid compute index"))?
182-
.address;
183-
let storage_addr = config
181+
.ok_or(ComputeError::ConfigError("Invalid compute index"))?;
182+
let addr = create_socket_addr(&raw_addr.address).await.or_else(|_| {
183+
Err(ComputeError::ConfigError(
184+
"Invalid compute node address in config file",
185+
))
186+
})?;
187+
188+
let raw_storage_addr = config
184189
.storage_nodes
185190
.get(config.compute_node_idx)
186-
.ok_or(ComputeError::ConfigError("Invalid storage index"))?
187-
.address;
191+
.ok_or(ComputeError::ConfigError("Invalid storage index"))?;
192+
let storage_addr = create_socket_addr(&raw_storage_addr.address).await.or_else(|_| {
193+
Err(ComputeError::ConfigError(
194+
"Invalid storage node address in config file",
195+
))
196+
})?;
197+
188198
let tcp_tls_config = TcpTlsConfig::from_tls_spec(addr, &config.tls_config)?;
189199
let api_addr = SocketAddr::new(addr.ip(), config.compute_api_port);
190200
let api_tls_info = config

src/compute_raft.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::raft_util::{RaftContextKey, RaftInFlightProposals};
1212
use crate::tracked_utxo::TrackedUtxoSet;
1313
use crate::unicorn::{UnicornFixedParam, UnicornInfo};
1414
use crate::utils::{
15-
calculate_reward, get_total_coinbase_tokens, make_utxo_set_from_seed, BackupCheck,
16-
UtxoReAlignCheck,
15+
calculate_reward, create_socket_addr_for_list, get_total_coinbase_tokens,
16+
make_utxo_set_from_seed, BackupCheck, UtxoReAlignCheck,
1717
};
1818
use a_block_chain::crypto::sha3_256;
1919
use a_block_chain::primitives::asset::TokenAmount;
@@ -239,9 +239,15 @@ impl ComputeRaft {
239239
if config.backup_restore.unwrap_or(false) {
240240
db_utils::restore_file_backup(config.compute_db_mode, &DB_SPEC, None).unwrap();
241241
}
242+
let raw_node_ips = config
243+
.compute_nodes
244+
.clone()
245+
.into_iter()
246+
.map(|v| v.address.clone())
247+
.collect::<Vec<String>>();
242248
let raft_active = ActiveRaft::new(
243249
config.compute_node_idx,
244-
&config.compute_nodes,
250+
&create_socket_addr_for_list(&raw_node_ips).await.unwrap_or_default(),
245251
use_raft,
246252
Duration::from_millis(config.compute_raft_tick_timeout as u64),
247253
db_utils::new_db(config.compute_db_mode, &DB_SPEC, raft_db, None),
@@ -1593,7 +1599,7 @@ fn take_first_n<K: Clone + Ord, V>(n: usize, from: &mut BTreeMap<K, V>) -> BTree
15931599
mod test {
15941600
use super::*;
15951601
use crate::configurations::{DbMode, NodeSpec, TxOutSpec};
1596-
use crate::utils::{create_valid_transaction, get_test_common_unicorn};
1602+
use crate::utils::{create_socket_addr, create_valid_transaction, get_test_common_unicorn};
15971603
use a_block_chain::crypto::sign_ed25519 as sign;
15981604
use a_block_chain::primitives::asset::TokenAmount;
15991605
use rug::Integer;
@@ -1881,9 +1887,7 @@ mod test {
18811887
}
18821888

18831889
async fn new_test_node(seed_utxo: &[&str]) -> ComputeRaft {
1884-
let compute_node = NodeSpec {
1885-
address: "0.0.0.0:0".parse().unwrap(),
1886-
};
1890+
let compute_node = create_socket_addr("0.0.0.0").await.unwrap();
18871891
let tx_out = TxOutSpec {
18881892
public_key: "5371832122a8e804fa3520ec6861c3fa554a7f6fb617e6f0768452090207e07c"
18891893
.to_owned(),
@@ -1895,7 +1899,9 @@ mod test {
18951899
tls_config: Default::default(),
18961900
api_keys: Default::default(),
18971901
compute_unicorn_fixed_param: get_test_common_unicorn(),
1898-
compute_nodes: vec![compute_node],
1902+
compute_nodes: vec![NodeSpec {
1903+
address: compute_node.to_string(),
1904+
}],
18991905
storage_nodes: vec![],
19001906
user_nodes: vec![],
19011907
compute_raft: 0,

src/configurations.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// use crate::comms_handler::Node;
12
use crate::compute_raft::MinerWhitelist;
23
use crate::db_utils::{CustomDbSpec, SimpleDb};
34
use crate::wallet::WalletDb;
@@ -9,12 +10,6 @@ use std::net::SocketAddr;
910

1011
pub type UtxoSetSpec = BTreeMap<String, Vec<TxOutSpec>>;
1112

12-
/// Configuration info for a node
13-
#[derive(Debug, Clone, Copy, Deserialize)]
14-
pub struct NodeSpec {
15-
pub address: SocketAddr,
16-
}
17-
1813
/// Configuration info for TLS
1914
#[derive(Default, Clone, Deserialize)]
2015
pub struct TlsSpec {
@@ -95,6 +90,12 @@ pub enum DbMode {
9590
InMemory,
9691
}
9792

93+
/// Configuration info for a node
94+
#[derive(Debug, Clone, Deserialize)]
95+
pub struct NodeSpec {
96+
pub address: String,
97+
}
98+
9899
/// Configuration option for a compute node
99100
#[derive(Debug, Clone, Deserialize)]
100101
pub struct ComputeNodeConfig {
@@ -204,7 +205,7 @@ pub struct StorageNodeConfig {
204205
#[derive(Debug, Clone, Deserialize)]
205206
pub struct MinerNodeConfig {
206207
/// Socket Address of this miner node
207-
pub miner_address: SocketAddr,
208+
pub miner_address: String,
208209
/// Use specific database
209210
pub miner_db_mode: DbMode,
210211
/// Configuration for handling TLS
@@ -239,7 +240,7 @@ pub struct MinerNodeConfig {
239240
#[derive(Debug, Clone, Deserialize)]
240241
pub struct UserNodeConfig {
241242
/// Socket Address of this User node
242-
pub user_address: SocketAddr,
243+
pub user_address: String,
243244
/// Use specific database
244245
pub user_db_mode: DbMode,
245246
/// Configuration for handling TLS
@@ -287,9 +288,9 @@ pub struct PreLaunchNodeConfig {
287288
/// Use specific database
288289
pub storage_db_mode: DbMode,
289290
/// All compute nodes addresses
290-
pub compute_nodes: Vec<NodeSpec>,
291+
pub compute_nodes: Vec<String>,
291292
/// All storage nodes addresses: only use first
292-
pub storage_nodes: Vec<NodeSpec>,
293+
pub storage_nodes: Vec<String>,
293294
/// Limit for the number of peers this node can have
294295
pub peer_limit: usize,
295296
}

src/miner.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::interfaces::{
77
use crate::threaded_call::{ThreadedCallChannel, ThreadedCallSender};
88
use crate::transactor::Transactor;
99
use crate::utils::{
10-
self, apply_mining_tx, construct_coinbase_tx, format_parition_pow_address,
10+
self, apply_mining_tx, construct_coinbase_tx, create_socket_addr, format_parition_pow_address,
1111
generate_pow_for_block, get_paiments_for_wallet, get_paiments_for_wallet_from_utxo,
1212
to_api_keys, to_route_pow_infos, try_send_to_ui, ApiKeys, DeserializedBlockchainItem,
1313
LocalEvent, LocalEventChannel, LocalEventSender, ResponseResult, RoutesPoWInfo,
@@ -176,11 +176,15 @@ impl MinerNode {
176176
/// * `extra` - additional parameter for construction
177177
pub async fn new(config: MinerNodeConfig, mut extra: ExtraNodeParams) -> Result<MinerNode> {
178178
let addr = config.miner_address;
179-
let compute_addr = config
179+
let raw_compute_addr = config
180180
.compute_nodes
181181
.get(config.miner_compute_node_idx)
182-
.ok_or(MinerError::ConfigError("Invalid compute index"))?
183-
.address;
182+
.ok_or(MinerError::ConfigError("Invalid compute index"))?;
183+
let compute_addr = create_socket_addr(&raw_compute_addr.address).await.or_else(|_| {
184+
Err(MinerError::ConfigError(
185+
"Invalid compute node address in config file",
186+
))
187+
})?;
184188

185189
// Restore old keys if backup is present
186190
if config.backup_restore.unwrap_or(false) {
@@ -194,8 +198,9 @@ impl MinerNode {
194198
extra.custom_wallet_spec,
195199
)?;
196200
let disable_tcp_listener = extra.disable_tcp_listener;
197-
let tcp_tls_config = TcpTlsConfig::from_tls_spec(addr, &config.tls_config)?;
198-
let api_addr = SocketAddr::new(addr.ip(), config.miner_api_port);
201+
let tls_addr = create_socket_addr(&addr).await.unwrap();
202+
let tcp_tls_config = TcpTlsConfig::from_tls_spec(tls_addr, &config.tls_config)?;
203+
let api_addr = SocketAddr::new(tls_addr.ip(), config.miner_api_port);
199204
let api_tls_info = config
200205
.miner_api_use_tls
201206
.then(|| tcp_tls_config.clone_private_info());

src/pre_launch.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use crate::comms_handler::{CommsError, Event, Node, TcpTlsConfig};
22
use crate::configurations::{
3-
DbMode, ExtraNodeParams, NodeSpec, PreLaunchNodeConfig, PreLaunchNodeType, TlsSpec,
3+
DbMode, ExtraNodeParams, PreLaunchNodeConfig, PreLaunchNodeType, TlsSpec,
44
};
55
use crate::db_utils::{self, SimpleDb, SimpleDbSpec};
66
use crate::interfaces::{DbItem, NodeType, PreLaunchRequest, Response};
77
use crate::raft_store::{get_presistent_committed, CommittedIndex};
8-
use crate::utils::{LocalEvent, LocalEventChannel, LocalEventSender, ResponseResult};
8+
use crate::utils::{
9+
create_socket_addr_for_list, LocalEvent, LocalEventChannel, LocalEventSender, ResponseResult,
10+
};
911
use bincode::deserialize;
1012
use bytes::Bytes;
1113
use std::{collections::BTreeSet, error::Error, fmt, future::Future, net::SocketAddr};
@@ -74,7 +76,7 @@ struct PreLaunchNodeConfigSelected {
7476
/// Configuration for handling TLS
7577
pub tls_config: TlsSpec,
7678
/// All nodes addresses
77-
pub pre_launch_nodes: Vec<NodeSpec>,
79+
pub pre_launch_nodes: Vec<SocketAddr>,
7880
/// Db spec
7981
pub db_spec: SimpleDbSpec,
8082
/// Raft db spec
@@ -84,13 +86,14 @@ struct PreLaunchNodeConfigSelected {
8486
}
8587

8688
impl PreLaunchNodeConfigSelected {
87-
fn new(config: PreLaunchNodeConfig) -> Self {
89+
async fn new(config: PreLaunchNodeConfig) -> Self {
8890
match config.node_type {
8991
PreLaunchNodeType::Compute => Self {
9092
pre_launch_node_idx: config.compute_node_idx,
9193
pre_launch_db_mode: config.compute_db_mode,
9294
tls_config: config.tls_config,
93-
pre_launch_nodes: config.compute_nodes,
95+
pre_launch_nodes: create_socket_addr_for_list(&config.compute_nodes)
96+
.await.unwrap_or_default(),
9497
db_spec: crate::compute::DB_SPEC,
9598
raft_db_spec: crate::compute_raft::DB_SPEC,
9699
peer_limit: config.peer_limit,
@@ -99,7 +102,8 @@ impl PreLaunchNodeConfigSelected {
99102
pre_launch_node_idx: config.storage_node_idx,
100103
pre_launch_db_mode: config.storage_db_mode,
101104
tls_config: config.tls_config,
102-
pre_launch_nodes: config.storage_nodes,
105+
pre_launch_nodes: create_socket_addr_for_list(&config.storage_nodes)
106+
.await.unwrap_or_default(),
103107
db_spec: crate::storage::DB_SPEC,
104108
raft_db_spec: crate::storage_raft::DB_SPEC,
105109
peer_limit: config.peer_limit,
@@ -131,13 +135,13 @@ impl PreLaunchNode {
131135
config: PreLaunchNodeConfig,
132136
mut extra: ExtraNodeParams,
133137
) -> Result<PreLaunchNode> {
134-
let config = PreLaunchNodeConfigSelected::new(config);
138+
let config = PreLaunchNodeConfigSelected::new(config).await;
135139
let addr = config
136140
.pre_launch_nodes
137141
.get(config.pre_launch_node_idx)
138-
.ok_or(PreLaunchError::ConfigError("Invalid pre-launch index"))?
139-
.address;
140-
let tcp_tls_config = TcpTlsConfig::from_tls_spec(addr, &config.tls_config)?;
142+
.ok_or(PreLaunchError::ConfigError("Invalid pre-launch index"))?;
143+
144+
let tcp_tls_config = TcpTlsConfig::from_tls_spec(addr.clone(), &config.tls_config)?;
141145

142146
let node = Node::new(
143147
&tcp_tls_config,
@@ -155,9 +159,16 @@ impl PreLaunchNode {
155159
db_utils::new_db(config.pre_launch_db_mode, spec, extra.raft_db.take(), None)
156160
};
157161

158-
let pre_launch_nodes = config.pre_launch_nodes.iter().map(|s| s.address);
159-
let shutdown_group: BTreeSet<SocketAddr> = pre_launch_nodes.clone().collect();
160-
let pre_launch_nodes: Vec<_> = pre_launch_nodes.filter(|a| *a != addr).collect();
162+
let pre_launch_nodes = config.pre_launch_nodes.iter().map(|s| s);
163+
let shutdown_group: BTreeSet<SocketAddr> = pre_launch_nodes
164+
.clone()
165+
.into_iter()
166+
.map(|v| v.clone())
167+
.collect();
168+
let pre_launch_nodes: Vec<_> = pre_launch_nodes
169+
.filter(|a| *a != addr)
170+
.map(|v| v.clone())
171+
.collect();
161172

162173
let raft_db_send = if config.pre_launch_node_idx == 0 {
163174
Some(PreLaunchRequest::SendDbItems {

0 commit comments

Comments
 (0)