From 0a37f2072d7c3d28ca83f268670d4225ea706128 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 2 Jul 2018 23:36:33 +0200 Subject: [PATCH 001/623] add travis CI --- .travis.yml | 82 ----------------------------------------------------- 1 file changed, 82 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac331dcf9..250756396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -<<<<<<< HEAD language: cpp compiler: @@ -22,84 +21,3 @@ notifications: - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" - "Change view : %{compare_url}" - "Build details : %{build_url}" -======= -# errata: -# - A travis bug causes caches to trample eachother when using the same -# compiler key (which we don't use anyway). This is worked around for now by -# replacing the "compilers" with a build name prefixed by the no-op ":" -# command. See: https://github.com/travis-ci/travis-ci/issues/4393 -# - sudo/dist/group are set so as to get Blue Box VMs, necessary for [loopback] -# IPv6 support - -sudo: required -dist: precise -group: legacy - -os: linux -language: cpp -compiler: gcc -env: - global: - - MAKEJOBS=-j3 - - RUN_TESTS=false - - BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID - - CCACHE_SIZE=100M - - CCACHE_TEMPDIR=/tmp/.ccache-temp - - CCACHE_COMPRESS=1 - - BASE_OUTDIR=$TRAVIS_BUILD_DIR/out - - SDK_URL=https://bitcoincore.org/depends-sources/sdks - - PYTHON_DEBUG=1 - - WINEDEBUG=fixme-all -cache: - apt: true - directories: - - depends/built - - depends/sdk-sources - - $HOME/.ccache -matrix: - fast_finish: true - include: - - compiler: ": ARM" - env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python-zmq" PPA="ppa:chris-lea/zeromq" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" - - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc python-zmq" PPA="ppa:chris-lea/zeromq" DEP_OPTS="DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" - - compiler: ": No wallet" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Cross-Mac" - env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" BITCOIN_CONFIG="--enable-reduce-exports" OSX_SDK=10.9 GOAL="deploy" - exclude: - - compiler: gcc -install: - - if [ -n "$PACKAGES" ]; then sudo rm -f /etc/apt/sources.list.d/travis_ci_zeromq3-source.list; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi -before_script: - - unset CC; unset CXX - - mkdir -p depends/SDKs depends/sdk-sources - - if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS -script: - - if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi - - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST - - BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib" - - depends/$HOST/native/bin/ccache --max-size=$CCACHE_SIZE - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export CCACHE_READONLY=1; fi - - test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh - - ./configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make distdir PACKAGE=bitcoin VERSION=$HOST - - cd bitcoin-$HOST - - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib - - if [ "$RUN_TESTS" = "true" ]; then make check; fi - - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.sh; fi -after_script: - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi ->>>>>>> zcash/master From dfec6b538670091bec1d6fd2523a8624988a8c16 Mon Sep 17 00:00:00 2001 From: ca333 Date: Tue, 3 Jul 2018 19:27:05 +0200 Subject: [PATCH 002/623] update travisCI deployment --- .travis.yml | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 250756396..81c2092aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,33 @@ +dist: xenial language: cpp - compiler: - - gcc - +- gcc before_install: - - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa - - sudo apt-get update -qq - - sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate -#install: - -script: - - ./zcutil/build.sh -j 5 - +- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa +- sudo apt-get update -qq +- sudo apt-get install libgnutls28-dev +- sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev + m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils + automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate +script: +- "./zcutil/build.sh -j 5" notifications: irc: channels: - - "chat.freenode.net#komodoplatform" + - chat.freenode.net#komodoplatform template: - - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" - - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" - - "Change view : %{compare_url}" - - "Build details : %{build_url}" + - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" + - 'Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build + Time: %{duration}' + - 'Change view : %{compare_url}' + - 'Build details : %{build_url}' +before_deploy: + - git tag "$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)" +deploy: + provider: releases + api_key: + secure: oyMB9JDSoL/val/d80Em3sd3mSJY+PPkiclUb3ktizNz7DgYZbBiStUOZIJo95GUYADEvm9RVrP0JmBiDuqneEjfFRzME9/MnpY/LmRCiYGgprMDR80ZqbLgOzSKpE10RE2XM3vZkZeXT/JcGGayUm0faElep2qx62S4ozsAxSvFJ5l/PG+wEltrlnp1z8uYdXV3PBChbjzXJ0BdMVxMrrU39kwzqwu2Ge9PnNjVv0AVxn/oZpf+bzYa7vkSuGTRe2Jcs8U9AABYnZ22wu+tdlD76pdOJzGEwR70e8CjUJmdSn+M+wwAPPHStPW/JHFwSaWsKZtUyB5EWQW2kqq6P+M1Fe7yo6srznsaAcZRWeCrbUO/k44bEfnj7HMGmxfjDJOwbxVEoHg7im+l3HLUiG8rcw5dM/TAnrmgjH/OEj/EM1lbwV2C+PdDGOjdguljEhjBABGRbRABMZjwW8w+uBFVlKlcn7y+zJbMB3mGd+FNGo/OgAcsFzRcpaN8SrC/kzUF2SeEwJjTKvAqRgA66yl7CzDPBtUv2NtoPUz/8YO9rsdGElcWfmDIVacuIEjo1CizlbDzeS7zPiFPW5MRCGryLFLt0WjA/s8lkLO+DbGYXPa4rG6+7ZNUDLfziM+lFqZH8b382/bhv+a6ctpWjaazjiW6yWemsuN8QhByuGw= + file: src/komodod + skip_cleanup: true + on: + repo: KomodoPlatform/komodo From b310ffff5bfa1a0e84184e43f0a3cba33a48ec52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Jul 2018 09:50:49 -1100 Subject: [PATCH 003/623] Fix ac_private help --- src/wallet/rpcwallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a1773f43b..53086291a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1075,8 +1075,6 @@ UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp) UniValue movecmd(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1100,6 +1098,8 @@ UniValue movecmd(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1150,8 +1150,6 @@ UniValue movecmd(const UniValue& params, bool fHelp) UniValue sendfrom(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1181,6 +1179,8 @@ UniValue sendfrom(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("sendfrom", "\"tabby\", \"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.01, 6, \"donation\", \"seans outpost\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1217,8 +1217,6 @@ UniValue sendfrom(const UniValue& params, bool fHelp) UniValue sendmany(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1257,6 +1255,8 @@ UniValue sendmany(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\", 6, \"testing\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); From ac09a89f9764fb1ffc8bca5d87d2c7d153a3fdd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 03:54:47 -1100 Subject: [PATCH 004/623] Test --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8d1649d3b..f533b7761 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,9 +6826,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) + { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { + if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; From 20a1f68495067de1150a6d315c2351239c3857d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:01:37 -1100 Subject: [PATCH 005/623] +print --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f533b7761..93bcb0421 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,8 +6826,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. + fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { + fprintf(stderr,"check for asking initial headers: nSyncStarted.%d fFetch.%d\n",(int32_t)nSyncStarted,(int32_t)fFetch); // Only actively request headers from a single peer, unless we're close to today. if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { From 3a796a89aa1f0f0e13daa584d9137395eee11e4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:07:53 -1100 Subject: [PATCH 006/623] Prints --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 93bcb0421..c4cbcc751 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,16 +6826,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - fprintf(stderr,"see if can request\n"); + //fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { - fprintf(stderr,"check for asking initial headers: nSyncStarted.%d fFetch.%d\n",(int32_t)nSyncStarted,(int32_t)fFetch); // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ((nSyncStarted < 3 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pto->nStartingHeight,pindexStart->nHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 3df89af7feddbe125b7095aa69df42bb2c82c05d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:16:09 -1100 Subject: [PATCH 007/623] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c4cbcc751..e517d8a6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6830,7 +6830,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted < 3 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ((nSyncStarted < 30 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From 18c515eb032f5e1bfbc5405e6bf76699e8375a47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:20:21 -1100 Subject: [PATCH 008/623] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e517d8a6e..2b820f1b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6827,15 +6827,15 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. //fprintf(stderr,"see if can request\n"); - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted < 30 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( (nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pto->nStartingHeight,pindexStart->nHeight); + fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 8d124e7f5059d8e362892bba322996e040e5151a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:24:47 -1100 Subject: [PATCH 009/623] syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2b820f1b2..80d9e533f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6830,7 +6830,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { // Only actively request headers from a single peer, unless we're close to today. - if ( (nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From 7aa8bcb497e7acb230c7537574fd0b03fabd19e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:28:34 -1100 Subject: [PATCH 010/623] Syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 80d9e533f..a083f65e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6829,12 +6829,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle) //fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; // Only actively request headers from a single peer, unless we're close to today. if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); From 2a46683da275aa0cae25b366655fe9dc9a30903b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:32:12 -1100 Subject: [PATCH 011/623] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a083f65e3..89a0551dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6831,7 +6831,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) { CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; // Only actively request headers from a single peer, unless we're close to today. - if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( nSyncStarted < 3 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From e9b849601d3967fa11eedfa3ea882e40f3c905f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:27:09 -1100 Subject: [PATCH 012/623] Revert init headers tweaks --- src/main.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 89a0551dd..8d1649d3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,16 +6826,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - //fprintf(stderr,"see if can request\n"); - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) - { - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { // Only actively request headers from a single peer, unless we're close to today. - if ( nSyncStarted < 3 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) - { + if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; - fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 9c2f6f11bb3c45991e1b4a294aa0130b17404d76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:44:54 -1100 Subject: [PATCH 013/623] Work around inadvertent CPU mining --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5cd88d7de..0f49c3758 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1248,13 +1248,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; txn_count = pblock->vtx.size(); - if ( txn_count > 1 ) + if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + return(1); + if ( txn_count > 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) { if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } + // add strict check for 100% of vin -> vout txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) @@ -1265,7 +1268,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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 if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx + if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) From c6d2cccf9231989c5cd4b1fdbe08a98f6a282785 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:49:19 -1100 Subject: [PATCH 014/623] -print --- src/komodo_bitcoind.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0f49c3758..cfa4c7c33 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,7 +1257,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - // add strict check for 100% of vin -> vout txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) From feefa2d3201c11adb6957bb8bf7b2508ae0d3a07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:52:44 -1100 Subject: [PATCH 015/623] Vins == 1 check for staking utxo --- 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 cfa4c7c33..6aadde9b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1250,7 +1250,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ txn_count = pblock->vtx.size(); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) return(1); - if ( txn_count > 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) + if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) { From 6420c2d1c0ac052d40416ee8f73cf12e05785525 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:56:50 -1100 Subject: [PATCH 016/623] 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 6aadde9b8..0ca0bd123 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1248,8 +1248,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; txn_count = pblock->vtx.size(); - if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) @@ -1277,8 +1275,10 @@ 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); + } //else return(-1); } + if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + return(1); return(isPoS); } From d4acce54ac3df12a22c21e6f5229f0b9a7b99d6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:03:22 -1100 Subject: [PATCH 017/623] Test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ca0bd123..2374c3262 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1277,6 +1277,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); } //else return(-1); } + fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) return(1); return(isPoS); From 5c6adb31e91cac5f12be0b5beecc86d73ef136b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:06:07 -1100 Subject: [PATCH 018/623] 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 2374c3262..df0cc6baa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1275,7 +1275,7 @@ 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); + } else return(-1); } fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) From 764576d5e2ffeb4a84d9416606745475da35f483 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:11:06 -1100 Subject: [PATCH 019/623] Prepare for new isPoS --- 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 df0cc6baa..2374c3262 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1275,7 +1275,7 @@ 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); + } //else return(-1); } fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) From ffd6dd51965634aa9a02e74a79b87106a8737105 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:19:48 -1100 Subject: [PATCH 020/623] Fix isPoS detection --- 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 2374c3262..d459678f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,6 +1247,8 @@ 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) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; + if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + 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 ) { @@ -1277,9 +1279,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); } //else return(-1); } - fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); - if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); + //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); return(isPoS); } From 800b9aa7779cfd4a380f72026e723f63bd70979e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:32:30 -1100 Subject: [PATCH 021/623] No exemption for isPoS --- 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 d459678f9..88fea5e2b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,8 +1247,8 @@ 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) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); + //if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + // 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 a3d08df0fc90383a350e83efacf5c3a9a862ce17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:03:25 -1100 Subject: [PATCH 022/623] Prevent PoW in 100% PoS --- 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 88fea5e2b..acba52c7c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1352,7 +1352,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - else if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW + 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 ) { From 640b264174a72ad13e2139d073bb36fd4c2036f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:17:15 -1100 Subject: [PATCH 023/623] 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 acba52c7c..66076ac96 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1356,7 +1356,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! + if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! return(-1); else { From 6ac497242db9b056b3c18ac321dd4414224f1f12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:45:13 -1100 Subject: [PATCH 024/623] Ht.200 exemption --- 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 66076ac96..fa2bb3ba2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,8 +1247,8 @@ 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) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - //if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - // return(1); + if ( ASSETCHAINS_STAKED == 100 && height < 200 ) + 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 d6f8eeb965d75f13c771349632c2ed5084ed6bb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 21:48:08 -1100 Subject: [PATCH 025/623] Remove mindiff cap for 100% PoS --- src/coins.cpp | 2 +- src/komodo_bitcoind.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index b2d838506..38b105e9d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -466,7 +466,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = AccessCoins(prevout.hash); if (!coins || !coins->IsAvailable(prevout.n)) { - fprintf(stderr,"HaveInputs missing input %s/v%d\n",prevout.hash.ToString().c_str(),prevout.n); + //fprintf(stderr,"HaveInputs missing input %s/v%d\n",prevout.hash.ToString().c_str(),prevout.n); return false; } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fa2bb3ba2..113a470c2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1094,13 +1094,16 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+57; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + if ( ASSETCHAINS_STAKED != 100 || nHeight < 2000 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; From 99fb7ab30a79c9a65abc69e4bf9dc79c3dc28291 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 21:49:51 -1100 Subject: [PATCH 026/623] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8d1649d3b..d4dfae7ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1311,7 +1311,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa uint256 hash = tx.GetHash(); if (pool.exists(hash)) { - fprintf(stderr,"already in mempool\n"); + //fprintf(stderr,"already in mempool\n"); return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } From 99fbc8f0c0667c92a90e8fa41928efe7ac9b5404 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:01:16 -1100 Subject: [PATCH 027/623] -print --- 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 53086291a..67bafd32b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4605,7 +4605,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } if ( setAddress.size() ) From 1da1d6616340bc1722271b3a8ba770a81c2380de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:01:46 -1100 Subject: [PATCH 028/623] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 755b7439e..667e1a3c4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -432,7 +432,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } From 01e50e731f64dc48cf7c8aa5862aa8b9babb8f26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:02:31 -1100 Subject: [PATCH 029/623] +symbol --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 667e1a3c4..dcf22b1bd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1009,7 +1009,7 @@ void static BitcoinMiner() uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); - fprintf(stderr," mined block %d!\n",Mining_height); + fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height); } CValidationState state; if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) From d184dbb444a93b791f1323563b36708c521ab81b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 6 Jul 2018 04:07:07 -1100 Subject: [PATCH 030/623] Hash in utxo for PoS --- src/komodo_bitcoind.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 113a470c2..4f6b6e2fc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1114,7 +1114,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh pasthash = pindex->GetBlockHash(); memcpy(hashbuf,&pasthash,sizeof(pasthash)); memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); + if ( nHeight >= 2000 ) + { + memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); + } else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); for (iter=0; iter<3600; iter++) { From 049e24ce9e7e0528d1bbcf754bd5ecd71ce6ce86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:48:52 -1100 Subject: [PATCH 031/623] Test newstake --- src/komodo_bitcoind.h | 131 ++++++++++++++++++++++++++++++++++++++++-- src/miner.cpp | 2 + 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4f6b6e2fc..6f3af9d27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1086,9 +1086,131 @@ uint32_t komodo_segid32(char *coinaddr) return(addrhash.uints[0]); } +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; bits256 txid; int8_t segid = -1; + if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + { + 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 ) + { + txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; + vout = pblock->vtx[txn_count-1].vin[0].prevout.n; + 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 ) + { + segid = komodo_segid32(voutaddr) & 0x3f; + } + } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); + } + } + } + return(segid); +} + +int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) +{ + static uint8_t prevhashbuf[100]; static int32_t prevheight; + int32_t i; + if ( height == prevheight && n == 100 ) + memcpy(hashbuf,prevhashbuf,100); + else + { + memset(hashbuf,0xff,n); + for (i=0; i 6000 ) // about 100 blocks + minage = 6000; + pindex = 0; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + segid = ((nHeight + addrhash.uints[0]) & 0x3f); + komodo_segids(hashbuf,nHeight-101,100); + memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); + memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + for (iter=0; iter<3600; iter++) + { + diff = (iter + blocktime - txtime - minage); + if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; + coinage = (value * diff) * ((diff >> 16) + 1); + hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( hashval <= bnTarget ) + { + winner = 1; + if ( validateflag == 0 ) + { + blocktime += iter; + blocktime += segid * 2; + } + break; + } + if ( validateflag != 0 ) + { + /*for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs target "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ + break; + } + } + //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); + } + if ( nHeight < 10 ) + return(blocktime); + return(blocktime * winner); +} + uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + //if ( nHeight >= 4000 ) + return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) blocktime = prevtime+57; @@ -1120,18 +1242,19 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); } else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); for (iter=0; iter<3600; iter++) { diff = (iter + blocktime - txtime - minage); + if ( diff > 3600*24*30 ) + diff = 3600*24*30 if ( iter > 0 ) diff += iter + segid*2; - //if ( diff > 3600*24 ) - // break; if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; diff --git a/src/miner.cpp b/src/miner.cpp index dcf22b1bd..7bf93a8ed 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -920,6 +920,8 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + if ( Mining_height >= 4000 ) + HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) From 86f88c4f0c000fa72a46014b471e4af0e50a195f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:53:28 -1100 Subject: [PATCH 032/623] Syntax --- src/komodo_bitcoind.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6f3af9d27..b1656d09b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1088,21 +1088,21 @@ uint32_t komodo_segid32(char *coinaddr) 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; bits256 txid; int8_t segid = -1; + 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 ( komodo_blockload(block,pindex) == 0 ) { - 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 ) + txn_count = block.vtx.size(); + if ( txn_count > 1 && block.vtx[txn_count-1].vin.size() == 1 && block.vtx[txn_count-1].vout.size() == 1 ) { - txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; - vout = pblock->vtx[txn_count-1].vin[0].prevout.n; + txid = block.vtx[txn_count-1].vin[0].prevout.hash; + vout = block.vtx[txn_count-1].vin[0].prevout.n; txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) + if ( ExtractDestination(block.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 ) + if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; } @@ -1209,7 +1209,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - //if ( nHeight >= 4000 ) +//if ( nHeight >= 4000 ) return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) @@ -1248,7 +1248,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) - diff = 3600*24*30 + diff = 3600*24*30; if ( iter > 0 ) diff += iter + segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) From 4aef05c93fa6de279bfd21d10c7cafc27dcc3985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:56:53 -1100 Subject: [PATCH 033/623] Fix --- 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 b1656d09b..c981b20b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+60 ) blocktime = prevtime+60; From b7865ea8f39a9aec6189720e02cd57aa1752abb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 02:47:46 -1100 Subject: [PATCH 034/623] Newstake active at 4000 --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c981b20b7..787ba5f6b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1209,7 +1209,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; -//if ( nHeight >= 4000 ) + if ( nHeight >= 4000 ) return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 67bafd32b..2230a1aa7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4621,6 +4621,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt fprintf(stderr,"komodo_staked setAddress.count error\n"); continue; } + if ( IsMine(*pwalletMain, address) == 0 ) + continue; } CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; From e8dd12a110e009eb75decca4e106e91af5116597 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 04:37:40 -1100 Subject: [PATCH 035/623] -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 787ba5f6b..e68c1a74b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1395,7 +1395,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { - 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)); + //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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 41070f82b7c103f7e97bd249e2eea7fe4a12a7f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 06:57:59 -1100 Subject: [PATCH 036/623] Skip fractional utxo for staking --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2230a1aa7..9cbefea63 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,6 +4625,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN && *utxovaluep != 0 ) + continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); CTxDestination address; From 2f83c3e638aed65cff55367e71323d1dd25b726a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 07:00:06 -1100 Subject: [PATCH 037/623] Simplify --- 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 9cbefea63..c866a3be8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,7 +4625,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN && *utxovaluep != 0 ) + if ( nValue < COIN ) continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); From e3124af1da164fe1b9d54d5c8667f4bf4efe4336 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 20:31:28 -1100 Subject: [PATCH 038/623] Decker's fix for watch only addresses --- 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 c866a3be8..1e330b20c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,7 +4625,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN ) + if ( nValue < COIN || !out.fSpendable ) continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); From 42c0fc6a632c2c3fd19f844924d980abc6766161 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 21:01:23 -1100 Subject: [PATCH 039/623] -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 e68c1a74b..d469ab953 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1406,7 +1406,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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 (%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); } From 196c69f770084c0bda8cdf41c826454e44e52789 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 00:13:09 -1100 Subject: [PATCH 040/623] Fix easy diff check for PoS --- COPYING | 1 + src/pow.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/COPYING b/COPYING index c84bfb7aa..eecf5ccc8 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,4 @@ +Copyright (c) 2016-2018 The Komodo developers Copyright (c) 2016-2017 The Zcash developers Copyright (c) 2009-2017 The Bitcoin Core developers diff --git a/src/pow.cpp b/src/pow.cpp index 2e525e8cb..5e9560850 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,6 +190,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); + if ( height >= 4000 && ASSETCHAINS_STAKED != 0 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From dec86f1b5a0e12b9fe1bfafa283f7622714de064 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 00:14:24 -1100 Subject: [PATCH 041/623] Delay activation to 4200 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5e9560850..cd7f47c71 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( height >= 4000 && ASSETCHAINS_STAKED != 0 ) + if ( height >= 4200 && ASSETCHAINS_STAKED != 0 ) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 0cd39760aada64f7bc6dce1b84ef8338caa76521 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:05:40 -1100 Subject: [PATCH 042/623] Test --- src/komodo_bitcoind.h | 9 ++++++--- src/miner.cpp | 2 +- src/pow.cpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d469ab953..79bd25e38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( nHeight < 6000 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1209,7 +1210,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight >= 4000 ) + if ( nHeight >= 4000 ) // POSTEST64 remove when this is oldstake return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) @@ -1448,7 +1449,9 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + if ( ASSETCHAINS_STAKED == 100 && height >= 4000 && height < 6000 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); //fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget); diff --git a/src/miner.cpp b/src/miner.cpp index 7bf93a8ed..0b41c5cc0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -920,7 +920,7 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 ) + if ( Mining_height >= 4000 && Mining_height < 6000 ) // POSTEST64 remove this HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { diff --git a/src/pow.cpp b/src/pow.cpp index cd7f47c71..8f12f56b4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( height >= 4200 && ASSETCHAINS_STAKED != 0 ) + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 6000 ) // POSTEST64 remove this bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 07529d5eb13f1a9f2c79b6bcac4db9c9dbc9efd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:06:18 -1100 Subject: [PATCH 043/623] 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 79bd25e38..2eb1f1164 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1449,7 +1449,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4000 && height < 6000 ) + if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); From f02af889b9ae06953deb19534e5282d8aaac5cef Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:53:38 -1100 Subject: [PATCH 044/623] Test --- src/komodo_bitcoind.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2eb1f1164..c29668146 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1449,8 +1449,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) + if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) // POSTEST64 + { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + fprintf(stderr,"setmindiff ht.%d\n",height); + } else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); @@ -1481,7 +1484,8 @@ 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) return(0); + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) + return(0); fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); return(-1); } @@ -1490,7 +1494,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! + if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! POSTEST64 return(-1); else { From b45eddd85afc97ca559fa24839abe7bb62bd908a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:59:05 -1100 Subject: [PATCH 045/623] 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 c29668146..6e76e5349 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1454,7 +1454,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"setmindiff ht.%d\n",height); } - else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + else + { + bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); + } bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); //fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget); From ffd2c3834893741d599198824b38fe7cbdd80b42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 03:03:21 -1100 Subject: [PATCH 046/623] Remove easy diff at 4400 --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++-- src/pow.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6e76e5349..863c39134 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 6000 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks @@ -1449,12 +1449,12 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) // POSTEST64 + /*if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 4400 ) // POSTEST64 { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"setmindiff ht.%d\n",height); } - else + else*/ { bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); diff --git a/src/miner.cpp b/src/miner.cpp index 0b41c5cc0..2fb623b84 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -911,7 +911,7 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { int32_t percPoS,z; /*if ( Mining_height <= 100 ) @@ -920,7 +920,7 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 && Mining_height < 6000 ) // POSTEST64 remove this + if ( Mining_height >= 4000 && Mining_height < 4400 ) // POSTEST64 remove this HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { diff --git a/src/pow.cpp b/src/pow.cpp index 8f12f56b4..a6117b35c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 6000 ) // POSTEST64 remove this + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 62a9cee4d34c239c620f2d96ae6eb08b9c9e07f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:01:57 -1100 Subject: [PATCH 047/623] -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 863c39134..d742914e8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1457,7 +1457,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else*/ { bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); + //fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); } bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); From f89f4ef034de31075d95849e238d0c50869cb3b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:04:55 -1100 Subject: [PATCH 048/623] Update URL to white paper --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d85d013d..788635536 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ It downloads and stores the entire history of Komodo transactions; depending on - Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) - Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) - API references: [http://docs.supernet.org/](http://docs.supernet.org/) #Not up to date. -- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/06/Komodo-Whitepaper-June-3.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) ## List of Komodo Platform Technologies From 4ff37947b10c03df679003289e2e79590ff73115 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:32:02 -1100 Subject: [PATCH 049/623] -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 d742914e8..1f6680134 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -567,7 +567,7 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) #endif hashBlock, true)) { - fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From 5aa69f6d75c8c5839bc00e61c2e93a0830949b66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:34:27 -1100 Subject: [PATCH 050/623] -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 1f6680134..2b4cf8cbc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1490,7 +1490,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); + //fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); return(-1); } } From 45ee62cb719499b3ff2fde6168e2ef9aa0364076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:17:39 -1100 Subject: [PATCH 051/623] Ht 6000 test --- src/komodo_bitcoind.h | 20 ++++++-------------- src/miner.cpp | 11 ++--------- src/pow.cpp | 2 -- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2b4cf8cbc..0f3033914 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,15 +1140,16 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < prevtime+60 ) - blocktime = prevtime+60; + if ( nHeight < 6000 ) + { + if ( blocktime < prevtime+60 ) + blocktime = prevtime+60; + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1449,16 +1450,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - /*if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 4400 ) // POSTEST64 - { - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - fprintf(stderr,"setmindiff ht.%d\n",height); - } - else*/ - { - bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - //fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); - } + bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); //fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget); diff --git a/src/miner.cpp b/src/miner.cpp index 2fb623b84..5e7871dd4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,7 +425,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-13 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-30 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); @@ -914,14 +914,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { int32_t percPoS,z; - /*if ( Mining_height <= 100 ) - { - sleep(60); - continue; - }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 && Mining_height < 4400 ) // POSTEST64 remove this - HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) @@ -984,7 +977,7 @@ void static BitcoinMiner() return false; if ( B.nTime > GetAdjustedTime() ) { - fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); + //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime-2 ) { sleep(1); diff --git a/src/pow.cpp b/src/pow.cpp index a6117b35c..2e525e8cb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,8 +190,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 7ed0e00b8201a1c6e5f7c63d040c59a04e71c9c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:23:30 -1100 Subject: [PATCH 052/623] Test --- src/komodo_bitcoind.h | 2 ++ src/pow.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0f3033914..b95efc8d1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1150,6 +1150,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } + if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; diff --git a/src/pow.cpp b/src/pow.cpp index 2e525e8cb..a6117b35c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,6 +190,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 4646f21b5bd0b210e56336cdeeab914eb1ffcfde Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:30:41 -1100 Subject: [PATCH 053/623] Height 6000 disable 60 sec delay --- 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 b95efc8d1..e1249a955 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Sun, 8 Jul 2018 16:50:11 -1100 Subject: [PATCH 054/623] Remove miner locks --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5e7871dd4..20ff32d7c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,7 +425,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-30 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); @@ -975,7 +975,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; - if ( B.nTime > GetAdjustedTime() ) + if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) { //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime-2 ) @@ -999,8 +999,8 @@ void static BitcoinMiner() } else { - while ( GetAdjustedTime() < B.nTime ) - sleep(1); + //while ( B.nTime > GetAdjustedTime() ) + // sleep(1); uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From 0c35569bdcc102afab31183e81999465e7526a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:52:14 -1100 Subject: [PATCH 055/623] tweak --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 20ff32d7c..2e552d62f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -999,8 +999,8 @@ void static BitcoinMiner() } else { - //while ( B.nTime > GetAdjustedTime() ) - // sleep(1); + while ( B.nTime-57 > GetAdjustedTime() ) + sleep(1); uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From 3aac96a8228e4f126cbf2c8b097902f631b9b58c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:53:01 -1100 Subject: [PATCH 056/623] <6000 compatibility --- src/miner.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 2e552d62f..bbcbf6643 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1001,6 +1001,11 @@ void static BitcoinMiner() { while ( B.nTime-57 > GetAdjustedTime() ) sleep(1); + if ( Mining_height < 6000 ) + { + while ( B.nTime > GetAdjustedTime() ) + sleep(1); + } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From de7cb53f9933e773c3be96f435a9d3081d5098b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:20:08 -1100 Subject: [PATCH 057/623] Test post 6000 --- src/komodo_bitcoind.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e1249a955..3956e36f1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1145,6 +1145,11 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime < prevtime+60 ) blocktime = prevtime+60; } + else + { + if ( blocktime < prevtime+30 ) + blocktime = prevtime+30; + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); From 422b307c873ac94a0ddf080642ba3596e77eaae4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:24:40 -1100 Subject: [PATCH 058/623] Reduce gap --- 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 3956e36f1..1f3c251ec 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,8 +1147,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } else { - if ( blocktime < prevtime+30 ) - blocktime = prevtime+30; + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { From f1d8e4b6b5a96d6c173cf4bd7dc0c2162615ecf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:38:27 -1100 Subject: [PATCH 059/623] Fix timestamps --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1f3c251ec..44ec68aa7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,6 +1140,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); + if ( blocktime < GetAdjustedTime() ) + blocktime = GetAdjustedTime(); if ( nHeight < 6000 ) // POSTEST64 { if ( blocktime < prevtime+60 ) From 89931e6e6096908f98521cf334aa07f44f74f9ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:40:33 -1100 Subject: [PATCH 060/623] Fix --- 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 44ec68aa7..a3077828a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,7 +1140,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < GetAdjustedTime() ) + if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( nHeight < 6000 ) // POSTEST64 { From 7c28c718f0e6c2b583dd96c347eec3c165fdba3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:44:15 -1100 Subject: [PATCH 061/623] +segids print --- 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 a3077828a..3fda9ce00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Mon, 9 Jul 2018 08:57:16 -1100 Subject: [PATCH 062/623] -print --- 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 3fda9ce00..a3077828a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Mon, 9 Jul 2018 22:15:27 -1100 Subject: [PATCH 063/623] 7250 diff cap.16 hardfork for PoS --- src/komodo_bitcoind.h | 11 +++++++++-- src/miner.cpp | 11 +++++++++-- src/pow.cpp | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a3077828a..1a679c485 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1159,6 +1159,13 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else if ( nHeight >= 7250 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1491,8 +1498,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - //fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); - return(-1); + if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget + return(-1); } } if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW diff --git a/src/miner.cpp b/src/miner.cpp index bbcbf6643..bc56df370 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -856,7 +856,7 @@ void static BitcoinMiner() // // Search // - uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(pblock->nBits); roundrobin_delay = ROUNDROBIN_DELAY; @@ -911,10 +911,17 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_STAKED != 0 ) { int32_t percPoS,z; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + if ( Mining_height >= 7250 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( HASHtarget < bnMaxPoSdiff ) + HASHtarget = bnMaxPoSdiff; + } if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index a6117b35c..39204f7f9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,8 +190,19 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( ASSETCHAINS_STAKED != 0 ) + { + if ( height >= 4200 && height < 4400 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else if ( height >= 7250 ) + { + arith_uint256 bnMaxPoSdiff; + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } + } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From ed3d0a051e6e325ccbd658e5d3502d740c3940a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 22:21:39 -1100 Subject: [PATCH 064/623] Syntax --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bc56df370..d85e4d510 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -913,14 +913,14 @@ void static BitcoinMiner() } else Mining_start = 0; if ( ASSETCHAINS_STAKED != 0 ) { - int32_t percPoS,z; + int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); if ( Mining_height >= 7250 ) { bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( HASHtarget < bnMaxPoSdiff ) - HASHtarget = bnMaxPoSdiff; + if ( HASHTarget < bnMaxPoSdiff ) + HASHTarget = bnMaxPoSdiff; } if ( ASSETCHAINS_STAKED < 100 ) { From 97a337f739d0234ea11c348deeb37b8e7b3e7ded Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 01:19:29 -1100 Subject: [PATCH 065/623] Initial revisions --- src/komodo_bitcoind.h | 126 +++++------------------------------------- src/komodo_defs.h | 1 + src/miner.cpp | 39 ++----------- src/pow.cpp | 16 ++---- 4 files changed, 27 insertions(+), 155 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a679c485..7685011e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1136,37 +1136,26 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) } } -uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) +uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); - if ( nHeight < 6000 ) // POSTEST64 - { - if ( blocktime < prevtime+60 ) - blocktime = prevtime+60; - } - else - { - if ( blocktime < prevtime+3 ) - blocktime = prevtime+3; - } + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - else if ( nHeight >= 7250 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } - mfactor = 1024; + if ( value < SATOSHIDEN ) + return(0); + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (bnTarget / bnMaxPoSdiff); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; @@ -1187,7 +1176,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) { winner = 1; @@ -1224,100 +1213,15 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe return(blocktime * winner); } -uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) -{ - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight >= 4000 ) // POSTEST64 remove when this is oldstake - return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); - txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < prevtime+57 ) - blocktime = prevtime+57; - if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) - { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); - return(0); - } - if ( ASSETCHAINS_STAKED != 100 || nHeight < 2000 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } - if ( (minage= nHeight*3) > 6000 ) // about 100 blocks - minage = 6000; - pindex = 0; - if ( (pindex= komodo_chainactive(nHeight>50?nHeight-50:1)) != 0 ) - { - vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); - segid = ((nHeight + addrhash.uints[0]) & 0x3f); - pasthash = pindex->GetBlockHash(); - memcpy(hashbuf,&pasthash,sizeof(pasthash)); - memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); - if ( nHeight >= 2000 ) - { - memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)],&txid,sizeof(txid)); - memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); - } else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); - for (iter=0; iter<3600; iter++) - { - diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24*30 ) - diff = 3600*24*30; - if ( iter > 0 ) - diff += iter + segid*2; - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; - coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); - if ( hashval <= bnTarget ) - { - winner = 1; - if ( validateflag == 0 ) - { - blocktime += iter; - blocktime += segid * 2; - } - break; - } - if ( validateflag != 0 ) - { - /*for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ - break; - } - } - //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); - } - } //else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex); - if ( nHeight < 10 ) - return(blocktime); - return(blocktime * winner); -} - arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; + CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; + easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); for (i=n=0; i<100; i++) { ht = height - 100 + i; @@ -1375,7 +1279,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); if ( 1 ) { for (i=31; i>=24; i--) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 1d7351638..9650620a9 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -8,5 +8,6 @@ #define KOMODO_LIMITED_NETWORKSIZE 4 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +#define KOMODO_MAXPOS_DIFF 16 #endif diff --git a/src/miner.cpp b/src/miner.cpp index d85e4d510..2ec853756 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -117,11 +117,7 @@ uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize); -//uint64_t komodo_paxtotal(); int32_t komodo_baseid(char *origbase); -//int32_t komodo_is_issuer(); -//int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo); -//int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); uint64_t komodo_commission(const CBlock *block); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); @@ -140,29 +136,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return NULL; } CBlock *pblock = &pblocktemplate->block; // pointer for convenience - /*if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && chainActive.Tip()->nHeight >= ASSETCHAINS_MINHEIGHT ) - { - isrealtime = komodo_isrealtime(&kmdheight); - deposits = komodo_paxtotal(); - while ( KOMODO_ON_DEMAND == 0 && deposits == 0 && (int32_t)mempool.GetTotalTxSize() == 0 ) - { - deposits = komodo_paxtotal(); - if ( KOMODO_PASSPORT_INITDONE == 0 || KOMODO_INITDONE == 0 || (komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && (isrealtime= komodo_isrealtime(&kmdheight)) == 0) ) - { - //fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f ht.%d\n",KOMODO_INITDONE,isrealtime,(double)deposits/COIN,kmdheight); - } - else if ( komodo_isrealtime(&kmdheight) != 0 && (deposits != 0 || (int32_t)mempool.GetTotalTxSize() > 0) ) - { - fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),isrealtime,KOMODO_ON_DEMAND); - break; - } - sleep(10); - } - KOMODO_ON_DEMAND = 0; - if ( 0 && deposits != 0 ) - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); - }*/ - // -regtest only: allow overriding block.nVersion with + // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); @@ -915,13 +889,10 @@ void static BitcoinMiner() { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 7250 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( HASHTarget < bnMaxPoSdiff ) - HASHTarget = bnMaxPoSdiff; - } + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( HASHTarget < bnMaxPoSdiff ) + HASHTarget = bnMaxPoSdiff; if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index 39204f7f9..0b00c5929 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,6 +127,7 @@ extern int32_t KOMODO_CHOSEN_ONE; extern uint64_t ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #define KOMODO_ELECTION_GAP 2000 +#define KOMODO_MAXPOS_DIFF 16 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); int32_t KOMODO_LOADINGBLOCKS = 1; @@ -192,16 +193,11 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int return error("CheckProofOfWork(): nBits below minimum work"); if ( ASSETCHAINS_STAKED != 0 ) { - if ( height >= 4200 && height < 4400 ) - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - else if ( height >= 7250 ) - { - arith_uint256 bnMaxPoSdiff; - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } + arith_uint256 bnMaxPoSdiff; + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 443277cab34f7617975f4e6d829b0bb086614302 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:04:00 -1100 Subject: [PATCH 066/623] 7500 changes --- src/komodo_bitcoind.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a679c485..afd54c784 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1026,7 +1026,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 ) { @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 ratio,hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1162,13 +1162,18 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe else if ( nHeight >= 7250 ) { bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); if ( bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; } mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + { minage = 6000; + if ( height >= 7500 ) + txtime -= KOMODO_MAXMEMPOOLTIME; + } pindex = 0; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); @@ -1187,7 +1192,9 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( height < 7500 ) + hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) { winner = 1; From 41ee6d2a1f142c1e61d10d7071dec8f5bed30972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:07:27 -1100 Subject: [PATCH 067/623] Syntax --- 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 afd54c784..20c2c63b4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 ratio,hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); From 25c8fec1c32b46fb79d70c255c0a427656d10e26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:08:27 -1100 Subject: [PATCH 068/623] nHeight --- 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 20c2c63b4..e7a74b0f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,7 +1171,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( (minage= nHeight*3) > 6000 ) // about 100 blocks { minage = 6000; - if ( height >= 7500 ) + if ( nHeight >= 7500 ) txtime -= KOMODO_MAXMEMPOOLTIME; } pindex = 0; @@ -1192,7 +1192,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - if ( height < 7500 ) + if ( nHeight < 7500 ) hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) From 5a62cfb73b41d046ca0e99406586b0c10b4613d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:23:24 -1100 Subject: [PATCH 069/623] Fix exceptions --- 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 e7a74b0f9..f6f7005ba 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1028,9 +1028,9 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && || ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From c515ae54d208935617019796ffaf7db9d55a7c3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:25:00 -1100 Subject: [PATCH 070/623] Syntax --- 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 f6f7005ba..0ec295fbd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1030,7 +1030,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 && || ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From 837aaaecb605847ba895b4ff8a2c81b3e0c9cbe4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:26:27 -1100 Subject: [PATCH 071/623] Fix exception --- src/komodo_bitcoind.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7685011e2..18117f665 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1026,11 +1026,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { @@ -1140,6 +1140,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); + txtime -= KOMODO_MAXMEMPOOLTIME; if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( blocktime < prevtime+3 ) @@ -1152,7 +1153,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( value < SATOSHIDEN ) return(0); bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - ratio = (bnTarget / bnMaxPoSdiff); + ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); if ( bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; From d60e3fd1a1f414c9c6cfb76827ef0cd2cf09e7e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:51:35 -1100 Subject: [PATCH 072/623] +print --- src/komodo_bitcoind.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ec295fbd..95679eb4c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1207,12 +1207,15 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs target "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); break; } } From 1cb7611fc9254216319434abf0b22d0fa0c00a1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:58:38 -1100 Subject: [PATCH 073/623] Test --- src/komodo_bitcoind.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 95679eb4c..f02c9a2e0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1207,7 +1207,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } if ( validateflag != 0 ) { - for (i=31; i>=0; i--) + /*for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) @@ -1215,13 +1215,16 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe fprintf(stderr," vs target "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( 1 ) { + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); From c662a3bad1d1eeb154ea45cebed61167b3cde929 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:04:53 -1100 Subject: [PATCH 074/623] 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 f02c9a2e0..7fcb1671b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,8 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval,origtarget; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + origtarget = bnTarget; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1229,7 +1230,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr,"%02x",((uint8_t *)&origtarget)[i]); fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); } if ( nHeight < 10 ) From a86b70f4811c67195f0b9af90d67be87f59a9c5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:09:16 -1100 Subject: [PATCH 075/623] Test --- src/komodo_bitcoind.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7fcb1671b..b7d4c7d51 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval,origtarget; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,newhashval,hashval,origtarget,bnMaxPoSdiff; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; origtarget = bnTarget; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) @@ -1195,7 +1195,14 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe coinage = (value * diff) * ((diff >> 16) + 1); if ( nHeight < 7500 ) hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); - else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + else + { + newhashval = (ratio * arith_uint256(supply)) * (UintToArith256(hash) / arith_uint256(coinage+1)); + + if ( hashval < 8000 ) + hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + else hashval = newhashval; + } if ( hashval <= bnTarget ) { winner = 1; @@ -1224,7 +1231,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( 1 ) { for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 5ce19c1775e32ab951b2e6fce2f1dd6f20e971ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:16:41 -1100 Subject: [PATCH 076/623] Test --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b7d4c7d51..b09857ace 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1197,8 +1197,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); else { - newhashval = (ratio * arith_uint256(supply)) * (UintToArith256(hash) / arith_uint256(coinage+1)); - + newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval < 8000 ) hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); else hashval = newhashval; @@ -1232,7 +1231,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); - fprintf(stderr," ratio -> "); + fprintf(stderr," newhash -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); From 84f19b77ae2ca56557a422a86b2b8aef880442f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:19:15 -1100 Subject: [PATCH 077/623] Fix --- src/komodo_bitcoind.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 18117f665..9e774bf50 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); txtime -= KOMODO_MAXMEMPOOLTIME; if ( validateflag == 0 && blocktime < GetAdjustedTime() ) @@ -1152,11 +1152,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value < SATOSHIDEN ) return(0); - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - ratio = (bnMaxPoSdiff / bnTarget); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; @@ -1177,7 +1174,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; @@ -1190,12 +1187,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ + /*for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs target "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ break; } } From b19bee1eb7af6520b0f4235a826e31514455d6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:25:18 -1100 Subject: [PATCH 078/623] 8000 changes --- 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 b09857ace..08fcb2be7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,7 +1165,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) + if ( nHeight < 8000 && bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; } mfactor = 1024; From 14fd7614736d64a0831f20718fb2516fd7430d4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:26:41 -1100 Subject: [PATCH 079/623] 8000 changes --- src/komodo_bitcoind.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 08fcb2be7..b6887dbf3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1229,14 +1229,11 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); if ( 1 ) { - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); - fprintf(stderr," newhash -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&origtarget)[i]); + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); } if ( nHeight < 10 ) From 38cbe99ba41c90156fd526d43e3182fd2cb3394b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:28:03 -1100 Subject: [PATCH 080/623] Fix --- 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 9e774bf50..132ebc135 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,7 +1174,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From f108acf94381c5230f90eb3e5568d6e9c6a9b695 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:53:28 -1100 Subject: [PATCH 081/623] Easy diff for PoS --- src/komodo_bitcoind.h | 2 +- src/komodo_defs.h | 1 - src/miner.cpp | 5 +---- src/pow.cpp | 6 +----- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 132ebc135..ea830ce9e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1200,7 +1200,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 9650620a9..1d7351638 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -8,6 +8,5 @@ #define KOMODO_LIMITED_NETWORKSIZE 4 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" -#define KOMODO_MAXPOS_DIFF 16 #endif diff --git a/src/miner.cpp b/src/miner.cpp index 2ec853756..9ca979e07 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -889,10 +889,7 @@ void static BitcoinMiner() { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( HASHTarget < bnMaxPoSdiff ) - HASHTarget = bnMaxPoSdiff; + HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index 0b00c5929..6d218ef13 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,7 +127,6 @@ extern int32_t KOMODO_CHOSEN_ONE; extern uint64_t ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #define KOMODO_ELECTION_GAP 2000 -#define KOMODO_MAXPOS_DIFF 16 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); int32_t KOMODO_LOADINGBLOCKS = 1; @@ -194,10 +193,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int if ( ASSETCHAINS_STAKED != 0 ) { arith_uint256 bnMaxPoSdiff; - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From a03465f69e964711dca1df25466cee5a76e12665 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:22:11 -1100 Subject: [PATCH 082/623] Rescale --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ea830ce9e..7072781ba 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1152,6 +1152,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value < SATOSHIDEN ) return(0); + value /= SATOSHIDEN; mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks From 0a953df21b0ac2cd6a6aad286681811757ae378b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:38:28 -1100 Subject: [PATCH 083/623] Txtime2 --- src/komodo_bitcoind.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7072781ba..cb7ef6c65 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -580,6 +580,32 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(tx.nLockTime); } +uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) +{ + CTxDestination address; CBlockIndex *pindex; CTransaction tx; uint256 hashBlock; uint32_t txtime = 0; + *valuep = 0; + if (!GetTransaction(hash, tx, +#ifndef KOMODO_ZCASH + Params().GetConsensus(), +#endif + hashBlock, true)) + { + //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + return(0); + } + if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 ) + txtime = pindex->nTime; + else txtime = tx.nLockTime; + //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + if ( n < tx.vout.size() ) + { + *valuep = tx.vout[n].nValue; + if (ExtractDestination(tx.vout[n].scriptPubKey, address)) + strcpy(destaddr,CBitcoinAddress(address).ToString().c_str()); + } + return(txtime); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; @@ -1139,8 +1165,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - txtime = komodo_txtime(&value,txid,vout,address); - txtime -= KOMODO_MAXMEMPOOLTIME; + txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( blocktime < prevtime+3 ) From cc08cccff2682eedb5e30afa6e0385ef1d217674 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:40:48 -1100 Subject: [PATCH 084/623] Fix --- 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 cb7ef6c65..08c43c468 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 ) + if ( (pindex= mapBlockIndex[pindex->GetHash()]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From 85bf0316b012d54a2494ac264ef71462b4121828 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:42:03 -1100 Subject: [PATCH 085/623] Fix --- 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 08c43c468..7beb0db42 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[pindex->GetHash()]) != 0 ) + if ( (pindex= mapBlockIndex[pindex->GetBlockHash()]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From ec894008176b9054daad5e24edb4a7182b5f58a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:07:01 -1100 Subject: [PATCH 086/623] Fix --- 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 7beb0db42..4f0698038 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[pindex->GetBlockHash()]) != 0 ) + if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); @@ -1172,7 +1172,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) From bfa19436af5f4672c8d9505a1e7640efa0e5c2de Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:21:41 -1100 Subject: [PATCH 087/623] Test --- src/komodo_bitcoind.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4f0698038..95b4f6e47 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1182,7 +1182,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; - pindex = 0; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); komodo_segids(hashbuf,nHeight-101,100); @@ -1195,11 +1194,13 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) diff = 3600*24*30; + else if ( diff < 0 ) + diff = 60; if ( iter > 0 ) diff += segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) continue; - coinage = (value * diff) * ((diff >> 16) + 1); + coinage = (value * diff); hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { @@ -1233,7 +1234,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); } if ( nHeight < 10 ) return(blocktime); From 5e90f44589025333edb436302287991edc0d517d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:32:27 -1100 Subject: [PATCH 088/623] Test --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 95b4f6e47..c053285a7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1193,7 +1193,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) + { + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,minage); diff = 3600*24*30; + } else if ( diff < 0 ) diff = 60; if ( iter > 0 ) From b9ed7fa848605b8a09231138085c36c646679cc0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:34:12 -1100 Subject: [PATCH 089/623] 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 c053285a7..f10c34b3f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1194,7 +1194,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,minage); + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } else if ( diff < 0 ) From 745a8dfc5dbb5e8c7e5fda32b1ddec422341c4f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:36:54 -1100 Subject: [PATCH 090/623] 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 f10c34b3f..28b8d4368 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1194,7 +1194,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,(int32_t)minage); + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } else if ( diff < 0 ) From f6567e80078d9bab45e0f61186349dc30647f966 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:44:04 -1100 Subject: [PATCH 091/623] 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 28b8d4368..599b6b44e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1192,13 +1192,13 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh for (iter=0; iter<3600; iter++) { diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24*30 ) + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) { printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } - else if ( diff < 0 ) - diff = 60; if ( iter > 0 ) diff += segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) From 0999e80e0edbcd0376a18e2087989c43dd9def14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:50:26 -1100 Subject: [PATCH 092/623] 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 599b6b44e..d942d3078 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); From 01994dbac72583b7ffd101a1ce33adc990ba9480 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:57:20 -1100 Subject: [PATCH 093/623] Test --- src/komodo_bitcoind.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d942d3078..856e22e7d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,7 +1172,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1196,7 +1196,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = 60; else if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); + //printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } if ( iter > 0 ) @@ -1217,20 +1217,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); - fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); + fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 1 ) + if ( 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 26b9af8048b43fa5c9f0e6a5c25b993689645901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:06:04 -1100 Subject: [PATCH 094/623] Prints --- src/komodo_bitcoind.h | 6 +++--- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 856e22e7d..e667ae280 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1217,17 +1217,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e330b20c..5151936c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,7 +4645,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { From 4dc0ad386693422611dee60bf75ae8ca85b6b5f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:15:24 -1100 Subject: [PATCH 095/623] -print --- src/komodo_bitcoind.h | 4 ++-- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e667ae280..9872275e1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1227,14 +1227,14 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag != 0 ) + if ( validateflag > 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } if ( nHeight < 10 ) return(blocktime); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5151936c4..a3559fc00 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,7 +4645,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 9aa243103f25b465873f3ddc8e8bd2e179a2fa44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:20:45 -1100 Subject: [PATCH 096/623] 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 9872275e1..3eac19dff 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1328,7 +1328,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) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - if ( ASSETCHAINS_STAKED == 100 && height < 200 ) + if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) 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 ) @@ -1438,7 +1438,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! POSTEST64 + if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! POSTEST64 return(-1); else { From 8316bde87de5d4fb4b67d6c46bdf365c1969fd23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:27:12 -1100 Subject: [PATCH 097/623] 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 3eac19dff..9076ef125 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1227,7 +1227,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag > 1 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); @@ -1345,7 +1345,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { - //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)); + 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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 0c974f218db513b2660f7e6b4c691fa2b34efdd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:31:01 -1100 Subject: [PATCH 098/623] +print --- 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 a3559fc00..1e330b20c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 5a7fd132cf5080d572423a48e761e90fc499f6ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 09:54:28 -1100 Subject: [PATCH 099/623] Fix estimate PoS perc --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9076ef125..1c0a6414d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1269,6 +1269,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else { + n++; percPoS++; if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); diff --git a/src/miner.cpp b/src/miner.cpp index 9ca979e07..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -784,7 +784,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 ) { //fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height); - sleep(3); + //sleep(3); } #ifdef ENABLE_WALLET CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1,gpucount); @@ -976,11 +976,11 @@ void static BitcoinMiner() { while ( B.nTime-57 > GetAdjustedTime() ) sleep(1); - if ( Mining_height < 6000 ) + /*if ( Mining_height < 6000 ) { while ( B.nTime > GetAdjustedTime() ) sleep(1); - } + }*/ uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From d5a38d16a8866207cb96ab96f6a99befd3bb8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 11:17:30 -1100 Subject: [PATCH 100/623] +print --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c837268f9..8824959e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - /*for (z=31; z>=16; z--) + for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n");*/ + fprintf(stderr," POW\n"); if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) From afdcba6b470d707f5d0f5f182690d4031b5349ed Mon Sep 17 00:00:00 2001 From: Christoph Ritzer Date: Wed, 11 Jul 2018 13:35:48 +0200 Subject: [PATCH 101/623] remove a bad alert --- src/Makefile.test.include | 1 - src/init.cpp | 5 - src/test/alert_tests.cpp | 447 -------------------------------------- 3 files changed, 453 deletions(-) delete mode 100644 src/test/alert_tests.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index ff270bd6a..a52b66335 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -45,7 +45,6 @@ BITCOIN_TESTS =\ test/arith_uint256_tests.cpp \ test/bignum.h \ test/addrman_tests.cpp \ - test/alert_tests.cpp \ test/allocator_tests.cpp \ test/base32_tests.cpp \ test/base58_tests.cpp \ diff --git a/src/init.cpp b/src/init.cpp index 1b8018b56..a9bdc6151 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1756,11 +1756,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) StartNode(threadGroup, scheduler); - // Monitor the chain, and alert if we get blocks much quicker or slower than expected - int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing; - CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload, - boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing); - scheduler.scheduleEvery(f, nPowTargetSpacing); #ifdef ENABLE_MINING // Generate coins in the background diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp deleted file mode 100644 index ef607dacc..000000000 --- a/src/test/alert_tests.cpp +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright (c) 2013 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -// -// Unit tests for alert system -// - -#include "alert.h" -#include "chain.h" -#include "chainparams.h" -#include "clientversion.h" -#include "data/alertTests.raw.h" - -#include "main.h" -#include "rpcprotocol.h" -#include "rpcserver.h" -#include "serialize.h" -#include "streams.h" -#include "util.h" -#include "utilstrencodings.h" - -#include "test/test_bitcoin.h" - -#include - -#include -#include -#include - -#include "key.h" -#include "alertkeys.h" -#include - -/* - * If the alert key pairs have changed, the test suite will fail as the - * test data is now invalid. To create valid test data, signed with a - * new alert private key, follow these steps: - * - * 1. Copy your private key into alertkeys.h. Don't commit this file! - * See sendalert.cpp for more info. - * - * 2. Set the GENERATE_ALERTS_FLAG to true. - * - * 3. Build and run: - * test_bitcoin -t Generate_Alert_Test_Data - * - * 4. Test data is saved in your current directory as alertTests.raw.NEW - * Copy this file to: src/test/data/alertTests.raw - * - * For debugging purposes, terminal output can be copied into: - * src/test/data/alertTests.raw.h - * - * 5. Clean up... - * - Set GENERATE_ALERTS_FLAG back to false. - * - Remove your private key from alertkeys.h - * - * 6. Build and verify the new test data: - * test_bitcoin -t Alert_tests - * - */ -#define GENERATE_ALERTS_FLAG false - -#if GENERATE_ALERTS_FLAG - -// NOTE: -// A function SignAndSave() was used by Bitcoin Core to create alert test data -// but it has not been made publicly available. So instead, we have adapted -// some publicly available code which achieves the intended result: -// https://gist.github.com/lukem512/9b272bd35e2cdefbf386 - - -// Code to output a C-style array of values -template -std::string HexStrArray(const T itbegin, const T itend, int lineLength) -{ - std::string rv; - static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - rv.reserve((itend-itbegin)*3); - int i = 0; - for(T it = itbegin; it < itend; ++it) - { - unsigned char val = (unsigned char)(*it); - if(it != itbegin) - { - if (i % lineLength == 0) - rv.push_back('\n'); - else - rv.push_back(' '); - } - rv.push_back('0'); - rv.push_back('x'); - rv.push_back(hexmap[val>>4]); - rv.push_back(hexmap[val&15]); - rv.push_back(','); - i++; - } - - return rv; -} - -template -inline std::string HexStrArray(const T& vch, int lineLength) -{ - return HexStrArray(vch.begin(), vch.end(), lineLength); -} - - -// Sign CAlert with alert private key -bool SignAlert(CAlert &alert) -{ - // serialize alert data - CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); - sMsg << *(CUnsignedAlert*)&alert; - alert.vchMsg = std::vector(sMsg.begin(), sMsg.end()); - - // sign alert - std::vector vchTmp(ParseHex(pszPrivKey)); - CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); - CKey key; - if (!key.SetPrivKey(vchPrivKey, false)) - { - printf("key.SetPrivKey failed\n"); - return false; - } - if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) - { - printf("SignAlert() : key.Sign failed\n"); - return false; - } - return true; -} - -// Sign a CAlert and serialize it -bool SignAndSerialize(CAlert &alert, CDataStream &buffer) -{ - // Sign - if(!SignAlert(alert)) - { - printf("SignAndSerialize() : could not sign alert\n"); - return false; - } - // ...and save! - buffer << alert; - return true; -} - -void GenerateAlertTests() -{ - CDataStream sBuffer(SER_DISK, CLIENT_VERSION); - - CAlert alert; - alert.nRelayUntil = 60; - alert.nExpiration = 24 * 60 * 60; - alert.nID = 1; - alert.nCancel = 0; // cancels previous messages up to this ID number - alert.nMinVer = 0; // These versions are protocol versions - alert.nMaxVer = 999001; - alert.nPriority = 1; - alert.strComment = "Alert comment"; - alert.strStatusBar = "Alert 1"; - - // Replace SignAndSave with SignAndSerialize - SignAndSerialize(alert, sBuffer); - - // More tests go here ... - alert.setSubVer.insert(std::string("/MagicBean:0.1.0/")); - alert.strStatusBar = "Alert 1 for MagicBean 0.1.0"; - SignAndSerialize(alert, sBuffer); - - alert.setSubVer.insert(std::string("/MagicBean:0.2.0/")); - alert.strStatusBar = "Alert 1 for MagicBean 0.1.0, 0.2.0"; - SignAndSerialize(alert, sBuffer); - - alert.setSubVer.clear(); - ++alert.nID; - alert.nCancel = 1; - alert.nPriority = 100; - alert.strStatusBar = "Alert 2, cancels 1"; - SignAndSerialize(alert, sBuffer); - - alert.nExpiration += 60; - ++alert.nID; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nPriority = 5000; - alert.strStatusBar = "Alert 3, disables RPC"; - alert.strRPCError = "RPC disabled"; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nPriority = 5000; - alert.strStatusBar = "Alert 4, re-enables RPC"; - alert.strRPCError = ""; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nMinVer = 11; - alert.nMaxVer = 22; - alert.nPriority = 100; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.strStatusBar = "Alert 2 for MagicBean 0.1.0"; - alert.setSubVer.insert(std::string("/MagicBean:0.1.0/")); - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nMinVer = 0; - alert.nMaxVer = 999999; - alert.strStatusBar = "Evil Alert'; /bin/ls; echo '"; - alert.setSubVer.clear(); - bool b = SignAndSerialize(alert, sBuffer); - - if (b) { - // Print the hex array, which will become the contents of alertTest.raw.h - std::vector vch = std::vector(sBuffer.begin(), sBuffer.end()); - printf("%s\n", HexStrArray(vch, 8).c_str()); - - // Write the data to alertTests.raw.NEW, to be copied to src/test/data/alertTests.raw - std::ofstream outfile("alertTests.raw.NEW", std::ios::out | std::ios::binary); - outfile.write((const char*)&vch[0], vch.size()); - outfile.close(); - } -} - - - -struct GenerateAlertTestsFixture : public TestingSetup { - GenerateAlertTestsFixture() {} - ~GenerateAlertTestsFixture() {} -}; - -BOOST_FIXTURE_TEST_SUITE(Generate_Alert_Test_Data, GenerateAlertTestsFixture); -BOOST_AUTO_TEST_CASE(GenerateTheAlertTests) -{ - GenerateAlertTests(); -} -BOOST_AUTO_TEST_SUITE_END() - - -#else - - -struct ReadAlerts : public TestingSetup -{ - ReadAlerts() - { - std::vector vch(alert_tests::alertTests, alert_tests::alertTests + sizeof(alert_tests::alertTests)); - CDataStream stream(vch, SER_DISK, CLIENT_VERSION); - try { - while (!stream.eof()) - { - CAlert alert; - stream >> alert; - alerts.push_back(alert); - } - } - catch (const std::exception&) { } - } - ~ReadAlerts() { } - - static std::vector read_lines(boost::filesystem::path filepath) - { - std::vector result; - - std::ifstream f(filepath.string().c_str()); - std::string line; - while (std::getline(f,line)) - result.push_back(line); - - return result; - } - - std::vector alerts; -}; - -BOOST_FIXTURE_TEST_SUITE(Alert_tests, ReadAlerts) - - -BOOST_AUTO_TEST_CASE(AlertApplies) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - BOOST_FOREACH(const CAlert& alert, alerts) - { - BOOST_CHECK(alert.CheckSignature(alertKey)); - } - - BOOST_CHECK(alerts.size() >= 3); - - // Matches: - BOOST_CHECK(alerts[0].AppliesTo(1, "")); - BOOST_CHECK(alerts[0].AppliesTo(999001, "")); - BOOST_CHECK(alerts[0].AppliesTo(1, "/MagicBean:11.11.11/")); - - BOOST_CHECK(alerts[1].AppliesTo(1, "/MagicBean:0.1.0/")); - BOOST_CHECK(alerts[1].AppliesTo(999001, "/MagicBean:0.1.0/")); - - BOOST_CHECK(alerts[2].AppliesTo(1, "/MagicBean:0.1.0/")); - BOOST_CHECK(alerts[2].AppliesTo(1, "/MagicBean:0.2.0/")); - - // Don't match: - BOOST_CHECK(!alerts[0].AppliesTo(-1, "")); - BOOST_CHECK(!alerts[0].AppliesTo(999002, "")); - - BOOST_CHECK(!alerts[1].AppliesTo(1, "")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "MagicBean:0.1.0")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "/MagicBean:0.1.0")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(-1, "/MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(999002, "/MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "/MagicBean:0.2.0/")); - - BOOST_CHECK(!alerts[2].AppliesTo(1, "/MagicBean:0.3.0/")); - - SetMockTime(0); -} - - -BOOST_AUTO_TEST_CASE(AlertNotify) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - boost::filesystem::path temp = GetTempPath() / - boost::filesystem::unique_path("alertnotify-%%%%.txt"); - - mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string(); - - BOOST_FOREACH(CAlert alert, alerts) - alert.ProcessAlert(alertKey, false); - - std::vector r = read_lines(temp); - BOOST_CHECK_EQUAL(r.size(), 6u); - -// Windows built-in echo semantics are different than posixy shells. Quotes and -// whitespace are printed literally. - -#ifndef _WIN32 - BOOST_CHECK_EQUAL(r[0], "Alert 1"); - BOOST_CHECK_EQUAL(r[1], "Alert 2, cancels 1"); - BOOST_CHECK_EQUAL(r[2], "Alert 2, cancels 1"); - BOOST_CHECK_EQUAL(r[3], "Alert 3, disables RPC"); - BOOST_CHECK_EQUAL(r[4], "Alert 4, reenables RPC"); // dashes should be removed - BOOST_CHECK_EQUAL(r[5], "Evil Alert; /bin/ls; echo "); // single-quotes should be removed -#else - BOOST_CHECK_EQUAL(r[0], "'Alert 1' "); - BOOST_CHECK_EQUAL(r[1], "'Alert 2, cancels 1' "); - BOOST_CHECK_EQUAL(r[2], "'Alert 2, cancels 1' "); - BOOST_CHECK_EQUAL(r[3], "'Alert 3, disables RPC' "); - BOOST_CHECK_EQUAL(r[4], "'Alert 4, reenables RPC' "); // dashes should be removed - BOOST_CHECK_EQUAL(r[5], "'Evil Alert; /bin/ls; echo ' "); -#endif - boost::filesystem::remove(temp); - - SetMockTime(0); - mapAlerts.clear(); -} - -BOOST_AUTO_TEST_CASE(AlertDisablesRPC) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - // Command should work before alerts - BOOST_CHECK_EQUAL(GetWarnings("rpc"), ""); - - // First alert should disable RPC - alerts[5].ProcessAlert(alertKey, false); - BOOST_CHECK_EQUAL(alerts[5].strRPCError, "RPC disabled"); - BOOST_CHECK_EQUAL(GetWarnings("rpc"), "RPC disabled"); - - // Second alert should re-enable RPC - alerts[6].ProcessAlert(alertKey, false); - BOOST_CHECK_EQUAL(alerts[6].strRPCError, ""); - BOOST_CHECK_EQUAL(GetWarnings("rpc"), ""); - - SetMockTime(0); - mapAlerts.clear(); -} - -static bool falseFunc() { return false; } - -BOOST_AUTO_TEST_CASE(PartitionAlert) -{ - // Test PartitionCheck - CCriticalSection csDummy; - CBlockIndex indexDummy[400]; - CChainParams& params = Params(CBaseChainParams::MAIN); - int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing; - - // Generate fake blockchain timestamps relative to - // an arbitrary time: - int64_t now = 1427379054; - SetMockTime(now); - for (int i = 0; i < 400; i++) - { - indexDummy[i].phashBlock = NULL; - if (i == 0) indexDummy[i].pprev = NULL; - else indexDummy[i].pprev = &indexDummy[i-1]; - indexDummy[i].nHeight = i; - indexDummy[i].nTime = now - (400-i)*nPowTargetSpacing; - // Other members don't matter, the partition check code doesn't - // use them - } - - // Test 1: chain with blocks every nPowTargetSpacing seconds, - // as normal, no worries: - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(strMiscWarning.empty()); - - // Test 2: go 3.5 hours without a block, expect a warning: - now += 3*60*60+30*60; - SetMockTime(now); - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(!strMiscWarning.empty()); - BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); - strMiscWarning = ""; - - // Test 3: test the "partition alerts only go off once per day" - // code: - now += 60*10; - SetMockTime(now); - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(strMiscWarning.empty()); - - // Test 4: get 2.5 times as many blocks as expected: - now += 60*60*24; // Pretend it is a day later - SetMockTime(now); - int64_t quickSpacing = nPowTargetSpacing*2/5; - for (int i = 0; i < 400; i++) // Tweak chain timestamps: - indexDummy[i].nTime = now - (400-i)*quickSpacing; - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(!strMiscWarning.empty()); - BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); - strMiscWarning = ""; - - SetMockTime(0); -} - -BOOST_AUTO_TEST_SUITE_END() - -#endif From 1cdb961ba26865efb46b30eb1daa61327d7cea28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:51:42 -1100 Subject: [PATCH 102/623] Fix PoW mining in mixed PoS/PoW, fix orphaned stake tx --- src/chain.h | 26 ++++++++++++++++++++++++++ src/komodo_bitcoind.h | 15 +++++++++------ src/main.cpp | 28 ++++++++++++++++++++++------ src/miner.cpp | 4 ++-- src/validationinterface.cpp | 4 ++++ src/validationinterface.h | 1 + src/wallet/wallet.cpp | 12 ++++++++++++ src/wallet/wallet.h | 1 + 8 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/chain.h b/src/chain.h index a28e4e44a..e2b03c4df 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,6 +16,7 @@ #include +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -321,6 +322,31 @@ public: //! Efficiently find an ancestor of this block. CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; + + bool IsPOSBlock() const + { + if ( ASSETCHAINS_STAKED != 0 ) + { + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + const CBlockIndex *pindex = this; + if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(true); + } + } + } + } + return(false); + } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0a6414d..2c27589cc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1328,7 +1328,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) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; + 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 ) return(1); txn_count = pblock->vtx.size(); @@ -1343,7 +1343,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + if ( pblock->IsPOSBlock() != 0 ) + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { 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)); @@ -1351,14 +1352,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( pblock->IsPOSBlock() != 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); + } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ } //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); @@ -1443,10 +1446,10 @@ 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 + return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - else if ( height > 100 ) - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound if ( bhash > bnTarget ) { for (i=31; i>=16; i--) diff --git a/src/main.cpp b/src/main.cpp index d4dfae7ae..bd6aef8ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3252,13 +3252,17 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) return false; - if (!fBare) { + if (!fBare) + { // Resurrect mempool transactions from the disconnected block. - BOOST_FOREACH(const CTransaction &tx, block.vtx) { + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3275,11 +3279,23 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree)); // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: - BOOST_FOREACH(const CTransaction &tx, block.vtx) { - SyncWithWallets(tx, NULL); - } + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + // SyncWithWallets(tx, NULL); + //} // Update cached incremental witnesses //fprintf(stderr,"chaintip false\n"); + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; + if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + { + EraseFromWallets(tx.GetHash()); + } + else + { + SyncWithWallets(tx, NULL); + } + } GetMainSignals().ChainTip(pindexDelete, &block, newTree, false); return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 8824959e1..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - for (z=31; z>=16; z--) + /*for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n"); + fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index cd3e30f3d..a8e15db99 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -51,3 +51,7 @@ void UnregisterAllValidationInterfaces() { void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) { g_signals.SyncTransaction(tx, pblock); } + +void EraseFromWallets(const uint256 &hash) { + g_signals.EraseTransaction(hash); +} diff --git a/src/validationinterface.h b/src/validationinterface.h index 1855dacd7..a1f111753 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -28,6 +28,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn); void UnregisterAllValidationInterfaces(); /** Push an updated transaction to all registered wallets */ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL); +void EraseFromWallets(const uint256 &hash); class CValidationInterface { protected: diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..1cf52d1b4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,6 +1358,18 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } +void CWallet::EraseFromWallet(const uint256 &hash) +{ + if (!fFileBacked) + return; + { + LOCK(cs_wallet); + if (mapWallet.erase(hash)) + CWalletDB(strWalletFile).EraseTx(hash); + } + return; +} + void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f77a55a04..f6c8563ef 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -995,6 +995,7 @@ public: bool UpdateNullifierNoteMap(); void UpdateNullifierNoteMapWithTx(const CWalletTx& wtx); bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb); + void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); void EraseFromWallet(const uint256 &hash); From d1db09204a50e47ea882160c8bf1634a8900d42a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:58:41 -1100 Subject: [PATCH 103/623] Syntax --- src/chain.h | 25 ------------------------- src/komodo_bitcoind.h | 32 ++++++++++++++++++++++++++++---- src/main.cpp | 4 ++-- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/chain.h b/src/chain.h index e2b03c4df..41cf28652 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,7 +16,6 @@ #include -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -323,30 +322,6 @@ public: CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; - bool IsPOSBlock() const - { - if ( ASSETCHAINS_STAKED != 0 ) - { - int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; - const CBlockIndex *pindex = this; - if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) - { - txid = pblock->vtx[n-1].vin[0].prevout.hash; - vout = pblock->vtx[n-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) - { - strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) - { - fprintf(stderr,"is PoS block!\n"); - return(true); - } - } - } - } - return(false); - } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2c27589cc..ab7bad30f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -606,6 +606,30 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(txtime); } +int32_t komodo_isPoS(CBlock *pblock) +{ + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + if ( ASSETCHAINS_STAKED != 0 ) + { + if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(1); + } + } + } + } + return(0); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; @@ -1151,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; ivtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - if ( pblock->IsPOSBlock() != 0 ) + if ( komodo_isPoS(pblock) != 0 ) eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { @@ -1352,7 +1376,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - if ( pblock->IsPOSBlock() != 0 ) + 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) ) diff --git a/src/main.cpp b/src/main.cpp index bd6aef8ce..ea18662aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) { EraseFromWallets(tx.GetHash()); } From 72953c8342459633b16e6a8f33523a0ba7099f83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:00:38 -1100 Subject: [PATCH 104/623] Syntax --- src/wallet/wallet.cpp | 12 ------------ src/wallet/wallet.h | 1 - 2 files changed, 13 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1cf52d1b4..10bf93598 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,18 +1358,6 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } -void CWallet::EraseFromWallet(const uint256 &hash) -{ - if (!fFileBacked) - return; - { - LOCK(cs_wallet); - if (mapWallet.erase(hash)) - CWalletDB(strWalletFile).EraseTx(hash); - } - return; -} - void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f6c8563ef..0c6a90840 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -998,7 +998,6 @@ public: void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); void WitnessNoteCommitment( std::vector commitments, std::vector>& witnesses, From 333cf46c477808757d82ddd319b9730faf649d6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:16:21 -1100 Subject: [PATCH 105/623] Accept duplicate height 1 --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ea18662aa..7529a9d98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) + if ( (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) { EraseFromWallets(tx.GetHash()); } @@ -4094,7 +4094,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + { + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + return true; return(false); + } if ( nHeight != 0 ) { if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) From 42bbeb4f4db3b9850f93ced9b6edc52d763e75ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:21:28 -1100 Subject: [PATCH 106/623] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7529a9d98..5f51a47c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4098,7 +4098,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) return true; - return(false); + return state.DoS(1, error("%s: trying to change height 1 forbidden", __func__)); } if ( nHeight != 0 ) { From 8808427254f402bcba651ae3838437bdd23470a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:26:47 -1100 Subject: [PATCH 107/623] -print --- 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 ab7bad30f..366011db6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -621,7 +621,7 @@ int32_t komodo_isPoS(CBlock *pblock) strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) { - fprintf(stderr,"is PoS block!\n"); + //fprintf(stderr,"is PoS block!\n"); return(1); } } @@ -1181,7 +1181,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) { memcpy(prevhashbuf,hashbuf,100); prevheight = height; - fprintf(stderr,"segids.%d\n",height); + fprintf(stderr,"prevsegids.%d\n",height+n); } } } From 6789cd6db6fcdbbc7a6d483e7ebfe64d33e4b191 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:28:12 -1100 Subject: [PATCH 108/623] -print --- 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 366011db6..25bd2b831 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1175,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From ce2b6b330c64fecb79bef0c9608c8c8b3e3690e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 07:41:16 -1100 Subject: [PATCH 109/623] Steepen PoW diff easement --- 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 25bd2b831..ddfe7c6eb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1332,7 +1332,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); + if ( bnTarget > easydiff ) + bnTarget = easydiff; if ( 1 ) { for (i=31; i>=24; i--) From 43ff67f5fceadd67d277ce2d028d00f65fd5097d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 08:57:03 -1100 Subject: [PATCH 110/623] Handle 100% PoS for -ac_target = < 100 --- 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 ddfe7c6eb..e9bcb0389 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1313,7 +1313,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ave = (sum / arith_uint256(n)); if ( ave > target ) ave = target; - } else return(target); + } else ave = easydiff; //else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); From 4cc33bf81ee66f3e864b53c170663c440b44e80c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:10:51 -1100 Subject: [PATCH 111/623] Test --- src/komodo_bitcoind.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bcb0389..58b037a62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,19 +1267,37 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; + CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - for (i=n=0; i<100; i++) + for (i=n=m=0; i<100; i++) { ht = height - 100 + i; if ( ht <= 1 ) continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + if ( komodo_segid(ht) >= 0 ) + { + n++; + percPoS++; + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"0"); + } + else + { + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"1"); + sum += hashval; + m++; + n++; + } + } + /*if ( (pindex= komodo_chainactive(ht)) != 0 ) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); @@ -1298,9 +1316,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); } - if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) - fprintf(stderr," %d, ",percPoS); - } + }*/ + if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) + fprintf(stderr," %d, ",percPoS); } if ( n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; @@ -1308,9 +1326,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); - if ( n > 0 ) + if ( m > 0 ) { - ave = (sum / arith_uint256(n)); + ave = (sum / arith_uint256(m)); if ( ave > target ) ave = target; } else ave = easydiff; //else return(target); From 153a7898146c872ac4647b4f68184670bf0d662c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:12:39 -1100 Subject: [PATCH 112/623] Neutral diff for PoW --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58b037a62..3eff2a882 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1104,9 +1104,8 @@ 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] - PoW mining on PoS chain must solve a harder diff that adjusts, but never less than KOMODO_POWMINMULT */ -#define KOMODO_POWMINMULT 16 +//#define KOMODO_POWMINMULT 16 uint64_t komodo_commission(const CBlock *pblock) { @@ -1325,7 +1324,7 @@ 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)); + //target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( m > 0 ) { ave = (sum / arith_uint256(m)); From 9e1a6d76c4e0b72d1d0ffabb1888932ca08d50f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:45:35 -1100 Subject: [PATCH 113/623] Fix null hashval --- 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 3eff2a882..f405f2571 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1291,7 +1291,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"1"); - sum += hashval; + sum += UintToArith256(pindex->GetBlockHash()); m++; n++; } From ae2d90651b0651ac548bba99a934d91032b4e790 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 10:09:58 -1100 Subject: [PATCH 114/623] 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 f405f2571..afd1fe46e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1351,7 +1351,7 @@ 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 = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); - if ( bnTarget > easydiff ) + if ( bnTarget > easydiff || bnTarget < ave ) bnTarget = easydiff; if ( 1 ) { From ae67e0923cf3dc1ba3850b0999fea0700f6f0c65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 10:58:42 -1100 Subject: [PATCH 115/623] Fix PoS estimator for first 100 blocks --- src/komodo_bitcoind.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index afd1fe46e..6656b8e25 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1293,7 +1293,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr,"1"); sum += UintToArith256(pindex->GetBlockHash()); m++; - n++; } } /*if ( (pindex= komodo_chainactive(ht)) != 0 ) From b6c80e46e31b3833d589a9699d91ff833ab89846 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 11:06:05 -1100 Subject: [PATCH 116/623] 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 6656b8e25..c48413575 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1348,10 +1348,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); - if ( bnTarget > easydiff || bnTarget < ave ) + if ( bnTarget > easydiff ) bnTarget = easydiff; + else if ( bnTarget < ave ) // overflow + bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); if ( 1 ) { for (i=31; i>=24; i--) From 0fa08b81c9ce0b4df8feadcaba2581ed78ec29b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 11:41:39 -1100 Subject: [PATCH 117/623] Fix PoSperc count --- 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 c48413575..7a50f3ce2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1318,7 +1318,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } - if ( n < 100 ) + if ( m+n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); From 8ba2ae9e592d6b078b4a700b409f5a9cae07d503 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 12:46:10 -1100 Subject: [PATCH 118/623] One more underflow check --- src/komodo_bitcoind.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7a50f3ce2..785cfe6cf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1352,7 +1352,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( bnTarget > easydiff ) bnTarget = easydiff; else if ( bnTarget < ave ) // overflow + { bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + if ( bnTarget < ave ) + bnTarget = ave; + } if ( 1 ) { for (i=31; i>=24; i--) From 6d2fc2903ee81ecbec27b83490a0044e13064c95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:19:45 -1100 Subject: [PATCH 119/623] -stopat= --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + src/main.cpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c46486430..8dfc7108c 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f61fd05ea..8188a6154 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1539,6 +1539,7 @@ void komodo_args(char *argv0) } } } + KOMODO_STOPAT = GetArg("-stopat",0); ASSETCHAINS_CC = GetArg("-ac_cc",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); diff --git a/src/main.cpp b/src/main.cpp index 5f51a47c4..cfc97db81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2691,7 +2691,8 @@ static int64_t nTimeTotal = 0; bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { const CChainParams& chainparams = Params(); - + if ( KOMODO_STOPAT != 0 && pindex->nHeight > KOMODO_STOPAT ) + return(false); //fprintf(stderr,"connectblock ht.%d\n",(int32_t)pindex->nHeight); AssertLockHeld(cs_main); bool fExpensiveChecks = true; From 7e282415b1b24c51f6bbc5b96b118139ce8b8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:57:20 -1100 Subject: [PATCH 120/623] Coin supply api --- src/chain.h | 2 +- src/komodo_bitcoind.h | 47 +++++++++++++++++++++++++++++++++++++++++++ src/rpcmisc.cpp | 18 +++++++++++++++++ src/rpcserver.h | 1 + 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 41cf28652..8c86a7ede 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; //! Which # file this block is stored in (blk?????.dat) int nFile; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 785cfe6cf..7230757e5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,3 +1532,50 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } +int64_t komodo_newcoins(CBlockIndex *pindex) +{ + int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + n = pblock->vtx.size(); + for (i=0; ivtx[i]; + if ( (m= tx.vin.size()) > 0 ) + { + for (j=0; j= vintx.vout.size() ) + { + fprintf(stderr,"ERROR: %s/v%d cant find\n",txid.ToString().c_str(),vout); + return(0); + } + vinsum += vintx.vout[vout].nValue; + } + } + if ( (m= tx.vout.size()) > 0 ) + { + for (j=0; j %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + return(voutsum - vinsum); +} + +int64_t komodo_coinsupply(int32_t height) +{ + CBlockIndex *pindex; int64_t supply = 0; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + if ( pindex->newcoins == 0 ) + pindex->newcoins = komodo_newcoins(pindex); + supply += pindex->newcoins; + } + return(supply); +} diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 065739a9a..b055e591a 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,6 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); +int64_t komodo_coinsupply(int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -226,6 +227,23 @@ public: }; #endif +UniValue coinsupply(const UniValue& params, bool fHelp) +{ + int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + if (fHelp || params.size() > 1) + throw runtime_error("coinsupply \n"); + if ( params.size() == 0 ) + height = chainActive.Height(); + else height = atoi(params[0].get_str()); + if ( (supply= komodo_coinsupply(height)) > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("height", (int)height)); + result.push_back(Pair("supply", ValueFromAmount(supply))); + } else result.push_back(Pair("error", "couldnt calculate supply")); + return(result); +} + UniValue jumblr_deposit(const UniValue& params, bool fHelp) { int32_t retval; UniValue result(UniValue::VOBJ); diff --git a/src/rpcserver.h b/src/rpcserver.h index 5bb949299..586d79a88 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -207,6 +207,7 @@ extern UniValue getblocktemplate(const UniValue& params, bool fHelp); extern UniValue submitblock(const UniValue& params, bool fHelp); extern UniValue estimatefee(const UniValue& params, bool fHelp); extern UniValue estimatepriority(const UniValue& params, bool fHelp); +extern UniValue coinsupply(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp From ab98eb8e6ab5ea2005dae06145a9998e40fa5a68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:59:32 -1100 Subject: [PATCH 121/623] 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 7230757e5..9005d8c04 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1534,7 +1534,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(CBlockIndex *pindex) { - int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i Date: Thu, 12 Jul 2018 00:01:02 -1100 Subject: [PATCH 122/623] 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 9005d8c04..b50273c79 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + const CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:01:42 -1100 Subject: [PATCH 123/623] 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 b50273c79..cb2a4af53 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:04:45 -1100 Subject: [PATCH 124/623] Test --- src/komodo_bitcoind.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cb2a4af53..7d9fd5c3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlockIndex *pindex) +int64_t komodo_newcoins(CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pblock->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins == 0 ) - pindex->newcoins = komodo_newcoins(pindex); + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(&block); + else return(0); + } supply += pindex->newcoins; } return(supply); From 97a4e9238a097ae986508b7ee5b88d9c4b6675d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:06:47 -1100 Subject: [PATCH 125/623] Test --- src/komodo_bitcoind.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7d9fd5c3a..e24883c08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,7 +1532,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlock *pblock) +int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); @@ -1564,7 +1564,7 @@ int64_t komodo_newcoins(CBlock *pblock) voutsum += tx.vout[j].nValue; } } - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1573,13 +1573,17 @@ int64_t komodo_coinsupply(int32_t height) CBlockIndex *pindex; CBlock block; int64_t supply = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { - if ( pindex->newcoins == 0 ) + while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(&block); - else return(0); + if ( pindex->newcoins == 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + else return(0); + } + supply += pindex->newcoins; + pindex = pindex->pprev; } - supply += pindex->newcoins; } return(supply); } From 26204e59df5d16a22ac2b3b35b1a6ef516432f2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:18:58 -1100 Subject: [PATCH 126/623] Add coinsupply rpc --- src/rpcserver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ed5110114..f37124d0c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -280,6 +280,7 @@ static const CRPCCommand vRPCCommands[] = { "network", "clearbanned", &clearbanned, true }, /* Block chain and UTXO */ + { "blockchain", "coinsupply", &coinsupply, true }, { "blockchain", "getblockchaininfo", &getblockchaininfo, true }, { "blockchain", "getbestblockhash", &getbestblockhash, true }, { "blockchain", "getblockcount", &getblockcount, true }, From df74ee5fa0c5e28abccff98e19c9c89d980c31be Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:23:50 -1100 Subject: [PATCH 127/623] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e24883c08..1fd179ae9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1571,15 +1571,21 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; + fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) { + printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); - else return(0); + else + { + fprintf(stderr,"error loading block.%d\n",pindex->nHeight); + return(0); + } } supply += pindex->newcoins; pindex = pindex->pprev; From a46d6afb2b2670c2b7973db24787cb06a82ef53f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:28:15 -1100 Subject: [PATCH 128/623] Test --- src/chain.h | 1 + src/komodo_bitcoind.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 8c86a7ede..5400abb00 100644 --- a/src/chain.h +++ b/src/chain.h @@ -181,6 +181,7 @@ public: void SetNull() { phashBlock = NULL; + newcoins = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1fd179ae9..6c5f615f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1576,7 +1576,6 @@ int64_t komodo_coinsupply(int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) @@ -1588,6 +1587,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 67459d80b4680504c80a9dec77556c770c398714 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:39:04 -1100 Subject: [PATCH 129/623] 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 6c5f615f3..5140c0d27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1564,6 +1564,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) voutsum += tx.vout[j].nValue; } } + if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1571,7 +1572,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; - fprintf(stderr,"coinsupply %d\n",height); + //fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1587,7 +1588,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; - printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 261895095501daf0acd7134471628456c50e8bc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:52:36 -1100 Subject: [PATCH 130/623] Test --- src/chain.h | 4 ++-- src/komodo_bitcoind.h | 17 +++++++++++------ src/rpcmisc.cpp | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/chain.h b/src/chain.h index 5400abb00..71d788531 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; + int64_t newcoins,zfunds; //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -181,7 +181,7 @@ public: void SetNull() { phashBlock = NULL; - newcoins = 0; + newcoins = zfunds = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5140c0d27..e9bde8595 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,14 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) +int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; j 100000*SATOSHIDEN || voutsum-vinsum < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } -int64_t komodo_coinsupply(int32_t height) +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { - CBlockIndex *pindex; CBlock block; int64_t supply = 0; + CBlockIndex *pindex; CBlock block; int64_t zfunds=0,supply = 0; //fprintf(stderr,"coinsupply %d\n",height); + *zfundsp = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1580,7 +1583,7 @@ int64_t komodo_coinsupply(int32_t height) if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); else { fprintf(stderr,"error loading block.%d\n",pindex->nHeight); @@ -1588,9 +1591,11 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + zfunds += pindex->zfunds; //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } + *zfundsp = zfunds; return(supply); } diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b055e591a..04376f4a5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,7 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); -int64_t komodo_coinsupply(int32_t height); +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -229,17 +229,19 @@ public: UniValue coinsupply(const UniValue& params, bool fHelp) { - int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + int32_t height = 0; int64_t zfunds,supply = 0; UniValue result(UniValue::VOBJ); if (fHelp || params.size() > 1) throw runtime_error("coinsupply \n"); if ( params.size() == 0 ) height = chainActive.Height(); else height = atoi(params[0].get_str()); - if ( (supply= komodo_coinsupply(height)) > 0 ) + if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("height", (int)height)); result.push_back(Pair("supply", ValueFromAmount(supply))); + result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); + result.push_back(Pair("total", ValueFromAmount(zfunds + supply))); } else result.push_back(Pair("error", "couldnt calculate supply")); return(result); } From ae4dbe22bbe32f6a8d1f71db7ac2efa47badec67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:58:25 -1100 Subject: [PATCH 131/623] tx.GetJoinSplitValueOut() --- src/komodo_bitcoind.h | 2 +- src/primitives/transaction.cpp | 17 ++++++++++++++++- src/primitives/transaction.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bde8595..0293c0dd5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); + zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jvpub_new; - + if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue)) throw std::runtime_error("CTransaction::GetJoinSplitValueIn(): value out of range"); } + + return nValue; +} +CAmount CTransaction::GetJoinSplitValueOut() const +{ + CAmount nValue = 0; + for (std::vector::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it) + { + // NB: vpub_new "gives" money to the value pool just as inputs do + nValue += it->vpub_old; + + if (!MoneyRange(it->vpub_old) || !MoneyRange(nValue)) + throw std::runtime_error("CTransaction::GetJoinSplitValueOut(): value out of range"); + } + return nValue; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 88ee9a312..e3615c120 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -445,6 +445,8 @@ public: // Return sum of JoinSplit vpub_new CAmount GetJoinSplitValueIn() const; + // Return sum of JoinSplit vpub_old + CAmount GetJoinSplitValueOut() const; // Compute priority, given priority of inputs and (optionally) tx size double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const; From 1ec2a42ff317ab4cbc81dafb49d6108a6ea6cc16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:01:45 -1100 Subject: [PATCH 132/623] Test --- src/komodo_bitcoind.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0293c0dd5..1ceeebd38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,7 +1566,12 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) + { + fprintf(stderr,"ht.%d special case return 3\n",nHeight); + return(3 * SATOSHIDEN); + } + if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } From 3118a070000f4267ded1e5c70e3253f3a54c0551 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:16:41 -1100 Subject: [PATCH 133/623] Test --- src/komodo_bitcoind.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1ceeebd38..1c0264a3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins; zfunds += pindex->zfunds; - //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds)); pindex = pindex->pprev; } } diff --git a/src/main.cpp b/src/main.cpp index cfc97db81..b08d2e522 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1104,7 +1104,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if ( ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); - if ( txout.nValue > 0 && iscoinbase == 0 ) + if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } nValueOut += txout.nValue; From 7130a7cdc8572f8376bb147fb8f4ffbdfc8ff4fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:21:32 -1100 Subject: [PATCH 134/623] Test --- src/komodo_bitcoind.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0264a3a..f33fc2c01 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,11 +1566,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) - { - fprintf(stderr,"ht.%d special case return 3\n",nHeight); + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - } if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); @@ -1585,7 +1582,7 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( pindex->newcoins == 0 ) + if ( pindex->newcoins == 0 && pindex->zfunds == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); From aa51eef61991942a6e7eed944d08b673e7c646d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:37:55 -1100 Subject: [PATCH 135/623] coinsupply rpc call --- 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 f33fc2c01..27f0a26a4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1568,8 +1568,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) *zfundsp = zfunds; if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); + //if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) + //. fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } From 8aa6378bc9dde7c81c093e0cd898018bcfc27cfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:46:32 -1100 Subject: [PATCH 136/623] Add symbol to coinsupply return --- src/rpcmisc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 04376f4a5..bf7f345d5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -238,6 +238,7 @@ UniValue coinsupply(const UniValue& params, bool fHelp) if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) { result.push_back(Pair("result", "success")); + result.push_back(Pair("coin", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)); result.push_back(Pair("height", (int)height)); result.push_back(Pair("supply", ValueFromAmount(supply))); result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); From 40df8d84b1c06d9bf6ce1069724b8cda94fba94c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 03:52:54 -1100 Subject: [PATCH 137/623] Reduce staking CPU usage --- src/miner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index c837268f9..7bd6777d4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -949,7 +949,11 @@ void static BitcoinMiner() fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n");*/ if ( h > hashTarget ) + { + if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + sleep(1); return false; + } if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) { //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); From 0f7abeea0ea7af9a4a4204cf19a386039424164e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 04:08:51 -1100 Subject: [PATCH 138/623] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 7bd6777d4..bc5bbe1f7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -396,6 +396,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { 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); + sleep(1); if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; From 2b72340d10710d0f54c04fb463b289f74a3bf210 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 06:25:02 -1100 Subject: [PATCH 139/623] -print --- 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 1e330b20c..7199db0be 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4690,7 +4690,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt //fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep)); *blocktimep = earliest; } - } else fprintf(stderr,"no earliest utxo for staking\n"); + } //else fprintf(stderr,"no earliest utxo for staking\n"); return(siglen); } From 29bb0d039cd1d94d8f121f84177c4b3843cd9cb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:23:58 -1100 Subject: [PATCH 140/623] Cap search to 2 minutes --- 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 27f0a26a4..cc60bc0e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1212,7 +1212,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); - for (iter=0; iter<3600; iter++) + for (iter=0; iter<120; iter++) { diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) From 8a7c025aaef77372b506d94007bd6873a807d43f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:39:33 -1100 Subject: [PATCH 141/623] De-clumpify at 900 --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cc60bc0e2..d09503751 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1227,7 +1227,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff); - hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (UintToArith256(hash) / coinage256); + if ( nHeight >= 900 ) + hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { winner = 1; From 832ca82122ea5ce196d0bf8b6e0ac261bb8120f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:53:46 -1100 Subject: [PATCH 142/623] +print --- 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 7199db0be..334b1dfe3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c3ed86ad18cd337cfb0155d049bc001acde4a466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:01:48 -1100 Subject: [PATCH 143/623] Test --- src/komodo_bitcoind.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d09503751..734c57f73 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1189,10 +1189,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); - if ( validateflag == 0 && blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); - if ( blocktime < prevtime+3 ) - blocktime = prevtime+3; + if ( validateflag == 0 ) + { + fprintf(stderr,"blocktime.%u -> ",blocktime); + if ( blocktime < GetAdjustedTime() ) + blocktime = GetAdjustedTime(); + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); @@ -1236,6 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From e0a3ab0a32f12e972850b030e39e8d101a04f148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:24:58 -1100 Subject: [PATCH 144/623] Test --- src/komodo_bitcoind.h | 14 +++++++------- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 734c57f73..fa5266d38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); - if ( blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + if ( blocktime < GetAdjustedTime()-60 ) + blocktime = GetAdjustedTime()-60; + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1217,7 +1217,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); - for (iter=0; iter<120; iter++) + for (iter=0; iter<180; iter++) { diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -1401,7 +1401,7 @@ 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,(char *)""); + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { 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)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 334b1dfe3..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4640,10 +4640,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } From 8785f8cee0a64b1e7849c454d787764632b2b4e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:26:41 -1100 Subject: [PATCH 145/623] Fix --- 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 fa5266d38..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1195,7 +1195,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) - blocktime = GetAdjustedTime()-60; + blocktime = GetAdjustedTime()+30; //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) @@ -1234,7 +1234,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh coinage = (value * diff); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - if ( nHeight >= 900 ) + if ( nHeight >= 900 && nHeight < 916 ) hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { From ed3d9247b42eb3797596457d1e6e3f51a1eb0e10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:28:34 -1100 Subject: [PATCH 146/623] New version --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index bc5bbe1f7..c6855cd57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From 593d06a8c749d4a3aa11f76781b5f8c385726ec3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:29:20 -1100 Subject: [PATCH 147/623] -print --- 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 400dc9088..85141aa6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 668ff11a727af89f84dba5ffd22c5a0f471cc6b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:38:47 -1100 Subject: [PATCH 148/623] +print --- 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 85141aa6a..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c067f5148bc234ad863ccaa31f54994911f9c286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:44:07 -1100 Subject: [PATCH 149/623] +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 e0c88065b..2916e4d56 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From e53395fccf810c66d567336fbe2fd1f09ae19d60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:50:00 -1100 Subject: [PATCH 150/623] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2916e4d56..1a9377e85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,9 +1257,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( 0 && validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From cb595b48018eaa00c18631a1afb3597bf74c0f3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:00:10 -1100 Subject: [PATCH 151/623] -print --- src/komodo_bitcoind.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a9377e85..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,12 +1257,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); if ( 0 && validateflag != 0 ) From 2da6a5a5ad4d6813a9a7fed1b5416f29a475b11c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:05:05 -1100 Subject: [PATCH 152/623] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c6855cd57..773762937 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From eedbc1907eb46c12bae422c53014fba2531b3c66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:09:48 -1100 Subject: [PATCH 153/623] 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 e0c88065b..4e09b3592 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - //fprintf(stderr,"blocktime.%u -> ",blocktime); + fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From 0debf37ff7cb7a0294eecc1f324a83050521b130 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:14:15 -1100 Subject: [PATCH 154/623] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4e09b3592..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } diff --git a/src/miner.cpp b/src/miner.cpp index 773762937..ca04343e4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,8 +400,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) - return(0); + //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); From cdb34664622baacc337fc8a5d413bf64939dc486 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:18:16 -1100 Subject: [PATCH 155/623] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ca04343e4..2b37590e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,7 +492,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } - else + else if ( ASSETCHAINS_STAKED == 0 ) { CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) From afa90f17b126d345fdae07b56479de45dc374a4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:23:36 -1100 Subject: [PATCH 156/623] Detect new block while sleeping --- src/miner.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2b37590e1..8a0c63f88 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -951,8 +951,8 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) - sleep(1); + //if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + // sleep(1); return false; } if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) @@ -980,12 +980,11 @@ void static BitcoinMiner() else { while ( B.nTime-57 > GetAdjustedTime() ) - sleep(1); - /*if ( Mining_height < 6000 ) { - while ( B.nTime > GetAdjustedTime() ) - sleep(1); - }*/ + sleep(1); + if ( chainActive.Tip()->nHeight >= Mining_height ) + return(false); + } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From b0910b9e2a17f93f908a47ac6170c46d49b3cb5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:33:01 -1100 Subject: [PATCH 157/623] +print --- 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 400dc9088..4c3a66c2a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From b30fdbd2378bbee5bb5801f83e5fc45d37ef5fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:48:32 -1100 Subject: [PATCH 158/623] +segids print --- 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 e0c88065b..8c4e2c537 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Thu, 12 Jul 2018 10:49:26 -1100 Subject: [PATCH 159/623] -prints --- src/komodo_bitcoind.h | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8c4e2c537..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; iGetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 308ee0761c265b2c1af855d67a85b4e9014cc2dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:52:38 -1100 Subject: [PATCH 160/623] Guard error 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 e0c88065b..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1404,7 +1404,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { - 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 ( 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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 6d2faeb0b8ddcdf843198067740e8be7a7618e62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:13:32 -1100 Subject: [PATCH 161/623] +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 0c714ba9c..4b91f8230 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From d5614a7628dd72f744ed15cd878f2b32dea8ebeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:43:32 -1100 Subject: [PATCH 162/623] Set nBits more often --- src/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 8a0c63f88..dbe6dc41c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -832,8 +832,9 @@ void static BitcoinMiner() // Search // uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); savebits = pblock->nBits; - HASHTarget = arith_uint256().SetCompact(pblock->nBits); + HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 ) { From 3dcc06d3acbd1cca46554f72589c15da41b49c26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:12:27 -1100 Subject: [PATCH 163/623] +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 4b91f8230..74b9786f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag != 0 ) + //if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 5162b553a0e0f91d5a976d533b810e72855fd2ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:14:22 -1100 Subject: [PATCH 164/623] -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 74b9786f3..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 0401884fee36534c5508b794d89c559bfd0a66ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 04:45:32 -1100 Subject: [PATCH 165/623] Mitigation of very long block times, starting 2500 for PoW --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c714ba9c..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1219,6 +1219,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); for (iter=0; iter<180; iter++) { + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) diff = 60; @@ -1229,9 +1231,9 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( iter > 0 ) diff += segid*2; - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; coinage = (value * diff); + 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 ) From 485df724b988548f9204f0f59ef5841c51f32496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:12:59 -1100 Subject: [PATCH 166/623] Fix invalid tx in mempool for PoS --- 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 da244e079..42318252f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) + if ( txheight > 246748 ) { - if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From 82fd97935b50eead75971b2d32e1180710237b6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:15:43 -1100 Subject: [PATCH 167/623] Revert --- 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 42318252f..e584b2c93 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From b39b4d733efea2fb3140a737ec6f57ca86217043 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 00:11:29 -1100 Subject: [PATCH 168/623] ( --- 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 e584b2c93..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,7 +1076,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { From 3cbc956e040778621e9ebd563485ac71635d2cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 03:08:05 -1100 Subject: [PATCH 169/623] Test fix for crash --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..df0cd9c2b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2112,7 +2112,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) continue; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + //if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) { From 84eabd0d59a56b98e2bed897f8b8a6787750b386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 05:43:18 -1100 Subject: [PATCH 170/623] Skip null privacy address --- src/komodo_bitcoind.h | 13 ++++++++++--- src/wallet/rpcwallet.cpp | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index da244e079..eb649be99 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1546,7 +1546,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; + CTxDestination address; int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i 0 ) { for (j=0; j %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) - voutsum += tx.vout[j].nValue; + { + if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) + voutsum += tx.vout[j].nValue; + } } } *zfundsp = zfunds; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6831585c4..07bf91c89 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4643,11 +4643,17 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + besttime = 0; + if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); - } - else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } else continue; + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; @@ -4655,7 +4661,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 27d76b740bb4b59e35335706c6d06b7f604de1d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:02:53 -1100 Subject: [PATCH 171/623] Syntax --- 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 eb649be99..f328853b3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1574,7 +1574,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) voutsum += tx.vout[j].nValue; - else printf("skip %.8f -> %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + else printf("skip %.8f -> %s\n",dstr(tx.vout[j].nValue),CBitcoinAddress(address).ToString().c_str()); } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) From b388a2914475cda3196eb45218f99f610283b9eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:22:25 -1100 Subject: [PATCH 172/623] Add loop --- src/wallet/rpcwallet.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 07bf91c89..542666755 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4646,11 +4646,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = 0; if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - besttime = eligible; - eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) - break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } } else continue; eligible = besttime; if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) From beb03773e4bd9c8550b3b48183ed2950ca7e1b02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:37:07 -1100 Subject: [PATCH 173/623] Test --- 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 542666755..d5b01a495 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4640,6 +4640,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { + m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { @@ -4652,7 +4653,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible--; if ( eligible < (uint32_t)tipindex->nTime-300 ) break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + m++; + //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); } } else continue; eligible = besttime; @@ -4664,7 +4666,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 424aeca00d8ff14e541be3d84a3ee478c0171aa7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:04:10 -1100 Subject: [PATCH 174/623] Test --- 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 d5b01a495..be1be1b28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,7 +4651,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 17ec046d90b8966caea92d8c67cb62d1f5051721 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:15:26 -1100 Subject: [PATCH 175/623] Test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index be1be1b28..765b718a1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4601,6 +4601,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) @@ -4702,6 +4703,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); + fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); return(siglen); } From 4fc4e200964a77efdb62eec30682642f8c98c704 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:22:28 -1100 Subject: [PATCH 176/623] Test --- 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 765b718a1..51b9edb8e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4652,7 +4652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + //if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 55dd662212f77be38ad94625d0019fa4fd3a671f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:41:29 -1100 Subject: [PATCH 177/623] Optimize staking loop a bit --- src/wallet/rpcwallet.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 51b9edb8e..88759a6f4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4601,15 +4601,26 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + if ( (tipindex= chainActive.Tip()) == 0 ) + return(0); fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { + counter++; + if ( chainActive.Tip() != tipindex ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if ( setAddress.size() ) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + /*if ( setAddress.size() ) { CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) @@ -4624,23 +4635,13 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } if ( IsMine(*pwalletMain, address) == 0 ) continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; + }*/ const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - { - //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - //if (pwalletMain->mapAddressBook.count(address)) - // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); - } - //BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex; - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) @@ -4703,7 +4704,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); return(siglen); } From aa2ef3abfcbaba8090f930a9358a92c178909c59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:05:00 -1100 Subject: [PATCH 178/623] Test --- src/wallet/rpcwallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 88759a6f4..9b7e17d4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4668,7 +4668,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); + if ( counter > 1000 ) + break; } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From d04efc6ff574bfdd826cdd137bd0aec0d4393f5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:30:38 -1100 Subject: [PATCH 179/623] Test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9b7e17d4e..5073ab845 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4642,6 +4642,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; +continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) From ac53109534eb6023a960ee2e01862ab2256dc623 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:29:29 -1100 Subject: [PATCH 180/623] Optimized staker --- src/komodo_bitcoind.h | 11 ++ src/wallet/rpcwallet.cpp | 212 +++++++++++++++++++++++++++------------ 2 files changed, 160 insertions(+), 63 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f328853b3..58fc643b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1185,6 +1185,17 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) } } +uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) +{ + bits256 addrhash; uint8_t hashbuf[256]; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); + memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)hashp,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + return(addrhash.uints[0]); +} + uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5073ab845..13ca693f5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4513,6 +4513,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); +int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4590,10 +4591,86 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) return(siglen); } +struct komodo_staking +{ + char address[64]; + uint256 txid; + arith_uint256 hashval; + uint64_t nValue; + uint32_t segid32; + int32_t vout; + const CScript scriptPubKey; +}; + +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +{ + uint256 hash; uint32_t segid32; struct komodo_staking *kp; + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + kp = &array[(*numlp)++]; + memset(*kp,0,sizeof(*kp)); + strcpy(kp->address,address); + kp->txid = txid; + kp->vout = vout; + kp->hashval = UintToArith256(hash); + kp->txtime = txtime; + kp->segid32 = segid32; + kp->nValue = nValue; + kp->scriptPubKey = pk; + return(array); +} + +arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime) +{ + int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval; + diff = (iter + blocktime - kp->txtime - minage); + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + coinage = ((uint64_t)kp->nValue/COIN * diff); + if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (kp->hashval / coinage256); + if ( nHeight >= 900 && nHeight < 916 ) + hashval = (hashval / coinage256); + return(hashval); +} + +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +{ + int32_t maxiters = 180; + int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + segid = ((nHeight + kp->segid32) & 0x3f); + hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + for (iter=0; itertxtime+minage ) + continue; + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + blocktime += iter; + blocktime += segid * 2; + return(blocktime); + } + } + } + return(0); +} + int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { - set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; + static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4603,79 +4680,88 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); if ( (tipindex= chainActive.Tip()) == 0 ) return(0); - fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); - BOOST_FOREACH(const COutput& out, vecOutputs) + nHeight = tipindex->nHeight + 1; + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + minage = 6000; + komodo_segids(hashbuf,nHeight-101,100); + fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); + if ( time(NULL) > lasttime+600 ) { - counter++; - if ( chainActive.Tip() != tipindex ) + if ( array != 0 ) { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); + free(array); + array = 0; + maxkp = numkp = 0; } - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + BOOST_FOREACH(const COutput& out, vecOutputs) { - //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - /*if ( setAddress.size() ) - { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight ) { - fprintf(stderr,"komodo_staked ExtractDestination error\n"); + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if (!setAddress.count(address)) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) { - fprintf(stderr,"komodo_staked setAddress.count error\n"); - continue; - } - if ( IsMine(*pwalletMain, address) == 0 ) - continue; - }*/ - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; -continue; - m = 0; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); - if ( eligible > 0 ) - { - besttime = 0; - if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) - { - besttime = eligible; - eligible--; - //if ( eligible < (uint32_t)tipindex->nTime+3 ) - break; - m++; - //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); - } - } else continue; - eligible = besttime; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) - { - earliest = eligible; - best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); - if ( counter > 1000 ) - break; + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); } - } //else fprintf(stderr,"utxo not eligible\n"); - } //else fprintf(stderr,"no tipindex\n"); + } + } + lasttime = (uint32_t)time(NULL); + fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } + for (i=0; inTime+27,minage); + //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( eligible > 0 ) + { + besttime = m = 0; + if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime+3 ) + break; + m++; + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + } + } + else + { + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + continue; + } + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + { + earliest = eligible; + best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; + *utxovaluep = (uint64_t)kp->nValue; + //decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); + *utxovoutp = kp->vout; + *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + } + } //else fprintf(stderr,"utxo not eligible\n"); + } //else fprintf(stderr,"no tipindex\n"); if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 5649e3d39d0350598fa5bbeaf08c8a570fc7cb75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:30:50 -1100 Subject: [PATCH 181/623] 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 58fc643b7..fad483d3f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; uint8_t hashbuf[256]; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); From 1273624d3e440bd9578f246b45531dd4661dd7c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:38:45 -1100 Subject: [PATCH 182/623] Test --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fad483d3f..d624dc72a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 13ca693f5..d9de578d5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4514,6 +4514,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); +int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4597,17 +4598,22 @@ struct komodo_staking uint256 txid; arith_uint256 hashval; uint64_t nValue; - uint32_t segid32; + uint32_t segid32,txtime; int32_t vout; - const CScript scriptPubKey; + CScript scriptPubKey; }; -struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk) { uint256 hash; uint32_t segid32; struct komodo_staking *kp; segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); - kp = &array[(*numlp)++]; - memset(*kp,0,sizeof(*kp)); + if ( *numkp >= *maxkp ) + { + *maxkp += 1000; + array = (struct komodo_staking *)realloc(array,sizeof(*array) * (*maxkp)); + } + kp = &array[(*numkp)++]; + memset(kp,0,sizeof(*kp)); strcpy(kp->address,address); kp->txid = txid; kp->vout = vout; @@ -4667,7 +4673,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4716,7 +4722,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } } } From aecf58592c68a873893e4c8f476b6014d214f6d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:41:08 -1100 Subject: [PATCH 183/623] Fix --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d9de578d5..3633c56e4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4720,7 +4720,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; - if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) + if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } @@ -4746,16 +4746,16 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); continue; } eligible = besttime; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; From 76df25be7a6f964272eb4383b698375c95351726 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:51:01 -1100 Subject: [PATCH 184/623] Test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3633c56e4..c37e78889 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4732,8 +4732,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; inTime+27,minage); - //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + continue; + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { besttime = m = 0; From ecae680bfa8f842849ca057233ea5973d7daec20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:52:42 -1100 Subject: [PATCH 185/623] Test --- 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 c37e78889..babeabe6e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4734,7 +4734,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); if ( eligible > 0 ) { besttime = m = 0; From 011b0a24334378c2a71ef3a069efac111f3afeed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:02:23 -1100 Subject: [PATCH 186/623] Test --- src/wallet/rpcwallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index babeabe6e..59516472b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+600 ) + //if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4747,7 +4747,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else @@ -4769,6 +4769,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); + if ( array != 0 ) + { + free(array); + array = 0; + maxkp = numkp = 0; + } if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; @@ -4800,7 +4806,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d\n",(uint32_t)time(NULL),counter,numkp); return(siglen); } From 518e079e9172d69e211ed783bb7873f36b1e0333 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:14:53 -1100 Subject: [PATCH 187/623] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 59516472b..384c23001 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,11 +4740,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-180 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 1d8f1b466afec494601820a696923f53ff68f6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:18:36 -1100 Subject: [PATCH 188/623] Test --- 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 384c23001..cc8f63040 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,7 +4740,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; @@ -4757,6 +4756,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; From 817aedba536f3573c715a90b49c24a2d240a68a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:53:42 -1100 Subject: [PATCH 189/623] Test --- src/wallet/rpcwallet.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cc8f63040..7c1b81af1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,13 +4691,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+600 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -4731,6 +4732,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } for (i=0; inHeight+1 > nHeight ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; @@ -4770,11 +4776,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( array != 0 ) + if ( 0 && array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } if ( earliest != 0 ) { From a87b6f5f629a2d55c2db677155e5347f6dcad7e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:55:01 -1100 Subject: [PATCH 190/623] Test --- 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 7c1b81af1..8a0d83d1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4750,7 +4750,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-180 ) + if ( eligible < (uint32_t)tipindex->nTime-60 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From cbce9f1f65a3bca9c373577178d6e6447d09dc90 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 14 Jul 2018 23:00:09 +0000 Subject: [PATCH 191/623] WIP debugging why leveldb iterator is broke --- src/main.cpp | 14 +++++++++++--- src/txdb.cpp | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..15d74adb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,10 +590,18 @@ CBlockTreeDB *pblocktree = NULL; int64_t komodo_snapshot() { + fprintf(stderr,"komodo_snapshot\n"); int64_t total = -1; - if ( pblocktree != 0 ) - total = pblocktree->Snapshot(); - else fprintf(stderr,"null pblocktree start with -addressindex=true\n"); + if (fAddressIndex) { + if ( pblocktree != 0 ) { + total = pblocktree->Snapshot(); + } else { + fprintf(stderr,"null pblocktree start with -addressindex=true\n"); + } + } else { + fprintf(stderr,"getsnapshot requires -addressindex=true\n"); + } + fprintf(stderr,"total=%li\n", total); return(total); } diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..fa3766faf 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,18 +402,31 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + //boost::scoped_ptr pcursor(pdb->NewIterator(leveldb::ReadOptions()) ); + //boost::scoped_ptr pcursor(db->NewIterator()); + fprintf(stderr,"Snapshot\n"); + + //pcursor->SeekToFirst(); + pcursor->SeekToLast(); + fprintf(stderr,"SeekToLast\n"); + fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { + fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); + fprintf(stderr,"about to try\n"); try { leveldb::Slice slKey = pcursor->key(); + fprintf(stderr,"made slice\n"); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); + fprintf(stderr,"made ssKey\n"); CAddressIndexKey indexKey; ssKey >> chType; + fprintf(stderr,"made chType\n"); ssKey >> indexKey; + fprintf(stderr,"made indexKey\n"); fprintf(stderr,"chType.%d\n",chType); if ( chType == DB_ADDRESSINDEX ) { @@ -428,12 +441,13 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } } else { break; } } catch (const std::exception& e) { + fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } } From 45c4bfef6434afc0f351566691257b49a126cebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:02:20 -1100 Subject: [PATCH 192/623] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8a0d83d1f..d068ac18d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + //if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4776,7 +4776,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( array != 0 ) { free(array); array = 0; From d5c81c59bbc70ea5067c316cf34a73960cc181a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:11:43 -1100 Subject: [PATCH 193/623] Test --- 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 d068ac18d..28166a6fa 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); From b8b06863603f0f0b284731d107cb4efc0de73447 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:21:33 -1100 Subject: [PATCH 194/623] Test --- src/wallet/rpcwallet.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28166a6fa..d11300c96 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4660,7 +4660,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4673,12 +4673,12 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4730,7 +4730,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { @@ -4738,9 +4738,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); + fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From cfe64b2b487c991b8775a875949025bfb0ed0299 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:26:38 -1100 Subject: [PATCH 195/623] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d11300c96..987e6db62 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,6 +4651,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter Date: Sat, 14 Jul 2018 12:35:26 -1100 Subject: [PATCH 196/623] Test --- src/wallet/rpcwallet.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 987e6db62..1977bb4df 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,20 +4645,24 @@ arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uin return(hashval); } -uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf) { - int32_t maxiters = 180; + int32_t maxiters = 180; uint256 hash; int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout); + kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + for (int i=32; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; itertxtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -4739,7 +4743,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); From 37d6294dbe692798fac29b536754a6cc8bf00425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:36:44 -1100 Subject: [PATCH 197/623] Test --- 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 1977bb4df..5612f5f79 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4662,7 +4662,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod { if ( blocktime+iter+segid*2 < kp->txtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); From d3ce166fb8b21972151ecb7673c8f9bbbd942194 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:41:30 -1100 Subject: [PATCH 198/623] Test --- src/wallet/rpcwallet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5612f5f79..824eb60b9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4653,9 +4653,9 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=32; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + //for (int i=32; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); + if ( blocktime > tipindex->nTime+60 ) + blocktime = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+100 ) { if ( array != 0 ) { @@ -4735,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { From 6e7dcf31067a4501dd6caf2643b58c1b5936ffe4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:42:51 -1100 Subject: [PATCH 199/623] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 824eb60b9..a8575497f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4695,8 +4695,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); - if ( blocktime > tipindex->nTime+60 ) - blocktime = tipindex->nTime+60; + if ( *blocktimep > tipindex->nTime+60 ) + *blocktimep = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); if ( time(NULL) > lasttime+100 ) { From 1973dfa0505aa51cf471bc67aac2919a00615e82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:49:18 -1100 Subject: [PATCH 200/623] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a8575497f..330c5f253 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4665,7 +4665,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4698,7 +4698,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( *blocktimep > tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+100 ) + if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4748,7 +4748,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); - fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); + //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From 2d4811152640e6e4413f811af0b02cc8605022b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:02:35 -1100 Subject: [PATCH 201/623] -prints --- src/wallet/rpcwallet.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 330c5f253..c55a306ed 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4697,7 +4697,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); if ( *blocktimep > tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; - fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); + //fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) @@ -4737,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { @@ -4770,7 +4770,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); + winners++; + //fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; @@ -4780,11 +4781,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); *utxovoutp = kp->vout; *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winnders.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( numkp < 10000 && array != 0 ) { free(array); array = 0; @@ -4822,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d\n",(uint32_t)time(NULL),counter,numkp); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); return(siglen); } From 8cbf8d6a12fee8999c1a8b591e606b681e31b2f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:12:08 -1100 Subject: [PATCH 202/623] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c55a306ed..debec99b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4735,7 +4735,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } lasttime = (uint32_t)time(NULL); - fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); + //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } for (i=winners=0; inTime-60 ) + if ( eligible < (uint32_t)tipindex->nTime+30 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); @@ -4823,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); + //fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); return(siglen); } From 779b7b3a5b5a472bd0893807bbbf023fa4313360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:16:18 -1100 Subject: [PATCH 203/623] Typo --- 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 debec99b6..23ba352dd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4781,7 +4781,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); *utxovoutp = kp->vout; *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winnders.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 8afd5b3a0444e241dbcd885ffc300f580e60dcf3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:25:57 -1100 Subject: [PATCH 204/623] Test --- 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 23ba352dd..383c84ef9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+30 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From a3b8c12830810f7d8b81bf7bfe5296675d2aa550 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:26:39 -1100 Subject: [PATCH 205/623] Test --- 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 383c84ef9..c4374737f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-63 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 48c3fcbed30c10ef75297659012ab036bceaca30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:48:09 -1100 Subject: [PATCH 206/623] Snapshot() reverse iterator --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..ae15d37e1 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,7 +402,7 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { @@ -428,7 +428,7 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } From 6651944ae70065fa8f4a93c4fb81d2263d04f360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:59:08 -1100 Subject: [PATCH 207/623] Test --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index ae15d37e1..31af362ac 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -400,7 +400,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { - char chType; int64_t total = -1; std::string address; + char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); @@ -428,7 +428,6 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -436,6 +435,7 @@ int64_t CBlockTreeDB::Snapshot() } catch (const std::exception& e) { break; } + pcursor->Prev(); } return(total); } From 7246f7f31d21875d47ea815bf822bada3a88ad0c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 15 Jul 2018 22:01:35 -0700 Subject: [PATCH 208/623] WIP correctly calculate block progress for asset chains --- src/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..c17f4456f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3195,10 +3195,18 @@ void static UpdateTip(CBlockIndex *pindexNew) { nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); KOMODO_NEWBLOCKS++; + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + } else { + progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + } + LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); From 3bd2c3bd6a060f3408a22aff6debaa76865b0884 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 16 Jul 2018 07:57:56 +0000 Subject: [PATCH 209/623] Fix progress estimate for asset chains, mostly --- src/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c17f4456f..2ef9eb519 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3199,7 +3199,8 @@ void static UpdateTip(CBlockIndex *pindexNew) { if ( ASSETCHAINS_SYMBOL[0] == 0 ) { progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); } else { - progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + int32_t longestchain = komodo_longestchain(); + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, @@ -4858,11 +4859,21 @@ bool static LoadBlockIndexDB() it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor(); PruneBlockIndexCandidates(); + + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()); + } else { + int32_t longestchain = komodo_longestchain(); + // TODO: komodo_longestchain does not have the data it needs at the time LoadBlockIndexDB + // runs, which makes it return 0, so we guess 50% for now + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5; + } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip())); + progress); EnforceNodeDeprecation(chainActive.Height(), true); From 8d487e52a7f01b137e3704315e0eedcf8e6b001c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 21:41:16 -1100 Subject: [PATCH 210/623] Change deprecation height for 1400000 --- src/deprecation.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/deprecation.h b/src/deprecation.h index 78ed8ebda..ec8b084d9 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -6,14 +6,14 @@ #define ZCASH_DEPRECATION_H // Deprecation policy: -// * Shut down 16 weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the 2 weeks' worth of blocks prior to shut down. -static const int APPROX_RELEASE_HEIGHT = 800000; -static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 24); +// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. +// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. +//static const int APPROX_RELEASE_HEIGHT = 800000; +//static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months +static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and From 86131275722b856b80d3032d74f89d94ff6e0ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 22:47:16 -1100 Subject: [PATCH 211/623] LastTip() and tweak deprecation heights --- src/chain.cpp | 1 + src/chain.h | 6 ++++++ src/deprecation.h | 10 ++++----- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 16 +++++++------- src/komodo_gateway.h | 2 +- src/komodo_jumblr.h | 2 +- src/komodo_pax.h | 4 ++-- src/main.cpp | 44 +++++++++++++++++++-------------------- src/metrics.cpp | 2 +- src/miner.cpp | 34 +++++++++++++++--------------- src/rest.cpp | 6 +++--- src/rpcblockchain.cpp | 30 +++++++++++++------------- src/rpcmining.cpp | 24 ++++++++++----------- src/rpcmisc.cpp | 8 +++---- src/rpcrawtransaction.cpp | 2 +- src/txmempool.cpp | 2 +- src/wallet/rpcdump.cpp | 8 +++---- src/wallet/rpcwallet.cpp | 12 +++++------ src/wallet/wallet.cpp | 12 +++++------ 20 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 7bb72d5d3..d79a66f9a 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -11,6 +11,7 @@ using namespace std; * CChain implementation */ void CChain::SetTip(CBlockIndex *pindex) { + lastTip = pindex; if (pindex == NULL) { vChain.clear(); return; diff --git a/src/chain.h b/src/chain.h index 71d788531..d882083e6 100644 --- a/src/chain.h +++ b/src/chain.h @@ -416,6 +416,7 @@ public: class CChain { private: std::vector vChain; + CBlockIndex *lastTip; public: /** Returns the index entry for the genesis block of this chain, or NULL if none. */ @@ -427,6 +428,11 @@ public: CBlockIndex *Tip() const { return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL; } + + /** Returns the last tip of the chain, or NULL if none. */ + CBlockIndex *LastTip() const { + return vChain.size() > 0 ? lastTip : NULL; + } /** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */ CBlockIndex *operator[](int nHeight) const { diff --git a/src/deprecation.h b/src/deprecation.h index ec8b084d9..11eb69ef4 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -7,13 +7,13 @@ // Deprecation policy: // * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. -//static const int APPROX_RELEASE_HEIGHT = 800000; -//static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); +// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down. +static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; +static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months +static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and diff --git a/src/komodo.h b/src/komodo.h index ae0898ed3..e89dea2e4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -823,7 +823,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_event_rewind(sp,symbol,pindex->nHeight); komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } - komodo_currentheight_set(chainActive.Tip()->nHeight); + komodo_currentheight_set(chainActive.LastTip()->nHeight); if ( pindex != 0 ) { height = pindex->nHeight; @@ -907,7 +907,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime()); + notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( 0 && i > 0 ) { for (k=0; kGetBlockTime()); + if ( chainActive.LastTip() != 0 ) + return((uint32_t)chainActive.LastTip()->GetBlockTime()); else return(0); } @@ -760,11 +760,11 @@ CBlockIndex *komodo_chainactive(int32_t height) { if ( chainActive.Tip() != 0 ) { - if ( height <= chainActive.Tip()->nHeight ) + if ( height <= chainActive.LastTip()->nHeight ) return(chainActive[height]); - // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); + // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight); } - //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height); return(0); } @@ -994,7 +994,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex; - if ( (pindex= chainActive.Tip()) == 0 ) + if ( (pindex= chainActive.LastTip()) == 0 ) return(-1); notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid); *notarized_heightp = notarized_height; @@ -1036,7 +1036,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_ *valuep = tx.vout[n].nValue; *txheightp = pindex->nHeight; *txheighttimep = pindex->nTime; - if ( *tiptimep == 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 ) *tiptimep = (uint32_t)tipindex->nTime; locktime = tx.nLockTime; //fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); @@ -1069,7 +1069,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 ) *kmdheightp = sp->CURRENT_HEIGHT; else *kmdheightp = 0; - if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) + if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) return(1); else return(0); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9de6b4fc9..6a8ef310b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1490,7 +1490,7 @@ void komodo_passport_iteration() komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"wb")) != 0 ) { - buf[0] = (uint32_t)chainActive.Tip()->nHeight; + buf[0] = (uint32_t)chainActive.LastTip()->nHeight; buf[1] = (uint32_t)komodo_longestchain(); if ( buf[0] != 0 && buf[0] == buf[1] ) { diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index f36bb441a..fa44425fd 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -648,7 +648,7 @@ void jumblr_iteration() free(retstr); } } - height = (int32_t)chainActive.Tip()->nHeight; + height = (int32_t)chainActive.LastTip()->nHeight; if ( time(NULL) < lasttime+40 ) return; lasttime = (uint32_t)time(NULL); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d0bad0e14..35d226fc3 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -637,13 +637,13 @@ uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->nHeight ) { if ( height < 100000000 ) { static uint32_t counter; if ( counter++ < 3 ) - printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight); + printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->nHeight); } return(0); } diff --git a/src/main.cpp b/src/main.cpp index 2ef9eb519..330bf6ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1269,7 +1269,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) + if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1399,7 +1399,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime); if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool @@ -1891,7 +1891,7 @@ void CheckForkWarningConditions() if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 288) pindexBestForkTip = NULL; - if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6))) + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.LastTip()->nChainWork + (GetBlockProof(*chainActive.LastTip()) * 6))) { if (!fLargeWorkForkFound && pindexBestForkBase) { @@ -1926,7 +1926,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) AssertLockHeld(cs_main); // If we are on a fork that is sufficiently large, set a warning flag CBlockIndex* pfork = pindexNewForkTip; - CBlockIndex* plonger = chainActive.Tip(); + CBlockIndex* plonger = chainActive.LastTip(); while (pfork && pfork != plonger) { while (plonger && plonger->nHeight > pfork->nHeight) @@ -1983,7 +1983,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime())); - CBlockIndex *tip = chainActive.Tip(); + CBlockIndex *tip = chainActive.LastTip(); assert (tip); LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__, tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0), @@ -2111,14 +2111,14 @@ namespace Consensus { // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( coins->vout[prevout.n].nValue >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue,(int32_t)nSpendHeight-1)) != 0 ) { - //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.LastTip()->nTime); nValueIn += interest; } } @@ -2868,7 +2868,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!tx.IsCoinBase()) { - nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); + nFees += view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime) - tx.GetValueOut(); sum += interest; std::vector vChecks; @@ -3197,16 +3197,16 @@ void static UpdateTip(CBlockIndex *pindexNew) { KOMODO_NEWBLOCKS++; double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); } else { int32_t longestchain = komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.LastTip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress, pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); @@ -3455,7 +3455,7 @@ static void PruneBlockIndexCandidates() { // Note that we can't delete the current block itself, as we may need to return to it later in case a // reorganization to a better block fails. std::set::iterator it = setBlockIndexCandidates.begin(); - while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) { + while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.LastTip())) { setBlockIndexCandidates.erase(it++); } // Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates. @@ -3507,8 +3507,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if ( KOMODO_REWIND != 0 ) { CBlockIndex *tipindex; - fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->nHeight,KOMODO_REWIND); - while ( KOMODO_REWIND > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->nHeight,KOMODO_REWIND); + while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) { fBlocksDisconnected = true; fprintf(stderr,"%d ",(int32_t)tipindex->nHeight); @@ -3922,9 +3922,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- CheckBlockHeader\n"); - if ( chainActive.Tip() != 0 ) + if ( chainActive.LastTip() != 0 ) { - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip\n"); @@ -4103,7 +4103,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + if ( nHeight == 1 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight > 1 ) { CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) @@ -4440,8 +4440,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - if ( chainActive.Tip() != 0 ) - komodo_currentheight_set(chainActive.Tip()->nHeight); + if ( chainActive.LastTip() != 0 ) + komodo_currentheight_set(chainActive.LastTip()->nHeight); checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); { LOCK(cs_main); @@ -4871,8 +4871,8 @@ bool static LoadBlockIndexDB() } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress); EnforceNodeDeprecation(chainActive.Height(), true); diff --git a/src/metrics.cpp b/src/metrics.cpp index 6c8f80fe5..cb9fe245c 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -211,7 +211,7 @@ int printStats(bool mining) { LOCK2(cs_main, cs_vNodes); height = chainActive.Height(); - tipmediantime = chainActive.Tip()->GetMedianTimePast(); + tipmediantime = chainActive.LastTip()->GetMedianTimePast(); connections = vNodes.size(); netsolps = GetNetworkHashPS(120, -1); } diff --git a/src/miner.cpp b/src/miner.cpp index dbe6dc41c..0c458a985 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -166,7 +166,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { LOCK2(cs_main, mempool.cs); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->nHeight + 1; uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus()); pblock->nTime = GetAdjustedTime(); @@ -334,7 +334,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } - CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -400,14 +400,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + //if ( (int32_t)chainActive.LastTip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } @@ -640,19 +640,19 @@ static bool ProcessBlockFound(CBlock* pblock) #endif // ENABLE_WALLET { LogPrintf("%s\n", pblock->ToString()); - LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1); + LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1); // Found a solution { LOCK(cs_main); - if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) + if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash()) { uint256 hash; int32_t i; hash = pblock->hashPrevBlock; for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- prev (stale)\n"); - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); @@ -680,7 +680,7 @@ static bool ProcessBlockFound(CBlock* pblock) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); @@ -718,13 +718,13 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; - while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 && + while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.LastTip()->nHeight != 235300 && { sleep(1); if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) break; } - komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); + komodo_chosennotary(¬aryid,chainActive.LastTip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; @@ -750,9 +750,9 @@ void static BitcoinMiner() fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { - if (chainparams.MiningRequiresPeers()) //chainActive.Tip()->nHeight != 235300 && + if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->nHeight != 235300 && { - //if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 ) + //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->nHeight < 100 ) // break; // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. @@ -776,7 +776,7 @@ void static BitcoinMiner() // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); if ( Mining_height != pindexPrev->nHeight+1 ) { Mining_height = pindexPrev->nHeight+1; @@ -962,7 +962,7 @@ void static BitcoinMiner() while ( GetAdjustedTime() < B.nTime-2 ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) { fprintf(stderr,"new block arrived\n"); return(false); @@ -983,7 +983,7 @@ void static BitcoinMiner() while ( B.nTime-57 > GetAdjustedTime() ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) return(false); } uint256 tmp = B.GetHash(); @@ -992,7 +992,7 @@ void static BitcoinMiner() fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height); } CValidationState state; - if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) + if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); for (z=31; z>=0; z--) @@ -1112,7 +1112,7 @@ void static BitcoinMiner() fprintf(stderr,"timeout, break\n"); break; } - if ( pindexPrev != chainActive.Tip() ) + if ( pindexPrev != chainActive.LastTip() ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"Tip advanced, break\n"); diff --git a/src/rest.cpp b/src/rest.cpp index 8e2e4d1e6..38cc38466 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -530,7 +530,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // serialize data // use exact same output as mentioned in Bip64 CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string ssGetUTXOResponseString = ssGetUTXOResponse.str(); req->WriteHeader("Content-Type", "application/octet-stream"); @@ -540,7 +540,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) case RF_HEX: { CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n"; req->WriteHeader("Content-Type", "text/plain"); @@ -554,7 +554,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // pack in some essentials // use more or less the same output as mentioned in Bip64 objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height())); - objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex())); + objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.LastTip()->GetBlockHash().GetHex())); objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation)); UniValue utxos(UniValue::VARR); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 42cf7f2b0..7f8984c63 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -38,10 +38,10 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul // minimum difficulty = 1.0. if (blockindex == NULL) { - if (chainActive.Tip() == NULL) + if (chainActive.LastTip() == NULL) return 1.0; else - blockindex = chainActive.Tip(); + blockindex = chainActive.LastTip(); } uint32_t bits; @@ -326,7 +326,7 @@ UniValue getbestblockhash(const UniValue& params, bool fHelp) ); LOCK(cs_main); - return chainActive.Tip()->GetBlockHash().GetHex(); + return chainActive.LastTip()->GetBlockHash().GetHex(); } UniValue getdifficulty(const UniValue& params, bool fHelp) @@ -803,13 +803,13 @@ UniValue kvsearch(const UniValue& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->nHeight)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); @@ -837,7 +837,7 @@ UniValue minerids(const UniValue& params, bool fHelp) LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else { CBlockIndex *pblockindex = chainActive[height]; @@ -899,8 +899,8 @@ UniValue notaries(const UniValue& params, bool fHelp) else timestamp = (uint32_t)time(NULL); if ( height < 0 ) { - height = chainActive.Tip()->nHeight; - timestamp = chainActive.Tip()->GetBlockTime(); + height = chainActive.LastTip()->nHeight; + timestamp = chainActive.LastTip()->GetBlockTime(); } else if ( params.size() < 2 ) { @@ -988,7 +988,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) std::string rel = params[1].get_str(); int32_t height; if ( params.size() == 2 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else height = atoi(params[2].get_str().c_str()); //if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 ) basevolume = 100000; @@ -1280,10 +1280,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); - obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); + obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); - obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()))); - obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()))); + obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); ZCIncrementalMerkleTree tree; @@ -1294,7 +1294,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("commitments", tree.size())); #endif - CBlockIndex* tip = chainActive.Tip(); + CBlockIndex* tip = chainActive.LastTip(); UniValue valuePools(UniValue::VARR); valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none)); obj.push_back(Pair("valuePools", valuePools)); @@ -1319,7 +1319,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) if (fPruneMode) { - CBlockIndex *block = chainActive.Tip(); + CBlockIndex *block = chainActive.LastTip(); while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) block = block->pprev; @@ -1394,7 +1394,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } // Always report the currently active tip. - setTips.insert(chainActive.Tip()); + setTips.insert(chainActive.LastTip()); /* Construct the output array. */ UniValue res(UniValue::VARR); const CBlockIndex *forked; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index afe4e5a33..47fbeec30 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -39,7 +39,7 @@ using namespace std; * If 'height' is nonnegative, compute the estimate at the time when a given block was found. */ int64_t GetNetworkHashPS(int lookup, int height) { - CBlockIndex *pb = chainActive.Tip(); + CBlockIndex *pb = chainActive.LastTip(); if (height >= 0 && height < chainActive.Height()) pb = chainActive[height]; @@ -224,7 +224,7 @@ UniValue generate(const UniValue& params, bool fHelp) CBlock *pblock = &pblocktemplate->block; { LOCK(cs_main); - IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce); + IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce); } // Hash state @@ -268,7 +268,7 @@ UniValue generate(const UniValue& params, bool fHelp) } endloop: CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -550,7 +550,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) return "duplicate-inconclusive"; } - CBlockIndex* const pindexPrev = chainActive.Tip(); + CBlockIndex* const pindexPrev = chainActive.LastTip(); // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; @@ -589,7 +589,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) else { // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier - hashWatchedChain = chainActive.Tip()->GetBlockHash(); + hashWatchedChain = chainActive.LastTip()->GetBlockHash(); nTransactionsUpdatedLastLP = nTransactionsUpdatedLast; } @@ -599,7 +599,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) checktxtime = boost::get_system_time() + boost::posix_time::minutes(1); boost::unique_lock lock(csBestBlock); - while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) + while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) { if (!cvBlockChange.timed_wait(lock, checktxtime)) { @@ -621,7 +621,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) static CBlockIndex* pindexPrev; static int64_t nStart; static CBlockTemplate* pblocktemplate; - if (pindexPrev != chainActive.Tip() || + if (pindexPrev != chainActive.LastTip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on @@ -629,7 +629,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Store the pindexBest used before CreateNewBlockWithKey, to avoid races nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrevNew = chainActive.Tip(); + CBlockIndex* pindexPrevNew = chainActive.LastTip(); nStart = GetTime(); // Create new block @@ -640,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT); #else pblocktemplate = CreateNewBlockWithKey(); #endif @@ -693,7 +693,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Correct this if GetBlockTemplate changes the order // entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); //} - CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus()); + CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->nHeight+1, Params().GetConsensus()); entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; @@ -726,7 +726,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); } - result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); + result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); @@ -809,7 +809,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bf7f345d5..4405a407d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -133,8 +133,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); obj.push_back(Pair("longestchain", longestchain)); obj.push_back(Pair("timeoffset", GetTimeOffset())); - if ( chainActive.Tip() != 0 ) - obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); + if ( chainActive.LastTip() != 0 ) + obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); @@ -152,7 +152,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("errors", GetWarnings("statusbar"))); { char pubkeystr[65]; int32_t notaryid; - if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) + if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); @@ -826,7 +826,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp) result.push_back(Pair("utxos", utxos)); LOCK(cs_main); - result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex())); + result.push_back(Pair("hash", chainActive.LastTip()->GetBlockHash().GetHex())); result.push_back(Pair("height", (int)chainActive.Height())); return result; } else { diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a9aff1b7f..525c35ca4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -179,7 +179,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->nHeight); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 51ed1103e..e96f0d975 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -437,7 +437,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - tipindex = chainActive.Tip(); + tipindex = chainActive.LastTip(); if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0) { transactionsToRemove.push_back(tx); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 15caad846..c8dc7aa5b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -278,7 +278,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - int64_t nTimeBegin = chainActive.Tip()->GetBlockTime(); + int64_t nTimeBegin = chainActive.LastTip()->GetBlockTime(); bool fGood = true; @@ -364,7 +364,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys file.close(); pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI - CBlockIndex *pindex = chainActive.Tip(); + CBlockIndex *pindex = chainActive.LastTip(); while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) pindex = pindex->pprev; @@ -509,8 +509,8 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) // produce output file << strprintf("# Wallet dump created by Komodo %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); - file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); - file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); + file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.LastTip()->GetBlockHash().ToString()); + file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.LastTip()->GetBlockTime())); file << "\n"; for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID &keyid = it->second; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c4374737f..084a4f752 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -574,7 +574,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) valuesize = (int32_t)strlen(params[1].get_str().c_str()); } memcpy(keyvalue,key,keylen); - if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) { if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) { @@ -599,7 +599,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) // printf("%02x",((uint8_t *)&sig)[i]); //printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height", (int64_t)height)); @@ -671,7 +671,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis ) { fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis); @@ -2713,13 +2713,13 @@ UniValue listunspent(const UniValue& params, bool fHelp) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } - //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); @@ -2746,7 +2746,7 @@ uint64_t komodo_interestsum() { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index df0cd9c2b..ce5630fb6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false); - double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false); + double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false); while (pindex) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) @@ -2299,20 +2299,20 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( KOMODO_EXCHANGEWALLET == 0 ) { uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( pcoin->vout[i].nValue >= 10*COIN ) { - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( (tipindex= chainActive.LastTip()) != 0 ) { komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->nHeight); interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); } else interest = 0; - //interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + //interest = komodo_interestnew(chainActive.LastTip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime); if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime); - //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.LastTip()->nHeight+1,pcoin->nLockTime,chainActive.LastTip()->nTime); //ptr = (uint64_t *)&pcoin->vout[i].nValue; //(*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -2687,7 +2687,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction txNew = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now + txNew.nLockTime = (uint32_t)chainActive.LastTip()->nTime + 1; // set to a time close to now // Activates after Overwinter network upgrade // Set nExpiryHeight to expiryDelta (default 20) blocks past current block height From 17839698a34ac122200fe4eaf82f709b3b1c94a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jul 2018 00:55:48 -1100 Subject: [PATCH 212/623] block_from_future_rejecttime used in RAMstaker --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 084a4f752..02cea5bef 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4737,6 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } + block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inHeight+1 > nHeight ) @@ -4758,7 +4759,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-63 ) + if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From d62d9d7889f7c647f19534f0986e0e9372db6377 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 01:40:24 +0000 Subject: [PATCH 213/623] Almost working snapshot, we need to sum unspent outputs for each address and return to final snapshot data in json response --- src/txdb.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index fa3766faf..dfef647e6 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -400,36 +400,30 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { - char chType; int64_t total = -1; std::string address; + char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); - //boost::scoped_ptr pcursor(pdb->NewIterator(leveldb::ReadOptions()) ); - //boost::scoped_ptr pcursor(db->NewIterator()); - fprintf(stderr,"Snapshot\n"); - + //pcursor->SeekToFirst(); pcursor->SeekToLast(); - fprintf(stderr,"SeekToLast\n"); - fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { - fprintf(stderr,"pcursor valid\n"); + //fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); - fprintf(stderr,"about to try\n"); try { leveldb::Slice slKey = pcursor->key(); - fprintf(stderr,"made slice\n"); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); - fprintf(stderr,"made ssKey\n"); - CAddressIndexKey indexKey; + // CAddressIndexKey indexKey; + CAddressIndexIteratorKey indexKey; ssKey >> chType; - fprintf(stderr,"made chType\n"); ssKey >> indexKey; - fprintf(stderr,"made indexKey\n"); - fprintf(stderr,"chType.%d\n",chType); - if ( chType == DB_ADDRESSINDEX ) + //fprintf(stderr,"chType.%d\n",chType); + //fprintf(stderr,"dbindex prefix=%d\n",DB_ADDRESSINDEX); + //if ( chType == 'u' ) // chType == DB_ADDRESSINDEX ) + if ( chType == DB_ADDRESSUNSPENTINDEX ) // chType == DB_ADDRESSINDEX ) { + try { leveldb::Slice slValue = pcursor->value(); CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); @@ -437,11 +431,9 @@ int64_t CBlockTreeDB::Snapshot() ssValue >> nValue; getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - if ( total < 0 ) - total = (int64_t)nValue; - else total += (int64_t)nValue; + + total += (double) nValue / COIN; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -450,6 +442,7 @@ int64_t CBlockTreeDB::Snapshot() fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } + pcursor->Prev(); } return(total); } From 920f9601222ad9d4d047e6242e75e539ed991f03 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 06:05:36 +0000 Subject: [PATCH 214/623] Correctly print out snapshot data to stderr for now --- src/txdb.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index dfef647e6..00d3d276b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,38 +402,46 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); + std::map addressAmounts; //pcursor->SeekToFirst(); pcursor->SeekToLast(); while (pcursor->Valid()) { - //fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); try { leveldb::Slice slKey = pcursor->key(); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); - // CAddressIndexKey indexKey; CAddressIndexIteratorKey indexKey; ssKey >> chType; ssKey >> indexKey; - //fprintf(stderr,"chType.%d\n",chType); - //fprintf(stderr,"dbindex prefix=%d\n",DB_ADDRESSINDEX); - //if ( chType == 'u' ) // chType == DB_ADDRESSINDEX ) - if ( chType == DB_ADDRESSUNSPENTINDEX ) // chType == DB_ADDRESSINDEX ) - { + if ( chType == DB_ADDRESSUNSPENTINDEX ) + { try { leveldb::Slice slValue = pcursor->value(); CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; + //if (!getAddressFromIndex(indexKey.type, indexKey.hashBytes, address)) { getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - total += (double) nValue / COIN; - //addressIndex.push_back(make_pair(indexKey, nValue)); + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + } else { + // update unspent tally for this address + addressAmounts[address] += nValue; + } + + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + total += (double) nValue / COIN; + //addressIndex.push_back(make_pair(indexKey, nValue)); + //} } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -442,8 +450,14 @@ int64_t CBlockTreeDB::Snapshot() fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } - pcursor->Prev(); + pcursor->Prev(); } + + for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) + { + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + } + return(total); } From 7000ef1af3ddfc99bde07c185c781ea198d5eea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:26:34 -1100 Subject: [PATCH 215/623] Possible workaround for crash --- src/wallet/wallet.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ce5630fb6..e62c6e60b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1885,6 +1885,11 @@ void CWallet::ReacceptWalletTransactions() bool CWalletTx::RelayWalletTransaction() { + if ( pwallet == 0 ) + { + fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); + return(false); + } assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase()) { @@ -2124,9 +2129,13 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx = *item.second; - if (wtx.RelayWalletTransaction()) - result.push_back(wtx.GetHash()); + CWalletTx& wtx; + if ( item.second != 0 ) + { + wtx = *item.second; + if (wtx.RelayWalletTransaction()) + result.push_back(wtx.GetHash()); + } } return result; } From 3872e9cb59b99fbffc23ea9fa3587afbb68a524c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:29:01 -1100 Subject: [PATCH 216/623] Fix --- src/wallet/wallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e62c6e60b..5100a2470 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2129,10 +2129,9 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx; if ( item.second != 0 ) { - wtx = *item.second; + CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction()) result.push_back(wtx.GetHash()); } From 92dc28a3c92a1b5fea3c5ccf69dd796c6664e7b6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 18:42:30 +0000 Subject: [PATCH 217/623] Return snapshot info as JSON --- src/main.cpp | 9 ++++----- src/rpcmisc.cpp | 12 ++++++++---- src/txdb.cpp | 43 ++++++++++++++++++++++++------------------- src/txdb.h | 3 ++- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 15d74adb2..dfebfec4f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -588,21 +588,20 @@ CBlockTreeDB *pblocktree = NULL; #define KOMODO_ZCASH #include "komodo.h" -int64_t komodo_snapshot() +UniValue komodo_snapshot() { - fprintf(stderr,"komodo_snapshot\n"); int64_t total = -1; + UniValue result(UniValue::VOBJ); if (fAddressIndex) { if ( pblocktree != 0 ) { - total = pblocktree->Snapshot(); + result = pblocktree->Snapshot(); } else { fprintf(stderr,"null pblocktree start with -addressindex=true\n"); } } else { fprintf(stderr,"getsnapshot requires -addressindex=true\n"); } - fprintf(stderr,"total=%li\n", total); - return(total); + return(result); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bf7f345d5..198b41090 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -1015,7 +1015,7 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) } -int32_t komodo_snapshot(); +UniValue komodo_snapshot(); UniValue getsnapshot(const UniValue& params, bool fHelp) { @@ -1026,9 +1026,13 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) "getsnapshot\n" ); } - if ( (total= komodo_snapshot()) >= 0 ) - result.push_back(Pair("total", (double)total/COIN)); - else result.push_back(Pair("error", "no addressindex")); + result = komodo_snapshot(); + if ( result.size() > 0 ) { + // add timestamp, maybe block height? + result.push_back(Pair("time", time(NULL))); + } else { + result.push_back(Pair("error", "no addressindex")); + } return(result); } diff --git a/src/txdb.cpp b/src/txdb.cpp index 00d3d276b..63b640123 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -10,6 +10,7 @@ #include "main.h" #include "pow.h" #include "uint256.h" +#include "core_io.h" #include @@ -398,11 +399,12 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); -int64_t CBlockTreeDB::Snapshot() +extern UniValue CBlockTreeDB::Snapshot() { - char chType; int64_t total = 0; std::string address; + char chType; int64_t total = 0; int64_t totalAddresses = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); std::map addressAmounts; + UniValue result(UniValue::VOBJ); //pcursor->SeekToFirst(); pcursor->SeekToLast(); @@ -425,23 +427,22 @@ int64_t CBlockTreeDB::Snapshot() CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; - //if (!getAddressFromIndex(indexKey.type, indexKey.hashBytes, address)) { - getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - std::map ::iterator pos = addressAmounts.find(address); - if (pos == addressAmounts.end()) { - // insert new address + utxo amount - fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); - addressAmounts[address] = nValue; - } else { - // update unspent tally for this address - addressAmounts[address] += nValue; - } + getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } else { + // update unspent tally for this address + addressAmounts[address] += nValue; + } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - total += (double) nValue / COIN; - //addressIndex.push_back(make_pair(indexKey, nValue)); - //} + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + total += nValue; + //addressIndex.push_back(make_pair(indexKey, nValue)); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -453,12 +454,16 @@ int64_t CBlockTreeDB::Snapshot() pcursor->Prev(); } + // TODO: create addresses key with array of {address,amount} + + fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) { - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + result.push_back(make_pair( it->first.c_str(), (double) it->second / COIN ) ); } - return(total); + return(result); } bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) { diff --git a/src/txdb.h b/src/txdb.h index cb4d6d19e..6c6b41917 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -13,6 +13,7 @@ #include #include #include +#include class CBlockFileInfo; class CBlockIndex; @@ -94,7 +95,7 @@ public: bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); - int64_t Snapshot(); + UniValue Snapshot(); }; #endif // BITCOIN_TXDB_H From 29a5aa99fd5090bf3ca1b1248a844807bcff377c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 19:39:55 +0000 Subject: [PATCH 218/623] Move address+amount data to addresses key in JSON; add some useful metadata to snapshot response --- src/txdb.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 63b640123..9170ceea0 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -454,15 +454,23 @@ extern UniValue CBlockTreeDB::Snapshot() pcursor->Prev(); } - // TODO: create addresses key with array of {address,amount} + UniValue addresses(UniValue::VARR); fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) { - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); - result.push_back(make_pair( it->first.c_str(), (double) it->second / COIN ) ); + UniValue obj(UniValue::VOBJ); + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + obj.push_back( make_pair("addr", it->first.c_str() ) ); + obj.push_back( make_pair("amount", (double) it->second / COIN)); + addresses.push_back(obj); } + result.push_back(make_pair("addresses", addresses)); + result.push_back(make_pair("total", total / COIN )); + result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + result.push_back(make_pair("total_addresses", totalAddresses)); + result.push_back(make_pair("height", chainActive.Height())); return(result); } From 6e74fd25780d8ac14d20bd89d5ced6eb368e7440 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 21:37:52 +0000 Subject: [PATCH 219/623] In memory sorting, add a few metadata fields; printing small floats correctly still not working --- src/txdb.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 9170ceea0..b4ea54f9b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -409,6 +409,14 @@ extern UniValue CBlockTreeDB::Snapshot() //pcursor->SeekToFirst(); pcursor->SeekToLast(); + int64_t startingHeight = chainActive.Height(); + + // prevent any node updates so we can get a consistent snapshot at this height + // causes coredumps + // LOCK(cs_main); + // does not compile + //LOCK(cs_wallet); + while (pcursor->Valid()) { boost::this_thread::interruption_point(); @@ -442,7 +450,6 @@ extern UniValue CBlockTreeDB::Snapshot() //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); total += nValue; - //addressIndex.push_back(make_pair(indexKey, nValue)); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -455,22 +462,39 @@ extern UniValue CBlockTreeDB::Snapshot() } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); - for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) - { - UniValue obj(UniValue::VOBJ); - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); - obj.push_back( make_pair("addr", it->first.c_str() ) ); - obj.push_back( make_pair("amount", (double) it->second / COIN)); - addresses.push_back(obj); + + typedef std::function, std::pair)> Comparator; + Comparator compFunctor = [](std::pair elem1 ,std::pair elem2) { + return elem1.second > elem2.second; /* descending */ + }; + // This is our intermediate data structure that allows us to calculate addressSorted + std::set, Comparator> sortedSnapshot(addressAmounts.begin(), addressAmounts.end(), compFunctor); + + UniValue obj(UniValue::VOBJ); + UniValue addressesSorted(UniValue::VARR); + for (std::pair element : sortedSnapshot) { + UniValue obj(UniValue::VOBJ); + obj.push_back( make_pair("addr", element.first.c_str() ) ); + std::ostringstream strs; + strs << ((double) element.second/COIN); + std::string amount = strs.str(); + + //std::string amount = boost::lexical_cast((double) element.second/COIN); + //sprintf(amount, "%.8f", (double) element.second / COIN); + obj.push_back( make_pair("amount", amount) ); + addressesSorted.push_back(obj); } - result.push_back(make_pair("addresses", addresses)); + result.push_back(make_pair("addresses", addressesSorted)); result.push_back(make_pair("total", total / COIN )); result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + // Total number of addresses in this snaphot result.push_back(make_pair("total_addresses", totalAddresses)); - result.push_back(make_pair("height", chainActive.Height())); + // The snapshot began at this block height + result.push_back(make_pair("start_height", startingHeight)); + // The snapshot finished at this block height + result.push_back(make_pair("ending_height", chainActive.Height())); return(result); } From 3eb535b8b4c61e63027611aaf02f3a4dcae9626b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 22:31:06 +0000 Subject: [PATCH 220/623] Include start_time+end_time and correctly format amount --- src/main.cpp | 1 + src/rpcmisc.cpp | 3 +-- src/txdb.cpp | 15 +++------------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dfebfec4f..11bc3a352 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -592,6 +592,7 @@ UniValue komodo_snapshot() { int64_t total = -1; UniValue result(UniValue::VOBJ); + if (fAddressIndex) { if ( pblocktree != 0 ) { result = pblocktree->Snapshot(); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 198b41090..01bd813e6 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -1028,8 +1028,7 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) } result = komodo_snapshot(); if ( result.size() > 0 ) { - // add timestamp, maybe block height? - result.push_back(Pair("time", time(NULL))); + result.push_back(Pair("end_time", time(NULL))); } else { result.push_back(Pair("error", "no addressindex")); } diff --git a/src/txdb.cpp b/src/txdb.cpp index b4ea54f9b..2360ed340 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -405,18 +405,13 @@ extern UniValue CBlockTreeDB::Snapshot() boost::scoped_ptr pcursor(NewIterator()); std::map addressAmounts; UniValue result(UniValue::VOBJ); + result.push_back(Pair("start_time", time(NULL))); //pcursor->SeekToFirst(); pcursor->SeekToLast(); int64_t startingHeight = chainActive.Height(); - // prevent any node updates so we can get a consistent snapshot at this height - // causes coredumps - // LOCK(cs_main); - // does not compile - //LOCK(cs_wallet); - while (pcursor->Valid()) { boost::this_thread::interruption_point(); @@ -476,12 +471,8 @@ extern UniValue CBlockTreeDB::Snapshot() for (std::pair element : sortedSnapshot) { UniValue obj(UniValue::VOBJ); obj.push_back( make_pair("addr", element.first.c_str() ) ); - std::ostringstream strs; - strs << ((double) element.second/COIN); - std::string amount = strs.str(); - - //std::string amount = boost::lexical_cast((double) element.second/COIN); - //sprintf(amount, "%.8f", (double) element.second / COIN); + char amount[32]; + sprintf(amount, "%.8f", (double) element.second / COIN); obj.push_back( make_pair("amount", amount) ); addressesSorted.push_back(obj); } From 539080b3a4109285dc1a3b77fb5a15e782d7cc7e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 22:33:19 +0000 Subject: [PATCH 221/623] Less noise to stderr --- src/txdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 2360ed340..cb0358403 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -435,7 +435,7 @@ extern UniValue CBlockTreeDB::Snapshot() std::map ::iterator pos = addressAmounts.find(address); if (pos == addressAmounts.end()) { // insert new address + utxo amount - fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); addressAmounts[address] = nValue; totalAddresses++; } else { From 4ac134db0c5c0e7e99222bfd3f2fb62f255094eb Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 18 Jul 2018 02:34:10 -0400 Subject: [PATCH 222/623] change zcashd reference, update example conf --- contrib/debian/examples/komodo.conf | 140 ++++++++++++++++++++++++++++ src/bitcoind.cpp | 12 +-- 2 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 contrib/debian/examples/komodo.conf diff --git a/contrib/debian/examples/komodo.conf b/contrib/debian/examples/komodo.conf new file mode 100644 index 000000000..656a43533 --- /dev/null +++ b/contrib/debian/examples/komodo.conf @@ -0,0 +1,140 @@ +## +## komodo.conf configuration file. Lines beginning with # are comments. +## + +# Network-related settings: + +# Run a regression test network +#regtest=0 + +# Connect via a SOCKS5 proxy +#proxy=127.0.0.1:9050 + +# Bind to given address and always listen on it. Use [host]:port notation for IPv6 +#bind= + +# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6 +#whitebind= + +############################################################## +## Quick Primer on addnode vs connect ## +## Let's say for instance you use addnode=4.2.2.4 ## +## addnode will connect you to and tell you about the ## +## nodes connected to 4.2.2.4. In addition it will tell ## +## the other nodes connected to it that you exist so ## +## they can connect to you. ## +## connect will not do the above when you 'connect' to it. ## +## It will *only* connect you to 4.2.2.4 and no one else.## +## ## +## So if you're behind a firewall, or have other problems ## +## finding nodes, add some using 'addnode'. ## +## ## +## If you want to stay private, use 'connect' to only ## +## connect to "trusted" nodes. ## +## ## +## If you run multiple nodes on a LAN, there's no need for ## +## all of them to open lots of connections. Instead ## +## 'connect' them all to one node that is port forwarded ## +## and has lots of connections. ## +## Thanks goes to [Noodle] on Freenode. ## +############################################################## + +# Use as many addnode= settings as you like to connect to specific peers +#addnode=69.164.218.197 +#addnode=10.0.0.2:8233 + +# Alternatively use as many connect= settings as you like to connect ONLY to specific peers +#connect=69.164.218.197 +#connect=10.0.0.1:8233 + +# Listening mode, enabled by default except when 'connect' is being used +#listen=1 + +# Maximum number of inbound+outbound connections. +#maxconnections= + +# +# JSON-RPC options (for controlling a running Komodo/komodod process) +# + +# server=1 tells komodod to accept JSON-RPC commands (set as default if not specified) +#server=1 + +# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. +# This option can be specified multiple times (default: bind to all interfaces) +#rpcbind= + +# You must set rpcuser and rpcpassword to secure the JSON-RPC api +#rpcuser=Ulysses +#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593 + +# How many seconds komodo will wait for a complete RPC HTTP request. +# after the HTTP connection is established. +#rpcclienttimeout=30 + +# By default, only RPC connections from localhost are allowed. +# Specify as many rpcallowip= settings as you like to allow connections from other hosts, +# either as a single IPv4/IPv6 or with a subnet specification. + +# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED, +# because the rpcpassword is transmitted over the network unencrypted and also because anyone +# that can authenticate on the RPC port can steal your keys + take over the account running komodod +# For more information see https://github.com/zcash/zcash/issues/1497 + +#rpcallowip=10.1.1.34/255.255.255.0 +#rpcallowip=1.2.3.4/24 +#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96 + +# Listen for RPC connections on this TCP port: +#rpcport=8232 + +# You can use Komodo or komodod to send commands to Komodo/komodod +# running on another host using this option: +#rpcconnect=127.0.0.1 + +# Transaction Fee + +# Send transactions as zero-fee transactions if possible (default: 0) +#sendfreetransactions=0 + +# Create transactions that have enough fees (or priority) so they are likely to # begin confirmation within n blocks (default: 1). +# This setting is overridden by the -paytxfee option. +#txconfirmtarget=n + +# Miscellaneous options + +# Enable attempt to mine komodo. +#gen=0 + +# Set the number of threads to be used for mining komodo (-1 = all cores). +#genproclimit=1 + +# Specify a different Equihash solver (e.g. "tromp") to try to mine komodo +# faster when gen=1. +#equihashsolver=default + +# Pre-generate this many public/private key pairs, so wallet backups will be valid for +# both prior transactions and several dozen future transactions. +#keypool=100 + +# Pay an optional transaction fee every time you send komodo. Transactions with fees +# are more likely than free transactions to be included in generated blocks, so may +# be validated sooner. This setting does not affect private transactions created with +# 'z_sendmany'. +#paytxfee=0.00 + +#Rewind the chain to specific block height. This is useful for creating snapshots at a given block height. +#rewind=777777 + +#Stop the chain a specific block height. This is useful for creating snapshots at a given block height. +#stopat=1000000 + +#Set an address to use as change address for all transactions. This value must be set to a 33 byte pubkey. All mined coins will also be sent to this address. +#pubkey=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + +#Forfeit all user rewards to miners. Set this to explicitly not claim user rewards. +#exchange=1 + +#Donate all user rewards to a a specific address. This value must be set to a 33 byte pubkey. +#donation=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 5c12cfa2f..36fea57bf 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -144,21 +144,21 @@ bool AppInit(int argc, char* argv[]) ReadConfigFile(mapArgs, mapMultiArgs); } catch (const missing_zcash_conf& e) { fprintf(stderr, - (_("Before starting zcashd, you need to create a configuration file:\n" + (_("Before starting komodod, you need to create a configuration file:\n" "%s\n" "It can be completely empty! That indicates you are happy with the default\n" - "configuration of zcashd. But requiring a configuration file to start ensures\n" - "that zcashd won't accidentally compromise your privacy if there was a default\n" + "configuration of komodod. But requiring a configuration file to start ensures\n" + "that komodod won't accidentally compromise your privacy if there was a default\n" "option you needed to change.\n" "\n" "You can look at the example configuration file for suggestions of default\n" "options that you may want to change. It should be in one of these locations,\n" - "depending on how you installed Zcash:\n") + + "depending on how you installed Komodo:\n") + _("- Source code: %s\n" "- .deb package: %s\n")).c_str(), GetConfigFile().string().c_str(), - "contrib/debian/examples/zcash.conf", - "/usr/share/doc/zcash/examples/zcash.conf"); + "contrib/debian/examples/komodo.conf", + "/usr/share/doc/komodo/examples/komodo.conf"); return false; } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); From 9ef7fec1efd4f45ca603fbd7a25aa2beae4a5f64 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 18 Jul 2018 06:54:43 +0000 Subject: [PATCH 223/623] Protect komodo_snapshot() by cs_main lock --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 1376c3c7b..aa4435843 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,6 +590,7 @@ CBlockTreeDB *pblocktree = NULL; UniValue komodo_snapshot() { + LOCK(cs_main); int64_t total = -1; UniValue result(UniValue::VOBJ); From f345b95386d1ac73bc136b549dbf6f41e1854b86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jul 2018 03:02:37 -1100 Subject: [PATCH 224/623] Initial assets --- src/cc/assets.cpp | 191 ++++++++++++++++++++ src/cc/betprotocol.cpp | 15 ++ src/cc/betprotocol.h | 15 ++ src/cc/eval.cpp | 19 ++ src/cc/eval.h | 19 +- src/cc/import.cpp | 15 ++ src/cc/utils.h | 15 ++ src/cryptoconditions/src/anon.c | 14 ++ src/cryptoconditions/src/cryptoconditions.c | 15 ++ src/cryptoconditions/src/ed25519.c | 15 ++ src/cryptoconditions/src/eval.c | 15 ++ src/cryptoconditions/src/internal.h | 15 ++ src/cryptoconditions/src/json_rpc.c | 15 ++ src/cryptoconditions/src/prefix.c | 14 ++ src/cryptoconditions/src/preimage.c | 14 ++ src/cryptoconditions/src/threshold.c | 14 ++ src/cryptoconditions/src/utils.c | 15 ++ 17 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 src/cc/assets.cpp diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp new file mode 100644 index 000000000..1e7dc61a8 --- /dev/null +++ b/src/cc/assets.cpp @@ -0,0 +1,191 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include +#include