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

BIP-68: Mempool-only sequence number constraint verification #6312

Closed
wants to merge 12 commits into from

Conversation

maaku
Copy link
Contributor

@maaku maaku commented Jun 20, 2015

Essentially enforces sequence numbers as a relative lock-time as an IsStandard() rule to make it easy to test applications using it; blocks containing transactions with invalid sequence numbers given the age of their inputs per BIP 68 are still accepted.

This pull-req is not a soft-fork nor does it contain any code to start that process.

This pull request builds on top of #6177.

Background: BIP 68, Consensus-enforced transaction replacement signalled via sequence numbers

@petertodd
Copy link
Contributor

Mind fixing that BIP link? 404

@maaku
Copy link
Contributor Author

maaku commented Jun 21, 2015

Fixed.

On Sun, Jun 21, 2015 at 11:28 AM, Peter Todd notifications@github.com
wrote:

Mind fixing that BIP link? 404


Reply to this email directly or view it on GitHub
#6312 (comment).

@petertodd
Copy link
Contributor

Now again, could you please do up a quick demo example app that actually uses this? e.g. like my https://github.com/petertodd/checklocktimeverify-demos/blob/master/micropayment-channel.py

Doesn't have to be much, but we really need a worked out example here... Notably, see how without a way to fix tx mutability the nSequence proposal really isn't any different in practice than just signing increasingly decreasing nLockTime's? Because if you could safely sign the transaction it'd already be mined and thus you don't need a relative nSequence - an absolute nLockTime calculated from the height/time of the tx you know already is in the chain is fine.

IMO there's no reason to merge this until it has a safe use-case that provides a concrete benefit over the existing status quo; a simple change in what exact number is being signed isn't a concrete benefit.

@btcdrak
Copy link
Contributor

btcdrak commented Jun 23, 2015

Why doesn' this patch include the code for OP_CHECKSEQUENCEVERIFY?

@maaku
Copy link
Contributor Author

maaku commented Jun 23, 2015

@btcdrak that code is here:

https://github.com/maaku/bitcoin/tree/checksequenceverify

It is entirely separate from what this pull request accomplishes. For example, it is possible to do simple transaction replacement without CHECKSEQUENCEVERIFY, as explained in the BIP. Likewise the source code of the CSV branch does not in fact depend on this pull request -- all CSV does is verify a constraint on the sequence number of the input, it does not depend on that sequence number having consensus-enforced semantics.

@btcdrak
Copy link
Contributor

btcdrak commented Jun 23, 2015

@maaku I think the value of this PR in isolation is limited. You really need the opcode as well. It would be wonderful if you could publish a separate PR+BIP for CSV if you dont wish to combine them.

CSV is a very useful feature and one I think we clearly need to help address scalability. I see no profit in not getting it on the table now especially since it's been deployed in Elements already and is clearly working.

@maaku
Copy link
Contributor Author

maaku commented Jun 23, 2015

I'm working on it. Things take time.
On Jun 23, 2015 15:14, "฿tcDrak" notifications@github.com wrote:

@maaku https://github.com/maaku I think the value of this PR in
isolation is limited. You really need the opcode as well. It would be
wonderful if you could publish a separate PR+BIP for CSV if you dont wish
to combine them.

CSV is a very useful feature and one I think we clearly need to help
address scalability. I see no profit in not getting it on the table now
especially since it's been deployed in Elements already and is clearly
working.


Reply to this email directly or view it on GitHub
#6312 (comment).

@@ -14,5 +14,7 @@ static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
static const int COINBASE_MATURITY = 100;
/** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */
static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
/** Threshold for inverted CTxIn::nSequence: below this value it is interpreted as a relative lock-time, otherwise ignored. */
static const uint32_t SEQUENCE_THRESHOLD = (1 << 31);
Copy link
Member

Choose a reason for hiding this comment

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

Probably should call this something other than sequence?

@btcdrak
Copy link
Contributor

btcdrak commented Aug 4, 2015

needs rebase

@maaku
Copy link
Contributor Author

maaku commented Aug 12, 2015

Rebased.

@@ -860,6 +942,18 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
view.SetBackend(dummy);
}

// Enforce sequnce numbers as relative lock-time
Copy link
Contributor

Choose a reason for hiding this comment

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

s/sequnce/sequence

@dcousens
Copy link
Contributor

concept ACK

@btcdrak
Copy link
Contributor

btcdrak commented Aug 17, 2015

Refs #6564

@rustyrussell
Copy link
Contributor

Agreed with @petertodd that this is fairly pointless without BIP-62 (malleability), but I do want both for lightning.

