Builds on #7184
Adds a commit to keep the mempool consistent with respect to sequence locked txs in the event of a reorg
@NicolasDorier My approach and yours are not that different.
I remember having done this remark already: and I was still not too much convinced by your response, I’m saying it here so other reviewer can dig in about it:
My main doubt is that there is a case where the nHeight/nTime of LockPoint should be invalidated but is not. Imagine you have a tx spending unconf coin C1 when tip is B1 and height X. MaxInputHash would be equals to hash(B1).
Now if B2 is found at height X+1, C1 still unconf, since B1 is still in the chain the LockPoint is not invalidated. My worry is that LockPoint SHOULD be invalidated as the prevHeights vector for calculating the LockPoint would not be the same anymore (the assumed height of C1 would be X+2 instead of X+1). The value of nHeight/nTime in the LockPoint would be impacted by it. I am still not entirely clear if it would have a chance of corrupting the mempool with an invalid tx though. (which would give problem to GBT which now rely on a coherent mempool)
@NicolasDorier Yes sorry I hate the way those get lost. Here is your old comment: https://github.com/morcos/bitcoin/commit/f8b6614#commitcomment-15979134
I ended up punting on building the infrastructure to accept sequence locked txs that were not yet final. I have the code written to do it, but it requires slight changes to the BIP 68 code and I didn’t want to hold up merger for something of dubious value. But then I forgot to go back and clarify why the code here is safe.
I’ve now added a commit with what is hopefully a detailed explanation. And in the process I actually made it more efficient by eliminating the mempool input heights instead of capping them which will make recalculations on reorg even less frequent.
bip68-sequence.py
to exercise the reorg logic) 5912944f4d5eeb4078a5bb658ad09ef7eabbf53b
178+ update_lock_points(LockPoints _lp) : lp(_lp) { }
179+
180+ void operator() (CTxMemPoolEntry &e) { e.UpdateLockPoints(lp); }
181+
182+private:
183+ LockPoints lp;
60@@ -61,6 +61,11 @@ void CTxMemPoolEntry::UpdateFeeDelta(int64_t newFeeDelta)
61 feeDelta = newFeeDelta;
62 }
63
64+void CTxMemPoolEntry::UpdateLockPoints(LockPoints& lp)
If I’ve done something wrong it was by mistake I’m new and trying to learn. Sorry if I messed up
What happened exactly? If you have specific questions about development and review process feel free to mail me on laanwj@gmail.com
43+ int height;
44+ int64_t time;
45+ // As long as the current chain descends from the highest height block
46+ // containing one of the inputs used in the calculation, then the cached
47+ // values are still valid even after a reorg.
48+ uint256 maxInputHash;
Obtain LockPoints to store in CTxMemPoolEntry and during a reorg, evaluate whether they are still valid and if not, recalculate them.