Skip to content

Commit

Permalink
feat(node): make payment forward optional
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi authored and joshuef committed May 30, 2024
1 parent 78effff commit 0f4543d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/memcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 2 additions & 7 deletions sn_node/src/bin/safenode/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,15 @@ 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,
node_socket_addr,
bootstrap_peers,
opt.local,
root_dir,
owner,
opt.owner.clone(),
#[cfg(feature = "upnp")]
opt.upnp,
);
Expand Down
26 changes: 15 additions & 11 deletions sn_node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct NodeBuilder {
metrics_server_port: Option<u16>,
/// Enable hole punching for nodes connecting from home networks.
pub is_behind_home_network: bool,
owner: String,
owner: Option<String>,
#[cfg(feature = "upnp")]
upnp: bool,
}
Expand All @@ -88,7 +88,7 @@ impl NodeBuilder {
initial_peers: Vec<Multiaddr>,
local: bool,
root_dir: PathBuf,
owner: String,
owner: Option<String>,
#[cfg(feature = "upnp")] upnp: bool,
) -> Self {
Self {
Expand Down Expand Up @@ -207,7 +207,8 @@ pub(crate) struct Node {
#[cfg(feature = "open-metrics")]
pub(crate) node_metrics: Option<NodeMetrics>,
/// node owner's discord username, in readable format
owner: String,
/// if not set, there will be no payment forward to be undertaken
owner: Option<String>,
}

impl Node {
Expand Down Expand Up @@ -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() => {
Expand Down

0 comments on commit 0f4543d

Please sign in to comment.