Skip to content

Conversation

remagpie
Copy link
Contributor

@remagpie remagpie commented Aug 1, 2019

Fixes #16382

This patch tries to treat maxfeerate in sendrawtransaction/testmempoolaccept RPC as a rate(BTC/kB) instead of an absolute value(BTC).
The included test case checks if the new behavior works correctly, by using the transaction with an absolute fee of ~0.02BTC, where the fee rate is ~0.2BTC/kB.
This test should be failing if the default maxfeerate is 0.1BTC, but pass if the default value is 0.1BTC/kB

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. A few questions.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 1, 2019

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

Conflicts

No conflicts as of last run.

@maflcko
Copy link
Member

maflcko commented Aug 2, 2019

A few tests need to be updated, since the default is no longer an absolute value of 0.01, but a fee rate of 0.01 BTC/kB. Generally txs are less than 1kB, so the absurd high-fee will kick in earlier.

@maflcko maflcko added this to the 0.19.0 milestone Aug 2, 2019
@promag
Copy link
Contributor

promag commented Aug 2, 2019

Concept ACK.

AcceptToMemoryPool could be changed to receive absurd_fee_rate instead? Then computing the transaction fee could be moved there (reducing duplicate code) and DEFAULT_MAX_FEE_RATE could be moved to validation.h.

Should backport this?

@maflcko
Copy link
Member

maflcko commented Aug 2, 2019

@promag The fee check has nothing to do with validation, so the default value should not live in validation. See also " [WIP] Remove nAbsurdFee fee from AcceptToMemoryPool #15810 " by @jnewbery

@maflcko
Copy link
Member

maflcko commented Aug 2, 2019

Also, I'd rather not change validation in a bugfix for an rpc.

@promag
Copy link
Contributor

promag commented Aug 2, 2019

@MarcoFalke sorry for not being clear on my comment, I wasn't suggesting to do that change here, hence the backport question.

Thanks for referencing #15810.

@maflcko
Copy link
Member

maflcko commented Aug 2, 2019

This was introduced here: #16382 (comment), so no it does not need backport.

@remagpie remagpie force-pushed the maxfeerate-as-rate branch 2 times, most recently from 0bb71b1 to c540e25 Compare August 3, 2019 03:31
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Looks good. Some style comments

@remagpie remagpie force-pushed the maxfeerate-as-rate branch from 8153e7f to 7335bd3 Compare August 5, 2019 19:15
@maflcko
Copy link
Member

maflcko commented Aug 5, 2019

ACK 7335bd3

@remagpie
Copy link
Contributor Author

remagpie commented Aug 6, 2019

One of the Travis jobs has failed by timeout.
I have no idea why it failed though.
Should I investigate about it?

@Sjors
Copy link
Member

Sjors commented Aug 6, 2019

I restarted Travis for you.

ACK 7335bd3, though I suggest having the RPC code catch absurdly-high-fee from validation and change it to absurdly-high-fee-rate.

The rename from DEFAULT_MAX_RAW_TX_FEE to DEFAULT_MAX_RAW_TX_FEE_RATE adds a much needed clarification. It's less easy to confuse with DEFAULT_TRANSACTION_MAXFEE (-maxtxfee).

We're still in a bit of weird situation, but it's fine for now: fundrawtransaction has a feeRate arguments and checks absolute fee against -maxtxfee, while sendrawtransaction checks the feeRate (against maxfeerate), and doesn't check the absolute fee.

@maflcko maflcko changed the title wallet/rpc: Use the default maxfeerate value as BTC/kB rpc: Use the default maxfeerate value as BTC/kB Aug 6, 2019
@maflcko
Copy link
Member

maflcko commented Aug 6, 2019

cc @kallewoof

rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx)
assert_equal(rawTxSigned['complete'], True)
# 1000 sat fee, ~100 b transaction, fee rate should land around 10 sat/b = 0.00010000 BTC/kB
# 2000000 sat fee, ~100 b transaction, fee rate should land around 20000 sat/b = 0.20000000 BTC/kB
Copy link
Contributor

Choose a reason for hiding this comment

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

This tests the default, but removes the test for when a user provides a max fee rate below the default. That is probably the more frequent use case, so it should be tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I'll refactor the test a little bit so that both cases are covered.

@remagpie
Copy link
Contributor Author

remagpie commented Aug 7, 2019

@Sjors I agree with the rationale behind your suggestion, but I can't think of a neat way of actually implementing it.
I prefer leaving it as is, but I'm open to suggestion if there's any good idea for the implementation.

@remagpie remagpie force-pushed the maxfeerate-as-rate branch from 7335bd3 to 49b1f48 Compare August 7, 2019 14:24
@maflcko
Copy link
Member

maflcko commented Aug 12, 2019

