|
|
@ -151,7 +151,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ |
|
|
|
int64_t komodo_block_unlocktime(uint32_t nHeight); |
|
|
|
uint64_t komodo_commission(const CBlock *block,int32_t height); |
|
|
|
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); |
|
|
|
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); |
|
|
|
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33, void *ptr); |
|
|
|
int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); |
|
|
|
int32_t komodo_is_notarytx(const CTransaction& tx); |
|
|
|
CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); |
|
|
@ -580,51 +580,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 |
|
|
|
int32_t stakeHeight = chainActive.Height() + 1; |
|
|
|
|
|
|
|
//LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x stake.%i\n", nBlockSize,blocktime,pblock->nBits,isStake);
|
|
|
|
if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) |
|
|
|
{ |
|
|
|
LEAVE_CRITICAL_SECTION(cs_main); |
|
|
|
LEAVE_CRITICAL_SECTION(mempool.cs); |
|
|
|
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[512],*ptr; |
|
|
|
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), stakeHeight); |
|
|
|
|
|
|
|
if (ASSETCHAINS_LWMAPOS != 0) |
|
|
|
{ |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
blocktime = GetAdjustedTime(); |
|
|
|
//siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig);
|
|
|
|
// if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock.
|
|
|
|
// This has been moved from the mining loop to save CPU, and to also make ac_staked work
|
|
|
|
while ( blocktime-57 > GetAdjustedTime() ) |
|
|
|
{ |
|
|
|
sleep(1); |
|
|
|
if ( (rand() % 100) < 1 ) |
|
|
|
fprintf(stderr, "%u seconds until elegible, waiting.\n", blocktime-((uint32_t)GetAdjustedTime()+57)); |
|
|
|
if ( chainActive.LastTip()->GetHeight() >= stakeHeight ) |
|
|
|
{ |
|
|
|
fprintf(stderr, "Block Arrived, reset staking loop.\n"); |
|
|
|
return(0); |
|
|
|
} |
|
|
|
if( !GetBoolArg("-gen",false) ) |
|
|
|
return(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ( siglen > 0 ) |
|
|
|
{ |
|
|
|
CAmount txfees; |
|
|
|
|
|
|
|
txfees = 0; |
|
|
|
|
|
|
|
pblock->vtx.push_back(txStaked); |
|
|
|
pblocktemplate->vTxFees.push_back(txfees); |
|
|
|
pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); |
|
|
|
nFees += txfees; |
|
|
|
pblock->nTime = blocktime; |
|
|
|
//printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13)));
|
|
|
|
} else return(0); //fprintf(stderr,"no utxos eligible for staking\n");
|
|
|
|
} |
|
|
|
|
|
|
|
// Create coinbase tx
|
|
|
|
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); |
|
|
@ -646,16 +601,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 |
|
|
|
txNew.vout[0].nValue += 5000; |
|
|
|
pblock->vtx[0] = txNew; |
|
|
|
|
|
|
|
if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) |
|
|
|
{ |
|
|
|
char checkaddr[64]; |
|
|
|
Getscriptaddress(checkaddr,txNew.vout[0].scriptPubKey); |
|
|
|
//`fprintf(stderr,"set mining coinbase -> %s\n",checkaddr);
|
|
|
|
txNew.vout.resize(2); |
|
|
|
txNew.vout[1].nValue = 0; |
|
|
|
txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); |
|
|
|
} |
|
|
|
else if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) |
|
|
|
if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && (ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_FOUNDERS_REWARD != 0) && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) |
|
|
|
{ |
|
|
|
int32_t i; uint8_t *ptr; |
|
|
|
txNew.vout.resize(2); |
|
|
@ -756,7 +702,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 |
|
|
|
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); |
|
|
|
if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) |
|
|
|
{ |
|
|
|
uint32_t r; |
|
|
|
uint32_t r; CScript opret; void **ptr=0; |
|
|
|
|
|
|
|
CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); |
|
|
|
if ( pblock->nTime < pindexPrev->nTime+60 ) |
|
|
|
pblock->nTime = pindexPrev->nTime + 60; |
|
|
@ -770,7 +717,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 |
|
|
|
memcpy(&r,&randvals,sizeof(r)); |
|
|
|
pblock->nTime += (r % (33 - gpucount)*(33 - gpucount)); |
|
|
|
} |
|
|
|
if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) |
|
|
|
if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33,ptr) > 0 ) |
|
|
|
{ |
|
|
|
CAmount txfees = 5000; |
|
|
|
pblock->vtx.push_back(txNotary); |
|
|
@ -935,8 +882,6 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, |
|
|
|
scriptPubKey[34] = OP_CHECKSIG; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) |
|
|
|
scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); |
|
|
|
return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); |
|
|
|
} |
|
|
|
|
|
|
|