make notarypay work with KMD notaries
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
||||||
int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp);
|
int32_t komodo_electednotary(int32_t *numnotariesp,uint8_t *pubkey33,int32_t height,uint32_t timestamp);
|
||||||
|
int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp);
|
||||||
unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params);
|
unsigned int lwmaGetNextPOSRequired(const CBlockIndex* pindexLast, const Consensus::Params& params);
|
||||||
bool EnsureWalletIsAvailable(bool avoidException);
|
bool EnsureWalletIsAvailable(bool avoidException);
|
||||||
extern bool fRequestShutdown;
|
extern bool fRequestShutdown;
|
||||||
@@ -1825,8 +1826,6 @@ uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount)
|
|||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp);
|
|
||||||
|
|
||||||
int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len)
|
int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len)
|
||||||
{
|
{
|
||||||
// Check the notarisation is valid, and extract notarised height.
|
// Check the notarisation is valid, and extract notarised height.
|
||||||
@@ -1855,13 +1854,12 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notar
|
|||||||
{
|
{
|
||||||
// fetch notary pubkey array.
|
// fetch notary pubkey array.
|
||||||
uint64_t total = 0, AmountToPay = 0;
|
uint64_t total = 0, AmountToPay = 0;
|
||||||
int32_t staked_era; int8_t numSN;
|
int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0};
|
||||||
uint8_t staked_pubkeys[64][33];
|
numSN = komodo_notaries(notarypubkeys, height, timestamp);
|
||||||
staked_era = STAKED_era(timestamp);
|
|
||||||
// No point going further, no notaries can be paid.
|
// No point going further, no notaries can be paid.
|
||||||
if ( staked_era == 0 )
|
if ( notarypubkeys[0][0] == 0 )
|
||||||
return(0);
|
return(0);
|
||||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
|
||||||
|
|
||||||
// Check the notarisation is valid.
|
// Check the notarisation is valid.
|
||||||
int32_t notarizedheight = komodo_getnotarizedheight(timestamp, height, script, len);
|
int32_t notarizedheight = komodo_getnotarizedheight(timestamp, height, script, len);
|
||||||
@@ -1886,7 +1884,7 @@ uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &Notar
|
|||||||
ptr[0] = 33;
|
ptr[0] = 33;
|
||||||
for (int8_t i=0; i<33; i++)
|
for (int8_t i=0; i<33; i++)
|
||||||
{
|
{
|
||||||
ptr[i+1] = staked_pubkeys[NotarisationNotaries[n]][i];
|
ptr[i+1] = notarypubkeys[NotarisationNotaries[n]][i];
|
||||||
//fprintf(stderr,"%02x",ptr[i+1]);
|
//fprintf(stderr,"%02x",ptr[i+1]);
|
||||||
}
|
}
|
||||||
ptr[34] = OP_CHECKSIG;
|
ptr[34] = OP_CHECKSIG;
|
||||||
@@ -1901,13 +1899,12 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height)
|
|||||||
{
|
{
|
||||||
std::vector<int8_t> NotarisationNotaries;
|
std::vector<int8_t> NotarisationNotaries;
|
||||||
uint32_t timestamp = pblock->nTime;
|
uint32_t timestamp = pblock->nTime;
|
||||||
int32_t staked_era; int8_t numSN;
|
int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0};
|
||||||
uint8_t staked_pubkeys[64][33];
|
numSN = komodo_notaries(notarypubkeys, height, timestamp);
|
||||||
staked_era = STAKED_era(timestamp);
|
|
||||||
// No point going further, no notaries can be paid.
|
// No point going further, no notaries can be paid.
|
||||||
if ( staked_era == 0 )
|
if ( notarypubkeys[0][0] == 0 )
|
||||||
return(0);
|
return(0);
|
||||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
|
||||||
|
|
||||||
uint8_t *script; int32_t scriptlen;
|
uint8_t *script; int32_t scriptlen;
|
||||||
// Loop over the notarisation and extract the position of the participating notaries in the array of pukeys for this era.
|
// Loop over the notarisation and extract the position of the participating notaries in the array of pukeys for this era.
|
||||||
@@ -1920,7 +1917,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height)
|
|||||||
{
|
{
|
||||||
script = (uint8_t *)&tx1.vout[txin.prevout.n].scriptPubKey[0];
|
script = (uint8_t *)&tx1.vout[txin.prevout.n].scriptPubKey[0];
|
||||||
scriptlen = (int32_t)tx1.vout[txin.prevout.n].scriptPubKey.size();
|
scriptlen = (int32_t)tx1.vout[txin.prevout.n].scriptPubKey.size();
|
||||||
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,staked_pubkeys[i],33) == 0 )
|
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[i],33) == 0 )
|
||||||
NotarisationNotaries.push_back(i);
|
NotarisationNotaries.push_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1979,7 +1976,7 @@ uint64_t komodo_checknotarypay(CBlock *pblock,int32_t height)
|
|||||||
// Check the pubkeys match the pubkeys in the notarisation.
|
// Check the pubkeys match the pubkeys in the notarisation.
|
||||||
script = (uint8_t *)&txout.scriptPubKey[0];
|
script = (uint8_t *)&txout.scriptPubKey[0];
|
||||||
scriptlen = (int32_t)txout.scriptPubKey.size();
|
scriptlen = (int32_t)txout.scriptPubKey.size();
|
||||||
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,staked_pubkeys[NotarisationNotaries[n-1]],33) == 0 )
|
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[NotarisationNotaries[n-1]],33) == 0 )
|
||||||
{
|
{
|
||||||
// check the value is correct
|
// check the value is correct
|
||||||
if ( pblock->vtx[0].vout[n].nValue == AmountToPay )
|
if ( pblock->vtx[0].vout[n].nValue == AmountToPay )
|
||||||
@@ -2196,9 +2193,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
// Check min sigs.
|
// Check min sigs.
|
||||||
if ( pblock->vtx[1].vin.size() < (num_notaries_STAKED[STAKED_era(pblock->nTime)]/5) )
|
int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0};
|
||||||
|
numSN = komodo_notaries(notarypubkeys, height, pblock->nTime)
|
||||||
|
if ( pblock->vtx[1].vin.size() < numSN/5) )
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%li\n",height,(num_notaries_STAKED[STAKED_era(pblock->nTime)]/5),pblock->vtx[1].vin.size());
|
fprintf(stderr, "ht.%i does not meet minsigs.%i sigs.%li\n",height,numSN/5),pblock->vtx[1].vin.size());
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,9 +152,9 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex);
|
|||||||
int32_t komodo_is_notarytx(const CTransaction& tx);
|
int32_t komodo_is_notarytx(const CTransaction& tx);
|
||||||
CScript Marmara_scriptPubKey(int32_t height,CPubKey pk);
|
CScript Marmara_scriptPubKey(int32_t height,CPubKey pk);
|
||||||
CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk);
|
CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk);
|
||||||
int32_t komodo_is_notarytx(const CTransaction& tx);
|
|
||||||
uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len);
|
uint64_t komodo_notarypay(CMutableTransaction &txNew, std::vector<int8_t> &NotarisationNotaries, uint32_t timestamp, int32_t height, uint8_t *script, int32_t len);
|
||||||
int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len);
|
int32_t komodo_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len);
|
||||||
|
int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp);
|
||||||
|
|
||||||
CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake)
|
CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake)
|
||||||
{
|
{
|
||||||
@@ -248,15 +248,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pblock->nTime = GetAdjustedTime();
|
pblock->nTime = GetAdjustedTime();
|
||||||
// Now we have the block time, we can get the active notaries.
|
// Now we have the block time + height, we can get the active notaries.
|
||||||
int32_t staked_era = 0; int8_t numSN = 0;
|
int8_t numSN = 0; uint8_t notarypubkeys[64][33] = {0};
|
||||||
uint8_t staked_pubkeys[64][33] = {0};
|
if ( ASSETCHAINS_NOTARY_PAY[0] != 0 )
|
||||||
if ( is_STAKED(ASSETCHAINS_SYMBOL) < 3 )
|
|
||||||
{
|
{
|
||||||
// Only use speical miner for LABS chains in the actual cluster that use notarypay!
|
// Only use speical miner for notary pay chains.
|
||||||
// It wouldnt hurt to use it on other chains, but serves little purpose.
|
numSN = komodo_notaries(notarypubkeys, nHeight, pblock->nTime)
|
||||||
staked_era = STAKED_era(pblock->nTime);
|
|
||||||
numSN = numStakedNotaries(staked_pubkeys,staked_era);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CCoinsViewCache view(pcoinsTip);
|
CCoinsViewCache view(pcoinsTip);
|
||||||
@@ -268,7 +265,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
// Priority order to process transactions
|
// Priority order to process transactions
|
||||||
list<COrphan> vOrphan; // list memory doesn't move
|
list<COrphan> vOrphan; // list memory doesn't move
|
||||||
map<uint256, vector<COrphan*> > mapDependers;
|
map<uint256, vector<COrphan*> > mapDependers;
|
||||||
bool fPrintPriority = GetBoolArg("-printpriority", true);
|
bool fPrintPriority = GetBoolArg("-printpriority", false);
|
||||||
|
|
||||||
// This vector will be sorted into a priority queue:
|
// This vector will be sorted into a priority queue:
|
||||||
vector<TxPriority> vecPriority;
|
vector<TxPriority> vecPriority;
|
||||||
@@ -302,17 +299,16 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
CAmount nTotalIn = 0;
|
CAmount nTotalIn = 0;
|
||||||
bool fMissingInputs = false;
|
bool fMissingInputs = false;
|
||||||
bool fNotarisation = false;
|
bool fNotarisation = false;
|
||||||
std::vector<int8_t> TMP_NotarisationNotaries = {0};
|
std::vector<int8_t> TMP_NotarisationNotaries;
|
||||||
if (tx.IsCoinImport())
|
if (tx.IsCoinImport())
|
||||||
{
|
{
|
||||||
CAmount nValueIn = GetCoinImportValue(tx); // burn amount
|
CAmount nValueIn = GetCoinImportValue(tx); // burn amount
|
||||||
nTotalIn += nValueIn;
|
nTotalIn += nValueIn;
|
||||||
dPriority += (double)nValueIn * 1000; // flat multiplier... max = 1e16.
|
dPriority += (double)nValueIn * 1000; // flat multiplier... max = 1e16.
|
||||||
} else {
|
} else {
|
||||||
//int numNotaryVins = 0;
|
|
||||||
TMP_NotarisationNotaries.clear();
|
TMP_NotarisationNotaries.clear();
|
||||||
bool fToCryptoAddress = false;
|
bool fToCryptoAddress = false;
|
||||||
if ( numSN != 0 && staked_pubkeys[0][0] != 0 && komodo_is_notarytx(tx) == 1 )
|
if ( numSN != 0 && notarypubkeys[0][0] != 0 && komodo_is_notarytx(tx) == 1 )
|
||||||
fToCryptoAddress = true;
|
fToCryptoAddress = true;
|
||||||
|
|
||||||
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
BOOST_FOREACH(const CTxIn& txin, tx.vin)
|
||||||
@@ -361,7 +357,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
{
|
{
|
||||||
script = (uint8_t *)&tx1.vout[txin.prevout.n].scriptPubKey[0];
|
script = (uint8_t *)&tx1.vout[txin.prevout.n].scriptPubKey[0];
|
||||||
scriptlen = (int32_t)tx1.vout[txin.prevout.n].scriptPubKey.size();
|
scriptlen = (int32_t)tx1.vout[txin.prevout.n].scriptPubKey.size();
|
||||||
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,staked_pubkeys[i],33) == 0 )
|
if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[i],33) == 0 )
|
||||||
{
|
{
|
||||||
// We can add the index of each notary to vector, and clear it if this notarisation is not valid later on.
|
// We can add the index of each notary to vector, and clear it if this notarisation is not valid later on.
|
||||||
TMP_NotarisationNotaries.push_back(i);
|
TMP_NotarisationNotaries.push_back(i);
|
||||||
@@ -395,7 +391,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
|
|
||||||
if ( fNotarisation )
|
if ( fNotarisation )
|
||||||
{
|
{
|
||||||
// Special miner for notary pay chains.
|
// Special miner for notary pay chains. Can only enter this if numSN is set higher up.
|
||||||
if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 )
|
if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 )
|
||||||
{
|
{
|
||||||
// Get the OP_RETURN for the notarisation
|
// Get the OP_RETURN for the notarisation
|
||||||
@@ -458,7 +454,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32
|
|||||||
porphan->dPriority = dPriority;
|
porphan->dPriority = dPriority;
|
||||||
porphan->feeRate = feeRate;
|
porphan->feeRate = feeRate;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user