rpc: Use the default maxfeerate value as BTC/kB #16521

pull remagpie wants to merge 2 commits into bitcoin:master from remagpie:maxfeerate-as-rate changing 5 files +48 −26
  1. remagpie commented at 5:43 pm on August 1, 2019: contributor

    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

  2. in src/rpc/rawtransaction.cpp:44 in 5665a1a0dd outdated
    43+/** High fee rate for sendrawtransaction and testmempoolaccept.
    44+ * By default, transaction with a fee rate higher than this will be rejected by
    45+ * the RPCs. This can be overridden with the maxfeerate argument.
    46  */
    47-constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
    48+constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
    


    MarcoFalke commented at 5:54 pm on August 1, 2019:

    Can the type be changed as well?

    0const static CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
    

    remagpie commented at 7:00 pm on August 1, 2019:
    CFeeRate can’t be constexpr since it doesn’t have constexpr constructor. We can change it to const though.

    MarcoFalke commented at 7:37 pm on August 1, 2019:
    Yeah,static const is more than enough for our purposes

    MarcoFalke commented at 1:27 pm on August 2, 2019:
    @Remagpie Mind to address this? I think changing the type makes it harder to get wrong again in the code in the future.

    remagpie commented at 2:23 am on August 3, 2019:
    Sorry for the late response. I think there’s no problem if it’s okay to use static const here. I’ll fix this.
  3. in src/rpc/rawtransaction.cpp:878 in 5665a1a0dd outdated
    874@@ -873,19 +875,21 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
    875     CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
    876     const uint256& tx_hash = tx->GetHash();
    877 
    878-    CAmount max_raw_tx_fee = DEFAULT_MAX_RAW_TX_FEE;
    879+    CAmount max_raw_tx_fee_rate = DEFAULT_MAX_RAW_TX_FEE_RATE;
    


    MarcoFalke commented at 5:56 pm on August 1, 2019:
    0    CFeeRate max_raw_tx_fee_rate{DEFAULT_MAX_RAW_TX_FEE_RATE};
    

    remagpie commented at 7:16 pm on August 1, 2019:
    Fixed.
  4. in test/functional/rpc_rawtransaction.py:447 in 5665a1a0dd outdated
    445         assert_equal(rawTxSigned['complete'], True)
    446-        # 1000 sat fee, ~100 b transaction, fee rate should land around 10 sat/b = 0.00010000 BTC/kB
    447+        # 2000000 sat fee, ~100 b transaction, fee rate should land around 20000 sat/b = 0.20000000 BTC/kB
    448         # Thus, testmempoolaccept should reject
    449-        testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']], 0.00001000)[0]
    450+        testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']], 0.02000000)[0]
    


    MarcoFalke commented at 5:57 pm on August 1, 2019:
    Why is this test change needed?

    remagpie commented at 7:02 pm on August 1, 2019:
    This didn’t have to be changed. I’ll revert this line.
  5. in test/functional/rpc_rawtransaction.py:479 in 5665a1a0dd outdated
    458         # And below calls should both succeed
    459-        testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.00070000')[0]
    460+        testres = self.nodes[2].testmempoolaccept(rawtxs=[rawTxSigned['hex']], maxfeerate='0.20000000')[0]
    461         assert_equal(testres['allowed'], True)
    462-        self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.00070000')
    463+        self.nodes[2].sendrawtransaction(hexstring=rawTxSigned['hex'], maxfeerate='0.20000000')
    


    MarcoFalke commented at 5:57 pm on August 1, 2019:
    Same here

    remagpie commented at 7:04 pm on August 1, 2019:
    This line is testing if the RPC call succeeds if appropriate maxfeerate was provided. Since the amount of fee attached to the transaction was changed, maxfeerate should be increased too.
  6. MarcoFalke approved
  7. MarcoFalke commented at 5:57 pm on August 1, 2019: member
    Thanks for working on this. A few questions.
  8. DrahtBot added the label RPC/REST/ZMQ on Aug 1, 2019
  9. DrahtBot added the label Tests on Aug 1, 2019
  10. remagpie force-pushed on Aug 1, 2019
  11. in test/functional/rpc_rawtransaction.py:441 in 31ad96127d outdated
    437@@ -438,21 +438,23 @@ def run_test(self):
    438 
    439         self.sync_all()
    440         inputs = [{ "txid" : txId, "vout" : vout['n'] }]
    441-        outputs = { self.nodes[0].getnewaddress() : Decimal("0.99999000") } # 1000 sat fee
    442+        outputs = { self.nodes[0].getnewaddress() : Decimal("0.98000000") } # 2000000 sat fee
    


    MarcoFalke commented at 7:38 pm on August 1, 2019:
    Why is the test changed at all?

    remagpie commented at 2:52 am on August 2, 2019:

    Let me explain it a bit in detail.

    I wanted to test if a transaction with sufficiently high fee rate gets rejected if no maxfeerate was specified. I could’ve created a new transaction with a high fee and run test with it, but I thought it would be nice if I can reuse the existing code so that the change becomes minimal. The existing rawTx’s fee was too low for that, but there should be no difference if I change the related values altogether. So I increased the fee from 1000 sat to 0.02 BTC, and other maxfeerate values accordingly.


    MarcoFalke commented at 12:11 pm on August 2, 2019:

    I wanted to test if a transaction with sufficiently high fee rate gets rejected if no maxfeerate was specified.

    This is tested in other functional tests already. (I presume you can find them by removing the failure in the source code, re-compile and re-run the tests)


    remagpie commented at 12:49 pm on August 2, 2019:

    I changed my code as following, but couldn’t find any failing test. Could you point the exact test you’re referring to?

    0+ CFeeRate max_raw_tx_fee_rate{DEFAULT_MAX_RAW_TX_FEE_RATE * 1000000};
    1- CFeeRate max_raw_tx_fee_rate{DEFAULT_MAX_RAW_TX_FEE_RATE};
    

    MarcoFalke commented at 1:21 pm on August 2, 2019:
    You might be right. Going to take a look… :eyes:

    MarcoFalke commented at 1:26 pm on August 2, 2019:
    You are right. Sorry, you can keep your changes as they are.
  12. DrahtBot commented at 7:48 pm on August 1, 2019: member

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

    Conflicts

    No conflicts as of last run.

  13. DrahtBot added the label Needs rebase on Aug 2, 2019
  14. MarcoFalke commented at 1:29 pm on August 2, 2019: member
    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.
  15. MarcoFalke added this to the milestone 0.19.0 on Aug 2, 2019
  16. promag commented at 2:04 pm on August 2, 2019: member

    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?

  17. MarcoFalke commented at 3:25 pm on August 2, 2019: member
    @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
  18. MarcoFalke commented at 3:27 pm on August 2, 2019: member
    Also, I’d rather not change validation in a bugfix for an rpc.
  19. promag commented at 3:31 pm on August 2, 2019: member

    @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.

  20. MarcoFalke commented at 3:34 pm on August 2, 2019: member
    This was introduced here: #16382 (comment), so no it does not need backport.
  21. remagpie force-pushed on Aug 3, 2019
  22. remagpie force-pushed on Aug 3, 2019
  23. DrahtBot removed the label Needs rebase on Aug 3, 2019
  24. in src/rpc/rawtransaction.cpp:815 in 8153e7f7e6 outdated
    817     }
    818 
    819+    size_t weight = GetTransactionWeight(*tx);
    820+    // the +3/4 part rounds the value up, and is the same formula used when
    821+    // calculating the fee for a transaction
    822+    // (see GetVirtualTransactionSize)
    


    MarcoFalke commented at 5:37 pm on August 5, 2019:
    Couldn’t you call GetVirtualTransactionSize instead of copy-pasting the constants here?

    remagpie commented at 6:12 pm on August 5, 2019:
    It seems it’s possible. I’ll replace it.
  25. in src/rpc/rawtransaction.cpp:892 in 8153e7f7e6 outdated
    894     }
    895 
    896+    size_t weight = GetTransactionWeight(*tx);
    897+    // the +3/4 part rounds the value up, and is the same formula used when
    898+    // calculating the fee for a transaction
    899+    // (see GetVirtualTransactionSize)
    


    MarcoFalke commented at 5:37 pm on August 5, 2019:
    Same
  26. in test/functional/feature_segwit.py:243 in 8153e7f7e6 outdated
    239@@ -240,7 +240,7 @@ def run_test(self):
    240         tx.vin.append(CTxIn(COutPoint(int(txid2, 16), 0), b""))
    241         tx.vout.append(CTxOut(int(49.95 * COIN), CScript([OP_TRUE, OP_DROP] * 15 + [OP_TRUE])))  # Huge fee
    242         tx.calc_sha256()
    243-        txid3 = self.nodes[0].sendrawtransaction(ToHex(tx))
    244+        txid3 = self.nodes[0].sendrawtransaction(ToHex(tx), 0)
    


    MarcoFalke commented at 5:38 pm on August 5, 2019:
    Please use name arguments for unnamed integer values. Also, this commit needs to be squashed into the earlier one (the one where the tests start to fail)

    remagpie commented at 6:35 pm on August 5, 2019:
    Most of the other test code using sendrawtransaction doesn’t use named parameter for maxfeerate. Do you have any reason for using different convention here?

    MarcoFalke commented at 6:38 pm on August 5, 2019:
    Up to you. Just pick what you prefer.

    remagpie commented at 7:17 pm on August 5, 2019:
    Squashed, and didn’t change to a named argument.
  27. in test/functional/wallet_basic.py:436 in 8153e7f7e6 outdated
    432@@ -433,7 +433,7 @@ def run_test(self):
    433         # Split into two chains
    434         rawtx = self.nodes[0].createrawtransaction([{"txid": singletxid, "vout": 0}], {chain_addrs[0]: node0_balance / 2 - Decimal('0.01'), chain_addrs[1]: node0_balance / 2 - Decimal('0.01')})
    435         signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx)
    436-        singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"])
    437+        singletxid = self.nodes[0].sendrawtransaction(signedtx["hex"], 0)
    


    MarcoFalke commented at 5:38 pm on August 5, 2019:
    Same
  28. MarcoFalke commented at 5:38 pm on August 5, 2019: member
    Looks good. Some style comments
  29. remagpie force-pushed on Aug 5, 2019
  30. MarcoFalke commented at 7:28 pm on August 5, 2019: member
    ACK 7335bd33aec9105811755921bf14463975c392d7
  31. remagpie commented at 2:37 am on August 6, 2019: contributor
    One of the Travis jobs has failed by timeout. I have no idea why it failed though. Should I investigate about it?
  32. Sjors commented at 12:26 pm on August 6, 2019: member

    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.

  33. MarcoFalke renamed this:
    wallet/rpc: Use the default maxfeerate value as BTC/kB
    rpc: Use the default maxfeerate value as BTC/kB
    on Aug 6, 2019
  34. MarcoFalke commented at 2:21 pm on August 6, 2019: member
  35. in test/functional/rpc_rawtransaction.py:445 in 7335bd33ae outdated
    442+        outputs = { self.nodes[0].getnewaddress() : Decimal("0.98000000") } # 2000000 sat fee
    443         rawTx = self.nodes[2].createrawtransaction(inputs, outputs)
    444         rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx)
    445         assert_equal(rawTxSigned['complete'], True)
    446-        # 1000 sat fee, ~100 b transaction, fee rate should land around 10 sat/b = 0.00010000 BTC/kB
    447+        # 2000000 sat fee, ~100 b transaction, fee rate should land around 20000 sat/b = 0.20000000 BTC/kB
    


    kallewoof commented at 8:33 am on August 7, 2019:
    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.

    remagpie commented at 1:58 pm on August 7, 2019:
    Agreed. I’ll refactor the test a little bit so that both cases are covered.
  36. remagpie commented at 1:56 pm on August 7, 2019: contributor
    @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.
  37. remagpie force-pushed on Aug 7, 2019
  38. MarcoFalke commented at 6:47 pm on August 12, 2019: member

    ACK 49b1f4811735f523571f3e99abd58b61cd1ac3e8

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3ACK 49b1f4811735f523571f3e99abd58b61cd1ac3e8
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUh4Hgv+KIUo919Iwy0K/MPxGM6EE+WdBPrO/cqSixufYn5kMZ5+goPcBAJ8v5O9
     8OoC4SzTmMKwl6qHJPgeBp3EGjubgD1Up5KBepQq70zOHdTmukvA3tn1nepc7w/GI
     9nkJ9AYoXpivFI8MTabuHDNa0/0psBv1nteKsBNcow4rKSb8RSuf2Itu0HT5a9t2H
    107VcvYcsQjNizgafy7FHuahYa855UwkdjGdpRntqxDqViDr69FErQI/VurM0YtrCZ
    118PiFA3i++igwMpgnsDBq0Guc+Ng2cqmyVIVVF3GlfEhHSZQPJbfopSeCfArdcgdY
    12TneK5tbSL/q0rRWIMOwBUoT2iuTv297E7rIFkAz0lg0STuOuIws5WfrbtE35Guv+
    13zpyRIhGS3a8YWCuSF3ZnwnqscOp/IpWt3ojzOCN/tbQO6JUi33WhYLP1BnE7Wnkl
    14hZDmDlSdniqjfqK9HR0754ia4Po5bQCGxJnNO5h9D4abpkb8I9Rjzty8agfZYwwW
    15kPsjLD0H
    16=AiEa
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash 9a3ed53c1fee1a38984565afc1e5e4de52ffa6dde5c6b84909b5d9645e01d6d1 -

  39. wallet/rpc: Use the default maxfeerate value as BTC/kB 261843e4be
  40. 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)
    2dfd6834ef
  41. in src/rpc/rawtransaction.cpp:45 in 49b1f48117 outdated
    44+/** High fee rate for sendrawtransaction and testmempoolaccept.
    45+ * By default, transaction with a fee rate higher than this will be rejected by
    46+ * the RPCs. This can be overridden with the maxfeerate argument.
    47  */
    48-constexpr static CAmount DEFAULT_MAX_RAW_TX_FEE{COIN / 10};
    49+const static CFeeRate DEFAULT_MAX_RAW_TX_FEE_RATE{COIN / 10};
    


    practicalswift commented at 11:02 am on August 18, 2019:
    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 … :-)

    remagpie commented at 3:17 pm on August 18, 2019:
    Fixed.
  42. remagpie force-pushed on Aug 18, 2019
  43. MarcoFalke commented at 7:17 pm on September 16, 2019: member
    re-run ci
  44. MarcoFalke closed this on Sep 16, 2019

  45. MarcoFalke reopened this on Sep 16, 2019

  46. remagpie commented at 2:08 am on September 17, 2019: contributor
    I couldn’t reproduce the failing test on my machine. Is it CI’s problem?
  47. laanwj commented at 2:47 pm on September 18, 2019: member
    ACK 2dfd6834ef8737e16e4b96df0c459f30a0721d6c (ACKs by Sjors and MarcoFalke above for trivially different code)
  48. laanwj referenced this in commit 0ee0474234 on Sep 18, 2019
  49. laanwj merged this on Sep 18, 2019
  50. laanwj closed this on Sep 18, 2019

  51. MarcoFalke commented at 6:36 pm on September 18, 2019: member

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

    Signature:

     0-----BEGIN PGP SIGNED MESSAGE-----
     1Hash: SHA512
     2
     3post-merge re-ACK 2dfd6834ef8737e16e4b96df0c459f30a0721d6c (only change is style nit)
     4-----BEGIN PGP SIGNATURE-----
     5
     6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
     7pUhodQv+N39HguRkVUKt6PzE2gGZ6BR0e9Jwypn08WD0kWVsrRwPOZzdpq/HBUys
     8Ispph9JBh3EXGFiBTwOPaybH1yLAEyyAvvFd0/sJifOblu3QfkKwwr8b81/+s8lE
     98SV+vwi0TWMVvSrq42DEdPtXlA65EhjBfRkuF4o58D7PtXa3l5keKbQGrVfZqnTb
    10OFZc0ZaWrjXd3cwhJo/W5SE4RHXSKxydq5qipkqYhCQ59y2M+F41WMHH89Q92jgO
    113iBUREvJb7/Yix4aM4DPK06DGaVUx5P7NxmJqsJfI4N4VY2QQF0MejpZRbe38Ddc
    12iVW69qby89m5VXIuc+boktMkfsqMI4YcUUTjLetI3tLGjWm//U2HLJRa1RHSAHhS
    13eHQ47zx7f+sNpFextdDmX2rTlGK7YO3j9b8dsaw4fLPgvy9ydENhqeTzX51cMtCi
    14D39F36riarcGlBRto14j0txq21+LeqBI4qdRy/pBCmgcneN5ktWnKfsqQK4hXTs9
    15pmvpv7um
    16=2xaT
    17-----END PGP SIGNATURE-----
    

    Timestamp of file with hash fbaf9ebc856aec97f9850a70c2b6a2435c1b4ab700db0b49752d9eb74c89975e -

  52. in test/functional/rpc_rawtransaction.py:442 in 2dfd6834ef
    438         vout = next(o for o in rawTx['vout'] if o['value'] == Decimal('1.00000000'))
    439 
    440         self.sync_all()
    441         inputs = [{ "txid" : txId, "vout" : vout['n'] }]
    442-        outputs = { self.nodes[0].getnewaddress() : Decimal("0.99999000") } # 1000 sat fee
    443+        outputs = { self.nodes[0].getnewaddress() : Decimal("0.999990000") } # 10000 sat fee
    


    MarcoFalke commented at 7:00 pm on September 18, 2019:

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

    0>>> 0.9 == 0.90
    1True
    

    kallewoof commented at 2:24 am on September 20, 2019:
    Yeah, should be 0.99990000

    remagpie commented at 2:57 am on September 20, 2019:
    OMG. I’ll send a patch soon.

    jonatack commented at 5:02 pm on September 21, 2019:

    Yeah, should be 0.99990000

    Done in #16929.

  53. sidhujag referenced this in commit 1871f280a4 on Sep 23, 2019
  54. laanwj referenced this in commit 742cd77f6f on Sep 25, 2019
  55. sidhujag referenced this in commit a16705aba6 on Sep 25, 2019
  56. deadalnix referenced this in commit 04e6d1809a on Oct 22, 2020
  57. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-19 09:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me