(I also note that we should in future detach the locktime field from requiring non-FFFFFFFF nSequence; they're completely orthogonal AFAICT. But that's a minor soft-fork.)

@dcousens
Copy link
Contributor

@petertodd isn't the point of this that it is relative? That is, I don't need to know what block the first transaction is in, nor the follow up transactions?
But I know that they will be (at least) no less than nSequence apart?

@maaku
Copy link
Contributor Author

maaku commented Aug 18, 2015

@rustyrussell @petertodd : what relative lock-time gives you is a committed response window to a proof-of-publication. With CHECKSEQUENCEVERIFY (#6564) there is indeed some features you can get that in some situations aren't just replicatable with CHECKLOCKTIMEVERIFY. However the most exciting use cases also require something additional still. In the case of lightning, not just BIP 62, but some sort of normative txid.

@dcousens I believe @petertodd's point is that since all the inputs are already on the block chain, you can just set nLockTime to the confirmed age of the input + the relative lock-time. And if the inputs are not all confirmed, then you are building chains of transactions that aren't safe due to malleability. So really this is a feature that becomes most useful when we have a definitive fix for malleability, which we will in the not so distant future.

@petertodd
Copy link
Contributor

Yup, my objection was a somewhat pedantic point of process; now that CSV has been proposed it's moot objection.

Will review all this stuff soon FWIW, travelling right now... Per usual. :/

On 17 August 2015 18:43:33 GMT-07:00, Mark Friedenbach notifications@github.com wrote:

@rustyrussell @petertodd : what relative lock-time gives you is a
committed response window to a proof-of-publication. With
CHECKSEQUENCEVERIFY (#6564) there is indeed some features you can get
that in some situations aren't just replicatable with
CHECKLOCKTIMEVERIFY. However the most exciting use cases also require
something additional still. In the case of lightning, not just BIP 62,
but some sort of normative txid.

@dcousens I believe @petertodd's point is that since all the inputs are
already on the block chain, you can just set nLockTime to the confirmed
age of the input + the relative lock-time. And if the inputs are not
all confirmed, then you are building chains of transactions that aren't
safe due to malleability. So really this is a feature that becomes most
useful when we have a definitive fix for malleability, which we will in
the not so distant future.


Reply to this email directly or view it on GitHub:
#6312 (comment)

@dcousens
Copy link
Contributor

And if the inputs are not all confirmed, then you are building chains of transactions that aren't safe due to malleability.

Right, thanks for clearing that up @maaku :)

@rustyrussell
Copy link
Contributor

@maaku Just to clarify (though a bit OT):

Lightning wants normalized txid for simpler dual-input anchors, but doesn't need it (the escape tx design seems to work).

Lightning needs normalized txid for outsourcing of revocation enforcement.

@maaku
Copy link
Contributor Author

maaku commented Aug 19, 2015

Fixed @luke-jr's nits.

@NicolasDorier
Copy link
Contributor

This change to BIP68 (bitcoin/bips#260) while making a clearer specification just broke completely this PR. Basically this PR assumed similar blocktime calculation (MTP or not) policy for both nLockTime and sequence lock time. But the change of specification makes MTP mandatory for sequence locktime while nLockTime is still depends on MTP activation.

This PR, if preferred over alternatives, will need to be updated. (or the change to specification reverted) I expect the changes to tests code and logic to be significant though to be worth the trouble.

I think the best choices are either to move to Morcos' PR (#7184) which is very different from this implementation. Or, reverting bitcoin/bips#260 if people wants to stick with this well reviewed PR.

@btcdrak
Copy link
Contributor

btcdrak commented Dec 14, 2015

The assumption of MTP only was discussed at the IRC meeting and that BIP68 and BIP113 need to be softforked together.

I am in favour of #7184. However, the assumption was if this PR is chosen over #7184 then this PR would be updated accordingly to the new specification. It's just #7184 already made the assumption. It's a lot cleaner to assume MTP and really, there is no situation where it would not be MTP because we are deploying 68 and 113 together.

@morcos
Copy link
Member

morcos commented Dec 14, 2015

Yeah sorry about that, I guess it is a bit tough to try to keep BIP spec in line with code.
But honestly I think this confusion shows why I like the code organization of #7184 better. The consensus code for sequence and nLockTime is too intermingled here.

One of the hesitations with switching to #7184 has been that this PR is already heavily reviewed and tested. I think this is wrong. It had a lot of preliminary review, but then the code changed, and I think its had only minimal testing. An example is the checking of sequence locks that is throughout the wallet and GUI code in this PR. I believe those would lead to unacceptable performance for any node with a half way decent size wallet. They would slow down a lot of operations and also make the utxo cache worthless.

@btcdrak
Copy link
Contributor

btcdrak commented Dec 14, 2015

@morcos I absolutely agree, we cannot claim this PR is well reviewed because each reviewer, reviewed it in a different state. Regardless, this has been beneficial in refining the specification and implementation.

@NicolasDorier
Copy link
Contributor

Understood, I have no particular feeling about it, just worried #7184 would delay CSV adoption for months.

@jtimon
Copy link
Contributor

jtimon commented Dec 20, 2015

I think this is wrong. It had a lot of preliminary review, but then the code changed, and I think its had only minimal testing.

It is true that the code changed after most of the reviews were done. Fortunately @btcdrak kept the commits separated so that concern has an easy solution: remove the latest changes.
I have to say that this has also been tested as part of the elements/alpha testchain (still in operation) for more than 6 months. @rustyrussell may be able to tell us more about tests in the context of lighting development (my apologies if that's not the case).

@NicolasDorier
Copy link
Contributor

@jtimon one of my change is actually a bug fix... sadly it was squashed. Regardless of what happen, this should be kept.

The problem was that the birth time of an unconfirmed coin was set to blockTime which depended on MTP activation. Whereas confirmed coins always used MTP time.

@maaku
Copy link
Contributor Author

maaku commented Dec 20, 2015

I have to say it was bad form that #7184 merged everything into one commit as it makes the review significantly harder (and less critically, credit assignment less clear). I think it was also bad form to split off a separate PR for the exact same feature, rather than discuss the alternative implementation pathway in the same thread, but I digress...

@jtimon
Copy link
Contributor

jtimon commented Dec 20, 2015

@NicolasDorier Well, if it was a bugfix then it's not sad that it was squashed, is it?
I mean more the later changes to make the function a pure function, which is, I assume the less reviewed changes @morcos is concerned with.

In my opinion no optimization had been needed in the mining code this could have been merged before 0.12 with no backporting problems. If the optimizations hadn't been urgent they could have been later during 0.13.99. But now it's too late for that, thus the need for #7176 . All the possible fixes could be built on top of the same branch (this one, for example) to compare them more easily, but seems not everybody agrees that a common base makes branches easier because I have already say this without the different proponents agreeing on a common base, and @maaku seems to be the only other person that thinks #7187 should be based on this PR instead of #7184 so I shouldn't insist on this.

@NicolasDorier
Copy link
Contributor

By "sad being squashed", I mean that if you want to revert recent changes I made, at least you should keep the bug fix commit. Extracting it would have been simpler without squash. (but well, the bug is not a big deal to fix again)

@maaku
Copy link
Contributor Author

maaku commented Dec 20, 2015

Which is why it is better not to squash until the very end before merge.
On Dec 20, 2015 7:04 PM, "Nicolas Dorier" notifications@github.com wrote:

By "sad being squashed", I mean that if you want to revert recent changes
I made, at least you should keep the bug fix commit. Extracting it would
have been simpler without squash. (but well, the bug is not a big deal to
fix again)


Reply to this email directly or view it on GitHub
#6312 (comment).

@btcdrak
Copy link
Contributor

btcdrak commented Dec 20, 2015

@maaku I think #7184 can be redone with commit history. @morcos

@morcos
Copy link
Member

morcos commented Dec 20, 2015

As already posted on #7184

maaku/bitcoin@sequencenumbers...morcos:7184onorig6312

Feel free to incorporate that here if that is preferred.

@rustyrussell
Copy link
Contributor

Tested-by: Rusty Russell rusty@rustcorp.com.au

(I merged both this and #6564 for the test, with only a trivial conflict to resolve).

@btcdrak
Copy link
Contributor

btcdrak commented Jan 14, 2016

Closing in favour of #7184

morcos added a commit to morcos/bitcoin that referenced this pull request Jan 14, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
@laanwj laanwj closed this Jan 16, 2016
morcos added a commit to morcos/bitcoin that referenced this pull request Feb 10, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
jtimon pushed a commit to jtimon/bitcoin that referenced this pull request Feb 14, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
btcdrak pushed a commit to btcdrak/bitcoin that referenced this pull request Feb 16, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
btcdrak pushed a commit to btcdrak/bitcoin that referenced this pull request Mar 18, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
rebroad pushed a commit to rebroad/bitcoin that referenced this pull request Dec 7, 2016
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.

The majority of this code is copied from maaku in bitcoin#6312
Further credit: btcdrak, sipa, NicolasDorier
@bitcoin bitcoin locked and limited conversation to collaborators Jan 9, 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.

None yet