Merge branch 'FSM' of https://github.com/jl777/komodo into VHT
This commit is contained in:
117
src/miner.cpp
117
src/miner.cpp
@@ -18,6 +18,7 @@
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
#include "pubkey.h"
|
||||
#include "miner.h"
|
||||
#ifdef ENABLE_MINING
|
||||
#include "pow/tromp/equi_miner.h"
|
||||
@@ -141,7 +142,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],NOTARYADDRS[64][36];
|
||||
extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB;
|
||||
void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len);
|
||||
|
||||
extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],NUM_NOTARIES;
|
||||
extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],NUM_NOTARIES,ASSETCHAINS_MARMARA;
|
||||
uint32_t Mining_start,Mining_height;
|
||||
int32_t My_notaryid = -1;
|
||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
||||
@@ -156,19 +157,25 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits
|
||||
int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33);
|
||||
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);
|
||||
CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk);
|
||||
|
||||
CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake)
|
||||
CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake)
|
||||
{
|
||||
CScript scriptPubKeyIn(_scriptPubKeyIn);
|
||||
|
||||
CPubKey pk = CPubKey();
|
||||
std::vector<std::vector<unsigned char>> vAddrs;
|
||||
txnouttype txT;
|
||||
if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs))
|
||||
CPubKey pk;
|
||||
if ( _pk.size() != 33 )
|
||||
{
|
||||
if (txT == TX_PUBKEY)
|
||||
pk = CPubKey(vAddrs[0]);
|
||||
}
|
||||
pk = CPubKey();
|
||||
std::vector<std::vector<unsigned char>> vAddrs;
|
||||
txnouttype txT;
|
||||
if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs))
|
||||
{
|
||||
if (txT == TX_PUBKEY)
|
||||
pk = CPubKey(vAddrs[0]);
|
||||
}
|
||||
} else pk = _pk;
|
||||
|
||||
uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params();
|
||||
//fprintf(stderr,"create new block\n");
|
||||
@@ -556,36 +563,17 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 )
|
||||
txNew.vout[0].nValue += 5000;
|
||||
pblock->vtx[0] = txNew;
|
||||
|
||||
//fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0);
|
||||
// check if coinbase transactions must be time locked at current subsidy and prepend the time lock
|
||||
// to transaction if so, cast for GTE operator
|
||||
if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE)
|
||||
if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 )
|
||||
{
|
||||
int32_t opretlen, p2shlen, scriptlen;
|
||||
CScriptExt opretScript = CScriptExt();
|
||||
|
||||
txNew.vout.resize(2);
|
||||
|
||||
// prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins
|
||||
// protected only by the time lock rather than 100% inaccessible
|
||||
opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight));
|
||||
if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition())
|
||||
{
|
||||
fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n");
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
|
||||
{
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
LEAVE_CRITICAL_SECTION(mempool.cs);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
opretScript += scriptPubKeyIn;
|
||||
|
||||
txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript));
|
||||
txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK);
|
||||
txNew.vout[1].nValue = 0;
|
||||
} // timelocks and commissions are currently incompatible due to validation complexity of the combination
|
||||
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 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 )
|
||||
{
|
||||
int32_t i; uint8_t *ptr;
|
||||
@@ -593,6 +581,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
txNew.vout[1].nValue = commission;
|
||||
if ( ASSETCHAINS_SCRIPTPUB.size() > 1 )
|
||||
{
|
||||
//fprintf(stderr,"mine to -ac_script\n");
|
||||
//txNew.vout[1].scriptPubKey = CScript() << ParseHex();
|
||||
int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str());
|
||||
len >>= 1;
|
||||
@@ -606,11 +595,42 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount,
|
||||
ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0];
|
||||
ptr[0] = 33;
|
||||
for (i=0; i<33; i++)
|
||||
{
|
||||
ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i];
|
||||
//fprintf(stderr,"%02x",ptr[i+1]);
|
||||
}
|
||||
ptr[34] = OP_CHECKSIG;
|
||||
//fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n");
|
||||
}
|
||||
//printf("autocreate commision vout\n");
|
||||
}
|
||||
else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE)
|
||||
{
|
||||
int32_t opretlen, p2shlen, scriptlen;
|
||||
CScriptExt opretScript = CScriptExt();
|
||||
|
||||
txNew.vout.resize(2);
|
||||
|
||||
// prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins
|
||||
// protected only by the time lock rather than 100% inaccessible
|
||||
opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight));
|
||||
if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition())
|
||||
{
|
||||
fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n");
|
||||
if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_SYMBOL[0] != 0 && !isStake) )
|
||||
{
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
LEAVE_CRITICAL_SECTION(mempool.cs);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
opretScript += scriptPubKeyIn;
|
||||
|
||||
txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript));
|
||||
txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK);
|
||||
txNew.vout[1].nValue = 0;
|
||||
} // timelocks and commissions are currently incompatible due to validation complexity of the combination
|
||||
|
||||
pblock->vtx[0] = txNew;
|
||||
pblocktemplate->vTxFees[0] = -nFees;
|
||||
@@ -778,7 +798,10 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
|
||||
if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 )
|
||||
{
|
||||
if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 )
|
||||
scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG;
|
||||
{
|
||||
pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY);
|
||||
scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = strlen(ASSETCHAINS_SCRIPTPUB.c_str());
|
||||
@@ -791,8 +814,10 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
|
||||
else if ( USE_EXTERNAL_PUBKEY != 0 )
|
||||
{
|
||||
//fprintf(stderr,"use notary pubkey\n");
|
||||
scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
|
||||
} else
|
||||
pubkey = ParseHex(NOTARY_PUBKEY);
|
||||
scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if ( !isStake || ASSETCHAINS_STAKED != 0 )
|
||||
{
|
||||
@@ -809,7 +834,11 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight,
|
||||
scriptPubKey[34] = OP_CHECKSIG;
|
||||
}
|
||||
}
|
||||
return CreateNewBlock(scriptPubKey, gpucount, isStake);
|
||||
if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 )
|
||||
scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey);
|
||||
if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 )
|
||||
isStake = true;
|
||||
return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake);
|
||||
}
|
||||
|
||||
void komodo_broadcast(CBlock *pblock,int32_t limit)
|
||||
@@ -1205,14 +1234,14 @@ void static BitcoinMiner_noeq()
|
||||
miningTimer.start();
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0);
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0);
|
||||
#else
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey();
|
||||
#endif
|
||||
if ( ptr == 0 )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 100 )
|
||||
if ( counter++ < 10 )
|
||||
fprintf(stderr,"created illegal block, retry\n");
|
||||
continue;
|
||||
}
|
||||
@@ -1500,15 +1529,15 @@ void static BitcoinMiner()
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
// notaries always default to staking
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0);
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0);
|
||||
#else
|
||||
CBlockTemplate *ptr = CreateNewBlockWithKey();
|
||||
#endif
|
||||
if ( ptr == 0 )
|
||||
{
|
||||
static uint32_t counter;
|
||||
if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
|
||||
fprintf(stderr,"created illegal block, retry\n");
|
||||
if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 )
|
||||
fprintf(stderr,"created illegal blockB, retry\n");
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
@@ -1912,12 +1941,12 @@ void static BitcoinMiner()
|
||||
for (int i = 0; i < nThreads; i++) {
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) )
|
||||
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
|
||||
else
|
||||
minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet));
|
||||
#else
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH)
|
||||
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) )
|
||||
minerThreads->create_thread(&BitcoinMiner);
|
||||
else
|
||||
minerThreads->create_thread(&BitcoinMiner_noeq);
|
||||
|
||||
Reference in New Issue
Block a user