I know this code is mostly inherited from the existing feebumper::CreateTransaction()
, but I think it can be made a lot more readable. CFeeRate
overrides the <
operator (so std::max
can be used) and the +=
operator. Do you think the following code is clearer:
0 // Get the fee rate of the original transaction. This is calculated from
1 // the tx fee/vsize, so it may have been rounded down. Add 1 satoshi to the
2 // result.
3 old_fee = wtx.GetDebit(ISMINE_SPENDABLE) - wtx.tx->GetValueOut();
4 int64_t txSize = GetVirtualTransactionSize(*(wtx.tx));
5 CFeeRate feerate(old_fee, txSize);
6 feerate += CFeeRate(1);
7
8 // The node has a configurable incremental relay fee. Increment the fee by
9 // the minimum of that and the wallet's conservative
10 // WALLET_INCREMENTAL_RELAY_FEE value to future proof against changes to
11 // network wide policy for incremental relay fee that our node may not be
12 // aware of. This ensures we're over the over the required relay fee rate
13 // (BIP 125 rule 4). The replacement tx will be at least as large as the
14 // original tx, so the total fee will be greater (BIP 125 rule 3)
15 CFeeRate node_incremental_relay_fee = wallet->chain().relayIncrementalFee();
16 CFeeRate wallet_incremental_relay_fee = CFeeRate(WALLET_INCREMENTAL_RELAY_FEE);
17 feerate += std::max(node_incremental_relay_fee, wallet_incremental_relay_fee);
18
19 // Fee rate must also be at least the wallet's GetMinimumFeeRate
20 CFeeRate min_feerate(GetMinimumFeeRate(*wallet, new_coin_control, /* feeCalc */ nullptr));
21
22 // Set the required fee rate for the replacement transaction in coin control.
23 new_coin_control.m_feerate = std::max(feerate, min_feerate);
(I also re-added the comment about adding 1 to the fee rate in case the calculated old fee rate was rounded down).