-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: log nEvicted
message in LimitOrphans
then return void
#25683
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. ConflictsNo conflicts as of last run. |
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.
Not sure if the prefix is accurate. You are modifying a log message, not a test.
I think an alternative way to solve this would be to move both log messages into the function and not return anything?
bd76cad
to
7b9b184
Compare
nEvicted
returned by LimitOrphans
nEvicted
message into LimitOrphans
src/txorphanage.cpp
Outdated
@@ -135,7 +135,8 @@ unsigned int TxOrphanage::LimitOrphans(unsigned int max_orphans) | |||
EraseTx(m_orphan_list[randompos]->first); | |||
++nEvicted; | |||
} | |||
return nEvicted; | |||
if (nEvicted > 0) LogPrint(BCLog::MEMPOOL, "orphanage overflow, removed %u tx\n", nEvicted); | |||
return nExpired + nEvicted; |
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.
The return value isn't used outside of tests, so I think it can be removed. If someone is interested in the size, they can just call .size()
.
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.
auto size_before = orphanage.Size();
auto limit = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
auto n_evicted = WITH_LOCK(g_cs_orphans, return orphanage.LimitOrphans(limit));
Assert(size_before - n_evicted <= limit);
Assert(orphanage.Size() <= limit);
In most cases size_before - n_evicted == orphange.Size()
, so we don't need the return value of LimitOrphans
. But IMO it will not hurt to use the return value for an additional check. Actually I also think EraseForBlock
can return nErased
.
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.
In most cases size_before - n_evicted == orphange.Size(), so we don't need the return value of LimitOrphans
Can you give an example where the equality wouldn't hold, assuming after the changes in this pull requests?
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.
The equality wouldn't hold if n_evicted
or n_expired
is incremented but EraseTx
fail to remove tx from m_orphanage
. It seems this never happen since the txid
passed to EraseTx
is valid. So feel free to request change and I will make the function return void.
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.
Yeah, I am thinking, either:
- the equality holds, in which case the return value is unused and redundant, also confuse the devs which is the "correct" way to get the size. Also, if the return value was used in the future, it can trivially be added back.
- the equality doesn't hold, in which case the return value is confusing, since it is wrong.
Regardless of which case holds, removing the return value is likely the correct "fix".
f813763
to
a61fb90
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.
Please squash your commits according to https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits
e28e7bb
to
9fd3102
Compare
nEvicted
message into LimitOrphans
nEvicted
message in LimitOrphans
then return void
review ACK 9fd3102 |
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 9fd3102
LimitOrphans()
removes expired transactions from the orphanage and additionally evicts transactions at random should the limit still be exceeded after removing expired transactions. Before this PR, the number of evicted transactions (excluding the number of expired transactions) was returned, which let to hitting an asserting in the fuzz tests that assumed the return value to be the total number of removed transactions (evicted + expired).
This PR removes the assertion from the fuzz test and changes LimitOrphans()
to return nothing (the logging of the number of evicted transactions is therefore moved to the orphanage).
nit: The PR description still says "Now the function returns the sum of expired and evicted tx, used for test assertion." which is not true for the current version of the PR.
`LimitOrphans()` can log expired tx and it should log evicted tx as well instead of returning the number for caller to print the message. Since `LimitOrphans()` now return void, the redundant assertion check in fuzz test is also removed.
9fd3102
to
b4b657b
Compare
Thanks for reviewing, I modify the PR description and a typo |
…s` then return void b4b657b refactor: log `nEvicted` message in `LimitOrphans` then return void (chinggg) Pull request description: Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49347 LimitOrphans() can log expired tx and it should log evicted tx as well instead of returning the `nEvicted` number for caller to print the message. Since `LimitOrphans()` now returns void, the redundant assertion check in fuzz test is also removed. Top commit has no ACKs. Tree-SHA512: 18c41702321b0e59812590cd389f3163831d431f4ebdc3b3e1e0698496a6bdbac52288f28f779237a58813c6717da1a35e8933d509822978ff726c1b13cfc778
Fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49347
LimitOrphans() can log expired tx and it should log evicted tx as well instead of returning the
nEvicted
number for caller to print the message.Since
LimitOrphans()
now returns void, the redundant assertion check in fuzz test is also removed.