Merge branch 'FSM' into jl777

This commit is contained in:
jl777
2018-12-15 07:45:51 -11:00
14 changed files with 274 additions and 544 deletions

83
qa/pull-tester/cc-tests.sh Executable file
View File

@@ -0,0 +1,83 @@
#!/bin/bash
set -e -o pipefail
CURDIR=$(cd $(dirname "$0"); pwd)
# Get BUILDDIR and REAL_BITCOIND
. "${CURDIR}/tests-config.sh"
export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli
export BITCOIND=${REAL_BITCOIND}
#Run the tests
# FAUCET test should be permanently first!!!
testScripts=(
'cryptoconditions_faucet.py'
'cryptoconditions_channels.py'
'cryptoconditions_dice.py'
'cryptoconditions_oracles.py'
'cryptoconditions_rewards.py'
'cryptoconditions_token.py'
'cryptoconditions_gateways.py'
);
extArg="-extended"
passOn=${@#$extArg}
successCount=0
declare -a failures
function runTestScript
{
local testName="$1"
shift
echo -e "=== Running testscript ${testName} ==="
if eval "$@"
then
successCount=$(expr $successCount + 1)
echo "--- Success: ${testName} ---"
else
failures[${#failures[@]}]="$testName"
echo "!!! FAIL: ${testName} !!!"
fi
echo
}
if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then
for (( i = 0; i < ${#testScripts[@]}; i++ ))
do
if [ -z "$1" ] || [ "${1:0:1}" == "-" ] || [ "$1" == "${testScripts[$i]}" ] || [ "$1.py" == "${testScripts[$i]}" ]
then
runTestScript \
"${testScripts[$i]}" \
"${BUILDDIR}/qa/rpc-tests/${testScripts[$i]}" \
--srcdir "${BUILDDIR}/src" ${passOn}
fi
done
for (( i = 0; i < ${#testScriptsExt[@]}; i++ ))
do
if [ "$1" == $extArg ] || [ "$1" == "${testScriptsExt[$i]}" ] || [ "$1.py" == "${testScriptsExt[$i]}" ]
then
runTestScript \
"${testScriptsExt[$i]}" \
"${BUILDDIR}/qa/rpc-tests/${testScriptsExt[$i]}" \
--srcdir "${BUILDDIR}/src" ${passOn}
fi
done
echo -e "\n\nTests completed: $(expr $successCount + ${#failures[@]})"
echo "successes $successCount; failures: ${#failures[@]}"
if [ ${#failures[@]} -gt 0 ]
then
echo -e "\nFailing tests: ${failures[*]}"
exit 1
else
exit 0
fi
else
echo "No rpc tests to run. Wallet, utils, and bitcoind must all be enabled"
fi

View File

@@ -13,14 +13,6 @@ export BITCOIND=${REAL_BITCOIND}
testScripts=( testScripts=(
'ac_private.py' 'ac_private.py'
'verushash.py' 'verushash.py'
'cryptoconditions.py'
'cryptoconditions_channels.py'
'cryptoconditions_dice.py'
'cryptoconditions_faucet.py'
'cryptoconditions_gateways.py'
'cryptoconditions_oracles.py'
'cryptoconditions_rewards.py'
'cryptoconditions_token.py'
'paymentdisclosure.py' 'paymentdisclosure.py'
'prioritisetransaction.py' 'prioritisetransaction.py'
'wallet_treestate.py' 'wallet_treestate.py'

View File

@@ -14,6 +14,8 @@ You can run a single test by calling `qa/pull-tester/rpc-tests.sh <testname>`.
Run all possible tests with `qa/pull-tester/rpc-tests.sh -extended`. Run all possible tests with `qa/pull-tester/rpc-tests.sh -extended`.
Also it's possible to run CryptoConditions tests only by `qa/pull-tester/cc-tests.sh --noshutdown --tracerpc`
Possible options: Possible options:
``` ```

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,71 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsChannelsTest(BitcoinTestFramework): class CryptoconditionsChannelsTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_channels_tests(self): def run_channels_tests(self):
@@ -159,7 +95,8 @@ class CryptoconditionsChannelsTest(BitcoinTestFramework):
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -4,78 +4,15 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsDiceTest(BitcoinTestFramework):
def setup_chain(self): class CryptoconditionsDiceTest(CryptoconditionsTestFramework):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_dice_tests(self): def run_dice_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
@@ -244,7 +181,8 @@ class CryptoconditionsDiceTest(BitcoinTestFramework):
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,71 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsFaucetTest(BitcoinTestFramework): class CryptoconditionsFaucetTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_faucet_tests(self): def run_faucet_tests(self):
rpc = self.rpc rpc = self.rpc

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,72 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsGatewaysTest(BitcoinTestFramework): class CryptoconditionsGatewaysTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_gateways_tests(self): def run_gateways_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
@@ -137,12 +72,14 @@ class CryptoconditionsGatewaysTest(BitcoinTestFramework):
result = rpc.gatewayslist() result = rpc.gatewayslist()
assert_equal(result[0], bind_txid) assert_equal(result[0], bind_txid)
def run_test(self): def run_test(self):
print("Mining blocks...") print("Mining blocks...")
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,72 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsOraclesTest(BitcoinTestFramework): class CryptoconditionsOraclesTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_oracles_tests(self): def run_oracles_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
@@ -269,8 +204,6 @@ class CryptoconditionsOraclesTest(BitcoinTestFramework):
oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc) oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc)
result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1") result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1")
assert_equal("[u'0']", str(result["samples"][0]), "Data match") assert_equal("[u'0']", str(result["samples"][0]), "Data match")
assert_equal("[u'00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff']", str(result["samples"][1]), "Data match")
assert_equal("[u'00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff']", str(result["samples"][2]), "Data match")
def run_test(self): def run_test(self):
@@ -278,7 +211,8 @@ class CryptoconditionsOraclesTest(BitcoinTestFramework):
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,72 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsRewardsTest(BitcoinTestFramework): class CryptoconditionsRewardsTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_rewards_tests(self): def run_rewards_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
@@ -194,7 +129,8 @@ class CryptoconditionsRewardsTest(BitcoinTestFramework):
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -4,7 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import CryptoconditionsTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
@@ -12,72 +12,7 @@ from test_framework.util import assert_equal, assert_greater_than, \
from cryptoconditions import assert_success, assert_error, generate_random_string from cryptoconditions import assert_success, assert_error, generate_random_string
class CryptoconditionsTokenTest(BitcoinTestFramework): class CryptoconditionsTokenTest(CryptoconditionsTestFramework):
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
self.num_nodes = 2
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid
def run_token_tests(self): def run_token_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
@@ -274,7 +209,8 @@ class CryptoconditionsTokenTest(BitcoinTestFramework):
rpc = self.nodes[0] rpc = self.nodes[0]
rpc1 = self.nodes[1] rpc1 = self.nodes[1]
# utxos from block 1 become mature in block 101 # utxos from block 1 become mature in block 101
rpc.generate(101) if not self.options.noshutdown:
rpc.generate(101)
self.sync_all() self.sync_all()
rpc.getinfo() rpc.getinfo()
rpc1.getinfo() rpc1.getinfo()

View File

@@ -180,3 +180,72 @@ class ComparisonTestFramework(BitcoinTestFramework):
extra_args=[['-debug', '-whitelist=127.0.0.1']] * self.num_nodes, extra_args=[['-debug', '-whitelist=127.0.0.1']] * self.num_nodes,
binary=[self.options.testbinary] + binary=[self.options.testbinary] +
[self.options.refbinary]*(self.num_nodes-1)) [self.options.refbinary]*(self.num_nodes-1))
class CryptoconditionsTestFramework(BitcoinTestFramework):
def __init__(self):
self.num_nodes = 2
def setup_chain(self):
print("Initializing CC test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, self.num_nodes)
def setup_network(self, split = False):
print("Setting up network...")
self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D"
self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf"
self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9"
self.addr1 = "RXEXoa1nRmKhMbuZovpcYwQMsicwzccZBp"
self.pubkey1 = "024026d4ad4ecfc1f705a9b42ca64af6d2ad947509c085534a30b8861d756c6ff0"
self.privkey1 = "UtdydP56pGTFmawHzHr1wDrc4oUwCNW1ttX8Pc3KrvH3MA8P49Wi"
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir,
extra_args=[[
# always give -ac_name as first extra_arg and port as third
'-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node0/REGTEST.conf',
'-port=64367',
'-rpcport=64368',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt'
],
['-ac_name=REGTEST',
'-conf='+self.options.tmpdir+'/node1/REGTEST.conf',
'-port=64365',
'-rpcport=64366',
'-regtest',
'-addressindex=1',
'-spentindex=1',
'-ac_supply=5555555',
'-ac_reward=10000000000000',
'-pubkey=' + self.pubkey1,
'-ac_cc=2',
'-whitelist=127.0.0.1',
'-debug',
'-addnode=127.0.0.1:64367',
'--daemon',
'-rpcuser=rt',
'-rpcpassword=rt']]
)
self.is_network_split = split
self.rpc = self.nodes[0]
self.rpc1 = self.nodes[1]
self.sync_all()
print("Done setting up network")
def send_and_mine(self, xtn, rpc_connection):
txid = rpc_connection.sendrawtransaction(xtn)
assert txid, 'got txid'
# we need the tx above to be confirmed in the next block
rpc_connection.generate(1)
return txid

11
src/cc/dapps/Makefile Normal file
View File

@@ -0,0 +1,11 @@
# just type make to compile all dapps
all: zmigrate oraclefeed
zmigrate:
$(CC) zmigrate.c -o zmigrate -lm
oraclefeed:
$(CC) oraclefeed.c -o oraclefeed -lm
clean:
rm zmigrate oraclefeed

28
src/cc/dapps/README.md Normal file
View File

@@ -0,0 +1,28 @@
# CryptoCondition dApps
## Compiling
To compile all dapps in this directory:
make
## zmigrate - Sprout to Sapling Migration dApp
This tool converts Sprout zaddress funds into Sapling funds in a new Sapling address.
### Usage
./zmigrate zsaplingaddr
The above command may need to be run multiple times to complete the process.
This CLI implementation will be called by GUI wallets, average users do not
need to worry about using this low-level tool.
## oraclefeed - feed of price data using oracles
### Usage
./oraclefeed $ACNAME $ORACLETXID $MYPUBKEY $FORMAT $BINDTXID [refcoin_cli]
Supported formats are L and Ihh. Price data from CoinDesk API.

View File

@@ -134,7 +134,7 @@ namespace {
// First sort by most total work, ... // First sort by most total work, ...
if (pa->chainPower > pb->chainPower) return false; if (pa->chainPower > pb->chainPower) return false;
if (pa->chainPower < pb->chainPower) return true; if (pa->chainPower < pb->chainPower) return true;
// ... then by earliest time received, ... // ... then by earliest time received, ...
if (pa->nSequenceId < pb->nSequenceId) return false; if (pa->nSequenceId < pb->nSequenceId) return false;
if (pa->nSequenceId > pb->nSequenceId) return true; if (pa->nSequenceId > pb->nSequenceId) return true;
@@ -469,7 +469,7 @@ namespace {
// Make sure pindexBestKnownBlock is up to date, we'll need it. // Make sure pindexBestKnownBlock is up to date, we'll need it.
ProcessBlockAvailability(nodeid); ProcessBlockAvailability(nodeid);
if (state->pindexBestKnownBlock == NULL || state->pindexBestKnownBlock->chainPower < chainActive.Tip()->chainPower) { if (state->pindexBestKnownBlock == NULL || state->pindexBestKnownBlock->chainPower < chainActive.Tip()->chainPower) {
// This peer has nothing interesting. // This peer has nothing interesting.
return; return;
@@ -961,13 +961,13 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeight) bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeight)
{ {
// if time locks are on, ensure that this coin base is time locked exactly as it should be // if time locks are on, ensure that this coin base is time locked exactly as it should be
if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) || if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) ||
(((nHeight >= 31680) || strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0) && komodo_ac_block_subsidy(nHeight) >= ASSETCHAINS_TIMELOCKGTE)) (((nHeight >= 31680) || strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0) && komodo_ac_block_subsidy(nHeight) >= ASSETCHAINS_TIMELOCKGTE))
{ {
CScriptID scriptHash; CScriptID scriptHash;
// to be valid, it must be a P2SH transaction and have an op_return in vout[1] that // to be valid, it must be a P2SH transaction and have an op_return in vout[1] that
// holds the full output script, which may include multisig, etc., but starts with // holds the full output script, which may include multisig, etc., but starts with
// the time lock verify of the correct time lock for this block height // the time lock verify of the correct time lock for this block height
if (tx.vout.size() == 2 && if (tx.vout.size() == 2 &&
CScriptExt(tx.vout[0].scriptPubKey).IsPayToScriptHash(&scriptHash) && CScriptExt(tx.vout[0].scriptPubKey).IsPayToScriptHash(&scriptHash) &&
@@ -1116,7 +1116,7 @@ bool ContextualCheckTransaction(
return state.DoS(100, error("CheckTransaction(): error computing signature hash"), return state.DoS(100, error("CheckTransaction(): error computing signature hash"),
REJECT_INVALID, "error-computing-signature-hash"); REJECT_INVALID, "error-computing-signature-hash");
} }
} }
if (!(tx.IsMint() || tx.vjoinsplit.empty())) if (!(tx.IsMint() || tx.vjoinsplit.empty()))
@@ -1750,7 +1750,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
} }
// Bring the best block into scope // Bring the best block into scope
view.GetBestBlock(); view.GetBestBlock();
nValueIn = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime); nValueIn = view.GetValueIn(chainActive.LastTip()->GetHeight(),&interest,tx,chainActive.LastTip()->nTime);
if ( 0 && interest != 0 ) if ( 0 && interest != 0 )
fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); fprintf(stderr,"add interest %.8f\n",(double)interest/COIN);
@@ -1845,7 +1845,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
dFreeCount += nSize; dFreeCount += nSize;
} }
if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19) if (fRejectAbsurdFee && nFees > ::minRelayTxFee.GetFee(nSize) * 10000 && nFees > nValueOut/19)
{ {
string errmsg = strprintf("absurdly high fees %s, %d > %d", string errmsg = strprintf("absurdly high fees %s, %d > %d",
hash.ToString(), hash.ToString(),
@@ -2301,9 +2301,9 @@ int IsNotInSync()
CBlockIndex *pbi = chainActive.Tip(); CBlockIndex *pbi = chainActive.Tip();
int longestchain = komodo_longestchain(); int longestchain = komodo_longestchain();
if ( !pbi || if ( !pbi ||
(pindexBestHeader == 0) || (pindexBestHeader == 0) ||
((pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) || ((pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) ||
(longestchain != 0 && longestchain > pbi->GetHeight()) ) (longestchain != 0 && longestchain > pbi->GetHeight()) )
{ {
return (pbi && pindexBestHeader && (pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) ? return (pbi && pindexBestHeader && (pindexBestHeader->GetHeight() - 1) > pbi->GetHeight()) ?
@@ -2331,7 +2331,7 @@ void CheckForkWarningConditions()
// of our head, drop it // of our head, drop it
if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288) if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288)
pindexBestForkTip = NULL; pindexBestForkTip = NULL;
if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->chainPower > (chainActive.LastTip()->chainPower + (GetBlockProof(*chainActive.LastTip()) * 6)))) if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->chainPower > (chainActive.LastTip()->chainPower + (GetBlockProof(*chainActive.LastTip()) * 6))))
{ {
if (!fLargeWorkForkFound && pindexBestForkBase) if (!fLargeWorkForkFound && pindexBestForkBase)
@@ -2923,7 +2923,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
{ {
CCoinsModifier outs = view.ModifyCoins(hash); CCoinsModifier outs = view.ModifyCoins(hash);
outs->ClearUnspendable(); outs->ClearUnspendable();
CCoins outsBlock(tx, pindex->GetHeight()); CCoins outsBlock(tx, pindex->GetHeight());
// The CCoins serialization does not serialize negative numbers. // The CCoins serialization does not serialize negative numbers.
// No network rules currently depend on the version here, so an inconsistency is harmless // No network rules currently depend on the version here, so an inconsistency is harmless
@@ -3107,7 +3107,7 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
// Aim for one false-positive about every fifty years of normal running: // Aim for one false-positive about every fifty years of normal running:
const int FIFTY_YEARS = 50*365*24*60*60; const int FIFTY_YEARS = 50*365*24*60*60;
double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS); double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS);
if (bestHeader->GetHeight() > BLOCKS_EXPECTED) if (bestHeader->GetHeight() > BLOCKS_EXPECTED)
{ {
if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED) if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED)
@@ -3186,7 +3186,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
} }
return true; return true;
} }
bool fScriptChecks = (!fCheckpointsEnabled || pindex->GetHeight() >= Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints())); bool fScriptChecks = (!fCheckpointsEnabled || pindex->GetHeight() >= Checkpoints::GetTotalBlocksEstimate(chainparams.Checkpoints()));
//if ( KOMODO_TESTNET_EXPIRATION != 0 && pindex->GetHeight() > KOMODO_TESTNET_EXPIRATION ) // "testnet" //if ( KOMODO_TESTNET_EXPIRATION != 0 && pindex->GetHeight() > KOMODO_TESTNET_EXPIRATION ) // "testnet"
// return(false); // return(false);
@@ -3252,7 +3252,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
// Grab the consensus branch ID for the block's height // Grab the consensus branch ID for the block's height
auto consensusBranchId = CurrentEpochBranchId(pindex->GetHeight(), Params().GetConsensus()); auto consensusBranchId = CurrentEpochBranchId(pindex->GetHeight(), Params().GetConsensus());
std::vector<PrecomputedTransactionData> txdata; std::vector<PrecomputedTransactionData> txdata;
txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated txdata.reserve(block.vtx.size()); // Required so that pointers to individual PrecomputedTransactionData don't get invalidated
for (unsigned int i = 0; i < block.vtx.size(); i++) for (unsigned int i = 0; i < block.vtx.size(); i++)
@@ -3392,7 +3392,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
blockundo.vtxundo.push_back(CTxUndo()); blockundo.vtxundo.push_back(CTxUndo());
} }
UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->GetHeight()); UpdateCoins(tx, view, i == 0 ? undoDummy : blockundo.vtxundo.back(), pindex->GetHeight());
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
BOOST_FOREACH(const uint256 &note_commitment, joinsplit.commitments) { BOOST_FOREACH(const uint256 &note_commitment, joinsplit.commitments) {
// Insert the note commitments into our temporary tree. // Insert the note commitments into our temporary tree.
@@ -3427,9 +3427,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
} }
int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart; int64_t nTime1 = GetTimeMicros(); nTimeConnect += nTime1 - nTimeStart;
LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001); LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime1 - nTimeStart), 0.001 * (nTime1 - nTimeStart) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime1 - nTimeStart) / (nInputs-1), nTimeConnect * 0.000001);
CAmount blockReward = nFees + GetBlockSubsidy(pindex->GetHeight(), chainparams.GetConsensus()) + sum; CAmount blockReward = nFees + GetBlockSubsidy(pindex->GetHeight(), chainparams.GetConsensus()) + sum;
if ( ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && if ( ASSETCHAINS_COMMISSION != 0 ) //ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 &&
{ {
uint64_t checktoshis; uint64_t checktoshis;
if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->GetHeight())) != 0 ) if ( (checktoshis= komodo_commission((CBlock *)&block,(int32_t)pindex->GetHeight())) != 0 )
@@ -3494,7 +3494,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
} }
ConnectNotarisations(block, pindex->GetHeight()); ConnectNotarisations(block, pindex->GetHeight());
if (fTxIndex) if (fTxIndex)
if (!pblocktree->WriteTxIndex(vPos)) if (!pblocktree->WriteTxIndex(vPos))
return AbortNode(state, "Failed to write transaction index"); return AbortNode(state, "Failed to write transaction index");
@@ -3766,7 +3766,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
// Write the chain state to disk, if necessary. // Write the chain state to disk, if necessary.
if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED))
return false; return false;
if (!fBare) { if (!fBare) {
// resurrect mempool transactions from the disconnected block. // resurrect mempool transactions from the disconnected block.
for (int i = 0; i < block.vtx.size(); i++) for (int i = 0; i < block.vtx.size(); i++)
@@ -3775,7 +3775,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
CTransaction &tx = block.vtx[i]; CTransaction &tx = block.vtx[i];
list<CTransaction> removed; list<CTransaction> removed;
CValidationState stateDummy; CValidationState stateDummy;
// don't keep staking or invalid transactions // don't keep staking or invalid transactions
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL))
{ {
@@ -3796,7 +3796,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
// Update chainActive and related variables. // Update chainActive and related variables.
UpdateTip(pindexDelete->pprev); UpdateTip(pindexDelete->pprev);
// Get the current commitment tree // Get the current commitment tree
SproutMerkleTree newSproutTree; SproutMerkleTree newSproutTree;
SaplingMerkleTree newSaplingTree; SaplingMerkleTree newSaplingTree;
@@ -3942,10 +3942,10 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
// Remove conflicting transactions from the mempool. // Remove conflicting transactions from the mempool.
list<CTransaction> txConflicted; list<CTransaction> txConflicted;
mempool.removeForBlock(pblock->vtx, pindexNew->GetHeight(), txConflicted, !IsInitialBlockDownload()); mempool.removeForBlock(pblock->vtx, pindexNew->GetHeight(), txConflicted, !IsInitialBlockDownload());
// Remove transactions that expire at new block height from mempool // Remove transactions that expire at new block height from mempool
mempool.removeExpired(pindexNew->GetHeight()); mempool.removeExpired(pindexNew->GetHeight());
// Update chainActive & related variables. // Update chainActive & related variables.
UpdateTip(pindexNew); UpdateTip(pindexNew);
// Tell wallet about transactions that went from mempool // Tell wallet about transactions that went from mempool
@@ -3961,7 +3961,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
GetMainSignals().ChainTip(pindexNew, pblock, oldSproutTree, oldSaplingTree, true); GetMainSignals().ChainTip(pindexNew, pblock, oldSproutTree, oldSaplingTree, true);
EnforceNodeDeprecation(pindexNew->GetHeight()); EnforceNodeDeprecation(pindexNew->GetHeight());
int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1; int64_t nTime6 = GetTimeMicros(); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001);
LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001);
@@ -3969,7 +3969,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
KOMODO_INSYNC = (int32_t)pindexNew->GetHeight(); KOMODO_INSYNC = (int32_t)pindexNew->GetHeight();
else KOMODO_INSYNC = 0; else KOMODO_INSYNC = 0;
//fprintf(stderr,"connect.%d insync.%d ASSETCHAINS_SAPLING.%d\n",(int32_t)pindexNew->GetHeight(),KOMODO_INSYNC,ASSETCHAINS_SAPLING); //fprintf(stderr,"connect.%d insync.%d ASSETCHAINS_SAPLING.%d\n",(int32_t)pindexNew->GetHeight(),KOMODO_INSYNC,ASSETCHAINS_SAPLING);
if ( KOMODO_INSYNC != 0 ) //ASSETCHAINS_SYMBOL[0] == 0 && if ( KOMODO_INSYNC != 0 ) //ASSETCHAINS_SYMBOL[0] == 0 &&
komodo_broadcast(pblock,8); komodo_broadcast(pblock,8);
else if ( ASSETCHAINS_SYMBOL[0] != 0 ) else if ( ASSETCHAINS_SYMBOL[0] != 0 )
komodo_broadcast(pblock,4); komodo_broadcast(pblock,4);
@@ -4000,7 +4000,7 @@ static CBlockIndex* FindMostWorkChain() {
bool fInvalidAncestor = false; bool fInvalidAncestor = false;
while (pindexTest && !chainActive.Contains(pindexTest)) { while (pindexTest && !chainActive.Contains(pindexTest)) {
assert(pindexTest->nChainTx || pindexTest->GetHeight() == 0); assert(pindexTest->nChainTx || pindexTest->GetHeight() == 0);
// Pruned nodes may have entries in setBlockIndexCandidates for // Pruned nodes may have entries in setBlockIndexCandidates for
// which block files have been deleted. Remove those as candidates // which block files have been deleted. Remove those as candidates
// for the most work chain if we come across them; we can't switch // for the most work chain if we come across them; we can't switch
@@ -4282,9 +4282,9 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
AssertLockHeld(cs_main); AssertLockHeld(cs_main);
int nHeight = pindex->GetHeight(); int nHeight = pindex->GetHeight();
// Remove the invalidity flag from this block and all its descendants. // Remove the invalidity flag from this block and all its descendants.
BlockMap::iterator it = mapBlockIndex.begin(); BlockMap::iterator it = mapBlockIndex.begin();
while (it != mapBlockIndex.end()) { while (it != mapBlockIndex.end()) {
@@ -4677,7 +4677,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
int32_t i,j,rejects=0,lastrejects=0; int32_t i,j,rejects=0,lastrejects=0;
//fprintf(stderr,"put block's tx into mempool\n"); //fprintf(stderr,"put block's tx into mempool\n");
// Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid.
LOCK(mempool.cs); LOCK2(cs_main,mempool.cs);
//fprintf(stderr, "starting... mempoolsize.%ld\n",mempool.size());
list<CTransaction> transactionsToRemove; list<CTransaction> transactionsToRemove;
BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) {
const CTransaction &tx = e.GetTx(); const CTransaction &tx = e.GetTx();
@@ -4695,10 +4696,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
// CC validation shouldnt (cant) depend on the state of mempool! // CC validation shouldnt (cant) depend on the state of mempool!
while ( 1 ) while ( 1 )
{ {
list<CTransaction> removed;
for (i=0; i<block.vtx.size(); i++) for (i=0; i<block.vtx.size(); i++)
{ {
CValidationState state; CValidationState state;
CTransaction Tx; CTransaction Tx;
const CTransaction &tx = (CTransaction)block.vtx[i]; const CTransaction &tx = (CTransaction)block.vtx[i];
if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0))) if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED && komodo_isPoS((CBlock *)&block) != 0)))
continue; continue;
@@ -4714,7 +4716,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
ptx = &sTx; ptx = &sTx;
} else rejects++; } else rejects++;
} }
// here we remove any txs in the temp mempool that were included in the block.
tmpmempool.remove(tx, removed, false);
} }
//fprintf(stderr, "removed.%ld\n",removed.size());
if ( rejects == 0 || rejects == lastrejects ) if ( rejects == 0 || rejects == lastrejects )
{ {
if ( 0 && lastrejects != 0 ) if ( 0 && lastrejects != 0 )
@@ -4761,29 +4766,15 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C
if ( ASSETCHAINS_CC != 0 ) if ( ASSETCHAINS_CC != 0 )
{ {
// here we add back all txs from the temp mempool to the main mempool. // here we add back all txs from the temp mempool to the main mempool.
// which removes any tx locally that were invalid after the block arrives. BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx)
int numadded,numiters = 0;
CValidationState state; bool fMissingInputs,fOverrideFees = false;
list<CTransaction> removed;
LOCK(mempool.cs);
while ( 1 )
{ {
numiters++; const CTransaction &tx = e.GetTx();
numadded = 0; const uint256 &hash = tx.GetHash();
BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) if ( tx.vjoinsplit.size() == 0 ) {
{ mempool.addUnchecked(hash,e,true);
CTransaction tx = e.GetTx();
if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == true )
{
numadded++;
tmpmempool.remove(tx, removed, false);
}
} }
if ( numadded == 0 )
break;
} }
if ( 0 && numadded > 0 ) //fprintf(stderr, "finished adding back. mempoolsize.%ld\n",mempool.size());
fprintf(stderr, "CC mempool add: numiters.%d numadded.%d remains.%d\n",numiters,numadded,(int32_t)tmpmempool.size());
// empty the temp mempool for next time. // empty the temp mempool for next time.
tmpmempool.clear(); tmpmempool.clear();
} }
@@ -4799,13 +4790,13 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
return true; return true;
assert(pindexPrev); assert(pindexPrev);
int nHeight = pindexPrev->GetHeight()+1; int nHeight = pindexPrev->GetHeight()+1;
// Check proof of work // Check proof of work
if ( (ASSETCHAINS_SYMBOL[0] != 0 || nHeight < 235300 || nHeight > 236000) && block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) if ( (ASSETCHAINS_SYMBOL[0] != 0 || nHeight < 235300 || nHeight > 236000) && block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
{ {
cout << block.nBits << " block.nBits vs. calc " << GetNextWorkRequired(pindexPrev, &block, consensusParams) << cout << block.nBits << " block.nBits vs. calc " << GetNextWorkRequired(pindexPrev, &block, consensusParams) <<
" for block #" << nHeight << endl; " for block #" << nHeight << endl;
return state.DoS(100, error("%s: incorrect proof of work", __func__), return state.DoS(100, error("%s: incorrect proof of work", __func__),
REJECT_INVALID, "bad-diffbits"); REJECT_INVALID, "bad-diffbits");
@@ -4880,7 +4871,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn
// Check that all transactions are finalized // Check that all transactions are finalized
for (uint32_t i = 0; i < block.vtx.size(); i++) { for (uint32_t i = 0; i < block.vtx.size(); i++) {
const CTransaction& tx = block.vtx[i]; const CTransaction& tx = block.vtx[i];
// Check transaction contextually against consensus rules at block height // Check transaction contextually against consensus rules at block height
if (!ContextualCheckTransaction(tx, state, nHeight, 100)) { if (!ContextualCheckTransaction(tx, state, nHeight, 100)) {
return false; // Failure reason has been set in validation state object return false; // Failure reason has been set in validation state object
@@ -5036,7 +5027,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
// regardless of whether pruning is enabled; it should generally be safe to // regardless of whether pruning is enabled; it should generally be safe to
// not process unrequested blocks. // not process unrequested blocks.
bool fTooFarAhead = (pindex->GetHeight() > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP)); bool fTooFarAhead = (pindex->GetHeight() > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP));
// TODO: deal better with return value and error conditions for duplicate // TODO: deal better with return value and error conditions for duplicate
// and unrequested blocks. // and unrequested blocks.
//fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead); //fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead);
@@ -5061,7 +5052,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C
return false; return false;
} }
} }
int nHeight = pindex->GetHeight(); int nHeight = pindex->GetHeight();
// Write block to history file // Write block to history file
try { try {
@@ -5464,7 +5455,7 @@ bool static LoadBlockIndexDB()
return false; return false;
LogPrintf("%s: loaded guts\n", __func__); LogPrintf("%s: loaded guts\n", __func__);
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
// Calculate chainPower // Calculate chainPower
vector<pair<int, CBlockIndex*> > vSortedByHeight; vector<pair<int, CBlockIndex*> > vSortedByHeight;
vSortedByHeight.reserve(mapBlockIndex.size()); vSortedByHeight.reserve(mapBlockIndex.size());
@@ -5722,7 +5713,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
//fprintf(stderr,"end VerifyDB %u\n",(uint32_t)time(NULL)); //fprintf(stderr,"end VerifyDB %u\n",(uint32_t)time(NULL));
if (pindexFailure) if (pindexFailure)
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainActive.Height() - pindexFailure->GetHeight() + 1, nGoodTransactions); return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainActive.Height() - pindexFailure->GetHeight() + 1, nGoodTransactions);
// check level 4: try reconnecting blocks // check level 4: try reconnecting blocks
if (nCheckLevel >= 4) { if (nCheckLevel >= 4) {
CBlockIndex *pindex = pindexState; CBlockIndex *pindex = pindexState;
@@ -5737,9 +5728,9 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->GetHeight(), pindex->GetBlockHash().ToString()); return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->GetHeight(), pindex->GetBlockHash().ToString());
} }
} }
LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->GetHeight(), nGoodTransactions); LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", chainActive.Height() - pindexState->GetHeight(), nGoodTransactions);
return true; return true;
} }
@@ -6581,7 +6572,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
pfrom->fDisconnect = true; pfrom->fDisconnect = true;
return false; return false;
} }
if (!vRecv.empty()) if (!vRecv.empty())
vRecv >> addrFrom >> nNonce; vRecv >> addrFrom >> nNonce;
if (!vRecv.empty()) { if (!vRecv.empty()) {
@@ -6604,7 +6595,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
} }
pfrom->nVersion = nVersion; pfrom->nVersion = nVersion;
pfrom->addrLocal = addrMe; pfrom->addrLocal = addrMe;
if (pfrom->fInbound && addrMe.IsRoutable()) if (pfrom->fInbound && addrMe.IsRoutable())
{ {