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

TXs do not re-enter mempool when a block is disconnected #306

Closed
pinheadmz opened this issue Dec 1, 2019 · 0 comments · Fixed by #319 · May be fixed by bcoin-org/bcoin#917
Closed

TXs do not re-enter mempool when a block is disconnected #306

pinheadmz opened this issue Dec 1, 2019 · 0 comments · Fixed by #319 · May be fixed by bcoin-org/bcoin#917

Comments

@pinheadmz
Copy link
Member

pinheadmz commented Dec 1, 2019

This came to my attention when a user opened bcoin-org/bcoin#915, as an amazing coincidence I was also studying the Bitcoin Core BIP68 test which shed some important light on the subject.

The issue arises when a block is disconnected (either by a reorg, or locally with rpc invalidateblock) and there are two relevant places in the code.

First: when a block is removed, if the mempool is empty, all the TXs in the block are discarded:

hsd/lib/mempool/mempool.js

Lines 333 to 339 in 27c99ad

async _removeBlock(block, txs) {
if (this.map.size === 0
&& this.claims.size === 0
&& this.airdrops.size === 0) {
this.tip = block.prevBlock;
return;
}

Second, if a 'reorganize' event is caught by mempool, the mempool is "sterilized" by _handleReorg() but this function is a little brutal, it removes all CSV transactions and all coinbase-spends.

The effect of these two snippets is to simplify mempool processing after a reorg (the BIP68 rules get stupid-complicated when transactions are re-entering the mempool, especially if the parent of a CSV TX re-enters the mempool)

I don't think this is a much an issue with bcoin but it will be with Handshake, since this is the code all miners will be running, and there are more likely to be re-orgs in the early stages of the chain. The effect will be lots of transactions disappearing completely from mempools and blocks if a block is removed, the sender (or recipient) will have to re-broadcast. It is also very non-optimal for miners because they are throwing away fees.

Using the Bitcoin Core test as a guide, I'm going to try to implement deeper reorg-mempool behavior behavior in bcoin and after review and merge, port that back to hsd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant