Skip to content

Commit

Permalink
rusk: add get_provisioners_change impl
Browse files Browse the repository at this point in the history
Resolves #1516
  • Loading branch information
herr-seppia committed Apr 12, 2024
1 parent d3bf46d commit c71a1a4
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions rusk/src/lib/chain/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

mod query;

use node_data::bls::PublicKey;
use phoenix_core::transaction::StakeData;
use tracing::info;

use dusk_bytes::DeserializableSlice;
Expand Down Expand Up @@ -141,6 +143,13 @@ impl VMExecution for Rusk {
self.query_provisioners(Some(base_commit))
}

fn get_changed_provisioners(
&self,
base_commit: [u8; 32],
) -> anyhow::Result<Vec<(PublicKey, Option<Stake>)>> {
self.query_provisioners_change(Some(base_commit))
}

fn get_provisioner(
&self,
pk: &dusk_bls12_381_sign::PublicKey,
Expand Down Expand Up @@ -189,12 +198,8 @@ impl Rusk {
let provisioners = self
.provisioners(base_commit)
.map_err(|e| anyhow::anyhow!("Cannot get provisioners {e}"))?
.map(|(key, stake)| {
let (value, eligibility) = stake.amount.unwrap_or_default();
let stake =
Stake::new(value, stake.reward, eligibility, stake.counter);
let pubkey_bls = node_data::bls::PublicKey::new(key);
(pubkey_bls, stake)
.map(|(pk, stake)| {
(node_data::bls::PublicKey::new(pk), Self::to_stake(stake))
});
let mut ret = Provisioners::empty();
for (pubkey_bls, stake) in provisioners {
Expand All @@ -203,4 +208,29 @@ impl Rusk {

Ok(ret)
}

fn query_provisioners_change(
&self,
base_commit: Option<[u8; 32]>,
) -> anyhow::Result<Vec<(node_data::bls::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),
)
})
.collect())
}

fn to_stake(stake: StakeData) -> Stake {
let (value, eligibility) = stake.amount.unwrap_or_default();
Stake::new(value, stake.reward, eligibility, stake.counter)
}
}

0 comments on commit c71a1a4

Please sign in to comment.