diff --git a/src/coins.cpp b/src/coins.cpp index bbff5495b..3388f7439 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -400,7 +400,10 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr interest = komodo_interest(nHeight,value,tx.nLockTime,tiptime); #ifdef KOMODO_ENABLE_INTEREST if ( ASSETCHAINS_SYMBOL[0] == 0 && nHeight >= 60000 ) + { + printf("nResult %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nResult/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); nResult += interest; + } #endif (*interestp) += interest; } diff --git a/src/coins.h b/src/coins.h index 123d8b4eb..7d5bc8168 100644 --- a/src/coins.h +++ b/src/coins.h @@ -6,6 +6,8 @@ #ifndef BITCOIN_COINS_H #define BITCOIN_COINS_H +#define KOMODO_ENABLE_INTEREST //enabling this is a hardfork, activate with new RR method + #include "compressor.h" #include "memusage.h" #include "serialize.h" diff --git a/src/komodo.h b/src/komodo.h index 71a9c0e40..94a204b21 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -18,8 +18,8 @@ // Todo: // 1. error check fiat redeem amounts -// 2. net balance limiter, activate dPoW for all fiats -// 3. REVS and non-fiat chains +// 2. net balance limiter +// 3. new RR algo // 4. verify: interest payment, ratification, reorgs // 5. automate notarization fee payouts // 6. automated distribution of test REVS snapshot @@ -33,6 +33,8 @@ #define GENESIS_NBITS 0x1f00ffff #define KOMODO_MINRATIFY 7 +int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks + #include "komodo_globals.h" #include "komodo_utils.h" @@ -348,7 +350,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) static int32_t hwmheight; uint64_t signedmask,voutmask; uint8_t scriptbuf[4096],pubkeys[64][33]; uint256 kmdtxid,btctxid,txhash; - int32_t i,j,k,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; + int32_t i,j,k,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; komodo_init(pindex->nHeight); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; @@ -391,6 +393,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #endif // signedmask is needed here! notaryid = komodo_voutupdate(notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue); + if ( i == 0 && j == 0 && komodo_chosennotary(&nid,height,scriptbuf + 1) >= 0 ) + { + if ( height < sizeof(Minerids)/sizeof(*Minerids) ) + Minerids[height] = nid; + } if ( 0 && i > 0 ) { for (k=0; knHeight); + Minerids[pindex->nHeight] = -2; //hash = block.GetHash(); //for (i=0; i<32; i++) // printf("%02x",((uint8_t *)&hash)[i]); @@ -446,6 +447,43 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) } } +int8_t komodo_minerid(int32_t height) +{ + int32_t notaryid; CBlockIndex *pindex; uint8_t pubkey33[33]; + if ( height <= chainActive.Tip()->nHeight ) + { + if ( (pindex= chainActive[height]) != 0 ) + { + komodo_index2pubkey33(pubkey33,pindex,height); + komodo_chosennotary(¬aryid,height,pubkey33); + return(notaryid); + } + } + return(-2); +} + +int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]) +{ + int32_t notaryid; + komodo_chosennotary(¬aryid,height,pubkey33); + if ( height >= 34000 && notaryid >= 0 ) + { + for (i=1; i<64; i++) + { + if ( Minerids[height-i] == -2 ) + { + Minerids[height-i] = komodo_minerid(height-i); + if ( Minerids[height - i] == -2 ) + fprintf(stderr,"second -2 for Minerids[%d] current.%d\n",height-i,CURRENT_HEIGHT); + } + if ( Minerids[height-i] == notaryid ) + return(-1); + } + return(1); + } + return(0); +} + int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { int32_t notarized_height; uint256 notarized_hash,notarized_desttxid; CBlockIndex *notary; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 777010982..564065482 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -229,15 +229,20 @@ void komodo_init(int32_t height) { pthread_mutex_init(&komodo_mutex,NULL); decode_hex(NOTARY_PUBKEY33,33,(char *)NOTARY_PUBKEY.c_str()); - n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); - for (k=0; k= 0 ) { - if ( Notaries_genesis[k][0] == 0 || Notaries_genesis[k][1] == 0 || Notaries_genesis[k][0][0] == 0 || Notaries_genesis[k][1][0] == 0 ) - break; - decode_hex(pubkeys[k],33,(char *)Notaries_genesis[k][1]); + n = (int32_t)(sizeof(Notaries_genesis)/sizeof(*Notaries_genesis)); + for (k=0; knHeight,&interest,tx,chainActive.Tip()->nTime); - + if ( interest != 0 ) + fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool view.SetBackend(dummy); } diff --git a/src/miner.cpp b/src/miner.cpp index 6a48da1a5..489ee701f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -439,12 +439,13 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // // Internal miner // -#define ROUNDROBIN_DELAY 44 +#define ROUNDROBIN_DELAY 30 extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE; extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33]; uint32_t Mining_start,Mining_height; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); +int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { @@ -589,10 +590,10 @@ void static BitcoinMiner(CWallet *pwallet) // // Search // - int32_t notaryid; uint32_t savebits; int64_t nStart = GetTime(); + uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); - if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_chosennotary(¬aryid,pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_is_special(pindexPrev->nHeight+1,NOTARY_PUBKEY33) > 0 ) { hashTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); Mining_start = (uint32_t)time(NULL); diff --git a/src/pow.cpp b/src/pow.cpp index 1b8ebe18c..9d0548347 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -105,7 +105,9 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param } int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33); +int32_t komodo_is_special(int32_t height,uint8_t pubkey33[33]); extern int32_t KOMODO_CHOSEN_ONE,CURRENT_HEIGHT; +extern int8_t Minerids[1024 * 1024 * 5]; // 5 million blocks bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params) { @@ -122,39 +124,22 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in { if ( pubkey33[i] != 0 ) nonz++; - //fprintf(stderr,"%02x",pubkey33[i]); } - //fprintf(stderr," height.%d special.%d nonz.%d\n",height,special,nonz); if ( nonz == 0 ) return(true); // will come back via different path with pubkey set - else if ( 0 ) + if ( notaryid >= 0 ) { - for (i=0; i<33; i++) - fprintf(stderr,"%02x",pubkey33[i]); - fprintf(stderr," special.%d notaryid.%d ht.%d mod.%d\n",special,notaryid,height,(height % 35)); - } - if ( special > 0 ) // special notary id == (height % numnotaries) - { - if (UintToArith256(hash) <= bnTarget) // accept normal diff - return true; - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - flag = 1; + if ( komodo_is_special(height,pubkey33) > 0 ) + { + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + flag = 1; + } } //else bnTarget /= 8; } - /*else if ( height == 0 && KOMODO_CHOSEN_ONE != 0 ) - { - extern uint8_t NOTARY_PUBKEY33[33]; - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - memcpy(pubkey33,NOTARY_PUBKEY33,33); - special = 1; - notaryid = -1; - printf("KOMODO_CHOSEN_ONE -> MINDIFF\n"); - }*/ - // Check range if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); // Check proof of work matches claimed amount - if (UintToArith256(hash) > bnTarget) + if ( UintToArith256(hash) > bnTarget ) { for (i=0; i<33; i++) printf("%02x",pubkey33[i]); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 881b5256f..15c5bb2eb 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -18,7 +18,7 @@ #include "utilmoneystr.h" #include "zcash/Note.hpp" #include "crypter.h" - +#include "coins.h" #include #include @@ -2402,9 +2402,12 @@ bool CWallet::SelectCoins(const CAmount& nTargetValue, setnHeight,out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); #ifdef KOMODO_ENABLE_INTEREST if ( ASSETCHAINS_SYMBOL[0] == 0 && txheight >= 60000 ) + { + printf("nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueRet/COIN,(double)interest/COIN,nHeight,tx.nLockTime,tiptime); nValueRet += interest; -#endif + } fprintf(stderr,"interest %llu from %llu lock.%u tip.%u\n",(long long)interest,(long long)out.tx->vout[out.i].nValue,out.tx->nLockTime,chainActive.Tip()->nTime); +#endif setCoinsRet.insert(make_pair(out.tx, out.i)); } return (nValueRet >= nTargetValue);