ACK 49b1f48

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK 49b1f4811735f523571f3e99abd58b61cd1ac3e8
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUh4Hgv+KIUo919Iwy0K/MPxGM6EE+WdBPrO/cqSixufYn5kMZ5+goPcBAJ8v5O9
OoC4SzTmMKwl6qHJPgeBp3EGjubgD1Up5KBepQq70zOHdTmukvA3tn1nepc7w/GI
nkJ9AYoXpivFI8MTabuHDNa0/0psBv1nteKsBNcow4rKSb8RSuf2Itu0HT5a9t2H
7VcvYcsQjNizgafy7FHuahYa855UwkdjGdpRntqxDqViDr69FErQI/VurM0YtrCZ
8PiFA3i++igwMpgnsDBq0Guc+Ng2cqmyVIVVF3GlfEhHSZQPJbfopSeCfArdcgdY
TneK5tbSL/q0rRWIMOwBUoT2iuTv297E7rIFkAz0lg0STuOuIws5WfrbtE35Guv+
zpyRIhGS3a8YWCuSF3ZnwnqscOp/IpWt3ojzOCN/tbQO6JUi33WhYLP1BnE7Wnkl
hZDmDlSdniqjfqK9HR0754ia4Po5bQCGxJnNO5h9D4abpkb8I9Rjzty8agfZYwwW
kPsjLD0H
=AiEa
-----END PGP SIGNATURE-----

Timestamp of file with hash 9a3ed53c1fee1a38984565afc1e5e4de52ffa6dde5c6b84909b5d9645e01d6d1 -

*/
constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
const static CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
Copy link
Contributor

Choose a reason for hiding this comment

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

Style nit: The storage-class specifier is typically put at the start of the declaration in this project -- that is: static const … is typically used instead of const static … :-)

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.

This patch adds test for the following case
- maxfeerate is omitted, and the actual fee rate is higher than
  the default value(0.1 BTC/kB)
@remagpie remagpie force-pushed the maxfeerate-as-rate branch from 49b1f48 to 2dfd683 Compare August 18, 2019 15:16
@maflcko
Copy link
Member

maflcko commented Sep 16, 2019

re-run ci

@maflcko maflcko closed this Sep 16, 2019
@maflcko maflcko reopened this Sep 16, 2019
@remagpie
Copy link
Contributor Author

I couldn't reproduce the failing test on my machine. Is it CI's problem?

@laanwj
Copy link
Member

laanwj commented Sep 18, 2019

ACK 2dfd683 (ACKs by Sjors and MarcoFalke above for trivially different code)

laanwj added a commit that referenced this pull request Sep 18, 2019
2dfd683 test: Add test for default maxfeerate in sendrawtransaction (Joonmo Yang)
261843e wallet/rpc: Use the default maxfeerate value as BTC/kB (Joonmo Yang)

Pull request description:

  Fixes #16382

  This patch tries to treat `maxfeerate` in sendrawtransaction/testmempoolaccept RPC as a rate(BTC/kB) instead of an absolute value(BTC).
  The included test case checks if the new behavior works correctly, by using the transaction with an absolute fee of ~0.02BTC, where the fee rate is ~0.2BTC/kB.
  This test should be failing if the default `maxfeerate` is 0.1BTC, but pass if the default value is 0.1BTC/kB

ACKs for top commit:
  laanwj:
    ACK 2dfd683 (ACKs by Sjors and MarcoFalke above for trivially different code)

Tree-SHA512: a1795bffe8a182acef8844797955db1f60bb0c0ded97148f3572dc265234d5219271a3a7aa0b6418a43f73b2b2720ef7412ba169c99bb1cdcac52051f537d6af
@laanwj laanwj merged commit 2dfd683 into bitcoin:master Sep 18, 2019
@maflcko
Copy link
Member

maflcko commented Sep 18, 2019

post-merge re-ACK 2dfd683 (only change is style nit)

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

post-merge re-ACK 2dfd6834ef8737e16e4b96df0c459f30a0721d6c (only change is style nit)
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhodQv+N39HguRkVUKt6PzE2gGZ6BR0e9Jwypn08WD0kWVsrRwPOZzdpq/HBUys
Ispph9JBh3EXGFiBTwOPaybH1yLAEyyAvvFd0/sJifOblu3QfkKwwr8b81/+s8lE
8SV+vwi0TWMVvSrq42DEdPtXlA65EhjBfRkuF4o58D7PtXa3l5keKbQGrVfZqnTb
OFZc0ZaWrjXd3cwhJo/W5SE4RHXSKxydq5qipkqYhCQ59y2M+F41WMHH89Q92jgO
3iBUREvJb7/Yix4aM4DPK06DGaVUx5P7NxmJqsJfI4N4VY2QQF0MejpZRbe38Ddc
iVW69qby89m5VXIuc+boktMkfsqMI4YcUUTjLetI3tLGjWm//U2HLJRa1RHSAHhS
eHQ47zx7f+sNpFextdDmX2rTlGK7YO3j9b8dsaw4fLPgvy9ydENhqeTzX51cMtCi
D39F36riarcGlBRto14j0txq21+LeqBI4qdRy/pBCmgcneN5ktWnKfsqQK4hXTs9
pmvpv7um
=2xaT
-----END PGP SIGNATURE-----

