From 8f5466cb1d85518ba80190fa312281321aa721ff Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 14 Nov 2023 16:33:59 +0200 Subject: [PATCH] feat: create min dust fee setting (#5947) Description --- Create a setting to ignore dust below a certain value/ Motivation and Context --- See https://github.com/tari-project/tari/issues/5807 Fixes: https://github.com/tari-project/tari/issues/5807 Fixes: #4501 --------- Co-authored-by: Brian Pearce --- base_layer/wallet/src/output_manager_service/config.rs | 3 +++ .../wallet/src/output_manager_service/input_selection.rs | 8 ++++++-- base_layer/wallet/src/output_manager_service/service.rs | 2 +- .../storage/sqlite_db/output_sql.rs | 2 ++ common/config/presets/d_console_wallet.toml | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/base_layer/wallet/src/output_manager_service/config.rs b/base_layer/wallet/src/output_manager_service/config.rs index 66c215e416..82330b8649 100644 --- a/base_layer/wallet/src/output_manager_service/config.rs +++ b/base_layer/wallet/src/output_manager_service/config.rs @@ -28,6 +28,8 @@ pub struct OutputManagerServiceConfig { /// If a large amount of tiny valued uT UTXOs are used as inputs to a transaction, the fee may be larger than the /// transaction amount. Set this value to `false` to allow spending of "dust" UTXOs for small valued transactions. pub prevent_fee_gt_amount: bool, + /// Ignores dust below this value, value in micro MinoTari + pub dust_ignore_value: u64, /// This is the size of the event channel used to communicate output manager events to the wallet. pub event_channel_size: usize, /// The number of confirmations (difference between tip height and mined height) required for the output to be @@ -49,6 +51,7 @@ impl Default for OutputManagerServiceConfig { fn default() -> Self { Self { prevent_fee_gt_amount: true, + dust_ignore_value: 100, event_channel_size: 250, num_confirmations_required: 3, tx_validator_batch_size: 100, diff --git a/base_layer/wallet/src/output_manager_service/input_selection.rs b/base_layer/wallet/src/output_manager_service/input_selection.rs index c29b32c9b3..fdd0f2cc11 100644 --- a/base_layer/wallet/src/output_manager_service/input_selection.rs +++ b/base_layer/wallet/src/output_manager_service/input_selection.rs @@ -40,22 +40,25 @@ pub struct UtxoSelectionCriteria { pub filter: UtxoSelectionFilter, pub ordering: UtxoSelectionOrdering, pub excluding: Vec, + pub min_dust: u64, pub excluding_onesided: bool, } impl UtxoSelectionCriteria { - pub fn smallest_first() -> Self { + pub fn smallest_first(min_dust: u64) -> Self { Self { filter: UtxoSelectionFilter::Standard, ordering: UtxoSelectionOrdering::SmallestFirst, + min_dust, ..Default::default() } } - pub fn largest_first() -> Self { + pub fn largest_first(min_dust: u64) -> Self { Self { filter: UtxoSelectionFilter::Standard, ordering: UtxoSelectionOrdering::LargestFirst, + min_dust, ..Default::default() } } @@ -64,6 +67,7 @@ impl UtxoSelectionCriteria { Self { filter: UtxoSelectionFilter::SpecificOutputs { commitments }, ordering: UtxoSelectionOrdering::Default, + min_dust: 0, ..Default::default() } } diff --git a/base_layer/wallet/src/output_manager_service/service.rs b/base_layer/wallet/src/output_manager_service/service.rs index 3de89bcaa6..497c901692 100644 --- a/base_layer/wallet/src/output_manager_service/service.rs +++ b/base_layer/wallet/src/output_manager_service/service.rs @@ -1607,7 +1607,7 @@ where let selection = self .select_utxos( amount_per_split * MicroMinotari(number_of_splits as u64), - UtxoSelectionCriteria::largest_first(), + UtxoSelectionCriteria::largest_first(self.resources.config.dust_ignore_value), fee_per_gram, number_of_splits, self.default_features_and_scripts_size() diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs index e00d3543ed..9a932c365e 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/output_sql.rs @@ -196,10 +196,12 @@ impl OutputSql { conn: &mut SqliteConnection, ) -> Result, OutputManagerStorageError> { let i64_tip_height = tip_height.and_then(|h| i64::try_from(h).ok()).unwrap_or(i64::MAX); + let i64_value = i64::try_from(selection_criteria.min_dust).unwrap_or(i64::MAX); let mut query = outputs::table .into_boxed() .filter(outputs::status.eq(OutputStatus::Unspent as i32)) + .filter(outputs::value.gt(i64_value)) .order_by(outputs::spending_priority.desc()); // NOTE: Safe mode presets `script_lock_height` and `maturity` filters for all queries diff --git a/common/config/presets/d_console_wallet.toml b/common/config/presets/d_console_wallet.toml index fb64012ee5..6ae892684e 100644 --- a/common/config/presets/d_console_wallet.toml +++ b/common/config/presets/d_console_wallet.toml @@ -133,6 +133,8 @@ transaction_event_channel_size = 25000 # transaction amount. Set this value to `false` to allow spending of "dust" UTXOs for small valued transactions # (default = true). prevent_fee_gt_amount = false +# Ignores dust below this value, value in micro MinoTari, defaults to 100 +# dust_ignore_value: 100, # This is the size of the event channel used to communicate output manager events to the wallet. A busy console # wallet doing thousands of bulk payments or used for stress testing needs a fairly big size (>3000) (default = 250). event_channel_size = 3500