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

Murisi/reverse conversion at source #4288

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/4287-consolidate-dust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix underestimation of MASP balances
([\#4287](https://github.com/anoma/namada/pull/4287))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Simplify exchanging balance amounts to older epochs
([\#4288](https://github.com/anoma/namada/pull/4288))
1 change: 0 additions & 1 deletion crates/apps_lib/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ async fn query_shielded_balance(
context.client(),
context.io(),
&viewing_key,
masp_epoch,
)
.await
.unwrap()
Expand Down
35 changes: 23 additions & 12 deletions crates/core/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,35 @@ impl AssetData {

/// Give this pre-asset type the given epoch if already has an epoch. Return
/// the replaced value.
pub fn redate(&mut self, to: MaspEpoch) {
pub fn redate(self, to: MaspEpoch) -> Self {
if self.epoch.is_some() {
self.epoch = Some(to);
Self {
epoch: Some(to),
..self
}
} else {
self
}
}

/// Update the MaspEpoch to the next one
pub fn redate_to_next_epoch(&mut self) {
if let Some(ep) = self.epoch.as_mut() {
if let Some(next) = ep.next() {
*ep = next;
pub fn redate_to_next_epoch(self) -> Self {
if let Some(next) = self.epoch.as_ref().and_then(MaspEpoch::next) {
Self {
epoch: Some(next),
..self
}
} else {
self
}
}

/// Remove the epoch associated with this pre-asset type
pub fn undate(&mut self) {
self.epoch = None;
pub fn undate(self) -> Self {
Self {
epoch: None,
..self
}
}
}

Expand Down Expand Up @@ -1128,23 +1139,23 @@ mod test {

#[test]
fn test_masp_asset_data_basics() {
let mut data = AssetData {
let data = AssetData {
token: address::testing::nam(),
denom: Denomination(6),
position: MaspDigitPos::One,
epoch: None,
};

data.undate();
let data = data.undate();
assert!(data.epoch.is_none());

let epoch_0 = MaspEpoch::new(3);
data.redate(epoch_0);
let mut data = data.redate(epoch_0);
assert!(data.epoch.is_none());
data.epoch = Some(epoch_0);

let epoch_1 = MaspEpoch::new(5);
data.redate(epoch_1);
let data = data.redate(epoch_1);
assert_eq!(data.epoch, Some(epoch_1));
}

Expand Down
5 changes: 0 additions & 5 deletions crates/shielded_token/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,6 @@ pub type MaspAmount = ValueSum<(Option<MaspEpoch>, Address), token::Change>;
/// transaction
pub type SpentNotesTracker = HashMap<ViewingKey, HashSet<usize>>;

/// An extension of Option's cloned method for pair types
fn cloned_pair<T: Clone, U: Clone>((a, b): (&T, &U)) -> (T, U) {
(a.clone(), b.clone())
}

/// Represents the amount used of different conversions
pub type Conversions =
BTreeMap<AssetType, (AllowedConversion, MerklePath<Node>, i128)>;
Expand Down
Loading
Loading