Timestamp of file with hash fbaf9ebc856aec97f9850a70c2b6a2435c1b4ab700db0b49752d9eb74c89975e -

txId = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
rawTx = self.nodes[0].getrawtransaction(txId, True)
vout = next(o for o in rawTx['vout'] if o['value'] == Decimal('1.00000000'))

self.sync_all()
inputs = [{ "txid" : txId, "vout" : vout['n'] }]
outputs = { self.nodes[0].getnewaddress() : Decimal("0.99999000") } # 1000 sat fee
outputs = { self.nodes[0].getnewaddress() : Decimal("0.999990000") } # 10000 sat fee
Copy link
Member

Choose a reason for hiding this comment

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

eh, actually this is incorrect. Appending zeros after the number after the decimal point does not change the number.

>>> 0.9 == 0.90
True

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, should be 0.99990000

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OMG. I'll send a patch soon.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, should be 0.99990000

Done in #16929.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 23, 2019
2dfd683 test: Add test for default maxfeerate in sendrawtransaction (Joonmo Yang)
261843e wallet/rpc: Use the default maxfeerate value as BTC/kB (Joonmo Yang)

Pull request description:

  Fixes bitcoin#16382

  This patch tries to treat `maxfeerate` in sendrawtransaction/testmempoolaccept RPC as a rate(BTC/kB) instead of an absolute value(BTC).
  The included test case checks if the new behavior works correctly, by using the transaction with an absolute fee of ~0.02BTC, where the fee rate is ~0.2BTC/kB.
  This test should be failing if the default `maxfeerate` is 0.1BTC, but pass if the default value is 0.1BTC/kB

ACKs for top commit:
  laanwj:
    ACK 2dfd683 (ACKs by Sjors and MarcoFalke above for trivially different code)

Tree-SHA512: a1795bffe8a182acef8844797955db1f60bb0c0ded97148f3572dc265234d5219271a3a7aa0b6418a43f73b2b2720ef7412ba169c99bb1cdcac52051f537d6af
laanwj added a commit that referenced this pull request Sep 25, 2019
6659810 test: use named args for sendrawtransaction calls (Jon Atack)
5c1cd78 doc: improve rawtransaction code/test docs (Jon Atack)
acc14c5 test: fix incorrect value in rpc_rawtransaction.py (Jon Atack)

Pull request description:

  Follow-up to PR #16521.

  - Fix incorrect value in rpc_rawtransaction test as per https://github.com/bitcoin/bitcoin/pull/16521/files#r325842308
  - Improve the code docs
  - Use named arguments as per https://github.com/bitcoin/bitcoin/pull/16521/files#r310715127

  Happy to squash or keep only the first commit if the others are too fixup-y.

ACKs for top commit:
  laanwj:
    ACK 6659810

Tree-SHA512: bf5258f23802ab3ba3defb8791097e08e63f3e2af21023f832cd270dc88d1fa04349e921d69f9f5fedac5dce5cd3c1cc46b48febbede4bc18dccb8be994565b2
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 25, 2019
… as BTC/kB

6659810 test: use named args for sendrawtransaction calls (Jon Atack)
5c1cd78 doc: improve rawtransaction code/test docs (Jon Atack)
acc14c5 test: fix incorrect value in rpc_rawtransaction.py (Jon Atack)

Pull request description:

  Follow-up to PR bitcoin#16521.

  - Fix incorrect value in rpc_rawtransaction test as per https://github.com/bitcoin/bitcoin/pull/16521/files#r325842308
  - Improve the code docs
  - Use named arguments as per https://github.com/bitcoin/bitcoin/pull/16521/files#r310715127

  Happy to squash or keep only the first commit if the others are too fixup-y.

ACKs for top commit:
  laanwj:
    ACK 6659810

Tree-SHA512: bf5258f23802ab3ba3defb8791097e08e63f3e2af21023f832cd270dc88d1fa04349e921d69f9f5fedac5dce5cd3c1cc46b48febbede4bc18dccb8be994565b2
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 22, 2020
Summary:
 * wallet/rpc: Use the default maxfeerate value as BTC/kB

 * test: Add test for default maxfeerate in sendrawtransaction

This patch adds test for the following case
- maxfeerate is omitted, and the actual fee rate is higher than
  the default value(0.1 BTC/kB)

This is a backport of Core [[bitcoin/bitcoin#16521 | PR16521]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D8027
@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.

sendrawtransaction maxfeerate is interpreted as absolute fee by default
9 participants