Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add moonlight transactions #1930

Merged
merged 12 commits into from
Jul 22, 2024
9 changes: 4 additions & 5 deletions consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ mod tests {
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use dusk_bytes::DeserializableSlice;
use execution_core::{StakePublicKey, StakeSecretKey};
use execution_core::{BlsPublicKey, BlsSecretKey};
use hex::FromHex;
use node_data::ledger::{Header, Seed};
use std::collections::HashMap;
Expand Down Expand Up @@ -246,7 +246,7 @@ mod tests {
.iter()
.map(|hex| hex::decode(hex).expect("valid hex"))
.map(|data| {
StakeSecretKey::from_slice(&data[..]).expect("valid secret key")
BlsSecretKey::from_slice(&data[..]).expect("valid secret key")
})
.collect();

Expand All @@ -267,9 +267,8 @@ mod tests {
tip_header.height = 0;

for secret_key in sks {
let pubkey_bls = node_data::bls::PublicKey::new(
StakePublicKey::from(&secret_key),
);
let pubkey_bls =
node_data::bls::PublicKey::new(BlsPublicKey::from(&secret_key));

p.add_member_with_value(pubkey_bls.clone(), 1000 * DUSK);

Expand Down
9 changes: 5 additions & 4 deletions consensus/src/commons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ use std::collections::HashMap;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use thiserror::Error;

use crate::operations::VoterWithCredits;
use execution_core::{BlsSigError, StakeSecretKey};
use execution_core::{BlsSecretKey, BlsSigError};
use node_data::bls::PublicKey;
use node_data::message::{AsyncQueue, Message, Payload};
use node_data::StepName;
use tracing::error;

use crate::operations::VoterWithCredits;

pub type TimeoutSet = HashMap<StepName, Duration>;

#[derive(Clone, Default, Debug)]
Expand All @@ -30,7 +31,7 @@ pub struct RoundUpdate {

// This provisioner consensus keys
pub pubkey_bls: PublicKey,
pub secret_key: StakeSecretKey,
pub secret_key: BlsSecretKey,

seed: Seed,
hash: [u8; 32],
Expand All @@ -44,7 +45,7 @@ pub struct RoundUpdate {
impl RoundUpdate {
pub fn new(
pubkey_bls: PublicKey,
secret_key: StakeSecretKey,
secret_key: BlsSecretKey,
tip_header: &Header,
base_timeouts: TimeoutSet,
att_voters: Vec<VoterWithCredits>,
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use std::fmt;
use std::io;
use std::time::Duration;

use execution_core::StakePublicKey;
use node_data::ledger::Fault;
use node_data::ledger::InvalidFault;
use node_data::ledger::{Block, Header, Slash, SpentTransaction, Transaction};
use execution_core::BlsPublicKey;
use node_data::ledger::{
Block, Fault, Header, InvalidFault, Slash, SpentTransaction, Transaction,
};
use node_data::StepName;
use thiserror::Error;

pub type StateRoot = [u8; 32];
pub type EventHash = [u8; 32];
pub type VoterWithCredits = (StakePublicKey, usize);
pub type VoterWithCredits = (BlsPublicKey, usize);

#[derive(Debug, Error)]
pub enum Error {
Expand Down
10 changes: 5 additions & 5 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::user::sortition;

use crate::config::CONSENSUS_MAX_ITER;
use dusk_bytes::Serializable as BytesSerializable;
use execution_core::{StakeAggPublicKey, StakeSignature};
use execution_core::{BlsAggPublicKey, BlsSignature};
use tokio::sync::RwLock;
use tracing::error;

Expand Down Expand Up @@ -177,13 +177,13 @@ pub fn verify_votes(
}

impl Cluster<PublicKey> {
fn aggregate_pks(&self) -> Result<StakeAggPublicKey, StepSigError> {
fn aggregate_pks(&self) -> Result<BlsAggPublicKey, StepSigError> {
let pks: Vec<_> =
self.iter().map(|(pubkey, _)| *pubkey.inner()).collect();

match pks.split_first() {
Some((first, rest)) => {
let mut apk = StakeAggPublicKey::from(first);
let mut apk = BlsAggPublicKey::from(first);
apk.aggregate(rest)?;
Ok(apk)
}
Expand All @@ -196,7 +196,7 @@ fn verify_step_signature(
header: &ConsensusHeader,
step: StepName,
vote: &Vote,
apk: StakeAggPublicKey,
apk: BlsAggPublicKey,
signature: &[u8; 48],
) -> Result<(), StepSigError> {
// Compile message to verify
Expand All @@ -206,7 +206,7 @@ fn verify_step_signature(
StepName::Proposal => Err(StepSigError::InvalidType)?,
};

let sig = StakeSignature::from_bytes(signature)?;
let sig = BlsSignature::from_bytes(signature)?;
let mut msg = header.signable();
msg.extend_from_slice(sign_seed);
vote.write(&mut msg).expect("Writing to vec should succeed");
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/user/sortition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ mod tests {
use crate::user::provisioners::{Provisioners, DUSK};
use crate::user::sortition::Config;
use dusk_bytes::DeserializableSlice;
use execution_core::{StakePublicKey, StakeSecretKey};
use execution_core::{BlsPublicKey, BlsSecretKey};

use node_data::ledger::Seed;

Expand Down Expand Up @@ -298,15 +298,15 @@ mod tests {
.take(n)
.map(|hex| hex::decode(hex).expect("valid hex"))
.map(|data| {
StakeSecretKey::from_slice(&data[..]).expect("valid secret key")
BlsSecretKey::from_slice(&data[..]).expect("valid secret key")
})
.collect();

let mut p = Provisioners::empty();
for (i, sk) in sks.iter().enumerate().skip(1) {
let stake_value = 1000 * (i) as u64 * DUSK;
let stake_pk =
node_data::bls::PublicKey::new(StakePublicKey::from(sk));
node_data::bls::PublicKey::new(BlsPublicKey::from(sk));
p.add_member_with_value(stake_pk, stake_value);
}
p
Expand Down
6 changes: 3 additions & 3 deletions consensus/src/user/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Stake {
value: u64,

pub reward: u64,
pub counter: u64,
pub nonce: u64,
pub eligible_since: u64,
}

Expand All @@ -18,13 +18,13 @@ impl Stake {
value: u64,
reward: u64,
eligible_since: u64,
counter: u64,
nonce: u64,
) -> Self {
Self {
value,
reward,
eligible_since,
counter,
nonce,
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/alice/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use execution_core::transfer::Mint;
use execution_core::transfer::Withdraw;
use rusk_abi::TRANSFER_CONTRACT;

/// Alice contract.
Expand All @@ -16,8 +16,8 @@ impl Alice {
// no-op
}

pub fn withdraw(&mut self, mint: Mint) {
let _: () = rusk_abi::call(TRANSFER_CONTRACT, "withdraw", &mint)
pub fn withdraw(&mut self, withdraw: Withdraw) {
let _: () = rusk_abi::call(TRANSFER_CONTRACT, "withdraw", &withdraw)
.expect("Transparent withdrawal transaction should succeed");
}

Expand Down
14 changes: 7 additions & 7 deletions contracts/stake/benches/get_provisioners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use criterion::{criterion_group, criterion_main, Criterion};
use execution_core::{stake::StakeData, StakePublicKey, StakeSecretKey};
use execution_core::{stake::StakeData, BlsPublicKey, BlsSecretKey};
use rand::rngs::StdRng;
use rand::{CryptoRng, RngCore, SeedableRng};
use rusk_abi::{
Expand Down Expand Up @@ -66,7 +66,7 @@ fn instantiate(vm: &VM) -> Session {

fn do_get_provisioners(
session: &mut Session,
) -> Result<impl Iterator<Item = (StakePublicKey, StakeData)>, Error> {
) -> Result<impl Iterator<Item = (BlsPublicKey, StakeData)>, Error> {
let (sender, receiver) = mpsc::channel();
session.feeder_call::<_, ()>(
STAKE_CONTRACT,
Expand All @@ -76,7 +76,7 @@ fn do_get_provisioners(
sender,
)?;
Ok(receiver.into_iter().map(|bytes| {
rkyv::from_bytes::<(StakePublicKey, StakeData)>(&bytes)
rkyv::from_bytes::<(BlsPublicKey, StakeData)>(&bytes)
.expect("The contract should only return (pk, stake_data) tuples")
}))
}
Expand All @@ -87,11 +87,11 @@ fn do_insert_stake<Rng: RngCore + CryptoRng>(
) -> Result<(), Error> {
let stake_data = StakeData {
amount: Some((TEST_STAKE, 0)),
counter: 1,
nonce: 1,
reward: 0,
};
let sk = StakeSecretKey::random(rng);
let pk = StakePublicKey::from(&sk);
let sk = BlsSecretKey::random(rng);
let pk = BlsPublicKey::from(&sk);
session.call::<_, ()>(
STAKE_CONTRACT,
"insert_stake",
Expand All @@ -116,7 +116,7 @@ fn get_provisioners(c: &mut Criterion) {

c.bench_function("get_provisioners", |b| {
b.iter(|| {
let _: Vec<(StakePublicKey, StakeData)> =
let _: Vec<(BlsPublicKey, StakeData)> =
do_get_provisioners(&mut session)
.expect("getting provisioners should succeed")
.collect();
Expand Down
5 changes: 1 addition & 4 deletions contracts/stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use state::StakeState;
/// The minimum amount of Dusk one can stake.
pub const MINIMUM_STAKE: Dusk = dusk(1_000.0);

use execution_core::StakePublicKey;
use rusk_abi::{ContractId, PaymentInfo};

#[no_mangle]
Expand Down Expand Up @@ -56,9 +55,7 @@ unsafe fn withdraw(arg_len: u32) -> u32 {

#[no_mangle]
unsafe fn get_stake(arg_len: u32) -> u32 {
rusk_abi::wrap_call(arg_len, |pk: StakePublicKey| {
STATE.get_stake(&pk).cloned()
})
rusk_abi::wrap_call(arg_len, |pk| STATE.get_stake(&pk).cloned())
}

#[no_mangle]
Expand Down
Loading
Loading