From cda14ac8b941627770145a200ef3e8b6c3705fb7 Mon Sep 17 00:00:00 2001 From: Justin Berman Date: Mon, 19 Feb 2024 18:03:27 -0800 Subject: [PATCH] monero: Use fee priority enums from monero repo CLI/RPC wallets (#499) * monero: Use fee priority enums from monero repo CLI/RPC wallets * Update processor for fee priority change * Remove FeePriority::Default Done in consultation with @j-berman. The RPC/CLI/GUI almost always adjust up except barring very explicit commands, hence why FeePriority 0 is now only exposed via the explicit command of FeePriority::Custom { priority: 0 }. Also helps with terminology. --------- Co-authored-by: Luke Parker --- coins/monero/src/wallet/send/mod.rs | 18 ++++++++++-------- coins/monero/tests/runner.rs | 2 +- coins/monero/tests/send.rs | 4 ++-- coins/monero/tests/wallet2_compatibility.rs | 4 +--- processor/src/networks/monero.rs | 2 +- tests/full-stack/src/tests/mint_and_burn.rs | 2 +- tests/processor/src/networks.rs | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/coins/monero/src/wallet/send/mod.rs b/coins/monero/src/wallet/send/mod.rs index ff4cfd72..f4ac208e 100644 --- a/coins/monero/src/wallet/send/mod.rs +++ b/coins/monero/src/wallet/send/mod.rs @@ -274,20 +274,22 @@ impl Fee { #[derive(Clone, Copy, PartialEq, Eq, Debug)] #[allow(non_camel_case_types)] pub enum FeePriority { - Lowest, - Low, - Medium, - High, + Unimportant, + Normal, + Elevated, + Priority, Custom { priority: u32 }, } +/// https://github.com/monero-project/monero/blob/ac02af92867590ca80b2779a7bbeafa99ff94dcb/ +/// src/simplewallet/simplewallet.cpp#L161 impl FeePriority { pub(crate) fn fee_priority(&self) -> u32 { match self { - FeePriority::Lowest => 0, - FeePriority::Low => 1, - FeePriority::Medium => 2, - FeePriority::High => 3, + FeePriority::Unimportant => 1, + FeePriority::Normal => 2, + FeePriority::Elevated => 3, + FeePriority::Priority => 4, FeePriority::Custom { priority, .. } => *priority, } } diff --git a/coins/monero/tests/runner.rs b/coins/monero/tests/runner.rs index ff80656e..f99fb7b1 100644 --- a/coins/monero/tests/runner.rs +++ b/coins/monero/tests/runner.rs @@ -212,7 +212,7 @@ macro_rules! test { let builder = SignableTransactionBuilder::new( protocol, - rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), + rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(), Change::new( &ViewPair::new( &random_scalar(&mut OsRng) * ED25519_BASEPOINT_TABLE, diff --git a/coins/monero/tests/send.rs b/coins/monero/tests/send.rs index ca4ea5ad..ece54737 100644 --- a/coins/monero/tests/send.rs +++ b/coins/monero/tests/send.rs @@ -110,7 +110,7 @@ test!( let mut builder = SignableTransactionBuilder::new( protocol, - rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), + rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(), Change::new(&change_view, false), ); add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await; @@ -294,7 +294,7 @@ test!( let mut builder = SignableTransactionBuilder::new( protocol, - rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), + rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(), Change::fingerprintable(None), ); add_inputs(protocol, &rpc, vec![outputs.first().unwrap().clone()], &mut builder).await; diff --git a/coins/monero/tests/wallet2_compatibility.rs b/coins/monero/tests/wallet2_compatibility.rs index 9f9892f8..2002f3bd 100644 --- a/coins/monero/tests/wallet2_compatibility.rs +++ b/coins/monero/tests/wallet2_compatibility.rs @@ -90,9 +90,7 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) { // TODO: Needs https://github.com/monero-project/monero/pull/8882 // let fee_rate = daemon_rpc - // // Uses `FeePriority::Low` instead of `FeePriority::Lowest` because wallet RPC - // // adjusts `monero_rpc::TransferPriority::Default` up by 1 - // .get_fee(daemon_rpc.get_protocol().await.unwrap(), FeePriority::Low) + // .get_fee(daemon_rpc.get_protocol().await.unwrap(), FeePriority::Unimportant) // .await // .unwrap(); diff --git a/processor/src/networks/monero.rs b/processor/src/networks/monero.rs index 1659bd5a..1def02ea 100644 --- a/processor/src/networks/monero.rs +++ b/processor/src/networks/monero.rs @@ -761,7 +761,7 @@ impl Network for Monero { vec![(address.into(), amount - fee)], &Change::fingerprintable(Some(Self::test_address().into())), vec![], - self.rpc.get_fee(protocol, FeePriority::Low).await.unwrap(), + self.rpc.get_fee(protocol, FeePriority::Unimportant).await.unwrap(), ) .unwrap() .sign(&mut OsRng, &Zeroizing::new(Scalar::ONE.0)) diff --git a/tests/full-stack/src/tests/mint_and_burn.rs b/tests/full-stack/src/tests/mint_and_burn.rs index 0421cd97..6ce22e8c 100644 --- a/tests/full-stack/src/tests/mint_and_burn.rs +++ b/tests/full-stack/src/tests/mint_and_burn.rs @@ -389,7 +389,7 @@ async fn mint_and_burn_test() { )], &Change::new(&view_pair, false), vec![Shorthand::transfer(None, serai_addr).encode()], - rpc.get_fee(Protocol::v16, FeePriority::Low).await.unwrap(), + rpc.get_fee(Protocol::v16, FeePriority::Unimportant).await.unwrap(), ) .unwrap() .sign(&mut OsRng, &Zeroizing::new(Scalar::ONE)) diff --git a/tests/processor/src/networks.rs b/tests/processor/src/networks.rs index 5b912593..e0aec77f 100644 --- a/tests/processor/src/networks.rs +++ b/tests/processor/src/networks.rs @@ -342,7 +342,7 @@ impl Wallet { vec![(to_addr, AMOUNT)], &Change::new(view_pair, false), data, - rpc.get_fee(Protocol::v16, FeePriority::Low).await.unwrap(), + rpc.get_fee(Protocol::v16, FeePriority::Unimportant).await.unwrap(), ) .unwrap() .sign(&mut OsRng, spend_key)