Pages:
Author

Topic: Explain lock time / replacing transactions (Read 9181 times)

legendary
Activity: 1708
Merit: 1007
January 14, 2014, 03:06:32 PM
#28
From another thread...

Wow, thanks! but that is WAY over my head. I'd better go watch the Khan Academy videos. . .

People will come up with pretty tools to make it easier as we go.  But for now, the guts are certainly here and do work.

This really can be done by hand though, if you have an urgent need to do it.  Decoding a transaction in hex by hand is pretty easy.  Just follow the docs and remember that each byte is 2 chars, and that you are counting in hex (in my example below, the pkscript length 19 is in hex and means 16+9=25).

And double check everything before you send anything.


01000000 - version
01 - vin count
 2084ba9f2f0f98bb - prevout hash
 1cf0320ee1c486b5
 9b6b79e243de7596
 d3e44fa087b597aa
 01000000 - prevout index
 00 - signature script length
 ffffffff - sequence
01 - vout count
 00e1f50500000000 - value
 19 - pkscript length
 76a91428f60d621b - pkscript
 5d07b9c2820c11cc
 c6d41146b53a3e88
 ac
00000000 - locktime


A transaction is final when:
 the sequences are no longer incrementable or
 the locktime is in the past

A transaction that is not final will not be accepted for relay.  The brute force method of transaction replacement, which works with all software on all networks, is to not broadcast the transaction (sendrawtransaction) until it is ready.  Most uses don't actually need any sort of replacement mechanism.

This only works for some use cases.  There are a few cases that the transaction must be valid and signed, and broadcasted to at least one third party.  Which still works, because it's not required that said third party distribute further, so long as they are willing to accept that one into their own queue.
legendary
Activity: 1526
Merit: 1129
January 14, 2014, 01:11:27 PM
#27
At the time I just took out the return statement to reactivate that codepath, and then used a bitcoinj app to do the replacement. Nothing fancy.
kjj
legendary
Activity: 1302
Merit: 1024
January 14, 2014, 08:36:57 AM
#26
From another thread...

Wow, thanks! but that is WAY over my head. I'd better go watch the Khan Academy videos. . .

People will come up with pretty tools to make it easier as we go.  But for now, the guts are certainly here and do work.

This really can be done by hand though, if you have an urgent need to do it.  Decoding a transaction in hex by hand is pretty easy.  Just follow the docs and remember that each byte is 2 chars, and that you are counting in hex (in my example below, the pkscript length 19 is in hex and means 16+9=25).

And double check everything before you send anything.


01000000 - version
01 - vin count
 2084ba9f2f0f98bb - prevout hash
 1cf0320ee1c486b5
 9b6b79e243de7596
 d3e44fa087b597aa
 01000000 - prevout index
 00 - signature script length
 ffffffff - sequence
01 - vout count
 00e1f50500000000 - value
 19 - pkscript length
 76a91428f60d621b - pkscript
 5d07b9c2820c11cc
 c6d41146b53a3e88
 ac
00000000 - locktime


A transaction is final when:
 the sequences are no longer incrementable or
 the locktime is in the past

A transaction that is not final will not be accepted for relay.  The brute force method of transaction replacement, which works with all software on all networks, is to not broadcast the transaction (sendrawtransaction) until it is ready.  Most uses don't actually need any sort of replacement mechanism.
newbie
Activity: 16
Merit: 0
January 14, 2014, 08:14:43 AM
#25

Also, what makes you think it didn't work? I did local transaction replacements on private testnets and it worked fine.


Would you be so kind to explain in short the simplest method to make transaction replacements for test? Just use createrawtransaction for 2 trxs with different nSequence? Sorry for dumb question,  but I'm completelly new in bitcoin programming and it is very difficult to understand what to do exactly, too many new information.)
legendary
Activity: 1526
Merit: 1129
January 14, 2014, 07:16:04 AM
#24
Please don't characterise what "other developers" think so casually. Obviously I think it's viable with some internal resource scheduling work (which is needed anyway), and Satoshi also thought it's viable. Many others haven't even weighed in, as far as I know.

Also, what makes you think it didn't work? I did local transaction replacements on private testnets and it worked fine.

I edited the section to remove the pointless editorialising and simply state the facts as they are.
newbie
Activity: 16
Merit: 0
January 14, 2014, 07:09:58 AM
#23
Thank you for explanation.
legendary
Activity: 1120
Merit: 1149
January 14, 2014, 06:25:08 AM
#22

However we have done a lot of research and documentation on how it can be used:

https://en.bitcoin.it/wiki/Contracts

Sorry for question in old thread,  but it is about the things I'm very interesting too.
So, this functionality is not implemented in bitcoin or any altcoin, am I right?


nLockTime is, mempool transaction replacement isn't.

I added a warning to the contracts page explaining how mempool tx replacement is disabled and that implementors shouldn't assume it ever will be enabled. The page should be rewritten in the future to avoid reference to it.
newbie
Activity: 16
Merit: 0
January 14, 2014, 05:20:18 AM
#21

However we have done a lot of research and documentation on how it can be used:

https://en.bitcoin.it/wiki/Contracts

Sorry for question in old thread,  but it is about the things I'm very interesting too.
So, this functionality is not implemented in bitcoin or any altcoin, am I right?
newbie
Activity: 13
Merit: 0
January 11, 2014, 09:13:45 PM
#20
You lock the transaction so it isn't included in the chain and until that time you can update the transaction.

Vice versa... You unlock transaction for further changes...
newbie
Activity: 26
Merit: 0
Transaction replacement has been "implemented" since day 1, but it was switched off until some concerns with it can be addressed.

Those concerns were not yet addressed so it wasn't yet switched back on.

However we have done a lot of research and documentation on how it can be used:

https://en.bitcoin.it/wiki/Contracts

Mike thanks for the link! Those features are exciting!
legendary
Activity: 1072
Merit: 1174
December 07, 2012, 09:38:17 AM
#18

nLockTime is implemented and has always been enabled (disabling this would be a forking change).

It is transaction replacement (which is related, but not the same thing) which is disabled (and enabling this is just a local implementation change, not a forking change).
legendary
Activity: 1190
Merit: 1004
legendary
Activity: 1526
Merit: 1129
December 07, 2012, 07:11:29 AM
#16
Transaction replacement has been "implemented" since day 1, but it was switched off until some concerns with it can be addressed.

Those concerns were not yet addressed so it wasn't yet switched back on.

However we have done a lot of research and documentation on how it can be used:

https://en.bitcoin.it/wiki/Contracts
donator
Activity: 2772
Merit: 1019
December 07, 2012, 03:35:31 AM
#15
You can change everything.

This is not true. All prevouts must remain identical and none may be removed or added, for a transaction to be considered a new version of another. Input scripts may be changed, though.

For outputs, you can change everything.

sorry to necro this thread.

I like this feature. Is it implemented by now and if so what are the implications of "old clients" being around that don't yet implement this?
legendary
Activity: 1072
Merit: 1174
You can change everything.

This is not true. All prevouts must remain identical and none may be removed or added, for a transaction to be considered a new version of another. Input scripts may be changed, though.

For outputs, you can change everything.
legendary
Activity: 1708
Merit: 1007
Basically if presented with 2 transactions then miners can randomly choose which to include in a block (if using the same outputs). The only condition is that the tx they include mustn't use the same outputs as a tx already in a block.

So you send out tx A with no fee, and tx B with a fee + lock time.

Two scenarios:

1.  tx A gets included in a block before tx B's locktime finishes. By the time tx B becomes active, tx A is already in a block so it gets dropped.

2. tx A never gets into a block. tx B becomes active + gets into a block. tx A is forgotten.

I'm pretty sure that the free transaction that doesn't consider a lock time would render the one with the fee and lock time invalid.  The reason for this is because the scripting system is required to use a lock time, and this requires a fee, but it's the use of the lock time that keeps the inputs from being 'commited' by the clients that see the lock time transaction.  However, the regular (feeless) transaction would cause the inputs to be 'commited' by the clients, and thus the scripted transaction would become invalid and be dropped before it's lock expired.  I could be wrong about this, not sure.
administrator
Activity: 5166
Merit: 12850
You can change everything.
member
Activity: 115
Merit: 10
You could add additional inputs or remove some of the inputs if there were several. You could even change the input scripts (as long as they still work).
Thanks.  I that clears up a lot.  Can you change the outputs or are they required to be the same?
legendary
Activity: 1232
Merit: 1083
Basically if presented with 2 transactions then miners can randomly choose which to include in a block (if using the same outputs). The only condition is that the tx they include mustn't use the same outputs as a tx already in a block.

I think I'm beginning to understand this, tell me if I have it right.  A output can only be spent once, thus, if two transactions spend the same output (as one of their inputs) then they count as the same transaction. So if you had two transactions:

T1:
Input1,Input2 -> Output1

T2:
Input1,Input3 -> Output2

They would both be considered different versions of the same transaction since the both share Input1.

I am pretty sure the current client would consider the second transaction that it received invalid, since it is reusing an input.

It would assume that it is a double spend attempt and refuse to forward it to the rest of the network.

If you could get both to miners, then the miner would have to decide which one would be used.

Once one is incorporated into the chain, then the other one is considered dead.

Quote
If you had a transaction
T3:
Input1 -> Output1 with a lock time that was non-zero and greater than the current block number then that transaction then that transaction is still open, you would be able to broadcast a replacement transaction (with a higher sequence number) and change the output or the script  (or both) to whatever you wanted, but you couldn't change the input.

That is the intention of the lock system.
administrator
Activity: 5166
Merit: 12850
You could add additional inputs or remove some of the inputs if there were several. You could even change the input scripts (as long as they still work).
Pages:
Jump to: