16 SEQUENCE_LOCKTIME_DISABLE_FLAG = (1<<31)
17 SEQUENCE_LOCKTIME_TYPE_FLAG = (1<<22)
18 SEQUENCE_LOCKTIME_GRANULARITY = 9
19 SEQUENCE_LOCKTIME_MASK = 0x0000ffff
22 NOT_FINAL_ERROR =
"64: non-BIP68-final" 28 self.
nodes.append(
start_node(0, self.options.tmpdir, [
"-debug",
"-blockprioritysize=0"]))
29 self.
nodes.append(
start_node(1, self.options.tmpdir, [
"-debug",
"-blockprioritysize=0",
"-acceptnonstdtxn=0"]))
38 print "Running test disable flag" 41 print "Running test sequence-lock-confirmed-inputs" 44 print "Running test sequence-lock-unconfirmed-inputs" 47 print "Running test BIP68 not consensus before versionbits activation" 50 print "Verifying nVersion=2 transactions aren't standard" 53 print "Activating BIP68 (and 112/113)" 56 print "Verifying nVersion=2 transactions are now standard" 69 assert(len(utxos) > 0)
79 sequence_value = SEQUENCE_LOCKTIME_DISABLE_FLAG | 1
80 tx1.vin = [
CTxIn(
COutPoint(int(utxo[
"txid"], 16), utxo[
"vout"]), nSequence=sequence_value)]
85 tx1_id = int(tx1_id, 16)
91 sequence_value = sequence_value & 0x7fffffff
98 except JSONRPCException
as exp:
121 while len(addresses) < max_outputs:
125 random.shuffle(addresses)
126 num_outputs = random.randint(1, max_outputs)
128 for i
in xrange(num_outputs):
129 outputs[addresses[i]] = random.randint(1, 20)*0.01
140 for i
in xrange(400):
142 num_inputs = random.randint(1, 10)
143 random.shuffle(utxos)
149 using_sequence_locks =
False 154 for j
in xrange(num_inputs):
155 sequence_value = 0xfffffffe
158 if random.randint(0,1):
159 using_sequence_locks =
True 162 input_will_pass = (random.randint(1,10) == 1)
163 sequence_value = utxos[j][
"confirmations"]
164 if not input_will_pass:
177 if ((cur_time - orig_time) >> SEQUENCE_LOCKTIME_GRANULARITY) >= SEQUENCE_LOCKTIME_MASK:
178 can_time_lock =
False 181 if random.randint(0,1)
and can_time_lock:
183 time_delta = sequence_value << SEQUENCE_LOCKTIME_GRANULARITY
184 if input_will_pass
and time_delta > cur_time - orig_time:
185 sequence_value = ((cur_time - orig_time) >> SEQUENCE_LOCKTIME_GRANULARITY)
186 elif (
not input_will_pass
and time_delta <= cur_time - orig_time):
187 sequence_value = ((cur_time - orig_time) >> SEQUENCE_LOCKTIME_GRANULARITY)+1
188 sequence_value |= SEQUENCE_LOCKTIME_TYPE_FLAG
189 tx.vin.append(
CTxIn(
COutPoint(int(utxos[j][
"txid"], 16), utxos[j][
"vout"]), nSequence=sequence_value))
190 value += utxos[j][
"amount"]*COIN
192 tx_size = len(
ToHex(tx))//2 + 120*num_inputs + 50
198 except JSONRPCException
as exp:
199 assert(
not should_pass
and using_sequence_locks)
202 assert(should_pass
or not using_sequence_locks)
234 def test_nonzero_locks(orig_tx, node, relayfee, use_height_lock):
236 if not use_height_lock:
237 sequence_value |= SEQUENCE_LOCKTIME_TYPE_FLAG
241 tx.vin = [
CTxIn(
COutPoint(orig_tx.sha256, 0), nSequence=sequence_value)]
242 tx.vout = [
CTxOut(int(orig_tx.vout[0].nValue - relayfee*COIN),
CScript([b
'a']))]
246 node.sendrawtransaction(
ToHex(tx))
247 except JSONRPCException
as exp:
249 assert(orig_tx.hash
in node.getrawmempool())
252 assert(orig_tx.hash
not in node.getrawmempool())
255 test_nonzero_locks(tx2, self.
nodes[0], self.
relayfee, use_height_lock=
True)
256 test_nonzero_locks(tx2, self.
nodes[0], self.
relayfee, use_height_lock=
False)
261 cur_time = int(time.time())
269 test_nonzero_locks(tx2, self.
nodes[0], self.
relayfee, use_height_lock=
True)
270 test_nonzero_locks(tx2, self.
nodes[0], self.
relayfee, use_height_lock=
False)
282 tx3 = test_nonzero_locks(tx2, self.
nodes[0], self.
relayfee, use_height_lock=
False)
289 tx4 = test_nonzero_locks(tx3, self.
nodes[0], self.
relayfee, use_height_lock=
True)
293 tx5 = test_nonzero_locks(tx4, self.
nodes[0], self.
relayfee, use_height_lock=
True)
297 tx5.vin.append(
CTxIn(
COutPoint(int(utxos[0][
"txid"], 16), utxos[0][
"vout"]), nSequence=1))
298 tx5.vout[0].nValue += int(utxos[0][
"amount"]*COIN)
303 except JSONRPCException
as exp:
338 assert(tx3.hash
not in mempool)
339 assert(tx2.hash
in mempool)
375 tx3.vin = [
CTxIn(
COutPoint(tx2.sha256, 0), nSequence=sequence_value)]
381 except JSONRPCException
as exp:
390 block.vtx.extend([tx1, tx2, tx3])
391 block.hashMerkleRoot = block.calc_merkle_root()
400 min_activation_height = 432
418 assert(before_activation ==
False)
420 assert(before_activation)
423 if __name__ ==
'__main__':
UniValue prioritisetransaction(const UniValue ¶ms, bool fHelp)
def get_bip9_status(node, key)
UniValue getblockheader(const UniValue ¶ms, bool fHelp)
def FromHex(obj, hex_string)
UniValue getrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue sendmany(const UniValue ¶ms, bool fHelp)
UniValue listunspent(const UniValue ¶ms, bool fHelp)
UniValue sendtoaddress(const UniValue ¶ms, bool fHelp)
UniValue submitblock(const UniValue ¶ms, bool fHelp)
def connect_nodes(from_connection, node_num)
UniValue getnewaddress(const UniValue ¶ms, bool fHelp)
UniValue getblockhash(const UniValue ¶ms, bool fHelp)
UniValue getblockcount(const UniValue ¶ms, bool fHelp)
UniValue signrawtransaction(const UniValue ¶ms, bool fHelp)
UniValue createrawtransaction(const UniValue ¶ms, bool fHelp)
def satoshi_round(amount)
def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None)
def test_bip68_not_consensus(self)
def test_version2_relay(self, before_activation)
UniValue generate(const UniValue ¶ms, bool fHelp)
UniValue sendrawtransaction(const UniValue ¶ms, bool fHelp)
def sync_blocks(rpc_connections, wait=1)
def test_sequence_lock_unconfirmed_inputs(self)
UniValue getrawmempool(const UniValue ¶ms, bool fHelp)
UniValue getbestblockhash(const UniValue ¶ms, bool fHelp)
UniValue getnetworkinfo(const UniValue ¶ms, bool fHelp)
def test_disable_flag(self)
def get_median_time_past(self, confirmations)
UniValue setmocktime(const UniValue ¶ms, bool fHelp)
def assert_equal(thing1, thing2)
def test_sequence_lock_confirmed_inputs(self)