From 68ef9dd9a9ba02d4d88560c7881ee7f95b5cd57f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:10:49 -1100 Subject: [PATCH 01/20] Add contextual check in connect block from connecttip --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bffddf01f..22c8eb4f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3180,7 +3180,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - + if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) + { + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->nHeight); + return false; + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); if ( hashPrevBlock != view.GetBestBlock() ) From c299983eaf2ccb6e87235e382eb33111ac22ffcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:11:38 -1100 Subject: [PATCH 02/20] GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 22c8eb4f4..82dae2593 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3182,7 +3182,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) { - fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->nHeight); + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; } // verify that the view's current state corresponds to the previous block From f52cbb1b069f228b1d6747a0ef25345e61b88d39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:25:42 -1100 Subject: [PATCH 03/20] Jan 15th activation --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 82dae2593..6aebb4708 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3180,7 +3180,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1546028567 && !ContextualCheckBlock(block, state, pindex->pprev) ) + if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; From 665c152e30d29fb7c977a87af083e24ba9d09964 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:35:05 -1100 Subject: [PATCH 04/20] +prints --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6aebb4708..04f26d765 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1091,6 +1091,7 @@ bool ContextualCheckTransaction( } // Rules that apply to Overwinter or later: + fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); if (overwinterActive) { // Reject transactions intended for Sprout @@ -3180,7 +3181,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 + fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; From b0a3c8589c8eefb9500ed4affb7bf27c1b1e7d77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:39:49 -1100 Subject: [PATCH 05/20] Type --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 04f26d765..82d548f53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,7 +3181,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); From e5e2d5007f550695acce0f321c8e0aea47fc88cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:46:02 -1100 Subject: [PATCH 06/20] Cap sapling accept block exemption --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 82d548f53..056f08dbd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5077,7 +5077,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // the problem is when a future sapling block comes in before we detected saplinght if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { - fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } From f421590c81a074f3fc1764da246da12e994bbeef Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:49:16 -1100 Subject: [PATCH 07/20] Fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 056f08dbd..14b21b861 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5078,7 +5078,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); - if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } if ( *futureblockp == 0 ) From 21ee92f6f334b62a5988f08ae663fba1a6410786 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:58:46 -1100 Subject: [PATCH 08/20] Grandfather logic --- src/main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 14b21b861..117c6604e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,11 +3181,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); - if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) //&& pindex->nTime > 1547510400 Activate Jan 15th, 2019 + //fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); + if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); - return false; + if ( pindex->nTime > 1547510400 ) + return false; + fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); @@ -5077,8 +5079,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // the problem is when a future sapling block comes in before we detected saplinght if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) { - fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); - if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+10000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + if ( pindex->GetHeight() < 0 || (pindex->GetHeight() >= saplinght && pindex->GetHeight() < saplinght+50000) || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) *futureblockp = 1; } if ( *futureblockp == 0 ) From 0234e33c938cd5531537935221b6ff76d03e471c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:00:46 -1100 Subject: [PATCH 09/20] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 117c6604e..c27c1f0e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1091,7 +1091,7 @@ bool ContextualCheckTransaction( } // Rules that apply to Overwinter or later: - fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); + //fprintf(stderr,"ht.%d overwinterActive.%d tx.overwintered.%d\n",nHeight,overwinterActive,overwinterActive); if (overwinterActive) { // Reject transactions intended for Sprout From bce13f9276ce64e1a2def0a0af60def624cb0ec6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:07:01 -1100 Subject: [PATCH 10/20] 0.3.3b --- src/main.cpp | 1 - src/rpc/misc.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c27c1f0e5..f5922d840 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3181,7 +3181,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - //fprintf(stderr,"connect.%d checkPOW.%d nTime.%u %d\n",pindex->GetHeight(),fCheckPOW,(uint32_t)pindex->nTime,ContextualCheckBlock(block, state, pindex->pprev)); if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 181d6cdbb..0ebfa7b25 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -72,7 +72,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.3.3" +#define KOMODO_VERSION "0.3.3b" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From 42911ea6c2f2af88923b865bee619ed7753dcbc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:21:29 -1100 Subject: [PATCH 11/20] Double maxreorg --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index f318a8c13..2c4cef14e 100644 --- a/src/main.h +++ b/src/main.h @@ -78,7 +78,7 @@ static const bool DEFAULT_ALERTS = true; /** Minimum alert priority for enabling safe mode. */ static const int ALERT_PRIORITY_SAFE_MODE = 4000; /** Maximum reorg length we will accept before we shut down and alert the user. */ -static const unsigned int MAX_REORG_LENGTH = _COINBASE_MATURITY - 1; +static const unsigned int MAX_REORG_LENGTH = 2*(_COINBASE_MATURITY - 1); /** Maximum number of signature check operations in an IsStandard() P2SH script */ static const unsigned int MAX_P2SH_SIGOPS = 15; /** The maximum number of sigops we're willing to relay/mine in a single tx */ From 9269bc177c448d4a66e9f88222bb306e1779184f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:25:23 -1100 Subject: [PATCH 12/20] Allow tunable maxreorg --- src/komodo_utils.h | 1 + src/main.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2437b0bf6..6010cf4c4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1701,6 +1701,7 @@ void komodo_args(char *argv0) } } KOMODO_STOPAT = GetArg("-stopat",0); + MAX_REORG_LENGTH = GetArg("-maxreorg",MAX_REORG_LENGTH); ASSETCHAINS_CC = GetArg("-ac_cc",0); KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); diff --git a/src/main.h b/src/main.h index 2c4cef14e..463c91237 100644 --- a/src/main.h +++ b/src/main.h @@ -78,7 +78,7 @@ static const bool DEFAULT_ALERTS = true; /** Minimum alert priority for enabling safe mode. */ static const int ALERT_PRIORITY_SAFE_MODE = 4000; /** Maximum reorg length we will accept before we shut down and alert the user. */ -static const unsigned int MAX_REORG_LENGTH = 2*(_COINBASE_MATURITY - 1); +static unsigned int MAX_REORG_LENGTH = (_COINBASE_MATURITY - 1); /** Maximum number of signature check operations in an IsStandard() P2SH script */ static const unsigned int MAX_P2SH_SIGOPS = 15; /** The maximum number of sigops we're willing to relay/mine in a single tx */ From 10b90968afce6a863ebab317f09510993bc2ff69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:28:17 -1100 Subject: [PATCH 13/20] +comments --- src/chainparams.cpp | 2 +- src/net.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 49f08e98e..d97ed8624 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -230,7 +230,7 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat CChainParams::checkpointData = checkpointData; } -int32_t MAX_BLOCK_SIZE(int32_t height) +int32_t MAX_BLOCK_SIZE(int32_t height) // make sure to change MAX_PROTOCOL_MESSAGE_LENGTH also!!!! { //fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight); if ( height <= 0 || (mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight > 0 && height >= mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) diff --git a/src/net.h b/src/net.h index 8901146ca..3f30175c3 100644 --- a/src/net.h +++ b/src/net.h @@ -63,7 +63,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; // depends on MAX_BLOCK_SIZE /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From 59177fa5980649d5fa38f86b7ca767fe7718240d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:39:53 -1100 Subject: [PATCH 14/20] No static assert --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5922d840..aefb3bcb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4088,7 +4088,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // then pindexFork will be null, and we would need to remove the entire chain including // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->GetHeight() - (pindexFork ? pindexFork->GetHeight() : -1) : 0; - static_assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); + assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); if (reorgLength > MAX_REORG_LENGTH) { int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; From 2f847e2ef4ca3c77b6131183f1913e3b3714afad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:40:34 -1100 Subject: [PATCH 15/20] Assert 1 arg --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index aefb3bcb0..f5e5a6ab0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4088,7 +4088,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // then pindexFork will be null, and we would need to remove the entire chain including // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->GetHeight() - (pindexFork ? pindexFork->GetHeight() : -1) : 0; - assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); + assert(MAX_REORG_LENGTH > 0);//, "We must be able to reorg some distance"); if (reorgLength > MAX_REORG_LENGTH) { int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; From c5b3b68ace990ee876587a3e2c2794796ef3ace2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:18:19 -1100 Subject: [PATCH 16/20] Increase witness cache size for maxreorg --- src/komodo_utils.h | 3 +++ src/wallet/wallet.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6010cf4c4..2252cce38 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,6 +1650,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; +extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { @@ -1702,6 +1703,8 @@ void komodo_args(char *argv0) } KOMODO_STOPAT = GetArg("-stopat",0); MAX_REORG_LENGTH = GetArg("-maxreorg",MAX_REORG_LENGTH); + WITNESS_CACHE_SIZE = MAX_REORG_LENGTH+10; + ASSETCHAINS_CC = GetArg("-ac_cc",0); KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 29f1737eb..653603ff7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -76,7 +76,7 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. #define _COINBASE_MATURITY 100 -static const unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 02d75902ad4a84c2e5042dd29fab9f228d640f28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:30:47 -1100 Subject: [PATCH 17/20] Move declaration WITNESS_CACHE --- src/komodo_globals.h | 1 + src/komodo_utils.h | 1 - src/wallet/wallet.h | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index a14cea753..8a72b5ad7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,6 +44,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; +unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 2252cce38..a5b22e592 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,7 +1650,6 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; -extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 653603ff7..c8f9bcbb6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -75,8 +75,8 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; //! Size of witness cache // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. -#define _COINBASE_MATURITY 100 -unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +extern unsigned int WITNESS_CACHE_SIZE; + //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 2df13c428f9740e563f0b2a960901b458db21e36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:24:04 -1100 Subject: [PATCH 18/20] Workaround for -maxreorg --- src/komodo_defs.h | 3 ++- src/wallet/wallet.cpp | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c0a3caffd..bd516be61 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -28,7 +28,8 @@ #define KOMODO_FIRSTFUNGIBLEID 100 #define KOMODO_SAPLING_ACTIVATION 1544832000 // Dec 15th, 2018 #define KOMODO_SAPLING_DEADLINE 1550188800 // Feb 15th, 2019 - +#define _COINBASE_MATURITY 100 + extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 024194695..969e0c81b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1184,6 +1184,7 @@ bool DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n return true; } + void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) { LOCK(cs_wallet); @@ -1193,10 +1194,17 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) if (!::DecrementNoteWitnesses(wtxItem.second.mapSaplingNoteData, pindex->GetHeight(), nWitnessCacheSize)) needsRescan = true; } - nWitnessCacheSize -= 1; - // TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302) - assert(nWitnessCacheSize > 0); - + if ( WITNESS_CACHE_SIZE == _COINBASE_MATURITY+10 ) + { + nWitnessCacheSize -= 1; + // TODO: If nWitnessCache is zero, we need to regenerate the caches (#1302) + assert(nWitnessCacheSize > 0); + } + else + { + if ( nWitnessCacheSize > 0 ) + nWitnessCacheSize-- + } // For performance reasons, we write out the witness cache in // CWallet::SetBestChain() (which also ensures that overall consistency // of the wallet.dat is maintained). From 512d96862abc5ab95bd0afd1bd6fd695458f14f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:30:24 -1100 Subject: [PATCH 19/20] Help human instructions for -maxreorg --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5e5a6ab0..b29e80efc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4114,7 +4114,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo "- " + strprintf(_("Fork point: %s %s, height %d"), ASSETCHAINS_SYMBOL,pindexFork->phashBlock->GetHex(), pindexFork->GetHeight()) + "\n\n" + _("Please help, human!"); - LogPrintf("*** %s\n", msg); + LogPrintf("*** %s\nif you launch with -maxreorg=%d it might be able to resolve this automatically", msg,reorgLength+10); uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_ERROR); StartShutdown(); return false; From 4f48570935324e2c3a531bfb084810764e7d1fff Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 04:31:04 -1100 Subject: [PATCH 20/20] ; --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 969e0c81b..dd188d418 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1203,8 +1203,8 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) else { if ( nWitnessCacheSize > 0 ) - nWitnessCacheSize-- - } + nWitnessCacheSize--; + } // For performance reasons, we write out the witness cache in // CWallet::SetBestChain() (which also ensures that overall consistency // of the wallet.dat is maintained).