From 3a3df6c4ec7b3f841ea185a1cd59e556c1cf8880 Mon Sep 17 00:00:00 2001 From: qima Date: Wed, 12 Jun 2024 19:14:56 +0800 Subject: [PATCH] WIP --- .github/workflows/merge.yml | 193 ++++++++++++++++++------------------ sn_client/src/api.rs | 2 +- sn_transfers/src/genesis.rs | 17 +++- 3 files changed, 114 insertions(+), 98 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index d38b704393..316d893689 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -723,6 +723,105 @@ jobs: exit 1 fi + faucet_test: + if: "!startsWith(github.event.head_commit.message, 'chore(release):')" + name: Faucet test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + + - name: install ripgrep + shell: bash + run: sudo apt-get install -y ripgrep + + - name: Build binaries + run: cargo build --release --bin safenode --bin safe + timeout-minutes: 30 + + - name: Build faucet binary + run: cargo build --release --bin faucet --features gifting + timeout-minutes: 30 + + - name: Start a local network + uses: maidsafe/sn-local-testnet-action@main + with: + action: start + interval: 2000 + node-path: target/release/safenode + faucet-path: target/release/faucet + platform: ubuntu-latest + build: true + + - name: Check we're _not_ warned about using default genesis + run: | + if rg "USING DEFAULT" "${{ matrix.safe_path }}"/*/*/logs; then + exit 1 + fi + shell: bash + + - name: Move built binaries and clear out target dir + shell: bash + run: | + mv target/release/faucet ~/faucet + mv target/release/safe ~/safe + rm -rf target + + - name: Check SAFE_PEERS was set + shell: bash + run: | + if [[ -z "$SAFE_PEERS" ]]; then + echo "The SAFE_PEERS variable has not been set" + exit 1 + else + echo "SAFE_PEERS has been set to $SAFE_PEERS" + fi + + - name: Create and fund a wallet first time + run: | + ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 > first.txt + cat first.txt + env: + SN_LOG: "all" + timeout-minutes: 5 + + - name: Create and fund a wallet second time + run: | + ls -l /home/runner/.local/share + ls -l /home/runner/.local/share/safe + rm -rf /home/runner/.local/share/safe/test_faucet + rm -rf /home/runner/.local/share/safe/test_genesis + rm -rf /home/runner/.local/share/safe/client + ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 > second.txt + cat second.txt + env: + SN_LOG: "all" + timeout-minutes: 5 + + - name: Create and fund a wallet third time with different keypair + run: | + ls -l /home/runner/.local/share + ls -l /home/runner/.local/share/safe + rm -rf /home/runner/.local/share/safe/test_faucet + rm -rf /home/runner/.local/share/safe/test_genesis + rm -rf /home/runner/.local/share/safe/client + GENESIS_PK=a9925296499299fdbf4412509d342a92e015f5b996e9acd1d2ab7f2326e3ad05934326efdc345345a95e973ac1bb6637 GENESIS_SK=40f6bbc870355c68138ac70b450b6425af02b49874df3f141b7018378ceaac66 ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 > second.txt + cat third.txt + env: + SN_LOG: "all" + timeout-minutes: 5 + + - name: Stop the local network and upload logs + if: always() + uses: maidsafe/sn-local-testnet-action@main + with: + action: stop + platform: ubuntu-latest + log_file_prefix: safe_test_logs_faucet + large_file_upload_test: if: "!startsWith(github.event.head_commit.message, 'chore(release):')" name: Large file upload @@ -1074,97 +1173,3 @@ jobs: action: stop log_file_prefix: safe_test_logs_heavy_replicate_bench platform: ubuntu-latest - - faucet_test: - if: "!startsWith(github.event.head_commit.message, 'chore(release):')" - name: Faucet test - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - - name: install ripgrep - shell: bash - run: sudo apt-get install -y ripgrep - - - name: Build binaries - run: cargo build --release --bin safenode --bin safe - timeout-minutes: 30 - - - name: Build faucet binary - run: cargo build --release --bin faucet --features gifting - timeout-minutes: 30 - - - name: Start a local network - uses: maidsafe/sn-local-testnet-action@main - with: - action: start - interval: 2000 - node-path: target/release/safenode - faucet-path: target/release/faucet - platform: ubuntu-latest - build: true - - - name: Check we're _not_ warned about using default genesis - run: | - if rg "USING DEFAULT" "${{ matrix.safe_path }}"/*/*/logs; then - exit 1 - fi - shell: bash - - # The test currently fails because the GH runner runs out of disk space. So we clear out the target dir here. - # Might be related to additional deps used in the codebase. - - name: Move built binaries and clear out target dir - shell: bash - run: | - mv target/release/faucet ~/faucet - mv target/release/safe ~/safe - rm -rf target - - - name: Check SAFE_PEERS was set - shell: bash - run: | - if [[ -z "$SAFE_PEERS" ]]; then - echo "The SAFE_PEERS variable has not been set" - exit 1 - else - echo "SAFE_PEERS has been set to $SAFE_PEERS" - fi - - - name: Create and fund a wallet to pay for files storage - run: | - ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 - env: - SN_LOG: "all" - timeout-minutes: 5 - - - name: Create and fund a wallet to pay for files storage - run: | - ls -l /home/runner/.local/share - ls -l /home/runner/.local/share/safe - rm -rf /home/runner/.local/share/safe/test_faucet - rm -rf /home/runner/.local/share/safe/test_genesis - rm -rf /home/runner/.local/share/safe/client - ~/faucet --log-output-dest=data-dir send 100000000 $(~/safe --log-output-dest=data-dir wallet address | tail -n 1) | tail -n 1 - env: - SN_LOG: "all" - timeout-minutes: 5 - /home/runner/.local/share/safe - - - name: Start a client to upload - run: ~/safe --log-output-dest=data-dir files upload "ubuntu-14.04.6-desktop-i386.iso" --retry-strategy quick - env: - SN_LOG: "all" - timeout-minutes: 30 - - - name: Stop the local network and upload logs - if: always() - uses: maidsafe/sn-local-testnet-action@main - with: - action: stop - platform: ubuntu-latest - log_file_prefix: safe_test_logs_large_file_upload - build: true diff --git a/sn_client/src/api.rs b/sn_client/src/api.rs index 4e61c3bc9e..fd4f440cee 100644 --- a/sn_client/src/api.rs +++ b/sn_client/src/api.rs @@ -862,7 +862,7 @@ impl Client { let cash_note_addr = SpendAddress::from_unique_pubkey(&unique_pubkey); let network_address = NetworkAddress::from_spend_address(cash_note_addr); - trace!("Sending spend {unique_pubkey:?} to the network via put_record, with addr of {cash_note_addr:?}"); + info!("Sending spend {unique_pubkey:?} to the network via put_record, with addr of {cash_note_addr:?}"); let key = network_address.to_record_key(); let record_kind = RecordKind::Spend; let record = Record { diff --git a/sn_transfers/src/genesis.rs b/sn_transfers/src/genesis.rs index a08b209eaf..f1087319cc 100644 --- a/sn_transfers/src/genesis.rs +++ b/sn_transfers/src/genesis.rs @@ -10,7 +10,7 @@ use super::wallet::HotWallet; use crate::{ wallet::Result as WalletResult, CashNote, DerivationIndex, Input, MainPubkey, MainSecretKey, - NanoTokens, Output, SignedSpend, SpendReason, Transaction, TransactionBuilder, + NanoTokens, Output, SignedSpend, SpendAddress, SpendReason, Transaction, TransactionBuilder, TransferError as CashNoteError, UniquePubkey, }; @@ -153,10 +153,21 @@ 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_SPEND_UNIQUE_KEY + let is_genesis = 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) + && spend.spend.amount == NanoTokens::from(GENESIS_CASHNOTE_AMOUNT); + if is_genesis { + info!( + "Spend {:?} is a genesis spend.", + SpendAddress::from_unique_pubkey(&spend.spend.unique_pubkey) + ); + info!( + "inputs: {:?}, outputs: {:?}", + spend.spend.spent_tx.inputs, spend.spend.spent_tx.outputs + ); + } + is_genesis } pub fn load_genesis_wallet() -> Result {