Limit amount of memory used in large re-orgs#5943
Closed
gavinandresen wants to merge 3 commits intobitcoin:masterfrom
Closed
Limit amount of memory used in large re-orgs#5943gavinandresen wants to merge 3 commits intobitcoin:masterfrom
gavinandresen wants to merge 3 commits intobitcoin:masterfrom
Conversation
2627182 to
f366ebc
Compare
f366ebc to
82cb1e0
Compare
Print out the temporary directory at the end of testing if --nocleanup is given (I found this very useful when running --tracerpc --nocleanup when developing new tests). And, by default, wait at most ten seconds for mempools or chains to sync before failing a test.
Add a ForgetTransaction routine that is the opposite of RelayTransaction: it clears a transaction from peer nodes setInventoryKnown, so if we receive an 'inv' in the future we will respond with 'getdata' and un-forget it. Relies on a new mruset.erase() method (with unit tests).
…k into mempool Deep re-orgs try to put all transactions from all blocks back into the mempool; this is not a problem in practice (because deep re-orgs happen approximately never), but will be a problem when either the mempool is limited or you run out of memory for the mempool. This change limits the number of blocks worth of transactions to six.
82cb1e0 to
05697af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request was inspired by three things:
Block re-org code before this pull request saves all transactions in the old fork to the memory pool before adding all the blocks on the new fork to the chain. That can use arbitrary amounts of memory if the re-org is arbitrarily long; for 'reasonable' re-orgs almost all of the transactions will be in blocks on the new fork, so you eventually end up with a small memory pool, and allocated a lot of memory for nothing.
This pull request has almost identical behavior for short (6-or-fewer block-deep) re-orgs. But for deeper re-orgs, it does not add transactions to the memory pool-- it assumes that the transactions are likely to be on the new fork, and, if they are not, that either the sender or the receiver of the transaction will re-broadcast.
I made changes to the transaction relaying code that make transaction re-broadcast more robust; if for any reason a transaction is not added to the memory pool during a re-org, it is also cleared from the networking layer's 'setInventoryKnown' so a later re-broadcast will be successful.
Builds on #5940 and #5945
Tested using mempool_resurrect_test.py and also manual testing to make sure the wallet's automatic rebroadcast of unconfirmed transactions Does The Right Thing.