diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index 2e6136357..a1865b649 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 ( (uint64_t)pn < 0x1000 || (uint64_t)b.pn <= 0x1000 ) + { + 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; diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..f7a58fa50 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))) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 481ede104..05893328f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -594,6 +594,27 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) return(0); } +CBlockIndex *komodo_chainactive(int32_t height) +{ + if ( chainActive.Tip() != 0 ) + { + 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 null chainActive.Tip() height %d\n",height); + return(0); +} + +uint32_t komodo_heightstamp(int32_t height) +{ + CBlockIndex *ptr; + if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) + return(ptr->nTime); + else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -618,11 +639,6 @@ void komodo_connectpindex(CBlockIndex *pindex) komodo_connectblock(pindex,block); } -CBlockIndex *komodo_chainactive(int32_t height) -{ - return(chainActive[height]); -} - int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height); @@ -788,3 +804,28 @@ 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,int32_t dispflag) +{ + 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 -= 16000; + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 || dispflag != 0 ) + { + 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); + } + 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); + } + } + return(0); +} + diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 185145bdd..a79537ee3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -628,26 +628,33 @@ const char *banned_txids[] = "a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265 "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 + // all vouts banned + "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 + "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); @@ -714,13 +721,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; i %.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]); @@ -1283,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])); } @@ -1293,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/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/komodo_notary.h b/src/komodo_notary.h index 6a77ecb77..e47638c8e 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -27,17 +27,17 @@ const char *Notaries_genesis[][2] = { "movecrypto_EU", "021ab53bc6cf2c46b8a5456759f9d608966eff87384c2b52c0ac4cc8dd51e9cc42" }, { "badass_EU", "0209d48554768dd8dada988b98aca23405057ac4b5b46838a9378b95c3e79b9b9e" }, { "crackers_NA", "029e1c01131974f4cd3f564cc0c00eb87a0f9721043fbc1ca60f9bd0a1f73f64a1" }, - { "proto_EU", "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1" }, + { "proto_EU", "03681ffdf17c8f4f0008cefb7fa0779c5e888339cdf932f0974483787a4d6747c1" }, // 10 { "jeezy_EU", "023cb3e593fb85c5659688528e9a4f1c4c7f19206edc7e517d20f794ba686fd6d6" }, { "farl4web_EU", "035caa40684ace968677dca3f09098aa02b70e533da32390a7654c626e0cf908e1" }, { "nxtswe_EU", "032fb104e5eaa704a38a52c126af8f67e870d70f82977e5b2f093d5c1c21ae5899" }, { "traderbill_EU", "03196e8de3e2e5d872f31d79d6a859c8704a2198baf0af9c7b21e29656a7eb455f" }, - { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, + { "vanbreuk_EU", "024f3cad7601d2399c131fd070e797d9cd8533868685ddbe515daa53c2e26004c3" }, // 15 { "titomane_EU", "03517fcac101fed480ae4f2caf775560065957930d8c1facc83e30077e45bdd199" }, { "supernet_AE", "029d93ef78197dc93892d2a30e5a54865f41e0ca3ab7eb8e3dcbc59c8756b6e355" }, { "supernet_EU", "02061c6278b91fd4ac5cab4401100ffa3b2d5a277e8f71db23401cc071b3665546" }, { "supernet_NA", "033c073366152b6b01535e15dd966a3a8039169584d06e27d92a69889b720d44e1" }, - { "yassin_EU", "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0" }, + { "yassin_EU", "033fb7231bb66484081952890d9a03f91164fb27d392d9152ec41336b71b15fbd0" }, // 20 { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, { "badass_SH", "026b49dd3923b78a592c1b475f208e23698d3f085c4c3b4906a59faf659fd9530b" }, { "badass_NA", "02afa1a9f948e1634a29dc718d218e9d150c531cfa852843a1643a02184a63c1a7" }, @@ -71,7 +71,7 @@ const char *Notaries_elected[][2] = { "crackers_SH", "02be28310e6312d1dd44651fd96f6a44ccc269a321f907502aae81d246fabdb03e" }, { "durerus_EU", "02bcbd287670bdca2c31e5d50130adb5dea1b53198f18abeec7211825f47485d57" }, { "etszombi_AR", "031c79168d15edabf17d9ec99531ea9baa20039d0cdc14d9525863b83341b210e9" }, - { "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, + { "etszombi_EU", "0281b1ad28d238a2b217e0af123ce020b79e91b9b10ad65a7917216eda6fe64bf7" }, // 15 { "etszombi_SH", "025d7a193c0757f7437fad3431f027e7b5ed6c925b77daba52a8755d24bf682dde" }, { "farl4web_EU", "0300ecf9121cccf14cf9423e2adb5d98ce0c4e251721fa345dec2e03abeffbab3f" }, { "farl4web_SH", "0396bb5ed3c57aa1221d7775ae0ff751e4c7dc9be220d0917fa8bbdf670586c030" }, @@ -198,7 +198,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height) void komodo_notarysinit(int32_t origheight,uint8_t pubkeys[64][33],int32_t num) { static int32_t hwmheight; - int32_t k,i,htind,nonz,height; struct knotary_entry *kp; struct knotaries_entry N; + int32_t k,i,htind,height; struct knotary_entry *kp; struct knotaries_entry N; if ( Pubkeys == 0 ) Pubkeys = (struct knotaries_entry *)calloc(KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP,sizeof(*Pubkeys)); memset(&N,0,sizeof(N)); @@ -260,7 +260,7 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33) return(modval); } } - if ( height >= 300000 ) + if ( height >= 250000 )//300000 ) return(-1); htind = height / KOMODO_ELECTION_GAP; pthread_mutex_lock(&komodo_mutex); @@ -345,7 +345,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n void komodo_init(int32_t height) { - static int didinit; uint256 zero; int32_t i,k,n; uint8_t pubkeys[64][33]; + static int didinit; uint256 zero; int32_t k,n; uint8_t pubkeys[64][33]; if ( 0 && height != 0 ) printf("komodo_init ht.%d didinit.%d\n",height,didinit); if ( didinit == 0 ) diff --git a/src/main.cpp b/src/main.cpp index 7396530ce..1599b2fe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,7 +325,19 @@ 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) { @@ -367,7 +379,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 != mapBlockIndex.end() && itOld->second->nChainWork > 0) + { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; state->hashLastUnknownBlock.SetNull(); @@ -380,14 +393,15 @@ 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) { // 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; } @@ -706,65 +720,11 @@ 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 i,txheight=0; uint32_t cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) - { - locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - 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 ( 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 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); - 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); - } - } - //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); -} - -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,int32_t interesttime) +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,interesttime) < 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) @@ -810,7 +770,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); } /** @@ -912,24 +872,19 @@ 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))); - /*if ( komodo_validate_interest(tx) < 0 ) - { - fprintf(stderr,"CheckTransaction komodo_validate_interest error\n"); - return(false); - }*/ + numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); 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); } } @@ -1156,11 +1111,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - /*if ( komodo_validate_interest(tx) < 0 ) // called from CheckFinalTx() below + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 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"); @@ -1184,7 +1139,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? @@ -2338,7 +2293,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]; - nInputs += tx.vin.size(); nSigOps += GetLegacySigOpCount(tx); if (nSigOps > MAX_BLOCK_SIGOPS) @@ -2827,27 +2781,22 @@ 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 ) { - fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); - while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) + fprintf(stderr,"rewind start ht.%d\n",chainActive.Tip()->nHeight); + while ( KOMODO_REWIND > 0 && chainActive.Tip()->nHeight > KOMODO_REWIND ) { if ( !DisconnectTip(state) ) { - //InvalidateBlock(state,chainActive.Tip()); - return false; + InvalidateBlock(state,chainActive.Tip()); + break; } } - 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; @@ -2976,11 +2925,12 @@ 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. 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); } @@ -3277,11 +3227,8 @@ 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 ) - { - //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"); - } + 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"); } @@ -3361,7 +3308,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 1bea5030f..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,int32_t interesttime); +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 91318d641..ac1ceff3d 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,int32_t dispflag); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -202,16 +203,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 ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) + { + fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); + continue; + } COrphan* porphan = NULL; double dPriority = 0; CAmount nTotalIn = 0; @@ -427,7 +425,7 @@ 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]); @@ -438,8 +436,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); } } @@ -552,6 +549,7 @@ int32_t komodo_baseid(char *origbase); int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *nonzpkeysp,int32_t height); int32_t FOUND_BLOCK,KOMODO_MAYBEMINED; extern int32_t KOMODO_LASTMINED; +int32_t roundrobin_delay; void static BitcoinMiner(CWallet *pwallet) { @@ -666,9 +664,10 @@ void static BitcoinMiner(CWallet *pwallet) // // Search // - uint8_t pubkeys[66][33]; int mids[66],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + uint8_t pubkeys[66][33]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); + roundrobin_delay = ROUNDROBIN_DELAY; if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 )//komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { j = 65; @@ -704,7 +703,15 @@ void static BitcoinMiner(CWallet *pwallet) if ( mids[j] == -1 ) gpucount++; } - fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL)); + if ( gpucount > j/3 ) + { + double delta; + i = ((Mining_height + notaryid) % 64); + delta = sqrt((double)gpucount - j/3); + roundrobin_delay += ((delta * i) / 64) - delta; + //fprintf(stderr,"delta.%f %f %f\n",delta,(double)(gpucount - j/3) / 2,(delta * i) / 64); + } + fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u %d\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL),roundrobin_delay); } for (j=0; j<65; j++) if ( mids[j] == notaryid ) @@ -758,10 +765,10 @@ void static BitcoinMiner(CWallet *pwallet) // fprintf(stderr," missed target\n"); return false; } - if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+ROUNDROBIN_DELAY ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && Mining_start != 0 && time(NULL) < Mining_start+roundrobin_delay ) { - //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+ROUNDROBIN_DELAY-time(NULL))); - int32_t nseconds = Mining_start+ROUNDROBIN_DELAY-time(NULL); + //printf("Round robin diff sleep %d\n",(int32_t)(Mining_start+roundrobin_delay-time(NULL))); + int32_t nseconds = Mining_start+roundrobin_delay-time(NULL); if ( nseconds > 0 ) sleep(nseconds); MilliSleep((rand() % 1700) + 1); @@ -885,12 +892,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; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) + { + fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); + break; + }*/ } } } diff --git a/src/pow.cpp b/src/pow.cpp index ce959254c..e0957ab75 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,9 +156,8 @@ 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--) printf("%02x",((uint8_t *)&hash)[i]); printf(" hash vs "); @@ -171,9 +170,24 @@ 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) ) + { + fprintf(stderr,"pow error height.%d loading.%d notaryid.%d\n",height,KOMODO_LOADINGBLOCKS,notaryid); return error("CheckProofOfWork(): hash doesn't match nBits"); - } + } else fprintf(stderr,"skip return error height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS); + } else fprintf(stderr,"skip height.%d loading.%d\n",height,KOMODO_LOADINGBLOCKS); + } + if ( 0 && height > 248000 ) + { + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); + fprintf(stderr," hash vs "); + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," POW ok for ht.%d notaryid.%d: ",height,notaryid); + for (i=0; i<33; i++) + fprintf(stderr,"%02x",pubkey33[i]); + fprintf(stderr,"\n"); } return true; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ac7f1f9f5..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) { @@ -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);