Skip to content

Commit

Permalink
Corrections, stale files
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Sep 2, 2024
1 parent c520a9e commit 9fb8d5a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 107 deletions.
2 changes: 2 additions & 0 deletions rusk-wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ reqwest = { version = "0.11", features = ["stream"] }
dusk-bytes = "0.1"

wallet-core = { version = "0.1", path = "../wallet-core" }
execution-core = { version = "0.1", path = "../execution-core" }


tracing = "0.1"
tracing-subscriber = { version = "0.3.0", features = [
Expand Down
25 changes: 13 additions & 12 deletions rusk-wallet/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod sync;
use dusk_bytes::Serializable;
use flume::Receiver;
use tokio::time::{sleep, Duration};
use wallet_core::input::{try_input_notes, Inputs};
use wallet_core::input::try_input_notes;
use wallet_core::prelude::{Error as WalletCoreError, *};

use std::path::Path;
Expand Down Expand Up @@ -43,6 +43,7 @@ pub struct Prover;

impl Prove for Prover {
fn prove(tx_circuit_vec_bytes: &[u8]) -> Result<Vec<u8>, WalletCoreError> {
// delegate proving to the prover
let prover = RuskHttpClient::new("http://127.0.0.1:8080".to_string());
let prove_req =
RuskRequest::new("prove_execute", tx_circuit_vec_bytes.to_owned());
Expand Down Expand Up @@ -158,7 +159,7 @@ impl State {
target: u64,
) -> Result<Vec<(Note, Opening)>, Error> {
if let Some((_, vk, pk)) = self.addresses.get(index as usize) {
let inputs: Result<Inputs, Error> = self
let inputs: Result<Vec<(Note, u64)>, Error> = self
.cache()
.notes(pk)?
.into_iter()
Expand All @@ -170,9 +171,9 @@ impl State {
})
.collect();

try_input_notes(inputs?, target)?
try_input_notes(inputs?, target)
.into_iter()
.map(|(note, _)| {
.map(|note| {
let opening = self.fetch_opening(&note)?;

Ok((note, opening))
Expand All @@ -199,24 +200,24 @@ impl State {
.collect()
}

/// Fetch the current anchor of the state.
pub(crate) fn fetch_anchor(&self) -> Result<BlsScalar, Error> {
/// Fetch the current root of the state.
pub(crate) fn fetch_root(&self) -> Result<BlsScalar, Error> {
let status = self.status;
status("Fetching anchor...");
status("Fetching root...");

let anchor = self
let root = self
.client
.contract_query::<(), 0>(TRANSFER_CONTRACT, "root", &())
.wait()?;
status("Anchor received!");
let anchor = rkyv::from_bytes(&anchor).map_err(|_| Error::Rkyv)?;
Ok(anchor)
status("root received!");
let root = rkyv::from_bytes(&root).map_err(|_| Error::Rkyv)?;
Ok(root)
}

/// Queries the node for the amount staked by a key.
pub(crate) fn fetch_stake(
&self,
pk: &PhoenixPublicKey,
pk: &AccountPublicKey,
) -> Result<Option<StakeData>, Error> {
let status = self.status;
status("Fetching stake...");
Expand Down
4 changes: 3 additions & 1 deletion rusk-wallet/src/clients/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use crate::clients::{Addresses, Cache, TRANSFER_CONTRACT};
use crate::rusk::RuskHttpClient;
use crate::{Error, RuskRequest};

const TREE_LEAF: usize = size_of::<TreeLeaf>();
use execution_core::transfer::phoenix::ArchivedTreeLeaf;

const TREE_LEAF: usize = size_of::<ArchivedTreeLeaf>();

pub(crate) async fn sync_db(
client: &RuskHttpClient,
Expand Down
11 changes: 0 additions & 11 deletions rusk-wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,6 @@ impl From<CoreError> for Error {
}
}

impl From<wallet_core::input::InputNotesError> for Error {
fn from(e: wallet_core::input::InputNotesError) -> Self {
use wallet_core::input::InputNotesError::*;

match e {
TargetGreaterThanSum => Self::NoteCombinationProblem,
EmptyNotes => Self::AddressNotOwned,
}
}
}

impl From<rocksdb::Error> for Error {
fn from(e: rocksdb::Error) -> Self {
Self::RocksDB(e)
Expand Down
12 changes: 6 additions & 6 deletions rusk-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {

// retrieve keys
let sk = derive_phoenix_sk(&self.seed, index);
let pk = derive_phoenix_pk(&self.seed, index);
let pk = addr.pk().clone();

Ok((pk, sk))
}
Expand Down Expand Up @@ -308,7 +308,7 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {

let index = addr.index()?;
let vk = derive_phoenix_vk(&self.seed, index);
let pk = derive_phoenix_pk(&self.seed, index);
let pk = addr.pk();

let live_notes = self.state()?.fetch_notes(&pk)?;
let spent_notes = self.state()?.cache().spent_notes(&pk)?;
Expand Down Expand Up @@ -434,17 +434,17 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
let amt = *amt;

let sender_sk = derive_phoenix_sk(&self.seed, sender_index);
let change_pk = derive_phoenix_pk(&self.seed, sender_index);
let change_pk = sender.pk();
let reciever_pk = rcvr.pk();

let inputs = state.inputs(sender_index, amt + gas.limit * gas.price)?;

let root = state.fetch_anchor()?;
let root = state.fetch_root()?;

let tx = phoenix::<_, Prover>(
&mut rng,
&sender_sk,
&change_pk,
change_pk,
reciever_pk,
inputs,
root,
Expand Down Expand Up @@ -488,7 +488,7 @@ impl<F: SecureWalletFile + Debug> Wallet<F> {
let sender_pk = addr.pk();
let sender_sk = derive_phoenix_sk(&self.seed, sender_index);
let stake_sk = derive_bls_sk(&self.seed, sender_index);
let nonce = state.fetch_stake(sender_pk)?.map(|s| s.nonce).unwrap_or(0);
let nonce = state.fetch_stake(stake_sk)?.map(|s| s.nonce).unwrap_or(0);

let inputs = state.inputs(sender_index, amt + gas.limit * gas.price)?;

Expand Down
10 changes: 6 additions & 4 deletions rusk-wallet/src/wallet/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
//! This library contains the primitive related to the gas used for transaction
//! in the Dusk Network.
use crate::currency::Lux;

/// The minimum gas limit
pub const MIN_LIMIT: u64 = 350_000_000;

/// The default gas limit
pub const DEFAULT_LIMIT: u64 = 500_000_000;

/// The default gas price
pub const DEFAULT_PRICE: u64 = 1;
pub const DEFAULT_PRICE: Lux = 1;

#[derive(Debug)]
/// Gas price and limit for any transaction
pub struct Gas {
/// The gas price in [Lux]
pub price: u64,
pub price: Lux,
/// The gas limit
pub limit: u64,
}
Expand All @@ -42,15 +44,15 @@ impl Gas {
/// Set the price
pub fn set_price<T>(&mut self, price: T)
where
T: Into<Option<u64>>,
T: Into<Option<Lux>>,
{
self.price = price.into().unwrap_or(DEFAULT_PRICE);
}

/// Set the price and return the Gas
pub fn with_price<T>(mut self, price: T) -> Self
where
T: Into<u64>,
T: Into<Lux>,
{
self.price = price.into();
self
Expand Down
29 changes: 0 additions & 29 deletions rusk-wallet/tests/common.rs

This file was deleted.

10 changes: 0 additions & 10 deletions rusk-wallet/tests/transactions.rs

This file was deleted.

2 changes: 1 addition & 1 deletion wallet-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sha2 = { version = "0.10", default-features = false }
rand = { version = "0.8", default-features = false }
ff = { version = "0.13", default-features = false }
poseidon-merkle = { version = "0.7", features = ["rkyv-impl"] }
execution-core = { version = "0.1", path = "../execution-core/" }
execution-core = { version = "0.1", path = "../execution-core/", default-features = false }

[dev-dependencies]
rand = "0.8"
Expand Down
44 changes: 11 additions & 33 deletions wallet-core/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ use execution_core::JubJubScalar;
use ff::Field;
use rand::{CryptoRng, RngCore};

/// Note and the .value of the note seperated by u64
pub type Inputs = Vec<(Note, u64)>;

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, PartialEq)]
/// Error when calculating input notes for use in transaction
pub enum InputNotesError {
/// No notes were supplied
EmptyNotes,
/// The target was greater than the value of the notes
TargetGreaterThanSum,
}

/// Pick the notes to be used in a transaction from a vector of notes.
///
/// The resulting array is only 4 notes long, the argument of this function can
Expand All @@ -41,12 +28,9 @@ pub enum InputNotesError {
///
/// See `InputNotesError` type for possible errors
/// this function can yield.
pub fn try_input_notes(
nodes: Inputs,
target_sum: u64,
) -> Result<Inputs, InputNotesError> {
pub fn try_input_notes(nodes: Vec<(Note, u64)>, target_sum: u64) -> Vec<Note> {
if nodes.is_empty() {
return Err(InputNotesError::EmptyNotes);
return Vec::new();
}

let mut i = 0;
Expand All @@ -57,7 +41,7 @@ pub fn try_input_notes(
}

if sum < target_sum {
return Err(InputNotesError::TargetGreaterThanSum);
return Vec::new();
}

pick_notes(target_sum, nodes)
Expand All @@ -74,15 +58,12 @@ pub fn try_input_notes(
///
/// Note: it is presupposed that the input notes contain enough balance to
/// cover the given `value`.
fn pick_notes(
value: u64,
notes_and_values: Inputs,
) -> Result<Inputs, InputNotesError> {
fn pick_notes(value: u64, notes_and_values: Vec<(Note, u64)>) -> Vec<Note> {
let mut notes_and_values = notes_and_values;
let len = notes_and_values.len();

if len <= MAX_INPUT_NOTES {
return Ok(notes_and_values);
return notes_and_values.into_iter().map(|(note, _)| note).collect();
}

notes_and_values.sort_by(|(_, aval), (_, bval)| aval.cmp(bval));
Expand All @@ -93,18 +74,15 @@ fn pick_notes(
.sum::<u64>()
>= value
})
.map(|indices| {
indices
.into_iter()
.map(|index| notes_and_values[index].clone())
.collect()
})
.map(|index| notes_and_values[index].clone())
.map(|(n, _)| n)
.to_vec()
}

fn pick_lexicographic<F: Fn(&[usize; MAX_INPUT_NOTES]) -> bool>(
max_len: usize,
is_valid: F,
) -> Result<[usize; MAX_INPUT_NOTES], InputNotesError> {
) -> [usize; MAX_INPUT_NOTES] {
let mut indices = [0; MAX_INPUT_NOTES];
indices
.iter_mut()
Expand All @@ -113,7 +91,7 @@ fn pick_lexicographic<F: Fn(&[usize; MAX_INPUT_NOTES]) -> bool>(

loop {
if is_valid(&indices) {
return Ok(indices);
return indices;
}

let mut i = MAX_INPUT_NOTES - 1;
Expand All @@ -136,7 +114,7 @@ fn pick_lexicographic<F: Fn(&[usize; MAX_INPUT_NOTES]) -> bool>(
}
}

Err(InputNotesError::EmptyNotes)
[0; MAX_INPUT_NOTES]
}

/// Generate a note, useful for testing purposes
Expand Down
1 change: 1 addition & 0 deletions wallet-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub mod prelude {

pub use execution_core::{
dusk, from_dusk,
signatures::bls::PublicKey as AccountPublicKey,
stake::StakeData,
transfer::{
contract_exec::{ContractCall, ContractExec},
Expand Down

0 comments on commit 9fb8d5a

Please sign in to comment.