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 21cdbc7 commit 69764d4
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 18 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
7 changes: 4 additions & 3 deletions rusk/src/lib/node/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::{mpsc, Arc, LazyLock};
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 sha3::{Digest, Sha3_256};
Expand Down Expand Up @@ -396,12 +397,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
14 changes: 5 additions & 9 deletions rusk/src/lib/node/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use execution_core::{
transfer::Transaction as ProtocolTransaction, Event,
};
use node::vm::VMExecution;
use node_data::bls::PublicKey;
use node_data::ledger::{Block, Slash, SpentTransaction, Transaction};

use super::Rusk;
Expand Down Expand Up @@ -189,7 +190,7 @@ impl VMExecution for Rusk {
fn get_changed_provisioners(
&self,
base_commit: [u8; 32],
) -> anyhow::Result<Vec<(node_data::bls::PublicKey, Option<Stake>)>> {
) -> anyhow::Result<Vec<(PublicKey, Option<Stake>)>> {
self.query_provisioners_change(Some(base_commit))
}

Expand Down Expand Up @@ -243,7 +244,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 All @@ -256,20 +257,15 @@ impl Rusk {
fn query_provisioners_change(
&self,
base_commit: Option<[u8; 32]>,
) -> anyhow::Result<Vec<(node_data::bls::PublicKey, Option<Stake>)>> {
) -> anyhow::Result<Vec<(PublicKey, Option<Stake>)>> {
info!("Received get_provisioners_change request");
Ok(self
.last_provisioners_change(base_commit)
.map_err(|e| {
anyhow::anyhow!("Cannot get provisioners change: {e}")
})?
.into_iter()
.map(|(pk, stake)| {
(
node_data::bls::PublicKey::new(pk),
stake.map(Self::to_stake),
)
})
.map(|(pk, stake)| (PublicKey::new(pk), stake.map(Self::to_stake)))
.collect())
}

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
});
7 changes: 4 additions & 3 deletions rusk/tests/config/bench.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[acl.stake]
owners = []
allowlist = []
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/contract_deployment.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/gas-behavior.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/multi_transfer.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/slash.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/stake.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/transfer.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down
5 changes: 5 additions & 0 deletions rusk/tests/config/unspendable.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Block generator address
[[stake]]
address = "owFNnhnMuPHhyQcZ1dAqC5wuScqnXGkrEZWRQvYBU9wwNFHmG32gRTFdZhYSgw98KzNqm7rpCBkwoL4nzCE6gqGB9BrjsDJx3UgfTk78CM8BBWsehXamPSPYcC9ynq8Pi3V"
amount = 0

[[phoenix_balance]]
address = "ivmscertKgRyX8wNMJJsQcSVEyPsfSMUQXSAgeAPQXsndqFq9Pmknzhm61QvcEEdxPaGgxDS4RHpb6KKccrnSKN"
seed = 57005
Expand Down

0 comments on commit 69764d4

Please sign in to comment.