Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: btcash on May 03, 2017, 09:12:00 PM

Title: Relative locktime / CSV enforcement
Post by: btcash on May 03, 2017, 09:12:00 PM
I don't fully understand how bitcoin prevents relative locktime (rl) /csv transactions from being mined early.

1. Tx A with csv = 10 blocks  -> The output is spendable 10 blocks after Tx A has been mined
2. Tx A gets mined at height x
3. Tx B spends the output of Tx A, sets rl (sequence) = 12, pushed to the network at height x+1

I am not sure what happens now. The csv of Tx A is checked against the sequence of Tx B and the validation fails if larger?

if (nSequenceMasked > txToSequenceMasked)
return false; (

Doesn't this mean that Tx B would be mined before x+10? Why do we compare the locktime to the locktime of the spending TX? Wouldn't it be easier to simply compare it to the current block height or time?

Question 2:
Let's say I set the sequence to +10 blocks and csv +20, which one is valid?
With relative locktime + CSV you could create an address such that any BTC sent there can only be spent after sitting unspent for 6 months.

I could do the same thing with either relative locktime or csv?

Question 3:
Which sequence gets chosen if we have multiple inputs with different sequences?