Test
This commit is contained in:
@@ -670,18 +670,31 @@ uint64_t komodo_commission(const CBlock &block)
|
|||||||
return((total * ASSETCHAINS_COMMISSION) / COIN);
|
return((total * ASSETCHAINS_COMMISSION) / COIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime)
|
uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime)
|
||||||
{
|
{
|
||||||
uint32_t txtime,minutes; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
|
CBlockIndex *pindex; arith_uint256 hashval; uint256 hash; int32_t i; uint32_t txtime,minutes,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
|
||||||
|
if ( nHeight < 200 )
|
||||||
|
return(blocktime);
|
||||||
txtime = komodo_txtime(&value,hash,n);
|
txtime = komodo_txtime(&value,hash,n);
|
||||||
minutes = (blocktime - txtime) / 60;
|
minutes = (blocktime - txtime) / 60;
|
||||||
if ( txtime == 0 )
|
if ( txtime == 0 )
|
||||||
txtime = prevtime;
|
txtime = prevtime;
|
||||||
coinage = value * (blocktime - txtime) / supply;
|
if ( (pindex= komodo_chainactive(nHeight-200)) != 0 )
|
||||||
fprintf(stderr,"coinage.%llu %d ht.%d txtime.%u blocktime.%u prev.%u gap.%d minutes.%d %.8f/%llu\n",(long long)coinage,(int32_t)(blocktime - txtime),nHeight,txtime,blocktime,prevtime,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply);
|
{
|
||||||
if ( nHeight < 200 )
|
coinage = value * (blocktime - txtime) / supply;
|
||||||
return(blocktime);
|
hash = pindex->GetBlockHash(); // hash pubkey
|
||||||
else return(0);
|
hashval = UintToArith256(hash);
|
||||||
|
hashval = (hashval / arith_uint256(coinage+1));
|
||||||
|
if ( hashval <= bnTarget )
|
||||||
|
winner = 1;
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
printf("%02x",((uint8_t *)&hashval)[i]);
|
||||||
|
printf(" vs ");
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
printf("%02x",((uint8_t *)&bnTarget)[i]);
|
||||||
|
fprintf(stderr," winner.%d %s coinage.%llu %d ht.%d gap.%d minutes.%d %.8f/%llu\n",winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),minutes,dstr(value),(long long)supply);
|
||||||
|
}
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing
|
int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing
|
||||||
@@ -756,13 +769,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim
|
|||||||
{
|
{
|
||||||
if ( ASSETCHAINS_STAKED != 0 )
|
if ( ASSETCHAINS_STAKED != 0 )
|
||||||
{
|
{
|
||||||
CBlockIndex *previndex; uint32_t eligible;
|
arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible;
|
||||||
if ( prevtime == 0 )
|
if ( prevtime == 0 )
|
||||||
{
|
{
|
||||||
if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 )
|
if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 )
|
||||||
prevtime = (uint32_t)previndex->nTime;
|
prevtime = (uint32_t)previndex->nTime;
|
||||||
}
|
}
|
||||||
eligible = komodo_stake(height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime);
|
bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
|
||||||
|
eligible = komodo_stake(height,bnTarget,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime);
|
||||||
if ( eligible > block.nTime )
|
if ( eligible > block.nTime )
|
||||||
fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime));
|
fprintf(stderr,"eligible.%u vs blocktime.%u, lag.%d\n",eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t
|
|||||||
int32_t komodo_isrealtime(int32_t *kmdheightp);
|
int32_t komodo_isrealtime(int32_t *kmdheightp);
|
||||||
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
|
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
|
||||||
uint64_t komodo_commission(const CBlock &block);
|
uint64_t komodo_commission(const CBlock &block);
|
||||||
int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
|
int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
||||||
{
|
{
|
||||||
@@ -385,7 +385,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
nLastBlockTx = nBlockTx;
|
nLastBlockTx = nBlockTx;
|
||||||
nLastBlockSize = nBlockSize;
|
nLastBlockSize = nBlockSize;
|
||||||
blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
blocktime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
|
||||||
LogPrintf("CreateNewBlock(): total size %u blocktime.%u\n", nBlockSize,blocktime);
|
pblock->nTime = blocktime;
|
||||||
|
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||||
|
LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits);
|
||||||
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 )
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 )
|
||||||
{
|
{
|
||||||
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr;
|
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr;
|
||||||
@@ -480,7 +482,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
|
|||||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||||
pblock->hashReserved = uint256();
|
pblock->hashReserved = uint256();
|
||||||
//UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
//UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
//pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
|
||||||
pblock->nSolution.clear();
|
pblock->nSolution.clear();
|
||||||
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
|
||||||
|
|
||||||
@@ -1033,7 +1035,8 @@ void static BitcoinMiner()
|
|||||||
// Update nNonce and nTime
|
// Update nNonce and nTime
|
||||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||||
pblock->nBits = savebits;
|
pblock->nBits = savebits;
|
||||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
if ( ASSETCHAINS_STAKED == 0 )
|
||||||
|
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||||
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks)
|
||||||
{
|
{
|
||||||
// Changing pblock->nTime can change work required on testnet:
|
// Changing pblock->nTime can change work required on testnet:
|
||||||
|
|||||||
@@ -4439,11 +4439,12 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp)
|
|||||||
#include "script/sign.h"
|
#include "script/sign.h"
|
||||||
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
||||||
extern std::string NOTARY_PUBKEY;
|
extern std::string NOTARY_PUBKEY;
|
||||||
uint32_t komodo_stake(int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime);
|
uint32_t komodo_stake(arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime);
|
||||||
|
|
||||||
int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig)
|
int32_t komodo_staked(uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig)
|
||||||
{
|
{
|
||||||
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey;
|
set<CBitcoinAddress> setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector<COutput> vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow;
|
||||||
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||||
assert(pwalletMain != NULL);
|
assert(pwalletMain != NULL);
|
||||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||||
*utxovaluep = 0;
|
*utxovaluep = 0;
|
||||||
@@ -4490,7 +4491,7 @@ int32_t komodo_staked(uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,
|
|||||||
uint64_t interest; uint32_t locktime; int32_t txheight;
|
uint64_t interest; uint32_t locktime; int32_t txheight;
|
||||||
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
|
if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 )
|
||||||
{
|
{
|
||||||
eligible = komodo_stake((uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime);
|
eligible = komodo_stake(bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,*blocktimep,(uint32_t)tipindex->nTime);
|
||||||
if ( eligible > 0 && eligible < earliest )
|
if ( eligible > 0 && eligible < earliest )
|
||||||
{
|
{
|
||||||
earliest = eligible;
|
earliest = eligible;
|
||||||
|
|||||||
Reference in New Issue
Block a user