-
Notifications
You must be signed in to change notification settings - Fork 37.7k
tests, bug fix: DisconnectedBlockTransactions rewrite followups #28530
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
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
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.
Thanks for opening a followup! Did you want to pick up the memusage unit test too? (9dcef47 or a new one)
8c315c7
to
2517862
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.
ACK 2517862
Great job on moving the implementation code from the header file to disconnected_transactions.cpp. This was a necessary step, especially considering how significantly the code had grown.
2517862
to
436f53f
Compare
Added a commit to address review comment #28385 (comment) And rebased due to #28567 being merged for CI to be green |
8742350
to
225c9c3
Compare
Added the the test. |
cc @theuni @stickies-v who made some of the suggestions being addressed and reviewed the test previously |
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.
Approach ACK 225c9c3
Even though they're both correct and an improvement, I'd drop 6f5768d and 89c994a. For both, the fixups are arbitrary and incomplete (e.g. there are plenty of other places where we don't use list initialization in validation.cpp
, so why are only these two being fixed? "It's a follow-up" is a bit of a wonky rationale. I'd say let's not do it, or do it consistently and ideally enforce it (which I don't think is suitable for this PR). Likewise for the clang-format fixes. Inconsistent style-only refactors are generally a hard sell.
note: I reviewed 72ebef1 with --color-moved=zebra --color-moved-ws="allow-indentation-change"
(always useful to mention those things in PR description to help reviewers be more productive)
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.
Note for other reviewers: these are the memory allocation numbers I'm getting on my machine:
(lldb) p MAP_1
(const size_t) 32
(lldb) p MAP_100
(const size_t) 832
(lldb) p TX_USAGE
(const size_t) 640
(lldb) p ENTRY_USAGE_OVERESTIMATE
(const size_t) 896
Thanks for your review @stickies-v, will drop the commits as you suggested and address comments. |
6d922c3
to
8faa980
Compare
Force pushed 225c9c3 to 8faa980
|
ACK the first 3 commits. I'll pass on re-reviewing the test commit and confusing myself about memory accounting again :) |
In `AddTransactionsToBlock` description comment we have the asuumption that callers will never pass multiple transactions with the same txid We are asserting to assume that does not happen.
8faa980
to
3c00943
Compare
3c00943
to
e9906c1
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.
ACK e9906c1
Just 2 nits, happy to quickly re-ack since no other acks yet.
edit: PR description needs updating, would change title to tests, bugfix
and add the bugfix in the description, as well as the "assume duplicate transactions are not added to iters_by_txid
" commit
e9906c1
to
2c40895
Compare
With `queuedTx` owning the `CTransactionRef` shared ptrs, they (and the managed objects) are entirely allocated on the heap. In `DisconnectedBlockTransactions::DynamicMemoryUsage`, we account for the 2 pointers that make up the shared_ptr, but not for the managed object (CTransaction) or the control block. Prior to this commit, by calculating the `RecursiveDynamicUsage` on a `CTransaction` whenever modifying `cachedInnerUsage`, we account for the dynamic usage of the `CTransaction`, i.e. the `vins` and `vouts` vectors, but we do not account for the `CTransaction` object itself, nor for the `CTransactionRef` control block. This means prior to this commit, `DynamicMemoryUsage` underestimates dynamic memory usage by not including the `CTransaction` objects and the shared ptr control blocks. Fix this by calculating `RecursiveDynamicUsage` on the `CTransactionRef` instead of the `CTransaction` whenever modifying `cachedInnerUsage`.
2c40895
to
9b3da70
Compare
Thank you @stickies-v , I updated the PR description and address review comments. |
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.
ACK 9b3da70 - nice work!
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.
re ACK 9b3da70
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.
ACK 9b3da70
@@ -34,7 +34,7 @@ std::vector<CTransactionRef> DisconnectedBlockTransactions::LimitMemoryUsage() | |||
|
|||
while (!queuedTx.empty() && DynamicMemoryUsage() > m_max_mem_usage) { | |||
evicted.emplace_back(queuedTx.front()); | |||
cachedInnerUsage -= RecursiveDynamicUsage(*queuedTx.front()); | |||
cachedInnerUsage -= RecursiveDynamicUsage(queuedTx.front()); |
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.
For future reference for b2d0447
Imagining DynamicMemoryUsage
for a DisconnectedBlockTransactions
with 1 transaction (ignoring the iters_by_txid
part since that doesn't change),
before
DynamicUsage(queuedTx) + cachedInnerUsage
=MallocUsage(sizeof(list_node<CTransactionRef>) + cachedInnerUsage
=MallocUsage(sizeof(4 pointers) + RecursiveDynamicUsage(CTransaction)
=MallocUsage(sizeof(4 pointers) + DynamicUsage(vin) + DynamicUsage(vout) + sum([RecursiveDynamicUsage(input) for input in vin]) + sum([RecursiveDynamicUsage(output) for output in vout])
after
DynamicUsage(queuedTx) + cachedInnerUsage
=MallocUsage(sizeof(list_node<CTransactionRef>) + cachedInnerUsage
=MallocUsage(sizeof(4 pointers) + RecursiveDynamicUsage(CTransactionRef)
=MallocUsage(sizeof(4 pointers) + DynamicUsage(CTransactionRef) + RecursiveDynamicUsage(CTransaction)
=MallocUsage(sizeof(4 pointers) + MallocUsage(sizeof(CTransaction)) + MallocUsage(sizeof(stl_shared_counter)) + RecursiveDynamicUsage(CTransaction)
=MallocUsage(sizeof(4 pointers) + MallocUsage(sizeof(CTransaction)) + MallocUsage(sizeof(stl_shared_counter)) + DynamicUsage(vin) + DynamicUsage(vout) + sum([RecursiveDynamicUsage(input) for input in vin]) + sum([RecursiveDynamicUsage(output) for output in vout])
So we account for
- each list node, which is 2 pointers + a shared pointer object (2 pointers)
- each shared pointer's dynamically allocated memory i.e. the
CTransaction
object + its always dynamically allocated stuff (the vectors) + the control block
This PR is a follow-up to fix review comments and a bugfix from #28385
The PR
Updated
DisconnectedBlockTransactions
'sMAX_DISCONNECTED_TX_POOL
from kb to bytes.Moved
DisconnectedBlockTransactions
implementation code tokernel/disconnected_transactions.cpp
.AddTransactionsFromBlock
now assume duplicate transactions are not passed by asserting after inserting each transaction toiters_by_txid
.Included a Bug fix: In the current master we are underestimating the memory usage of
DisconnectedBlockTransactions
.cachedInnerUsage
we callRecursiveDynamicUsage
withCTransaction
which invokes thisRecursiveDynamicUsage(const CTransaction& tx)
version ofRecursiveDynamicUsage
, the output of that call only account for the memory usage of the inputs and outputs of theCTransaction
, this omits the memory usage of theCTransaction
object and the control block.RecursiveDynamicUsage
withCTransactionRef
when adding and subtractingcachedInnerUsage
which invokesRecursiveDynamicUsage(const std::shared_ptr<X>& p)
version ofRecursiveDynamicUsage
the output of the calculation accounts for theCTransaction
object, the control blocks, inputs and outputs memory usage.Added test for DisconnectedBlockTransactions memory limit.