Skip to content

Commit

Permalink
feat(auditor): recognize payment forwards with default key
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Jun 10, 2024
1 parent a338f01 commit 84156b3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
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 @@ -356,8 +358,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)
{
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

0 comments on commit 84156b3

Please sign in to comment.