-
Notifications
You must be signed in to change notification settings - Fork 37.7k
p2p: unbroadcast followups: rpcs, nLastResend, mempool sanity check #18895
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
Conversation
My assumption is that those TODOs would be taken care of as part of #18807. Is that correct @amitiuttarwar ? |
@fanquake sorry for the confusion 😛 |
@amitiuttarwar Yea of course. Just wanted to clarify that you weren't both working on the same changes in parallel. |
@fanquake thanks! Concept ACK :) will review soon |
b47cd8b
to
7abdadf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, but it looks like the mempool_packages
has a hardcoded mempool entry in the test, so that fails because the hardcoded entry is missing the unbraodcast
key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK.
I think that mempool_packages.py
just needs to wait a bit so that the unbroadcast status of txns does not change in between the getrawmempool
and getmempoolentry
calls because of delays in the p2p.
Also, it's confusing that #18807 has (almost) the same name as this PR, so maybe change the title?
Concept ACK. Code looks good, will do ACK when @MarcoFalke comments are addressed. |
b320734
to
365defb
Compare
Sorry for all the force pushes 😅. Addressed MarcoFalke's comments and the With |
365defb
to
cd76381
Compare
I meant an earlier spot in my comment: The |
cd76381
to
4ebe10f
Compare
@mzumsande OMG I am so sorry 🤦♀️ that should have been obvious. Just fixed it (I hope), waiting to see what travis says. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
4ebe10f
to
c8ac437
Compare
c8ac437
to
bc2d7a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost ACK
bc2d7a9
to
827fc85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall, the code looks good! the approaches are simple & make sense. solid test coverage. I also appreciate the thoughtful documentation :) thank you for taking this on!
I left a bunch of nits and thoughts to consider. Other than removing the const
to get rid of the build warning, feel free to take or leave whatever.
Just to note- this code adds unbroadcast info to 5 different RPC methods. Of these 5, the unbroadcast info of 2 are explicitly tested from the functional tests (getmempoolinfo
, getrawmempool
). But the others are implicitly tested because its a shared data structure that serves the data (getmempoolancestors
, getmempooldescendants
, getmempoolentry
). That coverage seems sufficient to me.
I like the wait_for_broadcast
method & how it encapsulates the synchronization required to ensure a txn is removed from the unbroadcast set. have you checked if there are other rpc call sites in the tests that might benefit (aka help prevent weird race conditions)? I’ll double check this for my next round of review.
thanks!
also I realized, since this updates some RPC endpoints, should there be release notes added? @MarcoFalke |
Sure, but I assumed this would be taken care of in the doc pr #18807 |
- expose info about number of txns in unbroadcast set and whether a mempool entry's tx has passed initial broadcast - makes rpcs more informative and allows for more explicit testing, eg tracking if tx is in unbroadcast set before and after originating node connects to peers (adds this in mempool_unbroadcast.py) - adds mempool method IsUnbroadcastTx to query for tx inclusion in mempool's unbroadcast set
- before reattempting broadcast for unbroadcast txns, check they are in mempool and remove if not - this protects from memory leaks and network spam just in case unbroadcast set (incorrectly) has extra txns - check that tx is in mempool before adding to unbroadcast set to try to prevent this from happening
- mempool entry 'unbroadcast' field changes when tx passes initial broadcast (receive getdata), so anytime you compare mempool entries as a whole, you must wait for all broadcasts to complete ('unbroadcast' = False) otherwise the state may change in between calls - update P2PTxInvStore to send msg_getdata for invs and add functionality to wait for a list of txids to complete initial broadcast - make mempool_packages.py wait because it compares entries using getrawmempool and getmempoolentry
827fc85
to
651f1d8
Compare
Review ACK 651f1d8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 651f1d8
ACK 651f1d8 🎉 double checked functional tests for possible races around returning |
…empool sanity check 651f1d8 [test] wait for inital broadcast before comparing mempool entries (gzhao408) 9d3f7eb [mempool] sanity check that all unbroadcast txns are in mempool (gzhao408) a7ebe48 [rpc] add unbroadcast info to mempool entries and getmempoolinfo (gzhao408) d160069 [wallet] remove nLastResend logic (gzhao408) Pull request description: Followup to bitcoin#18038 by amitiuttarwar which introduces the unbroadcast set: "a mechanism for the mempool to track locally submitted transactions" and decreases the frequency of rebroadcast from 10-15 minutes to 12-36 hours. This PR addresses some of the outstanding TODOs building on top of it: - remove `nLastResend` logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). (bitcoin#18038 [comment](bitcoin#18038 (comment))) - expose unbroadcast info via RPCs, for more informative queries and testing (bitcoin#18038 [comment](bitcoin#18038 (comment))) - add sanity check to verify unbroadcast transactions still exist in mempool before rebroadcasting (bitcoin#18038 [comment](bitcoin#18038 (comment))) ACKs for top commit: naumenkogs: Code review ACK 651f1d8 amitiuttarwar: ACK 651f1d8 🎉 MarcoFalke: Review ACK 651f1d8 Tree-SHA512: d5327e95ef39d44152b48df5c610502ae11c168f43dbbfb2885340c93d1ba9426eb3a5794573f5fc843502109cb3ffb63efa3f2db4f8f112efcde8f76d9a8845
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Posthumous code review ACK 651f1d8
@@ -716,6 +719,12 @@ class CTxMemPool | |||
return m_unbroadcast_txids; | |||
} | |||
|
|||
// Returns if a txid is in the unbroadcast set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be doxygen like the neighbouring functions. Perhaps touch up in #18807.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -399,6 +399,7 @@ static std::vector<RPCResult> MempoolEntryDescription() { return { | |||
RPCResult{RPCResult::Type::ARR, "spentby", "unconfirmed transactions spending outputs from this transaction", | |||
{RPCResult{RPCResult::Type::STR_HEX, "transactionid", "child transaction id"}}}, | |||
RPCResult{RPCResult::Type::BOOL, "bip125-replaceable", "Whether this transaction could be replaced due to BIP125 (replace-by-fee)"}, | |||
RPCResult{RPCResult::Type::BOOL, "unbroadcast", "Whether this transaction is currently unbroadcast (initial broadcast not yet confirmed)"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested rephrasing: s/confirmed/acknowledged/. I think "confirmed" might confuse the user into thinking we're referring to the transaction being included in a block. Perhaps "acknowledged" would be less confusing, or if a few more words are ok, "(initial broadcast not yet acknowledged by any peers)". Maybe @amitiuttarwar can squeeze this in #18807 (if not, I can open a separate PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great suggestion. adding to #18807
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
9e1cb1a [trivial/doc] Fix comment type (Amiti Uttarwar) 8f30260 [doc] Update unbroadcast description in RPC results (Amiti Uttarwar) 750456d [trivial] Remove misleading 'const' (Amiti Uttarwar) fa32e67 [test] Manage node connections better in mempool persist test (Amiti Uttarwar) 1f94bb0 [doc] Provide rationale for randomization in scheduling. (Amiti Uttarwar) 9c8a55d [mempool] Don't throw expected error message when upgrading (Amiti Uttarwar) ba54983 [test] Test that wallet transactions aren't rebroadcast before 12 hours (Amiti Uttarwar) 00d44a5 [test] P2P connection behavior should meet expectations (Amiti Uttarwar) bd093ca [test] updates to unbroadcast test (Amiti Uttarwar) dab298d [docs] add release notes (Amiti Uttarwar) Pull request description: This PR is a follow up to bitcoin#18038 which introduced the idea of an unbroadcast set & focuses mostly on documentation updates and test fixes. One small functionality update to not throw an expected error in `LoadMempool` when you upgrade software versions. bitcoin#18895 is another follow up to that addresses other functionality updates. Background context: The unbroadcast set is a mechanism for the mempool to track locally submitted transactions (via wallet or RPC). The node does a best-effort of delivering the transactions to the network via retries every 10-15 minutes until either a `GETDATA` is received or the transaction is removed from the mempool. ACKs for top commit: MarcoFalke: ACK 9e1cb1a 👁 gzhao408: ACK [`9e1cb1a`](bitcoin@9e1cb1a) Tree-SHA512: 0cd51c4ca368b9dce92d50d73ec6e9df278a259e609eef2858f24cb8595ad07acc3db781d9eb0c351715f18fca5a2b4526838981fdb34a522427e9dc868bdaa6
9e1cb1a [trivial/doc] Fix comment type (Amiti Uttarwar) 8f30260 [doc] Update unbroadcast description in RPC results (Amiti Uttarwar) 750456d [trivial] Remove misleading 'const' (Amiti Uttarwar) fa32e67 [test] Manage node connections better in mempool persist test (Amiti Uttarwar) 1f94bb0 [doc] Provide rationale for randomization in scheduling. (Amiti Uttarwar) 9c8a55d [mempool] Don't throw expected error message when upgrading (Amiti Uttarwar) ba54983 [test] Test that wallet transactions aren't rebroadcast before 12 hours (Amiti Uttarwar) 00d44a5 [test] P2P connection behavior should meet expectations (Amiti Uttarwar) bd093ca [test] updates to unbroadcast test (Amiti Uttarwar) dab298d [docs] add release notes (Amiti Uttarwar) Pull request description: This PR is a follow up to bitcoin#18038 which introduced the idea of an unbroadcast set & focuses mostly on documentation updates and test fixes. One small functionality update to not throw an expected error in `LoadMempool` when you upgrade software versions. bitcoin#18895 is another follow up to that addresses other functionality updates. Background context: The unbroadcast set is a mechanism for the mempool to track locally submitted transactions (via wallet or RPC). The node does a best-effort of delivering the transactions to the network via retries every 10-15 minutes until either a `GETDATA` is received or the transaction is removed from the mempool. ACKs for top commit: MarcoFalke: ACK 9e1cb1a 👁 gzhao408: ACK [`9e1cb1a`](bitcoin@9e1cb1a) Tree-SHA512: 0cd51c4ca368b9dce92d50d73ec6e9df278a259e609eef2858f24cb8595ad07acc3db781d9eb0c351715f18fca5a2b4526838981fdb34a522427e9dc868bdaa6
…empool sanity check 651f1d8 [test] wait for inital broadcast before comparing mempool entries (gzhao408) 9d3f7eb [mempool] sanity check that all unbroadcast txns are in mempool (gzhao408) a7ebe48 [rpc] add unbroadcast info to mempool entries and getmempoolinfo (gzhao408) d160069 [wallet] remove nLastResend logic (gzhao408) Pull request description: Followup to bitcoin#18038 by amitiuttarwar which introduces the unbroadcast set: "a mechanism for the mempool to track locally submitted transactions" and decreases the frequency of rebroadcast from 10-15 minutes to 12-36 hours. This PR addresses some of the outstanding TODOs building on top of it: - remove `nLastResend` logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). (bitcoin#18038 [comment](bitcoin#18038 (comment))) - expose unbroadcast info via RPCs, for more informative queries and testing (bitcoin#18038 [comment](bitcoin#18038 (comment))) - add sanity check to verify unbroadcast transactions still exist in mempool before rebroadcasting (bitcoin#18038 [comment](bitcoin#18038 (comment))) ACKs for top commit: naumenkogs: Code review ACK 651f1d8 amitiuttarwar: ACK 651f1d8 🎉 MarcoFalke: Review ACK 651f1d8 Tree-SHA512: d5327e95ef39d44152b48df5c610502ae11c168f43dbbfb2885340c93d1ba9426eb3a5794573f5fc843502109cb3ffb63efa3f2db4f8f112efcde8f76d9a8845
9e1cb1a [trivial/doc] Fix comment type (Amiti Uttarwar) 8f30260 [doc] Update unbroadcast description in RPC results (Amiti Uttarwar) 750456d [trivial] Remove misleading 'const' (Amiti Uttarwar) fa32e67 [test] Manage node connections better in mempool persist test (Amiti Uttarwar) 1f94bb0 [doc] Provide rationale for randomization in scheduling. (Amiti Uttarwar) 9c8a55d [mempool] Don't throw expected error message when upgrading (Amiti Uttarwar) ba54983 [test] Test that wallet transactions aren't rebroadcast before 12 hours (Amiti Uttarwar) 00d44a5 [test] P2P connection behavior should meet expectations (Amiti Uttarwar) bd093ca [test] updates to unbroadcast test (Amiti Uttarwar) dab298d [docs] add release notes (Amiti Uttarwar) Pull request description: This PR is a follow up to bitcoin#18038 which introduced the idea of an unbroadcast set & focuses mostly on documentation updates and test fixes. One small functionality update to not throw an expected error in `LoadMempool` when you upgrade software versions. bitcoin#18895 is another follow up to that addresses other functionality updates. Background context: The unbroadcast set is a mechanism for the mempool to track locally submitted transactions (via wallet or RPC). The node does a best-effort of delivering the transactions to the network via retries every 10-15 minutes until either a `GETDATA` is received or the transaction is removed from the mempool. ACKs for top commit: MarcoFalke: ACK 9e1cb1a eye gzhao408: ACK [`9e1cb1a`](9e1cb1a) Tree-SHA512: 0cd51c4ca368b9dce92d50d73ec6e9df278a259e609eef2858f24cb8595ad07acc3db781d9eb0c351715f18fca5a2b4526838981fdb34a522427e9dc868bdaa6
…empool sanity check 651f1d8 [test] wait for inital broadcast before comparing mempool entries (gzhao408) 9d3f7eb [mempool] sanity check that all unbroadcast txns are in mempool (gzhao408) a7ebe48 [rpc] add unbroadcast info to mempool entries and getmempoolinfo (gzhao408) d160069 [wallet] remove nLastResend logic (gzhao408) Pull request description: Followup to bitcoin#18038 by amitiuttarwar which introduces the unbroadcast set: "a mechanism for the mempool to track locally submitted transactions" and decreases the frequency of rebroadcast from 10-15 minutes to 12-36 hours. This PR addresses some of the outstanding TODOs building on top of it: - remove `nLastResend` logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). (bitcoin#18038 [comment](bitcoin#18038 (comment))) - expose unbroadcast info via RPCs, for more informative queries and testing (bitcoin#18038 [comment](bitcoin#18038 (comment))) - add sanity check to verify unbroadcast transactions still exist in mempool before rebroadcasting (bitcoin#18038 [comment](bitcoin#18038 (comment))) ACKs for top commit: naumenkogs: Code review ACK 651f1d8 amitiuttarwar: ACK 651f1d8 🎉 MarcoFalke: Review ACK 651f1d8 Tree-SHA512: d5327e95ef39d44152b48df5c610502ae11c168f43dbbfb2885340c93d1ba9426eb3a5794573f5fc843502109cb3ffb63efa3f2db4f8f112efcde8f76d9a8845
9e1cb1a [trivial/doc] Fix comment type (Amiti Uttarwar) 8f30260 [doc] Update unbroadcast description in RPC results (Amiti Uttarwar) 750456d [trivial] Remove misleading 'const' (Amiti Uttarwar) fa32e67 [test] Manage node connections better in mempool persist test (Amiti Uttarwar) 1f94bb0 [doc] Provide rationale for randomization in scheduling. (Amiti Uttarwar) 9c8a55d [mempool] Don't throw expected error message when upgrading (Amiti Uttarwar) ba54983 [test] Test that wallet transactions aren't rebroadcast before 12 hours (Amiti Uttarwar) 00d44a5 [test] P2P connection behavior should meet expectations (Amiti Uttarwar) bd093ca [test] updates to unbroadcast test (Amiti Uttarwar) dab298d [docs] add release notes (Amiti Uttarwar) Pull request description: This PR is a follow up to bitcoin#18038 which introduced the idea of an unbroadcast set & focuses mostly on documentation updates and test fixes. One small functionality update to not throw an expected error in `LoadMempool` when you upgrade software versions. bitcoin#18895 is another follow up to that addresses other functionality updates. Background context: The unbroadcast set is a mechanism for the mempool to track locally submitted transactions (via wallet or RPC). The node does a best-effort of delivering the transactions to the network via retries every 10-15 minutes until either a `GETDATA` is received or the transaction is removed from the mempool. ACKs for top commit: MarcoFalke: ACK 9e1cb1a eye gzhao408: ACK [`9e1cb1a`](9e1cb1a) Tree-SHA512: 0cd51c4ca368b9dce92d50d73ec6e9df278a259e609eef2858f24cb8595ad07acc3db781d9eb0c351715f18fca5a2b4526838981fdb34a522427e9dc868bdaa6
Summary: remove nLastResend logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). 1 This is a backport of Core [[bitcoin/bitcoin#18895 | PR18895]] [1/3] bitcoin/bitcoin@d160069 Depends on D9027 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D9023
Summary: a7ebe48b94c5a9195c8eabd193204c499cb4bfdb - expose info about number of txns in unbroadcast set and whether a mempool entry's tx has passed initial broadcast - makes rpcs more informative and allows for more explicit testing, eg tracking if tx is in unbroadcast set before and after originating node connects to peers (adds this in mempool_unbroadcast.py) - adds mempool method IsUnbroadcastTx to query for tx inclusion in mempool's unbroadcast set ------ 651f1d816f054cb9c637f8a99c9360bba381ef58 - mempool entry 'unbroadcast' field changes when tx passes initial broadcast (receive getdata), so anytime you compare mempool entries as a whole, you must wait for all broadcasts to complete ('unbroadcast' = False) otherwise the state may change in between calls - update P2PTxInvStore to send msg_getdata for invs and add functionality to wait for a list of txids to complete initial broadcast - make mempool_packages.py wait because it compares entries using getrawmempool and getmempoolentry ------ This is a backport of Core [[bitcoin/bitcoin#18895 | PR18895]] [2/3] bitcoin/bitcoin@a7ebe48 bitcoin/bitcoin@651f1d8 Depends on D9023 Test Plan: ninja && test/functional/test_runner.py mempool_* Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D9024
Summary: - before reattempting broadcast for unbroadcast txns, check they are in mempool and remove if not - this protects from memory leaks and network spam just in case unbroadcast set (incorrectly) has extra txns - check that tx is in mempool before adding to unbroadcast set to try to prevent this from happening This is a backport of Core [[bitcoin/bitcoin#18895 | PR18895]] [3/3] bitcoin/bitcoin@9d3f7eb Depends on D9024 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D9025
Followup to #18038 by amitiuttarwar which introduces the unbroadcast set: "a mechanism for the mempool to track locally submitted transactions" and decreases the frequency of rebroadcast from 10-15 minutes to 12-36 hours.
This PR addresses some of the outstanding TODOs building on top of it:
nLastResend
logic, which is used to ensure rebroadcast doesn't happen again if no new block has been mined (makes sense in 10-15 min period, but not necessary for 12-36 hour period). (P2P: Mempool tracks locally submitted transactions to improve wallet privacy #18038 comment)