Skip to content
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

mempool: remove block even if mempool is empty #916

Closed
wants to merge 1 commit into from

Conversation

pinheadmz
Copy link
Member

Closes #915

Thanks @mafintosh for finding this bug!

Test covers removeBlock with mempool empty and non-empty. Test will fail without code change.

@pinheadmz pinheadmz added bug Unexpected or incorrect behavior mempool Related to the mempool quick Can be fixed quickly, code change less than 10 lines labels Nov 27, 2019
@codecov-io

This comment has been minimized.

@pinheadmz
Copy link
Member Author

Looking at this some more, I think the bug has actually helped us pass tests that might actually be broken and here's why: As blocks get disconnected, the entire mempool needs to be checked for CSV transactions and premature coinbase spends that are invalid. This is especially likely when disconnecting multiple blocks in a row (a TX may pass insertTX(), but should still be evicted when the next block is disconnected). This logic is written in _handleReorg() but that function is NOT CALLED when a block is invalidated, or if a block is removed for any reason besides a 'reorganize' event, emitted by chain.

I'm going to work on his more before requesting a final review.

@pinheadmz
Copy link
Member Author

pinheadmz commented Nov 29, 2019

So I think there are two more steps that would make this better re: my last comment.

  1. Invalidating a block should actually be considered a reorg, disconnecting blocks one at a time and finally emitting a 'reorganize' event. @braydonf we should probably check that the chain-expansion branch does something like this, as opposed to the current behavior for invalidate():

pinheadmz@c827fd0

  1. Now that the 'reorganize' event is being emitted, mempool will evict TXs that are now invalid to due a lower chain height (i.e. CSV and coinbase maturity). _handleReorg() already does this, but in a brutal way -- just evicting everything with a CSV or coinbase spend. We can actually do the contextual checks on these TXs and allow them to remain in the mempool if they are still valid:

pinheadmz@cbeb00d

This commit is not complete, TXs that have CSV ancestors will have to be checked as well. See this test in Bitcoin Core: https://github.com/pinheadmz/bitcoin/blob/89a609f182a0f2ff558ed0015753429df9694a18/test/functional/feature_bip68_sequence.py#L302-L313

@pinheadmz pinheadmz closed this Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior mempool Related to the mempool quick Can be fixed quickly, code change less than 10 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mempool's removeBlock doesn't add TXs back if mempool is empty
3 participants