Skip to content

Conversation

gmaxwell
Copy link
Contributor

@gmaxwell gmaxwell commented Jun 9, 2016

This eliminates the primary leak that causes the orphan map to
always grow to its maximum size.

This does not go so far as to attempt to connect orphans made
connectable by a new block.

Keeping the orphan map less full helps improve the reliability
of relaying chains of transactions.

@laanwj laanwj added the P2P label Jun 9, 2016
map<COutPoint, set<uint256> >::iterator itByOutPoint = mapOrphanTransactionsByOutPoint.find(tx.vin[j].prevout);
if (itByOutPoint != mapOrphanTransactionsByOutPoint.end()) {
for (set<uint256>::iterator mi = itByOutPoint->second.begin(); mi != itByOutPoint->second.end(); ++mi) {
const uint256& orphanHash = *mi;
Copy link
Contributor

Choose a reason for hiding this comment

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

can you fix the whitespace here

@pstratem
Copy link
Contributor

ACK 70b5f60c761f56e0e84583e77d20a81db3fe1424

modulo whitespace nit

@gmaxwell
Copy link
Contributor Author

So, I'm not super happy with the behavior-- the issue is that it removes included or conflicted orphans, but if those orphans themselves have orphaned children, those won't get removed. The behavior I'm seeing in testing is that it initially removes many transactions but over time seems to remove fewer or fewer, and I think it's because the orphanmap gets full of double-orphans that were conflicted.

I'm not super keen on the performance implications of recursively eliminating there.

@pstratem
Copy link
Contributor

@gmaxwell Agreed this behavior is not ideal, but this is an improvement.

@@ -94,6 +94,7 @@ struct COrphanTx {
};
map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);
map<uint256, set<uint256> > mapOrphanTransactionsByPrev GUARDED_BY(cs_main);
Copy link
Member

@sipa sipa Jun 10, 2016

Choose a reason for hiding this comment

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

It would be more efficient to store map<uint256, COrphanTx>::iterators instead of uint256's.

@sipa
Copy link
Member

sipa commented Jun 10, 2016

@gmaxwell Here is a commit that switches the mapOrphansByPrev entirely to be by-COutPoint: https://github.com/sipa/bitcoin/commits/reworkorphans

sipa and others added 2 commits June 10, 2016 19:51
 always grow to its maximum size.

This does not go so far as to attempt to connect orphans made
 connectable by a new block.

Keeping the orphan map less full helps improve the reliability
 of relaying chains of transactions.
if (nNextSweep <= nNow) {
// Sweep out expired orphan pool entries:
int nErased = 0;
int64_t nMinExpTime = nNow + 15 * 60;
Copy link
Member

Choose a reason for hiding this comment

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

Can you turn this into a named constant?

@sipa
Copy link
Member

sipa commented Jun 11, 2016

utACK with nit

gmaxwell added 3 commits June 15, 2016 09:56
This prevents higher order orphans and other junk from
 holding positions in the orphan map.  Parents delayed
 twenty minutes are more are unlikely to ever arrive.

The freed space will improve the orphan matching success rate for
 other transactions.
…ted.

An orphan whos parents were rejected is never going to connect, so there
 is little utility in keeping it.

Orphans also helpfully tell us what we're missing, so go ahead and treat
 it as INVed.
Although this increases node memory usage in the worst case by perhaps
 30MB, the current behavior causes severe issues with dependent tx relay.
@gmaxwell
Copy link
Contributor Author

@sipa Nit picked.

@laanwj laanwj merged commit 54326a6 into bitcoin:master Jun 20, 2016
laanwj added a commit that referenced this pull request Jun 20, 2016
…d blocks.

54326a6 Increase maximum orphan size to 100,000 bytes. (Gregory Maxwell)
8c99d1b Treat orphans as implicit inv for parents, discard when parents rejected. (Gregory Maxwell)
11cc143 Adds an expiration time for orphan tx. (Gregory Maxwell)
db0ffe8 This eliminates the primary leak that causes the orphan map to  always grow to its maximum size. (Gregory Maxwell)
1b0bcc5 Track orphan by prev COutPoint rather than prev hash (Pieter Wuille)
@laanwj
Copy link
Member

laanwj commented Jun 20, 2016

utACK 54326a6

This was referenced Jun 22, 2016
codablock pushed a commit to codablock/dash that referenced this pull request Dec 28, 2017
…accepted blocks.

54326a6 Increase maximum orphan size to 100,000 bytes. (Gregory Maxwell)
8c99d1b Treat orphans as implicit inv for parents, discard when parents rejected. (Gregory Maxwell)
11cc143 Adds an expiration time for orphan tx. (Gregory Maxwell)
db0ffe8 This eliminates the primary leak that causes the orphan map to  always grow to its maximum size. (Gregory Maxwell)
1b0bcc5 Track orphan by prev COutPoint rather than prev hash (Pieter Wuille)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…accepted blocks.

54326a6 Increase maximum orphan size to 100,000 bytes. (Gregory Maxwell)
8c99d1b Treat orphans as implicit inv for parents, discard when parents rejected. (Gregory Maxwell)
11cc143 Adds an expiration time for orphan tx. (Gregory Maxwell)
db0ffe8 This eliminates the primary leak that causes the orphan map to  always grow to its maximum size. (Gregory Maxwell)
1b0bcc5 Track orphan by prev COutPoint rather than prev hash (Pieter Wuille)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants