From 2a5a502b8cfb9ce9fe2135f8827e07594f701981 Mon Sep 17 00:00:00 2001 From: Herr Seppia Date: Mon, 9 Sep 2024 16:17:50 +0200 Subject: [PATCH] rusk: support stake multisig --- rusk/src/lib/http/rusk.rs | 2 +- rusk/src/lib/node/rusk.rs | 20 ++++++++------------ rusk/src/lib/node/vm.rs | 2 +- rusk/tests/common/keys.rs | 13 +++++++++++-- rusk/tests/config/slash.toml | 4 ++++ rusk/tests/config/stake.toml | 4 ++++ 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/rusk/src/lib/http/rusk.rs b/rusk/src/lib/http/rusk.rs index 7c9a66edcc..2b4c80bfcd 100644 --- a/rusk/src/lib/http/rusk.rs +++ b/rusk/src/lib/http/rusk.rs @@ -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 { diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index 935270224d..6b9c316765 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -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, @@ -44,12 +46,6 @@ use crate::http::RuesEvent; use crate::Error::InvalidCreditsCount; use crate::{Error, Result}; -pub static DUSK_KEY: LazyLock = 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; @@ -396,12 +392,12 @@ impl Rusk { pub fn provisioners( &self, base_commit: Option<[u8; 32]>, - ) -> Result> { + ) -> Result> { 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", ) })) } @@ -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, }); diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index 2b8fcbfb45..c67c6c965e 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -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 { diff --git a/rusk/tests/common/keys.rs b/rusk/tests/common/keys.rs index 7815d79885..aa34c9d07a 100644 --- a/rusk/tests/common/keys.rs +++ b/rusk/tests/common/keys.rs @@ -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 = 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 }); diff --git a/rusk/tests/config/slash.toml b/rusk/tests/config/slash.toml index a25023954f..153c45fe1c 100644 --- a/rusk/tests/config/slash.toml +++ b/rusk/tests/config/slash.toml @@ -18,3 +18,7 @@ notes = [ address = "qe1FbZxf6YaCAeFNSvL1G82cBhG4Q4gBf4vKYo527Vws3b23jdbBuzKSFsdUHnZeBgsTnyNJLkApEpRyJw87sdzR9g9iESJrG5ZgpCs9jq88m6d4qMY5txGpaXskRQmkzE3" amount = 20_000_000_000 reward = 3_000_000_000 + +[[stake]] +address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V" +amount = 0 \ No newline at end of file diff --git a/rusk/tests/config/stake.toml b/rusk/tests/config/stake.toml index 9aca8ee612..5229b02283 100644 --- a/rusk/tests/config/stake.toml +++ b/rusk/tests/config/stake.toml @@ -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 \ No newline at end of file