Skip to content

Commit

Permalink
rusk: support stake multisig
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Sep 9, 2024
1 parent 0226b96 commit 2cf892c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rusk/src/lib/http/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Rusk {
.provisioners(None)
.expect("Cannot query state for provisioners")
.map(|(key, stake)| {
let key = bs58::encode(key.to_bytes()).into_string();
let key = bs58::encode(key.account.to_bytes()).into_string();
let amount = stake.amount.unwrap_or_default();

Provisioner {
Expand Down
20 changes: 8 additions & 12 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use std::path::Path;
use std::sync::{mpsc, Arc, LazyLock};
use std::sync::{mpsc, Arc};
use std::time::{Duration, Instant};
use std::{fs, io};

use execution_core::stake::StakeKeys;
use execution_core::transfer::PANIC_NONCE_NOT_READY;
use parking_lot::RwLock;
use rusk_recovery_tools::state::DUSK_CONSENSUS_KEY;
use sha3::{Digest, Sha3_256};
use tokio::task;
use tracing::{debug, info, warn};

use dusk_bytes::{DeserializableSlice, Serializable};
use dusk_bytes::Serializable;
use dusk_consensus::config::{
ratification_extra, ratification_quorum, validation_extra,
validation_quorum, MAX_NUMBER_OF_TRANSACTIONS,
Expand Down Expand Up @@ -44,12 +46,6 @@ use crate::http::RuesEvent;
use crate::Error::InvalidCreditsCount;
use crate::{Error, Result};

pub static DUSK_KEY: LazyLock<BlsPublicKey> = LazyLock::new(|| {
let dusk_cpk_bytes = include_bytes!("../../assets/dusk.cpk");
BlsPublicKey::from_slice(dusk_cpk_bytes)
.expect("Dusk consensus public key to be valid")
});

const DEFAULT_GAS_PER_DEPLOY_BYTE: u64 = 100;
const DEFAULT_MIN_DEPLOYMENT_GAS_PRICE: u64 = 2000;

Expand Down Expand Up @@ -396,12 +392,12 @@ impl Rusk {
pub fn provisioners(
&self,
base_commit: Option<[u8; 32]>,
) -> Result<impl Iterator<Item = (BlsPublicKey, StakeData)>> {
) -> Result<impl Iterator<Item = (StakeKeys, StakeData)>> {
let (sender, receiver) = mpsc::channel();
self.feeder_query(STAKE_CONTRACT, "stakes", &(), sender, base_commit)?;
Ok(receiver.into_iter().map(|bytes| {
rkyv::from_bytes::<(BlsPublicKey, StakeData)>(&bytes).expect(
"The contract should only return (pk, stake_data) tuples",
rkyv::from_bytes::<(StakeKeys, StakeData)>(&bytes).expect(
"The contract should only return (StakeKeys, StakeData) tuples",
)
}))
}
Expand Down Expand Up @@ -825,7 +821,7 @@ fn reward_slash_and_update_root(
});

rewards.push(Reward {
account: *DUSK_KEY,
account: *DUSK_CONSENSUS_KEY,
value: dusk_value,
reason: RewardReason::Other,
});
Expand Down
2 changes: 1 addition & 1 deletion rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Rusk {
.provisioners(base_commit)
.map_err(|e| anyhow::anyhow!("Cannot get provisioners {e}"))?
.map(|(pk, stake)| {
(node_data::bls::PublicKey::new(pk), Self::to_stake(stake))
(PublicKey::new(pk.account), Self::to_stake(stake))
});
let mut ret = Provisioners::empty();
for (pubkey_bls, stake) in provisioners {
Expand Down
13 changes: 11 additions & 2 deletions rusk/tests/common/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ use rand::prelude::*;
use rand::rngs::StdRng;
use tracing::info;

use execution_core::signatures::bls::SecretKey as BlsSecretKey;
use dusk_bytes::Serializable;
use execution_core::signatures::bls::{
PublicKey as BlsPublicKey, SecretKey as BlsSecretKey,
};

#[allow(dead_code)]
pub static STAKE_SK: LazyLock<BlsSecretKey> = LazyLock::new(|| {
info!("Generating BlsSecretKey");
let mut rng = StdRng::seed_from_u64(0xdead);

BlsSecretKey::random(&mut rng)
let sk = BlsSecretKey::random(&mut rng);
let pk = BlsPublicKey::from(&sk);
info!(
"Generated BlsSecretKey for BlsPublicKey {}",
bs58::encode(pk.to_bytes()).into_string()
);
sk
});
4 changes: 4 additions & 0 deletions rusk/tests/config/slash.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ notes = [
address = "qe1FbZxf6YaCAeFNSvL1G82cBhG4Q4gBf4vKYo527Vws3b23jdbBuzKSFsdUHnZeBgsTnyNJLkApEpRyJw87sdzR9g9iESJrG5ZgpCs9jq88m6d4qMY5txGpaXskRQmkzE3"
amount = 20_000_000_000
reward = 3_000_000_000

[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0
4 changes: 4 additions & 0 deletions rusk/tests/config/stake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ amount = 1_000_000_000_000
address = "25omWWRyfcMjYNbQZVyc3rypYLi8UqZuthoJHqbCEriRX3z2EmnBaXWZLFL2NvzvDnkoYoHLGiSYQpmupNJj1sSdWNstqzfFEpiqvSNYw7gqvoEiU9FsEHUMG1ZyG3XgL8Rv"
amount = 1_000_000_000_000
reward = 1_000_000_000_000

[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

0 comments on commit 2cf892c

Please sign in to comment.