From 17abd35a71c033e77b744893cf7e71b1bfe3f3ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Mar 2018 00:57:48 +0200 Subject: [PATCH 01/10] Dont write rpcport into .conf --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1270b3e55..8b12646ed 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1365,7 +1365,7 @@ void komodo_configfile(char *symbol,uint16_t port) #ifndef FROM_CLI if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=64\n",crc,password,port); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nserver=1\ntxindex=1\nrpcworkqueue=64\n",crc,password); fclose(fp); printf("Created (%s)\n",fname); } else printf("Couldnt create (%s)\n",fname); From 63998b663451794eaff3c7e4013e3919c677643d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Mar 2018 00:58:36 +0200 Subject: [PATCH 02/10] revert --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 8b12646ed..1270b3e55 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1365,7 +1365,7 @@ void komodo_configfile(char *symbol,uint16_t port) #ifndef FROM_CLI if ( (fp= fopen(fname,"wb")) != 0 ) { - fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nserver=1\ntxindex=1\nrpcworkqueue=64\n",crc,password); + fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=64\n",crc,password,port); fclose(fp); printf("Created (%s)\n",fname); } else printf("Couldnt create (%s)\n",fname); From e2c2f297d11f57f72d0bab7e9bb33c907fda36dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Mar 2018 20:32:08 +0200 Subject: [PATCH 03/10] Accept pre-notarization block that matches --- src/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 4277beabd..b0d20b7c5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3372,7 +3372,14 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta if (pcheckpoint && (nHeight < pcheckpoint->nHeight || nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1) ) return state.DoS(100, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) - return state.DoS(100, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); + { + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && pblockindex->GetBlockHash() == hash ) + { + fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); + return true; + } else return state.DoS(100, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); + } } // Reject block.nVersion < 4 blocks if (block.nVersion < 4) From cc07ad72d7719cf2d4bb69776f5adedeed059a44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Mar 2018 20:50:07 +0200 Subject: [PATCH 04/10] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b0d20b7c5..fc1d3fdd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3374,7 +3374,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) { CBlockIndex *heightblock = chainActive[nHeight]; - if ( heightblock != 0 && pblockindex->GetBlockHash() == hash ) + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) { fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); return true; From beb911ecb4b760399f67f23b8eba4c905247117b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 00:30:41 +0200 Subject: [PATCH 05/10] Prints --- src/komodo_bitcoind.h | 9 +++++---- src/main.cpp | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d4364a3ea..bec7bf161 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -814,16 +814,17 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has { if ( nHeight < notarized_height ) { - fprintf(stderr,"nHeight.%d < NOTARIZED_HEIGHT.%d\n",nHeight,notarized_height); + fprintf(stderr,"[%s] nHeight.%d < NOTARIZED_HEIGHT.%d\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); return(-1); } else if ( nHeight == notarized_height && memcmp(&hash,¬arized_hash,sizeof(hash)) != 0 ) { - fprintf(stderr,"nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",nHeight,notarized_height); + fprintf(stderr,"[%s] nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); return(-1); } - } else fprintf(stderr,"unexpected error notary_hash %s ht.%d at ht.%d\n",notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); - } else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 ) + } else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight); + } + else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 ) fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight); return(0); } diff --git a/src/main.cpp b/src/main.cpp index fc1d3fdd0..ee90b74bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3448,7 +3448,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc if (hash != chainparams.GetConsensus().hashGenesisBlock) { BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) + { return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + } pindexPrev = (*mi).second; if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); From 3ecbf9013400e6981990450949a298c5fddfb9f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 01:15:08 +0200 Subject: [PATCH 06/10] Test already existing block --- src/main.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index ee90b74bd..6a7dd95de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3437,6 +3437,36 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if (pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + if ( pindex != 0 ) // jl777 debug test + { + if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state)) + { + fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); + return false; + } + CBlockIndex* pindexPrev = NULL; + if (hash != chainparams.GetConsensus().hashGenesisBlock) + { + BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); + if (mi == mapBlockIndex.end()) + { + fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight); + return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + } + pindexPrev = (*mi).second; + if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) + { + fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight); + return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); + } + } + if (!ContextualCheckBlockHeader(block, state, pindexPrev)) + { + fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight); + return false; + } + } + return true; } From a36a3726cf93180c83cd4e0f95773d567a1af86b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 01:28:39 +0200 Subject: [PATCH 07/10] Mark failed blocks due to changed state --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6a7dd95de..ec94f1e4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3439,8 +3439,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); if ( pindex != 0 ) // jl777 debug test { - if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state)) + if (!CheckBlockHeader(pindex->nHeight:0,pindex, block, state)) { + pindex->nStatus |= BLOCK_FAILED_MASK; fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); return false; } @@ -3450,18 +3451,21 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { + pindex->nStatus |= BLOCK_FAILED_MASK; fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight); return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) { + pindex->nStatus |= BLOCK_FAILED_MASK; fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight); return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { + pindex->nStatus |= BLOCK_FAILED_MASK; fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight); return false; } From 2c5af2cd09e96f89cf12e330434a89caede7b3f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 01:47:06 +0200 Subject: [PATCH 08/10] -print --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 68 +++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bec7bf161..76f6765ad 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -814,7 +814,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has { if ( nHeight < notarized_height ) { - fprintf(stderr,"[%s] nHeight.%d < NOTARIZED_HEIGHT.%d\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); + //fprintf(stderr,"[%s] nHeight.%d < NOTARIZED_HEIGHT.%d\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height); return(-1); } else if ( nHeight == notarized_height && memcmp(&hash,¬arized_hash,sizeof(hash)) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index ec94f1e4e..99a5133d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3376,7 +3376,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) { - fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); + //fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); return true; } else return state.DoS(100, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); } @@ -3437,39 +3437,39 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if (pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - if ( pindex != 0 ) // jl777 debug test - { - if (!CheckBlockHeader(pindex->nHeight:0,pindex, block, state)) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); - return false; - } - CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus().hashGenesisBlock) - { - BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); - if (mi == mapBlockIndex.end()) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight); - return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); - } - pindexPrev = (*mi).second; - if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight); - return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); - } - } - if (!ContextualCheckBlockHeader(block, state, pindexPrev)) - { - pindex->nStatus |= BLOCK_FAILED_MASK; - fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight); - return false; - } - } + if ( pindex != 0 ) // jl777 debug test + { + if (!CheckBlockHeader(pindex->nHeight:0,pindex, block, state)) + { + pindex->nStatus |= BLOCK_FAILED_MASK; + fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); + return false; + } + CBlockIndex* pindexPrev = NULL; + if (hash != chainparams.GetConsensus().hashGenesisBlock) + { + BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); + if (mi == mapBlockIndex.end()) + { + pindex->nStatus |= BLOCK_FAILED_MASK; + fprintf(stderr,"known block.%d failing to find prevblock\n",(int32_t)pindex->nHeight); + return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + } + pindexPrev = (*mi).second; + if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) + { + pindex->nStatus |= BLOCK_FAILED_MASK; + fprintf(stderr,"known block.%d found invalid prevblock\n",(int32_t)pindex->nHeight); + return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); + } + } + if (!ContextualCheckBlockHeader(block, state, pindexPrev)) + { + pindex->nStatus |= BLOCK_FAILED_MASK; + fprintf(stderr,"known block.%d failing ContextualCheckBlockHeader\n",(int32_t)pindex->nHeight); + return false; + } + } return true; } From 6dc496fb3de759c879e5340eafe016aec092cd7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 01:47:56 +0200 Subject: [PATCH 09/10] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 99a5133d3..ce157f411 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3439,7 +3439,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); if ( pindex != 0 ) // jl777 debug test { - if (!CheckBlockHeader(pindex->nHeight:0,pindex, block, state)) + if (!CheckBlockHeader(pindex->nHeight,pindex, block, state)) { pindex->nStatus |= BLOCK_FAILED_MASK; fprintf(stderr,"known block failing CheckBlockHeader %d\n",(int32_t)pindex->nHeight); From 4e0d20786bb07aa4472ed89320e577450bc89b9c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Mar 2018 02:37:17 +0200 Subject: [PATCH 10/10] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ce157f411..9cfc4e5b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3437,7 +3437,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc *ppindex = pindex; if (pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - if ( pindex != 0 ) // jl777 debug test + if ( pindex != 0 && IsInitialBlockDownload() == 0 ) // jl777 debug test { if (!CheckBlockHeader(pindex->nHeight,pindex, block, state)) {