Merge pull request #717 from jl777/jl777
fixes for 100% PoS assetchains
This commit is contained in:
@@ -499,7 +499,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
#ifdef ENABLE_MINING
|
||||
strUsage += HelpMessageGroup(_("Mining options:"));
|
||||
strUsage += HelpMessageOpt("-gen", strprintf(_("Generate coins (default: %u)"), 0));
|
||||
strUsage += HelpMessageOpt("-genproclimit=<n>", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1));
|
||||
strUsage += HelpMessageOpt("-genproclimit=<n>", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 0));
|
||||
strUsage += HelpMessageOpt("-equihashsolver=<name>", _("Specify the Equihash solver to be used if enabled (default: \"default\")"));
|
||||
strUsage += HelpMessageOpt("-mineraddress=<addr>", _("Send mined coins to a specific single address"));
|
||||
strUsage += HelpMessageOpt("-minetolocalwallet", strprintf(
|
||||
@@ -1766,9 +1766,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
// Generate coins in the background
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain || !GetArg("-mineraddress", "").empty())
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0));
|
||||
#else
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 0));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1136,12 +1136,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh
|
||||
}
|
||||
if ( validateflag != 0 )
|
||||
{
|
||||
for (i=31; i>=24; i--)
|
||||
/*for (i=31; i>=24; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
|
||||
fprintf(stderr," vs target ");
|
||||
for (i=31; i>=24; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
||||
fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);
|
||||
fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1165,7 +1165,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
{
|
||||
CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val;
|
||||
*percPoSp = percPoS = 0;
|
||||
if ( height <= 10 )
|
||||
if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) )
|
||||
return(target);
|
||||
sum = arith_uint256(0);
|
||||
ave = sum;
|
||||
@@ -1181,22 +1181,25 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
hashval = UintToArith256(pindex->GetBlockHash());
|
||||
if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW
|
||||
{
|
||||
fprintf(stderr,"1");
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr,"1");
|
||||
sum += hashval;
|
||||
n++;
|
||||
}
|
||||
else
|
||||
{
|
||||
percPoS++;
|
||||
fprintf(stderr,"0");
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr,"0");
|
||||
}
|
||||
if ( (i % 10) == 9 )
|
||||
if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 )
|
||||
fprintf(stderr," %d, ",percPoS);
|
||||
}
|
||||
}
|
||||
if ( n < 100 )
|
||||
percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100;
|
||||
fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height);
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height);
|
||||
*percPoSp = percPoS;
|
||||
target = (target / arith_uint256(KOMODO_POWMINMULT));
|
||||
if ( n > 0 )
|
||||
@@ -1208,7 +1211,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
||||
if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget
|
||||
{
|
||||
bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc);
|
||||
if ( 1 )
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
{
|
||||
for (i=31; i>=24; i--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&ave)[i]);
|
||||
|
||||
@@ -920,9 +920,12 @@ void static BitcoinMiner()
|
||||
continue;
|
||||
}*/
|
||||
HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED);
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]);
|
||||
fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED);
|
||||
if ( ASSETCHAINS_STAKED < 100 )
|
||||
{
|
||||
for (z=31; z>=0; z--)
|
||||
fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]);
|
||||
fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED);
|
||||
}
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
@@ -1187,7 +1190,9 @@ void static BitcoinMiner()
|
||||
delete minerThreads;
|
||||
minerThreads = NULL;
|
||||
}
|
||||
|
||||
fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate);
|
||||
if ( nThreads == 0 )
|
||||
nThreads = 1;
|
||||
if (nThreads == 0 || !fGenerate)
|
||||
return;
|
||||
|
||||
|
||||
@@ -319,8 +319,8 @@ UniValue setgenerate(const UniValue& params, bool fHelp)
|
||||
if (params.size() > 1)
|
||||
{
|
||||
nGenProcLimit = params[1].get_int();
|
||||
if (nGenProcLimit == 0)
|
||||
fGenerate = false;
|
||||
//if (nGenProcLimit == 0)
|
||||
// fGenerate = false;
|
||||
}
|
||||
|
||||
mapArgs["-gen"] = (fGenerate ? "1" : "0");
|
||||
|
||||
@@ -383,7 +383,9 @@ static const CRPCCommand vRPCCommands[] =
|
||||
{ "wallet", "getaccount", &getaccount, true },
|
||||
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
|
||||
{ "wallet", "getbalance", &getbalance, false },
|
||||
{ "wallet", "getbalance64", &getbalance64, false },
|
||||
{ "wallet", "getnewaddress", &getnewaddress, true },
|
||||
// { "wallet", "getnewaddress64", &getnewaddress64, true },
|
||||
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true },
|
||||
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false },
|
||||
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false },
|
||||
|
||||
@@ -209,6 +209,7 @@ extern UniValue estimatefee(const UniValue& params, bool fHelp);
|
||||
extern UniValue estimatepriority(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue getaccountaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue setaccount(const UniValue& params, bool fHelp);
|
||||
@@ -220,6 +221,7 @@ extern UniValue verifymessage(const UniValue& params, bool fHelp);
|
||||
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue getbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue getbalance64(const UniValue& params, bool fHelp);
|
||||
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue movecmd(const UniValue& params, bool fHelp);
|
||||
extern UniValue sendfrom(const UniValue& params, bool fHelp);
|
||||
|
||||
@@ -152,9 +152,9 @@ void AsyncRPCOperation_mergetoaddress::main()
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
#ifdef ENABLE_WALLET
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0));
|
||||
#else
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 0));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -158,9 +158,9 @@ void AsyncRPCOperation_sendmany::main() {
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
#ifdef ENABLE_WALLET
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0));
|
||||
#else
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -137,9 +137,9 @@ void AsyncRPCOperation_shieldcoinbase::main() {
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
#ifdef ENABLE_WALLET
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0));
|
||||
#else
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ using namespace libzcash;
|
||||
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
extern UniValue TxJoinSplitToJSON(const CTransaction& tx);
|
||||
uint32_t komodo_segid32(char *coinaddr);
|
||||
|
||||
int64_t nWalletUnlockTime;
|
||||
static CCriticalSection cs_nWalletUnlockTime;
|
||||
@@ -4673,3 +4674,41 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
|
||||
} else fprintf(stderr,"no earliest utxo for staking\n");
|
||||
return(siglen);
|
||||
}
|
||||
|
||||
UniValue getbalance64(const UniValue& params, bool fHelp)
|
||||
{
|
||||
set<CBitcoinAddress> setAddress; vector<COutput> vecOutputs;
|
||||
UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address;
|
||||
const CKeyStore& keystore = *pwalletMain;
|
||||
CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid;
|
||||
assert(pwalletMain != NULL);
|
||||
if (fHelp || params.size() > 0)
|
||||
throw runtime_error("getbalance64\n");
|
||||
total = total2 = 0;
|
||||
memset(nValues,0,sizeof(nValues));
|
||||
memset(nValues2,0,sizeof(nValues2));
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
pwalletMain->AvailableCoins(vecOutputs, false, NULL, true);
|
||||
BOOST_FOREACH(const COutput& out, vecOutputs)
|
||||
{
|
||||
nValue = out.tx->vout[out.i].nValue;
|
||||
if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) )
|
||||
{
|
||||
segid = (komodo_segid32((char *)CBitcoinAddress(address).ToString().c_str()) & 0x3f);
|
||||
if ( out.nDepth < 100 )
|
||||
nValues2[segid] += nValue, total2 += nValue;
|
||||
else nValues[segid] += nValue, total += nValue;
|
||||
//fprintf(stderr,"%s %.8f depth.%d segid.%d\n",(char *)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,(int32_t)out.nDepth,segid);
|
||||
} else fprintf(stderr,"no destination\n");
|
||||
}
|
||||
ret.push_back(Pair("mature",(double)total/COIN));
|
||||
ret.push_back(Pair("immature",(double)total2/COIN));
|
||||
for (i=0; i<64; i++)
|
||||
{
|
||||
a.push_back((uint64_t)nValues[i]);
|
||||
b.push_back((uint64_t)nValues2[i]);
|
||||
}
|
||||
ret.push_back(Pair("staking", a));
|
||||
ret.push_back(Pair("notstaking", b));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void post_wallet_load(){
|
||||
#ifdef ENABLE_MINING
|
||||
// Generate coins in the background
|
||||
if (pwalletMain || !GetArg("-mineraddress", "").empty())
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1));
|
||||
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user