diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5564a79a5..56213206e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) + if ( txheight > 246748 ) { - if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { @@ -1198,7 +1198,7 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,segid32,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { @@ -1221,13 +1221,16 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; - vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + komodo_segids(hashbuf,nHeight-101,100); + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + segid = ((nHeight + segid32) & 0x3f); + /*vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); komodo_segids(hashbuf,nHeight-101,100); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout));*/ for (iter=0; iter<180; iter++) { if ( blocktime+iter+segid*2 < txtime+minage ) @@ -1243,12 +1246,14 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( iter > 0 ) diff += segid*2; coinage = (value * diff); - if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); + if ( blocktime+iter+segid*2 > prevtime+480 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); + //if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + // coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - if ( nHeight >= 900 && nHeight < 916 ) - hashval = (hashval / coinage256); + //if ( nHeight >= 900 && nHeight < 916 ) + // hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { winner = 1; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 47fbeec30..4c4d2eed5 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -32,6 +32,8 @@ using namespace std; +extern uint64_t ASSETCHAINS_STAKED; +arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); /** * Return average network hashes per second based on the last 'lookup' blocks, @@ -727,7 +729,15 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); } result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); - result.push_back(Pair("target", hashTarget.GetHex())); + if ( ASSETCHAINS_STAKED != 0 ) + { + arith_uint256 POWtarget; int32_t PoSperc; + POWtarget = komodo_PoWtarget(&PoSperc,hashTarget,(int32_t)(pindexPrev->nHeight+1),ASSETCHAINS_STAKED); + result.push_back(Pair("target", POWtarget.GetHex())); + result.push_back(Pair("PoSperc", (int64_t)PoSperc)); + result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED)); + result.push_back(Pair("origtarget", hashTarget.GetHex())); + } else result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff")); diff --git a/src/txdb.cpp b/src/txdb.cpp index cb0358403..af6cd0fbf 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,36 +402,36 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr extern UniValue CBlockTreeDB::Snapshot() { char chType; int64_t total = 0; int64_t totalAddresses = 0; std::string address; - boost::scoped_ptr pcursor(NewIterator()); + boost::scoped_ptr iter(NewIterator()); std::map addressAmounts; UniValue result(UniValue::VOBJ); result.push_back(Pair("start_time", time(NULL))); - //pcursor->SeekToFirst(); - pcursor->SeekToLast(); - int64_t startingHeight = chainActive.Height(); - - while (pcursor->Valid()) + fprintf(stderr, "Starting snapshot at height %li\n", startingHeight); + for (iter->SeekToLast(); iter->Valid(); iter->Prev()) { boost::this_thread::interruption_point(); try { - leveldb::Slice slKey = pcursor->key(); + leveldb::Slice slKey = iter->key(); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); CAddressIndexIteratorKey indexKey; - ssKey >> chType; - ssKey >> indexKey; - if ( chType == DB_ADDRESSUNSPENTINDEX ) + ssKey >> chType; + ssKey >> indexKey; + + //fprintf(stderr, "chType=%d\n", chType); + if (chType == DB_ADDRESSUNSPENTINDEX) { try { - leveldb::Slice slValue = pcursor->value(); + leveldb::Slice slValue = iter->value(); CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); + std::map ::iterator pos = addressAmounts.find(address); if (pos == addressAmounts.end()) { // insert new address + utxo amount @@ -440,20 +440,21 @@ extern UniValue CBlockTreeDB::Snapshot() totalAddresses++; } else { // update unspent tally for this address + //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); addressAmounts[address] += nValue; } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); total += nValue; + } catch (const std::exception& e) { - return error("failed to get address index value"); + fprintf(stderr, "DONE %s: LevelDB addressindex exception! - %s\n", __func__, e.what()); + break; } - } else { break; } + } } catch (const std::exception& e) { - fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); + fprintf(stderr, "DONE reading index entries\n"); break; } - pcursor->Prev(); } UniValue addresses(UniValue::VARR); @@ -477,9 +478,11 @@ extern UniValue CBlockTreeDB::Snapshot() addressesSorted.push_back(obj); } - result.push_back(make_pair("addresses", addressesSorted)); - result.push_back(make_pair("total", total / COIN )); - result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + if (totalAddresses > 0) { + result.push_back(make_pair("addresses", addressesSorted)); + result.push_back(make_pair("total", total / COIN )); + result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + } // Total number of addresses in this snaphot result.push_back(make_pair("total_addresses", totalAddresses)); // The snapshot began at this block height diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02cea5bef..176491b8b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4636,12 +4636,14 @@ arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uin if ( iter > 0 ) diff += segid*2; coinage = ((uint64_t)kp->nValue/COIN * diff); - if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); + if ( blocktime+iter+segid*2 > prevtime+480 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); + //if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + // coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (kp->hashval / coinage256); - if ( nHeight >= 900 && nHeight < 916 ) - hashval = (hashval / coinage256); + //if ( nHeight >= 900 && nHeight < 916 ) + // hashval = (hashval / coinage256); return(hashval); }