Skip to content

Conversation

@morcos
Copy link
Contributor

@morcos morcos commented Dec 8, 2015

Builds on #7184

Adds a commit to keep the mempool consistent with respect to sequence locked txs in the event of a reorg

@jtimon
Copy link
Contributor

jtimon commented Dec 8, 2015

Since #6312 has gne through a lot of review already, I would prefer that this branch builds on top of that to more easily review the differences. We can always squash things before merging for a cleaner history.

@morcos
Copy link
Contributor Author

morcos commented Dec 8, 2015

@jtimon That was the first thing I created: [email protected]:refactorb
(misunderstanding of what he was asking)

But I think #7184 is a cleaner implementation of BIP 68 on its own.

@jtimon
Copy link
Contributor

jtimon commented Dec 8, 2015

as said squashes to clean up the history can happen after review.
As mentiooned before, I still don't see how [email protected] achieves its alleged goal.

@morcos
Copy link
Contributor Author

morcos commented Dec 9, 2015

rebased

@NicolasDorier
Copy link
Contributor

I think this PR is too complicated for fixing the perf issue, if NicolasDorier/bitcoin@67646e0...b2a27a7 is correct, it would be simpler to review. Regardless if we use #7184 or not.

@jtimon
Copy link
Contributor

jtimon commented Dec 9, 2015

@NicolasDorier I agree. Maybe more importantly, all the extra complexity is outside of the consensus critical code. Maybe you should consider opening a PR for your solution?
In this thread we should focus on the code of this PR. We have #7176 to discuss the different solutions more generally.

@jtimon
Copy link
Contributor

jtimon commented Dec 9, 2015

Is this supposed to fix the performance issues of CNB without touching miner.cpp, or are this just preparations without the actual performance solution?

@morcos
Copy link
Contributor Author

morcos commented Dec 9, 2015

@jtimon This fixes the performance issues by never introducing them into CNB in the first place. #7184 on its own has performance issues with reorgs.

@NicolasDorier You think just the second commit here is significantly more complicated than your final commit in #7190?

@morcos
Copy link
Contributor Author

morcos commented Dec 9, 2015

squashed a bug fix (wasn't actually skipping the work it was supposed to)

@morcos morcos mentioned this pull request Dec 9, 2015
@NicolasDorier
Copy link
Contributor

I like the fact you separate CheckLockTime (if you rename IsFinalTx) and CheckSequenceLockTime, but I really don't like the LockPoints structure. I'm still reviewing if commit 2 might not result in mempool finality corruption, I really don't find it obvious.

@NicolasDorier
Copy link
Contributor

btw can you rename IsFinalTx to CheckLockTime as you said you wanted to do ?

@morcos
Copy link
Contributor Author

morcos commented Dec 9, 2015

@NicolasDorier My approach and yours are not that different.

  • You are storing the hash at which the calculation of the sequence lock time and height happened and using the fact that if that hash is still on the chain that the calculation must still be valid and the comparison to the current time and height must be valid because they can not have gone below what they were at the hash you saved.
  • I'm storing the lowest height hash at which the calculation of the sequence lock time and height would necessarily still be valid (which is the hash of the highest height input with a sequence lock, b/c if none of the inputs changed height then the calculation is trivially the same) and the result of the calculation. But in the case of my code, I have to redo the comparison part because the current time and height maybe be lower than they were at the time I originally did the comparison. So I will redo comparisons for every tx on every reorg, but that is extremely fast, and I save redoing the expensive calculations for many more txs.

@NicolasDorier
Copy link
Contributor

Ok I'm getting it. Seems like it can work.
You forget to check SequenceLockTime in rpcwallet.cpp, wallet.cpp.

@morcos
Copy link
Contributor Author

morcos commented Dec 9, 2015

@NicolasDorier I left that out on purpose. See #7184. It might need to be added back in but it wasn't really clear to me how that code ever gets hit. I've tried asking about it on IRC a couple of times. But it doesn't seem possible to me to generate a wallet tx which is sequence locked except in the event of a reorg, at which point the tx won't be in your mempool anyway.

@NicolasDorier
Copy link
Contributor

Ok, I don't really understand those implication yet.

@NicolasDorier
Copy link
Contributor

Will you rename to IsFinalTx to CheckLockTime and CheckSequenceLocks to CheckSequenceLockTime ?

@morcos
Copy link
Contributor Author

morcos commented Jan 14, 2016

Updated for the updated #7184 and took @sdaftuar's suggestion

@NicolasDorier
Copy link
Contributor

you may optimize even more: Only take the heights which correspond to an input who has a LockSequence for maxInputHeight calculation.

@morcos
Copy link
Contributor Author

morcos commented Feb 18, 2016

@NicolasDorier that's already done. CalculateSequenceLocks already sets heights for non sequence locked inputs to 0.

@sdaftuar
Copy link
Member

Code review ACK (apart from comment nit). Testing...

@sdaftuar
Copy link
Member

Tested ACK (hacked up some extra tests to bip68-sequence.py to exercise the reorg logic) 5912944f4d5eeb4078a5bb658ad09ef7eabbf53b

@btcdrak
Copy link
Contributor

btcdrak commented Feb 26, 2016

@sdaftuar Would you mind publishing/PRing those extra tests? Maybe they could be added to this PR?

@morcos
Copy link
Contributor Author

morcos commented Feb 29, 2016

comment nit addressed

@sipa
Copy link
Member

sipa commented Mar 5, 2016

Kicked Travis

src/txmempool.h Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it suffices to turn this into a const reference.

@odinTy
Copy link

odinTy commented Mar 5, 2016

If I've done something wrong it was by mistake I'm new and trying to learn. Sorry if I messed up

@odinTy
Copy link

odinTy commented Mar 5, 2016

Please explain all my mistakes please as this should help the future

@btcdrak
Copy link
Contributor

btcdrak commented Mar 15, 2016

utACK ddb4dab

@laanwj
Copy link
Member

laanwj commented Mar 16, 2016

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 [email protected]

@laanwj
Copy link
Member

laanwj commented Mar 16, 2016

ut/code review ACK ddb4dab

src/txmempool.h Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider storing a CBlockIndex* here instead of a uint256? (may be a stupid suggestion, but from what I see the only thing you do is look it back up in mapBlockIndex)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... i feel like we did consider that, but i can't see now why that wouldn't work. maybe it didn't work with some previous iteration. it makes sense to switch to that if we can't see any problems with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I don't see any problems with it at least: as I see it it'd simplify the code, reduce storage requirement for LockPoints, and makes the same (valid) assumption that a block index entry never goes away

@jtimon
Copy link
Contributor

jtimon commented Mar 16, 2016

Concept ACK, started reviewing more deeply.

@morcos
Copy link
Contributor Author

morcos commented Mar 16, 2016

@laanwj ok done. If you think this has sufficient review I can squash.

Obtain LockPoints to store in CTxMemPoolEntry and during a reorg, evaluate whether they are still valid and if not, recalculate them.
@morcos
Copy link
Contributor Author

morcos commented Mar 16, 2016

Squashed from e6cc06b which contained the switch to CBlockIndex*'s

@laanwj
Copy link
Member

laanwj commented Mar 16, 2016

utACK 982670c

@laanwj laanwj merged commit 982670c into bitcoin:master Mar 16, 2016
laanwj added a commit that referenced this pull request Mar 16, 2016
@btcdrak
Copy link
Contributor

btcdrak commented Mar 16, 2016

@laanwj this PR has been backported in 7543.

@maflcko
Copy link
Member

maflcko commented Apr 25, 2016

Removed 'needs backport' label per previous comment

@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants