Skip to content

Commit

Permalink
feat: remove two uneeded env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
grumbach committed May 17, 2024
1 parent 14a4660 commit b656a59
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 72 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/benchmark-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ env:
CLIENT_DATA_PATH: /home/runner/.local/share/safe/client
NODE_DATA_PATH: /home/runner/.local/share/safe/node
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
benchmark-cli:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/generate-benchmark-charts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ env:
CLIENT_DATA_PATH: /home/runner/.local/share/safe/client
NODE_DATA_PATH: /home/runner/.local/share/safe/node
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
benchmark-cli:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/memcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ env:
RESTART_TEST_NODE_DATA_PATH: /home/runner/.local/share/safe/restart_node
FAUCET_LOG_PATH: /home/runner/.local/share/safe/test_faucet/logs
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
memory-check:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ env:
CARGO_INCREMENTAL: 0 # bookkeeping for incremental builds has overhead, not useful in CI.
WINSW_URL: https://github.com/winsw/winsw/releases/download/v3.0.0-alpha.11/WinSW-x64.exe
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
cargo-udeps:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
CARGO_INCREMENTAL: 0 # bookkeeping for incremental builds has overhead, not useful in CI.
WORKFLOW_URL: https://github.com/maidsafe/stableset_net/actions/runs
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
e2e:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/nightly_wan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
CARGO_INCREMENTAL: 0 # bookkeeping for incremental builds has overhead, not useful in CI.
WORKFLOW_URL: https://github.com/maidsafe/stableset_net/actions/runs
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
e2e:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/nightly_wan_churn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ env:
CARGO_INCREMENTAL: 0 # bookkeeping for incremental builds has overhead, not useful in CI.
WORKFLOW_URL: https://github.com/maidsafe/stableset_net/actions/runs
GENESIS_PK: 9934c21469a68415e6b06a435709e16bff6e92bf302aeb0ea9199d2d06a55f1b1a21e155853d3f94ae31f8f313f886ee
GENESIS_CN_UNIQUE_KEY: 82e84d347286a2a2035e4fdb5f011649e0244c22d20ab6b14008499ee24e7259c312f3a6427359da0048ff9894b11b55
GENESIS_CN_PARENT_TX: 005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d99291005d1eeeffa2e111cf35356231316234393839666638343030616439353337323436613366323133633935323765343265653939343830303431623662613032643232633434323065393436313130663562646634653533303261326136383237343364343865323860d9929192

jobs:
e2e:
Expand Down
6 changes: 2 additions & 4 deletions sn_auditor/src/dag_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use color_eyre::eyre::{eyre, Result};
use graphviz_rust::{cmd::Format, exec, parse, printer::PrinterContext};
use serde::{Deserialize, Serialize};
use sn_client::networking::NetworkError;
use sn_client::transfers::{
Hash, NanoTokens, SignedSpend, SpendAddress, GENESIS_CASHNOTE_UNIQUE_KEY,
};
use sn_client::transfers::{Hash, NanoTokens, SignedSpend, SpendAddress, GENESIS_SPEND_UNIQUE_KEY};
use sn_client::Error as ClientError;
use sn_client::{Client, SpendDag, SpendDagGet};
use std::collections::{BTreeMap, BTreeSet};
Expand Down Expand Up @@ -304,7 +302,7 @@ impl SpendDagDb {
}

