Skip to content

Commit

Permalink
rusk-recovery: add DUSK key to the genesis stake state
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Sep 9, 2024
1 parent b18c5b3 commit 68c80e8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 19 additions & 1 deletion rusk-recovery/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ pub static FAUCET_KEY: Lazy<PublicKey> = Lazy::new(|| {
PublicKey::from_slice(&bytes).expect("faucet should have a valid key")
});

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

fn generate_transfer_state(
session: &mut Session,
snapshot: &Snapshot,
Expand Down Expand Up @@ -121,6 +127,18 @@ fn generate_stake_state(
snapshot: &Snapshot,
) -> Result<(), Box<dyn Error>> {
let theme = Theme::default();
session
.call::<_, ()>(
STAKE_CONTRACT,
"insert_stake",
&(
*DUSK_CONSENSUS_KEY,
*DUSK_CONSENSUS_KEY,
StakeData::default(),
),
u64::MAX,
)
.expect("stake to be inserted into the state");
snapshot.stakes().enumerate().for_each(|(idx, staker)| {
info!("{} provisioner #{}", theme.action("Generating"), idx);

Expand All @@ -142,7 +160,7 @@ fn generate_stake_state(
.call::<_, ()>(
STAKE_CONTRACT,
"insert_stake",
&(*staker.address(), stake),
&(staker.to_stake_keys(), stake),
u64::MAX,
)
.expect("stake to be inserted into the state");
Expand Down
11 changes: 10 additions & 1 deletion rusk-recovery/src/state/snapshot/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use dusk_bytes::Serializable;
use serde_derive::{Deserialize, Serialize};

use execution_core::{signatures::bls::PublicKey as BlsPublicKey, Dusk};
use execution_core::{
signatures::bls::PublicKey as BlsPublicKey, stake::StakeKeys, Dusk,
};

use super::wrapper::Wrapper;

Expand All @@ -23,4 +25,11 @@ impl GenesisStake {
pub fn address(&self) -> &BlsPublicKey {
&self.address
}

pub fn to_stake_keys(&self) -> StakeKeys {
StakeKeys {
account: *self.address(),
funds: *self.address(),
}
}
}

0 comments on commit 68c80e8

Please sign in to comment.