mempool / rpc: followup to getprioritisedtransactions and delete a mapDeltas entry when delta==0 #28885

pull kevkevinpal wants to merge 5 commits into bitcoin:master from kevkevinpal:followupsGetPrioritisedTransactions changing 3 files +23 −18
  1. kevkevinpal commented at 9:47 pm on November 15, 2023: contributor

    In this PR I am addressing some comments in #27501 as a followup.

    • changed prioritisation-map in the RPCResult to ""
    • Directly constructing 2 entry map for getprioritisedtransactions in functional tests
    • renamed txid to transactionid in RPCResult to be more consistent with naming elsewhere
    • exposed the modified_fee field instead of having it be a useless arg
    • Created a new test that asserts when prioritisedtransaction is called with a fee_delta of 0 it is not added to mempool
  2. DrahtBot commented at 9:47 pm on November 15, 2023: contributor

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

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK glozow

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Refactoring on Nov 15, 2023
  4. in src/rpc/mining.cpp:514 in abe31a5841 outdated
    507@@ -507,7 +508,12 @@ static RPCHelpMan getprioritisedtransactions()
    508             for (const auto& delta_info : mempool.GetPrioritisedTransactions()) {
    509                 UniValue result_inner{UniValue::VOBJ};
    510                 result_inner.pushKV("fee_delta", delta_info.delta);
    511+                CAmount modified_fee;
    512                 result_inner.pushKV("in_mempool", delta_info.in_mempool);
    513+                if(delta_info.in_mempool){
    514+                   modified_fee = *delta_info.modified_fee;
    515+                   result_inner.pushKV("modified_fee", (uint64_t)modified_fee);
    516+                }
    


    luke-jr commented at 11:46 pm on November 15, 2023:
    This isn’t a refactor.

    kevkevinpal commented at 0:13 am on November 16, 2023:
    good point let me change the title
  5. kevkevinpal renamed this:
    refactor: followup to getprioritisedtransactions and delete a mapDeltas entry when delta==0
    mempool / rpc: followup to getprioritisedtransactions and delete a mapDeltas entry when delta==0
    on Nov 16, 2023
  6. kevkevinpal marked this as ready for review on Nov 16, 2023
  7. ajtowns commented at 2:56 am on November 16, 2023: contributor
    Could you make the PR description a standalone statement of what this PR is trying to do, and leave the links to previous comments and questions in a separate comment?
  8. kevkevinpal commented at 4:09 pm on November 16, 2023: contributor

    Below are commits and corresponding comments they address

    80f7ccd test: Directly constructing 2 entry map for getprioritisedtransactions

    be75730 refactor: changed prioritisation-map -> ""

    49332a7 refactor: renaming txid -> transactionid

    816ee54 refactor: exposing modified_fee in getprioritisedtransactions

    7e54f44 test: Assert that a new tx with a delta of 0 is never added

    TODO/comments not addressed yet in this PR

    These might make more sense in their own pr? #27501 (review) #27501 (review) #27501 (review)

    Unsure if this is wanted #27501 (review)

  9. test: Directly constructing 2 entry map for getprioritisedtransactions
    Directly constructing the map in the assertion instead of indexing by txid
    so that we wouldn't miss new entries in future regressions.
    3a118e19e1
  10. in test/functional/mining_prioritisetransaction.py:115 in 80f7ccdefd outdated
    110@@ -111,9 +111,8 @@ def test_diamond(self):
    111         raw_after = self.nodes[0].getrawmempool(verbose=True)
    112         assert_equal(raw_before[txid_a], raw_after[txid_a])
    113         assert_equal(raw_before, raw_after)
    114-        prioritisation_map_in_mempool = self.nodes[0].getprioritisedtransactions()
    115-        assert_equal(prioritisation_map_in_mempool[txid_b], {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True})
    116-        assert_equal(prioritisation_map_in_mempool[txid_c], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True})
    117+        assert_equal(self.nodes[0].getprioritisedtransactions()[txid_b], {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True})
    118+        assert_equal(self.nodes[0].getprioritisedtransactions()[txid_c], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True})
    


    maflcko commented at 11:34 am on November 20, 2023:

    I don’t understand the first commit message:

    0 test: Directly constructing 2 entry map for getprioritisedtransactions
    1
    2Directly constructing the map so that we wouldn't miss extraneous
    3entries in future regressions.
    

    What does it mean and why is the code changed? Can you give an example or explanation?


    kevkevinpal commented at 0:08 am on November 22, 2023:

    I think I may have miss read the initial comment but I have updated the message and the tests.

    I am now testing the whole object we get back from self.nodes[0].getprioritisedtransactions() so in the future if there are new transactions added this assertion will fail

  11. kevkevinpal force-pushed on Nov 22, 2023
  12. kevkevinpal commented at 0:10 am on November 22, 2023: contributor

    looks like the “test each commit” git action failed but doesn’t seems related to the changes proposed

    I see the following in the logs

    0E: Failed to fetch mirror+file:/etc/apt/apt-mirrors.txt/pool/main/a/avahi/libavahi-core7_0.8-5ubuntu5.1_amd64.deb  404  Not Found [IP: 52.252.75.106 80]
    1E: Failed to fetch mirror+file:/etc/apt/apt-mirrors.txt/pool/main/a/avahi/avahi-daemon_0.8-5ubuntu5.1_amd64.deb  404  Not Found [IP: 52.252.75.106 80]
    
  13. kevkevinpal requested review from luke-jr on Nov 22, 2023
  14. kevkevinpal requested review from maflcko on Nov 22, 2023
  15. in src/rpc/mining.cpp:492 in cf848d7935 outdated
    488@@ -489,7 +489,7 @@ static RPCHelpMan getprioritisedtransactions()
    489         RPCResult{
    490             RPCResult::Type::OBJ_DYN, "", "prioritisation keyed by txid",
    491             {
    492-                {RPCResult::Type::OBJ, "txid", "", {
    493+                {RPCResult::Type::OBJ, "transactionid", "", {
    


    maflcko commented at 9:56 am on November 22, 2023:
    commit message: This is not a refactor

    kevkevinpal commented at 3:08 pm on November 22, 2023:

    updated the commit message in 9a918a4

    I also fixed the other ones that had refactor in the commit message since they weren’t really refactors either


    glozow commented at 11:30 am on November 27, 2023:
    9a918a4720ee091344a16dcd703d169ebdb7938e: Not sure if we should change results at this point?

    jonatack commented at 3:15 pm on November 27, 2023:
    Agree, as this RPC is already in the v26 release and isn’t a hidden RPC or one labelled as experimental, changing the output name in a later release could cause software consuming this API to no longer work.

    maflcko commented at 3:29 pm on November 27, 2023:
    This only changes the docs, no?

    jonatack commented at 3:45 pm on November 27, 2023:

    Oh, ok (it would be clearer to me if it was presented a little differently, along with the other instances).

    0-                {RPCResult::Type::OBJ, "transactionid", "", {
    1+                {RPCResult::Type::OBJ, "<transactionid>", "", {
    

    kevkevinpal commented at 0:09 am on November 29, 2023:
    updated this in this force push da0036c97c4bf4ad8498ee8c27cdb395636aa6fb
  16. in src/rpc/mining.cpp:515 in e13b1b8c5b outdated
    507@@ -507,7 +508,12 @@ static RPCHelpMan getprioritisedtransactions()
    508             for (const auto& delta_info : mempool.GetPrioritisedTransactions()) {
    509                 UniValue result_inner{UniValue::VOBJ};
    510                 result_inner.pushKV("fee_delta", delta_info.delta);
    511+                CAmount modified_fee;
    512                 result_inner.pushKV("in_mempool", delta_info.in_mempool);
    513+                if(delta_info.in_mempool){
    514+                   modified_fee = *delta_info.modified_fee;
    515+                   result_inner.pushKV("modified_fee", (uint64_t)modified_fee);
    


    maflcko commented at 9:57 am on November 22, 2023:
    Why the c-style cast at all?

    kevkevinpal commented at 3:12 pm on November 22, 2023:
    thanks! fixed in e3f2fc0
  17. kevkevinpal force-pushed on Nov 22, 2023
  18. kevkevinpal force-pushed on Nov 22, 2023
  19. in test/functional/mining_prioritisetransaction.py:268 in a1fb3eddc9 outdated
    262@@ -263,6 +263,12 @@ def run_test(self):
    263             if (x != high_fee_tx):
    264                 assert x not in mempool
    265 
    266+
    267+        self.log.info("Assert that prioritised free transaction with 0 delta is never added to mapDeltas")
    268+        tx_id_zero_del = self.wallet.create_self_transfer(fee_rate=0)['txid']
    


    glozow commented at 11:28 am on November 27, 2023:

    in a1fb3eddc91db708727fc48309d3bb6182858bbd

    I don’t think it matters what the feerate of this tx is?

    0        self.log.info("Assert that 0 delta is never added to mapDeltas")
    1        tx_id_zero_del = self.wallet.create_self_transfer()['txid']
    

    kevkevinpal commented at 10:41 pm on November 29, 2023:
    thanks! Yes you are right updated the test in 0d3a4ab
  20. glozow commented at 11:30 am on November 27, 2023: member
    Thanks for the followup!
  21. in src/rpc/mining.cpp:509 in a1fb3eddc9 outdated
    508@@ -508,6 +509,9 @@ static RPCHelpMan getprioritisedtransactions()
    509                 UniValue result_inner{UniValue::VOBJ};
    510                 result_inner.pushKV("fee_delta", delta_info.delta);
    511                 result_inner.pushKV("in_mempool", delta_info.in_mempool);
    512+                if(delta_info.in_mempool){
    


    jonatack commented at 3:19 pm on November 27, 2023:
    Don’t hesitate to run clang-format on your change locally before pushing, i.e. git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v, with HEAD~<number of commits in your change>

    kevkevinpal commented at 10:28 pm on November 29, 2023:
    thanks! I didnt know this was a command I could use, I will save it for later. I applied it to my commits and force pushed
  22. in src/rpc/mining.cpp:494 in a1fb3eddc9 outdated
    491+            RPCResult::Type::OBJ_DYN, "", "prioritisation keyed by txid",
    492             {
    493-                {RPCResult::Type::OBJ, "txid", "", {
    494+                {RPCResult::Type::OBJ, "transactionid", "", {
    495                     {RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
    496+                    {RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "new fee for this transactionid if in mempool"},
    


    jonatack commented at 3:25 pm on November 27, 2023:
    0                    {RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "new fee for this transaction. Only returned if transaction is in mempool"},
    

    As modified_fee is the only optional field in the result and depends on the value of the in_mempool field, would it be better to put it after the always-present fields, i.e. after in_mempool?


    kevkevinpal commented at 10:31 pm on November 29, 2023:
    makes sense thanks! force pushed in 2f11d8d
  23. kevkevinpal force-pushed on Nov 28, 2023
  24. kevkevinpal force-pushed on Nov 28, 2023
  25. kevkevinpal force-pushed on Nov 28, 2023
  26. kevkevinpal force-pushed on Nov 29, 2023
  27. kevkevinpal force-pushed on Nov 29, 2023
  28. kevkevinpal force-pushed on Nov 29, 2023
  29. kevkevinpal force-pushed on Nov 29, 2023
  30. kevkevinpal requested review from glozow on Dec 3, 2023
  31. kevkevinpal requested review from maflcko on Dec 3, 2023
  32. kevkevinpal requested review from jonatack on Dec 3, 2023
  33. in src/rpc/mining.cpp:491 in 401662f21e outdated
    494-                {RPCResult::Type::OBJ, "txid", "", {
    495-                    {RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
    496-                    {RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},
    497-                }}
    498-            },
    499+            RPCResult::Type::OBJ_DYN,
    


    glozow commented at 9:48 am on December 18, 2023:
    question - why the indentation changes?

    kevkevinpal commented at 2:40 am on December 19, 2023:
    @jonatack said that I should run the script in this comment and it lead to there being a indentation, I can remove if needed

    glozow commented at 10:59 am on December 20, 2023:
    That’s fine for lines that you’re adding or already changing (which iiuc is what jonatack was suggesting as well). To make review easier, I wouldn’t recommend reformatting other lines, as it crowds the diff.

    kevkevinpal commented at 1:04 am on January 9, 2024:
    fixed in latest force push fba275b
  34. in test/functional/mining_prioritisetransaction.py:48 in 2f11d8d07e outdated
    44@@ -45,15 +45,15 @@ def test_replacement(self):
    45         self.nodes[0].prioritisetransaction(tx_replacee["txid"], 0, 100)
    46         assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : False}})
    47         self.nodes[0].sendrawtransaction(tx_replacee["hex"])
    48-        assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : True}})
    49+        assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : True, "modified_fee": 1140}})
    


    glozow commented at 9:51 am on December 18, 2023:
    2f11d8d07e9141c56f6f7cc4e406d73723ead6e3 instead of magic numbers, can you make this programmatic, i.e. the tx fee + delta?

    kevkevinpal commented at 2:18 am on January 9, 2024:
    updated in 74fae193384b722462a9ede2d55b3375bad74332
  35. in test/functional/mining_prioritisetransaction.py:270 in 0d3a4abd80 outdated
    262@@ -263,6 +263,12 @@ def run_test(self):
    263             if (x != high_fee_tx):
    264                 assert x not in mempool
    265 
    266+
    267+        self.log.info("Assert that 0 delta is never added to mapDeltas")
    268+        tx_id_zero_del = self.wallet.create_self_transfer()['txid']
    269+        self.nodes[0].prioritisetransaction(txid=tx_id_zero_del, fee_delta=0)
    270+        assert tx_id_zero_del not in self.nodes[0].getrawmempool()
    


    glozow commented at 9:53 am on December 18, 2023:

    in 0d3a4abd805e3d4deec25f9902e762a7e693ce6b

    This is just testing that you didn’t submit the transaction. Did you mean to use the getprioritisedtransactions RPC instead?


    kevkevinpal commented at 2:22 am on January 9, 2024:
    yes you are right updated in 3fbcbc2
  36. glozow commented at 10:19 am on January 8, 2024: member
    Still working on this? I’ll be available to re-review quickly after comments are addressed.
  37. kevkevinpal commented at 3:28 pm on January 8, 2024: contributor

    Still working on this? I’ll be available to re-review quickly after comments are addressed.

    yes sorry I can try and make some followup changes to the comments soon

  38. kevkevinpal force-pushed on Jan 9, 2024
  39. kevkevinpal force-pushed on Jan 9, 2024
  40. kevkevinpal force-pushed on Jan 9, 2024
  41. kevkevinpal force-pushed on Jan 9, 2024
  42. rpc: changed prioritisation-map -> ""
    prioritisation-map gets eaten by the help generator to be "" so we are
    setting to "" to begin with
    2fca6c2dd0
  43. rpc: renaming txid -> transactionid
    renamed to transactionid because it is named this way in getrawmempool
    and getmempoolancestors
    252a86729a
  44. kevkevinpal force-pushed on Jan 9, 2024
  45. kevkevinpal force-pushed on Jan 9, 2024
  46. in test/functional/mempool_expiry.py:46 in 74fae19338 outdated
    41@@ -42,7 +42,8 @@ def test_transaction_expiry(self, timeout):
    42 
    43         # Add prioritisation to this transaction to check that it persists after the expiry
    44         node.prioritisetransaction(parent_txid, 0, COIN)
    45-        assert_equal(node.getprioritisedtransactions()[parent_txid], { "fee_delta" : COIN, "in_mempool" : True})
    46+        # Fee rate found in test/functional/test_framework/wallet.py create_self_transfer
    47+        assert_equal(node.getprioritisedtransactions()[parent_txid], { "fee_delta" : COIN, "in_mempool" : True, "modified_fee": COIN + COIN * (0.003 * 104 / 1000) })
    


    kevkevinpal commented at 2:17 am on January 9, 2024:
    Added a comment ontop showing where I got these numbers from

    glozow commented at 11:49 am on January 9, 2024:

    These are still magic numbers, even if they are accurate. The comment is helpful, but doesn’t change the fact that this test relies on the implementation of create_self_transfer, making it brittle. If we were to change the implementation so that the virtual size could be something other than 104, or if we adjusted the default feerate to something other than 0.003, this test would break, even though the mempool/RPC logic hasn’t changed.

    I was suggesting that you assign variables and reuse them in this test:

    • fee_delta to use in prioritisetransaction
    • parent_fee meaning the absolute fees of the tx. If you’re having trouble getting the fee, it’ll be one of the results returned from send_self_transfer.
    • assert here that modified_fee is equal to parent_fee + fee_delta

    kevkevinpal commented at 2:56 am on January 10, 2024:
    not sure why I didn’t think of just using the value returned from create_self_transfer fixed in dc189d3
  47. kevkevinpal force-pushed on Jan 9, 2024
  48. kevkevinpal force-pushed on Jan 10, 2024
  49. kevkevinpal force-pushed on Jan 10, 2024
  50. kevkevinpal requested review from glozow on Jan 10, 2024
  51. in src/rpc/mining.cpp:495 in dc189d3ec5 outdated
    491@@ -492,6 +492,7 @@ static RPCHelpMan getprioritisedtransactions()
    492                 {RPCResult::Type::OBJ, "<transactionid>", "", {
    493                     {RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
    494                     {RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},
    495+                    {RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "new fee for this transaction. Only returned if transaction is in mempool"},
    


    glozow commented at 9:16 am on January 11, 2024:

    dc189d3ec5c4af9bca02928dfeb4770570060982: I’m not sure that “new fee” would be understood by people. It would also be helpful to add the units here, i.e.

    0                    {RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "modified fee in satoshis. Only returned if in_mempool=true"},
    

    kevkevinpal commented at 2:18 pm on January 11, 2024:
    updated in cfdbcd19b32fd63954d7947dcc639aef291fb6b2
  52. glozow commented at 9:18 am on January 11, 2024: member
    ACK 5353af1c8a2dd402a303a786d8aae5edbfc1ff3a
  53. rpc: exposing modified_fee in getprioritisedtransactions
    Instead of having modified_fee be hidden we are now exposing it to avoid
    having useless code
    cfdbcd19b3
  54. test: Assert that a new tx with a delta of 0 is never added 0eebd6fe7d
  55. kevkevinpal force-pushed on Jan 11, 2024
  56. glozow commented at 3:12 pm on January 11, 2024: member
    reACK 0eebd6fe7d01ddc7f6b7f13a6ed6e705c7aeae4e, only change is the doc suggestion
  57. glozow assigned glozow on Jan 12, 2024
  58. glozow merged this on Jan 12, 2024
  59. glozow closed this on Jan 12, 2024

  60. glozow unassigned glozow on Jan 12, 2024

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-09-28 22:12 UTC

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