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

Interpret fee rates in reference fee unit #21

Merged
merged 54 commits into from
May 3, 2024
Merged

Interpret fee rates in reference fee unit #21

merged 54 commits into from
May 3, 2024

Conversation

JBetz
Copy link
Contributor

@JBetz JBetz commented Apr 24, 2024

Additionally, this introduces a new type CValue to distinguish amounts denominated in reference fee unit from actual assets. It's a rather fundamental change that may not be upstreamable, but already helped reveal some places where an amount was being treated as a value and vice-versa. If needed, we can always remove it later on once the any asset fee feature is more battle-tested. [Update: The use of CValue has been restricted to places that already needed to be updated for any asset fees, so it is no longer as an invasive of a change.]

I've also added a compiler time variable named ANY_ASSET_FEES for configuring the CURRENCY_UNIT and CURRENCY_ATOM constants to bee RFU and rfa instead of BTC and sat, respectively. Those two constants are used by RPC documentation for fee rates and represent the bulk of documentation changes we need for this feature.

Node parameters:

  • mintxfee
  • paytxfee
  • blockmintxfee
  • incrementalrelayfee
  • dustrelayfee

RPC arguments:

  • fee_rate in fundrawtransaction

Internal:

  • rates calculated by fee estimator

@JBetz JBetz requested a review from Mixa84 as a code owner April 24, 2024 06:33
@JBetz JBetz marked this pull request as draft April 24, 2024 06:41
@JBetz JBetz force-pushed the value-type branch 2 times, most recently from 0deda5f to 4771787 Compare April 24, 2024 13:21
CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinControl& coin_control, FeeCalculation* feeCalc)
{
return GetMinimumFeeRate(wallet, coin_control, feeCalc).GetFee(nTxBytes);
return GetMinimumFeeRate(wallet, coin_control, feeCalc).GetFee(nTxBytes, coin_control.m_fee_asset.value_or(::policyAsset));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetMinimumFeeRate is where mintxfee, paytxfee, and
blockmintxfee are used to negotiate a suitable fee rate for the transaction, and passing the asset parameter here ensures that the result is denominated in the fee asset and not RFU.

@@ -926,7 +928,7 @@ bool MemPoolAccept::PreChecks(ATMPArgs& args, Workspace& ws)

// No transactions are allowed below minRelayTxFee except from disconnected
// blocks
if (!bypass_limits && !CheckFeeRate(ws.m_vsize, ws.m_modified_fees, state)) return false;
if (!bypass_limits && !CheckFeeRate(ws.m_vsize, ws.m_modified_fees, feeAsset, state)) return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckFeeRate is where incrementalrelayfee is applied.

@@ -53,7 +53,7 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
nSize += (32 + 4 + 1 + 107 + 4); // the 148 mentioned above
}

return dustRelayFeeIn.GetFee(nSize);
return dustRelayFeeIn.GetFee(nSize, txout.nAsset.GetAsset());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally, dustrelayfee. Here it's used exclusively for non-fee outputs, but still needs to be converted using exchange rates to check that the output doesn't cost more in fees than it's worth.

Copy link
Contributor Author

@JBetz JBetz Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this shouldn't be using the exchange rates at all.

If there's a transaction with an output of some asset that the node doesn't have an exchange rate for, then there's no meaningful conversion from the fee rate to an amount using exchange rates. So we should probably just treat dustrelayfee as a lower bound on the amount that doesn't have anything to do with the RFU.

Otherwise, the node will reject non-fee outputs as dust just because it doesn't care about the asset, which is obviously wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some more investigating and realized that dust checks are currently limited to outputs that have the same asset as the fee, so there's no risk of different assets being compared.

This applies to in policy: https://github.com/ElementsProject/elements/blob/master/src/policy/policy.cpp#L149

And to wallet: https://github.com/ElementsProject/elements/blob/master/src/wallet/spend.cpp#L1143 and https://github.com/ElementsProject/elements/blob/master/src/wallet/spend.cpp#L1559

@JBetz JBetz marked this pull request as ready for review April 25, 2024 05:19
@JBetz JBetz mentioned this pull request Apr 30, 2024
8 tasks
@JBetz JBetz changed the title Interpret fee rate parameters in reference fee unit Interpret fee rates in reference fee unit May 1, 2024
Mixa84
Mixa84 previously approved these changes May 3, 2024
@JBetz JBetz merged commit b7d3729 into dev May 3, 2024
2 checks passed
@JBetz JBetz deleted the value-type branch May 3, 2024 15:39
JBetz added a commit that referenced this pull request May 3, 2024
* Introduce CValue for distinguishing amounts from values

* Remove random character

* Define insertion operator for CValue

* Move CValue to separate module

* Remove consensus changes

* Remove CValue usage for fee rates, restrict to mempool

* More cleanup

* Use CValue for descendant and ancestor fee updates

* More mempool fixes

* Remove unused include

* Fix variable shadowing

* More conversions

* Factor in fee asset when validating package fees

* More conversions

* Convert dust relay fee from RFU

* More cleanup

* Cleanup

* Don't factor in asset in when calculating dust threshold

* Convert package fees

* Return CValue from CalculateExchangeValue

* Use CValue for reverse exchange rate conversion

* Update method documentation

* Rename currency conversion methods

