Skip to content

Conversation

chinggg
Copy link
Contributor

@chinggg chinggg commented Jul 23, 2022

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.

@DrahtBot DrahtBot added the Tests label Jul 23, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 23, 2022

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

Conflicts

No conflicts as of last run.

Copy link
Member

@maflcko maflcko left a 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?

@chinggg chinggg force-pushed the fix-txorphan-limit branch 2 times, most recently from bd76cad to 7b9b184 Compare July 25, 2022 01:48
@chinggg chinggg changed the title test: Fix nEvicted returned by LimitOrphans log: move nEvicted message into LimitOrphans Jul 25, 2022
@@ -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;
Copy link
Member

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().

Copy link
Contributor Author

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.

Copy link
Member

@maflcko maflcko Jul 25, 2022

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?

Copy link
Contributor Author

@chinggg chinggg Jul 25, 2022

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.

Copy link
Member

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

@chinggg chinggg force-pushed the fix-txorphan-limit branch from f813763 to a61fb90 Compare July 25, 2022 12:30
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chinggg chinggg force-pushed the fix-txorphan-limit branch 2 times, most recently from e28e7bb to 9fd3102 Compare July 25, 2022 12:45
@chinggg chinggg changed the title log: move nEvicted message into LimitOrphans refactor: log nEvicted message in LimitOrphans then return void Jul 25, 2022
@maflcko
Copy link
Member

maflcko commented Jul 25, 2022

review ACK 9fd3102

Copy link
Member

@dergoegge dergoegge left a 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.
@chinggg chinggg force-pushed the fix-txorphan-limit branch from 9fd3102 to b4b657b Compare July 28, 2022 06:41
@chinggg
Copy link
Contributor Author

chinggg commented Jul 28, 2022

Thanks for reviewing, I modify the PR description and a typo redundant in commit message.

@maflcko maflcko merged commit b1c8ea4 into bitcoin:master Jul 29, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 29, 2022
…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
@bitcoin bitcoin locked and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants