From 0f4543d3122de4e094fd619f1d83fd1340cd8781 Mon Sep 17 00:00:00 2001 From: qima Date: Wed, 29 May 2024 19:17:41 +0800 Subject: [PATCH] feat(node): make payment forward optional --- .github/workflows/memcheck.yml | 2 +- sn_node/src/bin/safenode/main.rs | 9 ++------- sn_node/src/node.rs | 26 +++++++++++++++----------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/memcheck.yml b/.github/workflows/memcheck.yml index 75847a1114..fb4125e2e4 100644 --- a/.github/workflows/memcheck.yml +++ b/.github/workflows/memcheck.yml @@ -451,7 +451,7 @@ jobs: shell: bash timeout-minutes: 1 run: | - min_reward_forwarding_times="120" + min_reward_forwarding_times="100" reward_forwarding_count=$(rg "Reward forwarding completed sending spend" $NODE_DATA_PATH -c --stats | \ rg "(\d+) matches" | rg "\d+" -o) echo "Carried out $reward_forwarding_count reward forwardings" diff --git a/sn_node/src/bin/safenode/main.rs b/sn_node/src/bin/safenode/main.rs index ec5c85f9fe..54e427458c 100644 --- a/sn_node/src/bin/safenode/main.rs +++ b/sn_node/src/bin/safenode/main.rs @@ -209,12 +209,7 @@ fn main() -> Result<()> { // another process with these args. #[cfg(feature = "metrics")] rt.spawn(init_metrics(std::process::id())); - let owner = if let Some(owner) = opt.owner { - debug!("Node's owner set to: {owner}"); - owner.clone() - } else { - "user".to_owned() - }; + debug!("Node's owner set to: {:?}", opt.owner); let restart_options = rt.block_on(async move { let mut node_builder = NodeBuilder::new( keypair, @@ -222,7 +217,7 @@ fn main() -> Result<()> { bootstrap_peers, opt.local, root_dir, - owner, + opt.owner.clone(), #[cfg(feature = "upnp")] opt.upnp, ); diff --git a/sn_node/src/node.rs b/sn_node/src/node.rs index efa77e4403..954a5f15b3 100644 --- a/sn_node/src/node.rs +++ b/sn_node/src/node.rs @@ -75,7 +75,7 @@ pub struct NodeBuilder { metrics_server_port: Option, /// Enable hole punching for nodes connecting from home networks. pub is_behind_home_network: bool, - owner: String, + owner: Option, #[cfg(feature = "upnp")] upnp: bool, } @@ -88,7 +88,7 @@ impl NodeBuilder { initial_peers: Vec, local: bool, root_dir: PathBuf, - owner: String, + owner: Option, #[cfg(feature = "upnp")] upnp: bool, ) -> Self { Self { @@ -207,7 +207,8 @@ pub(crate) struct Node { #[cfg(feature = "open-metrics")] pub(crate) node_metrics: Option, /// node owner's discord username, in readable format - owner: String, + /// if not set, there will be no payment forward to be undertaken + owner: Option, } impl Node { @@ -308,15 +309,18 @@ impl Node { // runs every balance_forward_interval time _ = balance_forward_interval.tick() => { if cfg!(feature = "reward-forward") { - let start = std::time::Instant::now(); - trace!("Periodic balance forward triggered"); - let network = self.network.clone(); - let forwarding_reason = self.owner.clone(); + if let Some(ref owner) = self.owner { + let start = std::time::Instant::now(); + trace!("Periodic balance forward triggered"); + let network = self.network.clone(); + let forwarding_reason = owner.clone(); + + let _handle = spawn(async move { + let _ = Self::try_forward_blance(network, forwarding_reason); + info!("Periodic blance forward took {:?}", start.elapsed()); + }); + } - let _handle = spawn(async move { - let _ = Self::try_forward_blance(network, forwarding_reason); - info!("Periodic blance forward took {:?}", start.elapsed()); - }); } } node_cmd = cmds_receiver.recv() => {