From 563329ab204ab8d56842f025c0f1450b4eef8aee Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 22:04:24 -0700 Subject: [PATCH 001/186] Add new test file --- qa/pull-tester/rpc-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 50de39f64..fb4ff99a7 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -11,6 +11,7 @@ export BITCOIND=${REAL_BITCOIND} #Run the tests testScripts=( + 'cryptoconditions.py' 'paymentdisclosure.py' 'prioritisetransaction.py' 'wallet_treestate.py' From 107fe4500ac87aa4809046e5fff2381fcb078976 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 23:52:51 -0700 Subject: [PATCH 002/186] Fix location of kmd binary used in tests --- qa/pull-tester/tests-config.sh.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index cc76e8ad8..8d9467f3f 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -13,6 +13,6 @@ EXEEXT="@EXEEXT@" @ENABLE_ZMQ_TRUE@ENABLE_ZMQ=1 @ENABLE_PROTON_TRUE@ENABLE_PROTON=1 -REAL_BITCOIND="$BUILDDIR/src/zcashd${EXEEXT}" -REAL_BITCOINCLI="$BUILDDIR/src/zcash-cli${EXEEXT}" +REAL_BITCOIND="$BUILDDIR/src/komodod${EXEEXT}" +REAL_BITCOINCLI="$BUILDDIR/src/komodo-cli${EXEEXT}" From 8e5de27a674bfcf27c05ee87488b8e20129055aa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 5 Aug 2018 23:53:07 -0700 Subject: [PATCH 003/186] Fix some compile issues on os x --- configure.ac | 4 ++-- src/txdb.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 7de40ff26..33bcf519f 100644 --- a/configure.ac +++ b/configure.ac @@ -507,8 +507,8 @@ if test x$use_hardening != xno; then if test x$TARGET_OS != xwindows; then # All windows code is PIC, forcing it on just adds useless compile warnings - AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) - AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) + # AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) + # AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)]) AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)]) else diff --git a/src/txdb.cpp b/src/txdb.cpp index edebd4d7c..13d87e2c9 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -430,7 +430,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) }; int64_t startingHeight = chainActive.Height(); - fprintf(stderr, "Starting snapshot at height %li\n", startingHeight); + fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); @@ -487,7 +487,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); + fprintf(stderr, "total=%f, totalAddresses=%lli, utxos=%lli, ignored=%lli\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); for (std::pair element : addressAmounts) { vaddr.push_back( make_pair(element.second, element.first) ); From 752791ae3dc1c0b1c9f6d6c5179acda189d4d5cb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:36:10 -0700 Subject: [PATCH 004/186] Add stub test file for cc tests --- qa/rpc-tests/cryptoconditions.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 qa/rpc-tests/cryptoconditions.py diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py new file mode 100755 index 000000000..80f411303 --- /dev/null +++ b/qa/rpc-tests/cryptoconditions.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 SuperNET developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import assert_equal, assert_greater_than, \ + initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, \ + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds + +import time +from decimal import Decimal + +class WalletTest (BitcoinTestFramework): + + def setup_chain(self): + print("Initializing CC test directory "+self.options.tmpdir) + initialize_chain_clean(self.options.tmpdir, 4) + + def run_test (self): + print "Mining blocks..." + + self.nodes[0].generate(4) + self.sync_all() + + address = self.nodes[0].getnewaddress() + assert_equal(0,42) + +if __name__ == '__main__': + WalletTest ().main () From 3ccd5a79e5060b02985e970732e7228565c85908 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:43:31 -0700 Subject: [PATCH 005/186] Look for the correct config file in our tests --- qa/rpc-tests/test_framework/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index f3ea481ee..d368aa879 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -75,7 +75,7 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) - with open(os.path.join(datadir, "zcash.conf"), 'w') as f: + with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); @@ -144,7 +144,7 @@ def initialize_chain(test_dir): from_dir = os.path.join("cache", "node"+str(i)) to_dir = os.path.join(test_dir, "node"+str(i)) shutil.copytree(from_dir, to_dir) - initialize_datadir(test_dir, i) # Overwrite port/rpcport in zcash.conf + initialize_datadir(test_dir, i) # Overwrite port/rpcport in komodo.conf def initialize_chain_clean(test_dir, num_nodes): """ From 45a4cba477433583dca2a515020e8fd8ea624df4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 00:44:49 -0700 Subject: [PATCH 006/186] fix test docs --- qa/rpc-tests/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/README.md b/qa/rpc-tests/README.md index a0229b56d..17aee1967 100644 --- a/qa/rpc-tests/README.md +++ b/qa/rpc-tests/README.md @@ -18,9 +18,9 @@ Possible options: ``` -h, --help show this help message and exit - --nocleanup Leave bitcoinds and test.* datadir on exit or error - --noshutdown Don't stop bitcoinds after the test execution - --srcdir=SRCDIR Source directory containing bitcoind/bitcoin-cli (default: + --nocleanup Leave komodods and test.* datadir on exit or error + --noshutdown Don't stop komodods after the test execution + --srcdir=SRCDIR Source directory containing komodod/komodo-cli (default: ../../src) --tmpdir=TMPDIR Root directory for datadirs --tracerpc Print out all RPC calls as they are made @@ -31,7 +31,7 @@ If you set the environment variable `PYTHON_DEBUG=1` you will get some debug out A 200-block -regtest blockchain and wallets for four nodes is created the first time a regression test is run and is stored in the cache/ directory. Each node has the miner -subsidy from 25 mature blocks (25*10=250 ZEC) in its wallet. +subsidy from 25 mature blocks (25*10=250 KMD) in its wallet. After the first run, the cache/ blockchain and wallets are copied into a temporary directory and used as the initial @@ -42,5 +42,5 @@ to recover with: ```bash rm -rf cache -killall zcashd +killall komodod ``` From f4cdde0e85683eada52704d0f292dad4ae90fd50 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 08:09:15 -0700 Subject: [PATCH 007/186] Enable txindex in regtest komodo.confs and update binary in initialize_chain --- qa/rpc-tests/test_framework/util.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index d368aa879..8619ea44c 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -77,36 +77,41 @@ def initialize_datadir(dirname, n): os.makedirs(datadir) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); + f.write("txindex=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); f.write("port="+str(p2p_port(n))+"\n"); f.write("rpcport="+str(rpc_port(n))+"\n"); f.write("listenonion=0\n"); + # TODO: maybe make these optional, defaulted to on for now + f.write("addressindex=1\n"); + f.write("spentindex=1\n"); + f.write("timestampindex=1\n"); return datadir def initialize_chain(test_dir): """ Create (or copy from cache) a 200-block-long chain and 4 wallets. - bitcoind and bitcoin-cli must be in search path. + komodod and komodo-cli must be in search path. """ if not os.path.isdir(os.path.join("cache", "node0")): devnull = open("/dev/null", "w+") - # Create cache directories, run bitcoinds: + # Create cache directories, run komodods: for i in range(4): datadir=initialize_datadir("cache", i) - args = [ os.getenv("BITCOIND", "bitcoind"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] + args = [ os.getenv("BITCOIND", "komodod"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir, + print "initialize_chain: komodod started, calling komodo-cli -rpcwait getblockcount" + subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: bitcoin-cli -rpcwait getblockcount completed" + print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() rpcs = [] for i in range(4): From 6358342934b443f47d9bd8fffcbfc7beaaa9a1e1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 10:59:33 -0700 Subject: [PATCH 008/186] debug valid pubkey error --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 295460618..5dbd374d6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4836,7 +4836,7 @@ int32_t ensure_CCrequirements() if ( NOTARY_PUBKEY33[0] == 0 ) return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) - return(-1); + return(-2); else return(0); } @@ -4923,11 +4923,13 @@ UniValue diceaddress(const UniValue& params, bool fHelp) UniValue faucetaddress(const UniValue& params, bool fHelp) { struct CCcontract_info *cp,C; std::vector pubkey; + int errno; cp = CCinit(&C,EVAL_FAUCET); if ( fHelp || params.size() > 1 ) throw runtime_error("faucetaddress [pubkey]\n"); - if ( ensure_CCrequirements() < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + errno = ensure_CCrequirements(); + if ( errno < 0 ) + throw runtime_error(strprintf("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet. ERR=%d\n", errno)); if ( params.size() == 1 ) pubkey = ParseHex(params[0].get_str().c_str()); return(CCaddress(cp,(char *)"Faucet",pubkey)); From 25709e30789b62b55dc8a8f13dd10d7db61abafd Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 22:50:38 +0200 Subject: [PATCH 009/186] These %lli/%li formats are platform-dependent --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 13d87e2c9..af5927043 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -430,7 +430,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) }; int64_t startingHeight = chainActive.Height(); - fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); + //fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); @@ -487,7 +487,7 @@ extern UniValue CBlockTreeDB::Snapshot(int top) } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%lli, utxos=%lli, ignored=%lli\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); + //fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); for (std::pair element : addressAmounts) { vaddr.push_back( make_pair(element.second, element.first) ); From 467e1047aaf558370b165bd8848cca1f02fc378b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 6 Aug 2018 23:00:47 +0200 Subject: [PATCH 010/186] Optimize our cc python test; only start 1 node for now --- qa/rpc-tests/cryptoconditions.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 80f411303..a0f4fe0a8 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -12,20 +12,30 @@ from test_framework.util import assert_equal, assert_greater_than, \ import time from decimal import Decimal -class WalletTest (BitcoinTestFramework): +class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): print("Initializing CC test directory "+self.options.tmpdir) initialize_chain_clean(self.options.tmpdir, 4) + def setup_nodes(self): + return start_nodes(1, self.options.tmpdir) + + def setup_network(self, split=False): + self.nodes = start_nodes(1, self.options.tmpdir) + self.is_network_split=False + self.sync_all() + def run_test (self): print "Mining blocks..." - self.nodes[0].generate(4) + rpc = self.nodes[0] + rpc.generate(4) self.sync_all() - address = self.nodes[0].getnewaddress() - assert_equal(0,42) + faucet = rpc.faucetaddress() + assert_equal(faucet['result'], 'success') + assert_equal(faucet['myaddress'][0], 'R') if __name__ == '__main__': - WalletTest ().main () + CryptoConditionsTest ().main () From 32829f6d6fc8d559ebff5493278381295416d894 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 08:13:18 +0200 Subject: [PATCH 011/186] Fix various test suite bugs and create CC AC in our tests --- qa/rpc-tests/cryptoconditions.py | 33 +++++++++++++++++++++-------- qa/rpc-tests/test_framework/util.py | 14 ++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index a0f4fe0a8..0fc162c75 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -16,23 +16,38 @@ class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): print("Initializing CC test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + self.num_nodes = 1 + initialize_chain_clean(self.options.tmpdir, self.num_nodes) - def setup_nodes(self): - return start_nodes(1, self.options.tmpdir) - - def setup_network(self, split=False): - self.nodes = start_nodes(1, self.options.tmpdir) - self.is_network_split=False + def setup_network(self, split = False): + print("Setting up network...") + self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, + extra_args=[[ + '-ac_name=REGTEST', + '-addressindex=1', + '-spentindex=1', + '-ac_supply=5555555', + '-ac_reward=10000000', + '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', + '-ac_cc=1' + ]] * self.num_nodes + ) + self.is_network_split = split self.sync_all() def run_test (self): - print "Mining blocks..." - + print("Mining blocks...") rpc = self.nodes[0] rpc.generate(4) self.sync_all() + # this corresponds to -pubkey above + print("Importking pubkey") + rpc.importprivkey(privkey) + validate = rpc.validateaddress(self.pubkey) + # Begin actual CC tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') assert_equal(faucet['myaddress'][0], 'R') diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 8619ea44c..fc0a04bf2 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -1,4 +1,5 @@ # Copyright (c) 2014 The Bitcoin Core developers +# Copyright (c) 2018 The SuperNET developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -78,6 +79,7 @@ def initialize_datadir(dirname, n): with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("txindex=1\n"); + f.write("server=1\n"); f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); @@ -182,22 +184,22 @@ def _rpchost_to_args(rpchost): def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary=None): """ - Start a bitcoind and return RPC connection to it + Start a komodod and return RPC connection to it """ datadir = os.path.join(dirname, "node"+str(i)) if binary is None: - binary = os.getenv("BITCOIND", "bitcoind") + binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") if os.getenv("PYTHON_DEBUG", ""): - print "start_node: bitcoind started, calling bitcoin-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "bitcoin-cli"), "-datadir="+datadir] + + print "start_node: komodod started, calling komodo-cli -rpcwait getblockcount" + subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): - print "start_node: calling bitcoin-cli -rpcwait getblockcount returned" + print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) if timewait is not None: @@ -209,7 +211,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= def start_nodes(num_nodes, dirname, extra_args=None, rpchost=None, binary=None): """ - Start multiple bitcoinds, return RPC connections to them + Start multiple komodods, return RPC connections to them """ if extra_args is None: extra_args = [ None for i in range(num_nodes) ] if binary is None: binary = [ None for i in range(num_nodes) ] From 5ec4373ca4e54b98435a9ee329e047a46239769d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 09:22:40 +0200 Subject: [PATCH 012/186] More debugging trying to make getblockcount work and not have komodod hang the test --- qa/rpc-tests/cryptoconditions.py | 8 ++++++-- qa/rpc-tests/test_framework/util.py | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 0fc162c75..7e1810085 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -7,7 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, \ - stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port import time from decimal import Decimal @@ -24,7 +24,11 @@ class CryptoConditionsTest (BitcoinTestFramework): self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, - extra_args=[[ + extra_args=[[ + '-regtest', + '-server=1', + '-rpcport=64368', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', '-ac_name=REGTEST', '-addressindex=1', '-spentindex=1', diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index fc0a04bf2..146499d08 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -76,6 +76,7 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) + print("Writing to " + os.path.join(datadir,"komodo.conf")) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); f.write("txindex=1\n"); @@ -84,7 +85,9 @@ def initialize_datadir(dirname, n): f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); f.write("port="+str(p2p_port(n))+"\n"); - f.write("rpcport="+str(rpc_port(n))+"\n"); + rpcport = str(rpc_port(n)) + f.write("rpcport="+rpcport+"\n"); + print "RPC port=" + rpcport f.write("listenonion=0\n"); # TODO: maybe make these optional, defaulted to on for now f.write("addressindex=1\n"); @@ -108,10 +111,12 @@ def initialize_chain(test_dir): if i > 0: args.append("-connect=127.0.0.1:"+str(p2p_port(0))) bitcoind_processes[i] = subprocess.Popen(args) + cmd = os.getenv("BITCOINCLI", "komodo-cli") + cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): - print "initialize_chain: komodod started, calling komodo-cli -rpcwait getblockcount" - subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir, - "-rpcwait", "getblockcount"], stdout=devnull) + print "initialize_chain: komodod started, calling: " + cmd_args + subprocess.check_call([ cmd, "-datadir="+datadir, + "-rpcwait", "getblockcount"]) #, stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() @@ -193,8 +198,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") + cmd = os.getenv("BITCOINCLI", "komodo-cli") + cmd_args = cmd + "-datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): - print "start_node: komodod started, calling komodo-cli -rpcwait getblockcount" + print "start_node: komodod started, calling : " + cmd_args subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + _rpchost_to_args(rpchost) + ["-rpcwait", "getblockcount"], stdout=devnull) From d587c96cfc9aaf92c853ffda2c31b8ad509340f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Aug 2018 04:46:54 -1100 Subject: [PATCH 013/186] Minimum rewardsfunding --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index afa025851..d9de1ebdb 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -412,7 +412,7 @@ UniValue RewardsList() std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t APR,int64_t minseconds,int64_t maxseconds,int64_t mindeposit) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,a,b,c,d; struct CCcontract_info *cp,C; - if ( funds < 0 || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) + if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); return(0); From 626af0e73e29b97a246b11880df39628e529ff3c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:13:32 +0200 Subject: [PATCH 014/186] Getting closer, invalid rpc user/pass instead of wrong port --- qa/rpc-tests/cryptoconditions.py | 10 ++++++--- qa/rpc-tests/test_framework/util.py | 32 +++++++++++++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7e1810085..c9778fd3e 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -26,20 +26,24 @@ class CryptoConditionsTest (BitcoinTestFramework): self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-regtest', - '-server=1', - '-rpcport=64368', + # TODO: AC.conf instead of komodo.conf + #'-conf='+self.options.tmpdir+'/node0/komodo.conf', '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-port=64367', + '-rpcport=64368', '-ac_name=REGTEST', '-addressindex=1', '-spentindex=1', '-ac_supply=5555555', '-ac_reward=10000000', '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', - '-ac_cc=1' + '-ac_cc=1', + '-daemon', ]] * self.num_nodes ) self.is_network_split = split self.sync_all() + print("Done setting up network") def run_test (self): print("Mining blocks...") diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 146499d08..16f9e813f 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -84,10 +84,10 @@ def initialize_datadir(dirname, n): f.write("showmetrics=0\n"); f.write("rpcuser=rt\n"); f.write("rpcpassword=rt\n"); - f.write("port="+str(p2p_port(n))+"\n"); - rpcport = str(rpc_port(n)) - f.write("rpcport="+rpcport+"\n"); - print "RPC port=" + rpcport + #f.write("port="+str(p2p_port(n))+"\n"); + #rpcport = str(rpc_port(n)) + #f.write("rpcport="+rpcport+"\n"); + #print "RPC port=" + rpcport f.write("listenonion=0\n"); # TODO: maybe make these optional, defaulted to on for now f.write("addressindex=1\n"); @@ -115,8 +115,11 @@ def initialize_chain(test_dir): cmd_args = cmd + " -datadir="+datadir + " -rpcwait getblockcount" if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodod started, calling: " + cmd_args - subprocess.check_call([ cmd, "-datadir="+datadir, - "-rpcwait", "getblockcount"]) #, stdout=devnull) + strcmd = cmd + " " + "-datadir="+datadir + " -rpcwait getblockcount" + + print("Running " + strcmd) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ cmd, "-rpcwait", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "initialize_chain: komodo-cli -rpcwait getblockcount completed" devnull.close() @@ -198,13 +201,20 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if extra_args is not None: args.extend(extra_args) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") + cmd = os.getenv("BITCOINCLI", "komodo-cli") - cmd_args = cmd + "-datadir="+datadir + " -rpcwait getblockcount" + print("cmd=" + cmd) + #TODO: + cmd_args = " -datadir="+datadir + " -rpcport=64368 -rpcwait -conf=" +datadir+"/komodo.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): - print "start_node: komodod started, calling : " + cmd_args - subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + - _rpchost_to_args(rpchost) + - ["-rpcwait", "getblockcount"], stdout=devnull) + print "start_node: komodod started, calling : " + cmd + " " + cmd_args + strcmd = cmd + " " + cmd_args + + print("Running " + strcmd) + subprocess.check_call(strcmd, shell=True); + #subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + + # _rpchost_to_args(rpchost) + + # ["-rpcwait", "-rpcport=6438", "getblockcount"], stdout=devnull) if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() From 3528faa71183c1002031e26cc4037f8ebbab071d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:51:12 +0200 Subject: [PATCH 015/186] Use correct rpc user/pass; this only works the second time its run, some kind of timing/caching issue --- qa/rpc-tests/cryptoconditions.py | 14 +++++++++----- qa/rpc-tests/test_framework/util.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index c9778fd3e..7dc8c2d07 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -25,10 +25,10 @@ class CryptoConditionsTest (BitcoinTestFramework): self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ - '-regtest', + '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', # TODO: AC.conf instead of komodo.conf #'-conf='+self.options.tmpdir+'/node0/komodo.conf', - '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', + '-regtest', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', @@ -38,8 +38,12 @@ class CryptoConditionsTest (BitcoinTestFramework): '-ac_reward=10000000', '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', '-ac_cc=1', + '-whitelist=127.0.0.1', + '-debug', '-daemon', - ]] * self.num_nodes + '-rpcuser=rt', + '-rpcpassword=rt' + ]] ) self.is_network_split = split self.sync_all() @@ -51,8 +55,8 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(4) self.sync_all() # this corresponds to -pubkey above - print("Importking pubkey") - rpc.importprivkey(privkey) + print("Importing privkey") + rpc.importprivkey(self.privkey) validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 16f9e813f..81a9b4633 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -76,6 +76,8 @@ def initialize_datadir(dirname, n): datadir = os.path.join(dirname, "node"+str(n)) if not os.path.isdir(datadir): os.makedirs(datadir) + # kmd AC's don't use this, they use the conf auto-created when the AC is created + # plus CLI arguments. This is for komodod tests print("Writing to " + os.path.join(datadir,"komodo.conf")) with open(os.path.join(datadir, "komodo.conf"), 'w') as f: f.write("regtest=1\n"); @@ -102,6 +104,7 @@ def initialize_chain(test_dir): komodod and komodo-cli must be in search path. """ + print("initialize_chain") if not os.path.isdir(os.path.join("cache", "node0")): devnull = open("/dev/null", "w+") # Create cache directories, run komodods: @@ -199,13 +202,14 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) + print("args=" + ' '.join(args)) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) - #TODO: - cmd_args = " -datadir="+datadir + " -rpcport=64368 -rpcwait -conf=" +datadir+"/komodo.conf getblockcount " + #TODO: this will only work on the regtest AC, and probably breaks non-CC tests + cmd_args = " -datadir="+datadir + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args @@ -218,11 +222,14 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() - url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + print("connecting to " + url) if timewait is not None: proxy = AuthServiceProxy(url, timeout=timewait) else: proxy = AuthServiceProxy(url) + print("created proxy") proxy.url = url # store URL on proxy for info return proxy From 38a2d0c825077c815d4c92775ce4d7552ed1076d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 20:57:42 +0200 Subject: [PATCH 016/186] Pass along extra_args correctly to get correct rpc user/pass --- qa/rpc-tests/test_framework/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 81a9b4633..249d2d0ba 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -209,7 +209,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) #TODO: this will only work on the regtest AC, and probably breaks non-CC tests - cmd_args = " -datadir="+datadir + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " + cmd_args = ' '.join(extra_args) + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args From eb8f0960e1a9ea02ca2d373438d0851497882bd7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:23:05 +0200 Subject: [PATCH 017/186] Fix some docs and references to bitcoind --- qa/rpc-tests/test_framework/test_framework.py | 12 ++++++------ qa/rpc-tests/test_framework/util.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 56151bb3e..0d5fe5244 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -90,11 +90,11 @@ class BitcoinTestFramework(object): parser = optparse.OptionParser(usage="%prog [options]") parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", - help="Leave bitcoinds and test.* datadir on exit or error") + help="Leave komodods and test.* datadir on exit or error") parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true", - help="Don't stop bitcoinds after the test execution") + help="Don't stop komodods after the test execution") parser.add_option("--srcdir", dest="srcdir", default="../../src", - help="Source directory containing bitcoind/bitcoin-cli (default: %default)") + help="Source directory containing komodod/komodo-cli (default: %default)") parser.add_option("--tmpdir", dest="tmpdir", default=tempfile.mkdtemp(prefix="test"), help="Root directory for datadirs") parser.add_option("--tracerpc", dest="trace_rpc", default=False, action="store_true", @@ -137,7 +137,7 @@ class BitcoinTestFramework(object): stop_nodes(self.nodes) wait_bitcoinds() else: - print("Note: bitcoinds were not stopped and may still be running") + print("Note: komodods were not stopped and may still be running") if not self.options.nocleanup and not self.options.noshutdown: print("Cleaning up") @@ -165,10 +165,10 @@ class ComparisonTestFramework(BitcoinTestFramework): def add_options(self, parser): parser.add_option("--testbinary", dest="testbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to test") parser.add_option("--refbinary", dest="refbinary", - default=os.getenv("BITCOIND", "bitcoind"), + default=os.getenv("BITCOIND", "komodod"), help="bitcoind binary to use for reference nodes (if any)") def setup_chain(self): diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 249d2d0ba..2e349794b 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -202,7 +202,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= binary = os.getenv("BITCOIND", "komodod") args = [ binary, "-datadir="+datadir, "-keypool=1", "-discover=0", "-rest" ] if extra_args is not None: args.extend(extra_args) - print("args=" + ' '.join(args)) + #print("args=" + ' '.join(args)) bitcoind_processes[i] = subprocess.Popen(args) devnull = open("/dev/null", "w+") From dcc6cdb0830f71bbb7feef98fbc1a24f9efbccf1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:24:33 +0200 Subject: [PATCH 018/186] Remove reference to REGTEST.conf in start_node which all tests use, not just CC tests. it is passed via extra_args --- qa/rpc-tests/test_framework/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 2e349794b..1080f32f1 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -209,7 +209,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) #TODO: this will only work on the regtest AC, and probably breaks non-CC tests - cmd_args = ' '.join(extra_args) + " -rpcwait -conf=" +datadir+"/REGTEST.conf getblockcount " + cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args strcmd = cmd + " " + cmd_args From 8d454fb58e459b28f296ab46c8b0e4e7ea07a096 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:32:56 +0200 Subject: [PATCH 019/186] Sleep a bit to give time for regtest komodod to start --- qa/rpc-tests/test_framework/util.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 1080f32f1..2c63a9b23 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -215,6 +215,8 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= strcmd = cmd + " " + cmd_args print("Running " + strcmd) + import time + time.sleep(2) subprocess.check_call(strcmd, shell=True); #subprocess.check_call([ os.getenv("BITCOINCLI", "komodo-cli"), "-datadir="+datadir] + # _rpchost_to_args(rpchost) + From d48c67574f00cbb6b79bcdc02d392eabd052d7f0 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:45:32 +0200 Subject: [PATCH 020/186] Improve faucetaddress tests --- qa/rpc-tests/cryptoconditions.py | 5 ++++- qa/rpc-tests/test_framework/util.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7dc8c2d07..24bd2925b 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -62,7 +62,10 @@ class CryptoConditionsTest (BitcoinTestFramework): # Begin actual CC tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') - assert_equal(faucet['myaddress'][0], 'R') + # verify all keys look like valid AC addrs, could be better + for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: + assert_equal(faucet[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 2c63a9b23..856ae5a05 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -208,7 +208,6 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= cmd = os.getenv("BITCOINCLI", "komodo-cli") print("cmd=" + cmd) - #TODO: this will only work on the regtest AC, and probably breaks non-CC tests cmd_args = ' '.join(extra_args) + " -rpcwait getblockcount " if os.getenv("PYTHON_DEBUG", ""): print "start_node: komodod started, calling : " + cmd + " " + cmd_args @@ -225,6 +224,7 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) + #TODO: this breaks non CC tests url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) print("connecting to " + url) if timewait is not None: From 380bcb10ba6ac2436238175fe83da281d75227f3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 21:50:54 +0200 Subject: [PATCH 021/186] Add some dice tests --- qa/rpc-tests/cryptoconditions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 24bd2925b..7fb4eb47e 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -60,12 +60,20 @@ class CryptoConditionsTest (BitcoinTestFramework): validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests + + # Faucet tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') # verify all keys look like valid AC addrs, could be better for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + # Dice tests + dice = rpc.diceaddress() + assert_equal(dice['result'], 'success') + for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: + assert_equal(dice[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 7b6e9bf0695f5cf6d39bd113c54aac051b69eab2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Aug 2018 23:34:50 +0200 Subject: [PATCH 022/186] More faucet and token tests --- qa/rpc-tests/cryptoconditions.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 7fb4eb47e..a9c54d09b 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -21,7 +21,8 @@ class CryptoConditionsTest (BitcoinTestFramework): def setup_network(self, split = False): print("Setting up network...") - self.pubkey = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.addr = "RWPg8B91kfK5UtUN7z6s6TeV9cHSGtVY8D" + self.pubkey = "02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf" self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ @@ -36,7 +37,7 @@ class CryptoConditionsTest (BitcoinTestFramework): '-spentindex=1', '-ac_supply=5555555', '-ac_reward=10000000', - '-pubkey=02676d00110c2cd14ae24f95969e8598f7ccfaa675498b82654a5b5bd57fc1d8cf', + '-pubkey=' + self.pubkey, '-ac_cc=1', '-whitelist=127.0.0.1', '-debug', @@ -52,12 +53,11 @@ class CryptoConditionsTest (BitcoinTestFramework): def run_test (self): print("Mining blocks...") rpc = self.nodes[0] - rpc.generate(4) + rpc.generate(1) self.sync_all() # this corresponds to -pubkey above print("Importing privkey") rpc.importprivkey(self.privkey) - validate = rpc.validateaddress(self.pubkey) # Begin actual CC tests @@ -68,12 +68,29 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + result = rpc.faucetinfo() + assert_equal(result['result'], 'success') + + # fails + #result = rpc.faucetfund(1) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') + # Token tests + result = rpc.tokenaddress() + assert_equal(result['result'], 'success') + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.tokenaddress(self.pubkey) + assert_equal(result['result'], 'success') + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 8567b4386b8fa73818f7538b601f536672034aee Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 07:25:52 +0200 Subject: [PATCH 023/186] Add a test for tokenlist --- qa/rpc-tests/cryptoconditions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index a9c54d09b..e19bb6b23 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -91,6 +91,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: assert_equal(result[x][0], 'R') + # fails if no funds? + # result = rpc.tokencreate("DUKE", 0.10, "duke") + # assert_equal(result['result'], 'success') + + result = rpc.tokenlist() + assert_equal(result, []) + if __name__ == '__main__': CryptoConditionsTest ().main () From 776fb6cd6249dc07de77f1d55e7525448a2b8bfa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 09:11:33 +0200 Subject: [PATCH 024/186] Add tests for tokenorders and tokenbalance --- qa/rpc-tests/cryptoconditions.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index e19bb6b23..347f6ae2f 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -95,9 +95,20 @@ class CryptoConditionsTest (BitcoinTestFramework): # result = rpc.tokencreate("DUKE", 0.10, "duke") # assert_equal(result['result'], 'success') + # there are no tokens created yet result = rpc.tokenlist() assert_equal(result, []) + # there are no token orders yet + result = rpc.tokenorders() + assert_equal(result, []) + + result = rpc.tokenbalance(self.pubkey) + assert_equal(result['balance'], 0) + assert_equal(result['result'], 'success') + assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') + assert_equal(result['tokenid'], self.pubkey) + if __name__ == '__main__': CryptoConditionsTest ().main () From 77373514f575e8592b9af24fbc87da35b46f09c8 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 8 Aug 2018 09:25:47 +0200 Subject: [PATCH 025/186] Add dicelist test; dicefund/tokeninfo tests need to be funded to work correctly --- qa/rpc-tests/cryptoconditions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 347f6ae2f..8be0a69bf 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -80,6 +80,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: assert_equal(dice[x][0], 'R') + # no dice created yet + result = rpc.dicelist() + assert_equal(result, []) + + #result = rpc.dicefund("LUCKY",10000,1,10000,10,5) + #assert_equal(result, []) + # Token tests result = rpc.tokenaddress() assert_equal(result['result'], 'success') @@ -109,6 +116,8 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) + #result = rpc.tokeninfo(self.pubkey) + if __name__ == '__main__': CryptoConditionsTest ().main () From 112803d8e12488edc9f7b3fc59b0843c1487b66b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 7 Aug 2018 21:25:51 -1100 Subject: [PATCH 026/186] Require sbits/fundingtxid matches for rewards vins --- src/cc/rewards.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d9de1ebdb..6c5975e51 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -137,18 +137,23 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { - char destaddr[64]; - if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) + char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; + if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); + txid = tx.GetHash(); + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid)) != 0 && sbits == refsbits && (fundingtxid == reffundingtxid || txid == reffundingtxid) ) + { + + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + return(tx.vout[v].nValue); + } } return(0); } -bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee) +bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; @@ -164,7 +169,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio { if ( hashBlock == zerohash ) return eval->Invalid("cant rewards from mempool"); - if ( (assetoshis= IsRewardsvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + if ( (assetoshis= IsRewardsvout(cp,vinTx,tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) inputs += assetoshis; } } @@ -172,7 +177,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio for (i=0; iismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue) == 0 ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); @@ -264,7 +269,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } // 'L' vs 'F' and 'A' -uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) +uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -286,6 +291,8 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr { if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) { + if ( sbits != refsbits || fundingtxid != reffundingtxid ) + continue; fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( fundsflag != 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; @@ -323,7 +330,7 @@ uint64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey p { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsRewardsvout(cp,tx,vout)) > 0 ) + if ( refsbits == sbits && (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) totalinputs += nValue; else fprintf(stderr,"refsbits.%llx sbits.%llx nValue %.8f\n",(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case\n"); @@ -520,7 +527,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); if ( locktxid == zeroid ) - amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1); + amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); else { GetCCaddress(cp,coinaddr,rewardspk); @@ -542,7 +549,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) { - if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); From aca80695b1aee53138edd62e5db438838b5d687c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 00:10:51 -1100 Subject: [PATCH 027/186] -print --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index e89dea2e4..dff8b5ab6 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -427,7 +427,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(opretbuf,1,olen,fp) != olen ) errs++; -printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); +//printf("create ht.%d R opret[%d] sp.%p\n",height,olen,sp); //komodo_opreturn(height,opretvalue,opretbuf,olen,txhash,vout); komodo_eventadd_opreturn(sp,symbol,height,txhash,opretvalue,vout,opretbuf,olen); } From 84b0bd5230705641c292d740a5ca46726f4129fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 10:40:25 -1100 Subject: [PATCH 028/186] Dont count PoW diff blocks for isPoS count --- src/komodo_bitcoind.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 89e79ccbd..372317050 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1411,7 +1411,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he return(bnTarget); } -int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) +int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) @@ -1448,7 +1448,17 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 1; // close enough for a pre-filter //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ - } //else return(-1); + } + if ( slowflag != 0 && isPoS != 0 ) + { + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( bhash < bnTarget ) + { + fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + isPoS = 0; + } + } + //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); return(isPoS); @@ -1528,7 +1538,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { - if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) + if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) { if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! POSTEST64 return(-1); From 83f41bb0f9db920487167bd6401eb512114b5273 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 10:41:26 -1100 Subject: [PATCH 029/186] PoSperc --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 372317050..fc405d432 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1413,7 +1413,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); txn_count = pblock->vtx.size(); From 1399f859e0dab9bcd55b64c3d0a7b69dcc534bf2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 08:53:24 +0200 Subject: [PATCH 030/186] Mine more blocks to ensure a mature balance --- qa/rpc-tests/cryptoconditions.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 8be0a69bf..2784a5823 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -53,12 +53,20 @@ class CryptoConditionsTest (BitcoinTestFramework): def run_test (self): print("Mining blocks...") rpc = self.nodes[0] - rpc.generate(1) + + # utxos from block 1 become mature in block 101 + rpc.generate(101) self.sync_all() + # this corresponds to -pubkey above print("Importing privkey") rpc.importprivkey(self.privkey) + result = rpc.getwalletinfo() + # basic sanity tests + assert_equal(result['txcount'], 101) + assert_greater_than(result['balance'], 0.0) + # Begin actual CC tests # Faucet tests @@ -72,7 +80,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') # fails - #result = rpc.faucetfund(1) + #result = rpc.faucetfund(-1.0) # Dice tests dice = rpc.diceaddress() From 11b390d86cb51b03a20daf987f626aac82459245 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 22:59:21 -1100 Subject: [PATCH 031/186] Catch mined PoS lookalike blocks --- src/komodo_bitcoind.h | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fc405d432..87bb19807 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1434,25 +1434,17 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); - } else isPoS = 1; + } else isPoS = 2; } - if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx + if ( slowflag == 0 && isPoS == 0 ) // maybe previous block is not seen yet, do the best approx { if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; - /*txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) - { - strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) - isPoS = 1; // close enough for a pre-filter - //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); - } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ } if ( slowflag != 0 && isPoS != 0 ) { bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash < bnTarget ) + if ( bhash < bnTarget || isPoS != 2 ) { fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); isPoS = 0; @@ -1461,7 +1453,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); - return(isPoS); + return(isPoS != 0); } int64_t komodo_checkcommission(CBlock *pblock,int32_t height) From efb8981cb9d9ff63e3aa499ae4bc26652af319ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 23:41:59 -1100 Subject: [PATCH 032/186] Segid cache --- src/chain.h | 3 ++- src/komodo_bitcoind.h | 44 ++++++++++++++++++++++++++++++++++++++----- src/main.cpp | 4 ++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/chain.h b/src/chain.h index d882083e6..394b4a6bd 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - int64_t newcoins,zfunds; + int64_t newcoins,zfunds; int8_t segid; // jl777 fields //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -182,6 +182,7 @@ public: { phashBlock = NULL; newcoins = zfunds = 0; + segid = -2; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 87bb19807..96c76245f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,6 +1140,8 @@ int8_t komodo_segid(int32_t height) CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { + if ( pindex->segid >= -1 ) + return(pindex->segid); if ( komodo_blockload(block,pindex) == 0 ) { txn_count = block.vtx.size(); @@ -1413,9 +1415,15 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); + if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) + { + if ( pindex->segid == -1 ) + return(0); + else return(1); + } txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { @@ -1429,12 +1437,28 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( prevtime != 0 ) { if ( komodo_isPoS(pblock) != 0 ) + { eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); + } if ( eligible == 0 || eligible > pblock->nTime ) { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); - } else isPoS = 2; + if ( slowflag != 0 && pindex != 0 ) + pindex->segid = -1; + } + else + { + isPoS = 2; // 2 means staking utxo validated + if ( slowflag != 0 ) + { + if ( pindex != 0 && height > 100 ) + { + if ( pindex->segid == -2 ) + pindex->segid = komodo_segid(height); + } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); + } + } } if ( slowflag == 0 && isPoS == 0 ) // maybe previous block is not seen yet, do the best approx { @@ -1443,12 +1467,20 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag != 0 && isPoS != 0 ) { - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash < bnTarget || isPoS != 2 ) + if ( isPoS != 2 ) { - fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + fprintf(stderr,"ht.%d isPoS.%d utxo not validated -> must be PoW fake\n",height,isPoS); isPoS = 0; } + else + { + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + if ( bhash < bnTarget ) + { + fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + isPoS = 0; + } + } } //else return(-1); } @@ -1484,6 +1516,8 @@ bool KOMODO_TEST_ASSETCHAIN_SKIP_POW = 0; int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW == 0 && Params().NetworkIDString() == "regtest" ) + KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); diff --git a/src/main.cpp b/src/main.cpp index b42f85ce7..6dcd6b13b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3368,6 +3368,10 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(view.Flush()); DisconnectNotarisations(block); } + pindexDelete->segid = -2; + pindexDelete->newcoins = 0; + pindexDelete->zfunds = 0; + LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor(); // Write the chain state to disk, if necessary. From b70126d400c0967d4bd1ab315006ea176d52c13b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 8 Aug 2018 23:48:23 -1100 Subject: [PATCH 033/186] Add no cache flag and calculate entropy based on raw segued --- src/komodo_bitcoind.h | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 96c76245f..eee9a5067 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1135,12 +1135,12 @@ uint32_t komodo_segid32(char *coinaddr) return(addrhash.uints[0]); } -int8_t komodo_segid(int32_t height) +int8_t komodo_segid(int32_t nocache,int32_t height) { CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { - if ( pindex->segid >= -1 ) + if ( nocache == 0 && pindex->segid >= -1 ) return(pindex->segid); if ( komodo_blockload(block,pindex) == 0 ) { @@ -1175,7 +1175,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) memset(hashbuf,0xff,n); for (i=0; i prevtime+480 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); - //if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) - // coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - //if ( nHeight >= 900 && nHeight < 916 ) - // hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { winner = 1; @@ -1310,7 +1299,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(ht) >= 0 ) + if ( komodo_segid(0,ht) >= 0 ) { n++; percPoS++; @@ -1455,7 +1444,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex != 0 && height > 100 ) { if ( pindex->segid == -2 ) - pindex->segid = komodo_segid(height); + pindex->segid = komodo_segid(1,height); } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From a3b5f801ca81f19eec04b4f3a58a8c695a28f9ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 00:14:35 -1100 Subject: [PATCH 034/186] Update comments --- src/komodo_bitcoind.h | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eee9a5067..3e3257f08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1105,7 +1105,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ -//#define KOMODO_POWMINMULT 16 uint64_t komodo_commission(const CBlock *pblock) { @@ -1299,7 +1298,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(0,ht) >= 0 ) + if ( komodo_segid(0,ht) >= 0 ) // if using segid cache is unstable consensus, need to directly call komodo_stake() here { n++; percPoS++; @@ -1314,26 +1313,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he m++; } } - /*if ( (pindex= komodo_chainactive(ht)) != 0 ) - { - bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); - hashval = UintToArith256(pindex->GetBlockHash()); - if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW - { - if ( ASSETCHAINS_STAKED < 100 ) - fprintf(stderr,"1"); - sum += hashval; - n++; - } - else - { - n++; - percPoS++; - if ( ASSETCHAINS_STAKED < 100 ) - fprintf(stderr,"0"); - } - }*/ if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } @@ -1342,7 +1321,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; - //target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( m > 0 ) { ave = (sum / arith_uint256(m)); @@ -1547,7 +1525,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget + if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); } } From c6d212db1c1cc67d800591e45f81de6b29524e65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:31:27 -1100 Subject: [PATCH 035/186] Test --- src/komodo_bitcoind.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3e3257f08..eba33c301 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1298,7 +1298,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { - if ( komodo_segid(0,ht) >= 0 ) // if using segid cache is unstable consensus, need to directly call komodo_stake() here + if ( komodo_segid(0,ht) >= 0 ) { n++; percPoS++; @@ -1422,7 +1422,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex != 0 && height > 100 ) { if ( pindex->segid == -2 ) + { pindex->segid = komodo_segid(1,height); + fprintf(stderr,"set segid.%d <- %d\n",pindex->segid); + } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From 5d3f12159d351366fa2a991653534405d2b27260 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:32:34 -1100 Subject: [PATCH 036/186] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eba33c301..de1b3352e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,7 +1424,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex->segid == -2 ) { pindex->segid = komodo_segid(1,height); - fprintf(stderr,"set segid.%d <- %d\n",pindex->segid); + fprintf(stderr,"set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } From 549ca5a62592b85797d952ca77375838f58fb4d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:38:16 -1100 Subject: [PATCH 037/186] Test --- src/komodo_bitcoind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index de1b3352e..4b7f15190 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,6 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; + fprintf(stderr,"komodo_segid.(%s) -> %02x\n",segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } @@ -1412,7 +1413,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); if ( slowflag != 0 && pindex != 0 ) + { pindex->segid = -1; + fprintf(stderr,"A set segid.%d <- %d\n",height,pindex->segid); + } } else { @@ -1424,7 +1428,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( pindex->segid == -2 ) { pindex->segid = komodo_segid(1,height); - fprintf(stderr,"set segid.%d <- %d\n",height,pindex->segid); + fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } From a03223780511abfb48c0b83487bd404ee54c8a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:43:42 -1100 Subject: [PATCH 038/186] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b7f15190..ceddcee50 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,7 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; - fprintf(stderr,"komodo_segid.(%s) -> %02x\n",segid); + fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } From e77d279f0c60bd80fb9905fe26be11906af95901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:49:15 -1100 Subject: [PATCH 039/186] Test --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ceddcee50..767b3f4ce 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1155,7 +1155,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; - fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); + //fprintf(stderr,"komodo_segid.(%d) -> %02x\n",height,segid); } } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); } @@ -1383,7 +1383,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) @@ -1425,9 +1425,9 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( pindex != 0 && height > 100 ) { - if ( pindex->segid == -2 ) + if ( pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { - pindex->segid = komodo_segid(1,height); + pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); From 8f97da8ea443c95723bbc6e03a550f63f577334c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:52:14 -1100 Subject: [PATCH 040/186] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 767b3f4ce..501d14da5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1439,7 +1439,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; } - if ( slowflag != 0 && isPoS != 0 ) + if ( slowflag != 0 && isPoS != 0 && height > 12500 ) { if ( isPoS != 2 ) { From 435ef4fde25e36e044d1555959e8f741ca03c70b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 02:59:45 -1100 Subject: [PATCH 041/186] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 501d14da5..02d24fbd7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1386,12 +1386,13 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); - if ( (pindex= mapBlockIndex[pblock->GetHash()]) != 0 && pindex->segid >= -1 ) + pindex = mapBlockIndex[pblock->GetHash()]; + /*if ( pindex != 0 && pindex->segid >= -1 ) { if ( pindex->segid == -1 ) return(0); else return(1); - } + }*/ txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { From 15bec8194bec86cb7378e4d589a2fa531790e017 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:07:53 -1100 Subject: [PATCH 042/186] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 02d24fbd7..561174be7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1387,12 +1387,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); pindex = mapBlockIndex[pblock->GetHash()]; - /*if ( pindex != 0 && pindex->segid >= -1 ) + if ( pindex != 0 && pindex->segid >= -1 ) { if ( pindex->segid == -1 ) return(0); else return(1); - }*/ + } txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { @@ -1531,7 +1531,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) return(0); if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); From ad0f453e27545685af52fcd262620c2f11603fb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:10:53 -1100 Subject: [PATCH 043/186] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 561174be7..9b9bc7c4d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1531,7 +1531,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { - if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget for staked chains return(-1); @@ -1545,7 +1545,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 703faba6690b390eaebb1dcd9378b8cece67ea21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:16:38 -1100 Subject: [PATCH 044/186] Remove MGNX exemption --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b9bc7c4d..483f29d71 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1411,12 +1411,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( eligible == 0 || eligible > pblock->nTime ) { - if ( ASSETCHAINS_STAKED < 100 ) + if ( 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); if ( slowflag != 0 && pindex != 0 ) { pindex->segid = -1; - fprintf(stderr,"A set segid.%d <- %d\n",height,pindex->segid); + fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); } } else @@ -1440,7 +1440,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; } - if ( slowflag != 0 && isPoS != 0 && height > 12500 ) + if ( slowflag != 0 && isPoS != 0 ) { if ( isPoS != 2 ) { @@ -1545,7 +1545,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 12500) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 )//|| (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 6a8820f597a13839bc588ea19da395d03a6fa1c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:19:18 -1100 Subject: [PATCH 045/186] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 483f29d71..5e3913b23 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,9 +1424,9 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 2; // 2 means staking utxo validated if ( slowflag != 0 ) { - if ( pindex != 0 && height > 100 ) + if ( height > 100 ) { - if ( pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) + if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); From eea0a57b3c366b922feebc2811f45bbcd34aabbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:20:05 -1100 Subject: [PATCH 046/186] Test --- src/komodo_bitcoind.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5e3913b23..3285f2616 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1422,15 +1422,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else { isPoS = 2; // 2 means staking utxo validated - if ( slowflag != 0 ) + if ( slowflag != 0 && height > 100 ) { - if ( height > 100 ) + if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { - if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) - { - pindex->segid = segid; - fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } + pindex->segid = segid; + fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); } } From e4ec9bab3edeee439298da02dd5606208723760e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:23:21 -1100 Subject: [PATCH 047/186] 13000 MGNX height exemption --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3285f2616..19c9b15bd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1542,7 +1542,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 )//|| (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From efceba00d9acef94a022e591dc922b4dd4272300 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 03:26:04 -1100 Subject: [PATCH 048/186] Test --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 19c9b15bd..463901570 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1534,6 +1534,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } + if ( strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000 ) + return(0); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) @@ -1542,7 +1544,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { - if ( slowflag == 0 || (strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000) ) // need all past 100 blocks to calculate PoW target + if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); From 81915d9fce766617846073d2337e20720cdca84a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 06:47:24 -1100 Subject: [PATCH 049/186] Fix rewards unlock help trigger --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c2e486a05..d522ba536 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5044,7 +5044,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) UniValue rewardsunlock(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); std::string hex; char *name; uint256 fundingtxid,txid; - if ( fHelp || params.size() > 3 ) + if ( fHelp || params.size() > 3 || params.size() < 2 ) throw runtime_error("rewardsunlock name fundingtxid [txid]\n"); if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); From de3a68db84af05bbf755c5015789bf8f5ac1587d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 22:52:29 +0200 Subject: [PATCH 050/186] add more tests for faucetfund edge cases --- qa/rpc-tests/cryptoconditions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 2784a5823..06f965340 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -79,8 +79,15 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetinfo() assert_equal(result['result'], 'success') - # fails - #result = rpc.faucetfund(-1.0) + result = rpc.faucetfund("1") + assert_equal(result['result'], 'success') + assert_true(result['hex']) + + result = rpc.faucetfund("0") + assert_equal(result['result'], 'error') + + result = rpc.faucetfund("-1") + assert_equal(result['result'], 'error') # Dice tests dice = rpc.diceaddress() From 700c1fcfc3dffbe2654776e90e808c9a2974cd98 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 22:54:23 +0200 Subject: [PATCH 051/186] Improve error checking on funds argument to faucetfund --- qa/rpc-tests/test_framework/test_framework.py | 2 +- src/wallet/rpcwallet.cpp | 20 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 0d5fe5244..f545b4246 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -151,7 +151,7 @@ class BitcoinTestFramework(object): sys.exit(1) -# Test framework for doing p2p comparison testing, which sets up some bitcoind +# Test framework for doing p2p comparison testing, which sets up some komodod # binaries: # 1 binary: test binary # 2 binaries: 1 test binary, 1 ref binary diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5dbd374d6..386997b3f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5146,12 +5146,20 @@ UniValue faucetfund(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); funds = atof(params[0].get_str().c_str()) * COIN; - hex = FaucetFund(0,funds); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create faucet funding transaction")); + if (funds > 0) { + hex = FaucetFund(0,funds); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create faucet funding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "funding amount must be positive")); + } return(result); } From 2098a4c9bbfd60de2294fcebcd99cfe22f75cfe9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Aug 2018 23:37:38 +0200 Subject: [PATCH 052/186] Disallow negative funding in faucetfund --- qa/rpc-tests/cryptoconditions.py | 1 - src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 06f965340..97b41fd12 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -81,7 +81,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("1") assert_equal(result['result'], 'success') - assert_true(result['hex']) result = rpc.faucetfund("0") assert_equal(result['result'], 'error') diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 386997b3f..744b95b57 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5138,7 +5138,7 @@ UniValue faucetinfo(const UniValue& params, bool fHelp) UniValue faucetfund(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t funds; std::string hex; + UniValue result(UniValue::VOBJ); int64_t funds; std::string hex; if ( fHelp || params.size() > 1 ) throw runtime_error("faucetfund amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5147,7 +5147,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); funds = atof(params[0].get_str().c_str()) * COIN; if (funds > 0) { - hex = FaucetFund(0,funds); + hex = FaucetFund(0,(uint64_t) funds); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); From eccd52f4cc0798c1990ff41fca9c58e424d58f50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 18:59:18 -1100 Subject: [PATCH 053/186] Check for duplicate utxo in available coins --- src/cc/CCtx.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 666132590..072f86877 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -272,6 +272,11 @@ uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,in break; if ( i != mtx.vin.size() ) continue; + for (i=0; i Date: Fri, 10 Aug 2018 08:04:34 +0200 Subject: [PATCH 054/186] More faucet tests, currently sendrawtransaction failing with bad-txns-inputs-duplicate --- qa/rpc-tests/cryptoconditions.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 97b41fd12..36126cfc5 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -66,6 +66,7 @@ class CryptoConditionsTest (BitcoinTestFramework): # basic sanity tests assert_equal(result['txcount'], 101) assert_greater_than(result['balance'], 0.0) + balance = result['balance'] # Begin actual CC tests @@ -79,15 +80,34 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetinfo() assert_equal(result['result'], 'success') - result = rpc.faucetfund("1") - assert_equal(result['result'], 'success') - result = rpc.faucetfund("0") assert_equal(result['result'], 'error') result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') + result = rpc.faucetfund("1") + assert_equal(result['result'], 'success') + assert result['hex'], "hex key found" + + result = rpc.sendrawtransaction(result['hex']) + txid = result[0] + assert txid, "found txid" + + # we need the tx above to be confirmed in the next block + rpc.generate(1) + + # clear the rawmempool + rpc.getrawmempool() + result = rpc.getwalletinfo() + + # make sure our balance is less now + assert_greater_than(balance, result['balance']) + + result = rpc.faucetinfo() + assert_equal(result['result'], 'success') + assert_greater_than( result['funding'], 0 ) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From 066c16e5f69aea4d1b08ce639b3c02fa82b55b3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:06:05 -1100 Subject: [PATCH 055/186] segid print --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 463901570..53dd21802 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,11 +1424,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 2; // 2 means staking utxo validated if ( slowflag != 0 && height > 100 ) { + segid = -3; if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); + } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); } } } From 9e432c97adf3c7b411ca5d6739a2573dfe98ea6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:08:20 -1100 Subject: [PATCH 056/186] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 53dd21802..ac76958c4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1429,7 +1429,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); + } //else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); } } } From 278a61fd5e61309d1f8a0c1d5c73877295aa5a89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:23:40 -1100 Subject: [PATCH 057/186] uint64_t -> int64_t for coin values other than three --- src/cc/CCfaucet.h | 2 +- src/cc/CCinclude.h | 6 +++--- src/cc/dice.cpp | 4 ++-- src/cc/faucet.cpp | 14 +++++++------- src/cc/rewards.cpp | 14 +++++++------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index b875bd133..f9b933255 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -24,7 +24,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); // CCcustom -std::string FaucetFund(uint64_t txfee,uint64_t funds); +std::string FaucetFund(uint64_t txfee,int64_t funds); std::string FaucetGet(uint64_t txfee); UniValue FaucetInfo(); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index a59a2325c..6a1a25b35 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -81,7 +81,7 @@ char *pubkey33_str(char *dest,uint8_t *pubkey33); uint256 Parseuint256(char *hexstr); CPubKey pubkey2pk(std::vector pubkey); bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); -bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue); +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); std::vector Mypubkey(); @@ -92,8 +92,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); -uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs); -uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); +int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout); // curve25519 and sha256 bits256 curve25519_shared(bits256 privkey,bits256 otherpub); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8d8600fb6..e35f367f3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -604,9 +604,9 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -uint64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; std::vector > unspentOutputs; if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index b8b3b62cb..403b56c3e 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -uint64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -42,7 +42,7 @@ uint64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -154,7 +154,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string FaucetGet(uint64_t txfee) return(0); } -std::string FaucetFund(uint64_t txfee,uint64_t funds) +std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); @@ -191,7 +191,7 @@ std::string FaucetFund(uint64_t txfee,uint64_t funds) UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx; CPubKey faucetpk; struct CCcontract_info *cp,C; uint64_t funding; + CMutableTransaction mtx; CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 6c5975e51..442f0e460 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -66,7 +66,7 @@ */ -uint64_t RewardsCalc(uint64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) +int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { int32_t numblocks; uint64_t duration,reward = 0; fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); @@ -137,7 +137,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -156,7 +156,7 @@ uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i > unspentOutputs; @@ -314,9 +314,9 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr return(totalinputs); } -uint64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { - char coinaddr[64]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; + char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -513,7 +513,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t funding,sbits,reward=0,amount=0,inputs,CCchange=0,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; From c4a4cd05ecb25144d21c0e72ca9ff1b2b836f38f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:25:25 -1100 Subject: [PATCH 058/186] Fix --- src/cc/CCtx.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 072f86877..4bc081e15 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -23,7 +23,7 @@ By using -addressindex=1, it allows tracking of all the CC addresses */ -bool SignTx(CMutableTransaction &mtx,int32_t vini,uint64_t utxovalue,const CScript scriptPubKey) +bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { #ifdef ENABLE_WALLET CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore& keystore = *pwalletMain; @@ -41,7 +41,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,uint64_t utxovalue,const CScri std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0,utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*cond; CPubKey unspendablepk; + CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*cond; CPubKey unspendablepk; n = mtx.vout.size(); for (i=0; i > &addressIndex } } -uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) +int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) { uint256 txid; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); @@ -201,7 +201,7 @@ uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) return(0); } -int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,uint64_t value) +int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,int64_t value) { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; @@ -252,9 +252,9 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); } -uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; uint64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); From 59da6d30dd7bf503a4e14c7fac94bf117e852a81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:31:25 -1100 Subject: [PATCH 059/186] REWARDSCC_MAXAPR and use int64_t for all coin values --- src/cc/CCauction.h | 4 ++-- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 1 + src/cc/CCutils.cpp | 4 ++-- src/cc/auction.cpp | 18 +++++++++--------- src/cc/fsm.cpp | 12 ++++++------ src/cc/lotto.cpp | 14 +++++++------- src/cc/rewards.cpp | 7 +++++++ 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index 52cd03d14..855cdf72e 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -23,8 +23,8 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string AuctionPost(uint64_t txfee,uint256 itemhash,uint64_t minbid,char *title,char *description); -std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount); +std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); +std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid); #endif diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index a0354252e..41e3cb5b1 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -23,7 +23,7 @@ bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string LottoTicket(uint64_t txfee,uint64_t numtickets); +std::string LottoTicket(uint64_t txfee,int64_t numtickets); std::string LottoWinner(uint64_t txfee); #endif diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index e7db9d4a9..26819e9b9 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -20,6 +20,7 @@ #include "CCinclude.h" #define EVAL_REWARDS 0xe5 +#define REWARDSCC_MAXAPR (COIN/4) bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); UniValue RewardsInfo(uint256 rewardid); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 240e5b7e0..8cb06ab25 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -156,7 +156,7 @@ bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) return(destaddr[0] != 0); } -bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue) +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue) { char destaddr[64]; if ( vout.scriptPubKey.IsPayToCryptoCondition() != CCflag ) @@ -255,7 +255,7 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; uint64_t amount; std::vector origpubkey; + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7d8512ede..8265dfc45 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -147,9 +147,9 @@ uint64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount) +std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -169,7 +169,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -187,9 +187,9 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) return(0); } -std::string AuctionPost(uint64_t txfee,uint256 itemhash,uint64_t minbid,char *title,char *description) +std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index e3e112bf6..6141d8a4a 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -154,7 +154,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { - CMutableTransaction mtx; CPubKey mypk,fsmpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -174,7 +174,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { - CMutableTransaction mtx; CPubKey mypk,fsmpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 0ed223c25..0d03d5e15 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -147,9 +147,9 @@ uint64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub return(totalinputs); } -std::string LottoTicket(uint64_t txfee,uint64_t numtickets) +std::string LottoTicket(uint64_t txfee,int64_t numtickets) { - CMutableTransaction mtx; CPubKey mypk,Lottopk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -169,7 +169,7 @@ std::string LottoTicket(uint64_t txfee,uint64_t numtickets) std::string LottoWinner(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,Lottopk; uint64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 442f0e460..64d95c846 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -205,6 +205,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("cant find fundingtxid"); else if ( fundingTx.vout.size() > 0 && DecodeRewardsFundingOpRet(fundingTx.vout[fundingTx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) != 'F' ) return eval->Invalid("fundingTx not valid"); + if ( APR > REWARDSCC_MAXAPR ) + return eval->Invalid("excessive APR"); switch ( funcid ) { case 'F': @@ -424,6 +426,11 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 fprintf(stderr,"negative parameter error\n"); return(0); } + if ( APR > REWARDSCC_MAXAPR ) + { + fprintf(stderr,"25% APR is maximum\n"); + return(0); + } cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; From 984a9dc30a4e2609af080364e00a288e9c2b4614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:33:02 -1100 Subject: [PATCH 060/186] %% --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 64d95c846..c84c73591 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#include "CCinclude.h" +#include "CCrewards.h" /* The rewards CC contract is initially for OOT, which needs this functionality. However, many of the attributes can be parameterized to allow different rewards programs to run. Multiple rewards plans could even run on the same blockchain, though the user would need to choose which one to lock funds into. @@ -428,7 +428,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 } if ( APR > REWARDSCC_MAXAPR ) { - fprintf(stderr,"25% APR is maximum\n"); + fprintf(stderr,"25%% APR is maximum\n"); return(0); } cp = CCinit(&C,EVAL_REWARDS); From 0d84fb208ec4b3a0a35f09b43711b4d96f3ccf84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:38:55 -1100 Subject: [PATCH 061/186] Error check add inputs loop --- src/cc/CCtx.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4bc081e15..a22b4fd7d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -249,7 +249,6 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else if ( abovei >= 0 ) return(abovei); else return(belowi); - //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); } int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) @@ -283,19 +282,13 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->txid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - /*mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = out.tx->vout[out.i].nValue; - totalinputs += nValue; - n++; - if ( totalinputs >= total || n >= maxinputs ) - break;*/ if ( n >= maxutxos ) break; } } } remains = total; - for (i=0; i0; i++) { below = above = 0; abovei = belowi = -1; From 7b9e2b3c608dbb7469e042e6a88f76f68d7e3569 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 08:40:28 +0200 Subject: [PATCH 062/186] faucetget tests --- qa/rpc-tests/cryptoconditions.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 36126cfc5..f3022c036 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -86,10 +86,13 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') - result = rpc.faucetfund("1") + # why does this fail? + #result = rpc.faucetfund("1987") + result = rpc.faucetfund("2") assert_equal(result['result'], 'success') assert result['hex'], "hex key found" + # broadcast the xtn result = rpc.sendrawtransaction(result['hex']) txid = result[0] assert txid, "found txid" @@ -108,6 +111,15 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') assert_greater_than( result['funding'], 0 ) + result = rpc.faucetget() + assert_equal(result['result'], 'success') + assert result['hex'], "hex key found" + + # broadcast the xtn + result = rpc.sendrawtransaction(result['hex']) + txid = result[0] + assert txid, "found txid" + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From a6a826c625527a21f2953d7642a68a6f8da0f3d1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 09:23:04 +0200 Subject: [PATCH 063/186] Add more tests, fails sometimes still due to bad-txns-inputs-duplicate --- qa/rpc-tests/cryptoconditions.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index f3022c036..17a887bd5 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -29,10 +29,10 @@ class CryptoConditionsTest (BitcoinTestFramework): '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', # TODO: AC.conf instead of komodo.conf #'-conf='+self.options.tmpdir+'/node0/komodo.conf', - '-regtest', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', + '-regtest', '-addressindex=1', '-spentindex=1', '-ac_supply=5555555', @@ -88,6 +88,8 @@ class CryptoConditionsTest (BitcoinTestFramework): # why does this fail? #result = rpc.faucetfund("1987") + + # we need at least 1 + txfee to get result = rpc.faucetfund("2") assert_equal(result['result'], 'success') assert result['hex'], "hex key found" @@ -101,11 +103,12 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(1) # clear the rawmempool - rpc.getrawmempool() - result = rpc.getwalletinfo() + result = rpc.getrawmempool() + result = rpc.getwalletinfo() + balance2 = result['balance'] # make sure our balance is less now - assert_greater_than(balance, result['balance']) + assert_greater_than(balance, balance2) result = rpc.faucetinfo() assert_equal(result['result'], 'success') @@ -120,6 +123,13 @@ class CryptoConditionsTest (BitcoinTestFramework): txid = result[0] assert txid, "found txid" + # confirm above tx + rpc.generate(1) + result = rpc.getwalletinfo() + + # we should have slightly more funds from the faucet now + assert_greater_than(result['balance'], balance2) + # Dice tests dice = rpc.diceaddress() assert_equal(dice['result'], 'success') From 2b6315fd1370a6a95d5e89e4c707500c2f51f6c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 20:24:33 -1100 Subject: [PATCH 064/186] Fix utxo selection --- src/cc/CCtx.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a22b4fd7d..65adc6655 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -266,16 +266,22 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - for (i=0; i 0 ) + { + for (i=0; i 0 ) + { + for (i=0; itxid,up->vout,CScript())); totalinputs += up->nValue; remains -= up->nValue; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); if ( totalinputs >= total || (i+1) >= maxinputs ) break; } From ba0f55ac2f80cca6d8453ee772ca29b39f074d0f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 10:46:07 +0200 Subject: [PATCH 065/186] Add tests for tokencreate and rewardsaddress --- qa/rpc-tests/cryptoconditions.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 17a887bd5..23c6479fe 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -151,12 +151,11 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenaddress(self.pubkey) assert_equal(result['result'], 'success') - for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: + for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: assert_equal(result[x][0], 'R') - # fails if no funds? - # result = rpc.tokencreate("DUKE", 0.10, "duke") - # assert_equal(result['result'], 'success') + result = rpc.tokencreate("DUKE", "1987.420", "duke") + assert_equal(result['result'], 'success') # there are no tokens created yet result = rpc.tokenlist() @@ -174,6 +173,16 @@ class CryptoConditionsTest (BitcoinTestFramework): #result = rpc.tokeninfo(self.pubkey) + # Rewards Tests + + result = rpc.rewardsaddress() + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.rewardsaddress(self.pubkey) + for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + if __name__ == '__main__': CryptoConditionsTest ().main () From 0c3cdfb4f3f712b7371d4b550d84e09c59dc2f0b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 22:45:53 -1100 Subject: [PATCH 066/186] MAX APR to 25*COIN == 25% --- src/cc/CCrewards.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 26819e9b9..ef675797c 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -20,7 +20,7 @@ #include "CCinclude.h" #define EVAL_REWARDS 0xe5 -#define REWARDSCC_MAXAPR (COIN/4) +#define REWARDSCC_MAXAPR (COIN * 25) bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); UniValue RewardsInfo(uint256 rewardid); From 9b30af9799b6406c87c42a14768cac9561ed47cb Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 10 Aug 2018 18:10:21 +0200 Subject: [PATCH 067/186] Fix bug in FaucetGet where it returns an int instead of a string --- qa/rpc-tests/cryptoconditions.py | 9 +++++---- src/cc/faucet.cpp | 2 +- src/wallet/rpcwallet.cpp | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 23c6479fe..b99d31216 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -68,7 +68,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_greater_than(result['balance'], 0.0) balance = result['balance'] - # Begin actual CC tests + ###### Begin actual CC tests ###### # Faucet tests faucet = rpc.faucetaddress() @@ -77,6 +77,10 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['myCCaddress', 'FaucetCCaddress', 'Faucetmarker', 'myaddress']: assert_equal(faucet[x][0], 'R') + # no funds in the faucet yet + result = rpc.faucetget() + assert_equal(result['result'], 'error') + result = rpc.faucetinfo() assert_equal(result['result'], 'success') @@ -86,9 +90,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.faucetfund("-1") assert_equal(result['result'], 'error') - # why does this fail? - #result = rpc.faucetfund("1987") - # we need at least 1 + txfee to get result = rpc.faucetfund("2") assert_equal(result['result'], 'success') diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 403b56c3e..6cfa9c941 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -169,7 +169,7 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find faucet inputs\n"); - return(0); + return(""); } std::string FaucetFund(uint64_t txfee,int64_t funds) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 142b7696c..10b1f1676 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5179,7 +5179,10 @@ UniValue faucetget(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create faucet get transaction")); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create faucet get transaction")); + } return(result); } From 309ee4e3a168f8a68e3b0ff1c3ea0e5ae63b936d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 05:13:14 -1100 Subject: [PATCH 068/186] Return string in faucet --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 403b56c3e..1adec8af8 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -169,7 +169,7 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find faucet inputs\n"); - return(0); + return(""); } std::string FaucetFund(uint64_t txfee,int64_t funds) @@ -185,7 +185,7 @@ std::string FaucetFund(uint64_t txfee,int64_t funds) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,funds,faucetpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } - return(0); + return(""); } UniValue FaucetInfo() From 1ed46fb8378c594600cc2fdf2866f7af75581b3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 05:16:48 -1100 Subject: [PATCH 069/186] return("") for std::string --- src/cc/auction.cpp | 6 +++--- src/cc/dice.cpp | 38 +++++++++++++++++++------------------- src/cc/fsm.cpp | 6 +++--- src/cc/lotto.cpp | 4 ++-- src/cc/rewards.cpp | 30 +++++++++++++++--------------- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 8265dfc45..7b5f106d0 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -164,7 +164,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find Auction inputs\n"); - return(0); + return(""); } std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) @@ -184,7 +184,7 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find Auction inputs\n"); - return(0); + return(""); } std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) @@ -200,7 +200,7 @@ std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *tit mtx.vout.push_back(MakeCC1vout(EVAL_AUCTION,funds,Auctionpk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } - return(0); + return(""); } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e35f367f3..0dbad5cd6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,11 +805,11 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || timeoutblocks < 0 || timeoutblocks > 1440 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) - return(0); + return(""); if ( AddNormalinputs(mtx,mypk,funds+3*txfee,60) > 0 ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,dicepk)); @@ -818,7 +818,7 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceFundingOpRet('F',sbits,minbet,maxbet,maxodds,timeoutblocks))); } fprintf(stderr,"cant find enough inputs\n"); - return(0); + return(""); } std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) @@ -827,10 +827,10 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) - return(0); + return(""); scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { @@ -854,7 +854,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('E',sbits,fundingtxid,hentropy,zeroid))); } else fprintf(stderr,"cant find enough inputs\n"); } else fprintf(stderr,"only fund creator can add more funds (entropy)\n"); - return(0); + return(""); } std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) @@ -863,21 +863,21 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( bet < 0 || odds < 1 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) - return(0); + return(""); if ( bet < minbet || bet > maxbet || odds > maxodds ) { fprintf(stderr,"Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); - return(0); + return(""); } if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 ) { if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { fprintf(stderr,"entropy txid is spent\n"); - return(0); + return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); if ( AddNormalinputs(mtx,mypk,bet+2*txfee+odds,60) > 0 ) @@ -892,7 +892,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( entropyval == 0 && funding != 0 ) fprintf(stderr,"cant find dice entropy inputs\n"); else fprintf(stderr,"cant find dice inputs\n"); - return(0); + return(""); } std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) @@ -903,7 +903,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { fprintf(stderr,"Diceinit error\n"); - return("0"); + return(""); } fundingpk = DiceFundingPk(fundingPubKey); if ( winlosetimeout != 0 ) @@ -918,7 +918,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) { fprintf(stderr,"no txfee inputs for win/lose\n"); - return("0"); + return(""); } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { @@ -932,7 +932,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"bettxid already spent\n"); - return("0"); + return(""); } //fprintf(stderr,"iswin.%d matches\n",iswin); mtx.vin.push_back(CTxIn(bettxid,0,CScript())); @@ -942,7 +942,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 funcid = 'T'; if ( DiceVerifyTimeout(betTx,timeoutblocks) == 0 ) // hasnt timed out yet { - return("0"); + return(""); } else { @@ -958,7 +958,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 if ( odds < 1 || odds > maxodds ) { fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); - return("0"); + return(""); } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; @@ -973,7 +973,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 else { fprintf(stderr,"not enough inputs for %.8f\n",(double)fundsneeded/COIN); - return("0"); + return(""); } } else @@ -994,12 +994,12 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 { *resultp = -1; fprintf(stderr,"iswin.%d winlosetimeout.%d\n",iswin,winlosetimeout); - return("0"); + return(""); } } *resultp = -1; fprintf(stderr,"couldnt find bettx or entropytx\n"); - return("0"); + return(""); } double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 6141d8a4a..04c620e99 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -149,7 +149,7 @@ int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey std::string FSMList() { - return(0); + return(""); } std::string FSMCreate(uint64_t txfee,std::string name,std::string states) @@ -169,7 +169,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find fsm inputs\n"); - return(0); + return(""); } std::string FSMInfo(uint256 fsmtxid) @@ -178,7 +178,7 @@ std::string FSMInfo(uint256 fsmtxid) cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); - return(0); + return(""); } diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 0d03d5e15..e20cb3505 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -164,7 +164,7 @@ std::string LottoTicket(uint64_t txfee,int64_t numtickets) mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } else fprintf(stderr,"cant find Lotto inputs\n"); - return(0); + return(""); } std::string LottoWinner(uint64_t txfee) @@ -180,7 +180,7 @@ std::string LottoWinner(uint64_t txfee) mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,winnings,Lottopk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } - return(0); + return(""); } diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index c84c73591..896284245 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -424,12 +424,12 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 if ( funds < COIN || mindeposit < 0 || minseconds < 0 || maxseconds < 0 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } if ( APR > REWARDSCC_MAXAPR ) { fprintf(stderr,"25%% APR is maximum\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) @@ -440,7 +440,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 if ( RewardsPlanExists(cp,sbits,rewardspk,a,b,c,d) != 0 ) { fprintf(stderr,"Rewards plan (%s) already exists\n",planstr); - return(0); + return(""); } if ( AddNormalinputs(mtx,mypk,funds+2*txfee,64) > 0 ) { @@ -449,7 +449,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsFundingOpRet('F',sbits,APR,minseconds,maxseconds,mindeposit))); } fprintf(stderr,"cant find enough inputs\n"); - return(0); + return(""); } std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) @@ -458,7 +458,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i if ( amount < 0 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) @@ -469,7 +469,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i if ( RewardsPlanExists(cp,sbits,rewardspk,a,b,c,d) == 0 ) { fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); - return(0); + return(""); } sbits = stringbits(planstr); if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 ) @@ -478,7 +478,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('A',sbits,fundingtxid))); } else fprintf(stderr,"cant find enough inputs\n"); fprintf(stderr,"cant find fundingtxid\n"); - return(0); + return(""); } std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) @@ -487,7 +487,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t if ( deposit < 0 ) { fprintf(stderr,"negative parameter error\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) @@ -498,12 +498,12 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); - return(0); + return(""); } if ( deposit < mindeposit ) { fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); - return(0); + return(""); } if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval { @@ -515,7 +515,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)deposit/COIN); } fprintf(stderr,"cant find rewards inputs\n"); - return(0); + return(""); } std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) @@ -530,7 +530,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); - return(0); + return(""); } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); if ( locktxid == zeroid ) @@ -541,7 +541,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 if ( (amount= CCutxovalue(coinaddr,locktxid,0)) == 0 ) { fprintf(stderr,"%s locktxid/v0 is spent\n",coinaddr); - return(0); + return(""); } if ( GetTransaction(locktxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) { @@ -551,7 +551,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 else { fprintf(stderr,"%s no normal vout.1 in locktxid\n",coinaddr); - return(0); + return(""); } } if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) @@ -568,6 +568,6 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 fprintf(stderr,"cant find enough rewards inputs\n"); } fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN); - return(0); + return(""); } From 7a0727d5855f3e4f78725f2b5b8b440e3d2d6ffc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 10:37:00 -1100 Subject: [PATCH 070/186] Filter out CC utxo for normal add inputs --- src/cc/CCtx.cpp | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 65adc6655..7b42690ea 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -266,30 +266,33 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - if ( mtx.vin.size() > 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - for (i=0; i 0 ) + { + for (i=0; i 0 ) + { + for (i=0; itxid = txid; + up->nValue = out.tx->vout[out.i].nValue; + up->vout = vout; + if ( n >= maxutxos ) break; - if ( i != mtx.vin.size() ) - continue; - } - if ( n > 0 ) - { - for (i=0; itxid = txid; - up->nValue = out.tx->vout[out.i].nValue; - up->vout = vout; - if ( n >= maxutxos ) - break; + } } } } From f1084b8898c547e9d595c9cc045fee69b18bb5c1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 00:34:38 +0200 Subject: [PATCH 071/186] Refactor faucet/rewards/dice/token tests into their own functions --- qa/rpc-tests/cryptoconditions.py | 51 +++++++++++++++++++------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index b99d31216..420cddf31 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -27,8 +27,6 @@ class CryptoConditionsTest (BitcoinTestFramework): self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', - # TODO: AC.conf instead of komodo.conf - #'-conf='+self.options.tmpdir+'/node0/komodo.conf', '-port=64367', '-rpcport=64368', '-ac_name=REGTEST', @@ -50,27 +48,15 @@ class CryptoConditionsTest (BitcoinTestFramework): self.sync_all() print("Done setting up network") - def run_test (self): - print("Mining blocks...") + def run_faucet_tests(self): rpc = self.nodes[0] - # utxos from block 1 become mature in block 101 - rpc.generate(101) - self.sync_all() - - # this corresponds to -pubkey above - print("Importing privkey") - rpc.importprivkey(self.privkey) - - result = rpc.getwalletinfo() # basic sanity tests + result = rpc.getwalletinfo() assert_equal(result['txcount'], 101) assert_greater_than(result['balance'], 0.0) balance = result['balance'] - ###### Begin actual CC tests ###### - - # Faucet tests faucet = rpc.faucetaddress() assert_equal(faucet['result'], 'success') # verify all keys look like valid AC addrs, could be better @@ -131,7 +117,9 @@ class CryptoConditionsTest (BitcoinTestFramework): # we should have slightly more funds from the faucet now assert_greater_than(result['balance'], balance2) - # Dice tests + def run_dice_tests(self): + rpc = self.nodes[0] + dice = rpc.diceaddress() assert_equal(dice['result'], 'success') for x in ['myCCaddress', 'DiceCCaddress', 'Dicemarker', 'myaddress']: @@ -144,7 +132,8 @@ class CryptoConditionsTest (BitcoinTestFramework): #result = rpc.dicefund("LUCKY",10000,1,10000,10,5) #assert_equal(result, []) - # Token tests + def run_token_tests(self): + rpc = self.nodes[0] result = rpc.tokenaddress() assert_equal(result['result'], 'success') for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress']: @@ -172,10 +161,11 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) - #result = rpc.tokeninfo(self.pubkey) - - # Rewards Tests + result = rpc.tokeninfo(self.pubkey) + assert_equal(result['result'], 'success') + def run_rewards_tests(self): + rpc = self.nodes[0] result = rpc.rewardsaddress() for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress']: assert_equal(result[x][0], 'R') @@ -185,5 +175,24 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result[x][0], 'R') + def run_test (self): + print("Mining blocks...") + rpc = self.nodes[0] + + # utxos from block 1 become mature in block 101 + rpc.generate(101) + self.sync_all() + + # this corresponds to -pubkey above + print("Importing privkey") + rpc.importprivkey(self.privkey) + + + self.run_faucet_tests() + self.run_rewards_tests() + self.run_dice_tests() + self.run_token_tests() + + if __name__ == '__main__': CryptoConditionsTest ().main () From 03fb3946a109df5b9d5dd57e717bf4127a9da299 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 07:18:31 +0200 Subject: [PATCH 072/186] Fix various return values which should be std::string --- src/cc/CCassetstx.cpp | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 7d55b85ff..bfd51f4b7 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -60,12 +60,14 @@ UniValue AssetInfo(uint256 assetid) if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","cant find assetid")); - return(0); + return(result); } if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) { fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","assetid isnt assetcreation txid")); } result.push_back(Pair("result","success")); @@ -182,13 +184,13 @@ std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std:: if ( assetsupply < 0 ) { fprintf(stderr,"negative assetsupply %lld\n",(long long)assetsupply); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( name.size() > 32 || description.size() > 4096 ) { fprintf(stderr,"name.%d or description.%d is too big\n",(int32_t)name.size(),(int32_t)description.size()); - return(0); + return(""); } if ( txfee == 0 ) txfee = 10000; @@ -199,7 +201,7 @@ std::string CreateAsset(int64_t txfee,int64_t assetsupply,std::string name,std:: mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(cp->CChexstr) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetCreateOpRet('c',Mypubkey(),name,description))); } - return(0); + return(""); } std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector destpubkey,int64_t total) @@ -208,7 +210,7 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des if ( total < 0 ) { fprintf(stderr,"negative total %lld\n",(long long)total); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -234,7 +236,7 @@ std::string AssetTransfer(int64_t txfee,uint256 assetid,std::vector des } else fprintf(stderr,"not enough CC asset inputs for %.8f\n",(double)total/COIN); //} else fprintf(stderr,"numoutputs.%d != numamounts.%d\n",n,(int32_t)amounts.size()); } - return(0); + return(""); } std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64_t pricetotal) @@ -243,17 +245,17 @@ std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64 if ( bidamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative bidamount %lld, pricetotal %lld\n",(long long)bidamount,(long long)pricetotal); - return(0); + return(""); } if ( GetTransaction(assetid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find assetid\n"); - return(0); + return(""); } if ( vintx.vout.size() > 0 && DecodeAssetCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) == 0 ) { fprintf(stderr,"assetid isnt assetcreation txid\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -264,7 +266,7 @@ std::string CreateBuyOffer(int64_t txfee,int64_t bidamount,uint256 assetid,int64 mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,bidamount,GetUnspendable(cp,0))); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeAssetOpRet('b',assetid,zeroid,pricetotal,Mypubkey()))); } - return(0); + return(""); } std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t pricetotal) @@ -273,7 +275,7 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -296,18 +298,18 @@ std::string CreateSell(int64_t txfee,int64_t askamount,uint256 assetid,int64_t p } else fprintf(stderr,"need some assets to place ask\n"); } fprintf(stderr,"need some native coins to place ask\n"); - return(0); + return(""); } std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 assetid2,int64_t pricetotal) { CMutableTransaction mtx; CPubKey mypk; uint64_t mask; int64_t inputs,CCchange; CScript opret; struct CCcontract_info *cp,C; fprintf(stderr,"asset swaps disabled\n"); - return(0); + return(""); if ( askamount < 0 || pricetotal < 0 ) { fprintf(stderr,"negative askamount %lld, askamount %lld\n",(long long)pricetotal,(long long)askamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -335,7 +337,7 @@ std::string CreateSwap(int64_t txfee,int64_t askamount,uint256 assetid,uint256 a } else fprintf(stderr,"need some assets to place ask\n"); } fprintf(stderr,"need some native coins to place ask\n"); - return(0); + return(""); } std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) @@ -356,7 +358,7 @@ std::string CancelBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid) return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('o',assetid,zeroid,0,Mypubkey()))); } } - return(0); + return(""); } std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) @@ -377,7 +379,7 @@ std::string CancelSell(int64_t txfee,uint256 assetid,uint256 asktxid) return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet('x',assetid,zeroid,0,Mypubkey()))); } } - return(0); + return(""); } std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t fillamount) @@ -386,7 +388,7 @@ std::string FillBuyOffer(int64_t txfee,uint256 assetid,uint256 bidtxid,int64_t f if ( fillamount < 0 ) { fprintf(stderr,"negative fillamount %lld\n",(long long)fillamount); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); if ( txfee == 0 ) @@ -426,12 +428,12 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if ( fillunits < 0 ) { fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); - return(0); + return(""); } if ( assetid2 != zeroid ) { fprintf(stderr,"asset swaps disabled\n"); - return(0); + return(""); } cp = CCinit(&C,EVAL_ASSETS); @@ -475,5 +477,5 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt } else fprintf(stderr,"filltx not enough utxos\n"); } } - return(0); + return(""); } From efa644f28ebff71c000b5742fd1c89537c9b4a68 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 08:21:32 +0200 Subject: [PATCH 073/186] Add some rewards tests --- qa/rpc-tests/cryptoconditions.py | 10 +++++++++- src/cc/rewards.cpp | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 420cddf31..57befe997 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -161,8 +161,9 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) + # this is not a valid assetid result = rpc.tokeninfo(self.pubkey) - assert_equal(result['result'], 'success') + assert_equal(result['result'], 'error') def run_rewards_tests(self): rpc = self.nodes[0] @@ -174,6 +175,13 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['RewardsCCaddress', 'myCCaddress', 'Rewardsmarker', 'myaddress', 'CCaddress']: assert_equal(result[x][0], 'R') + # no rewards yet + result = rpc.rewardslist() + assert_equal(result, []) + + # looking up non-existent reward should return error + result = rpc.rewardsinfo("none") + assert_equal(result['result'], 'error') def run_test (self): print("Mining blocks...") diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 896284245..083133eca 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -371,12 +371,14 @@ UniValue RewardsInfo(uint256 rewardsid) if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","cant find fundingtxid")); return(result); } if ( vintx.vout.size() > 0 && DecodeRewardsFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) == 0 ) { fprintf(stderr,"fundingtxid isnt rewards creation txid\n"); + result.push_back(Pair("result","error")); result.push_back(Pair("error","fundingtxid isnt rewards creation txid")); return(result); } From 15b76bd76a871429eab3f71e1388db13c1990c20 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 08:58:56 +0200 Subject: [PATCH 074/186] More rewards tests --- qa/rpc-tests/cryptoconditions.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 57befe997..53c733ab0 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -183,6 +183,16 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_equal(result['result'], 'error') + result = rpc.rewardscreatefunding("STUFF", "1000", "5", "1", "10", "10") + assert result['hex'], 'got raw xtn' + txid = rpc.sendrawtransaction(result['hex']) + assert txid, 'got txid' + + # confirm the above xtn + rpc.generate(1) + result = rpc.rewardsinfo(txid) + assert_equal(result['result'], 'success') + def run_test (self): print("Mining blocks...") rpc = self.nodes[0] From 076a9ee19bb4c8285a28f96746ea2f3bb295a602 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 20:24:50 -1100 Subject: [PATCH 075/186] -MGNX exception --- src/cc/CCtx.cpp | 2 +- src/komodo_bitcoind.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 7b42690ea..2c3001c10 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -266,7 +266,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( mtx.vin.size() > 0 ) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ac76958c4..bd5505c1c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1535,8 +1535,6 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - if ( strcmp(ASSETCHAINS_SYMBOL,"MGNX") == 0 && height < 13000 ) - return(0); if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget,bhash)) == 0 ) From 4f054db067292205bd021501da97b82802ed6055 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 10 Aug 2018 20:53:43 -1100 Subject: [PATCH 076/186] Fix reward calc check --- src/cc/rewards.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 896284245..4d8e00b19 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -243,9 +243,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) - return false; - else if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt"); else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("lock tx vout.0 is normal output"); @@ -259,7 +257,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); - if ( tx.vout[1].nValue > amount+reward ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue+reward,sbits,fundingtxid) == 0 ) + return false; + else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); preventCCvouts = 1; break; From 88e714577b1ce5740431e39f23fd20538125f87b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 16:47:24 +0200 Subject: [PATCH 077/186] More rewards tests --- qa/rpc-tests/cryptoconditions.py | 14 ++++++++++++++ src/wallet/rpcwallet.cpp | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 53c733ab0..9367055d7 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -192,6 +192,20 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(1) result = rpc.rewardsinfo(txid) assert_equal(result['result'], 'success') + assert_equal(result['name'], 'STUFF') + assert_equal(result['APR'], "5.00000000") + assert_equal(result['minseconds'], 86400) + assert_equal(result['maxseconds'], 864000) + assert_equal(result['funding'], "1000.00000000") + assert_equal(result['mindeposit'], "10.00000000") + assert_equal(result['fundingtxid'], txid) + + # funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", txid, "0") + assert_equal(result['result'], 'error') + + result = rpc.rewardsaddfunding("STUFF", txid, "100") + assert_equal(result['result'], 'success') def run_test (self): print("Mining blocks...") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 10b1f1676..6329d4a52 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5024,7 +5024,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) UniValue rewardsaddfunding(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) throw runtime_error("rewardsaddfunding name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5035,11 +5035,19 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(0,name,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); + if (amount > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "funding amount must be positive")); + } return(result); } From 941619eb461ab11b6d5490f2233c6f5aeee7ba31 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 19:14:51 +0200 Subject: [PATCH 078/186] Make the REGTEST AC special in our test suite, so we get a predictable rpc port number --- qa/rpc-tests/cryptoconditions.py | 3 ++- qa/rpc-tests/test_framework/util.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 9367055d7..849d7daea 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -26,10 +26,11 @@ class CryptoConditionsTest (BitcoinTestFramework): self.privkey = "UqMgxk7ySPNQ4r9nKAFPjkXy6r5t898yhuNCjSZJLg3RAM4WW1m9" self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ + # always give -ac_name as first extra_arg + '-ac_name=REGTEST', '-conf='+self.options.tmpdir+'/node0/REGTEST.conf', '-port=64367', '-rpcport=64368', - '-ac_name=REGTEST', '-regtest', '-addressindex=1', '-spentindex=1', diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index 856ae5a05..5cb0d1b10 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -223,9 +223,10 @@ def start_node(i, dirname, extra_args=None, rpchost=None, timewait=None, binary= if os.getenv("PYTHON_DEBUG", ""): print "start_node: calling komodo-cli -rpcwait getblockcount returned" devnull.close() - #url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) - #TODO: this breaks non CC tests - url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + if extra_args[0] == '-ac_name=REGTEST': + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', 64368) + else: + url = "http://rt:rt@%s:%d" % (rpchost or '127.0.0.1', rpc_port(i)) print("connecting to " + url) if timewait is not None: proxy = AuthServiceProxy(url, timeout=timewait) From 012613d7ac289b53ecc5d277321f7dc3f9507bdc Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 19:24:19 +0200 Subject: [PATCH 079/186] Undo this, it should be on a diff branch --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 33bcf519f..7de40ff26 100644 --- a/configure.ac +++ b/configure.ac @@ -507,8 +507,8 @@ if test x$use_hardening != xno; then if test x$TARGET_OS != xwindows; then # All windows code is PIC, forcing it on just adds useless compile warnings - # AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) - # AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) + AX_CHECK_LINK_FLAG([[-Wl,-z,relro]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,relro"],[AC_MSG_ERROR(Cannot enable RELRO)]) + AX_CHECK_LINK_FLAG([[-Wl,-z,now]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-z,now"],[AC_MSG_ERROR(Cannot enable BIND_NOW)]) AX_CHECK_COMPILE_FLAG([-fPIE],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fPIE"],[AC_MSG_ERROR(Cannot enable -fPIE)]) AX_CHECK_LINK_FLAG([[-pie]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -pie"],[AC_MSG_ERROR(Cannot enable -pie)]) else From 9a017060c0d95a3f90667644c02e4c524600d49d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 11 Aug 2018 09:08:34 -1100 Subject: [PATCH 080/186] +print --- src/cc/dice.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0dbad5cd6..bf42277cc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -628,11 +628,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { + fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid != 'F' && funcid != 'T' ) - { n++; - fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); - } totalinputs += nValue; if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) { From d043ec4f27e4696e49a287767f1a175f1a1e8240 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 11 Aug 2018 09:16:43 -1100 Subject: [PATCH 081/186] Non-consensus portion of dice bet fix --- src/cc/dice.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bf42277cc..0b18c1bcc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -487,6 +487,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) DiceQueue(iswin,sbits,fundingtxid,txid); } break; + // make sure all funding txid are from matching sbits and fundingtxid!! case 'L': case 'W': case 'T': @@ -567,7 +568,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } -uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs) +uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; @@ -587,16 +588,19 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits ) { - if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) + if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - totalinputs += it->second.satoshis; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) + { + if ( total != 0 && maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + totalinputs += it->second.satoshis; + n++; + if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) + break; + } } } else fprintf(stderr,"null funcid\n"); } @@ -960,7 +964,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60)) > 0 ) + if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From 674e0bbebbef18b0c860a9f10cb9e5fa20f6038a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 11 Aug 2018 09:22:26 -1100 Subject: [PATCH 082/186] Fix rewards error check --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 18feff58d..86b48371d 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -182,7 +182,7 @@ bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransactio } if ( inputs != outputs+txfee ) { - fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); + fprintf(stderr,"inputs %llu vs outputs %llu txfee %llu\n",(long long)inputs,(long long)outputs,(long long)txfee); return eval->Invalid("mismatched inputs != outputs + txfee"); } else return(true); @@ -257,7 +257,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); - if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue+reward,sbits,fundingtxid) == 0 ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+reward,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); From 84b40e08a2f80ea0114804e3dfc861b8e95f57e8 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 12 Aug 2018 20:31:45 +0200 Subject: [PATCH 083/186] Start adding tests for rewardsunlock --- qa/rpc-tests/cryptoconditions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 849d7daea..9e7ddf8e5 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -207,6 +207,10 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsaddfunding("STUFF", txid, "100") assert_equal(result['result'], 'success') + fundingtxid = result['hex'] + assert fundingtxid, "got funding txid" + + result = rpc.rewardsunlock("STUFF", fundingtxid) def run_test (self): print("Mining blocks...") From 66027c0219598109a8fa86cddafe9a9bc7f49d80 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 13 Aug 2018 09:55:17 +0200 Subject: [PATCH 084/186] Add rewards tests --- qa/rpc-tests/cryptoconditions.py | 23 +++++++++++++++++++++-- src/wallet/rpcwallet.cpp | 25 ++++++++++++++++++------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 9e7ddf8e5..845d387b4 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -184,7 +184,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_equal(result['result'], 'error') - result = rpc.rewardscreatefunding("STUFF", "1000", "5", "1", "10", "10") + result = rpc.rewardscreatefunding("STUFF", "1000", "5", "0", "10", "10") assert result['hex'], 'got raw xtn' txid = rpc.sendrawtransaction(result['hex']) assert txid, 'got txid' @@ -195,7 +195,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') assert_equal(result['name'], 'STUFF') assert_equal(result['APR'], "5.00000000") - assert_equal(result['minseconds'], 86400) + assert_equal(result['minseconds'], 0) assert_equal(result['maxseconds'], 864000) assert_equal(result['funding'], "1000.00000000") assert_equal(result['mindeposit'], "10.00000000") @@ -210,7 +210,26 @@ class CryptoConditionsTest (BitcoinTestFramework): fundingtxid = result['hex'] assert fundingtxid, "got funding txid" + # the previous xtn has not been broadcasted yet result = rpc.rewardsunlock("STUFF", fundingtxid) + assert_equal(result['result'], 'error') + + # wrong plan name + result = rpc.rewardsunlock("SHTUFF", fundingtxid) + assert_equal(result['result'], 'error') + + txid = rpc.sendrawtransaction(fundingtxid) + assert txid, 'got txid from sendrawtransaction' + + # confirm the xtn above + rpc.generate(1) + + result = rpc.rewardsunlock("STUFF", fundingtxid) + # currently failing because reward is not > txfee? + # assert_equal(result['result'], 'success') + + result = rpc.rewardslock("STUFF", fundingtxid, "-5") + assert_equal(result['result'], 'error') def run_test (self): print("Mining blocks...") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6329d4a52..1654be8ba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5003,7 +5003,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) UniValue rewardslock(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) throw runtime_error("rewardslock name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5014,11 +5014,19 @@ UniValue rewardslock(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsLock(0,name,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards lock transaction")); + if ( amount > 0 ) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards lock transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "amount must be positive")); + } return(result); } @@ -5070,7 +5078,10 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards unlock transaction")); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards unlock transaction")); + } return(result); } From c269ecf5d9d205bf8a308cee1444e15895748988 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Aug 2018 23:05:56 -1100 Subject: [PATCH 085/186] Get right total to unlock! --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 86b48371d..a378c56a3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -257,7 +257,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); - if ( RewardsExactAmounts(cp,eval,tx,txfee+reward,sbits,fundingtxid) == 0 ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+vinTx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); From 21565974399d064fa4c658f547d7f1b434304159 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Aug 2018 23:07:40 -1100 Subject: [PATCH 086/186] Use tx not vents --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a378c56a3..198018d58 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -257,7 +257,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.1 mismatched scriptPubKey"); amount = vinTx.vout[0].nValue; reward = RewardsCalc(amount,tx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); - if ( RewardsExactAmounts(cp,eval,tx,txfee+vinTx.vout[1].nValue,sbits,fundingtxid) == 0 ) + if ( RewardsExactAmounts(cp,eval,tx,txfee+tx.vout[1].nValue,sbits,fundingtxid) == 0 ) return false; else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); From 7300a1c11702b6af5f36733805683fec38aa5b00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Aug 2018 23:14:56 -1100 Subject: [PATCH 087/186] Constrain dice vins to be for exact plan --- src/cc/dice.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0b18c1bcc..f084705fd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -313,18 +313,21 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) else return(zeroid); } -uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { - char destaddr[64]; + char destaddr[64]; uint8_t funcid; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) - return(tx.vout[v].nValue); + { + if ( (numvouts= tx.vout.size()) > 0 && (funcid= DecodeDiceOpRet(tx.GetHash(),tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits && ((funcid == 'F' && tx.GetHash() == reffundingtxid) || fundingtxid == reffundingtxid) ) + return(tx.vout[v].nValue); + } } return(0); } -int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) +int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t refsbits,uint256 reffundingtxid) { CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t assetoshis; numvins = tx.vin.size(); @@ -338,7 +341,7 @@ int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *c return eval->Invalid("always should find vin, but didnt"); else { - if ( (assetoshis= IsDicevout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + if ( (assetoshis= IsDicevout(cp,vinTx,tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) inputs += assetoshis; } } @@ -346,7 +349,7 @@ int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *c for (i=0; iInvalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) @@ -630,7 +633,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) + if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid != 'F' && funcid != 'T' ) From 8608399cb542de07ac8fff8270168cb6bc4bd04a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Aug 2018 23:16:48 -1100 Subject: [PATCH 088/186] Numvouts --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f084705fd..05d249a7a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -315,12 +315,12 @@ uint256 DiceGetEntropy(CTransaction tx,uint8_t reffuncid) uint64_t IsDicevout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { - char destaddr[64]; uint8_t funcid; uint64_t sbits; uint256 fundingtxid,hash,proof; + char destaddr[64]; uint8_t funcid; int32_t numvouts; uint64_t sbits; uint256 fundingtxid,hash,proof; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 ) + if ( Getscriptaddress(destaddr,tx.vout[v].scriptPubKey) > 0 && strcmp(destaddr,cp->unspendableCCaddr) == 0 && (numvouts= tx.vout.size()) > 0 ) { - if ( (numvouts= tx.vout.size()) > 0 && (funcid= DecodeDiceOpRet(tx.GetHash(),tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits && ((funcid == 'F' && tx.GetHash() == reffundingtxid) || fundingtxid == reffundingtxid) ) + if ( (funcid= DecodeDiceOpRet(tx.GetHash(),tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits && ((funcid == 'F' && tx.GetHash() == reffundingtxid) || fundingtxid == reffundingtxid) ) return(tx.vout[v].nValue); } } From a85ad9d32beeaa21f42d15297c6f0ec9f32204ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 12 Aug 2018 23:22:31 -1100 Subject: [PATCH 089/186] Prevent reporting locked funds as part of reward funds --- src/cc/rewards.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 198018d58..9314f7c94 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -328,11 +328,11 @@ int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) != 0 ) + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' ) { - if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) + if ( refsbits == sbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) + if ( (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) totalinputs += nValue; else fprintf(stderr,"refsbits.%llx sbits.%llx nValue %.8f\n",(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case\n"); From 944aed48a8aeb85c33524b93c9b16c55f2e95491 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 03:12:15 -1100 Subject: [PATCH 090/186] Test --- src/cc/dice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05d249a7a..94495cc4b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -591,9 +591,12 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK continue; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { - if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) + char str[65],sstr[16]; + unstringbits(sstr,sbits); + fprintf(stderr,"(%c) %.8f %s %s\n",fundsflag,funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); + if ( sbits == refsbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) { From a4a96df9e5d0e22ad10758acf536571ec64c8e61 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 03:15:16 -1100 Subject: [PATCH 091/186] Skip adding CC vin if CCchange is big enough --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 94495cc4b..0e1ebe9cb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -905,7 +905,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; *resultp = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -970,7 +970,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + if ( CCchange >= fundsneeded || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From a5a2c7cb3a1faa4fbf615be6b0c2c06ab0879baf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 03:16:59 -1100 Subject: [PATCH 092/186] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0e1ebe9cb..b00044040 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -595,7 +595,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { char str[65],sstr[16]; unstringbits(sstr,sbits); - fprintf(stderr,"(%c) %.8f %s %s\n",fundsflag,funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); + fprintf(stderr,"(%c) %.8f %s %s\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); if ( sbits == refsbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) From cb2ee04b3528e91ac6da2acf4789609a25823088 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 05:46:11 -1100 Subject: [PATCH 093/186] Fix dice finish --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b00044040..62a7d1046 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -970,7 +970,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + if ( CCchange >= fundsneeded+betTx.vout[1].nValue || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From 6e78d3df436e838c13b190a8a116bda379b9d7c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:06:49 -1100 Subject: [PATCH 094/186] KOMODO_MININGTHREADS to control staking vs PoW, delay start mining by 15 seconds --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 3 +++ src/miner.cpp | 12 ++++++------ src/rpcmining.cpp | 7 ++++++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c4ba26eb6..86c168a85 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 747a43b72..8269ee206 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1505,6 +1505,9 @@ void komodo_args(char *argv0) extern const char *Notaries_elected1[][2]; std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); + if ( GetBoolArg("-gen", false) != 0 ) + KOMODO_MININGTHREADS = GetArg("-genproclimit",1); + else KOMODO_MININGTHREADS = 0; if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); diff --git a/src/miner.cpp b/src/miner.cpp index fb2eb2d05..874c1b4f8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -106,7 +106,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" -extern int32_t KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; @@ -393,7 +393,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -453,7 +453,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); - if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || GetArg("-genproclimit", 0) > 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || KOMODO_MININGTHREADS > 0 ) { UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); @@ -788,7 +788,7 @@ void static BitcoinMiner() } if (!fvNodesEmpty )//&& !IsInitialBlockDownload()) break; - MilliSleep(5000); + MilliSleep(15000); //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,ASSETCHAINS_SYMBOL,(int32_t)IsInitialBlockDownload()); } while (true); @@ -950,7 +950,7 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget; - if ( GetArg("-genproclimit", 0) > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) + if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = @@ -978,7 +978,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - //if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + //if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) // sleep(1); return false; } diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 4c4d2eed5..df58a5573 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -33,6 +33,7 @@ using namespace std; extern uint64_t ASSETCHAINS_STAKED; +extern int32_t KOMODO_MININGTHREADS; arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); /** @@ -327,6 +328,9 @@ UniValue setgenerate(const UniValue& params, bool fHelp) mapArgs["-gen"] = (fGenerate ? "1" : "0"); mapArgs ["-genproclimit"] = itostr(nGenProcLimit); + if ( fGenerate == 0 ) + KOMODO_MININGTHREADS = -1; + else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit; #ifdef ENABLE_WALLET GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit); #else @@ -382,6 +386,7 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) obj.push_back(Pair("chain", Params().NetworkIDString())); #ifdef ENABLE_MINING obj.push_back(Pair("generate", getgenerate(params, false))); + obj.push_back(Pair("numthreads", (int64_t)KOMODO_MININGTHREADS)); #endif return obj; } @@ -647,7 +652,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) pblocktemplate = CreateNewBlockWithKey(); #endif if (!pblocktemplate) - throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); + throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking"); // Need to update only after we know CreateNewBlockWithKey succeeded pindexPrev = pindexPrevNew; From 9b940331f9f20cefe1f635bc21c493be9e96aa1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:31:14 -1100 Subject: [PATCH 095/186] Add segid to get block --- src/rpcblockchain.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b76698917..c9e94438c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -121,6 +121,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits))); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); From a4885032666a7512fa0c2f7145bff0ff18cf3dbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 21:37:46 -1100 Subject: [PATCH 096/186] Test --- src/rpcblockchain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index c9e94438c..d870ad75e 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -147,6 +147,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); UniValue deltas(UniValue::VARR); @@ -263,6 +264,7 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); + result.push_back(Pair("segid", (int64_t)blockindex->segid)); UniValue txs(UniValue::VARR); BOOST_FOREACH(const CTransaction&tx, block.vtx) { From 99c3975dcb84493caddc11ffd0ef667595da850b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 13 Aug 2018 23:00:06 -1100 Subject: [PATCH 097/186] Set default KOMODO_MININGTHREADS <= -1 --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8269ee206..616f7ecaa 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1507,7 +1507,7 @@ void komodo_args(char *argv0) IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( GetBoolArg("-gen", false) != 0 ) KOMODO_MININGTHREADS = GetArg("-genproclimit",1); - else KOMODO_MININGTHREADS = 0; + else KOMODO_MININGTHREADS = -1; if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); From 0e03d55920f323544b9f69b2852f05e245f98090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 02:18:44 -1100 Subject: [PATCH 098/186] Fix dice finish --- src/cc/dice.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 62a7d1046..7521df794 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -970,19 +970,21 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } CCchange = betTx.vout[0].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded+betTx.vout[1].nValue || (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) + CCchange -= (fundsneeded + betTx.vout[1].nValue); + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); - mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); - mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } else { fprintf(stderr,"not enough inputs for %.8f\n",(double)fundsneeded/COIN); return(""); } + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); + mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); + mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } else { From db871af56fd0de9d2eac2c67df414914db69ffcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 03:44:36 -1100 Subject: [PATCH 099/186] Fix dice finish --- src/cc/dice.cpp | 2 +- src/komodo_bitcoind.h | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7521df794..669cb9007 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -968,7 +968,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); return(""); } - CCchange = betTx.vout[0].nValue; + CCchange = betTx.vout[0].nValue + betTx.vout[1]; fundsneeded = txfee + odds*betTx.vout[1].nValue; if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) CCchange -= (fundsneeded + betTx.vout[1].nValue); diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bd5505c1c..13501d2a9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1327,14 +1327,16 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ave = (sum / arith_uint256(m)); if ( ave > target ) ave = target; - } else ave = easydiff; //else return(target); + } else ave = target; //easydiff; //else return(target); if ( percPoS == 0 ) percPoS = 1; if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { + //if ( oldflag != 0 ) + // bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); if ( oldflag != 0 ) - bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); - else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); + bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); + else bnTarget = (ave / arith_uint256(goalperc * goalperc * goalperc * goalperc)) * arith_uint256(percPoS * percPoS); if ( ASSETCHAINS_STAKED < 100 ) { for (i=31; i>=24; i--) @@ -1355,7 +1357,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); //bnTarget = (bnTarget * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); bnTarget = (bnTarget / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); - } else bnTarget = (ave / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); + } + else bnTarget = (ave / arith_uint256(goalperc * goalperc)) * arith_uint256(percPoS * percPoS * percPoS); if ( bnTarget > easydiff ) bnTarget = easydiff; else if ( bnTarget < ave ) // overflow From 2b4374d705f57e16a24234895fe99b7faead4ee2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 03:45:58 -1100 Subject: [PATCH 100/186] nValue --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 669cb9007..1f2c770d7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -968,7 +968,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); return(""); } - CCchange = betTx.vout[0].nValue + betTx.vout[1]; + CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; fundsneeded = txfee + odds*betTx.vout[1].nValue; if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) CCchange -= (fundsneeded + betTx.vout[1].nValue); From 1da742e71ecc8fa80334122faf76ae323e69231f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 14 Aug 2018 04:48:07 -1100 Subject: [PATCH 101/186] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f2c770d7..ef1b27bf3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -969,9 +969,9 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 return(""); } CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; - fundsneeded = txfee + odds*betTx.vout[1].nValue; - if ( CCchange >= fundsneeded+betTx.vout[1].nValue ) - CCchange -= (fundsneeded + betTx.vout[1].nValue); + fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; + if ( CCchange >= fundsneeded ) + CCchange -= fundsneeded; else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) From ef44dd00e197cbc8068d9a8a03fa324a185740d3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 15 Aug 2018 10:21:59 +0200 Subject: [PATCH 102/186] more rewards tests --- qa/rpc-tests/cryptoconditions.py | 45 ++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 845d387b4..ad7ee7467 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -184,7 +184,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_equal(result['result'], 'error') - result = rpc.rewardscreatefunding("STUFF", "1000", "5", "0", "10", "10") + result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") assert result['hex'], 'got raw xtn' txid = rpc.sendrawtransaction(result['hex']) assert txid, 'got txid' @@ -194,10 +194,10 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo(txid) assert_equal(result['result'], 'success') assert_equal(result['name'], 'STUFF') - assert_equal(result['APR'], "5.00000000") + assert_equal(result['APR'], "25.00000000") assert_equal(result['minseconds'], 0) assert_equal(result['maxseconds'], 864000) - assert_equal(result['funding'], "1000.00000000") + assert_equal(result['funding'], "7777.00000000") assert_equal(result['mindeposit'], "10.00000000") assert_equal(result['fundingtxid'], txid) @@ -205,11 +205,14 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsaddfunding("STUFF", txid, "0") assert_equal(result['result'], 'error') - result = rpc.rewardsaddfunding("STUFF", txid, "100") + result = rpc.rewardsaddfunding("STUFF", txid, "555") assert_equal(result['result'], 'success') fundingtxid = result['hex'] assert fundingtxid, "got funding txid" + result = rpc.rewardslock("STUFF", fundingtxid, "7") + assert_equal(result['result'], 'error') + # the previous xtn has not been broadcasted yet result = rpc.rewardsunlock("STUFF", fundingtxid) assert_equal(result['result'], 'error') @@ -224,13 +227,39 @@ class CryptoConditionsTest (BitcoinTestFramework): # confirm the xtn above rpc.generate(1) - result = rpc.rewardsunlock("STUFF", fundingtxid) - # currently failing because reward is not > txfee? - # assert_equal(result['result'], 'success') - + # amount must be positive result = rpc.rewardslock("STUFF", fundingtxid, "-5") assert_equal(result['result'], 'error') + # amount must be positive + result = rpc.rewardslock("STUFF", fundingtxid, "0") + assert_equal(result['result'], 'error') + + # trying to lock less than the min amount is an error + result = rpc.rewardslock("STUFF", fundingtxid, "7") + assert_equal(result['result'], 'error') + + # not working + #result = rpc.rewardslock("STUFF", fundingtxid, "10") + #assert_equal(result['result'], 'success') + #locktxid = result['hex'] + #assert locktxid, "got lock txid" + + # locktxid has not been broadcast yet + #result = rpc.rewardsunlock("STUFF", locktxid) + #assert_equal(result['result'], 'error') + + # broadcast xtn + #txid = rpc.sendrawtransaction(locktxid) + #assert txid, 'got txid from sendrawtransaction' + + # confirm the xtn above + #rpc.generate(1) + + #result = rpc.rewardsunlock("STUFF", locktxid) + #assert_equal(result['result'], 'error') + + def run_test (self): print("Mining blocks...") rpc = self.nodes[0] From 6ca2e998838df140e1168cdb1913ff6b8fe7ccf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:18:13 -1100 Subject: [PATCH 103/186] Backwards compatibility breaking changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assets: change tokeninfo to return "supply" in satoshis Max description length to 4096 Rewards: Fix rewardsunlock without giving it a locked txid always gives error Fix (nonconsensus) allow anybody to unlock only AFTER maxtime Fix rewards unlock to use mempool fix could you add a locked_funds value to rewardsinfo? Fix i deposited 100000 at 20% apr for one day i only got back 100000.01140669 seems like too little for 20% APR Faucet: Fix txid with 0x00 at beginning and end required for faucetget txid (65536 average iterations needed) Change reduce faucet get to 0.1 coins Can’t reproduce: it seems that if you re-run faucetget twice in the same block is when it pegs the cpu to max Dice: fix Dice status always returning loss Wont fix Profit margin for dice plan sounds good. -> use -ac_commission --- src/cc/CCassetstx.cpp | 3 +- src/cc/CCfaucet.h | 1 + src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 12 +++--- src/cc/faucet.cpp | 38 ++++++++++++++---- src/cc/rewards.cpp | 87 +++++++++++++++++++++++++++++++--------- src/rpcblockchain.cpp | 2 +- src/wallet/rpcwallet.cpp | 9 ++++- 8 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index bfd51f4b7..5869aa133 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -74,8 +74,7 @@ UniValue AssetInfo(uint256 assetid) result.push_back(Pair("tokenid",uint256_str(str,assetid))); result.push_back(Pair("owner",pubkey33_str(str,origpubkey.data()))); result.push_back(Pair("name",name)); - sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); - result.push_back(Pair("supply",numstr)); + result.push_back(Pair("supply",vintx.vout[0].nValue)); result.push_back(Pair("description",description)); return(result); } diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index f9b933255..39930cb20 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -20,6 +20,7 @@ #include "CCinclude.h" #define EVAL_FAUCET 0xe4 +#define FAUCETSIZE (COIN / 10) bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 6a1a25b35..5116c1da6 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -64,6 +64,7 @@ bool myAddtomempool(CTransaction &tx); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); bool mySendrawtransaction(std::string res); +int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); // CCcustom CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef1b27bf3..4f162eafc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1059,9 +1059,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - if ( spenttx.vout[2].scriptPubKey == fundingPubKey ) + if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); @@ -1075,15 +1075,17 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) { - if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) + if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) + //if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); } fprintf(stderr,"didnt find dicefinish tx\n"); - } else return(-1.); + } + return(-1.); } return(0.); } diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 1adec8af8..796dfb50c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -69,17 +69,17 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction if ( (assetoshis= IsFaucetvout(cp,tx,i)) != 0 ) outputs += assetoshis; } - if ( inputs != outputs+COIN+txfee ) + if ( inputs != outputs+FAUCETSIZE+txfee ) { fprintf(stderr,"inputs %llu vs outputs %llu\n",(long long)inputs,(long long)outputs); - return eval->Invalid("mismatched inputs != outputs + COIN + txfee"); + return eval->Invalid("mismatched inputs != outputs + FAUCETSIZE + txfee"); } else return(true); } bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -87,7 +87,6 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return eval->Invalid("no vouts"); else { - //fprintf(stderr,"check vins\n"); for (i=0; iInvalid("invalid faucet output"); + else if ( hash[0] != 0 || hash[31] != 0 ) + return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); @@ -154,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,len; uint8_t hash[32],buf[32768]; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -167,7 +171,27 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); + for (i=0; i<1000000; i++) + { + tmpmtx = mtx; + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time + if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) + { + len >>= 1; + decode_hex(buf,len,(char *)rawhex.c_str()); + vcalc_sha256(0,hash,buf,len); + fprintf(stderr,"%02x%02x ",hash[0],hash[31]); + if ( hash[0] == 0 && hash[31] == 0 ) + { + fprintf(stderr,"found valid txid after %d iterations\n",i); + return(rawhex); + } + } + rawhex.delete(); + tmpmtx.delete(); + } + fprintf(stderr,"couldnt generate valid txid\n"); + return(""); } else fprintf(stderr,"cant find faucet inputs\n"); return(""); } diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 9314f7c94..52bc82a7d 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -77,8 +77,10 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds //duration = (uint32_t)time(NULL) - (1532713903 - 3600 * 24); } else if ( duration > maxseconds ) duration = maxseconds; - reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); - fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN); + if ( 0 ) // amount * APR * duration / COIN * 100 * 365*24*3600 + reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); + else reward = (((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000)) / 10000; + fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f vals %.8f %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN,(double)((amount * duration) / (365 * 24 * 3600LL))/COIN,(double)(((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000))/COIN); return(reward); } @@ -270,10 +272,38 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return(true); } -// 'L' vs 'F' and 'A' -int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t refsbits,uint256 reffundingtxid,uint64_t needed) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; + uint8_t funcid; uint64_t sbits,nValue; uint256 fundingtxid; char str[65]; + memset(&txid,0,sizeof(txid)); + vout = -1; + nValue = 0; + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + if ( tx.vout.size() > 0 && tx.vout[0].nValue >= needed ) + { + const uint256 &hash = tx.GetHash(); + if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(hash,0) == 0 ) + { + if ( (funcid= DecodeRewardsOpRet(hash,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'U' && sbits == refsbits && fundingtxid == reffundingtxid ) + { + txid = hash; + vout = 0; + nValue = tx.vout[0].nValue; + fprintf(stderr,"found 'U' %s %.8f in unspent in mempool\n",uint256_str(str,txid),(double)nValue/COIN); + return(nValue); + } + } + } + } + return(nValue); +} + +// 'L' vs 'F' and 'A' +int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) +{ + char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -296,13 +326,16 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontra if ( sbits != refsbits || fundingtxid != reffundingtxid ) continue; fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); - if ( fundsflag != 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) - continue; - else if ( fundsflag == 0 && (funcid != 'L' || tx.vout.size() < 4) ) + if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; + else if ( maxseconds != 0 && funcid != 'L' ) + { + if ( CCduration(numblocks,txid)) < maxseconds ) + continue; + } if ( total != 0 && maxinputs != 0 ) { - if ( fundsflag == 0 ) + if ( maxseconds != 0 ) scriptPubKey = tx.vout[1].scriptPubKey; mtx.vin.push_back(CTxIn(txid,vout,CScript())); } @@ -313,13 +346,25 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontra } else fprintf(stderr,"null funcid\n"); } } + if ( maxseconds == 0 && totalinputs < total && (maxinputs == 0 || n < maxinputs-1) ) + { + fprintf(stderr,"search mempool for unlocked and unspent CC rewards output for %.8f\n",(double)(total-totalinputs)/COIN); + if ( (nValue= myIs_unlockedtx_inmempool(txid,vout,refsbits,reffundingtxid,total-totalinputs)) > 0 ) + { + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + fprintf(stderr,"added mempool vout for %.8f\n",(double)nValue/COIN); + totalinputs += nValue; + n++; + } + } return(totalinputs); } -int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t &lockedfunds,uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; + lockedfunds = 0; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -328,12 +373,16 @@ int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' ) + if ( (funcid= DecodeRewardsOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid)) == 'F' || funcid == 'A' || funcid == 'U' || funcid == 'L' ) { if ( refsbits == sbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( (nValue= IsRewardsvout(cp,tx,vout,sbits,fundingtxid)) > 0 ) - totalinputs += nValue; + { + if ( funcid == 'L' ) + lockedfunds += nValue; + else totalinputs += nValue; + } else fprintf(stderr,"refsbits.%llx sbits.%llx nValue %.8f\n",(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case\n"); } else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); @@ -367,7 +416,7 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa UniValue RewardsInfo(uint256 rewardsid) { - UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; uint64_t lockedfunds,APR,minseconds,maxseconds,mindeposit,sbits,funding; CPubKey rewardspk; struct CCcontract_info *cp,C; char str[67],numstr[65]; if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); @@ -395,9 +444,11 @@ UniValue RewardsInfo(uint256 rewardsid) result.push_back(Pair("mindeposit",numstr)); cp = CCinit(&C,EVAL_REWARDS); rewardspk = GetUnspendable(cp,0); - funding = RewardsPlanFunds(sbits,cp,rewardspk,rewardsid); + funding = RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,rewardsid); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); + sprintf(numstr,"%.8f",(double)lockedfunds/COIN); + result.push_back(Pair("locked",numstr)); return(result); } @@ -485,7 +536,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { - CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < 0 ) { fprintf(stderr,"negative parameter error\n"); @@ -507,7 +558,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); return(""); } - if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval + if ( (funding= RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval { if ( AddNormalinputs(mtx,mypk,deposit+2*txfee,64) > 0 ) { @@ -536,7 +587,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); if ( locktxid == zeroid ) - amount = AddRewardsInputs(scriptPubKey,0,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); + amount = AddRewardsInputs(scriptPubKey,maxseconds,cp,mtx,rewardspk,(1LL << 30),1,sbits,fundingtxid); else { GetCCaddress(cp,coinaddr,rewardspk); @@ -558,7 +609,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) { - if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d870ad75e..7f01c862f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -352,7 +352,7 @@ UniValue getdifficulty(const UniValue& params, bool fHelp) bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) { //char *uint256_str(char *str,uint256); char str[65]; - LOCK(mempool.cs); + //LOCK(mempool.cs); BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) { const CTransaction &tx = e.GetTx(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6329d4a52..5c16c3b9c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5319,7 +5319,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) result.push_back(Pair("status", "loss")); else result.push_back(Pair("status", "no pending bets")); } - } else result.push_back(Pair("status", "invalid bet txid")); + } else result.push_back(Pair("status", "bet still pending")); return(result); } @@ -5412,7 +5412,14 @@ UniValue tokencreate(const UniValue& params, bool fHelp) name = params[0].get_str(); supply = atof(params[1].get_str().c_str()) * COIN; if ( params.size() == 3 ) + { description = params[2].get_str(); + if ( description.size() > 4096 ) + { + result.push_back(Pair("error", "token description longer than 4096")); + return(result); + } + } hex = CreateAsset(0,supply,name,description); if ( hex.size() > 0 ) { From 76fb8636ec9c48b9d0c830fc7f66ca5871aa8d09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:22:18 -1100 Subject: [PATCH 104/186] Syntax --- src/cc/faucet.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 796dfb50c..e31ebbb25 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -187,8 +187,6 @@ std::string FaucetGet(uint64_t txfee) return(rawhex); } } - rawhex.delete(); - tmpmtx.delete(); } fprintf(stderr,"couldnt generate valid txid\n"); return(""); From 6986a67b5c41c7c7c2dfc9039de263c412fb70e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:23:23 -1100 Subject: [PATCH 105/186] Syntax --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 52bc82a7d..3c6b72ff2 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -325,12 +325,12 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont { if ( sbits != refsbits || fundingtxid != reffundingtxid ) continue; - fprintf(stderr,"fundsflag.%d (%c) %.8f %.8f\n",fundsflag,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); + fprintf(stderr,"maxseconds.%d (%c) %.8f %.8f\n",(int32_t)maxseconds,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; else if ( maxseconds != 0 && funcid != 'L' ) { - if ( CCduration(numblocks,txid)) < maxseconds ) + if ( CCduration(numblocks,txid) < maxseconds ) continue; } if ( total != 0 && maxinputs != 0 ) From 97e4544b10ca70dee4b18bd148b0ace03ee92369 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:33:12 -1100 Subject: [PATCH 106/186] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4f162eafc..bae8ad653 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1061,6 +1061,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { + char str[65]; + fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); From f4fc4a80f9a73e661e53e3e2aaca46cc066405d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:50:04 -1100 Subject: [PATCH 107/186] Add nonceto faucet get --- src/cc/faucet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index e31ebbb25..42e767442 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -174,6 +174,7 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; + opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { From a6c2a2fe36a667850987b307889eba9e63279b71 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:51:13 -1100 Subject: [PATCH 108/186] Test --- src/cc/faucet.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 42e767442..9956733bd 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -171,7 +171,7 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - for (i=0; i<1000000; i++) + for (i=0; i<1000; i++) { tmpmtx = mtx; opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); @@ -181,7 +181,9 @@ std::string FaucetGet(uint64_t txfee) len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); - fprintf(stderr,"%02x%02x ",hash[0],hash[31]); + for (j=0; j<32; j++) + fprintf(stderr,"%02x",hash[i]); + fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { fprintf(stderr,"found valid txid after %d iterations\n",i); From 300b9ceeb8e2ebaa01303b5e2a8f25dfd1c06a83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:52:08 -1100 Subject: [PATCH 109/186] Test --- src/cc/faucet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9956733bd..217d9145f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -171,6 +171,7 @@ std::string FaucetGet(uint64_t txfee) if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); for (i=0; i<1000; i++) { tmpmtx = mtx; @@ -186,12 +187,12 @@ std::string FaucetGet(uint64_t txfee) fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { - fprintf(stderr,"found valid txid after %d iterations\n",i); + fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } } } - fprintf(stderr,"couldnt generate valid txid\n"); + fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); } else fprintf(stderr,"cant find faucet inputs\n"); return(""); From b940bb4abdae315b8d74553ac605da4f026ee7b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:53:17 -1100 Subject: [PATCH 110/186] Fix --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 217d9145f..f27a90347 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,len; uint8_t hash[32],buf[32768]; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t hash[32],buf[32768]; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; From ca9af9a1f68028dcb6062f4600334ba2ca9acbbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:54:42 -1100 Subject: [PATCH 111/186] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index f27a90347..9f5d620b7 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -183,7 +183,7 @@ std::string FaucetGet(uint64_t txfee) decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); for (j=0; j<32; j++) - fprintf(stderr,"%02x",hash[i]); + fprintf(stderr,"%02x",hash[j]); fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { From 2accae9efdc8f6f5331941ed5032f8874597d5c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 00:56:14 -1100 Subject: [PATCH 112/186] Test --- src/cc/faucet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9f5d620b7..31e4bce21 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -172,7 +172,7 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - for (i=0; i<1000; i++) + for (i=0; i<1000000; i++) { tmpmtx = mtx; opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); @@ -182,9 +182,9 @@ std::string FaucetGet(uint64_t txfee) len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); vcalc_sha256(0,hash,buf,len); - for (j=0; j<32; j++) - fprintf(stderr,"%02x",hash[j]); - fprintf(stderr," "); + //for (j=0; j<32; j++) + // fprintf(stderr,"%02x",hash[j]); + //fprintf(stderr," "); if ( hash[0] == 0 && hash[31] == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); From 6155bc4b68d400d9309b3e343c20bbd41e17fed6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:00:43 -1100 Subject: [PATCH 113/186] tst --- src/cc/faucet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 31e4bce21..5acbb46b9 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -191,6 +191,8 @@ std::string FaucetGet(uint64_t txfee) return(rawhex); } } + if ( (i % 10000) == 9999 ) + fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); From fd39f0953539e7e99616bd2222513a6053ac5c96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:04:07 -1100 Subject: [PATCH 114/186] 0 mod 4096 for faucet get --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 5acbb46b9..fa21dc985 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( hash[0] != 0 || hash[31] != 0 ) + else if ( (hash[0] & 0x3f) != 0 || (hash[31] & 0x3f) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( hash[0] == 0 && hash[31] == 0 ) + if ( (hash[0] & 0x3f) == 0 && (hash[31] & 0x3f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From 43e77d75f7d2383569a0ed33681ffdb9b9689a36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:06:19 -1100 Subject: [PATCH 115/186] Test --- src/cc/faucet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index fa21dc985..c0aae09dc 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -190,8 +190,9 @@ std::string FaucetGet(uint64_t txfee) fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } + fprintf(stderr,"%x%x ",(hash[0] & 0x3f) >> 6,(hash[31] & 0x3f) >> 6); } - if ( (i % 10000) == 9999 ) + if ( (i % 1000) == 999 ) fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); From 6f054a7708c36d4f0c9fb1e1fa6f7e2e4529386b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:11:06 -1100 Subject: [PATCH 116/186] Test --- src/cc/faucet.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index c0aae09dc..dedbbcf3f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t hash[32],buf[32768]; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -181,19 +181,17 @@ std::string FaucetGet(uint64_t txfee) { len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); - vcalc_sha256(0,hash,buf,len); + hash = bits256_doublesha256(0,buf,len); //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash[0] & 0x3f) == 0 && (hash[31] & 0x3f) == 0 ) + if ( (hash.bytes[0] & 0x3f) == 0 && (hash.bytes[31] & 0x3f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } - fprintf(stderr,"%x%x ",(hash[0] & 0x3f) >> 6,(hash[31] & 0x3f) >> 6); + fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); } - if ( (i % 1000) == 999 ) - fprintf(stderr,"."); } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); From 135d90357fc66ddb532af65f2592624d520951e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:15:12 -1100 Subject: [PATCH 117/186] Test --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 5116c1da6..3954068e1 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -101,5 +101,6 @@ bits256 curve25519_shared(bits256 privkey,bits256 otherpub); bits256 curve25519_basepoint9(); bits256 curve25519(bits256 mysecret,bits256 basepoint); void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); +bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen); #endif From 09bff6c967f14bb7a7ae61607d4566f5d48f23bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:18:39 -1100 Subject: [PATCH 118/186] Test --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index dedbbcf3f..dd3b75399 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -158,7 +158,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -175,8 +175,8 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,opret); // signature changes each time + //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From 0ac322177136f9065d2dd6d3a8b08c711a190b41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:19:17 -1100 Subject: [PATCH 119/186] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index dd3b75399..b3c115cee 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -176,7 +176,7 @@ std::string FaucetGet(uint64_t txfee) { tmpmtx = mtx; //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From e9a15289d7072fb68c7615d02dbb6722daefe4e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:22:22 -1100 Subject: [PATCH 120/186] Test --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index b3c115cee..a3a3b350f 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0x3f) != 0 || (hash[31] & 0x3f) != 0 ) + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0x3f) == 0 && (hash.bytes[31] & 0x3f) == 0 ) + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From a997e9ed74e8fb476ec6d9c8f02618d2e40df2b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:24:39 -1100 Subject: [PATCH 121/186] Test --- src/cc/faucet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index a3a3b350f..90c3a7c1c 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) + else if ( (hash[0] & 0x7f) != 0 || (hash[31] & 0x7f) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,7 +185,7 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) + if ( (hash.bytes[0] & 0x7f) == 0 && (hash.bytes[31] & 0x7f) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); From 9193afd9269b65664fde52cbe660636c4ea2a086 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:25:23 -1100 Subject: [PATCH 122/186] Test --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 90c3a7c1c..af5e458ef 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -114,7 +114,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"check faucetget txid %s %02x/%02x\n",uint256_str(str,txid),hash[0],hash[31]); if ( tx.vout[i].nValue != FAUCETSIZE ) return eval->Invalid("invalid faucet output"); - else if ( (hash[0] & 0x7f) != 0 || (hash[31] & 0x7f) != 0 ) + else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) @@ -185,12 +185,12 @@ std::string FaucetGet(uint64_t txfee) //for (j=0; j<32; j++) // fprintf(stderr,"%02x",hash[j]); //fprintf(stderr," "); - if ( (hash.bytes[0] & 0x7f) == 0 && (hash.bytes[31] & 0x7f) == 0 ) + if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); return(rawhex); } - fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); + //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); } } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); From d614c74afb7ff1dcfd8d78ea6749ba294ffc11dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:28:08 -1100 Subject: [PATCH 123/186] Test --- src/cc/faucet.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index af5e458ef..caeb95765 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -175,16 +175,12 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - //opret << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i); - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << EVAL_FAUCET << 'G' << i)); // signature changes each time + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << i)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; decode_hex(buf,len,(char *)rawhex.c_str()); hash = bits256_doublesha256(0,buf,len); - //for (j=0; j<32; j++) - // fprintf(stderr,"%02x",hash[j]); - //fprintf(stderr," "); if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) { fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); From 815e9937bbbf280a49af3061d61d8b49c680a7df Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:39:51 -1100 Subject: [PATCH 124/186] Test --- src/cc/dice.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bae8ad653..912b1de7b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1057,16 +1057,19 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else { + char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + fprintf(stderr,"bettx is spent\n"); + if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - char str[65]; fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); - } else return(0.); + } + fprintf(stderr,"couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid)); + return(0.); } else if ( scriptPubKey == fundingPubKey ) res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1); From e65c27b52e3476bfcc7cdedf50398fa915f296ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:47:10 -1100 Subject: [PATCH 125/186] -print --- src/cc/dice.cpp | 4 ++-- src/cc/rewards.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 912b1de7b..a697d238e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1060,10 +1060,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx char str[65]; if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - fprintf(stderr,"bettx is spent\n"); + //fprintf(stderr,"bettx is spent\n"); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) { - fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); + //fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 3c6b72ff2..f625c04e7 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -313,7 +313,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont vout = (int32_t)it->first.index; if ( it->second.satoshis < 1000000 ) continue; - fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); + //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; jsecond.satoshis/COIN); if ( maxseconds == 0 && funcid != 'F' && funcid != 'A' && funcid != 'U' ) continue; else if ( maxseconds != 0 && funcid != 'L' ) @@ -333,6 +332,7 @@ int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcont if ( CCduration(numblocks,txid) < maxseconds ) continue; } + fprintf(stderr,"maxseconds.%d (%c) %.8f %.8f\n",(int32_t)maxseconds,funcid,(double)tx.vout[vout].nValue/COIN,(double)it->second.satoshis/COIN); if ( total != 0 && maxinputs != 0 ) { if ( maxseconds != 0 ) From fefaa934a9777c27f330dc9afc6b83f573684621 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 01:51:22 -1100 Subject: [PATCH 126/186] Cap reward to a doubling --- src/cc/rewards.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index f625c04e7..d3df9233b 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -80,6 +80,8 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds if ( 0 ) // amount * APR * duration / COIN * 100 * 365*24*3600 reward = (((amount * APR) / COIN) * duration) / (365*24*3600LL * 100); else reward = (((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000)) / 10000; + if ( reward > amount ) + reward = amount; fprintf(stderr,"amount %.8f %.8f %llu -> duration.%llu reward %.8f vals %.8f %.8f\n",(double)amount/COIN,((double)amount * APR)/COIN,(long long)((amount * APR) / (COIN * 365*24*3600)),(long long)duration,(double)reward/COIN,(double)((amount * duration) / (365 * 24 * 3600LL))/COIN,(double)(((amount * duration) / (365 * 24 * 3600LL)) * (APR / 1000000))/COIN); return(reward); } From 87c119b71c63ab787617e162f935452e4ad20329 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 02:29:44 -1100 Subject: [PATCH 127/186] Add pub key to faucet get I-return --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index caeb95765..e357310ff 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -175,7 +175,7 @@ std::string FaucetGet(uint64_t txfee) for (i=0; i<1000000; i++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << i)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << mypk << i)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; From af3024a34478e53ae103fd18302af00504408ecb Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 02:44:59 -1100 Subject: [PATCH 128/186] Faucet get only for first txid --- src/cc/faucet.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index e357310ff..9c0fc0cb0 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,8 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -116,6 +117,10 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx return eval->Invalid("invalid faucet output"); else if ( (hash[0] & 0xff) != 0 || (hash[31] & 0xff) != 0 ) return eval->Invalid("invalid faucetget txid"); + Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); + SetCCtxids(txids,destaddr); + for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) + return eval->Invalid("faucet is only for unused addresses"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); From 4b3021d80bb0b124f079545f3218f90f1346dabc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 05:07:28 -1100 Subject: [PATCH 129/186] Fix mempool zombie --- src/cc/faucet.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 9c0fc0cb0..827dc2716 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,j=0; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -120,7 +120,10 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx Getscriptaddress(destaddr,tx.vout[i].scriptPubKey); SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) - return eval->Invalid("faucet is only for unused addresses"); + { + if ( ++j > 1 ) + return eval->Invalid("faucet is only for unused addresses"); + } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"faucetget validated\n"); From f344c6933832aa2be566282366af774076ac7e86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 05:18:01 -1100 Subject: [PATCH 130/186] +prints --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index d3df9233b..7bbcb3065 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -567,9 +567,9 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t mtx.vout.push_back(MakeCC1vout(cp->evalcode,deposit,rewardspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)deposit/COIN); + } else fprintf(stderr,"cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); } - fprintf(stderr,"cant find rewards inputs\n"); + fprintf(stderr,"cant find rewards inputs funding %.8f locked %.8f vs deposit %.8f\n",(double)funding/COIN,(double)lockedfunds/COIN,(double)deposit/COIN); return(""); } From 8d13c0ef190900c64c55bd1eaedfff478d4df8d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 07:41:28 -1100 Subject: [PATCH 131/186] Consensus stable faucet get constraint --- src/cc/faucet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 827dc2716..142100c70 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -79,7 +79,7 @@ bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,j=0; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; + int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); @@ -121,8 +121,8 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { - if ( ++j > 1 ) - return eval->Invalid("faucet is only for unused addresses"); + if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) + return eval->Invalid("faucet is only for brand new addresses"); } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) From 5159767093007890c1c5cd0c911193356a760e37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:09:21 -1100 Subject: [PATCH 132/186] +print --- src/cc/faucet.cpp | 6 +++++- src/cc/rewards.cpp | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 142100c70..a467ed311 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -121,8 +121,12 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx SetCCtxids(txids,destaddr); for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) { + //int height = it->first.blockHeight; if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) - return eval->Invalid("faucet is only for brand new addresses"); + { + fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + //return eval->Invalid("faucet is only for brand new addresses"); + } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 7bbcb3065..c98b42a17 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -69,7 +69,7 @@ int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { int32_t numblocks; uint64_t duration,reward = 0; - fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); + //fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); if ( (duration= CCduration(numblocks,txid)) < minseconds ) { fprintf(stderr,"duration %llu < minseconds %llu\n",(long long)duration,(long long)minseconds); From c4a13b6f0d357265bafefd3257c63b1106835586 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:10:29 -1100 Subject: [PATCH 133/186] Test --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index a467ed311..ba87e06b3 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -125,7 +125,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) { fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); - //return eval->Invalid("faucet is only for brand new addresses"); + return eval->Invalid("faucet is only for brand new addresses"); } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); From 59e96a42569edfa7f283590e96e678cd28b3f3e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 08:19:58 -1100 Subject: [PATCH 134/186] -print --- src/cc/faucet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index ba87e06b3..0ab51ff13 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -124,7 +124,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx //int height = it->first.blockHeight; if ( CCduration(numblocks,it->first.txhash) > 0 && numblocks > 3 ) { - fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); + //fprintf(stderr,"would return error %s numblocks.%d ago\n",uint256_str(str,it->first.txhash),numblocks); return eval->Invalid("faucet is only for brand new addresses"); } } From 8e0ff2b732ad421148f71160d41e44e8f201d812 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 15 Aug 2018 23:24:59 +0200 Subject: [PATCH 135/186] Test refactoring, more tests, and lots of error checking improvements and uint64_t fixes --- qa/rpc-tests/cryptoconditions.py | 26 +++-- src/cc/rewards.cpp | 44 ++++++--- src/wallet/rpcwallet.cpp | 165 ++++++++++++++++++++----------- 3 files changed, 158 insertions(+), 77 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index ad7ee7467..8cfa4fd2a 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -46,11 +46,19 @@ class CryptoConditionsTest (BitcoinTestFramework): ]] ) self.is_network_split = split + self.rpc = self.nodes[0] self.sync_all() print("Done setting up network") + def send_and_mine(self, xtn): + txid = self.rpc.sendrawtransaction(xtn) + assert txid, 'got txid' + # we need the tx above to be confirmed in the next block + self.rpc.generate(1) + return txid + def run_faucet_tests(self): - rpc = self.nodes[0] + rpc = self.rpc # basic sanity tests result = rpc.getwalletinfo() @@ -90,9 +98,6 @@ class CryptoConditionsTest (BitcoinTestFramework): # we need the tx above to be confirmed in the next block rpc.generate(1) - # clear the rawmempool - result = rpc.getrawmempool() - result = rpc.getwalletinfo() balance2 = result['balance'] # make sure our balance is less now @@ -145,13 +150,18 @@ class CryptoConditionsTest (BitcoinTestFramework): for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: assert_equal(result[x][0], 'R') - result = rpc.tokencreate("DUKE", "1987.420", "duke") - assert_equal(result['result'], 'success') - # there are no tokens created yet result = rpc.tokenlist() assert_equal(result, []) + result = rpc.tokencreate("DUKE", "1987.420", "duke") + assert_equal(result['result'], 'success') + self.send_and_mine(result['hex']) + + result = rpc.tokenlist() + tokenid = result[0] + assert(tokenid, "got tokenid") + # there are no token orders yet result = rpc.tokenorders() assert_equal(result, []) @@ -166,6 +176,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokeninfo(self.pubkey) assert_equal(result['result'], 'error') + def run_rewards_tests(self): rpc = self.nodes[0] result = rpc.rewardsaddress() @@ -272,7 +283,6 @@ class CryptoConditionsTest (BitcoinTestFramework): print("Importing privkey") rpc.importprivkey(self.privkey) - self.run_faucet_tests() self.run_rewards_tests() self.run_dice_tests() diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 9314f7c94..9b58f4bf3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -66,6 +66,8 @@ */ +extern std::string CCerror; + int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { int32_t numblocks; uint64_t duration,reward = 0; @@ -532,6 +534,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + CCerror = "Rewards plan does not exist"; return(""); } fprintf(stderr,"APR %.8f minseconds.%llu maxseconds.%llu mindeposit %.8f\n",(double)APR/COIN,(long long)minseconds,(long long)maxseconds,(double)mindeposit/COIN); @@ -543,6 +546,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 if ( (amount= CCutxovalue(coinaddr,locktxid,0)) == 0 ) { fprintf(stderr,"%s locktxid/v0 is spent\n",coinaddr); + CCerror = "locktxid/v0 is spent"; return(""); } if ( GetTransaction(locktxid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) @@ -553,21 +557,37 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 else { fprintf(stderr,"%s no normal vout.1 in locktxid\n",coinaddr); + CCerror = "no normal vout.1 in locktxid"; return(""); } } - if ( amount > 0 && (reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit)) > txfee && scriptPubKey.size() > 0 ) - { - if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) - { - if ( inputs >= (reward + 2*txfee) ) - CCchange = (inputs - (reward + txfee)); - fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk)); - mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey)); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); - } - fprintf(stderr,"cant find enough rewards inputs\n"); + if ( amount > 0 ) { + reward = RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); + if (scriptPubKey.size() > 0) { + if (reward > txfee) { + if ( (inputs= AddRewardsInputs(ignore,1,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + { + if ( inputs >= (reward + 2*txfee) ) + CCchange = (inputs - (reward + txfee)); + fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk)); + mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey)); + return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); + } + CCerror = "cant find enough rewards inputs"; + fprintf(stderr,"%s\n", CCerror.c_str()); + } else { + // strprintf? + CCerror = strprintf("reward %.8f is <= the transaction fee", reward); + fprintf(stderr,"%s\n", CCerror.c_str()); + } + } else { + CCerror = "invalid scriptPubKey"; + fprintf(stderr,"%s\n", CCerror.c_str()); + } + } else { + CCerror = "amount must be positive"; + fprintf(stderr,"%s\n", CCerror.c_str()); } fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN); return(""); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1654be8ba..cbd08dd6c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,6 +38,9 @@ #include +#define ERR_RESULT(x) result.push_back(Pair("result", "error")); \ + result.push_back(Pair("error", x)); + using namespace std; using namespace libzcash; @@ -49,6 +52,8 @@ uint32_t komodo_segid32(char *coinaddr); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; +//TODO: find a better place for this +std::string CCerror; // Private method: UniValue z_getoperationstatus_IMPL(const UniValue&, bool); @@ -5074,7 +5079,10 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) txid = Parseuint256((char *)params[2].get_str().c_str()); else memset(&txid,0,sizeof(txid)); hex = RewardsUnlock(0,name,fundingtxid,txid); - if ( hex.size() > 0 ) + if (CCerror != "") { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", CCerror)); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); @@ -5194,8 +5202,7 @@ UniValue faucetget(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); hex = FaucetGet(0); - if ( hex.size() > 0 ) - { + if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else { @@ -5221,17 +5228,22 @@ UniValue dicefund(const UniValue& params, bool fHelp) maxodds = atol(params[4].get_str().c_str()); timeoutblocks = atol(params[5].get_str().c_str()); hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks); - if ( hex.size() > 0 ) - { + if (CCerror != "") { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", CCerror)); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create dice funding transaction")); + } else { + result.push_back(Pair("error", "couldnt create dice funding transaction")); + result.push_back(Pair("result", "error")); + } return(result); } UniValue diceaddfunds(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) throw runtime_error("diceaddfunds name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5241,18 +5253,28 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; - hex = DiceAddfunding(0,name,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create dice addfunding transaction")); + if ( amount > 0 ) { + hex = DiceAddfunding(0,name,fundingtxid,amount); + if (CCerror != "") { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", CCerror)); + } else if ( hex.size() > 0 ) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create dice addfunding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "amount must be positive")); + } return(result); } UniValue dicebet(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; uint64_t amount,odds; char *name; + UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid; int64_t amount,odds; char *name; if ( fHelp || params.size() != 4 ) throw runtime_error("dicebet name fundingtxid amount odds\n"); if ( ensure_CCrequirements() < 0 ) @@ -5263,18 +5285,24 @@ UniValue dicebet(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; odds = atol(params[3].get_str().c_str()); - hex = DiceBet(0,name,fundingtxid,amount,odds); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create faucet get transaction")); + if (amount > 0 && odds > 0) { + hex = DiceBet(0,name,fundingtxid,amount,odds); + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + ERR_RESULT("couldnt create faucet get transaction"); + } + } else { + ERR_RESULT("amount and odds must be positive"); + } return(result); } UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string hex; int32_t r; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -5295,7 +5323,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) UniValue dicestatus(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; uint64_t amount; std::string status; double winnings; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string status; double winnings; if ( fHelp || (params.size() != 2 && params.size() != 3) ) throw runtime_error("dicestatus name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -5435,7 +5463,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) UniValue tokentransfer(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); std::string hex; uint64_t amount; uint256 tokenid; + UniValue result(UniValue::VOBJ); std::string hex; int64_t amount; uint256 tokenid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokentransfer tokenid destpubkey amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5446,17 +5474,21 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) std::vector pubkey(ParseHex(params[1].get_str().c_str())); amount = atol(params[2].get_str().c_str()); hex = AssetTransfer(0,tokenid,pubkey,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt transfer assets")); + if (amount > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "couldnt transfer assets")); + } else { + ERR_RESULT("amount must be positive"); + } return(result); } UniValue tokenbid(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid; + UniValue result(UniValue::VOBJ); int64_t bidamount,numtokens; std::string hex; double price; uint256 tokenid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenbid numtokens tokenid price\n"); if ( ensure_CCrequirements() < 0 ) @@ -5468,11 +5500,15 @@ UniValue tokenbid(const UniValue& params, bool fHelp) price = atof(params[2].get_str().c_str()); bidamount = (price * numtokens) * COIN + 0.0000000049999; hex = CreateBuyOffer(0,bidamount,tokenid,numtokens); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create bid")); + if (price > 0 && numtokens > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "couldnt create bid")); + } else { + ERR_RESULT("price and numtokens must be positive"); + } return(result); } @@ -5519,7 +5555,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) UniValue tokenask(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid; + UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenask numtokens tokenid price\n"); if ( ensure_CCrequirements() < 0 ) @@ -5531,18 +5567,22 @@ UniValue tokenask(const UniValue& params, bool fHelp) price = atof(params[2].get_str().c_str()); askamount = (price * numtokens) * COIN + 0.0000000049999; hex = CreateSell(0,numtokens,tokenid,askamount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create ask")); + if (price > 0 && numtokens > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "couldnt create ask")); + } else { + ERR_RESULT("price and numtokens must be positive"); + } return(result); } UniValue tokenswapask(const UniValue& params, bool fHelp) { static uint256 zeroid; - UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid; + UniValue result(UniValue::VOBJ); int64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenswapask numtokens tokenid otherid price\n"); if ( ensure_CCrequirements() < 0 ) @@ -5555,11 +5595,15 @@ UniValue tokenswapask(const UniValue& params, bool fHelp) price = atof(params[3].get_str().c_str()); askamount = (price * numtokens); hex = CreateSwap(0,numtokens,tokenid,otherid,askamount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create swap")); + if (price > 0 && numtokens > 0) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else result.push_back(Pair("error", "couldnt create swap")); + } else { + ERR_RESULT("price and numtokens must be positive"); + } return(result); } @@ -5597,18 +5641,22 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) asktxid = Parseuint256((char *)params[1].get_str().c_str()); fillunits = atol(params[2].get_str().c_str()); hex = FillSell(0,tokenid,zeroid,asktxid,fillunits); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt fill bid")); + if (fillunits > 0) { + if ( hex.size() > 0) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt fill bid"); + } else { + ERR_RESULT("fillunits must be positive"); + } return(result); } UniValue tokenfillswap(const UniValue& params, bool fHelp) { static uint256 zeroid; - UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; + UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); if ( ensure_CCrequirements() < 0 ) @@ -5620,11 +5668,14 @@ UniValue tokenfillswap(const UniValue& params, bool fHelp) asktxid = Parseuint256((char *)params[2].get_str().c_str()); fillunits = atol(params[3].get_str().c_str()); hex = FillSell(0,tokenid,otherid,asktxid,fillunits); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt fill bid")); + if (fillunits > 0) { + if ( hex.size() > 0 ) { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else ERR_RESULT("couldnt fill bid"); + } else { + ERR_RESULT("fillunits must be positive"); + } return(result); } From 764eb2e5be573ffea8a82cb0dfe46d69fc66c422 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 22:10:55 -1100 Subject: [PATCH 136/186] +dice attack vector --- src/cc/dice.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a697d238e..c2f055d8d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -79,6 +79,12 @@ winner: timeout: same as winner, just without hentropy or proof +WARNING: there is an attack vector that precludes betting any large amounts, it goes as follows: + 1. do dicebet to get the house entropy revealed + 2. calculate bettor entropy that would win against the house entropy + 3. reorg the chain and make a big bet using the winning entropy calculated in 2. + + In order to mitigate this, the disclosure of the house entropy needs to be delayed beyond a reasonable reorg depth (notarization). It is recommended for production dice game with significant amounts of money to use such a delayed disclosure method. */ #include "../compat/endian.h" From 291a646a84610ba081019877c81a32f6c97256d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Aug 2018 23:47:37 -1100 Subject: [PATCH 137/186] Fix bid fill --- src/cc/CCassetsCore.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index da505db9c..9ef08348e 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -58,16 +58,20 @@ bool ValidateBidRemainder(int64_t remaining_units,int64_t remaining_nValue,int64 } else { - unitprice = (orig_nValue * COIN) / totalunits; - recvunitprice = (received_nValue * COIN) / paidunits; + //unitprice = (orig_nValue * COIN) / totalunits; + //recvunitprice = (received_nValue * COIN) / paidunits; + //if ( remaining_units != 0 ) + // newunitprice = (remaining_nValue * COIN) / remaining_units; + unitprice = (orig_nValue / totalunits); + recvunitprice = (received_nValue / paidunits); if ( remaining_units != 0 ) - newunitprice = (remaining_nValue * COIN) / remaining_units; + newunitprice = (remaining_nValue / remaining_units); if ( recvunitprice < unitprice ) { - fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + fprintf(stderr,"error recvunitprice %.16f < %.16f unitprice, new unitprice %.16f\n",(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); return(false); } - fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN*COIN),(double)unitprice/(COIN*COIN),(double)newunitprice/(COIN*COIN)); + fprintf(stderr,"orig %llu total %llu, recv %llu paid %llu,recvunitprice %.16f >= %.16f unitprice, new unitprice %.16f\n",(long long)orig_nValue,(long long)totalunits,(long long)received_nValue,(long long)paidunits,(double)recvunitprice/(COIN),(double)unitprice/(COIN),(double)newunitprice/(COIN)); } return(true); } @@ -89,8 +93,10 @@ bool SetBidFillamounts(int64_t &received_nValue,int64_t &remaining_units,int64_t return(true); } remaining_units = (totalunits - paidunits); - unitprice = (orig_nValue * COIN) / totalunits; - received_nValue = (paidunits * unitprice) / COIN; + //unitprice = (orig_nValue * COIN) / totalunits; + //received_nValue = (paidunits * unitprice) / COIN; + unitprice = (orig_nValue / totalunits); + received_nValue = (paidunits * unitprice); if ( unitprice > 0 && received_nValue > 0 && received_nValue <= orig_nValue ) { remaining_nValue = (orig_nValue - received_nValue); From f6160f58c13f4979c25e7b70f7a7d2ad310efd98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Aug 2018 01:06:06 -1100 Subject: [PATCH 138/186] Add rpc error checking --- src/wallet/rpcwallet.cpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5c16c3b9c..977aee98d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5441,6 +5441,11 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); std::vector pubkey(ParseHex(params[1].get_str().c_str())); amount = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || amount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = AssetTransfer(0,tokenid,pubkey,amount); if ( hex.size() > 0 ) { @@ -5463,6 +5468,11 @@ UniValue tokenbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[1].get_str().c_str()); price = atof(params[2].get_str().c_str()); bidamount = (price * numtokens) * COIN + 0.0000000049999; + if ( tokenid == zeroid || tokenid == zeroid || price <= 0 || bidamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CreateBuyOffer(0,bidamount,tokenid,numtokens); if ( hex.size() > 0 ) { @@ -5483,6 +5493,11 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); + if ( tokenid == zeroid || bidtxid == zeroid ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CancelBuyOffer(0,tokenid,bidtxid); if ( hex.size() > 0 ) { @@ -5504,6 +5519,11 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); fillamount = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || bidtxid == zeroid || fillamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = FillBuyOffer(0,tokenid,bidtxid,fillamount); if ( hex.size() > 0 ) { @@ -5526,6 +5546,11 @@ UniValue tokenask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[1].get_str().c_str()); price = atof(params[2].get_str().c_str()); askamount = (price * numtokens) * COIN + 0.0000000049999; + if ( tokenid == zeroid || numtokens <= 0 || price <= 0 || askamount <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CreateSell(0,numtokens,tokenid,askamount); if ( hex.size() > 0 ) { @@ -5537,7 +5562,6 @@ UniValue tokenask(const UniValue& params, bool fHelp) UniValue tokenswapask(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t askamount,numtokens; std::string hex; double price; uint256 tokenid,otherid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenswapask numtokens tokenid otherid price\n"); @@ -5570,18 +5594,22 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); + if ( tokenid == zeroid || asktxid == zeroid ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = CancelSell(0,tokenid,asktxid); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt cancel bid")); + } else result.push_back(Pair("error", "couldnt cancel ask")); return(result); } UniValue tokenfillask(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); @@ -5592,6 +5620,11 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); fillunits = atol(params[2].get_str().c_str()); + if ( tokenid == zeroid || asktxid == zeroid || fillunits <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } hex = FillSell(0,tokenid,zeroid,asktxid,fillunits); if ( hex.size() > 0 ) { @@ -5603,7 +5636,6 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) UniValue tokenfillswap(const UniValue& params, bool fHelp) { - static uint256 zeroid; UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,otherid,asktxid; if ( fHelp || params.size() != 4 ) throw runtime_error("tokenfillswap tokenid otherid asktxid fillunits\n"); From 4d47fcb9371c24507109c4427f870dcc3653db91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Aug 2018 01:07:44 -1100 Subject: [PATCH 139/186] Create nonzero tokens --- src/wallet/rpcwallet.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 977aee98d..1597051f2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5411,6 +5411,11 @@ UniValue tokencreate(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); name = params[0].get_str(); supply = atof(params[1].get_str().c_str()) * COIN; + if ( name.size() == 0 || supply <= 0 ) + { + result.push_back(Pair("error", "invalid parameter")); + return(result); + } if ( params.size() == 3 ) { description = params[2].get_str(); From 8a3e1884d6a97dccffd3e90ffa8d288152485005 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 16 Aug 2018 17:17:54 +0200 Subject: [PATCH 140/186] More token tests and more error checking and better errors from internals --- qa/rpc-tests/cryptoconditions.py | 50 ++++++++++++++++-- src/cc/CCassetstx.cpp | 12 +++-- src/wallet/rpcwallet.cpp | 90 +++++++++++--------------------- 3 files changed, 86 insertions(+), 66 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 8cfa4fd2a..68b381272 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -12,6 +12,12 @@ from test_framework.util import assert_equal, assert_greater_than, \ import time from decimal import Decimal +def assert_success(result): + assert_equal(result['result'], 'success') + +def assert_error(result): + assert_equal(result['result'], 'error') + class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): @@ -148,8 +154,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenaddress(self.pubkey) assert_equal(result['result'], 'success') for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']: - assert_equal(result[x][0], 'R') - + assert_equal(result[x][0], 'R') # there are no tokens created yet result = rpc.tokenlist() assert_equal(result, []) @@ -174,8 +179,47 @@ class CryptoConditionsTest (BitcoinTestFramework): # this is not a valid assetid result = rpc.tokeninfo(self.pubkey) - assert_equal(result['result'], 'error') + assert_error(result) + # invalid numtokens + result = rpc.tokenask("-1", tokenid, "1") + assert_error(result) + + # invalid numtokens + result = rpc.tokenask("0", tokenid, "1") + assert_error(result) + + # invalid price + result = rpc.tokenask("1", tokenid, "-1") + assert_error(result) + + # invalid price + result = rpc.tokenask("1", tokenid, "0") + assert_error(result) + + # invalid tokenid + result = rpc.tokenask("100", "deadbeef", "1") + assert_error(result) + + # valid + result = rpc.tokenask("100", tokenid, "7.77") + assert_success(result) + tokenaskhex = result['hex'] + assert tokenaskhex, "got tokenask hexk" + tokenaskid = self.send_and_mine(result['hex']) + + + # invalid fillunits + result = rpc.tokenfillask(tokenid, tokenaskid, "0") + assert_error(result) + + # invalid fillunits + result = rpc.tokenfillask(tokenid, tokenaskid, "-777") + assert_error(result) + + # should this pass or fail? + result = rpc.tokenfillask(tokenid, tokenaskid, "10") + #assert_success(result) def run_rewards_tests(self): rpc = self.nodes[0] diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index bfd51f4b7..40d76370c 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -14,6 +14,7 @@ ******************************************************************************/ #include "CCassets.h" +extern std::string CCerror; int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { @@ -427,12 +428,14 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector origpubkey; double dprice; uint64_t mask; int32_t askvout=0; int64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C; if ( fillunits < 0 ) { - fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits); + CCerror = strprintf("negative fillunits %lld\n",(long long)fillunits); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( assetid2 != zeroid ) { - fprintf(stderr,"asset swaps disabled\n"); + CCerror = "asset swaps disabled"; + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } @@ -474,7 +477,10 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt if ( CCchange != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk)); return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey))); - } else fprintf(stderr,"filltx not enough utxos\n"); + } else { + CCerror = strprintf("filltx not enough utxos"); + fprintf(stderr,"%s\n", CCerror.c_str()); + } } } return(""); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cbd08dd6c..0775842a2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -38,8 +38,7 @@ #include -#define ERR_RESULT(x) result.push_back(Pair("result", "error")); \ - result.push_back(Pair("error", x)); +#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); using namespace std; @@ -52,7 +51,6 @@ uint32_t komodo_segid32(char *coinaddr); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; -//TODO: find a better place for this std::string CCerror; // Private method: @@ -5002,7 +5000,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards funding transaction")); + } else ERR_RESULT("couldnt create rewards funding transaction"); return(result); } @@ -5024,14 +5022,8 @@ UniValue rewardslock(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "couldnt create rewards lock transaction")); - } - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "amount must be positive")); - } + } else ERR_RESULT( "couldnt create rewards lock transaction"); + } else ERR_RESULT("amount must be positive"); return(result); } @@ -5080,16 +5072,11 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) else memset(&txid,0,sizeof(txid)); hex = RewardsUnlock(0,name,fundingtxid,txid); if (CCerror != "") { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", CCerror)); - } else if ( hex.size() > 0 ) - { + ERR_RESULT(CCerror); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "couldnt create rewards unlock transaction")); - } + } else ERR_RESULT("couldnt create rewards unlock transaction"); return(result); } @@ -5181,14 +5168,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "couldnt create faucet funding transaction")); - } - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "funding amount must be positive")); - } + } else ERR_RESULT("couldnt create faucet funding transaction"); + } else ERR_RESULT( "funding amount must be positive"); return(result); } @@ -5205,10 +5186,7 @@ UniValue faucetget(const UniValue& params, bool fHelp) if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "couldnt create faucet get transaction")); - } + } else ERR_RESULT("couldnt create faucet get transaction"); return(result); } @@ -5229,14 +5207,12 @@ UniValue dicefund(const UniValue& params, bool fHelp) timeoutblocks = atol(params[5].get_str().c_str()); hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks); if (CCerror != "") { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", CCerror)); + ERR_RESULT(CCerror); } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); } else { - result.push_back(Pair("error", "couldnt create dice funding transaction")); - result.push_back(Pair("result", "error")); + ERR_RESULT( "couldnt create dice funding transaction"); } return(result); } @@ -5256,19 +5232,12 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp) if ( amount > 0 ) { hex = DiceAddfunding(0,name,fundingtxid,amount); if (CCerror != "") { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", CCerror)); + ERR_RESULT(CCerror); } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "couldnt create dice addfunding transaction")); - } - } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "amount must be positive")); - } + } else ERR_RESULT("couldnt create dice addfunding transaction"); + } else ERR_RESULT("amount must be positive"); return(result); } @@ -5291,9 +5260,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else { - ERR_RESULT("couldnt create faucet get transaction"); - } + } else ERR_RESULT("couldnt create faucet get transaction"); } else { ERR_RESULT("amount and odds must be positive"); } @@ -5317,7 +5284,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create dicefinish transaction")); + } else ERR_RESULT( "couldnt create dicefinish transaction"); return(result); } @@ -5457,7 +5424,7 @@ UniValue tokencreate(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create transaction")); + } else ERR_RESULT("couldnt create transaction"); return(result); } @@ -5479,7 +5446,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt transfer assets")); + } else ERR_RESULT("couldnt transfer assets"); } else { ERR_RESULT("amount must be positive"); } @@ -5528,7 +5495,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt cancel bid")); + } else ERR_RESULT("couldnt cancel bid"); return(result); } @@ -5549,7 +5516,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt fill bid")); + } else ERR_RESULT("couldnt fill bid"); return(result); } @@ -5572,7 +5539,7 @@ UniValue tokenask(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create ask")); + } else ERR_RESULT("couldnt create ask"); } else { ERR_RESULT("price and numtokens must be positive"); } @@ -5600,7 +5567,7 @@ UniValue tokenswapask(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create swap")); + } else ERR_RESULT("couldnt create swap"); } else { ERR_RESULT("price and numtokens must be positive"); } @@ -5623,7 +5590,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt cancel bid")); + } else ERR_RESULT("couldnt cancel bid"); return(result); } @@ -5642,11 +5609,14 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) fillunits = atol(params[2].get_str().c_str()); hex = FillSell(0,tokenid,zeroid,asktxid,fillunits); if (fillunits > 0) { - if ( hex.size() > 0) - { + if (CCerror != "") { + ERR_RESULT(CCerror); + } else if ( hex.size() > 0) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt fill bid"); + } else { + ERR_RESULT("couldnt fill bid"); + } } else { ERR_RESULT("fillunits must be positive"); } From 79887a0987e71877e81b1d88343a5a95af0eb6d9 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Thu, 16 Aug 2018 18:52:04 -0300 Subject: [PATCH 141/186] replace malloc in CC with calloc --- src/cryptoconditions/src/cryptoconditions.c | 6 +----- src/cryptoconditions/src/ed25519.c | 6 +++--- src/cryptoconditions/src/eval.c | 2 +- src/cryptoconditions/src/json_rpc.c | 5 +---- src/cryptoconditions/src/prefix.c | 2 +- src/cryptoconditions/src/utils.c | 12 ++++++------ 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 3c0e9ea2c..b58d7a70c 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -29,11 +29,7 @@ #include "src/json_rpc.c" #include -#ifdef __LP64__ #include -#else -#include // Index into CTransaction.vjoinsplit -#endif struct CCType *CCTypeRegistry[] = { @@ -199,7 +195,7 @@ CC *fulfillmentToCC(Fulfillment_t *ffill) { CC *cc_readFulfillmentBinary(const unsigned char *ffill_bin, size_t ffill_bin_len) { CC *cond = 0; - unsigned char *buf = malloc(ffill_bin_len); + unsigned char *buf = calloc(1,ffill_bin_len); Fulfillment_t *ffill = 0; asn_dec_rval_t rval = ber_decode(0, &asn_DEF_Fulfillment, (void **)&ffill, ffill_bin, ffill_bin_len); if (rval.code != RC_OK) { diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c index 6cdd80d1d..d7ebb085e 100644 --- a/src/cryptoconditions/src/ed25519.c +++ b/src/cryptoconditions/src/ed25519.c @@ -62,7 +62,7 @@ static int ed25519Sign(CC *cond, CCVisitor visitor) { if (cond->type->typeId != CC_Ed25519Type.typeId) return 1; CCEd25519SigningData *signing = (CCEd25519SigningData*) visitor.context; if (0 != memcmp(cond->publicKey, signing->pk, 32)) return 1; - if (!cond->signature) cond->signature = malloc(64); + if (!cond->signature) cond->signature = calloc(1,64); ed25519_sign(cond->signature, visitor.msg, visitor.msgLength, signing->pk, signing->skpk); signing->nSigned++; @@ -141,9 +141,9 @@ static void ed25519ToJSON(const CC *cond, cJSON *params) { static CC *ed25519FromFulfillment(const Fulfillment_t *ffill) { CC *cond = cc_new(CC_Ed25519); - cond->publicKey = malloc(32); + cond->publicKey = calloc(1,32); memcpy(cond->publicKey, ffill->choice.ed25519Sha256.publicKey.buf, 32); - cond->signature = malloc(64); + cond->signature = calloc(1,64); memcpy(cond->signature, ffill->choice.ed25519Sha256.signature.buf, 64); return cond; } diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c index a2bac4c51..df0f1af5d 100644 --- a/src/cryptoconditions/src/eval.c +++ b/src/cryptoconditions/src/eval.c @@ -68,7 +68,7 @@ static CC *evalFromFulfillment(const Fulfillment_t *ffill) { OCTET_STRING_t octets = eval->code; cond->codeLength = octets.size; - cond->code = malloc(octets.size); + cond->code = calloc(1,octets.size); memcpy(cond->code, octets.buf, octets.size); return cond; diff --git a/src/cryptoconditions/src/json_rpc.c b/src/cryptoconditions/src/json_rpc.c index 63b5909da..73377af50 100644 --- a/src/cryptoconditions/src/json_rpc.c +++ b/src/cryptoconditions/src/json_rpc.c @@ -17,11 +17,8 @@ #include "internal.h" #include -#ifdef __LP64__ #include -#else -#include // Index into CTransaction.vjoinsplit -#endif + static cJSON *jsonCondition(CC *cond) { cJSON *root = cJSON_CreateObject(); diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c index 97a9d1074..bebebba6e 100644 --- a/src/cryptoconditions/src/prefix.c +++ b/src/cryptoconditions/src/prefix.c @@ -26,7 +26,7 @@ struct CCType CC_PrefixType; static int prefixVisitChildren(CC *cond, CCVisitor visitor) { size_t prefixedLength = cond->prefixLength + visitor.msgLength; - unsigned char *prefixed = malloc(prefixedLength); + unsigned char *prefixed = calloc(1,prefixedLength); memcpy(prefixed, cond->prefix, cond->prefixLength); memcpy(prefixed + cond->prefixLength, visitor.msg, visitor.msgLength); visitor.msg = prefixed; diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c index 623331ff7..c98c6d17d 100644 --- a/src/cryptoconditions/src/utils.c +++ b/src/cryptoconditions/src/utils.c @@ -39,7 +39,7 @@ static int mod_table[] = {0, 2, 1}; void build_decoding_table() { - decoding_table = malloc(256); + decoding_table = calloc(1,256); for (int i = 0; i < 64; i++) decoding_table[(unsigned char) encoding_table[i]] = i; } @@ -49,7 +49,7 @@ unsigned char *base64_encode(const unsigned char *data, size_t input_length) { size_t output_length = 4 * ((input_length + 2) / 3); - unsigned char *encoded_data = malloc(output_length + 1); + unsigned char *encoded_data = calloc(1,output_length + 1); if (encoded_data == NULL) return NULL; for (int i = 0, j = 0; i < input_length;) { @@ -90,7 +90,7 @@ unsigned char *base64_decode(const unsigned char *data_, size_t input_length = strlen(data_); int rem = input_length % 4; - unsigned char *data = malloc(input_length + (4-rem)); + unsigned char *data = calloc(1,input_length + (4-rem)); strcpy(data, data_); // for unpadded b64 @@ -111,7 +111,7 @@ unsigned char *base64_decode(const unsigned char *data_, if (data[input_length - 1] == '=') (*output_length)--; if (data[input_length - 2] == '=') (*output_length)--; - unsigned char *decoded_data = malloc(*output_length); + unsigned char *decoded_data = calloc(1,*output_length); if (decoded_data == NULL) return NULL; for (int i = 0, j = 0; i < input_length;) { @@ -217,7 +217,7 @@ unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp) fprintf(stderr, "Encoding fingerprint failed\n"); return 0; } - unsigned char *hash = malloc(32); + unsigned char *hash = calloc(1,32); sha256(buf, rc.encoded, hash); return hash; } @@ -225,7 +225,7 @@ unsigned char *hashFingerprintContents(asn_TYPE_descriptor_t *asnType, void *fp) char* cc_hex_encode(const uint8_t *bin, size_t len) { - char* hex = malloc(len*2+1); + char* hex = calloc(1,len*2+1); if (bin == NULL) return hex; char map[16] = "0123456789ABCDEF"; for (int i=0; i Date: Fri, 17 Aug 2018 13:24:32 -0300 Subject: [PATCH 142/186] fix crash #1 on osx --- src/cryptoconditions/src/internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index e027176ee..5a9da13c0 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -56,8 +56,8 @@ typedef struct CCType { /* * Globals */ -struct CCType *CCTypeRegistry[32]; -int CCTypeRegistryLength; +extern struct CCType *CCTypeRegistry[16]; +extern int CCTypeRegistryLength; /* From bc3299692696f425219929a91a7e236a1918625c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Aug 2018 23:02:49 -1100 Subject: [PATCH 143/186] Reduce faucetget opreturn size, add rewards recover funds mode --- src/cc/faucet.cpp | 7 +++-- src/cc/rewards.cpp | 77 ++++++++++++++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 0ab51ff13..1ac601e64 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -170,7 +170,7 @@ int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; int32_t i,j,len; uint8_t buf[32768]; bits256 hash; + CMutableTransaction mtx,tmpmtx; CPubKey mypk,faucetpk; int64_t inputs,CCchange=0,nValue=FAUCETSIZE; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -184,10 +184,11 @@ std::string FaucetGet(uint64_t txfee) mtx.vout.push_back(MakeCC1vout(EVAL_FAUCET,CCchange,faucetpk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - for (i=0; i<1000000; i++) + j = rand() & 0xfffffff; + for (i=0; i<1000000; i++,j++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << mypk << i)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_FAUCET << (uint8_t)'G' << j)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 2f924e993..5bb7fec1b 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -241,17 +241,27 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t case 'U': //vin.0: locked funds CC vout.0 from lock //vin.1+: funding CC vout.0 from 'F' and 'A' and 'U' - //vout.0: funding CC change + //vout.0: funding CC change or recover normal payout //vout.1: normal output to unlock address //vout.n-1: opreturn 'U' sbits fundingtxid + if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("always should find vin.0, but didnt"); for (i=0; iismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("always should find vin.0, but didnt"); - else if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( numvouts == 1 && numvins == 1 ) + { + if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) + return eval->Invalid("unlock recover tx vout.0 is not normal output"); + else if ( tx.vout[0].scriptPubKey != vinTx.vout[1].scriptPubKey ) + return eval->Invalid("unlock recover tx vout.0 mismatched scriptPubKey"); + else if ( tx.vout[0].nValue > vinTx.vout[0].nValue ) + return eval->Invalid("unlock recover tx vout.0 mismatched amounts"); + else return(true); + } + if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("lock tx vout.0 is normal output"); else if ( tx.vout.size() < 3 ) return eval->Invalid("unlock tx not enough vouts"); @@ -541,9 +551,9 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t deposit) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; - if ( deposit < 0 ) + if ( deposit < txfee ) { - fprintf(stderr,"negative parameter error\n"); + fprintf(stderr,"deposit amount less than txfee\n"); return(""); } cp = CCinit(&C,EVAL_REWARDS); @@ -614,31 +624,46 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 return(""); } } - if ( amount > 0) { - reward= RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); - if (scriptPubKey.size() > 0) { - if (reward > txfee) { - if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) { - if ( inputs >= (reward + 2*txfee) ) - CCchange = (inputs - (reward + txfee)); - fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk)); - mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey)); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); + if ( amount > txfee ) + { + reward = RewardsCalc(amount,mtx.vin[0].prevout.hash,APR,minseconds,maxseconds,mindeposit); + if ( scriptPubKey.size() > 0 ) + { + if ( reward > txfee ) + { + if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + { + if ( inputs >= (reward + 2*txfee) ) + CCchange = (inputs - (reward + txfee)); + fprintf(stderr,"inputs %.8f CCchange %.8f amount %.8f reward %.8f\n",(double)inputs/COIN,(double)CCchange/COIN,(double)amount/COIN,(double)reward/COIN); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,rewardspk)); + mtx.vout.push_back(CTxOut(amount+reward,scriptPubKey)); + return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); + } + else + { + mtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); + //CCerror = "cant find enough rewards inputs"; + fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(rewards+txfee)/COIN); + return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); + } } - CCerror = "cant find enough rewards inputs"; - fprintf(stderr,"%s\n", CCerror.c_str()); - } else { + else + { CCerror = strprintf("reward %.8f is <= the transaction fee", reward); fprintf(stderr,"%s\n", CCerror.c_str()); - } - } else { + } + } + else + { CCerror = "invalid scriptPubKey"; fprintf(stderr,"%s\n", CCerror.c_str()); - } - } else { - CCerror = "amount must be positive"; - fprintf(stderr,"%s\n", CCerror.c_str()); + } + } + else + { + CCerror = "amount must be more than txfee"; + fprintf(stderr,"%s\n", CCerror.c_str()); } fprintf(stderr,"amount %.8f -> reward %.8f\n",(double)amount/COIN,(double)reward/COIN); return(""); From 276c654852c43c953183e93e73b8dd4bcd00fb7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Aug 2018 23:40:12 -1100 Subject: [PATCH 144/186] -s --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 5bb7fec1b..efb47fdb3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -644,7 +644,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 { mtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); //CCerror = "cant find enough rewards inputs"; - fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(rewards+txfee)/COIN); + fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(reward+txfee)/COIN); return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); } } From 9c5c9f0b9d7667630a1ff9079594bc868a5f8d2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 00:11:27 -1100 Subject: [PATCH 145/186] +prints --- src/cc/CCutils.cpp | 2 +- src/cc/eval.cpp | 2 +- src/cryptoconditions/src/internal.h | 2 +- src/cryptoconditions/src/utils.c | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 8cb06ab25..785e9d952 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -260,7 +260,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) // return(true); - //fprintf(stderr,"process CC %02x\n",cp->evalcode); + fprintf(stderr,"process CC %02x\n",cp->evalcode); if ( paramsNull.size() != 0 ) // Don't expect params return eval->Invalid("Cannot have params"); else if ( ctx.vout.size() == 0 ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 95f5c33de..949728be4 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -38,7 +38,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) pthread_mutex_lock(&KOMODO_CC_mutex); bool out = eval->Dispatch(cond, tx, nIn); pthread_mutex_unlock(&KOMODO_CC_mutex); - //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); + fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); assert(eval->state.IsValid() == out); if (eval->state.IsValid()) return true; diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index 5a9da13c0..8082f9b75 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -56,7 +56,7 @@ typedef struct CCType { /* * Globals */ -extern struct CCType *CCTypeRegistry[16]; +extern struct CCType *CCTypeRegistry[]; extern int CCTypeRegistryLength; diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c index c98c6d17d..25783ddfc 100644 --- a/src/cryptoconditions/src/utils.c +++ b/src/cryptoconditions/src/utils.c @@ -137,6 +137,7 @@ unsigned char *base64_decode(const unsigned char *data_, void base64_cleanup() { free(decoding_table); + decoding_table = 0; } From 007cc1f99686876edf97c481135836a20b690016 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 00:33:08 -1100 Subject: [PATCH 146/186] Remove trailing / in depends --- depends/packages/googletest.mk | 2 +- depends/packages/libevent.mk | 2 +- depends/packages/libgmp.mk | 4 ++-- depends/packages/librustzcash.mk | 2 +- depends/packages/libsodium.mk | 2 +- depends/packages/zeromq.mk | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/depends/packages/googletest.mk b/depends/packages/googletest.mk index 1275593f5..409c83a1b 100644 --- a/depends/packages/googletest.mk +++ b/depends/packages/googletest.mk @@ -1,6 +1,6 @@ package=googletest $(package)_version=1.8.0 -$(package)_download_path=https://github.com/google/$(package)/archive/ +$(package)_download_path=https://github.com/google/$(package)/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=release-$($(package)_version).tar.gz $(package)_sha256_hash=58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba51450db7d8 diff --git a/depends/packages/libevent.mk b/depends/packages/libevent.mk index 2a1125fda..ffe6f7e79 100644 --- a/depends/packages/libevent.mk +++ b/depends/packages/libevent.mk @@ -1,6 +1,6 @@ package=libevent $(package)_version=2.1.8 -$(package)_download_path=https://github.com/libevent/libevent/archive/ +$(package)_download_path=https://github.com/libevent/libevent/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=release-$($(package)_version)-stable.tar.gz $(package)_sha256_hash=316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index d8e41573a..c62fa18ed 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -1,7 +1,7 @@ package=libgmp ifeq ($(host_os),mingw32) -$(package)_download_path=https://github.com/joshuayabut/$(package)/archive/ +$(package)_download_path=https://github.com/joshuayabut/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=193836c1acc9dc00fe2521205d7bbe1ba13263f6cbef6f02584bf6f8b34b108f @@ -9,7 +9,7 @@ $(package)_git_commit=053c03b1cab347671d936f43ef66b48ab5e380ee $(package)_dependencies= $(package)_config_opts=--enable-cxx --disable-shared else ifeq ($(build_os),darwin) -$(package)_download_path=https://github.com/ca333/$(package)/archive/ +$(package)_download_path=https://github.com/ca333/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=59b2c2b5d58fdf5943bfde1fa709e9eb53e7e072c9699d28dc1c2cbb3c8cc32c diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index 20126776a..689082f8f 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -1,6 +1,6 @@ package=librustzcash $(package)_version=0.1 -$(package)_download_path=https://github.com/zcash/$(package)/archive/ +$(package)_download_path=https://github.com/zcash/$(package)/archive $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz $(package)_sha256_hash=a5760a90d4a1045c8944204f29fa2a3cf2f800afee400f88bf89bbfe2cce1279 diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index efa5d90de..67e096fae 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -9,7 +9,7 @@ $(package)_config_opts= else package=libsodium $(package)_version=1.0.15 -$(package)_download_path=https://download.libsodium.org/libsodium/releases/ +$(package)_download_path=https://download.libsodium.org/libsodium/releases $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4 $(package)_dependencies= diff --git a/depends/packages/zeromq.mk b/depends/packages/zeromq.mk index 850cce778..66e491ffb 100644 --- a/depends/packages/zeromq.mk +++ b/depends/packages/zeromq.mk @@ -1,6 +1,6 @@ ifeq ($(host_os),mingw32) $(package)_version=4.2.2-1 -$(package)_download_path=https://github.com/ca333/libzmq/archive/ +$(package)_download_path=https://github.com/ca333/libzmq/archive $(package)_download_file=v$($(package)_version).tar.gz $(package)_file_name=libzmq-$($(package)_version).tar.gz $(package)_sha256_hash=0e225b85ce11be23bf7eb7d3f25c6686728bf30d5c31f61c12d37bb646c69962 From 6252e12f176b6d3f083a81a34bed1f0042298415 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 00:54:53 -1100 Subject: [PATCH 147/186] +print --- src/script/interpreter.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 4295d4ddc..e33930624 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -952,7 +952,7 @@ bool EvalScript( if (stack.size() < 2) return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); - +fprintf(stderr,"check cryptocondition\n"); int fResult = checker.CheckCryptoCondition(stacktop(-1), stacktop(-2), script, consensusBranchId); if (fResult == -1) { return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT); @@ -1313,14 +1313,14 @@ int TransactionSignatureChecker::CheckCryptoCondition( } catch (logic_error ex) { return 0; } - //int32_t z; uint8_t *ptr; - //ptr = (uint8_t *)scriptCode.data(); - //for (z=0; zCheckEvalCondition(cond); @@ -1328,7 +1328,7 @@ int TransactionSignatureChecker::CheckCryptoCondition( int out = cc_verify(cond, (const unsigned char*)&sighash, 32, 0, condBin.data(), condBin.size(), eval, (void*)this); - //fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); + fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); cc_free(cond); return out; } From 64836d75a01a5fc106e17eeec10bfae3ddea6dcf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 01:11:31 -1100 Subject: [PATCH 148/186] +print --- src/script/interpreter.cpp | 1 + src/script/serverchecker.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index e33930624..e12e3a457 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1323,6 +1323,7 @@ int TransactionSignatureChecker::CheckCryptoCondition( fprintf(stderr," sighash nIn.%d nHashType.%d %.8f id.%d\n",(int32_t)nIn,(int32_t)nHashType,(double)amount/COIN,(int32_t)consensusBranchId); VerifyEval eval = [] (CC *cond, void *checker) { + fprintf(stderr,"checker.%p\n",(TransactionSignatureChecker*)checker); return ((TransactionSignatureChecker*)checker)->CheckEvalCondition(cond); }; diff --git a/src/script/serverchecker.cpp b/src/script/serverchecker.cpp index 4de69001a..4451ab485 100644 --- a/src/script/serverchecker.cpp +++ b/src/script/serverchecker.cpp @@ -102,5 +102,6 @@ bool ServerTransactionSignatureChecker::VerifySignature(const std::vector Date: Sat, 18 Aug 2018 01:27:42 -1100 Subject: [PATCH 149/186] +print --- src/cryptoconditions/src/cryptoconditions.c | 5 +++++ src/script/interpreter.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index b58d7a70c..011995566 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -232,12 +232,15 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, const unsigned char *condBin, size_t condBinLength, VerifyEval verifyEval, void *evalContext) { unsigned char targetBinary[1000]; + fprintf(stderr,"in cc_verify cond.%p msg.%p[%d] dohash.%d condbin.%p[%d]\n",cond,msg,(int32_t)msgLength,doHashMsg,condBin,(int32_t)condBinLength); const size_t binLength = cc_conditionBinary(cond, targetBinary); if (0 != memcmp(condBin, targetBinary, binLength)) { + fprintf(stderr,"cc_verify error A\n"); return 0; } if (!cc_ed25519VerifyTree(cond, msg, msgLength)) { + fprintf(stderr,"cc_verify error B\n"); return 0; } @@ -246,10 +249,12 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, else memcpy(msgHash, msg, 32); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { + fprintf(stderr,"cc_verify error C\n"); return 0; } if (!cc_verifyEval(cond, verifyEval, evalContext)) { + fprintf(stderr,"cc_verify error D\n"); return 0; } return 1; diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index e12e3a457..c9bf1b1ab 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1326,7 +1326,7 @@ int TransactionSignatureChecker::CheckCryptoCondition( fprintf(stderr,"checker.%p\n",(TransactionSignatureChecker*)checker); return ((TransactionSignatureChecker*)checker)->CheckEvalCondition(cond); }; - + fprintf(stderr,"non-checker path\n"); int out = cc_verify(cond, (const unsigned char*)&sighash, 32, 0, condBin.data(), condBin.size(), eval, (void*)this); fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); From dc71c17e6f387359a6cb4830362b89c81043dc6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 01:35:48 -1100 Subject: [PATCH 150/186] +prints --- src/cryptoconditions/src/cryptoconditions.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 011995566..488581e2a 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -117,14 +117,20 @@ uint32_t fromAsnSubtypes(const ConditionTypes_t types) { size_t cc_conditionBinary(const CC *cond, unsigned char *buf) { + fprintf(stderr,"inside cc_conditionBinary\n"); Condition_t *asn = calloc(1, sizeof(Condition_t)); + fprintf(stderr,"asn.%p\n",asn); asnCondition(cond, asn); + fprintf(stderr,"call derencode\n"); asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000); + fprintf(stderr,"back from derencode\n"); if (rc.encoded == -1) { fprintf(stderr, "CONDITION NOT ENCODED\n"); return 0; } + fprintf(stderr,"call ASN_STRUCT_FREE\n"); ASN_STRUCT_FREE(asn_DEF_Condition, asn); + fprintf(stderr,"return rc.encoded %d\n",(int32_t)rc.encoded); return rc.encoded; } From ebd4cace15b5e86eed68488bb4565b31d1d307f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 01:36:50 -1100 Subject: [PATCH 151/186] +print --- src/cryptoconditions/src/cryptoconditions.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 488581e2a..0ee535e2d 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -244,25 +244,29 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, fprintf(stderr,"cc_verify error A\n"); return 0; } - + fprintf(stderr,"after memcmp\n"); if (!cc_ed25519VerifyTree(cond, msg, msgLength)) { fprintf(stderr,"cc_verify error B\n"); return 0; } + fprintf(stderr,"after cc_ed25519VerifyTree\n"); unsigned char msgHash[32]; if (doHashMsg) sha256(msg, msgLength, msgHash); else memcpy(msgHash, msg, 32); + fprintf(stderr,"after memcpy/sha256\n"); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { fprintf(stderr,"cc_verify error C\n"); return 0; } + fprintf(stderr,"after cc_secp256k1VerifyTreeMsg32\n"); if (!cc_verifyEval(cond, verifyEval, evalContext)) { fprintf(stderr,"cc_verify error D\n"); return 0; } + fprintf(stderr,"return 1\n"); return 1; } From 0545c2cd9555d1c86b69b81cf6289ff9f07869fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 01:42:35 -1100 Subject: [PATCH 152/186] Next layer --- src/cryptoconditions/src/cryptoconditions.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 0ee535e2d..9ccb987fb 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -153,12 +153,15 @@ void asnCondition(const CC *cond, Condition_t *asn) { // This may look a little weird - we dont have a reference here to the correct // union choice for the condition type, so we just assign everything to the threshold // type. This works out nicely since the union choices have the same binary interface. - + fprintf(stderr,"asnCondition type.%p\n",asn->type); CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256; choice->cost = cc_getCost(cond); + fprintf(stderr,"after cost\n"); choice->fingerprint.buf = cond->type->fingerprint(cond); choice->fingerprint.size = 32; + fprintf(stderr,"after fingerprint\n"); choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond)); + fprintf(stderr,"after asnSubtypes\n"); } From 9178b67d65e83cfbed524cec46d8485dbbbde9f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 01:48:16 -1100 Subject: [PATCH 153/186] Fix --- src/cryptoconditions/src/cryptoconditions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index 9ccb987fb..c132b4870 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -153,7 +153,7 @@ void asnCondition(const CC *cond, Condition_t *asn) { // This may look a little weird - we dont have a reference here to the correct // union choice for the condition type, so we just assign everything to the threshold // type. This works out nicely since the union choices have the same binary interface. - fprintf(stderr,"asnCondition type.%p\n",asn->type); + fprintf(stderr,"asnCondition type.%p\n",cond->type); CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256; choice->cost = cc_getCost(cond); fprintf(stderr,"after cost\n"); From a57cea0bee671a68b2eda52d76d3a71f505d4869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 02:54:51 -1100 Subject: [PATCH 154/186] Fingerprint prints --- src/cryptoconditions/src/anon.c | 1 + src/cryptoconditions/src/cryptoconditions.c | 3 +-- src/cryptoconditions/src/ed25519.c | 1 + src/cryptoconditions/src/eval.c | 1 + src/cryptoconditions/src/prefix.c | 1 + src/cryptoconditions/src/preimage.c | 1 + src/cryptoconditions/src/secp256k1.c | 1 + src/cryptoconditions/src/threshold.c | 1 + 8 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cryptoconditions/src/anon.c b/src/cryptoconditions/src/anon.c index 43e96ae44..8c2b9cea6 100644 --- a/src/cryptoconditions/src/anon.c +++ b/src/cryptoconditions/src/anon.c @@ -55,6 +55,7 @@ static void anonToJSON(const CC *cond, cJSON *params) { static unsigned char *anonFingerprint(const CC *cond) { unsigned char *out = calloc(1, 32); + fprintf(stderr,"anon fingerprint %p %p\n",out,cond->fingerprint); memcpy(out, cond->fingerprint, 32); return out; } diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index c132b4870..fe277904e 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -71,8 +71,7 @@ char *cc_conditionUri(const CC *cond) { unsigned char *encoded = base64_encode(fp, 32); unsigned char *out = calloc(1, 1000); - sprintf(out, "ni:///sha-256;%s?fpt=%s&cost=%lu", - encoded, cc_typeName(cond), cc_getCost(cond)); + sprintf(out, "ni:///sha-256;%s?fpt=%s&cost=%lu",encoded, cc_typeName(cond), cc_getCost(cond)); if (cond->type->getSubtypes) { appendUriSubtypes(cond->type->getSubtypes(cond), out); diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c index d7ebb085e..8d4046241 100644 --- a/src/cryptoconditions/src/ed25519.c +++ b/src/cryptoconditions/src/ed25519.c @@ -27,6 +27,7 @@ struct CCType CC_Ed25519Type; static unsigned char *ed25519Fingerprint(const CC *cond) { Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t)); + fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32); return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp); } diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c index df0f1af5d..a3e773699 100644 --- a/src/cryptoconditions/src/eval.c +++ b/src/cryptoconditions/src/eval.c @@ -27,6 +27,7 @@ struct CCType CC_EvalType; static unsigned char *evalFingerprint(const CC *cond) { unsigned char *hash = calloc(1, 32); + fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code); sha256(cond->code, cond->codeLength, hash); return hash; } diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c index bebebba6e..ec961a939 100644 --- a/src/cryptoconditions/src/prefix.c +++ b/src/cryptoconditions/src/prefix.c @@ -39,6 +39,7 @@ static int prefixVisitChildren(CC *cond, CCVisitor visitor) { static unsigned char *prefixFingerprint(const CC *cond) { PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t)); + fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix); asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety fp->maxMessageLength = cond->maxMessageLength; OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength); diff --git a/src/cryptoconditions/src/preimage.c b/src/cryptoconditions/src/preimage.c index 8902817dd..3b1a1cf2e 100644 --- a/src/cryptoconditions/src/preimage.c +++ b/src/cryptoconditions/src/preimage.c @@ -46,6 +46,7 @@ static unsigned long preimageCost(const CC *cond) { static unsigned char *preimageFingerprint(const CC *cond) { unsigned char *hash = calloc(1, 32); + fprintf(stderr,"preimage %p %p\n",hash,cond->preimage); sha256(cond->preimage, cond->preimageLength, hash); return hash; } diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 78b9c4e9e..cbf4dfd32 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -73,6 +73,7 @@ void initVerify() { static unsigned char *secp256k1Fingerprint(const CC *cond) { Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t)); + fprintf(stderr,"secpfinger %p %p\n",fp,cond->publicKey); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE); return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp); } diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c index 88d4e7f50..0ac2b0dad 100644 --- a/src/cryptoconditions/src/threshold.c +++ b/src/cryptoconditions/src/threshold.c @@ -86,6 +86,7 @@ static int cmpConditionBin(const void *a, const void *b) { static unsigned char *thresholdFingerprint(const CC *cond) { /* Create fingerprint */ ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t)); + fprintf(stderr,"thresholdfinger %p\n",fp); fp->threshold = cond->threshold; for (int i=0; isize; i++) { Condition_t *asnCond = asnConditionNew(cond->subconditions[i]); From b626aafeb041db7f68faea47c23478e834bec15c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 03:01:37 -1100 Subject: [PATCH 155/186] Smaller buf --- src/cryptoconditions/src/internal.h | 2 +- src/cryptoconditions/src/secp256k1.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index 8082f9b75..3010a0bb2 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -28,7 +28,7 @@ extern "C" { #endif -#define BUF_SIZE 1024 * 1024 +#define BUF_SIZE 65536 // does it really need to be 1 MB?? 1024 * 1024 typedef char bool; diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index cbf4dfd32..75d7f2690 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -73,8 +73,9 @@ void initVerify() { static unsigned char *secp256k1Fingerprint(const CC *cond) { Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t)); - fprintf(stderr,"secpfinger %p %p\n",fp,cond->publicKey); + fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE); + fprintf(stderr,"got octet\n"); return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp); } From b4795ed684e6cff5ada8bada1b40f3ab750d766d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 03:07:53 -1100 Subject: [PATCH 156/186] -prints --- src/cc/CCutils.cpp | 2 +- src/cc/eval.cpp | 2 +- src/cryptoconditions/src/cryptoconditions.c | 17 +---------------- src/cryptoconditions/src/ed25519.c | 2 +- src/cryptoconditions/src/eval.c | 2 +- src/cryptoconditions/src/prefix.c | 2 +- src/cryptoconditions/src/preimage.c | 2 +- src/cryptoconditions/src/secp256k1.c | 3 +-- src/cryptoconditions/src/threshold.c | 2 +- src/script/interpreter.cpp | 12 ++++++------ 10 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 785e9d952..8cb06ab25 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -260,7 +260,7 @@ bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector param //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) // return(true); - fprintf(stderr,"process CC %02x\n",cp->evalcode); + //fprintf(stderr,"process CC %02x\n",cp->evalcode); if ( paramsNull.size() != 0 ) // Don't expect params return eval->Invalid("Cannot have params"); else if ( ctx.vout.size() == 0 ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 949728be4..b6fcf57dd 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -38,7 +38,7 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) pthread_mutex_lock(&KOMODO_CC_mutex); bool out = eval->Dispatch(cond, tx, nIn); pthread_mutex_unlock(&KOMODO_CC_mutex); - fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); + //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); assert(eval->state.IsValid() == out); if (eval->state.IsValid()) return true; diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index fe277904e..c9a4b27df 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -116,20 +116,14 @@ uint32_t fromAsnSubtypes(const ConditionTypes_t types) { size_t cc_conditionBinary(const CC *cond, unsigned char *buf) { - fprintf(stderr,"inside cc_conditionBinary\n"); Condition_t *asn = calloc(1, sizeof(Condition_t)); - fprintf(stderr,"asn.%p\n",asn); asnCondition(cond, asn); - fprintf(stderr,"call derencode\n"); asn_enc_rval_t rc = der_encode_to_buffer(&asn_DEF_Condition, asn, buf, 1000); - fprintf(stderr,"back from derencode\n"); if (rc.encoded == -1) { fprintf(stderr, "CONDITION NOT ENCODED\n"); return 0; } - fprintf(stderr,"call ASN_STRUCT_FREE\n"); ASN_STRUCT_FREE(asn_DEF_Condition, asn); - fprintf(stderr,"return rc.encoded %d\n",(int32_t)rc.encoded); return rc.encoded; } @@ -152,15 +146,11 @@ void asnCondition(const CC *cond, Condition_t *asn) { // This may look a little weird - we dont have a reference here to the correct // union choice for the condition type, so we just assign everything to the threshold // type. This works out nicely since the union choices have the same binary interface. - fprintf(stderr,"asnCondition type.%p\n",cond->type); CompoundSha256Condition_t *choice = &asn->choice.thresholdSha256; choice->cost = cc_getCost(cond); - fprintf(stderr,"after cost\n"); choice->fingerprint.buf = cond->type->fingerprint(cond); choice->fingerprint.size = 32; - fprintf(stderr,"after fingerprint\n"); choice->subtypes = asnSubtypes(cond->type->getSubtypes(cond)); - fprintf(stderr,"after asnSubtypes\n"); } @@ -240,35 +230,30 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, const unsigned char *condBin, size_t condBinLength, VerifyEval verifyEval, void *evalContext) { unsigned char targetBinary[1000]; - fprintf(stderr,"in cc_verify cond.%p msg.%p[%d] dohash.%d condbin.%p[%d]\n",cond,msg,(int32_t)msgLength,doHashMsg,condBin,(int32_t)condBinLength); + //fprintf(stderr,"in cc_verify cond.%p msg.%p[%d] dohash.%d condbin.%p[%d]\n",cond,msg,(int32_t)msgLength,doHashMsg,condBin,(int32_t)condBinLength); const size_t binLength = cc_conditionBinary(cond, targetBinary); if (0 != memcmp(condBin, targetBinary, binLength)) { fprintf(stderr,"cc_verify error A\n"); return 0; } - fprintf(stderr,"after memcmp\n"); if (!cc_ed25519VerifyTree(cond, msg, msgLength)) { fprintf(stderr,"cc_verify error B\n"); return 0; } - fprintf(stderr,"after cc_ed25519VerifyTree\n"); unsigned char msgHash[32]; if (doHashMsg) sha256(msg, msgLength, msgHash); else memcpy(msgHash, msg, 32); - fprintf(stderr,"after memcpy/sha256\n"); if (!cc_secp256k1VerifyTreeMsg32(cond, msgHash)) { fprintf(stderr,"cc_verify error C\n"); return 0; } - fprintf(stderr,"after cc_secp256k1VerifyTreeMsg32\n"); if (!cc_verifyEval(cond, verifyEval, evalContext)) { fprintf(stderr,"cc_verify error D\n"); return 0; } - fprintf(stderr,"return 1\n"); return 1; } diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c index 8d4046241..4fb3bbb8d 100644 --- a/src/cryptoconditions/src/ed25519.c +++ b/src/cryptoconditions/src/ed25519.c @@ -27,7 +27,7 @@ struct CCType CC_Ed25519Type; static unsigned char *ed25519Fingerprint(const CC *cond) { Ed25519FingerprintContents_t *fp = calloc(1, sizeof(Ed25519FingerprintContents_t)); - fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey); + //fprintf(stderr,"ed25519 fingerprint %p %p\n",fp,cond->publicKey); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, 32); return hashFingerprintContents(&asn_DEF_Ed25519FingerprintContents, fp); } diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c index a3e773699..544f6dd54 100644 --- a/src/cryptoconditions/src/eval.c +++ b/src/cryptoconditions/src/eval.c @@ -27,7 +27,7 @@ struct CCType CC_EvalType; static unsigned char *evalFingerprint(const CC *cond) { unsigned char *hash = calloc(1, 32); - fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code); + //fprintf(stderr,"evalfingerprint %p %p\n",hash,cond->code); sha256(cond->code, cond->codeLength, hash); return hash; } diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c index ec961a939..626fc5992 100644 --- a/src/cryptoconditions/src/prefix.c +++ b/src/cryptoconditions/src/prefix.c @@ -39,7 +39,7 @@ static int prefixVisitChildren(CC *cond, CCVisitor visitor) { static unsigned char *prefixFingerprint(const CC *cond) { PrefixFingerprintContents_t *fp = calloc(1, sizeof(PrefixFingerprintContents_t)); - fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix); + //fprintf(stderr,"prefixfinger %p %p\n",fp,cond->prefix); asnCondition(cond->subcondition, &fp->subcondition); // TODO: check asnCondition for safety fp->maxMessageLength = cond->maxMessageLength; OCTET_STRING_fromBuf(&fp->prefix, cond->prefix, cond->prefixLength); diff --git a/src/cryptoconditions/src/preimage.c b/src/cryptoconditions/src/preimage.c index 3b1a1cf2e..7c8e56996 100644 --- a/src/cryptoconditions/src/preimage.c +++ b/src/cryptoconditions/src/preimage.c @@ -46,7 +46,7 @@ static unsigned long preimageCost(const CC *cond) { static unsigned char *preimageFingerprint(const CC *cond) { unsigned char *hash = calloc(1, 32); - fprintf(stderr,"preimage %p %p\n",hash,cond->preimage); + //fprintf(stderr,"preimage %p %p\n",hash,cond->preimage); sha256(cond->preimage, cond->preimageLength, hash); return hash; } diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 75d7f2690..c1eb82765 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -73,9 +73,8 @@ void initVerify() { static unsigned char *secp256k1Fingerprint(const CC *cond) { Secp256k1FingerprintContents_t *fp = calloc(1, sizeof(Secp256k1FingerprintContents_t)); - fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE); + //fprintf(stderr,"secpfinger %p %p size %d vs %d\n",fp,cond->publicKey,(int32_t)sizeof(Secp256k1FingerprintContents_t),(int32_t)SECP256K1_PK_SIZE); OCTET_STRING_fromBuf(&fp->publicKey, cond->publicKey, SECP256K1_PK_SIZE); - fprintf(stderr,"got octet\n"); return hashFingerprintContents(&asn_DEF_Secp256k1FingerprintContents, fp); } diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c index 0ac2b0dad..13c3fdab3 100644 --- a/src/cryptoconditions/src/threshold.c +++ b/src/cryptoconditions/src/threshold.c @@ -86,7 +86,7 @@ static int cmpConditionBin(const void *a, const void *b) { static unsigned char *thresholdFingerprint(const CC *cond) { /* Create fingerprint */ ThresholdFingerprintContents_t *fp = calloc(1, sizeof(ThresholdFingerprintContents_t)); - fprintf(stderr,"thresholdfinger %p\n",fp); + //fprintf(stderr,"thresholdfinger %p\n",fp); fp->threshold = cond->threshold; for (int i=0; isize; i++) { Condition_t *asnCond = asnConditionNew(cond->subconditions[i]); diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index c9bf1b1ab..c2e02ad25 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -952,7 +952,7 @@ bool EvalScript( if (stack.size() < 2) return set_error(serror, SCRIPT_ERR_INVALID_STACK_OPERATION); -fprintf(stderr,"check cryptocondition\n"); +//fprintf(stderr,"check cryptocondition\n"); int fResult = checker.CheckCryptoCondition(stacktop(-1), stacktop(-2), script, consensusBranchId); if (fResult == -1) { return set_error(serror, SCRIPT_ERR_CRYPTOCONDITION_INVALID_FULFILLMENT); @@ -1313,7 +1313,7 @@ int TransactionSignatureChecker::CheckCryptoCondition( } catch (logic_error ex) { return 0; } - int32_t z; uint8_t *ptr; + /*int32_t z; uint8_t *ptr; ptr = (uint8_t *)scriptCode.data(); for (z=0; zCheckEvalCondition(cond); }; - fprintf(stderr,"non-checker path\n"); + //fprintf(stderr,"non-checker path\n"); int out = cc_verify(cond, (const unsigned char*)&sighash, 32, 0, condBin.data(), condBin.size(), eval, (void*)this); - fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); + //fprintf(stderr,"out.%d from cc_verify\n",(int32_t)out); cc_free(cond); return out; } From 7b257028f8be580b1219c7fabd23adf54d4a75b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 03:09:36 -1100 Subject: [PATCH 157/186] Test --- src/cryptoconditions/src/cryptoconditions.c | 2 +- src/script/serverchecker.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index c9a4b27df..b9b08af20 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -251,7 +251,7 @@ int cc_verify(const struct CC *cond, const unsigned char *msg, size_t msgLength, } if (!cc_verifyEval(cond, verifyEval, evalContext)) { - fprintf(stderr,"cc_verify error D\n"); + //fprintf(stderr,"cc_verify error D\n"); return 0; } return 1; diff --git a/src/script/serverchecker.cpp b/src/script/serverchecker.cpp index 4451ab485..e82fd3a81 100644 --- a/src/script/serverchecker.cpp +++ b/src/script/serverchecker.cpp @@ -102,6 +102,6 @@ bool ServerTransactionSignatureChecker::VerifySignature(const std::vector Date: Sat, 18 Aug 2018 03:19:28 -1100 Subject: [PATCH 158/186] Reduce BUF_SIZE --- src/cryptoconditions/src/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index 3010a0bb2..41080186e 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -28,7 +28,7 @@ extern "C" { #endif -#define BUF_SIZE 65536 // does it really need to be 1 MB?? 1024 * 1024 +#define BUF_SIZE 4096 typedef char bool; From 093487f6f0242a850f955493e6d75f839bf89f58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:09:51 -1100 Subject: [PATCH 159/186] Fix not enough rewards case --- src/cc/rewards.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index efb47fdb3..3674ac42b 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -631,7 +631,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 { if ( reward > txfee ) { - if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) > 0 ) + if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) >= reward+txfee ) { if ( inputs >= (reward + 2*txfee) ) CCchange = (inputs - (reward + txfee)); From 8b10fb48e0fd8b03ce35dcbb1983a7f59d573c3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:32:42 -1100 Subject: [PATCH 160/186] Handle partial but not enough rewards funding --- src/cc/rewards.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 3674ac42b..696867596 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -262,9 +262,9 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t else return(true); } if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("lock tx vout.0 is normal output"); - else if ( tx.vout.size() < 3 ) - return eval->Invalid("unlock tx not enough vouts"); + return eval->Invalid("unlock tx vout.0 is normal output"); + else if ( numvouts != 3 ) + return eval->Invalid("unlock tx wrong number of vouts"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("unlock tx vout.0 is normal output"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -277,6 +277,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return false; else if ( tx.vout[1].nValue > amount+reward ) return eval->Invalid("unlock tx vout.1 isnt amount+reward"); + else if ( tx.vout[2].nValue > 0 ) + return eval->Invalid("unlock tx vout.2 isnt 0"); preventCCvouts = 1; break; } @@ -587,7 +589,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; @@ -631,6 +633,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 { if ( reward > txfee ) { + firstmtx = mtx; if ( (inputs= AddRewardsInputs(ignore,0,cp,mtx,rewardspk,reward+txfee,30,sbits,fundingtxid)) >= reward+txfee ) { if ( inputs >= (reward + 2*txfee) ) @@ -642,10 +645,10 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 } else { - mtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); + firstmtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); //CCerror = "cant find enough rewards inputs"; fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(reward+txfee)/COIN); - return(FinalizeCCTx(-1LL,cp,mtx,mypk,txfee,opret)); + return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,opret)); } } else From de70190c2a310584fabeec4136e418c13c363265 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:40:23 -1100 Subject: [PATCH 161/186] Add opret --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 696867596..e34b8908f 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -589,7 +589,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; + CMutableTransaction mtx,firstmtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; @@ -648,7 +648,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 firstmtx.vout.push_back(CTxOut(amount-txfee,scriptPubKey)); //CCerror = "cant find enough rewards inputs"; fprintf(stderr,"not enough rewards funds to payout %.8f, recover mode tx\n",(double)(reward+txfee)/COIN); - return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,opret)); + return(FinalizeCCTx(-1LL,cp,firstmtx,mypk,txfee,EncodeRewardsOpRet('U',sbits,fundingtxid))); } } else From eb69e5cee62fe65e3dd32996f6a0c554d8e4fea2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:54:03 -1100 Subject: [PATCH 162/186] Windows rag --- src/cryptoconditions/src/secp256k1.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index c1eb82765..6b616705b 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -46,6 +46,12 @@ void lockSign() { fclose(fp); #endif if (read != 32) { +#ifdef _WIN32 + int32_t i; + for (i=0; i<32; i++) + ((uint8_t *)ent)[i] = rand(); + fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); +#endif fprintf(stderr, "Could not read 32 bytes entropy from system\n"); exit(1); } From 9f545d8eb3febdbdb5595415f2a82635ca4fd301 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 04:55:02 -1100 Subject: [PATCH 163/186] Fix --- src/cryptoconditions/src/secp256k1.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index 6b616705b..b3e198945 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -51,9 +51,10 @@ void lockSign() { for (i=0; i<32; i++) ((uint8_t *)ent)[i] = rand(); fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); -#endif +#else fprintf(stderr, "Could not read 32 bytes entropy from system\n"); exit(1); +#endif } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); From 96e1505ec8737bb501b946af2d3cc7648e4a4a38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 05:00:51 -1100 Subject: [PATCH 164/186] Allow weaker rand() for in memory values --- src/cryptoconditions/src/secp256k1.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index b3e198945..a95895fa4 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -45,16 +45,11 @@ void lockSign() { int read = (int) fread(&ent, 1, 32, fp); fclose(fp); #endif - if (read != 32) { -#ifdef _WIN32 + if (read != 32) + { int32_t i; for (i=0; i<32; i++) ((uint8_t *)ent)[i] = rand(); - fprintf(stderr,"@libscott plz make this a high entropy for windows\n"); -#else - fprintf(stderr, "Could not read 32 bytes entropy from system\n"); - exit(1); -#endif } if (!secp256k1_context_randomize(ec_ctx_sign, ent)) { fprintf(stderr, "Could not randomize secp256k1 context\n"); From 799f664f5f2a6b68d9a4ced0a3bfdc27a6b6240a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 18 Aug 2018 05:05:47 -1100 Subject: [PATCH 165/186] Fix --- src/cc/rewards.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index e34b8908f..61bcf5ca3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -251,7 +251,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t if ( (*cp->ismyvin)(tx.vin[i].scriptSig) == 0 ) return eval->Invalid("unexpected normal vin for unlock"); } - if ( numvouts == 1 && numvins == 1 ) + if ( numvouts == 2 && numvins == 1 ) { if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0 ) return eval->Invalid("unlock recover tx vout.0 is not normal output"); @@ -259,6 +259,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock recover tx vout.0 mismatched scriptPubKey"); else if ( tx.vout[0].nValue > vinTx.vout[0].nValue ) return eval->Invalid("unlock recover tx vout.0 mismatched amounts"); + else if ( tx.vout[1].nValue > 0 ) + return eval->Invalid("unlock recover tx vout.1 nonz amount"); else return(true); } if ( vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) From 8b26f1169c439e76ae4511cd3fcd90610b1fdfbe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:28:41 -1100 Subject: [PATCH 166/186] KOMODO_CONNECTING --- src/cc/CCinclude.h | 1 + src/cc/CCutils.cpp | 1 + src/komodo_globals.h | 2 +- src/main.cpp | 4 +++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3954068e1..761e64bcd 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -28,6 +28,7 @@ #include #include +extern int32_t KOMODO_CONNECTING; #define SMALLVAL 0.000000000000001 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 8cb06ab25..073c2b508 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,6 +256,7 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 86c168a85..5971e31cc 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/main.cpp b/src/main.cpp index 6dcd6b13b..7a0b0a250 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,7 +56,7 @@ using namespace std; CCriticalSection cs_main; extern uint8_t NOTARY_PUBKEY33[33]; -extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC; +extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING; int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); @@ -3448,6 +3448,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * return AbortNode(state, "Failed to read block"); pblock = █ } + KOMODO_CONNECTING = (int32_t)pindexNew->nHeight; // Get the current commitment tree ZCIncrementalMerkleTree oldTree; assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), oldTree)); @@ -3458,6 +3459,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * { CCoinsViewCache view(pcoinsTip); bool rv = ConnectBlock(*pblock, state, pindexNew, view, false, true); + KOMODO_CONNECTING = -1; GetMainSignals().BlockChecked(*pblock, state); if (!rv) { if (state.IsInvalid()) From 0bfdfaef027b56abf4d7c74d55bedd9fa480a1f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:34:46 -1100 Subject: [PATCH 167/186] Set KOMODO_CONNECTING from accepttomempool --- src/main.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7a0b0a250..b36e5ad82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1263,7 +1263,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; - int nextBlockHeight = chainActive.Height() + 1; + int flag=0,nextBlockHeight = chainActive.Height() + 1; auto consensusBranchId = CurrentEpochBranchId(nextBlockHeight, Params().GetConsensus()); // Node operator can choose to reject tx by number of transparent inputs @@ -1283,11 +1283,19 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); } + if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) + { + flag = 1; + KOMODO_CONNECTING = (int32_t)chainActive.LastTip()->nHeight + 1; + } if (!CheckTransaction(tx, state, verifier)) { - + if ( flag != 0 ) + KOMODO_CONNECTING = -1; return error("AcceptToMemoryPool: CheckTransaction failed"); } + if ( flag != 0 ) + KOMODO_CONNECTING = -1; // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) From ad274d5be87bc4a5f1b1ca28d00e095cdf25e96e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 04:40:37 -1100 Subject: [PATCH 168/186] Test --- src/cc/CCutils.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 073c2b508..bdeb93481 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,6 +256,8 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation + return(true); fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); From cd88cde2da53696542ae9e5d41899f6acb2aeae0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 06:37:46 -1100 Subject: [PATCH 169/186] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b36e5ad82..74037b65b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1286,7 +1286,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { flag = 1; - KOMODO_CONNECTING = (int32_t)chainActive.LastTip()->nHeight + 1; + KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!CheckTransaction(tx, state, verifier)) { From cb5763f0096a84ae26c759772f7d361ff5cf0052 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 06:53:50 -1100 Subject: [PATCH 170/186] Test --- src/cc/CCutils.cpp | 2 +- src/main.cpp | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index bdeb93481..61bebab40 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,9 +256,9 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; + fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/main.cpp b/src/main.cpp index 74037b65b..299906a9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1283,26 +1283,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); } - if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) - { - flag = 1; - KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; - } if (!CheckTransaction(tx, state, verifier)) { - if ( flag != 0 ) - KOMODO_CONNECTING = -1; return error("AcceptToMemoryPool: CheckTransaction failed"); } - if ( flag != 0 ) - KOMODO_CONNECTING = -1; // DoS level set to 10 to be more forgiving. // Check transaction contextually against the set of consensus rules which apply in the next block to be mined. if (!ContextualCheckTransaction(tx, state, nextBlockHeight, 10)) { return error("AcceptToMemoryPool: ContextualCheckTransaction failed"); } - + // Coinbase is only valid in a block, not as a loose transaction if (tx.IsCoinBase()) { @@ -1535,12 +1526,21 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // invalid blocks, however allowing such transactions into the mempool // can be exploited as a DoS attack. // XXX: is this neccesary for CryptoConditions? + if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) + { + flag = 1; + KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; + } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { + if ( flag != 0 ) + KOMODO_CONNECTING = -1; fprintf(stderr,"accept failure.10\n"); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } - + if ( flag != 0 ) + KOMODO_CONNECTING = -1; + // Store transaction in memory if ( komodo_is_notarytx(tx) == 0 ) KOMODO_ON_DEMAND++; From a409a6e419652bc09e9c0a48261bf7874b0903d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:02:12 -1100 Subject: [PATCH 171/186] Test --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 5971e31cc..2d64bc8fc 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; -int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING; +int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; From 1f5025d995902cbced16844c12b25bfb928c85f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:16:14 -1100 Subject: [PATCH 172/186] Handle out of order confirmed CC --- src/main.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 299906a9a..87e79eafc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4168,17 +4168,27 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // Check transactions if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { - CValidationState stateDummy; + CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); - for (int i = 0; i < block.vtx.size(); i++) + while ( 1 ) { - const CTransaction &tx = block.vtx[i]; - if (tx.IsCoinBase() != 0 ) - continue; - else if ( ASSETCHAINS_STAKED != 0 && (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) - continue; - AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL); - } + for (i=0; i Date: Sun, 19 Aug 2018 07:19:25 -1100 Subject: [PATCH 173/186] Test --- src/cc/CCinclude.h | 2 +- src/cc/dice.cpp | 2 +- src/main.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 761e64bcd..c12389275 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -60,7 +60,7 @@ bool GetAddressUnspent(uint160 addressHash, int type,std::vector 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 87e79eafc..2b239dcf3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1623,7 +1623,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx) +bool myAddtomempool(const CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) From 9a813a0441d30e1084fb3569b727caaf28eaaf5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 07:21:20 -1100 Subject: [PATCH 174/186] Test --- src/cc/CCinclude.h | 2 +- src/cc/dice.cpp | 2 +- src/main.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index c12389275..761e64bcd 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -60,7 +60,7 @@ bool GetAddressUnspent(uint160 addressHash, int type,std::vector 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 2b239dcf3..a2ec5cdb4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1623,7 +1623,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(const CTransaction &tx) +bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) @@ -4174,7 +4174,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 07:56:44 -1100 Subject: [PATCH 175/186] Fix --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a2ec5cdb4..8bf4f269b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4174,7 +4174,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 07:58:02 -1100 Subject: [PATCH 176/186] Syntax --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8bf4f269b..fba7193d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4174,12 +4174,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { for (i=0; i Date: Sun, 19 Aug 2018 08:42:57 -1100 Subject: [PATCH 177/186] Change mempool print --- src/cc/CCutils.cpp | 10 ++++++++-- src/main.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 61bebab40..54a9a0225 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -255,10 +255,16 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { - CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; - fprintf(stderr,"KOMODO_CONNECTING.%d\n",KOMODO_CONNECTING); + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); + height = KOMODO_CONNECTING; + if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) + { + from_mempool = 1; + height &= ((1<<30) - 1); + } + fprintf(stderr,"KOMODO_CONNECTING.%d mempool.%d\n",height,from_mempool); // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/main.cpp b/src/main.cpp index fba7193d0..5c2e02e54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1529,7 +1529,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if ( KOMODO_CONNECTING <= 0 && chainActive.LastTip() != 0 ) { flag = 1; - KOMODO_CONNECTING = 100000000 + (int32_t)chainActive.LastTip()->nHeight + 1; + KOMODO_CONNECTING = (1<<30) + (int32_t)chainActive.LastTip()->nHeight + 1; } if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { From 60a91e3bd4fc885d800b44cec8248c5f0539d11d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:04:01 -1100 Subject: [PATCH 178/186] Change dice odds > 1 to match industry method Get the first 5 nibbles < 1 million, mod it by 10000 and compare against 1000/(odds+1) --- src/cc/dice.cpp | 47 ++++++++++++++++++++++++++++++++++++-------- src/komodo_gateway.h | 1 + 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c2f055d8d..2616bd536 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -225,9 +225,14 @@ uint256 DiceHashEntropy(uint256 &entropy,uint256 _txidpriv) // max 1 vout per tx return(hentropy); } +int32_t dice_5nibbles(uint8_t *fivevals) +{ + return(((int32_t)fivevals[0]<<16) + ((int32_t)fivevals[1]<<12) + ((int32_t)fivevals[2]<<8) + ((int32_t)fivevals[3]<<4) + ((int32_t)fivevals[4])); +} + uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 hash,house,bettor; char str[65],str2[65]; int32_t i,modval; if ( odds < 10000 ) return(0); else odds -= 10000; @@ -247,11 +252,35 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t endiancpy(&buf[32],(uint8_t *)&houseentropy,32); vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); + winnings = 0; if ( odds > 1 ) - bettor = (bettor / arith_uint256(odds)); - if ( bettor >= house ) + { + //bettor = (bettor / arith_uint256(odds)); + endiancpy(buf,(uint8_t *)&house,32); + endiancpy(&buf[32],(uint8_t *)&bettor,32); + vcalc_sha256(0,(uint8_t *)&_hash,buf,64); + endiancpy(hash,_hash,32); + for (i=0; i<32; i++) + { + hash16[i<<1] = ((hash[i] >> 4) & 0x0f); + hash16[(i<<1) + 1] = (hash[i] & 0x0f); + } + modval = 0; + for (i=0; i<12; i++) + { + modval = dice_5nibbles(&hash16[i*5]); + if ( modval < 1000000 ) + { + modval %= 10000; + break; + } + } + fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)) + if ( modval < 10000/(odds+1) ) + winnings = bet * (odds+1); + } + else if ( bettor >= house ) winnings = bet * (odds+1); - else winnings = 0; return(winnings); } @@ -424,6 +453,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("cant find fundingtxid"); else if ( fundingTx.vout.size() > 0 && DecodeDiceFundingOpRet(fundingTx.vout[fundingTx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) != 'F' ) return eval->Invalid("fundingTx not valid"); + if ( maxodds > 9999 ) + return eval->Invalid("maxodds too big"); fundingPubKey = fundingTx.vout[1].scriptPubKey; switch ( funcid ) { @@ -838,9 +869,9 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 ) + if ( amount < 0 || maxodds < 1 || maxodds > 9999 ) { - fprintf(stderr,"negative parameter error\n"); + fprintf(stderr,"negative parameter or invalid maxodds error (limit 9999)\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -874,9 +905,9 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; - if ( bet < 0 || odds < 1 ) + if ( bet < 0 || odds < 1 || odds > 9999 ) { - fprintf(stderr,"negative parameter error\n"); + fprintf(stderr,"negative parameter or odds too big error\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6a8ef310b..20ece62d2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -755,6 +755,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( height > 1 && checktoshis == 0 ) { checktoshis = ((uint64_t)GetBlockSubsidy(height, Params().GetConsensus()) - block.vtx[0].vout[0].nValue); + //checktoshis += txn_count * 0.001; // rely on higher level validations to prevent emitting more coins than actual txfees } if ( height >= 2 && (overflow != 0 || total > checktoshis || strangeout != 0) ) { From cd98443d65ebc2d09a17b8a6ad0dc95e61b7082a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:06:59 -1100 Subject: [PATCH 179/186] Syntax --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2616bd536..0d7e168c3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -232,7 +232,7 @@ int32_t dice_5nibbles(uint8_t *fivevals) uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 hash,house,bettor; char str[65],str2[65]; int32_t i,modval; + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; if ( odds < 10000 ) return(0); else odds -= 10000; @@ -275,7 +275,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)) + fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 76b729d24639c0cd6c9ff26d023a5801053433a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:08:11 -1100 Subject: [PATCH 180/186] Fix --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0d7e168c3..e8d0678ce 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,6 +255,8 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + if ( odds > 9999 ) // shouldnt happen + return(0); //bettor = (bettor / arith_uint256(odds)); endiancpy(buf,(uint8_t *)&house,32); endiancpy(&buf[32],(uint8_t *)&bettor,32); @@ -275,7 +277,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - fprintf(stderr,"modval %d vs %d\n",modval,10000/(odds+1)); + fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From d2b767f71df0310161439e8ec4ebc11e33891021 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 19 Aug 2018 23:10:22 -1100 Subject: [PATCH 181/186] Test --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 5c2e02e54..51e53a742 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1535,7 +1535,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if ( flag != 0 ) KOMODO_CONNECTING = -1; - fprintf(stderr,"accept failure.10\n"); return error("AcceptToMemoryPool: BUG! PLEASE REPORT THIS! ConnectInputs failed against MANDATORY but not STANDARD flags %s", hash.ToString()); } if ( flag != 0 ) From bc3419f06d1ef275149940031b900f2c54d9c2be Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 02:26:42 -1100 Subject: [PATCH 182/186] Revert --- src/cc/dice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e8d0678ce..263b644ad 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,9 +255,14 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + { // old way + bettor = (bettor / arith_uint256(odds)); + if ( bettor >= house ) + winnings = bet * (odds+1); + return(winnings); + } if ( odds > 9999 ) // shouldnt happen return(0); - //bettor = (bettor / arith_uint256(odds)); endiancpy(buf,(uint8_t *)&house,32); endiancpy(&buf[32],(uint8_t *)&bettor,32); vcalc_sha256(0,(uint8_t *)&_hash,buf,64); From d930ed4f2e17faf5404051738e053c7bb3fdfc13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 02:27:11 -1100 Subject: [PATCH 183/186] Unrevert --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 263b644ad..b3115ab8f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,6 +255,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t winnings = 0; if ( odds > 1 ) { + if ( 0 ) { // old way bettor = (bettor / arith_uint256(odds)); if ( bettor >= house ) From 33f4e4925cdf9d048fc92c4748a94552af940dac Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 08:32:00 -1100 Subject: [PATCH 184/186] Fix maxodds check --- src/cc/dice.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b3115ab8f..03529b0ed 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -855,7 +855,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { fprintf(stderr,"negative parameter error\n"); return(""); @@ -877,13 +877,18 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 || maxodds < 1 || maxodds > 9999 ) + if ( amount < 0 || maxodds < 1 ) { - fprintf(stderr,"negative parameter or invalid maxodds error (limit 9999)\n"); + fprintf(stderr,"negative parameter\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); + if ( maxodds > 9999 ) + { + fprintf(stderr,"maxodds.%llu error (limit 9999)\n",(long long)maxodds); + return(""); + } scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { From e222a19d4b9bb42a3cd0df7875b69c5fd968e003 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 08:46:12 -1100 Subject: [PATCH 185/186] Fix maxodds check --- src/cc/dice.cpp | 7 +------ src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 03529b0ed..8da052c86 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -877,18 +877,13 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount) { CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; - if ( amount < 0 || maxodds < 1 ) + if ( amount < 0 ) { fprintf(stderr,"negative parameter\n"); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); - if ( maxodds > 9999 ) - { - fprintf(stderr,"maxodds.%llu error (limit 9999)\n",(long long)maxodds); - return(""); - } scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( 0 ) { diff --git a/src/main.cpp b/src/main.cpp index 51e53a742..47d5fb017 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4185,7 +4185,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } if ( rejects == 0 || rejects == lastrejects ) break; - fprintf(stderr,"addtomempool for CC checking: n.%d rejects.%d last.%d\n",(int32_t)block.vtx.size(),rejects,lastrejects); + fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0; } From 38b5d53f015a320b23853afc1d1f378495b20b36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 20 Aug 2018 21:41:20 -1100 Subject: [PATCH 186/186] +print --- src/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 47d5fb017..548ce2011 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4184,7 +4184,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C rejects++; } if ( rejects == 0 || rejects == lastrejects ) + { + if ( lastrejects != 0 ) + fprintf(stderr,"lastrejects.%d -> all tx in mempool\n",lastrejects); break; + } fprintf(stderr,"addtomempool ht.%d for CC checking: n.%d rejects.%d last.%d\n",height,(int32_t)block.vtx.size(),rejects,lastrejects); lastrejects = rejects; rejects = 0;