Skip to content

Commit

Permalink
chore(refactor): stabilise node size to 4k records,
Browse files Browse the repository at this point in the history
Update some reward forwarding naming
  • Loading branch information
joshuef committed May 13, 2024
1 parent dfa136d commit e010fa8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
4 changes: 0 additions & 4 deletions sn_networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ use tokio::sync::mpsc;
use walkdir::{DirEntry, WalkDir};
use xor_name::XorName;

/// Max number of records a node can store
#[cfg(not(feature = "reward-forward"))]
const MAX_RECORDS_COUNT: usize = 2048;
#[cfg(feature = "reward-forward")]
// A spend record is at the size of 4KB roughly.
// Given chunk record is maxed at size of 512KB.
// During Beta phase, it's almost one spend per chunk,
Expand Down
11 changes: 5 additions & 6 deletions sn_node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ impl Node {
let start = std::time::Instant::now();
trace!("Periodic balance forward triggered");
let network = self.network.clone();
let owner = self.owner.clone();
let forwarding_reason = self.owner.clone();

let _handle = spawn(async move {
let _ = Self::try_forward_blance(network, owner);
let _ = Self::try_forward_blance(network, forwarding_reason);
info!("Periodic blance forward took {:?}", start.elapsed());
});
}
Expand Down Expand Up @@ -759,9 +759,8 @@ impl Node {
}
}

// Shall be disabled after Beta
#[cfg(feature = "reward-forward")]
fn try_forward_blance(network: Network, owner: String) -> Result<()> {
/// Forward received rewards to another address
fn try_forward_blance(network: Network, forward_reason: String) -> Result<()> {
let mut spend_requests = vec![];
{
// load wallet
Expand All @@ -774,7 +773,7 @@ impl Node {
*NETWORK_ROYALTIES_PK,
)];

spend_requests.extend(wallet.prepare_forward_signed_spend(payee, owner)?);
spend_requests.extend(wallet.prepare_forward_signed_spend(payee, forward_reason)?);
}

let record_kind = RecordKind::Spend;
Expand Down
5 changes: 3 additions & 2 deletions sn_transfers/src/wallet/hot_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,16 @@ impl HotWallet {
pub fn prepare_forward_signed_spend(
&mut self,
to: Vec<TransactionPayeeDetails>,
owner: String,
reward_tracking_reason: String,
) -> Result<Vec<SignedSpend>> {
let (available_cash_notes, exclusive_access) = self.available_cash_notes()?;
debug!(
"Available CashNotes for local send: {:#?}",
available_cash_notes
);

let spend_reason = match SpendReason::create_reward_tracking_reason(&owner) {
let spend_reason = match SpendReason::create_reward_tracking_reason(&reward_tracking_reason)
{
Ok(spend_reason) => spend_reason,
Err(err) => {
error!("Failed to generate spend_reason {err:?}");
Expand Down

0 comments on commit e010fa8

Please sign in to comment.