Select orphan transaction uniformly for eviction#14626
Select orphan transaction uniformly for eviction#14626maflcko merged 1 commit intobitcoin:masterfrom
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
|
Concept ACK. |
The previous code was biased towards evicting transactions whose txid has a larger gap (lexicographically) with the previous txid in the orphan pool.
64e1dbb to
7257353
Compare
|
Rebased. |
| }; | ||
| std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans); | ||
|
|
||
| std::vector<std::map<uint256, COrphanTx>::iterator> g_orphan_list GUARDED_BY(g_cs_orphans); //! For random eviction |
There was a problem hiding this comment.
It's not storing a COrphanTx inside. It's storing a list of iterators to entries in a map from uint256 to COrphanTx.
Such iterators are only as large as one pointer.
|
utACK 7257353 |
|
@sdaftuar @naumenkogs Feel like reviewing this? |
naumenkogs
left a comment
There was a problem hiding this comment.
Concept ACK, will look closer.
First of all, we either should remove this comment or do what it says?
struct COrphanTx { // When modifying, adapt the copy of this definition in tests/DoS_tests.
| }; | ||
| std::map<COutPoint, std::set<std::map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(g_cs_orphans); | ||
|
|
||
| std::vector<std::map<uint256, COrphanTx>::iterator> g_orphan_list GUARDED_BY(g_cs_orphans); //! For random eviction |
There was a problem hiding this comment.
Is there any benefit of having COrphanTx inside, why not just using a hash?
There was a problem hiding this comment.
Right, I guess it's cleaner this way. Feel free to resolve this one.
|
utACK 7257353 |
|
ACK |
7257353 Select orphan transaction uniformly for eviction (Pieter Wuille) Pull request description: The previous code was biased towards evicting transactions whose txid has a larger gap (lexicographically) with the previous txid in the orphan pool. Tree-SHA512: e35f700aea5ed79d1bc57f64bffcb623424b40156fd0a12f05f74f981a8aa4175d5c18d042989243f7559242bdf1d6d720bcf588d28f43d74a798a4843f09c70
| // Unless we're deleting the last entry in g_orphan_list, move the last | ||
| // entry to the position we're deleting. | ||
| auto it_last = g_orphan_list.back(); | ||
| g_orphan_list[old_pos] = it_last; |
There was a problem hiding this comment.
style-nit: Looks odd to assign an iterator. (The code is still correct, since back() returns a reference, but the naming might be wrong)
|
ACK |
Summary: 7257353b93 Select orphan transaction uniformly for eviction (Pieter Wuille) Pull request description: The previous code was biased towards evicting transactions whose txid has a larger gap (lexicographically) with the previous txid in the orphan pool. Tree-SHA512: e35f700aea5ed79d1bc57f64bffcb623424b40156fd0a12f05f74f981a8aa4175d5c18d042989243f7559242bdf1d6d720bcf588d28f43d74a798a4843f09c70 Backport of Core [[bitcoin/bitcoin#14626 | PR14626]] Test Plan: ninja ninja check-all Reviewers: O1 Bitcoin ABC, #bitcoin_abc, Fabien Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D6488
| size_t randompos = rng.randrange(g_orphan_list.size()); | ||
| EraseOrphanTx(g_orphan_list[randompos]->first); |
There was a problem hiding this comment.
As the mapOrphanTransactions items are sorted by hash, the first item is random with a negligible bias:
| size_t randompos = rng.randrange(g_orphan_list.size()); | |
| EraseOrphanTx(g_orphan_list[randompos]->first); | |
| EraseOrphanTx(mapOrphanTransactions.begin()->first); |
Or did I miss something?
There was a problem hiding this comment.
That would always evict lower txids before higher txids. Not exactly negligible...
There was a problem hiding this comment.
There was a problem hiding this comment.
That would always evict lower txids before higher txids. Not exactly negligible...
I do not mean "random txid", rather "random transaction".
There was a problem hiding this comment.
No. That would apply if the transactions were secret, but since an attacker may know the transactions, they also know the txids. The hashing applied is not relevant.
If mapOrphanTransactions was say an unordered_map, and was using salted hash for its internal hashing (to convert txids to bucket positions) like is used in some places, then this would perhaps not be an issue.
7257353 Select orphan transaction uniformly for eviction (Pieter Wuille) Pull request description: The previous code was biased towards evicting transactions whose txid has a larger gap (lexicographically) with the previous txid in the orphan pool. Tree-SHA512: e35f700aea5ed79d1bc57f64bffcb623424b40156fd0a12f05f74f981a8aa4175d5c18d042989243f7559242bdf1d6d720bcf588d28f43d74a798a4843f09c70 Signed-off-by: pasta <[email protected]>
The previous code was biased towards evicting transactions whose txid has a larger gap (lexicographically) with the previous txid in the orphan pool.