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

wallet/rpc: sendrawtransaction maxfeerate #13541

Merged
merged 3 commits into from
Mar 18, 2019

Conversation

kallewoof
Copy link
Contributor

This adds a new maxfeerate parameter to sendrawtransaction which forces the node to reject a transaction whose feerate is above the given fee rate.

This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

See also #12911.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jun 27, 2018

Your PR show me actually that maxtxfee exists, which is uncorrelated with absurd fee we were talking about.

One could say that changing maxtxfee or having maxtxfeerate at config level would solve the issue without touching RPC. But, when you do a transaction manually, you know the maxfeerate to expect when you call sendrawtransaction, not when you modify the config file of bitcoind.

ACK.

(That said, I think this would be better in signrawtransaction* than sendrawtransaction)

@kallewoof
Copy link
Contributor Author

kallewoof commented Jun 27, 2018

Your PR show me actually that maxtxfee exists, which is uncorrelated with absurd fee we were talking about.

Yes, absurdfee can actually be specified for each call to AcceptToMempool, so it can be used after all.

One could say that changing maxtxfee or having maxtxfeerate at config level would solve the issue without touching RPC. But, when you do a transaction manually, you know the maxfeerate to expect when you call sendrawtransaction, not when you modify the config file of bitcoind.

I think having a configurable default maxtxfee would be a good idea. Perhaps this function should then ignore the default if the user does allowhighfees=true.

(That said, I think this would be better in signrawtransaction* than sendrawtransaction)

It fits better here, because it already has the functionality needed in the AcceptToMemoryPool function via the absurd fee feature. In sign, you sometimes do not know the input amounts, which means the system sometimes can't check. Here, the amounts are always known because the mempool either knows or the tx is invalid.

addr = self.nodes[2].getnewaddress()
txId = self.nodes[0].sendtoaddress(addr, 1.0)
rawTx = self.nodes[0].getrawtransaction(txId, True)
vout = False
Copy link
Contributor

Choose a reason for hiding this comment

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

= None?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternative (not tested)

vout = next(o for o in rawTx['vout'] if o['value'] == Decimal('1.00000000'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Several copies of this in rpc_rawtransaction, so I made a dedicated commit to address the others.

@@ -1087,14 +1087,15 @@ UniValue signrawtransaction(const JSONRPCRequest& request)

static UniValue sendrawtransaction(const JSONRPCRequest& request)
{
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
if (request.fHelp || request.params.size() < 1 || request.params.size() > 3)
throw std::runtime_error(
"sendrawtransaction \"hexstring\" ( allowhighfees )\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing parameter.

size_t weight = GetTransactionWeight(*tx);
CFeeRate fr(AmountFromValue(request.params[2]));
CAmount max_fee = fr.GetFee((weight+3)/4);
nMaxRawTxFee = nMaxRawTxFee > 0 ? std::min(nMaxRawTxFee, max_fee) : max_fee;
Copy link
Contributor

Choose a reason for hiding this comment

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

When specifying maxfeerate does it make sense to pass allowhighfees=true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am sort of overriding allowhighfees right now. I could disallow it completely, i.e. require that it is null or false, if using maxfeerate, but not sure it's worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To more directly answer your question, though, allowhighfees=true will simply remove the existing absurd fee cap (which is 0.1 btc I believe), so if maxfeerate was really high, it actually could result in a slightly higher cap.

Copy link
Member

Choose a reason for hiding this comment

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

Just have a single parameter... if it's a boolean, it's the (deprecated?) allowhighfees; if a number, then a specific limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@luke-jr does that work with named parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

does that work with named parameters?

Yes, it is already used by getbalance:

{ "wallet", "getbalance", &getbalance, {"account|dummy","minconf","include_watchonly"} },

@kallewoof kallewoof force-pushed the sendrawtransaction-maxfeerate branch 2 times, most recently from bbb81b6 to a43e61d Compare June 27, 2018 22:58
@kallewoof kallewoof force-pushed the sendrawtransaction-maxfeerate branch 6 times, most recently from f9893d4 to bec1abd Compare July 13, 2018 07:28
@kallewoof kallewoof force-pushed the sendrawtransaction-maxfeerate branch 7 times, most recently from d562cce to dbd466c Compare July 31, 2018 06:37
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 12, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15282 (test: Replace hard-coded hex tx with class in test framework by stevenroose)
  • #14691 (tests: Speedup feature_pruning test and refactor big transaction logic by conscott)
  • #14053 (Add address-based index (attempt 4?) by marcinja)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

utACK dbd466c

"\nSubmits raw transaction (serialized, hex-encoded) to local node and network.\n"
"\nAlso see createrawtransaction and signrawtransaction calls.\n"
"\nArguments:\n"
"1. \"hexstring\" (string, required) The hex string of the raw transaction)\n"
"2. allowhighfees (boolean, optional, default=false) Allow high fees\n"
"2. allowhighfees|maxfeerate (boolean/numeric, optional, default=false/∞) Allow high fees (boolean) or reject transactions whose fee rate is higher than the specified value (numeric), expressed in " + CURRENCY_UNIT + "/kB\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this default be whatever maxTxFee is, not ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed - it now outputs

2. allowhighfees|maxfeerate (boolean/numeric, optional, default=false/0.10) Allow 
high fees (boolean) or reject transactions whose fee rate is higher than the 
specified value (numeric), expressed in BTC/kB

for the default settings.

} else if (request.params[1].isNum()) {
size_t weight = GetTransactionWeight(*tx);
CFeeRate fr(AmountFromValue(request.params[1]));
nMaxRawTxFee = fr.GetFee((weight+3)/4);
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to add a quick comment here to clarify the +3/4 is for rounding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added note.

@kallewoof kallewoof force-pushed the sendrawtransaction-maxfeerate branch from 6c17985 to 7abd2e6 Compare March 13, 2019 23:49
@kallewoof
Copy link
Contributor Author

Addressed @MarcoFalke nits.

@maflcko maflcko merged commit 7abd2e6 into bitcoin:master Mar 18, 2019
maflcko pushed a commit that referenced this pull request Mar 18, 2019
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also #12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
}
}
return -1;
}
Copy link
Member

Choose a reason for hiding this comment

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

re-utACK 7abd2e6

Sorry I only noticed this unused method in this hunk after merge 😿.

laanwj added a commit that referenced this pull request Mar 18, 2019
fa5c511 refactor: Remove unused function (MarcoFalke)

Pull request description:

  Oversight of kallewoof and mine in #13541 (comment)

Tree-SHA512: 2fd3c4ecde5d3c58b113aa58d606976ceb4998358bde0547ead8e83df210722fa9821d2c88b717bdd190ef71593cd9c0154c3a5d3f2ccc3af8cbf6c36aaa6d45
@kallewoof kallewoof deleted the sendrawtransaction-maxfeerate branch March 18, 2019 23:58
@jnewbery
Copy link
Contributor

post-merge ACK 7abd2e6

(except the change to validation.cpp 🙈 )

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Apr 22, 2019
Github-Pull: bitcoin#13541
Rebased-From: 6c0a6f7

Modifications:
- Includes fix from bitcoin#15618
- Retains backward compatibility
- Doesn't change all the unrelated tests
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Apr 22, 2019
Github-Pull: bitcoin#13541
Rebased-From: 7abd2e6

Modifications:
- Retains backward compatibility
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 26, 2020
Summary:
 * test: Refactor vout fetches in rpc_rawtransaction

 * wallet/rpc: add maxfeerate parameter to sendrawtransaction

 * wallet/rpc: add maxfeerate parameter to testmempoolaccept

This is a backport of Core [[bitcoin/bitcoin#13541 | PR13541]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D6263
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Nov 15, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Nov 16, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Dec 5, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Dec 5, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Dec 6, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Dec 6, 2021
7abd2e6 wallet/rpc: add maxfeerate parameter to testmempoolaccept (Karl-Johan Alm)
6c0a6f7 wallet/rpc: add maxfeerate parameter to sendrawtransaction (Karl-Johan Alm)
e5efacb test: Refactor vout fetches in rpc_rawtransaction (Karl-Johan Alm)

Pull request description:

  This adds a new `maxfeerate` parameter to `sendrawtransaction` which forces the node to reject a transaction whose feerate is above the given fee rate.

  This is a safety harness from shooting yourself in the foot and accidentally overpaying fees.

  See also bitcoin#12911.

Tree-SHA512: efa50134a7c17c9330cfdfd48ba400e095c0a419cc45e630618d8b44929c25d780d1bb2710c1fbbb6e687eca373505b0338cdaa7f2ff4ca22636d84c31557a2e
kwvg added a commit to kwvg/dash that referenced this pull request Dec 8, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 11, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Dec 12, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants