Backport of #7184 (BIP68), #7524 (BIP112), #7187 (lockpoints), #7575 (BIP9) and #7648 (softfork) for 0.12.
EDIT: added #7531 (one line add test to extendedTests array and trivial comment edit #7773
ACK on this being the correct backport, but I would prefer to see 1 pull with the soft fork logic and all accompanying implementations backported at the same time. I think it would be much safer to test and review it together like that. Lets wait until we have the soft fork logic finished and merged.
SequenceLocks functions are used to evaluate sequence lock times or heights per BIP 68.
The majority of this code is copied from maaku in #6312
Further credit: btcdrak, sipa, NicolasDorier
it boggles the mind why these nits can't be delivered on a more timely basis
- Replace NOP3 with CHECKSEQUENCEVERIFY (BIP112)
<nSequence> CHECKSEQUENCEVERIFY -> <nSequence>
- Fails if txin.nSequence < nSequence, allowing funds of a txout to be locked for a number of blocks or a duration of time after its inclusion in a block.
- Pull most of CheckLockTime() out into VerifyLockTime(), a local function that will be reused for CheckSequence()
- Add bitwise AND operator to CScriptNum
- Enable CHECKSEQUENCEVERIFY as a standard script verify flag
- Transactions that fail CSV verification will be rejected from the mempool, making it easy to test the feature. However blocks containing "invalid" CSV-using transactions will still be accepted; this is *not* the soft-fork required to actually enable CSV for production use.
For the sake of a little repetition, make code more readable.
This if statement is a little obtuse and using braces here
improves readability.
Obtain LockPoints to store in CTxMemPoolEntry and during a reorg, evaluate whether they are still valid and if not, recalculate them.
Inspired by former implementations by Eric Lombrozo and Rusty Russell, and
based on code by Jorge Timon.
This commit introduces a way to gracefully bump the default
transaction version in a two step process.
This RPC test will test both the activation mechanism of the first versionbits soft fork as well as testing many code branches of the consensus logic for BIP's 68, 112, and 113.
ACK 3a99feb (backported myself and got the same code)
Mechanical backport check ACK 26e9a05cc3192ce19b7c46043aeb12230d3207a5
Ran the following script:
while read F L; do git show $F | egrep -v '^index ' | egrep -v '^commit ' | egrep -v '^@@ ' >/tmp/f; git show $L | egrep -v '^index ' | egrep -v '^commit ' | egrep -v '^@@ ' >/tmp/l; diff /tmp/f /tmp/l; done
with input: 12c89c918534f8e615e80381b692d89d6b09d174 159ee3dd90490eabf6c048c17a62ffa01f6a0967 02c243580295a7f1c0298fcd9afc2e76b607e724 9713ed3015da02b0132b665e965fd591689e6510 478fba6d5213a3f1ffeca5feeacf28aaf6844fd6 648be9b442587cc1682052bca80625aea906a01d 65751a3cf2421a9419172949cad9dc49b7383551 ee40924fef1e8835b9ef865360b126952ad8359d d23f6c6a0d2dc8a3f5f159faf7a40157259a8f8f 0bdaacd7913fd626691daa2946590547071dcf3b 6851107b3a52ec869e5e3a2cb4eb02d6c743b8e5 6f83cf2adb2fd73cfeaa8ef67054ea8a0e4ef4db 982670c333aff6d5660c18ed00931df764733529 ade85e126d1ba7cb90a3382fb8c3cc4f3b89dc4d a38107643f3f01cd92a4e6da9e7a9d025770ff37 c8d309e4b4d82dd233f167b4df503e6a5b4164ef c3c375226ebf98901849593b8ebfe8e8b69895c2 6170506fdf920e1cb07c086be670ad624cb04241 53e53a33c939949665f60d5eeb82abbb21f97128 c0c5e09fe2166a0b8ea6fc1f13e131e3ba8df478 b043c4b746c8199ce948aa5e8b186e0d1a61ad68 197c3760ff07daeecbb726a0cfef899502520ee5 15ba08c3b5f66a6c4726a746affc7fb3216d4206 c6c2f0fd782ccf607027414012f45c8f48561a30
(the corresponding non-test commits)
The output is:
29c29
< return state.DoS(10, false, REJECT_INVALID, "bad-txns-nonfinal", false, "non-final transaction");
---
> return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal");
68,70c68,70
< diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
< --- a/src/rpc/blockchain.cpp
< +++ b/src/rpc/blockchain.cpp
---
> diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
> --- a/src/rpcblockchain.cpp
> +++ b/src/rpcblockchain.cpp
40,42c40,42
< diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
< --- a/src/rpc/blockchain.cpp
< +++ b/src/rpc/blockchain.cpp
---
> diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
> --- a/src/rpcblockchain.cpp
> +++ b/src/rpcblockchain.cpp
12d11
< utilmoneystr.h \
14a14
> version.h \
18c18
< wallet/rpcwallet.h \
---
> wallet/wallet.h \
which is good, as there are no lines starting with '+' or '-' that changed between the diffs.
ACK caf138122decac7d96b2f53c0c894277cb0f33ca
backport matches, tACK caf1381
utACK
89 | + # generate some coins for later 90 | + self.coinbase_blocks = self.nodes[0].generate(2) 91 | + self.height = 3 # height of the next block to build 92 | + self.tip = int ("0x" + self.nodes[0].getbestblockhash() + "L", 0) 93 | + self.nodeaddress = self.nodes[0].getnewaddress() 94 | + self.last_block_time = time.time()
This should explicitly be int. Sadly, py2 will silently cast the float to int where needed.
60 | + assert(len(utxos) > 0) 61 | + 62 | + utxo = utxos[0] 63 | + 64 | + tx1 = CTransaction() 65 | + value = satoshi_round(utxo["amount"] - self.relayfee)*COIN
This should be int. (see previous comment)
179 | + sequence_value |= SEQUENCE_LOCKTIME_TYPE_FLAG 180 | + tx.vin.append(CTxIn(COutPoint(int(utxos[j]["txid"], 16), utxos[j]["vout"]), nSequence=sequence_value)) 181 | + value += utxos[j]["amount"]*COIN 182 | + # Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output 183 | + tx_size = len(ToHex(tx))/2 + 120*num_inputs + 50 184 | + tx.vout.append(CTxOut(value-self.relayfee*tx_size*COIN/1000, CScript([b'a'])))
the first arg to CTxOut should be int explicitly (see previous comment).
utACK c270b62. My nits can be fixed later
utACK, checked with sipa's script
partial backport from #7778 using fa2cea1
180 | @@ -181,7 +181,7 @@ def test_sequence_lock_confirmed_inputs(self): 181 | value += utxos[j]["amount"]*COIN 182 | # Overestimate the size of the tx - signatures should be less than 120 bytes, and leave 50 for the output 183 | tx_size = len(ToHex(tx))/2 + 120*num_inputs + 50 184 | - tx.vout.append(CTxOut(value-self.relayfee*tx_size*COIN/1000, CScript([b'a']))) 185 | + tx.vout.append(int(CTxOut(value-self.relayfee*tx_size*COIN/1000, CScript([b'a']))))
I'd be surprised if this worked. (You are passing the CTxOut into int())
Edit: You could just try a git cherry-pick ...; git reset HEAD~; git commit qa/rpc-tests/bip*
Fixed.
@MarcoFalke I cherry-picked your int/float fixes for RPC tests, from #7778 commit fa2cea1 in 640666b
utACK 640666b
ACK 3a99feb