Skip to content

Commit

Permalink
Merge pull request #3313 from dusk-network/mainnet-dryrun-20250103
Browse files Browse the repository at this point in the history
rusk: include changes from `rusk-release-1.0.0` branch
  • Loading branch information
herr-seppia authored Jan 5, 2025
2 parents 08c5e98 + 1b94eaf commit 794c7fd
Show file tree
Hide file tree
Showing 8 changed files with 2,043 additions and 6 deletions.
11 changes: 11 additions & 0 deletions node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ impl ProvisionerChange {
};
Some(event)
}

fn topic(&self) -> &str {
match &self {
ProvisionerChange::Stake(_) => "stake",
ProvisionerChange::Unstake(_) => "unstake",
ProvisionerChange::Slash(_) => "slash",
ProvisionerChange::HardSlash(_) => "hard_slash",
}
}

fn key(&self) -> &bls::PublicKey {
match &self {
ProvisionerChange::Stake(e) => &e.keys.account,
Expand Down Expand Up @@ -522,6 +532,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
info!(
event = "provisioner_update",
src,
topic = change.topic(),
account = account.to_bs58(),
value
);
Expand Down
1,932 changes: 1,932 additions & 0 deletions rusk-recovery/config/mainnet.toml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions rusk-recovery/config/mainnet_remote.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base_state = "https://nodes.dusk.network/genesis-state"

7 changes: 3 additions & 4 deletions rusk-recovery/config/testnet.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Dusk account

[[phoenix_balance]]
address = '68UiBbsJ4PumJyVpS91VbffhKgq9p6QaLC8QCqzgLiKBX71mvCswmeViTHDsBJ3RMwsVcxBSkZ3HbjHAL9qCNxh'
seed = 0xdead_beef
notes = [699_000_000_000_000]
[[moonlight_account]]
address = 'o1YvWG34EBTwdskfZ7PCvWKRUWKzskVnhJNjZHdau6VaUNpgDxpoSsisK8KGF6FayUi8Lzn4taAvZcHGprQuPsqFGH66SEPDRCbTmKGVwFYX7bEp2rF4wekvoc4dS8ghnKf'
balance = 699_000_000_000_000

# Faucet wallet

Expand Down
2 changes: 1 addition & 1 deletion rusk/src/assets/dusk.cpk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
j�<$m��U]@����$s!ԕ��3ꠅ�EZH�� ��Y�'먎�+i!�/6�Y�^�,�2^'�Gs{�x�Rh8�~hڀEY�^t������
�k}�95��A�:�v�>�8��������k"�D������s�<6�9��)M�kfIO�����)1E����1������a�>6ء/�$
2 changes: 1 addition & 1 deletion rusk/src/lib/node/vm/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Rusk {
.map_err(Into::into)
}

pub(crate) fn query<A, R>(
pub fn query<A, R>(
&self,
contract_id: ContractId,
call_name: &str,
Expand Down
92 changes: 92 additions & 0 deletions rusk/tests/services/mainnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::path::Path;
use std::sync::mpsc::{self, Receiver, Sender};

use dusk_core::dusk;
use dusk_core::stake::{StakeData, StakeKeys, STAKE_CONTRACT};
use dusk_core::transfer::moonlight::AccountData;
use dusk_core::transfer::phoenix::NoteLeaf;
use dusk_core::transfer::TRANSFER_CONTRACT;
use rusk::{Result, Rusk};
use tempfile::tempdir;

use crate::common::logger;
use crate::common::state::new_state;

const GENESIS_BALANCE: u64 = dusk(500_000_000.0);

// Creates the Rusk initial state for the tests below
fn initial_state<P: AsRef<Path>>(dir: P) -> Result<Rusk> {
let snapshot = toml::from_str(include_str!(
"../../../rusk-recovery/config/mainnet.toml"
))
.expect("Cannot deserialize config");

new_state(dir, &snapshot, u64::MAX)
}

#[tokio::test(flavor = "multi_thread")]
pub async fn mainnet_genesis() -> Result<()> {
// Setup the logger
logger();

let tmp = tempdir().expect("Should be able to create temporary directory");
let rusk = initial_state(&tmp)?;
let mut total_amount = 0u64;

let (sender, receiver): (Sender<Vec<u8>>, Receiver<Vec<u8>>) =
mpsc::channel();
rusk.feeder_query(STAKE_CONTRACT, "stakes", &(), sender, None)?;
for bytes in receiver.into_iter() {
let (_, data) = rkyv::from_bytes::<(StakeKeys, StakeData)>(&bytes)
.expect(
"The contract should only return (StakeKeys, StakeData) tuples",
);
total_amount += data.amount.unwrap_or_default().total_funds();
}

let skate_balance: u64 = rusk
.query(TRANSFER_CONTRACT, "contract_balance", &STAKE_CONTRACT)
.expect("Query to succeed");
assert_eq!(
total_amount, skate_balance,
"Total stake amount should match"
);

let sync_range = (0u64, u64::MAX);
let (sender, receiver): (Sender<Vec<u8>>, Receiver<Vec<u8>>) =
std::sync::mpsc::channel();
rusk.feeder_query(
TRANSFER_CONTRACT,
"sync_accounts",
&sync_range,
sender,
None,
)?;
for bytes in receiver.into_iter() {
let (data, _) = rkyv::from_bytes::<(AccountData, [u8; 193])>(&bytes)
.expect(
"The contract should only return (AccountData, [u8; 193]) tuples",
);
total_amount += data.balance;
}

let (sender, receiver): (Sender<Vec<u8>>, Receiver<Vec<u8>>) =
std::sync::mpsc::channel();
rusk.feeder_query(TRANSFER_CONTRACT, "sync", &sync_range, sender, None)?;
for bytes in receiver.into_iter() {
let leaf: NoteLeaf = rkyv::from_bytes(&bytes)
.expect("The contract should only return NoteLeaf");

total_amount += leaf.note.value(None).expect("Transparent note");
}

assert_eq!(total_amount, GENESIS_BALANCE, "Total amount should match");

Ok(())
}
1 change: 1 addition & 0 deletions rusk/tests/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod conversion;
//pub mod deploy;
pub mod finalization;
pub mod gas_behavior;
pub mod mainnet;
pub mod moonlight_stake;
pub mod multi_transfer;
pub mod owner_calls;
Expand Down

0 comments on commit 794c7fd

Please sign in to comment.