2018-09-26 16:17:47 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright (c) 2018 The Dash Core developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
from test_framework.mininode import *
|
2018-10-20 16:08:02 +02:00
|
|
|
from test_framework.test_framework import DashTestFramework
|
2018-09-26 16:17:47 +02:00
|
|
|
from test_framework.util import *
|
|
|
|
from time import *
|
|
|
|
|
|
|
|
'''
|
|
|
|
autoix-mempool.py
|
|
|
|
|
|
|
|
Checks if automatic InstantSend locks stop working when transaction mempool
|
|
|
|
is full (more than 0.1 part from max value).
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
2018-12-31 08:12:36 +01:00
|
|
|
MAX_MEMPOOL_SIZE = 1 # max node mempool in MBs
|
2018-09-26 16:17:47 +02:00
|
|
|
MB_SIZE = 1000000 # C++ code use this coefficient to calc MB in mempool
|
|
|
|
AUTO_IX_MEM_THRESHOLD = 0.1
|
|
|
|
|
|
|
|
|
2018-10-20 16:08:02 +02:00
|
|
|
class AutoIXMempoolTest(DashTestFramework):
|
2018-09-26 16:17:47 +02:00
|
|
|
def __init__(self):
|
2019-01-29 15:54:38 +01:00
|
|
|
super().__init__(13, 10, ["-maxmempool=%d" % MAX_MEMPOOL_SIZE, '-limitdescendantsize=10'], fast_dip3_enforcement=True)
|
2018-10-20 16:08:02 +02:00
|
|
|
# set sender, receiver
|
2018-09-26 16:17:47 +02:00
|
|
|
self.receiver_idx = self.num_nodes - 2
|
|
|
|
self.sender_idx = self.num_nodes - 3
|
|
|
|
|
|
|
|
def get_autoix_bip9_status(self):
|
|
|
|
info = self.nodes[0].getblockchaininfo()
|
2018-10-26 18:42:52 +02:00
|
|
|
# we reuse the dip3 deployment
|
|
|
|
return info['bip9_softforks']['dip0003']['status']
|
2018-09-26 16:17:47 +02:00
|
|
|
|
|
|
|
def activate_autoix_bip9(self):
|
|
|
|
# sync nodes periodically
|
|
|
|
# if we sync them too often, activation takes too many time
|
|
|
|
# if we sync them too rarely, nodes failed to update its state and
|
|
|
|
# bip9 status is not updated
|
|
|
|
# so, in this code nodes are synced once per 20 blocks
|
|
|
|
counter = 0
|
|
|
|
sync_period = 10
|
|
|
|
|
|
|
|
while self.get_autoix_bip9_status() == 'defined':
|
|
|
|
set_mocktime(get_mocktime() + 1)
|
|
|
|
set_node_times(self.nodes, get_mocktime())
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
counter += 1
|
|
|
|
if counter % sync_period == 0:
|
|
|
|
# sync nodes
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
while self.get_autoix_bip9_status() == 'started':
|
|
|
|
set_mocktime(get_mocktime() + 1)
|
|
|
|
set_node_times(self.nodes, get_mocktime())
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
counter += 1
|
|
|
|
if counter % sync_period == 0:
|
|
|
|
# sync nodes
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
while self.get_autoix_bip9_status() == 'locked_in':
|
|
|
|
set_mocktime(get_mocktime() + 1)
|
|
|
|
set_node_times(self.nodes, get_mocktime())
|
|
|
|
self.nodes[0].generate(1)
|
|
|
|
counter += 1
|
|
|
|
if counter % sync_period == 0:
|
|
|
|
# sync nodes
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# sync nodes
|
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
assert(self.get_autoix_bip9_status() == 'active')
|
|
|
|
|
|
|
|
def get_autoix_spork_state(self):
|
|
|
|
info = self.nodes[0].spork('active')
|
|
|
|
return info['SPORK_16_INSTANTSEND_AUTOLOCKS']
|
|
|
|
|
|
|
|
def set_autoix_spork_state(self, state):
|
2019-01-02 06:57:38 +01:00
|
|
|
# Increment mocktime as otherwise nodes will not update sporks
|
|
|
|
set_mocktime(get_mocktime() + 1)
|
|
|
|
set_node_times(self.nodes, get_mocktime())
|
|
|
|
|
2018-09-26 16:17:47 +02:00
|
|
|
if state:
|
|
|
|
value = 0
|
|
|
|
else:
|
|
|
|
value = 4070908800
|
|
|
|
self.nodes[0].spork('SPORK_16_INSTANTSEND_AUTOLOCKS', value)
|
|
|
|
|
|
|
|
# sends regular IX with high fee and may inputs (not-simple transaction)
|
|
|
|
def send_regular_IX(self, sender, receiver):
|
|
|
|
receiver_addr = receiver.getnewaddress()
|
|
|
|
txid = sender.instantsendtoaddress(receiver_addr, 1.0)
|
2018-10-20 16:08:02 +02:00
|
|
|
return self.wait_for_instantlock(txid, sender)
|
2018-09-26 16:17:47 +02:00
|
|
|
|
|
|
|
# sends simple trx, it should become IX if autolocks are allowed
|
|
|
|
def send_simple_tx(self, sender, receiver):
|
|
|
|
raw_tx = self.create_raw_trx(sender, receiver, 1.0, 1, 4)
|
|
|
|
txid = self.nodes[0].sendrawtransaction(raw_tx['hex'])
|
|
|
|
self.sync_all()
|
2018-10-20 16:08:02 +02:00
|
|
|
return self.wait_for_instantlock(txid, sender)
|
2018-09-26 16:17:47 +02:00
|
|
|
|
2018-11-05 10:28:04 +01:00
|
|
|
def get_mempool_usage(self, node):
|
2018-09-26 16:17:47 +02:00
|
|
|
info = node.getmempoolinfo()
|
|
|
|
return info['usage']
|
|
|
|
|
|
|
|
def fill_mempool(self):
|
2018-11-05 10:28:04 +01:00
|
|
|
# send lots of txes to yourself just to fill the mempool
|
|
|
|
counter = 0
|
|
|
|
sync_period = 10
|
|
|
|
dummy_address = self.nodes[0].getnewaddress()
|
|
|
|
while self.get_mempool_usage(self.nodes[self.sender_idx]) < MAX_MEMPOOL_SIZE * MB_SIZE * AUTO_IX_MEM_THRESHOLD:
|
|
|
|
self.nodes[0].sendtoaddress(dummy_address, 1.0)
|
|
|
|
counter += 1
|
|
|
|
if counter % sync_period == 0:
|
|
|
|
# sync nodes
|
|
|
|
self.sync_all()
|
2018-09-26 16:17:47 +02:00
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
def run_test(self):
|
2018-11-05 10:28:04 +01:00
|
|
|
# make sure masternodes are synced
|
|
|
|
sync_masternodes(self.nodes)
|
2019-03-03 18:26:06 +01:00
|
|
|
|
|
|
|
self.nodes[0].spork("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
self.mine_quorum()
|
|
|
|
|
2019-03-11 14:32:26 +01:00
|
|
|
self.log.info("Test old InstantSend")
|
2019-03-03 18:26:06 +01:00
|
|
|
self.test_auto();
|
|
|
|
|
2019-03-04 13:33:34 +01:00
|
|
|
self.nodes[0].spork("SPORK_20_INSTANTSEND_LLMQ_BASED", 0)
|
2019-03-03 18:26:06 +01:00
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
2019-03-11 14:32:26 +01:00
|
|
|
self.log.info("Test new InstantSend")
|
2019-03-03 18:26:06 +01:00
|
|
|
self.test_auto(True);
|
|
|
|
|
|
|
|
def test_auto(self, new_is = False):
|
2018-09-26 16:17:47 +02:00
|
|
|
self.activate_autoix_bip9()
|
|
|
|
self.set_autoix_spork_state(True)
|
|
|
|
|
|
|
|
# check pre-conditions for autoIX
|
|
|
|
assert(self.get_autoix_bip9_status() == 'active')
|
|
|
|
assert(self.get_autoix_spork_state())
|
|
|
|
|
2018-11-05 10:28:04 +01:00
|
|
|
# create 3 inputs for txes on sender node and give them 6 confirmations
|
|
|
|
sender = self.nodes[self.sender_idx]
|
|
|
|
receiver = self.nodes[self.receiver_idx]
|
|
|
|
sender_address = sender.getnewaddress()
|
2019-01-02 06:57:38 +01:00
|
|
|
for i in range(0, 4):
|
2018-11-05 10:28:04 +01:00
|
|
|
self.nodes[0].sendtoaddress(sender_address, 2.0)
|
|
|
|
for i in range(0, 6):
|
|
|
|
set_mocktime(get_mocktime() + 1)
|
|
|
|
set_node_times(self.nodes, get_mocktime())
|
|
|
|
self.nodes[0].generate(1)
|
2018-09-26 16:17:47 +02:00
|
|
|
self.sync_all()
|
|
|
|
|
2018-11-05 10:28:04 +01:00
|
|
|
# autoIX is working
|
|
|
|
assert(self.send_simple_tx(sender, receiver))
|
|
|
|
|
2018-09-26 16:17:47 +02:00
|
|
|
# fill mempool with transactions
|
2019-01-02 06:57:38 +01:00
|
|
|
self.set_autoix_spork_state(False)
|
2019-03-05 17:35:18 +01:00
|
|
|
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 4070908800)
|
|
|
|
self.wait_for_sporks_same()
|
2018-09-26 16:17:47 +02:00
|
|
|
self.fill_mempool()
|
2019-01-02 06:57:38 +01:00
|
|
|
self.set_autoix_spork_state(True)
|
2019-03-05 17:35:18 +01:00
|
|
|
self.nodes[0].spork("SPORK_2_INSTANTSEND_ENABLED", 0)
|
|
|
|
self.wait_for_sporks_same()
|
2018-09-26 16:17:47 +02:00
|
|
|
|
|
|
|
# autoIX is not working now
|
2018-11-05 10:28:04 +01:00
|
|
|
assert(not self.send_simple_tx(sender, receiver))
|
2019-03-03 18:26:06 +01:00
|
|
|
# regular IX is still working for old IS but not for new one
|
|
|
|
assert(not self.send_regular_IX(sender, receiver) if new_is else self.send_regular_IX(sender, receiver))
|
2018-09-26 16:17:47 +02:00
|
|
|
|
2019-01-02 06:57:38 +01:00
|
|
|
# generate one block to clean up mempool and retry auto and regular IX
|
|
|
|
# generate 2 more blocks to have enough confirmations for IX
|
|
|
|
self.nodes[0].generate(3)
|
|
|
|
self.sync_all()
|
|
|
|
assert(self.send_simple_tx(sender, receiver))
|
|
|
|
assert(self.send_regular_IX(sender, receiver))
|
|
|
|
|
2018-09-26 16:17:47 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
AutoIXMempoolTest().main()
|