From 9e8b81f63789ba441ec30e601501a7d211eb04cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 14:20:16 +0200 Subject: [PATCH 001/108] Remove print --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7396530ce..a327cca4c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -763,7 +763,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx - } else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); + } //else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); } if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; @@ -1184,7 +1184,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // be mined yet. if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) { - fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); + //fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } // is it already in the memory pool? From 89a2e5273c9b1d0ea95be4ba8d21e73c30543b0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 15:37:34 +0200 Subject: [PATCH 002/108] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 185145bdd..3a09400a2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -944,7 +944,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) printf("check deposit validates %s.%d [%d] %.8f -> %.8f (%.8f %.8f %.8f)\n",CURRENCIES[baseids[i-1]],height,i,dstr(srcvalues[i-1]),dstr(values[i-1]),dstr(pax->komodoshis),dstr(pax->fiatoshis),dstr(block.vtx[0].vout[i].nValue)); } - else + else if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) { for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); From 2ef1dfb6f12a5352cf34732371181be8a887e83f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 18:35:11 +0200 Subject: [PATCH 003/108] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 91318d641..8e4661a92 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -206,9 +206,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { if ( expired != 0 ) { - fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - list removed; - mempool.remove(tx, removed, true); + //fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); + //list removed; + //mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From 55d65e32caf60b5baa4e1a97d1e240c4adb0dd01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:26:19 +0200 Subject: [PATCH 004/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a327cca4c..b7c48332a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3196,7 +3196,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl { uint8_t pubkey33[33]; // Check timestamp - if ( 0 ) + if ( 1 ) { uint256 hash; int32_t i; hash = blockhdr.GetHash(); From 6460b5b19ca18c6298188df4aba9b616a77592f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:38:59 +0200 Subject: [PATCH 005/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b7c48332a..37804da3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -383,7 +383,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); - if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { + if (it != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; From da7775433d1ae81cc49570384d2d180700bc85a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:40:37 +0200 Subject: [PATCH 006/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 37804da3e..b7c48332a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -383,7 +383,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); - if (it != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { + if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; From 0a0ec219d79db1d26d2d37ee0103f07e45fc796a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:44:40 +0200 Subject: [PATCH 007/108] Test --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b7c48332a..1bcde7710 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -382,12 +382,13 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { ProcessBlockAvailability(nodeid); - BlockMap::iterator it = mapBlockIndex.find(hash); + /*BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; - } else { + } else*/ + { // An unknown block was announced; just assume that the latest one is the best one. state->hashLastUnknownBlock = hash; } From 944bf4b0913b4bd535c7595acef20ac27188ad93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:57:18 +0200 Subject: [PATCH 008/108] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1bcde7710..54683db07 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -367,7 +367,8 @@ void ProcessBlockAvailability(NodeId nodeid) { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { + if (itOld != 0 && itOld->second != 0 && itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; state->hashLastUnknownBlock.SetNull(); From 9b7233cf170c1149fbcbc149b488657285f90893 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 19:58:23 +0200 Subject: [PATCH 009/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 54683db07..47417e894 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -367,7 +367,7 @@ void ProcessBlockAvailability(NodeId nodeid) { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld != 0 && itOld->second != 0 && itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + if (itOld->second != 0 && itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; From a2f017de0858621c2274c788596dfff9a49b23ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:05:02 +0200 Subject: [PATCH 010/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 47417e894..30e3ab5cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -381,7 +381,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != NULL); - ProcessBlockAvailability(nodeid); + //ProcessBlockAvailability(nodeid); /*BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { From 88e117ada6716eecfac0352d8fe89395789dece5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:09:07 +0200 Subject: [PATCH 011/108] Test --- src/arith_uint256.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index 2e6136357..be1a44bba 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -109,6 +109,11 @@ base_uint& base_uint::operator/=(const base_uint& b) template int base_uint::CompareTo(const base_uint& b) const { + if ( pn == 0 || b.pn == 0 ) + { + fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn); + return(0); + } for (int i = WIDTH - 1; i >= 0; i--) { if (pn[i] < b.pn[i]) return -1; From 110696f9e17b4a42303dd6839a9cee11cd95ffb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:09:55 +0200 Subject: [PATCH 012/108] Test --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 30e3ab5cb..bf57f8cb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -367,7 +367,7 @@ void ProcessBlockAvailability(NodeId nodeid) { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld->second != 0 && itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; @@ -381,14 +381,14 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != NULL); - //ProcessBlockAvailability(nodeid); + ProcessBlockAvailability(nodeid); - /*BlockMap::iterator it = mapBlockIndex.find(hash); + BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; - } else*/ + } else { // An unknown block was announced; just assume that the latest one is the best one. state->hashLastUnknownBlock = hash; From e4f53bd20a5b8231e8d0cce2075759df50cc8822 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:23:25 +0200 Subject: [PATCH 013/108] Test --- src/arith_uint256.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index be1a44bba..a1865b649 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -109,7 +109,7 @@ base_uint& base_uint::operator/=(const base_uint& b) template int base_uint::CompareTo(const base_uint& b) const { - if ( pn == 0 || b.pn == 0 ) + if ( (uint64_t)pn < 0x1000 || (uint64_t)b.pn <= 0x1000 ) { fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn); return(0); From e40b78e93c84dc2506add49cb8a8b5a1fc6f6f62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:47:47 +0200 Subject: [PATCH 014/108] Crash fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bf57f8cb2..777926200 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3198,7 +3198,7 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl { uint8_t pubkey33[33]; // Check timestamp - if ( 1 ) + if ( 0 ) { uint256 hash; int32_t i; hash = blockhdr.GetHash(); From 628220bc5d70805698ec9c93bacb17a51012e9c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 20:54:07 +0200 Subject: [PATCH 015/108] Check against pblock->nTime --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 8e4661a92..c73122ffd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,7 +202,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,pblock->nTime)) { if ( expired != 0 ) { From ad8796cf7c8b78237da00ca6705ed4a56d03f97f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 21:35:19 +0200 Subject: [PATCH 016/108] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c73122ffd..dc0628eee 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -206,9 +206,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { if ( expired != 0 ) { - //fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - //list removed; - //mempool.remove(tx, removed, true); + fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); + list removed; + mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From a13fb56e553bc1b373ba862f85989ff10c74a285 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 21:40:31 +0200 Subject: [PATCH 017/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 777926200..7fa68be9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -384,7 +384,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); - if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { + if (it->second != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; From 4110a59a4376f576bcf23de5b94ab8089de6d506 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 22:15:29 +0200 Subject: [PATCH 018/108] Test --- src/main.cpp | 2 +- src/miner.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7fa68be9e..99800a600 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -740,7 +740,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748 { if ( tx.nLockTime != 1477258935 ) - fprintf(stderr,"komodo_validate_interest reject.%d locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime); if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); diff --git a/src/miner.cpp b/src/miner.cpp index dc0628eee..3caf774c0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,13 +202,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,pblock->nTime)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime+600)) { if ( expired != 0 ) { - fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - list removed; - mempool.remove(tx, removed, true); + //fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); + //list removed; + //mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From 10c862f271f1efb60e5b6489d2308edd5fe8aab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 22:32:48 +0200 Subject: [PATCH 019/108] Test --- src/main.cpp | 2 +- src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 99800a600..ba8944a24 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -747,7 +747,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } } - //fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); } return(0); } diff --git a/src/miner.cpp b/src/miner.cpp index 3caf774c0..301a1037a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -206,9 +206,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { if ( expired != 0 ) { - //fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - //list removed; - //mempool.remove(tx, removed, true); + fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); + list removed; + mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From b2d09a90d469c62c9cbbad5ca3855c404648b5aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 22:46:42 +0200 Subject: [PATCH 020/108] Test --- src/komodo_bitcoind.h | 5 ++++- src/main.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 481ede104..8a5bcfec1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -620,7 +620,10 @@ void komodo_connectpindex(CBlockIndex *pindex) CBlockIndex *komodo_chainactive(int32_t height) { - return(chainActive[height]); + if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + { + return(chainActive[height]); + } else return(0); } int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); diff --git a/src/main.cpp b/src/main.cpp index ba8944a24..cf7da0e44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,10 +710,15 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime) { - int32_t i,txheight=0; uint32_t cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; + int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + prevblocktime = 0; + if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) + { + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + prevblocktime = prev->nTime; + } if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) @@ -733,6 +738,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 cmptime = txblocktime; if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; + if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) + cmptime = prevblocktime; if ( cmptime >= 1490159171 - 24*3600 ) { if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) @@ -740,7 +747,9 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748 { if ( tx.nLockTime != 1477258935 ) + { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime); + } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); From b9551735cf54eb1f56488e15e291cdfab572954c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:07:51 +0200 Subject: [PATCH 021/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cf7da0e44..890482c30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -756,7 +756,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } } - fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); } return(0); } From 9a9b36ca7ee9af11b3957b2d72616cbbecb47727 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:20:31 +0200 Subject: [PATCH 022/108] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 890482c30..7797376f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -719,6 +719,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; } + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From 3fd98f8ff6fa0b9edf6cc520fbf42f0f22a470b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:21:02 +0200 Subject: [PATCH 023/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7797376f0..305dbc4ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -716,11 +716,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 prevblocktime = 0; if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) { + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; } - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From 52e5ebfdc2d8712e4ba2beedc8a0e6dbedd25540 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:22:08 +0200 Subject: [PATCH 024/108] Test --- src/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 305dbc4ba..d502b7e1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -714,13 +714,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { prevblocktime = 0; - if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) - { - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) - prevblocktime = prev->nTime; - } + locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + prevblocktime = prev->nTime; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From c2123afed997868470ec5187ada76fc3a1656a56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:58:39 +0200 Subject: [PATCH 025/108] Test --- src/komodo_gateway.h | 19 ++++++++++++++----- src/komodo_globals.h | 2 +- src/main.cpp | 26 +++++++++++++------------- src/main.h | 2 +- src/miner.cpp | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3a09400a2..a0a64231d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -628,26 +628,35 @@ const char *banned_txids[] = "a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265 "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 + // all vouts banned + "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 }; -void komodo_bannedset(uint256 *array,int32_t max) +int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) { int32_t i; + if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) + { + fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); + exit(-1); + } for (i=0; i= indallvouts) ) { printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j); return(-1); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 905b4fb4b..6d8d6c325 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -24,7 +24,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp); uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); -void komodo_bannedset(uint256 *array,int32_t max); +int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); pthread_mutex_t komodo_mutex; diff --git a/src/main.cpp b/src/main.cpp index d502b7e1e..25532182c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -708,15 +708,15 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; + if ( (txheight= txheightarg) == 0 ) + txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; if ( tiptime == 0 ) @@ -761,7 +761,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 return(0); } -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,int32_t interesttime) +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags) { int32_t i; if ( expiredp != 0 ) @@ -770,7 +770,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,interesttime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -821,7 +821,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); + return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags); } /** @@ -923,9 +923,9 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash::ProofVerifier& verifier) { - static uint256 array[15]; int32_t j,k,n; + static uint256 array[64]; static int32_t numbanned,indallvouts; int32_t j,k,n; if ( *(int32_t *)&array[0] == 0 ) - komodo_bannedset(array,(int32_t)(sizeof(array)/sizeof(*array))); + numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); /*if ( komodo_validate_interest(tx) < 0 ) { fprintf(stderr,"CheckTransaction komodo_validate_interest error\n"); @@ -934,13 +934,13 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash:: n = tx.vin.size(); for (j=0; j= indallvouts) ) { static uint32_t counter; if ( counter++ < 100 ) - printf("MEMPOOL: banned tx.%d being used at ht.%d vini.%d\n",k,(int32_t)chainActive.Tip()->nHeight,j); + printf("MEMPOOL: banned tx.%d being used at ht.%d vout.%d\n",k,(int32_t)chainActive.Tip()->nHeight,j); return(false); } } @@ -3288,7 +3288,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,block.nTime) < 0 ) + if ( komodo_validate_interest(0,tx,height != 0 ? height : komodo_block2height((CBlock *)&block)) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); @@ -3372,7 +3372,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() : block.GetBlockTime(); - if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) { + if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS)) { return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } diff --git a/src/main.h b/src/main.h index 1bea5030f..dcbd23632 100644 --- a/src/main.h +++ b/src/main.h @@ -351,7 +351,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason); * Check if transaction is final and can be included in a block with the * specified height and time. Consensus critical. */ -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,int32_t interesttime); +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index 301a1037a..ff6f0bcf1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,7 +202,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime+600)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS)) { if ( expired != 0 ) { From b575c4fb7b5ff63170885b3f32de0e5bdb220484 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:08:11 +0200 Subject: [PATCH 026/108] Test --- src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 25532182c..9daea90da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,11 +710,11 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; + int32_t i,txheight=0; uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + /*prevblocktime = 0; if ( (txheight= txheightarg) == 0 ) txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) @@ -739,7 +739,9 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) - cmptime = prevblocktime; + cmptime = prevblocktime;*/ + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + cmptime = prev->nTime + 600; if ( cmptime >= 1490159171 - 24*3600 ) { if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) From 9f539d8804000902a539efcc05bea1092a99e7d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:13:52 +0200 Subject: [PATCH 027/108] Test --- src/main.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9daea90da..b1d061427 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,11 +710,12 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i,txheight=0; uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { + /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; + prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - /*prevblocktime = 0; if ( (txheight= txheightarg) == 0 ) txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) @@ -739,7 +740,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) - cmptime = prevblocktime;*/ + cmptime = prevblocktime; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) cmptime = prev->nTime + 600; if ( cmptime >= 1490159171 - 24*3600 ) @@ -757,8 +758,23 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } + }*/ + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + cmptime = prev->nTime + 600; + if ( cmptime > 0 && txheightarg > 246748 ) + { + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 ) + { + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u vs nBlockTime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + } + if ( expiredp != 0 ) + *expiredp = cmptime-3600; + return(-1); + } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,cmptime); } return(0); } From 1a85595b5a5ddc4c39dda16faf602df4bcbe22da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:14:38 +0200 Subject: [PATCH 028/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b1d061427..cae353b38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; From 48b72e17251e06482d996bd0ed5a11bcbe52a564 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:16:18 +0200 Subject: [PATCH 029/108] Test --- src/komodo_gateway.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a0a64231d..16be739e4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -645,7 +645,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) if ( i != max ) printf("banned txid array error i.%d != max.%d\n",i,max); //else printf("set %d banned txids\n",max); - *allvoutsp = i-1; + *indallvoutsp = i-1; return(0); } diff --git a/src/main.cpp b/src/main.cpp index cae353b38..ab08b5a82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -759,7 +759,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { From 8795f3397f866c8c882bb981404966f98da86e78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:23:47 +0200 Subject: [PATCH 030/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ab08b5a82..2a2189a2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -767,7 +767,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u vs nBlockTime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; From 28c39e54b63108f82adf84a0b81fdfeed8ff539e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:28:42 +0200 Subject: [PATCH 031/108] Test --- src/komodo_gateway.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 16be739e4..2b1b8ef57 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -642,9 +642,6 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) } for (i=0; i Date: Fri, 24 Mar 2017 00:36:23 +0200 Subject: [PATCH 032/108] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2a2189a2d..466f1d139 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -763,6 +763,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { + if ( txheightarg < 247205 ) + cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) From ad0b9d62375ce58f4a9ab355ca57fcd49f905343 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:47:51 +0200 Subject: [PATCH 033/108] Test --- src/init.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..b9881cf1e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,6 +1246,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } + uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); + //uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); + CValidationState state; + { + LOCK(cs_main); + if ( mapBlockIndex.count(hash) != 0 ) + { + CBlockIndex* pblockindex; + if ( (pblockindex= mapBlockIndex[hash]) != 0 ) + InvalidateBlock(state, pblockindex); + } + } + if ( KOMODO_REWIND >= 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), From a710762818470e2fcaf865de4459ba3362c75888 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:51:12 +0200 Subject: [PATCH 034/108] Test --- src/init.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index b9881cf1e..ad7559fcd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1247,7 +1247,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); - //uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); + uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); CValidationState state; { LOCK(cs_main); @@ -1257,6 +1257,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if ( (pblockindex= mapBlockIndex[hash]) != 0 ) InvalidateBlock(state, pblockindex); } + if ( mapBlockIndex.count(hash2) != 0 ) + { + CBlockIndex* pblockindex; + if ( (pblockindex= mapBlockIndex[hash2]) != 0 ) + InvalidateBlock(state, pblockindex); + } } if ( KOMODO_REWIND >= 0 ) From 5ead8b4e858d4831fe80cc83c9c62c5549b704d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:55:19 +0200 Subject: [PATCH 035/108] Test --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index ad7559fcd..0f89ae6ed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1249,6 +1249,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); CValidationState state; + if ( 0 ) { LOCK(cs_main); if ( mapBlockIndex.count(hash) != 0 ) From e20babf1dffb8d577175d99bbc51528705352a98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:01:49 +0200 Subject: [PATCH 036/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 466f1d139..91de3b315 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -790,7 +790,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight-1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -3308,7 +3308,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,height != 0 ? height : komodo_block2height((CBlock *)&block)) < 0 ) + if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block)) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); From 88416f2bc93c5588621da3d14fc6a60b6519c9f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:04:18 +0200 Subject: [PATCH 037/108] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 91de3b315..11af67f81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -761,6 +761,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 }*/ if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) cmptime = prev->nTime + 600; + else fprintf(stderr,"couldnt get prev.[%d]\n",txheightarg-1); if ( cmptime > 0 && txheightarg > 246748 ) { if ( txheightarg < 247205 ) @@ -790,7 +791,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight-1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx From 7d44d3dddda83699e2c7d1c722938a4b5a7708de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:19:53 +0200 Subject: [PATCH 038/108] Test --- src/komodo_bitcoind.h | 27 +++++++++++++++++++-------- src/main.cpp | 12 +++++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8a5bcfec1..9c615c329 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -594,6 +594,25 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) return(0); } +CBlockIndex *komodo_chainactive(int32_t height) +{ + if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + { + return(chainActive[height]); + } else return(0); +} + +uint32_t komodo_heightstamp(int32_t height) +{ + CBlock block; CBlockIndex *ptr; + if ( (ptr= komodo_chainactive(height)) != 0 ) + { + if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) + return(block.nTime); + } + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -618,14 +637,6 @@ void komodo_connectpindex(CBlockIndex *pindex) komodo_connectblock(pindex,block); } -CBlockIndex *komodo_chainactive(int32_t height) -{ - if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) - { - return(chainActive[height]); - } else return(0); -} - int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height); diff --git a/src/main.cpp b/src/main.cpp index 11af67f81..4c37892bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -708,6 +708,8 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } +uint32_t komodo_heightstamp(int32_t height); + int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; @@ -759,9 +761,13 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) - cmptime = prev->nTime + 600; - else fprintf(stderr,"couldnt get prev.[%d]\n",txheightarg-1); + if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) + { + cmptime = chainActive.Tip()->nTime; + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + } + //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) + // cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { if ( txheightarg < 247205 ) From 58bec1f9b51b98cc7a49a9780eca0719f67b0930 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:27:03 +0200 Subject: [PATCH 039/108] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9c615c329..bfd138287 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -605,7 +605,7 @@ CBlockIndex *komodo_chainactive(int32_t height) uint32_t komodo_heightstamp(int32_t height) { CBlock block; CBlockIndex *ptr; - if ( (ptr= komodo_chainactive(height)) != 0 ) + if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) { if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) return(block.nTime); diff --git a/src/main.cpp b/src/main.cpp index 4c37892bd..de593507f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -761,6 +761,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ + if ( txheightarg == 0 ) + txheightarg = chainActive.Tip()->nHeight + 1; if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { cmptime = chainActive.Tip()->nTime; From fa0a031c09648c905e69297c4b1e3d4fcc238825 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:33:47 +0200 Subject: [PATCH 040/108] Test --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index de593507f..78af52e15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -762,11 +762,12 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } }*/ if ( txheightarg == 0 ) - txheightarg = chainActive.Tip()->nHeight + 1; + txheightarg = chainActive.Tip()->nHeight; + else txheightarg--; if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { - cmptime = chainActive.Tip()->nTime; fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + return(-1); } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; From d54aa57df49d7de997fdaf422528b045a882349b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:41:11 +0200 Subject: [PATCH 041/108] 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 bfd138287..be70286f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -599,7 +599,9 @@ CBlockIndex *komodo_chainactive(int32_t height) if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) { return(chainActive[height]); - } else return(0); + } + fprintf(stderr,"komodo_chainactive height %d > %d active.%d\n",height,chainActive.Tip()->nHeight); + return(0); } uint32_t komodo_heightstamp(int32_t height) @@ -607,9 +609,13 @@ uint32_t komodo_heightstamp(int32_t height) CBlock block; CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) { - if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) - return(block.nTime); - } + if ( komodo_blockload(block,ptr) == 0 ) + { + if ( komodo_block2height(&block) == height ) + return(block.nTime); + else fprintf(stderr,"komodo_heightstamp block2height %d != %d\n",komodo_block2height(&block),height); + } else fprintf(stderr,"komodo_heightstamp cant load block.%d\n",height); + } else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } From 89b6584b23447374f28eaef6dd5124157fc94170 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:45:07 +0200 Subject: [PATCH 042/108] 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 be70286f2..9b5d4e898 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -600,7 +600,7 @@ CBlockIndex *komodo_chainactive(int32_t height) { return(chainActive[height]); } - fprintf(stderr,"komodo_chainactive height %d > %d active.%d\n",height,chainActive.Tip()->nHeight); + fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); return(0); } From 5150cb47a92688f51dfcbc08d92ab241ba9c65e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:53:24 +0200 Subject: [PATCH 043/108] Test --- src/komodo_bitcoind.h | 8 +++++--- src/main.cpp | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b5d4e898..65b1b4e8b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -596,11 +596,13 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) CBlockIndex *komodo_chainactive(int32_t height) { - if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + if ( chainActive.Tip() != 0 ) { - return(chainActive[height]); + if ( height <= chainActive.Tip()->nHeight ) + return(chainActive[height]); + else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); } - fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); + fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 78af52e15..40d9ee355 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -712,7 +712,7 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; @@ -761,9 +761,17 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ + tip = chainActive.Tip(); if ( txheightarg == 0 ) - txheightarg = chainActive.Tip()->nHeight; - else txheightarg--; + { + if ( tip != 0 ) + txheightarg = tip->nHeight + 1; + else + { + fprintf(stderr,"couldnt get chaintip for [%d]\n",txheightarg); + return(-1); + } + } if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); @@ -779,14 +787,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)tip != 0 ? tip->nTime : 0,cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tip != 0 ? tip->nHeight : 0,(int32_t)tx.nLockTime,cmptime); } return(0); } From 4b470a580170be53b2418252c3a448c0f51f1c4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:54:48 +0200 Subject: [PATCH 044/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 40d9ee355..fcef4808f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -787,14 +787,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)tip != 0 ? tip->nTime : 0,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tip != 0 ? tip->nHeight : 0,(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } From 8c8a07ce2448e1a67734f09344d93a692c9a62ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:57:33 +0200 Subject: [PATCH 045/108] 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 65b1b4e8b..29a4f35c0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -602,7 +602,7 @@ CBlockIndex *komodo_chainactive(int32_t height) return(chainActive[height]); else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); } - fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); } From 0cb1d2da0db2f700ca78643fad8c51749a48f3d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:09:32 +0200 Subject: [PATCH 046/108] Test --- src/komodo_bitcoind.h | 12 +++--------- src/main.cpp | 26 +++++++++----------------- src/main.h | 2 +- src/miner.cpp | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 29a4f35c0..a80e0b1ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -608,16 +608,10 @@ CBlockIndex *komodo_chainactive(int32_t height) uint32_t komodo_heightstamp(int32_t height) { - CBlock block; CBlockIndex *ptr; + CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) - { - if ( komodo_blockload(block,ptr) == 0 ) - { - if ( komodo_block2height(&block) == height ) - return(block.nTime); - else fprintf(stderr,"komodo_heightstamp block2height %d != %d\n",komodo_block2height(&block),height); - } else fprintf(stderr,"komodo_heightstamp cant load block.%d\n",height); - } else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); + reeturn(ptr->nTime); + else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } diff --git a/src/main.cpp b/src/main.cpp index fcef4808f..f5965813c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) uint32_t komodo_heightstamp(int32_t height); -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) { int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) @@ -761,22 +761,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - tip = chainActive.Tip(); - if ( txheightarg == 0 ) + if ( (cmptime= prevblocktime) == 0 ) { - if ( tip != 0 ) - txheightarg = tip->nHeight + 1; - else + if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { - fprintf(stderr,"couldnt get chaintip for [%d]\n",txheightarg); + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); return(-1); } } - if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) - { - fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); - return(-1); - } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) @@ -799,7 +791,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(0); } -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags) +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,uint32_t prevblocktime) { int32_t i; if ( expiredp != 0 ) @@ -808,7 +800,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -859,7 +851,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags); + return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); } /** @@ -3326,7 +3318,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block)) < 0 ) + if ( komodo_validate_interest(0,tx,0,chainActive.Tip()->nTime) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); @@ -3410,7 +3402,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() : block.GetBlockTime(); - if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS)) { + if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) { return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } diff --git a/src/main.h b/src/main.h index dcbd23632..71ec17ef1 100644 --- a/src/main.h +++ b/src/main.h @@ -351,7 +351,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason); * Check if transaction is final and can be included in a block with the * specified height and time. Consensus critical. */ -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags); +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,uint32_t prevblocktime); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index ff6f0bcf1..91318d641 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,7 +202,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime)) { if ( expired != 0 ) { From f21afd942018132a59df0745717e33d6d5a1b1ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:11:26 +0200 Subject: [PATCH 047/108] 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 a80e0b1ed..213b9adde 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -610,7 +610,7 @@ uint32_t komodo_heightstamp(int32_t height) { CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) - reeturn(ptr->nTime); + return(ptr->nTime); else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } From c1004caa427af7934d6fd9f012b2bbd3258a5a84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:21:23 +0200 Subject: [PATCH 048/108] Test --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5965813c..888a502a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -712,9 +712,11 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) { - int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; + int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { + if ( txheightarg == 0 ) + locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); From ccd177d94f40deb2557d14d0d45dcf4bc3ddaae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:23:12 +0200 Subject: [PATCH 049/108] Test --- src/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 888a502a1..2d36ef88b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) uint32_t komodo_heightstamp(int32_t height); -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime) { int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) @@ -765,30 +765,30 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 }*/ if ( (cmptime= prevblocktime) == 0 ) { - if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) + if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) { - fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); return(-1); } } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; - if ( cmptime > 0 && txheightarg > 246748 ) + if ( cmptime > 0 && txheight > 246748 ) { - if ( txheightarg < 247205 ) + if ( txheight < 247205 ) cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u:%u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheighta,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); } return(0); } From 2af7fbc524fbf6b23f138ed2f4300f42c7b80d8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:24:55 +0200 Subject: [PATCH 050/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2d36ef88b..299f547b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -715,7 +715,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - if ( txheightarg == 0 ) + if ( txheight == 0 ) locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; From 03be8eb889ed9a72ced9c2b6de6fad1b6ca0b724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:26:05 +0200 Subject: [PATCH 051/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 299f547b5..92aa8f526 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -788,7 +788,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheighta,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); } return(0); } From 3345b002032f6b345a7e5d197ed898285df9f8f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:30:22 +0200 Subject: [PATCH 052/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 92aa8f526..b50bb8da1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -776,7 +776,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( cmptime > 0 && txheight > 246748 ) { if ( txheight < 247205 ) - cmptime -= 600; + cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) From 044a7b96ebe6afae2236186e27ff02786e5fce65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:42:27 +0200 Subject: [PATCH 053/108] Test --- src/main.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b50bb8da1..36dd3a02e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -715,8 +715,25 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - if ( txheight == 0 ) - locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); + //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + if ( GetTransaction(hash,tx,hashBlock,true) ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) + { + txheight = pindex->nHeight; + if ( (previndex= mapBlockIndex[pindex->hashPrevBlock]) != 0 ) + prevblocktime = previndex->nTime; + } + } + if ( prevblocktime != 0 ) + cmptime = prevblocktime + 600; + else + { + fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); + return(-1); + } /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); @@ -762,7 +779,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } - }*/ + } if ( (cmptime= prevblocktime) == 0 ) { if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) @@ -770,25 +787,23 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); return(-1); } - } - //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) - // cmptime = prev->nTime + 600; + }*/ if ( cmptime > 0 && txheight > 246748 ) { if ( txheight < 247205 ) - cmptime -= 16000; + cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u:%u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } From 4ba649d62dac475d1df2a0dcf88e0c8dd21bb724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:44:30 +0200 Subject: [PATCH 054/108] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 36dd3a02e..c92b3bfaf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -723,7 +723,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { txheight = pindex->nHeight; - if ( (previndex= mapBlockIndex[pindex->hashPrevBlock]) != 0 ) + if ( (previndex= pindex->pprev) != 0 ) prevblocktime = previndex->nTime; } } From f25914ebf547ad01682f477b22753f0783204536 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:45:32 +0200 Subject: [PATCH 055/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c92b3bfaf..68b4728c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -718,7 +718,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; - if ( GetTransaction(hash,tx,hashBlock,true) ) + if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { From 01efddaecf0f16fd7f72d93f82daa3599d200eb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:52:45 +0200 Subject: [PATCH 056/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 68b4728c7..f2f077b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -717,7 +717,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + uint256 hashBlock; CBlockIndex *pindex,*previndex; if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) From e8950acaa745149c53b2466a17f0a08f068b517a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:54:30 +0200 Subject: [PATCH 057/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f2f077b68..375096199 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -717,8 +717,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); - uint256 hashBlock; CBlockIndex *pindex,*previndex; - if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) + CTransaction gettx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + if ( GetTransaction(tx.GetHash(),gettx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { From aa8eaec46fe45170702176595ea7b507919af567 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:05:51 +0200 Subject: [PATCH 058/108] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 375096199..ac0d8501d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -817,7 +817,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -3335,9 +3335,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,0,chainActive.Tip()->nTime) < 0 ) + if ( komodo_validate_interest(0,tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->nTime) < 0 ) { - //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From d8be8b2ef749d74a2dc9381c91509f0775a50a7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:22:43 +0200 Subject: [PATCH 059/108] Test --- src/init.cpp | 20 -------------------- src/komodo_gateway.h | 4 ++-- src/main.cpp | 24 ++++++++++-------------- src/pow.cpp | 6 +++--- src/wallet/wallet.cpp | 2 +- 5 files changed, 16 insertions(+), 40 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 0f89ae6ed..0f03aac21 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,26 +1246,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } - uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); - uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); - CValidationState state; - if ( 0 ) - { - LOCK(cs_main); - if ( mapBlockIndex.count(hash) != 0 ) - { - CBlockIndex* pblockindex; - if ( (pblockindex= mapBlockIndex[hash]) != 0 ) - InvalidateBlock(state, pblockindex); - } - if ( mapBlockIndex.count(hash2) != 0 ) - { - CBlockIndex* pblockindex; - if ( (pblockindex= mapBlockIndex[hash2]) != 0 ) - InvalidateBlock(state, pblockindex); - } - } - if ( KOMODO_REWIND >= 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2b1b8ef57..6bf946d6e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -720,13 +720,13 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - extern int32_t KOMODO_REWIND; + /*extern int32_t KOMODO_REWIND; if ( KOMODO_REWIND < 0 ) { fprintf(stderr,">>>>>>> rewind.%d will pause here for a minute. issue command and stop\n",KOMODO_REWIND); sleep(60); KOMODO_REWIND = 0; - } + }*/ // 6a35506c65617365206d616b6520796f75722047697420636f6d6d6974206d65737361676573206d6f726520696e74657265737469 height.241778 checkdeposit n.4 [6a] [P] 80 vs 88 //for (i=0; inHeight >= KOMODO_REWIND ) + if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight >= KOMODO_REWIND ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { - if ( !DisconnectTip(state) ) + InvalidateBlock(state,chainActive.Tip()); + /*if ( !DisconnectTip(state) ) { - //InvalidateBlock(state,chainActive.Tip()); + InvalidateBlock(state,chainActive.Tip()); return false; - } + }*/ } - fprintf(stderr,"end rewind ht.%d\n",chainActive.Tip()->nHeight); - if ( chainActive.Tip()->nHeight == KOMODO_REWIND ) - { - fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(3); - return(true); - } - pindexOldTip = chainActive.Tip(); - pindexFork = chainActive.FindFork(pindexMostWork); - }*/ + fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); + sleep(60); + KOMODO_REWIND = 0; + return(true); + } // Build list of new blocks to connect. std::vector vpindexToConnect; bool fContinue = true; diff --git a/src/pow.cpp b/src/pow.cpp index ce959254c..c6cfe9fab 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -119,7 +119,7 @@ extern std::string NOTARY_PUBKEY; bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params) { - //extern int32_t KOMODO_REWIND; + extern int32_t KOMODO_REWIND; bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33]; @@ -156,7 +156,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( UintToArith256(hash) > bnTarget ) { if ( (height < 235300 || height >= 236000) && KOMODO_LOADINGBLOCKS == 0 && height > 188000 ) - //&& KOMODO_REWIND == 0 )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0 + //&& )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0 { int32_t i; for (i=31; i>=0; i--) @@ -171,7 +171,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in for (i=0; i<66; i++) printf("%d ",mids[i]); printf(" minerids from ht.%d\n",height); - if ( notaryid >= 0 || height > 225000 ) + if ( KOMODO_REWIND == 0 && (notaryid >= 0 || height > 225000) ) return error("CheckProofOfWork(): hash doesn't match nBits"); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ac7f1f9f5..030f6cc8a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -806,7 +806,7 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) extern char ASSETCHAINS_SYMBOL[16]; fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize); } - //if ( KOMODO_REWIND == 0 ) + if ( KOMODO_REWIND == 0 ) assert(nWitnessCacheSize > 0); //if (fFileBacked) { // CWalletDB walletdb(strWalletFile); From 8ba454139033186ca375b1169b954432e97179a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:26:30 +0200 Subject: [PATCH 060/108] Test --- 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 030f6cc8a..091fb5e22 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -757,7 +757,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) { - //extern int32_t KOMODO_REWIND; + extern int32_t KOMODO_REWIND; { LOCK(cs_wallet); for (std::pair& wtxItem : mapWallet) { From a43b1a183841c16cea68cc82422ca850754e21cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:31:24 +0200 Subject: [PATCH 061/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5a955975..08e9fdbfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3331,7 +3331,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->nTime) < 0 ) + if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nTime:0) < 0 ) { fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); return error("CheckBlock: komodo_validate_interest failed"); From a63e5f12561a3a40351b2c2a4e9620e2aa2690e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:32:04 +0200 Subject: [PATCH 062/108] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..d9fb2cd04 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1461,7 +1461,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); - if ( KOMODO_REWIND >= 0 ) + if ( KOMODO_REWIND == 0 ) { uiInterface.InitMessage(_("Activating best chain...")); // scan for better chains in the block chain database, that are not yet connected in the active best chain From b3df07a000fb341c5803cf29857879d905575cc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:36:37 +0200 Subject: [PATCH 063/108] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index d9fb2cd04..cffdb7a9b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,7 +1246,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } - if ( KOMODO_REWIND >= 0 ) + if ( KOMODO_REWIND == 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), GetArg("-checkblocks", 288))) { From afc067b72801fdbe22f41fc8b23880b623c24dc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:42:17 +0200 Subject: [PATCH 064/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 08e9fdbfd..1ffbc295b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3331,9 +3331,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nTime:0) < 0 ) + if ( komodo_validate_interest(0,tx,height,block.nTime) < 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,block.nTime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From 045850921ef707db62924e9f22d3ee2e9cd8972c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:51:56 +0200 Subject: [PATCH 065/108] Test --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ffbc295b..e619f2a67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -794,7 +794,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - if ( tx.nLockTime != 1477258935 ) + //if ( tx.nLockTime != 1477258935 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } @@ -3331,9 +3331,22 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,height,block.nTime) < 0 ) + uint32_t prevtime = 0; CBlockIndex *ptr; + if ( height == chainActive.Tip()->nHeight+1 ) + prevtime = chainActive.Tip()->nTime; + else if ( pindex != 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,block.nTime); + if ( (ptr= pindex->pprev) != 0 ) + prevtime = ptr->nTime; + } + if ( prevtime == 0 ) + { + if ( height > 0 && (ptr= chainActive[height-1]) ) + prevtime = ptr->nTime; + } + if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) + { + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From e0446653ba231e8c122d870740cb8e4a0cb4d7d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:58:47 +0200 Subject: [PATCH 066/108] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index cffdb7a9b..f7a58fa50 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1461,7 +1461,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); - if ( KOMODO_REWIND == 0 ) + if ( KOMODO_REWIND >= 0 ) { uiInterface.InitMessage(_("Activating best chain...")); // scan for better chains in the block chain database, that are not yet connected in the active best chain From 4f7a54254fe4102c57b1556169debab4e9a06069 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:12:06 +0200 Subject: [PATCH 067/108] Test --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e619f2a67..6e18120c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -713,7 +713,7 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime) { int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); @@ -794,7 +794,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - //if ( tx.nLockTime != 1477258935 ) + if ( tx.nLockTime != 1477258935 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } @@ -2885,7 +2885,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if (!DisconnectTip(state)) return false; } - if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight >= KOMODO_REWIND ) + if ( KOMODO_REWIND != 0 && (KOMODO_REWIND < 0 || chainActive.Tip()->nHeight >= KOMODO_REWIND) ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) @@ -3346,7 +3346,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat } if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); + //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From 8abcd8195e58b453fa613634afb7ea3beb294489 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:20:04 +0200 Subject: [PATCH 068/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6e18120c9..bd80a4eae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2885,7 +2885,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if (!DisconnectTip(state)) return false; } - if ( KOMODO_REWIND != 0 && (KOMODO_REWIND < 0 || chainActive.Tip()->nHeight >= KOMODO_REWIND) ) + if ( KOMODO_REWIND != 0 ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) From 310bb0a1b932db69a065d16d0558991589975c50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:20:21 +0200 Subject: [PATCH 069/108] Test --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd80a4eae..261694762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2890,12 +2890,11 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { - InvalidateBlock(state,chainActive.Tip()); - /*if ( !DisconnectTip(state) ) + if ( !DisconnectTip(state) ) { InvalidateBlock(state,chainActive.Tip()); return false; - }*/ + } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); sleep(60); From 4e4e39abfbded1855f35d25837ab84713c0a3d21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:35:23 +0200 Subject: [PATCH 070/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 261694762..1d43f3581 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3331,7 +3331,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat BOOST_FOREACH(const CTransaction& tx, block.vtx) { uint32_t prevtime = 0; CBlockIndex *ptr; - if ( height == chainActive.Tip()->nHeight+1 ) + if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) prevtime = chainActive.Tip()->nTime; else if ( pindex != 0 ) { @@ -3340,7 +3340,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat } if ( prevtime == 0 ) { - if ( height > 0 && (ptr= chainActive[height-1]) ) + if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) prevtime = ptr->nTime; } if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) From 45142781ececa0a22000ebd9292cd4da9e9c62c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:37:21 +0200 Subject: [PATCH 071/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1d43f3581..58d26f9cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2893,7 +2893,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if ( !DisconnectTip(state) ) { InvalidateBlock(state,chainActive.Tip()); - return false; + break; } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); From 7d1067177e59be3ee1a8bd3786581208d12300ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:39:52 +0200 Subject: [PATCH 072/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 58d26f9cc..228f0abcb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2887,7 +2887,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } if ( KOMODO_REWIND != 0 ) { - fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); + fprintf(stderr,"rewind start ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { if ( !DisconnectTip(state) ) @@ -2897,7 +2897,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(60); + sleep(3600); KOMODO_REWIND = 0; return(true); } From 6ec8416f90b92dad4c0ff377ee0b96e937b22b77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 05:12:32 +0200 Subject: [PATCH 073/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 228f0abcb..3aed7fd53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2888,7 +2888,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if ( KOMODO_REWIND != 0 ) { fprintf(stderr,"rewind start ht.%d\n",chainActive.Tip()->nHeight); - while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) + while ( KOMODO_REWIND > 0 && chainActive.Tip()->nHeight > KOMODO_REWIND ) { if ( !DisconnectTip(state) ) { @@ -2897,7 +2897,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(3600); + sleep(60); KOMODO_REWIND = 0; return(true); } From 129d39b037af07155a7aa9c7198a6bad47eccd34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 05:14:44 +0200 Subject: [PATCH 074/108] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 213b9adde..30a1a30fd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -600,7 +600,7 @@ CBlockIndex *komodo_chainactive(int32_t height) { if ( height <= chainActive.Tip()->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.Tip()->nHeight); } //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); diff --git a/src/main.cpp b/src/main.cpp index 3aed7fd53..182983673 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -731,7 +731,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime = prevblocktime + 600; else { - fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); + //fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); return(-1); } /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; From e6528c640c01fbf3c02f96bbf7f48bc9b412aa5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 05:25:46 +0200 Subject: [PATCH 075/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 182983673..5090b94fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3033,7 +3033,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { // The resulting new best tip may not be in setBlockIndexCandidates anymore, so // add it again. BlockMap::iterator it = mapBlockIndex.begin(); - while (it != mapBlockIndex.end()) { + while (it != mapBlockIndex.end() && it->second != 0 ) { if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) { setBlockIndexCandidates.insert(it->second); } From 3afed2e7186398f3d22248b0c6028f23da6351cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 05:45:13 +0200 Subject: [PATCH 076/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5090b94fa..7292781cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -729,11 +729,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } if ( prevblocktime != 0 ) cmptime = prevblocktime + 600; - else + else if ( txheight > 246748 ) { //fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); return(-1); - } + } else return(0); /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); From 2f852a342cb91ebfd165f3f5b601b8dfe7040998 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 05:59:38 +0200 Subject: [PATCH 077/108] Test --- src/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7292781cb..c34abde92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -723,17 +723,22 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { txheight = pindex->nHeight; + prevblocktime = pindex->nTime; if ( (previndex= pindex->pprev) != 0 ) prevblocktime = previndex->nTime; } } - if ( prevblocktime != 0 ) - cmptime = prevblocktime + 600; - else if ( txheight > 246748 ) + if ( prevblocktime == 0 ) { - //fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); - return(-1); - } else return(0); + if ( activeChain.Tip() != 0 && height == activeChain.Tip()->nHeight+1 ) + prevblocktime = activeChain.Tip()->nTime; + else + { + fprintf(stderr,"couldnt get prevblocktime for [%d]\n",txheight); + return(-1); + } + } + cmptime = prevblocktime + 600; /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); From 5aa4223f1ef832f8909231efe94cd972560724f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:03:46 +0200 Subject: [PATCH 078/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c34abde92..ce4ba6967 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -384,7 +384,7 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); - if (it->second != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { + if (it->size() != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; From f4ad37c5473bb7a79cee4809349e5d1caf3d124a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:04:52 +0200 Subject: [PATCH 079/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ce4ba6967..114280ef0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -730,7 +730,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } if ( prevblocktime == 0 ) { - if ( activeChain.Tip() != 0 && height == activeChain.Tip()->nHeight+1 ) + if ( chainActive.Tip.Tip() != 0 && txheight == chainActive.Tip.Tip()->nHeight+1 ) prevblocktime = activeChain.Tip()->nTime; else { From 354dc58a3bb4f348521fea4c9ebb436ef80066a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:05:51 +0200 Subject: [PATCH 080/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 114280ef0..f6c30f2a7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -730,8 +730,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } if ( prevblocktime == 0 ) { - if ( chainActive.Tip.Tip() != 0 && txheight == chainActive.Tip.Tip()->nHeight+1 ) - prevblocktime = activeChain.Tip()->nTime; + if ( chainActive.Tip() != 0 && txheight == chainActive.Tip()->nHeight+1 ) + prevblocktime = chainActive.Tip()->nTime; else { fprintf(stderr,"couldnt get prevblocktime for [%d]\n",txheight); From 3d8d574eacfab05c4f09f6a7925fb31a9eb16f78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:06:45 +0200 Subject: [PATCH 081/108] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f6c30f2a7..812095d0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -381,14 +381,14 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != NULL); - ProcessBlockAvailability(nodeid); + /*ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); - if (it->size() != 0 && it != mapBlockIndex.end() && it->second->nChainWork > 0) { + if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; - } else + } else*/ { // An unknown block was announced; just assume that the latest one is the best one. state->hashLastUnknownBlock = hash; From a7869456aca4f3e2faa0c5ee5176b033ead01e57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:12:46 +0200 Subject: [PATCH 082/108] Test --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 812095d0e..6b430e387 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -734,8 +734,9 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 prevblocktime = chainActive.Tip()->nTime; else { - fprintf(stderr,"couldnt get prevblocktime for [%d]\n",txheight); - return(-1); + prevblocktime = chainActive.Tip()->nTime; + fprintf(stderr,"couldnt get prevblocktime for [%d] use tiptime.%u\n",txheight,prevblocktime); + //return(-1); } } cmptime = prevblocktime + 600; From b2ae2b250795eda903e69915d579dad2b44e9db6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:30:40 +0200 Subject: [PATCH 083/108] Test --- src/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6b430e387..fc2a7f3d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -730,15 +730,20 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } if ( prevblocktime == 0 ) { - if ( chainActive.Tip() != 0 && txheight == chainActive.Tip()->nHeight+1 ) - prevblocktime = chainActive.Tip()->nTime; - else + if ( chainActive.Tip() != 0 ) { - prevblocktime = chainActive.Tip()->nTime; - fprintf(stderr,"couldnt get prevblocktime for [%d] use tiptime.%u\n",txheight,prevblocktime); - //return(-1); + if ( txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) + prevblocktime = chainActive.Tip()->nTime; + else + { + prevblocktime = chainActive.Tip()->nTime; + fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,prevblocktime); + return(-1); + } } } + if ( prevblocktime == 0 ) + return(-1); cmptime = prevblocktime + 600; /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; From 40a24f8f9d282c98765222efebe7e267910c96a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 06:39:12 +0200 Subject: [PATCH 084/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fc2a7f3d5..5b4142369 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -738,7 +738,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { prevblocktime = chainActive.Tip()->nTime; fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,prevblocktime); - return(-1); + //return(-1); } } } From 380b93d7681d15506a50df44dcc7ec7caa73915b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:10:28 +0200 Subject: [PATCH 085/108] Test --- src/main.cpp | 24 ++++++++++++++++++++++-- src/miner.cpp | 4 ++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5b4142369..d85543682 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2407,6 +2407,26 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin for (unsigned int i = 0; i < block.vtx.size(); i++) { const CTransaction &tx = block.vtx[i]; + uint32_t prevtime = 0; CBlockIndex *ptr; + if ( (ptr= pindex->pprev) != 0 ) + prevtime = ptr->nTime; + /*if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) + prevtime = chainActive.Tip()->nTime; + else if ( pindex != 0 ) + { + if ( (ptr= pindex->pprev) != 0 ) + prevtime = ptr->nTime; + } + if ( prevtime == 0 ) + { + if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) + prevtime = ptr->nTime; + }*/ + if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime) < 0 ) + { + //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); + return state.DoS(10, error("ConnectBlock(): validate interest failed"),REJECT_INVALID, "bad-apr-calc"); + } nInputs += tx.vin.size(); nSigOps += GetLegacySigOpCount(tx); @@ -3341,7 +3361,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - uint32_t prevtime = 0; CBlockIndex *ptr; + /*uint32_t prevtime = 0; CBlockIndex *ptr; if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) prevtime = chainActive.Tip()->nTime; else if ( pindex != 0 ) @@ -3358,7 +3378,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); - } + }*/ if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); } diff --git a/src/miner.cpp b/src/miner.cpp index 91318d641..c0ab729d4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -207,8 +207,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( expired != 0 ) { fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - list removed; - mempool.remove(tx, removed, true); + //list removed; + //mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From ac6feaa8a089953709c533d64eae62a49eb7ddc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:10:51 +0200 Subject: [PATCH 086/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d85543682..d150f6488 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -738,7 +738,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { prevblocktime = chainActive.Tip()->nTime; fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,prevblocktime); - //return(-1); + return(-1); } } } From 464fe491ab89e88bac1b5af4e6c8ac3fa4b2abd6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:23:55 +0200 Subject: [PATCH 087/108] Test --- src/komodo_gateway.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6bf946d6e..ef1937d0c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -643,7 +643,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) for (i=0; i= indallvouts) ) + if ( block.vtx[i].vin[j].prevout.hash == array[k] && (block.vtx[i].vin[j].prevout.n == 1 || k >= indallvouts) ) { printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j); return(-1); diff --git a/src/main.cpp b/src/main.cpp index d150f6488..c0d4ec9a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -994,7 +994,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash:: { for (k=0; k= indallvouts) ) + if ( tx.vin[j].prevout.hash == array[k] && (tx.vin[j].prevout.n == 1 || k >= indallvouts) ) { static uint32_t counter; if ( counter++ < 100 ) From e8d79f05b8c206d035da4d29e3c8538d03c0f882 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:31:40 +0200 Subject: [PATCH 088/108] Test --- src/main.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c0d4ec9a9..18bdff835 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) uint32_t komodo_heightstamp(int32_t height); -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime,int32_t strictflag) { int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) @@ -734,12 +734,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) prevblocktime = chainActive.Tip()->nTime; - else + else if ( strictflag == 0 ) { prevblocktime = chainActive.Tip()->nTime; - fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,prevblocktime); - return(-1); - } + fprintf(stderr,"couldnt get prevblocktime for [%d] use tiptime.%u\n",txheight,prevblocktime); + } else return(-1); } } if ( prevblocktime == 0 ) @@ -828,7 +827,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime,1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -2422,7 +2421,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) prevtime = ptr->nTime; }*/ - if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime) < 0 ) + if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime,1) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return state.DoS(10, error("ConnectBlock(): validate interest failed"),REJECT_INVALID, "bad-apr-calc"); @@ -3361,7 +3360,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - /*uint32_t prevtime = 0; CBlockIndex *ptr; + uint32_t prevtime = 0; CBlockIndex *ptr; if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) prevtime = chainActive.Tip()->nTime; else if ( pindex != 0 ) @@ -3374,11 +3373,11 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) prevtime = ptr->nTime; } - if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) + if ( komodo_validate_interest(0,tx,height,prevtime,0) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); - }*/ + } if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); } From b60897a5112f730f1ad824c7aefaabd57efcd5e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:35:46 +0200 Subject: [PATCH 089/108] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 18bdff835..8f2870fa9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -806,14 +806,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); + //fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n",strictflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } From c8e854e4c66fd7adf630796fa2b322c5c4407843 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:38:40 +0200 Subject: [PATCH 090/108] Test --- src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8f2870fa9..9e92c398e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -732,13 +732,13 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( chainActive.Tip() != 0 ) { - if ( txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) + if ( strictflag == 0 || txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) prevblocktime = chainActive.Tip()->nTime; - else if ( strictflag == 0 ) + else { - prevblocktime = chainActive.Tip()->nTime; - fprintf(stderr,"couldnt get prevblocktime for [%d] use tiptime.%u\n",txheight,prevblocktime); - } else return(-1); + fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,chainActive.Tip()->nTime); + return(-1); + } } } if ( prevblocktime == 0 ) From eeef062480bc0a419c3bcd76ef671496bb8b793e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 07:40:34 +0200 Subject: [PATCH 091/108] Test --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9e92c398e..7eabc07ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -813,7 +813,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } } - fprintf(stderr,"validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n",strictflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); + if ( strictflag != 0 ) + fprintf(stderr,"validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n",strictflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } @@ -2421,7 +2422,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) prevtime = ptr->nTime; }*/ - if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime,1) < 0 ) + if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime,2) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return state.DoS(10, error("ConnectBlock(): validate interest failed"),REJECT_INVALID, "bad-apr-calc"); From 14aa6cc0e2269f0ff91d61af84fb7c4e537348ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:28:13 +0200 Subject: [PATCH 092/108] Initial --- src/komodo_bitcoind.h | 24 ++++++ src/komodo_gateway.h | 1 + src/main.cpp | 193 +++++------------------------------------- src/main.h | 3 +- src/miner.cpp | 24 +++--- 5 files changed, 61 insertions(+), 184 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 30a1a30fd..81e9c3918 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -804,3 +804,27 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) return(1); else return(0); } + +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime) +{ + uint32_t cmptime = nTime; + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + { + if ( txheight > 246748 ) + { + if ( txheight < 247205 ) + cmptime -= 600; + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 ) + { + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + } + return(-1); + } + } + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + } + return(0); +} + diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ef1937d0c..d19a3d6f6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -629,6 +629,7 @@ const char *banned_txids[] = "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 // all vouts banned + "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 }; diff --git a/src/main.cpp b/src/main.cpp index 7eabc07ff..a06d6ba92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,7 +325,18 @@ void FinalizeNode(NodeId nodeid) { mapNodeState.erase(nodeid); } - + +void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) { + int expired = pool.Expire(GetTime() - age); + if (expired != 0) + LogPrint("mempool", "Expired %i transactions from the memory pool\n", expired); + + std::vector vNoSpendsRemaining; + pool.TrimToSize(limit, &vNoSpendsRemaining); + BOOST_FOREACH(const uint256& removed, vNoSpendsRemaining) + pcoinsTip->Uncache(removed); +} + // Requires cs_main. // Returns a bool indicating whether we requested this block. bool MarkBlockAsReceived(const uint256& hash) { @@ -708,132 +719,11 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } -uint32_t komodo_heightstamp(int32_t height); - -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime,int32_t strictflag) -{ - int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) - { - //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); - LOCK(cs_main); - CTransaction gettx; uint256 hashBlock; CBlockIndex *pindex,*previndex; - if ( GetTransaction(tx.GetHash(),gettx,hashBlock,true) ) - { - if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) - { - txheight = pindex->nHeight; - prevblocktime = pindex->nTime; - if ( (previndex= pindex->pprev) != 0 ) - prevblocktime = previndex->nTime; - } - } - if ( prevblocktime == 0 ) - { - if ( chainActive.Tip() != 0 ) - { - if ( strictflag == 0 || txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) - prevblocktime = chainActive.Tip()->nTime; - else - { - fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,chainActive.Tip()->nTime); - return(-1); - } - } - } - if ( prevblocktime == 0 ) - return(-1); - cmptime = prevblocktime + 600; - /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; - prevblocktime = 0; - locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - if ( (txheight= txheightarg) == 0 ) - txheight = chainActive.Tip()->nHeight + 1; - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) - prevblocktime = prev->nTime; - if ( tiptime == 0 ) - tiptime = (int32_t)chainActive.Tip()->nTime; - if ( txheighttime == 0 ) - { - static uint32_t counter0; - txheighttime = chainActive.Tip()->nTime; - if ( counter0++ < 3 ) - fprintf(stderr,"error getting txheighttime, set to tiptime.%u\n",txheighttime); - } - if ( txheighttime != 0 && txblocktime != 0 ) - { - cmptime = txheighttime; - if ( txblocktime < cmptime ) - cmptime = txblocktime; - } - else if ( (cmptime= txheighttime) == 0 ) - cmptime = txblocktime; - if ( tiptime != 0 && tiptime < cmptime ) - cmptime = tiptime; - if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) - cmptime = prevblocktime; - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) - cmptime = prev->nTime + 600; - if ( cmptime >= 1490159171 - 24*3600 ) - { - if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) - { - if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748 - { - if ( tx.nLockTime != 1477258935 ) - { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime); - } - if ( expiredp != 0 ) - *expiredp = cmptime-3600; - return(-1); - } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); - } - } - if ( (cmptime= prevblocktime) == 0 ) - { - if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) - { - fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); - return(-1); - } - }*/ - if ( cmptime > 0 && txheight > 246748 ) - { - if ( txheight < 247205 ) - cmptime -= 600; - if ( (int64_t)tx.nLockTime < cmptime-3600 ) - { - if ( tx.nLockTime != 1477258935 ) - { - //fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); - } - if ( expiredp != 0 ) - *expiredp = cmptime-3600; - return(-1); - } - } - if ( strictflag != 0 ) - fprintf(stderr,"validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n",strictflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); - } - return(0); -} - -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,uint32_t prevblocktime) +bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { int32_t i; - if ( expiredp != 0 ) - *expiredp = 0; if (tx.nLockTime == 0) return true; - if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 - { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime,1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 - { - fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); - return(false); // need to prevent pastdating tx - } //else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); - } if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; BOOST_FOREACH(const CTxIn& txin, tx.vin) @@ -879,7 +769,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); + return IsFinalTx(tx, nBlockHeight, nBlockTime); } /** @@ -984,11 +874,6 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash:: static uint256 array[64]; static int32_t numbanned,indallvouts; int32_t j,k,n; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); - /*if ( komodo_validate_interest(tx) < 0 ) - { - fprintf(stderr,"CheckTransaction komodo_validate_interest error\n"); - return(false); - }*/ n = tx.vin.size(); for (j=0; jnHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) { - fprintf(stderr,"komodo_validate_interest failure\n"); + fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); - }*/ + } if (!CheckTransaction(tx, state, verifier)) { fprintf(stderr,"accept failure.0\n"); @@ -2407,27 +2292,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin for (unsigned int i = 0; i < block.vtx.size(); i++) { const CTransaction &tx = block.vtx[i]; - uint32_t prevtime = 0; CBlockIndex *ptr; - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - /*if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) - prevtime = chainActive.Tip()->nTime; - else if ( pindex != 0 ) - { - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - } - if ( prevtime == 0 ) - { - if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) - prevtime = ptr->nTime; - }*/ - if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime,2) < 0 ) - { - //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); - return state.DoS(10, error("ConnectBlock(): validate interest failed"),REJECT_INVALID, "bad-apr-calc"); - } - nInputs += tx.vin.size(); nSigOps += GetLegacySigOpCount(tx); if (nSigOps > MAX_BLOCK_SIGOPS) @@ -3060,6 +2924,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { return false; } } + LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); // The resulting new best tip may not be in setBlockIndexCandidates anymore, so // add it again. @@ -3361,24 +3226,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - uint32_t prevtime = 0; CBlockIndex *ptr; - if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) - prevtime = chainActive.Tip()->nTime; - else if ( pindex != 0 ) - { - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - } - if ( prevtime == 0 ) - { - if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) - prevtime = ptr->nTime; - } - if ( komodo_validate_interest(0,tx,height,prevtime,0) < 0 ) - { - //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); - return error("CheckBlock: komodo_validate_interest failed"); - } + if ( komodo_validate_interest(tx,komodo_block2height((CBlock *)&block),block.nTime) < 0 ) + return error("CheckBlock: komodo_validate_interest failed"); if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); } @@ -3458,7 +3307,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() : block.GetBlockTime(); - if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) { + if (!IsFinalTx(tx, nHeight, nLockTimeCutoff)) { return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } diff --git a/src/main.h b/src/main.h index 71ec17ef1..3ba8ce7f2 100644 --- a/src/main.h +++ b/src/main.h @@ -46,6 +46,7 @@ class CValidationInterface; class CValidationState; struct CNodeStateStats; +#define DEFAULT_MEMPOOL_EXPIRY 1 /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/ static const unsigned int DEFAULT_BLOCK_MAX_SIZE = MAX_BLOCK_SIZE; @@ -351,7 +352,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason); * Check if transaction is final and can be included in a block with the * specified height and time. Consensus critical. */ -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,uint32_t prevblocktime); +bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index c0ab729d4..c0db1132a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,16 +202,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime)) - { - if ( expired != 0 ) - { - fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - //list removed; - //mempool.remove(tx, removed, true); - } + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); + if ( 0 && komodo_validate_interest(tx,pblock->nHeight,(uint32_t)pblock->nTime) < 0 ) + { + fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); + continue; + } COrphan* porphan = NULL; double dPriority = 0; CAmount nTotalIn = 0; @@ -438,8 +435,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) static uint32_t counter; if ( counter++ < 100 ) fprintf(stderr,"warning: testblockvalidity failed\n"); - //return(0); - throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); + return(0); } } @@ -891,6 +887,12 @@ void static BitcoinMiner(CWallet *pwallet) // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + { + fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); + break; + } } } } From 1691b50b8dfb8ca6dfa28b051e28d3a586c42217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:35:34 +0200 Subject: [PATCH 093/108] Test --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a06d6ba92..9b4e5633a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -326,15 +326,16 @@ void FinalizeNode(NodeId nodeid) { mapNodeState.erase(nodeid); } -void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) { - int expired = pool.Expire(GetTime() - age); +void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) +{ +/* int expired = pool.Expire(GetTime() - age); if (expired != 0) LogPrint("mempool", "Expired %i transactions from the memory pool\n", expired); std::vector vNoSpendsRemaining; pool.TrimToSize(limit, &vNoSpendsRemaining); BOOST_FOREACH(const uint256& removed, vNoSpendsRemaining) - pcoinsTip->Uncache(removed); + pcoinsTip->Uncache(removed);*/ } // Requires cs_main. From ea5f02cb0a595303c9ff6e6d2b0ba0ee06bcf215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:49:11 +0200 Subject: [PATCH 094/108] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9b4e5633a..2b6ccae3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2925,7 +2925,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { return false; } } - LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); + //LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); // The resulting new best tip may not be in setBlockIndexCandidates anymore, so // add it again. From da3dcb034b5836efd8af39f4cfec9f2250c1c5ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:52:56 +0200 Subject: [PATCH 095/108] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c0db1132a..3ce396485 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -429,8 +429,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + CValidationState tmpstate; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) From e70bdd48c5ad76fc8494b35be84d1525222fa41b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:53:41 +0200 Subject: [PATCH 096/108] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3ce396485..fa553eea8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -204,7 +204,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,pblock->nHeight,(uint32_t)pblock->nTime) < 0 ) + if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From c583e2a9ea145adfb74c00fe531ef4e41b354a96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:02:13 +0200 Subject: [PATCH 097/108] Test --- src/miner.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index fa553eea8..77771965e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -114,6 +114,7 @@ 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); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -429,8 +430,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - CValidationState tmpstate; - if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) @@ -887,8 +888,8 @@ void static BitcoinMiner(CWallet *pwallet) // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } - CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + CValidationState tmpstate; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) { fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); break; From f42de68876d60427e015bead745676367b168863 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:07:39 +0200 Subject: [PATCH 098/108] 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 81e9c3918..a48908371 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -822,8 +822,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(-1); } + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } return(0); } From d01c0463e79935a7de40c3b839858f98bb4b5d84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:27:24 +0200 Subject: [PATCH 099/108] Test --- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 4 ++-- src/main.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a48908371..6d4278259 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -818,11 +818,11 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } return(-1); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp2.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } } return(0); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d19a3d6f6..d3435d2e2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1290,7 +1290,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { basesp->approved += values[i]; didstats = 1; - printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); + //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); } //printf(" i.%d (%s) <- %.8f ADDFLAG APPROVED\n",i,coinaddr,dstr(values[i])); } @@ -1300,7 +1300,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { basesp->approved += values[i]; didstats = 1; - printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); + //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); } } //else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) != 0 ) diff --git a/src/main.cpp b/src/main.cpp index 2b6ccae3a..e35ef94e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( 0 && komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); From 3bc88f14513b15b49ac027e6cc110d847c1320af Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:46:52 +0200 Subject: [PATCH 100/108] Test --- src/komodo_bitcoind.h | 5 +++-- src/main.cpp | 4 ++-- src/miner.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6d4278259..f80c0f47d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -805,7 +805,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) else return(0); } -int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime) +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag) { uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) @@ -822,7 +822,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(-1); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp2.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + if ( dispflag != 0 ) + fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } } return(0); diff --git a/src/main.cpp b/src/main.cpp index e35ef94e7..2e0ea8fff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,3) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -3227,7 +3227,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(tx,komodo_block2height((CBlock *)&block),block.nTime) < 0 ) + if ( komodo_validate_interest(tx,komodo_block2height((CBlock *)&block),block.nTime,1) < 0 ) return error("CheckBlock: komodo_validate_interest failed"); if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); diff --git a/src/miner.cpp b/src/miner.cpp index 77771965e..233b972fe 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -114,7 +114,7 @@ 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 komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -205,7 +205,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime) < 0 ) + if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From bbaa0f9df448b312bd91c2d636f58b0c1d0f455f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:51:12 +0200 Subject: [PATCH 101/108] Test --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f80c0f47d..56ebad946 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,13 +810,13 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748-24*3600*3600 ) { if ( txheight < 247205 ) cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - if ( tx.nLockTime != 1477258935 ) + if ( tx.nLockTime != 1477258935 || dispflag != 0 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } diff --git a/src/miner.cpp b/src/miner.cpp index 233b972fe..3c9e79372 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -205,7 +205,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) + if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From 9f129494002fa31d43934cf6237264c4eaeffc38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 00:06:04 +0200 Subject: [PATCH 102/108] 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 56ebad946..583993481 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,7 +810,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748-24*3600*3600 ) + if ( txheight > 246748-1000 ) { if ( txheight < 247205 ) cmptime -= 600; @@ -818,7 +818,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( tx.nLockTime != 1477258935 || dispflag != 0 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } return(-1); } From 3d02f57b4235eac7b9dd1e6bf38bcf84504626b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 01:10:50 +0200 Subject: [PATCH 103/108] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 583993481..fd307a805 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,7 +810,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748-1000 ) + if ( txheight > 246748 ) { if ( txheight < 247205 ) cmptime -= 600; diff --git a/src/main.cpp b/src/main.cpp index 2e0ea8fff..1599b2fe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,3) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); From 948ad8f3f814196441968c7b7eaacc4d96dc0971 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 01:38:29 +0200 Subject: [PATCH 104/108] 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 fd307a805..c54995402 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -822,7 +822,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(-1); } - if ( dispflag != 0 ) + if ( 0 && dispflag != 0 ) fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } } From b366cab901a67e078fedff9ef6c3dbf13a50e8e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 02:08:58 +0200 Subject: [PATCH 105/108] Disable updating template time --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3c9e79372..e78e009b2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,13 +425,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); - UpdateTime(pblock, Params().GetConsensus(), pindexPrev); + //UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + if ( 0 && !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) From abdf25c80ce0a1910c597d2bd8e7112f5d45c71f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 10:28:21 +0200 Subject: [PATCH 106/108] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d3435d2e2..a79537ee3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -643,7 +643,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) } for (i=0; i Date: Sat, 25 Mar 2017 10:35:45 +0200 Subject: [PATCH 107/108] Fix miner --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e78e009b2..82d177cda 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -431,7 +431,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); CValidationState state; - if ( 0 && !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) @@ -882,18 +882,18 @@ void static BitcoinMiner(CWallet *pwallet) // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + //UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } - CValidationState tmpstate; + /*CValidationState tmpstate; if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) { fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); break; - } + }*/ } } } From 39d28b0641131bdeac307949f28206ab1e1dbf2d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 13:25:37 +0200 Subject: [PATCH 108/108] Expand time window --- 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 c54995402..05893328f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -813,7 +813,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ if ( txheight > 246748 ) { if ( txheight < 247205 ) - cmptime -= 600; + cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 || dispflag != 0 )