Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auditor): recognize payment forwards with default key #1860

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions sn_auditor/src/dag_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use color_eyre::eyre::{bail, eyre, Result};
use graphviz_rust::{cmd::Format, exec, parse, printer::PrinterContext};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use sn_client::transfers::{Hash, NanoTokens, SignedSpend, SpendAddress};
use sn_client::transfers::{
Hash, NanoTokens, SignedSpend, SpendAddress, DEFAULT_PAYMENT_FORWARD_SK,
};
use sn_client::{Client, SpendDag, SpendDagGet};
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Write;
Expand Down Expand Up @@ -358,8 +360,24 @@ impl SpendDagDb {
.or_default()
.insert((addr, amount));
} else {
// check with default key
if let Some(default_user_name_hash) =
spend.reason().get_sender_hash(&DEFAULT_PAYMENT_FORWARD_SK)
Comment on lines 362 to +365
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could reduce indentation and remove the return statement below with an else if let

Suggested change
} else {
// check with default key
if let Some(default_user_name_hash) =
spend.reason().get_sender_hash(&DEFAULT_PAYMENT_FORWARD_SK)
// check with default key
} else if let Some(default_user_name_hash) =
spend.reason().get_sender_hash(&DEFAULT_PAYMENT_FORWARD_SK)

And put the unknown participant block in a last else

{
if let Some(user_name) = beta_participants_read.get(&default_user_name_hash) {
warn!("With default key, got forwarded reward {amount} from {user_name} of {amount} at {addr:?}");
println!("With default key, got forwarded reward {amount} from {user_name} of {amount} at {addr:?}");
beta_tracking
.forwarded_payments
.entry(user_name.to_owned())
.or_default()
.insert((addr, amount));
return;
}
}

warn!("Found a forwarded reward {amount} for an unknown participant at {addr:?}: {user_name_hash:?}");
eprintln!("Found a forwarded reward {amount} for an unknown participant at {addr:?}: {user_name_hash:?}");
println!("Found a forwarded reward {amount} for an unknown participant at {addr:?}: {user_name_hash:?}");
beta_tracking
.forwarded_payments
.entry(format!("unknown participant: {user_name_hash:?}"))
Expand Down
10 changes: 10 additions & 0 deletions sn_transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub use wallet::{
QUOTE_EXPIRATION_SECS, WALLET_DIR_NAME,
};

use bls::SecretKey;
use lazy_static::lazy_static;

/// The following PKs shall be updated to match its correspondent SKs before the formal release
Expand All @@ -47,6 +48,9 @@ const DEFAULT_FOUNDATION_PK_STR: &str = "8f73b97377f30bed96df1c92daf9f21b4a82c86
const DEFAULT_NETWORK_ROYALTIES_STR: &str = "b4243ec9ceaec374ef992684cd911b209758c5de53d1e406b395bc37ebc8ce50e68755ea6d32da480ae927e1af4ddadb"; // DevSkim: ignore DS173237
/// Public key where payment forward to be targeted.
const DEFAULT_PAYMENT_FORWARD_STR: &str = "a585839f0502713a0ed6a327f3bd0c301f9e8fe298c93dd00ed7869d8e6804244f0d3014e90df45cd344a7ccd702865c"; // DevSkim: ignore DS173237
/// Default secrect key where payment forward to be targeted, for backward compatible purpose only.
const DEFAULT_PAYMENT_FORWARD_SK_STR: &str =
"49113d2083f57a976076adbe85decb75115820de1e6e74b47e0429338cef124a"; // DevSkim: ignore DS173237

lazy_static! {
pub static ref FOUNDATION_PK: MainPubkey = {
Expand Down Expand Up @@ -126,6 +130,12 @@ lazy_static! {
Err(err) => panic!("Failed to parse payment forward PK: {err:?}"),
}
};
pub static ref DEFAULT_PAYMENT_FORWARD_SK: SecretKey = {
match SecretKey::from_hex(DEFAULT_PAYMENT_FORWARD_SK_STR) {
Ok(sk) => sk,
Err(err) => panic!("Failed to parse default payment forward SK: {err:?}"),
}
};
}

// re-export crates used in our public API
Expand Down
Loading