Skip to content

Commit

Permalink
Merge branch 'murisi/masp-generic-amounts-rebased' (#1842)
Browse files Browse the repository at this point in the history
* origin/murisi/masp-generic-amounts-rebased:
  Switching to generic Amount branch of MASP crate.
  • Loading branch information
Fraccaman committed Sep 6, 2023
2 parents 69df362 + 6ed7b2d commit 5237106
Show file tree
Hide file tree
Showing 29 changed files with 128 additions and 185 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Upgraded the MASP crate commit used by Namada to the latest version.
([\#1842](https://github.com/anoma/namada/pull/1842))
58 changes: 4 additions & 54 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ libc = "0.2.97"
libloading = "0.7.2"
libsecp256k1 = {git = "https://github.com/heliaxdev/libsecp256k1", rev = "bbb3bd44a49db361f21d9db80f9a087c194c0ae9", default-features = false, features = ["std", "static-context"]}
# branch = "murisi/namada-integration"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "252a6059565b125c1444e9e7d0b7c8da0fba8f8f" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "252a6059565b125c1444e9e7d0b7c8da0fba8f8f", default-features = false, features = ["local-prover"] }
masp_primitives = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "50acc5028fbcd52a05970fe7991c7850ab04358e", default-features = false, features = ["local-prover"] }
num256 = "0.3.5"
num_cpus = "1.13.0"
num-derive = "0.3.3"
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,13 +1843,13 @@ pub async fn query_conversions<C: namada::ledger::queries::Client + Sync>(
// Track whether any non-sentinel conversions are found
let mut conversions_found = false;
for ((addr, _), epoch, conv, _) in conv_state.assets.values() {
let amt: masp_primitives::transaction::components::Amount =
let amt: masp_primitives::transaction::components::I32Sum =
conv.clone().into();
// If the user has specified any targets, then meet them
// If we have a sentinel conversion, then skip printing
if matches!(&target_token, Some(target) if target != addr)
|| matches!(&args.epoch, Some(target) if target != epoch)
|| amt == masp_primitives::transaction::components::Amount::zero()
|| amt.is_zero()
{
continue;
}
Expand Down Expand Up @@ -1893,7 +1893,7 @@ pub async fn query_conversion<C: namada::ledger::queries::Client + Sync>(
Address,
MaspDenom,
Epoch,
masp_primitives::transaction::components::Amount,
masp_primitives::transaction::components::I32Sum,
MerklePath<Node>,
)> {
namada::ledger::rpc::query_conversion(client, asset_type).await
Expand Down
35 changes: 0 additions & 35 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,38 +1460,3 @@ pub async fn submit_tx(
) -> Result<TxResponse, tx::Error> {
tx::submit_tx(client, to_broadcast).await
}

#[cfg(test)]
mod test_tx {
use masp_primitives::transaction::components::Amount;
use namada::core::types::storage::Epoch;
use namada::ledger::masp::{make_asset_type, MaspAmount};
use namada::types::address::testing::gen_established_address;
use namada::types::token::MaspDenom;

#[test]
fn test_masp_add_amount() {
let address_1 = gen_established_address();
let denom_1 = MaspDenom::One;
let denom_2 = MaspDenom::Three;
let epoch = Epoch::default();
let _masp_amount = MaspAmount::default();

let asset_base = make_asset_type(Some(epoch), &address_1, denom_1);
let _asset_denom = make_asset_type(Some(epoch), &address_1, denom_2);
let _asset_prefix = make_asset_type(Some(epoch), &address_1, denom_1);

let _amount_base =
Amount::from_pair(asset_base, 16).expect("Test failed");
let _amount_denom =
Amount::from_pair(asset_base, 2).expect("Test failed");
let _amount_prefix =
Amount::from_pair(asset_base, 4).expect("Test failed");

// masp_amount += amount_base;
// assert_eq!(masp_amount.get((epoch,)), Uint::zero());
// Amount::from_pair(atype, amount)
// MaspDenom::One
// assert_eq!(zero.abs(), Uint::zero());
}
}
10 changes: 6 additions & 4 deletions core/src/ledger/storage/masp_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
H: 'static + super::StorageHasher,
{
use masp_primitives::ff::PrimeField;
use masp_primitives::transaction::components::Amount as MaspAmount;
use masp_primitives::transaction::components::I32Sum as MaspAmount;
use rayon::iter::{
IndexedParallelIterator, IntoParallelIterator, ParallelIterator,
};
Expand Down Expand Up @@ -92,9 +92,11 @@ where
);
current_convs.insert(
(addr.clone(), denom),
(MaspAmount::from_pair(old_asset, -(reward.1 as i64)).unwrap()
+ MaspAmount::from_pair(new_asset, reward.1).unwrap()
+ MaspAmount::from_pair(reward_asset, reward.0).unwrap())
(MaspAmount::from_pair(old_asset, -(reward.1 as i32)).unwrap()
+ MaspAmount::from_pair(new_asset, reward.1 as i32)
.unwrap()
+ MaspAmount::from_pair(reward_asset, reward.0 as i32)
.unwrap())
.into(),
);
// Add a conversion from the previous asset type
Expand Down
2 changes: 1 addition & 1 deletion core/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ pub fn tokens() -> HashMap<Address, (&'static str, Denomination)> {
/// Temporary helper for testing, a hash map of tokens addresses with their
/// MASP XAN incentive schedules. If the reward is (a, b) then a rewarded tokens
/// are dispensed for every b possessed tokens.
pub fn masp_rewards() -> HashMap<Address, (u64, u64)> {
pub fn masp_rewards() -> HashMap<Address, (u32, u32)> {
vec![
(nam(), (0, 100)),
(btc(), (1, 100)),
Expand Down
14 changes: 14 additions & 0 deletions core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,20 @@ impl Mul<(u64, u64)> for Amount {
}
}

/// A combination of Euclidean division and fractions:
/// x*(a,b) = (a*(x//b), x%b).
impl Mul<(u32, u32)> for Amount {
type Output = (Amount, Amount);

fn mul(mut self, rhs: (u32, u32)) -> Self::Output {
let amt = Amount {
raw: (self.raw / rhs.1) * rhs.0,
};
self.raw %= rhs.1;
(amt, self)
}
}

impl Div<u64> for Amount {
type Output = Self;

Expand Down
Loading

0 comments on commit 5237106

Please sign in to comment.