* Fix typo

* Add justification for RFU to comments

* Use accessor instead of public instance variable unpacking CValue

* Use GetValue() in fee rate conversion

* Only apply dust check to outputs denominated in same asset as fee

* Interpret coin selection effective feerate in RFU

* Change GetModifiedFee() method to use RFU for summing with ancestor and descendant transactions

* Add functional test for "fee_rate" parameter in fundrawtransaction RPC and -mintxfee node configuration parameter

* Normalize fees to RFU during fee estimation

* Lint fixes

* More linting fixes

* More linting

* Apply method renams to fee amount conversions

* Add any asset fee rates test to test runner

* More amount conversion fixes

* Add compiler switch for currency constants

* Add new configuration flag to documentation

* Apply fixes to fee estimation functional test from ElementsProject/elements#1298

* Add tests for paytxfee parameter

* Cleanup

* Fix compiler flag

* Add tests for blockmintxfee

* Remove whitespace

* Add comments clarifying what's being demonstrated

* Remove nFeeValue, recompute as needed

* Revert "Remove nFeeValue, recompute as needed"

This reverts commit ab3a67b.

* Move No Coin configuration documentation to separate line

* Add constant for full name of currency atom

* Fix constant reference

* Fix typo
JBetz added a commit that referenced this pull request May 3, 2024
* Introduce CValue for distinguishing amounts from values

* Remove random character

* Define insertion operator for CValue

* Move CValue to separate module

* Remove consensus changes

* Remove CValue usage for fee rates, restrict to mempool

* More cleanup

* Use CValue for descendant and ancestor fee updates

* More mempool fixes

* Remove unused include

* Fix variable shadowing

* More conversions

* Factor in fee asset when validating package fees

* More conversions

* Convert dust relay fee from RFU

* More cleanup

* Cleanup

* Don't factor in asset in when calculating dust threshold

* Convert package fees

* Return CValue from CalculateExchangeValue

* Use CValue for reverse exchange rate conversion

* Update method documentation

* Rename currency conversion methods

* Fix typo

* Add justification for RFU to comments

* Use accessor instead of public instance variable unpacking CValue

* Use GetValue() in fee rate conversion

* Only apply dust check to outputs denominated in same asset as fee

* Interpret coin selection effective feerate in RFU

* Change GetModifiedFee() method to use RFU for summing with ancestor and descendant transactions

* Add functional test for "fee_rate" parameter in fundrawtransaction RPC and -mintxfee node configuration parameter

* Normalize fees to RFU during fee estimation

* Lint fixes

* More linting fixes

* More linting

* Apply method renams to fee amount conversions

* Add any asset fee rates test to test runner

* More amount conversion fixes

* Add compiler switch for currency constants

* Add new configuration flag to documentation

* Apply fixes to fee estimation functional test from ElementsProject/elements#1298

* Add tests for paytxfee parameter

* Cleanup

* Fix compiler flag

* Add tests for blockmintxfee

* Remove whitespace

* Add comments clarifying what's being demonstrated

* Remove nFeeValue, recompute as needed

* Revert "Remove nFeeValue, recompute as needed"

This reverts commit ab3a67b.

* Move No Coin configuration documentation to separate line

* Add constant for full name of currency atom

* Fix constant reference

* Fix typo
Mixa84 pushed a commit that referenced this pull request May 6, 2024
* Introduce CValue for distinguishing amounts from values

* Remove random character

* Define insertion operator for CValue

* Move CValue to separate module

* Remove consensus changes

* Remove CValue usage for fee rates, restrict to mempool

* More cleanup

* Use CValue for descendant and ancestor fee updates

* More mempool fixes

* Remove unused include

* Fix variable shadowing

* More conversions

* Factor in fee asset when validating package fees

* More conversions

* Convert dust relay fee from RFU

* More cleanup

* Cleanup

* Don't factor in asset in when calculating dust threshold

* Convert package fees

* Return CValue from CalculateExchangeValue

* Use CValue for reverse exchange rate conversion

* Update method documentation

* Rename currency conversion methods

* Fix typo

* Add justification for RFU to comments

* Use accessor instead of public instance variable unpacking CValue

* Use GetValue() in fee rate conversion

* Only apply dust check to outputs denominated in same asset as fee

* Interpret coin selection effective feerate in RFU

* Change GetModifiedFee() method to use RFU for summing with ancestor and descendant transactions

* Add functional test for "fee_rate" parameter in fundrawtransaction RPC and -mintxfee node configuration parameter

* Normalize fees to RFU during fee estimation

* Lint fixes

* More linting fixes

* More linting

* Apply method renams to fee amount conversions

* Add any asset fee rates test to test runner

* More amount conversion fixes

* Add compiler switch for currency constants

* Add new configuration flag to documentation

* Apply fixes to fee estimation functional test from ElementsProject/elements#1298

* Add tests for paytxfee parameter

* Cleanup

* Fix compiler flag

* Add tests for blockmintxfee

* Remove whitespace

* Add comments clarifying what's being demonstrated

* Remove nFeeValue, recompute as needed

* Revert "Remove nFeeValue, recompute as needed"

This reverts commit ab3a67b.

* Move No Coin configuration documentation to separate line

* Add constant for full name of currency atom

* Fix constant reference

* Fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants