-
Notifications
You must be signed in to change notification settings - Fork 115
fix(UTXO): improve tx fee calculation and min relay fee handling #2316
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
Changes from 4 commits
cea1b2f
455403c
8d2fe79
bc69a42
40cfbda
50a38f8
615ff3e
3f709fc
459a379
534006e
ad0699e
1b2c538
110a236
b5994e6
ae8c3ee
9126c49
997dcee
7ca03f4
850f7b3
eab8902
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -279,11 +279,43 @@ pub enum TxFee { | |
| pub enum ActualTxFee { | ||
| /// fee amount per Kbyte received from coin RPC | ||
| Dynamic(u64), | ||
| /// Use specified amount per each 1 kb of transaction and also per each output less than amount. | ||
| /// Use specified fee amount per each 1 kb of transaction and also per each output less than the fee amount. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you explain more about this fee scheme. the per each output part isn't really clear (understood it as 1 fee_rate per 1 output, which i doubt is a correct understanding).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, actually I have the same question: |
||
| /// Used by DOGE, but more coins might support it too. | ||
| FixedPerKb(u64), | ||
| } | ||
|
|
||
| impl ActualTxFee { | ||
| fn get_tx_fee(&self, tx_size: u64) -> u64 { | ||
| match self { | ||
| ActualTxFee::Dynamic(fee_per_kb) => (fee_per_kb * tx_size) / KILO_BYTE, | ||
|
||
| // return fee_per_kb here as swap spend transaction size is always less than 1 kb | ||
| ActualTxFee::FixedPerKb(fee_per_kb) => { | ||
| let tx_size_kb = if tx_size % KILO_BYTE == 0 { | ||
| tx_size / KILO_BYTE | ||
| } else { | ||
| tx_size / KILO_BYTE + 1 | ||
| }; | ||
| fee_per_kb * tx_size_kb | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /// Return extra tx fee for the change output as p2pkh | ||
| fn get_tx_fee_for_change(&self, tx_size: Option<u64>) -> u64 { | ||
|
||
| match self { | ||
| ActualTxFee::Dynamic(fee_per_kb) => (*fee_per_kb * P2PKH_OUTPUT_LEN) / KILO_BYTE, | ||
| ActualTxFee::FixedPerKb(fee_per_kb) => { | ||
| // take into account the change output if tx_size_kb(tx with change) > tx_size_kb(tx without change) | ||
| if tx_size.unwrap_or_default() % KILO_BYTE + P2PKH_OUTPUT_LEN > KILO_BYTE { | ||
| *fee_per_kb | ||
| } else { | ||
| 0 | ||
| } | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Fee policy applied on transaction creation | ||
| pub enum FeePolicy { | ||
| /// Send the exact amount specified in output(s), fee is added to spent input amount | ||
|
|
@@ -840,7 +872,7 @@ pub trait UtxoTxBroadcastOps { | |
| #[async_trait] | ||
| #[cfg_attr(test, mockable)] | ||
| pub trait UtxoTxGenerationOps { | ||
| async fn get_tx_fee(&self) -> UtxoRpcResult<ActualTxFee>; | ||
| async fn get_fee_per_kb(&self) -> UtxoRpcResult<ActualTxFee>; | ||
|
|
||
| /// Calculates interest if the coin is KMD | ||
| /// Adds the value to existing output to my_script_pub or creates additional interest output | ||
|
|
@@ -1741,7 +1773,6 @@ where | |
| { | ||
| let my_address = try_tx_s!(coin.as_ref().derivation_method.single_addr_or_err().await); | ||
| let key_pair = try_tx_s!(coin.as_ref().priv_key_policy.activated_key_or_err()); | ||
|
|
||
| let mut builder = UtxoTxBuilder::new(coin) | ||
| .await | ||
| .add_available_inputs(unspents) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.