Skip to content

Commit

Permalink
Merge branch 'main' into extract_methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonPaulGithub authored Mar 21, 2024
2 parents e580030 + c0887b2 commit d839cee
Show file tree
Hide file tree
Showing 26 changed files with 1,114 additions and 687 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion sn_cli/src/subcommands/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn create_register(
let meta = XorName::from_content(name.as_bytes());
let perms = match public {
true => Permissions::new_anyone_can_write(),
false => Permissions::new_owner_only(),
false => Permissions::default(),
};
let (register, storage_cost, royalties_fees) = client
.create_and_pay_for_register(meta, &mut wallet_client, verify_store, perms)
Expand Down
10 changes: 5 additions & 5 deletions sn_client/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ impl Client {
/// xorname,
/// &mut wallet_client,
/// true,
/// Permissions::new_owner_only(),
/// Permissions::default(),
/// )
/// .await?;
/// # Ok(())
Expand All @@ -553,10 +553,10 @@ impl Client {
)
.await?;

debug!("{address:?} Created in theorryyyyy");
debug!("{address:?} Created in theory");
let reg_address = reg.address();
if verify_store {
debug!("WE SHOULD VERRRRIFYING");
debug!("We should verify stored at {address:?}");
let mut stored = self.verify_register_stored(*reg_address).await.is_ok();

while !stored {
Expand Down Expand Up @@ -1150,7 +1150,7 @@ fn merge_split_register_records(

// merge it with the others if they are valid
let register: SignedRegister = all_registers.into_iter().fold(one_valid_reg, |mut acc, r| {
if acc.verified_merge(r).is_err() {
if acc.verified_merge(&r).is_err() {
warn!("Skipping register that failed to merge. Entry found for {key:?}");
}
acc
Expand Down Expand Up @@ -1225,7 +1225,7 @@ mod tests {

// test with 2 valid records: should return the two merged
let mut expected_merge = signed_register1.clone();
expected_merge.merge(signed_register2)?;
expected_merge.merge(&signed_register2)?;
let map = HashMap::from_iter(vec![
(xorname1, (record1.clone(), peers1.clone())),
(xorname2, (record2, peers2.clone())),
Expand Down
6 changes: 3 additions & 3 deletions sn_client/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ClientRegister {
/// # }
/// ```
pub fn create(client: Client, meta: XorName) -> Self {
Self::create_register(client, meta, Permissions::new_owner_only())
Self::create_register(client, meta, Permissions::default())
}

/// Create a new Register locally with a specific address.
Expand All @@ -95,7 +95,7 @@ impl ClientRegister {
/// # }
/// ```
pub fn create_with_addr(client: Client, addr: RegisterAddress) -> Self {
let register = Register::new(addr.owner(), addr.meta(), Permissions::new_owner_only());
let register = Register::new(addr.owner(), addr.meta(), Permissions::default());
Self {
client,
register,
Expand Down Expand Up @@ -541,7 +541,7 @@ impl ClientRegister {
self.register.clone()
}
};
self.register.merge(remote_replica);
self.register.merge(&remote_replica)?;
self.push(verify_store).await?;

Ok((storage_cost, royalties_fees))
Expand Down
4 changes: 2 additions & 2 deletions sn_node/src/bin/safenode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ struct Opt {
local: bool,

#[cfg(feature = "open-metrics")]
/// Specify the port to start the OpenMetrics Server in.
/// Specify the port for the OpenMetrics server.
///
/// The special value `0` will cause the OS to assign a random port.
/// If not specified, a port will be selected at random.
#[clap(long, default_value_t = 0)]
metrics_server_port: u16,
}
Expand Down
2 changes: 1 addition & 1 deletion sn_node/src/put_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ impl Node {

// merge the two registers
let mut merged_register = local_register.clone();
merged_register.verified_merge(register.to_owned())?;
merged_register.verified_merge(register)?;
if merged_register == local_register {
trace!("Register with addr {reg_addr:?} is the same as the local version");
Ok(None)
Expand Down
7 changes: 1 addition & 6 deletions sn_node/tests/data_with_churn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,7 @@ fn create_registers_task(
sleep(delay).await;

match client
.create_and_pay_for_register(
meta,
&mut wallet_client,
true,
Permissions::new_owner_only(),
)
.create_and_pay_for_register(meta, &mut wallet_client, true, Permissions::default())
.await
{
Ok(_) => content
Expand Down
4 changes: 2 additions & 2 deletions sn_node/tests/nodes_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ mod tests {
register_addr,
&mut wallet_client,
false,
Permissions::new_owner_only(),
Permissions::default(),
)
.await?;
info!("Cost is {storage_cost:?}: {prev_rewards_balance:?}");
Expand Down Expand Up @@ -162,7 +162,7 @@ mod tests {
register_addr,
&mut wallet_client,
false,
Permissions::new_owner_only(),
Permissions::default(),
)
.await?;
info!("Random Register created, paid {storage_cost}/{royalties_fees}");
Expand Down
14 changes: 2 additions & 12 deletions sn_node/tests/storage_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,7 @@ async fn storage_payment_register_creation_succeeds() -> Result<()> {
.await?;

let (mut register, _cost, _royalties_fees) = client
.create_and_pay_for_register(
xor_name,
&mut wallet_client,
true,
Permissions::new_owner_only(),
)
.create_and_pay_for_register(xor_name, &mut wallet_client, true, Permissions::default())
.await?;

let retrieved_reg = client.get_register(address).await?;
Expand Down Expand Up @@ -341,12 +336,7 @@ async fn storage_payment_register_creation_and_mutation_fails() -> Result<()> {

// this should fail to store as the amount paid is not enough
let (mut register, _cost, _royalties_fees) = client
.create_and_pay_for_register(
xor_name,
&mut wallet_client,
false,
Permissions::new_owner_only(),
)
.create_and_pay_for_register(xor_name, &mut wallet_client, false, Permissions::default())
.await?;

sleep(Duration::from_secs(5)).await;
Expand Down
7 changes: 1 addition & 6 deletions sn_node/tests/verify_data_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,7 @@ async fn store_registers(client: Client, register_count: usize, wallet_dir: Path
debug!("Creating Register at {addr:?}");

let (mut register, ..) = client
.create_and_pay_for_register(
meta,
&mut wallet_client,
true,
Permissions::new_owner_only(),
)
.create_and_pay_for_register(meta, &mut wallet_client, true, Permissions::default())
.await?;

println!("Editing Register at {addr:?}");
Expand Down
11 changes: 9 additions & 2 deletions sn_node_manager/src/add_services/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ pub fn parse_port_range(s: &str) -> Result<PortRange> {

#[derive(Debug, PartialEq)]
pub struct InstallNodeServiceCtxBuilder {
pub bootstrap_peers: Vec<Multiaddr>,
pub data_dir_path: PathBuf,
pub env_variables: Option<Vec<(String, String)>>,
pub genesis: bool,
pub local: bool,
pub log_dir_path: PathBuf,
pub name: String,
pub metrics_port: Option<u16>,
pub node_port: Option<u16>,
pub bootstrap_peers: Vec<Multiaddr>,
pub rpc_socket_addr: SocketAddr,
pub safenode_path: PathBuf,
pub service_user: String,
pub env_variables: Option<Vec<(String, String)>>,
}

impl InstallNodeServiceCtxBuilder {
Expand All @@ -76,6 +77,10 @@ impl InstallNodeServiceCtxBuilder {
args.push(OsString::from("--port"));
args.push(OsString::from(node_port.to_string()));
}
if let Some(metrics_port) = self.metrics_port {
args.push(OsString::from("--metrics-server-port"));
args.push(OsString::from(metrics_port.to_string()));
}

if !self.bootstrap_peers.is_empty() {
let peers_str = self
Expand Down Expand Up @@ -106,8 +111,10 @@ pub struct AddNodeServiceOptions {
pub env_variables: Option<Vec<(String, String)>>,
pub genesis: bool,
pub local: bool,
pub metrics_port: Option<PortRange>,
pub node_port: Option<PortRange>,
pub rpc_address: Option<Ipv4Addr>,
pub rpc_port: Option<PortRange>,
pub safenode_src_path: PathBuf,
pub safenode_dir_path: PathBuf,
pub service_data_dir_path: PathBuf,
Expand Down
65 changes: 40 additions & 25 deletions sn_node_manager/src/add_services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,16 @@ pub async fn add_node(
let target_node_count = current_node_count + options.count.unwrap_or(1);

let mut node_number = current_node_count + 1;
let mut port_number = if let Some(port) = options.node_port {
match port {
PortRange::Single(val) => Some(val),
PortRange::Range(start, _) => Some(start),
}
} else {
None
};
let mut node_port = get_start_port_if_applicable(options.node_port);
let mut metrics_port = get_start_port_if_applicable(options.metrics_port);
let mut rpc_port = get_start_port_if_applicable(options.rpc_port);

while node_number <= target_node_count {
let rpc_free_port = service_control.get_available_port()?;
let rpc_free_port = if let Some(port) = rpc_port {
port
} else {
service_control.get_available_port()?
};
let rpc_socket_addr = if let Some(addr) = options.rpc_address {
SocketAddr::new(IpAddr::V4(addr), rpc_free_port)
} else {
Expand All @@ -148,8 +147,9 @@ pub async fn add_node(
genesis: options.genesis,
local: options.local,
log_dir_path: service_log_dir_path.clone(),
metrics_port,
name: service_name.clone(),
node_port: port_number,
node_port,
rpc_socket_addr,
safenode_path: service_safenode_path.clone(),
service_user: options.user.clone(),
Expand All @@ -167,21 +167,21 @@ pub async fn add_node(
));

node_registry.nodes.push(NodeServiceData {
connected_peers: None,
data_dir_path: service_data_dir_path.clone(),
genesis: options.genesis,
listen_addr: None,
local: options.local,
service_name,
user: options.user.clone(),
log_dir_path: service_log_dir_path.clone(),
number: node_number,
rpc_socket_addr,
version: options.version.clone(),
status: ServiceStatus::Added,
listen_addr: None,
pid: None,
peer_id: None,
log_dir_path: service_log_dir_path.clone(),
data_dir_path: service_data_dir_path.clone(),
pid: None,
safenode_path: service_safenode_path,
connected_peers: None,
service_name,
status: ServiceStatus::Added,
user: options.user.clone(),
version: options.version.clone(),
});
// We save the node registry for each service because it's possible any number of
// services could fail to be added.
Expand All @@ -193,12 +193,9 @@ pub async fn add_node(
}

node_number += 1;
port_number = if let Some(port) = port_number {
let incremented_port = port + 1;
Some(incremented_port)
} else {
None
};
node_port = increment_port_option(node_port);
metrics_port = increment_port_option(metrics_port);
rpc_port = increment_port_option(rpc_port);
}

std::fs::remove_file(options.safenode_src_path)?;
Expand Down Expand Up @@ -360,3 +357,21 @@ pub fn add_faucet(
}
}
}

fn get_start_port_if_applicable(range: Option<PortRange>) -> Option<u16> {
if let Some(port) = range {
match port {
PortRange::Single(val) => return Some(val),
PortRange::Range(start, _) => return Some(start),
}
}
None
}

fn increment_port_option(port: Option<u16>) -> Option<u16> {
if let Some(port) = port {
let incremented_port = port + 1;
return Some(incremented_port);
}
None
}
Loading

0 comments on commit d839cee

Please sign in to comment.