-
Notifications
You must be signed in to change notification settings - Fork 279
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
Improve re-insertion of TXs from disconnected blocks into mempool #319
Conversation
This method used to just toss out any TX that might be problematic when the chain is rewound. Instead, we can actually check the context of each TX and allow them to remain in the mempool if they are still valid. Those checks include coinbase maturity and sequence locks.
Codecov Report
@@ Coverage Diff @@
## master #319 +/- ##
==========================================
+ Coverage 58.68% 59.39% +0.71%
==========================================
Files 129 129
Lines 35795 35793 -2
Branches 6027 6027
==========================================
+ Hits 21007 21261 +254
+ Misses 14788 14532 -256
Continue to review full report at Codecov.
|
Also thinking we can deal with Claims and AirdropProofs here too: Lines 414 to 416 in c554a6f
They can be re-evaluated on reorgs. |
Ok this latest commit adds the Claims and AirDrops back into the mempool after a reorg. This will require diligent review if we want to keep it. From what I can tell, there are no restrictions on AirDrops if the chain is rewound (unlike premature coinbase spends). The only restriction on Claims would be the inception time ( |
Forgot to include checks for block commitment of Claims re-entering mempool in last commit, that has been updated. Everything should be covered now. |
Bonus TODO: this is getting pretty advanced, but Bitcoin Core will even hold on to the evicted TXs until after a reorg is complete, and then see if any are still ok (for example, a coinbase spend might still be valid after a reorg, just not during): |
After looking at this for a while, I can't find anything wrong with it. Merging for now. |
Closes #306
Port of bcoin-org/bcoin#917, although it hasn't been reviewed or merged yet over there. I think this is a bigger concern for Handshake since this codebase will represent 100% of the network, and chain reorgs are more likely on hsd in the early days.
The contextual checks for TXs with covenants re-entering mempool after a block disconnect has already been written in
_handleReorg()
, so for that case I just added a test.The other cases ported over from bcoin are premature coinbase spends, and premature BIP68 sequence lock spends.
With these contextual checks in place, the "don't remove block if mempool empty" check can be safely removed.