pub async fn new_dag_with_genesis_only(client: &Client) -> Result<SpendDag> {
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_CASHNOTE_UNIQUE_KEY);
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_SPEND_UNIQUE_KEY);
let mut dag = SpendDag::new(genesis_addr);
let genesis_spend = match client.get_spend_from_network(genesis_addr).await {
Ok(s) => s,
Expand Down
8 changes: 3 additions & 5 deletions sn_cli/src/bin/subcommands/wallet/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use std::path::Path;
use bls::SecretKey;
use color_eyre::Result;
use sn_client::acc_packet::load_account_wallet_or_create_with_mnemonic;
use sn_client::transfers::{
CashNoteRedemption, SpendAddress, Transfer, GENESIS_CASHNOTE_UNIQUE_KEY,
};
use sn_client::transfers::{CashNoteRedemption, SpendAddress, Transfer, GENESIS_SPEND_UNIQUE_KEY};
use sn_client::{Client, SpendDag};

const SPEND_DAG_FILENAME: &str = "spend_dag";
Expand All @@ -29,7 +27,7 @@ async fn gather_spend_dag(client: &Client, root_dir: &Path) -> Result<SpendDag>
Err(err) => {
println!("Starting from Genesis as found no local spend dag on disk...");
info!("Starting from Genesis as failed to load spend dag from disk: {err}");
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_CASHNOTE_UNIQUE_KEY);
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_SPEND_UNIQUE_KEY);
client
.spend_dag_build_from(genesis_addr, None, true)
.await?
Expand Down Expand Up @@ -66,7 +64,7 @@ pub async fn audit(
} else {
//NB TODO use the above DAG to audit too
println!("Auditing the Currency, note that this might take a very long time...");
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_CASHNOTE_UNIQUE_KEY);
let genesis_addr = SpendAddress::from_unique_pubkey(&GENESIS_SPEND_UNIQUE_KEY);
client.follow_spend(genesis_addr).await?;
}
Ok(())
Expand Down
6 changes: 3 additions & 3 deletions sn_client/src/audit/spend_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ impl Client {

// check if we reached the genesis Tx
if parent_tx == *sn_transfers::GENESIS_CASHNOTE_PARENT_TX
&& spends.iter().all(|s| {
s.spend.unique_pubkey == *sn_transfers::GENESIS_CASHNOTE_UNIQUE_KEY
})
&& spends
.iter()
.all(|s| s.spend.unique_pubkey == *sn_transfers::GENESIS_SPEND_UNIQUE_KEY)
&& spends.len() == 1
{
debug!("Depth {depth} - Reached genesis Tx on one branch: {parent_tx_hash:?}");
Expand Down
6 changes: 3 additions & 3 deletions sn_client/src/audit/spend_dag_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ impl Client {

// check if we reached the genesis Tx
if parent_tx == *sn_transfers::GENESIS_CASHNOTE_PARENT_TX
&& spends.iter().all(|s| {
s.spend.unique_pubkey == *sn_transfers::GENESIS_CASHNOTE_UNIQUE_KEY
})
&& spends
.iter()
.all(|s| s.spend.unique_pubkey == *sn_transfers::GENESIS_SPEND_UNIQUE_KEY)
&& spends.len() == 1
{
debug!("Depth {depth} - reached genesis Tx on one branch: {parent_tx_hash:?}");
Expand Down
2 changes: 1 addition & 1 deletion sn_transfers/src/cashnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod transaction;
mod unique_keys;

pub(crate) use builder::{CashNoteBuilder, TransactionBuilder};
pub(crate) use transaction::Input;
pub(crate) use transaction::{Input, Output};

pub use address::SpendAddress;
pub use builder::UnsignedTransfer;
Expand Down
8 changes: 2 additions & 6 deletions sn_transfers/src/cashnotes/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl TransactionBuilder {
self,
reason: SpendReason,
network_royalties: Vec<DerivationIndex>,
) -> Result<CashNoteBuilder> {
) -> CashNoteBuilder {
let spent_tx = Transaction {
inputs: self.inputs,
outputs: self.outputs,
Expand All @@ -132,11 +132,7 @@ impl TransactionBuilder {
}
}

Ok(CashNoteBuilder::new(
spent_tx,
self.output_details,
signed_spends,
))
CashNoteBuilder::new(spent_tx, self.output_details, signed_spends)
}

/// Build the UnsignedTransfer which contains the generated (unsigned) Spends.
Expand Down
61 changes: 28 additions & 33 deletions sn_transfers/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::wallet::HotWallet;

use crate::{
wallet::Result as WalletResult, CashNote, DerivationIndex, Input, MainPubkey, MainSecretKey,
NanoTokens, SignedSpend, SpendReason, Transaction, TransactionBuilder,
NanoTokens, Output, SignedSpend, SpendReason, Transaction, TransactionBuilder,
TransferError as CashNoteError, UniquePubkey,
};

Expand All @@ -25,6 +25,13 @@ use thiserror::Error;
/// thus creating a total of 1,288,490,189,000,000,000 available units.
pub(super) const GENESIS_CASHNOTE_AMOUNT: u64 = (0.3 * TOTAL_SUPPLY as f64) as u64;

/// The derivation index for the genesis Spend.
const GENESIS_DERIVATION_INDEX: DerivationIndex = DerivationIndex([0u8; 32]);

/// Default genesis PK and SK for testing purpose. Be sure to pass the correct values via env.
const TESTING_GENESIS_PK: &str = "b814bc39a357e6f6000f4946da52dcfc72e19efe91e31d4e94e9cb408d765a4a6cf3bf2df14806f8fa524bd7ebb9bb4e"; // DevSkim: ignore DS173237
const TESTING_GENESIS_SK: &str = "23746be7fa5df26c3065eb7aa26860981e435c1853cafafe472417bc94f340e9"; // DevSkim: ignore DS173237

/// Based on the given store cost, it calculates what's the expected amount to be paid as network royalties.
/// Network royalties fee is expected to be 15% of the payment amount, i.e. 85% of store cost + 15% royalties fees.
pub fn calculate_royalties_fee(store_cost: NanoTokens) -> NanoTokens {
Expand Down Expand Up @@ -58,7 +65,7 @@ lazy_static! {
/// The hard coded value is for production release, allows all nodes to validate it.
/// The env set value is only used for testing purpose.
pub static ref GENESIS_PK: MainPubkey = {
let pk_str = std::env::var("GENESIS_PK").unwrap_or("b814bc39a357e6f6000f4946da52dcfc72e19efe91e31d4e94e9cb408d765a4a6cf3bf2df14806f8fa524bd7ebb9bb4e".to_string()); // DevSkim: ignore DS173237
let pk_str = std::env::var("GENESIS_PK").unwrap_or(TESTING_GENESIS_PK.to_string());

match MainPubkey::from_hex(pk_str) {
Ok(pk) => pk,
Expand All @@ -68,36 +75,30 @@ lazy_static! {
}

lazy_static! {
/// This key is public for auditing purposes.
/// The hard coded value is for production release, allows all nodes to validate it.
/// The env set value is only used for testing purpose.
pub static ref GENESIS_CASHNOTE_UNIQUE_KEY: UniquePubkey = {
let pk_str = std::env::var("GENESIS_CN_UNIQUE_KEY").unwrap_or("9524860078012d0cef2561b5e668bff150fae00675658310d4d3ffe5310b7436dca143cd459e87b08ce8467756bde6e7".to_string()); // DevSkim: ignore DS173237
match UniquePubkey::from_hex(pk_str) {
Ok(pk) => pk,
Err(err) => panic!("Failed to parse genesis_cashnote.unique_key: {err:?}"),
}
};
/// This is the unique key for the genesis Spend
pub static ref GENESIS_SPEND_UNIQUE_KEY: UniquePubkey = GENESIS_PK.new_unique_pubkey(&GENESIS_DERIVATION_INDEX);
}

lazy_static! {
/// This trasnsaction is public for auditing purposes.
/// The hard coded value is for production release, allows all nodes to validate it.
/// The env set value is only used for testing purpose.
pub static ref GENESIS_CASHNOTE_PARENT_TX: Transaction = {
let tx_str = std::env::var("GENESIS_CN_PARENT_TX").unwrap_or("005d1eeeffa2e111cf37653665646236353737363438656338306237386539353464633334316163643633343762303133356566663364346430313338353635373630306561663035316666623836366535623136353266656330643231303837303036383432353960d99291005d1eeeffa2e111cf37653665646236353737363438656338306237386539353464633334316163643633343762303133356566663364346430313338353635373630306561663035316666623836366535623136353266656330643231303837303036383432353960d9929192".to_string()); // DevSkim: ignore DS173237
match Transaction::from_hex(&tx_str) {
Ok(tx) => tx,
Err(err) => panic!("Failed to parse genesis_cashnote.parent_tx: {err:?}"),
}
let mut tx = Transaction::empty();
tx.inputs = vec![Input {
unique_pubkey: *GENESIS_SPEND_UNIQUE_KEY,
amount: NanoTokens::from(GENESIS_CASHNOTE_AMOUNT),
}];
tx.outputs = vec![Output {
unique_pubkey: *GENESIS_SPEND_UNIQUE_KEY,
amount: NanoTokens::from(GENESIS_CASHNOTE_AMOUNT),
}];
tx
};
}

lazy_static! {
/// Unlike the `GENESIS_PK`, the hard coded secret_key is for testing purpose.
/// The one for live network shall be passed in via env set.
static ref GENESIS_SK_STR: String = {
std::env::var("GENESIS_SK").unwrap_or("23746be7fa5df26c3065eb7aa26860981e435c1853cafafe472417bc94f340e9".to_string()) // DevSkim: ignore DS173237
std::env::var("GENESIS_SK").unwrap_or(TESTING_GENESIS_SK.to_string())
};
}

Expand Down Expand Up @@ -129,8 +130,8 @@ pub fn is_genesis_parent_tx(parent_tx: &Transaction) -> bool {
/// Return if provided Spend is genesis spend.
pub fn is_genesis_spend(spend: &SignedSpend) -> bool {
let bytes = spend.spend.to_bytes_for_signing();
spend.spend.unique_pubkey == *GENESIS_CASHNOTE_UNIQUE_KEY
&& GENESIS_CASHNOTE_UNIQUE_KEY.verify(&spend.derived_key_sig, bytes)
spend.spend.unique_pubkey == *GENESIS_SPEND_UNIQUE_KEY
&& GENESIS_SPEND_UNIQUE_KEY.verify(&spend.derived_key_sig, bytes)
&& is_genesis_parent_tx(&spend.spend.parent_tx)
&& spend.spend.amount == NanoTokens::from(GENESIS_CASHNOTE_AMOUNT)
}
Expand Down Expand Up @@ -187,8 +188,7 @@ pub fn create_first_cash_note_from_key(
) -> GenesisResult<CashNote> {
let main_pubkey = first_cash_note_key.main_pubkey();
debug!("genesis cashnote main_pubkey: {:?}", main_pubkey);
let derivation_index = DerivationIndex([0u8; 32]);
let derived_key = first_cash_note_key.derive_key(&derivation_index);
let derived_key = first_cash_note_key.derive_key(&GENESIS_DERIVATION_INDEX);

// Use the same key as the input and output of Genesis Tx.
// The src tx is empty as this is the first CashNote.
Expand All @@ -204,19 +204,14 @@ pub fn create_first_cash_note_from_key(
genesis_input,
Some(derived_key),
Transaction::empty(),
derivation_index,
GENESIS_DERIVATION_INDEX,
)
.add_output(
NanoTokens::from(GENESIS_CASHNOTE_AMOUNT),
main_pubkey,
derivation_index,
GENESIS_DERIVATION_INDEX,
)
.build(reason, vec![])
.map_err(|err| {
Error::GenesisCashNoteError(format!(
"Failed to build the CashNote transaction for genesis CashNote: {err}",
))
})?;
.build(reason, vec![]);

// build the output CashNotes
let output_cash_notes = cash_note_builder.build_without_verifying().map_err(|err| {
Expand Down
4 changes: 2 additions & 2 deletions sn_transfers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod genesis;
mod transfers;
mod wallet;

pub(crate) use cashnotes::{Input, TransactionBuilder};
pub(crate) use cashnotes::{Input, Output, TransactionBuilder};

/// Default value as a node owner
pub const DEFAULT_NODE_OWNER: &str = "maidsafe_test";
Expand All @@ -30,7 +30,7 @@ pub use error::{Result, TransferError};
pub use genesis::{
calculate_royalties_fee, create_first_cash_note_from_key, get_faucet_data_dir, get_genesis_sk,
is_genesis_parent_tx, is_genesis_spend, load_genesis_wallet, Error as GenesisError,
GENESIS_CASHNOTE, GENESIS_CASHNOTE_PARENT_TX, GENESIS_CASHNOTE_UNIQUE_KEY, GENESIS_PK,
GENESIS_CASHNOTE, GENESIS_CASHNOTE_PARENT_TX, GENESIS_PK, GENESIS_SPEND_UNIQUE_KEY,
TOTAL_SUPPLY,
};
pub use transfers::{CashNoteRedemption, OfflineTransfer, Transfer};
Expand Down
2 changes: 1 addition & 1 deletion sn_transfers/src/transfers/offline_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn create_offline_transfer_with(
let (tx_builder, src_txs, change_id) = create_transaction_builder_with(selected_inputs)?;

// Finalize the tx builder to get the cash_note builder.
let cash_note_builder = tx_builder.build(input_reason, network_royalties)?;
let cash_note_builder = tx_builder.build(input_reason, network_royalties);

let tx = cash_note_builder.spent_tx.clone();

Expand Down

0 comments on commit b656a59

Please sign in to comment.