Browse Source

Merge pull request #715 from jl777/jl777

Jl777
pull/4/head
jl777 6 years ago
committed by GitHub
parent
commit
9017c55676
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/komodo.h
  2. 6
      src/komodo_events.h
  3. 4
      src/komodo_globals.h
  4. 17
      src/komodo_utils.h
  5. 10
      src/main.cpp
  6. 38
      src/miner.cpp
  7. 2
      src/wallet/rpcwallet.cpp
  8. 10
      src/wallet/wallet.cpp

10
src/komodo.h

@ -538,7 +538,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
return(-1);
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
{
if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && NOTARY_PUBKEY33[0] != 0 )
if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && IS_KOMODO_NOTARY != 0 )
{
printf("%s KOMODO_LASTMINED.%d -> %d\n",ASSETCHAINS_SYMBOL,KOMODO_LASTMINED,height);
prevKOMODO_LASTMINED = KOMODO_LASTMINED;
@ -879,7 +879,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
notarized = 1;
}
if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("(tx.%d: ",i);
for (j=0; j<numvouts; j++)
{
@ -897,7 +897,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
}*/
if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("%.8f ",dstr(block.vtx[i].vout[j].nValue));
len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= sizeof(uint32_t) && len <= sizeof(scriptbuf) )
@ -916,7 +916,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
}
if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf(") ");
if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification);
@ -959,7 +959,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
}
}
}
if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 )
printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height);
if ( pindex->nHeight == hwmheight )
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0);

6
src/komodo_events.h

@ -41,14 +41,14 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig
{
static uint32_t counter; int32_t verified=0; char *coin; struct komodo_event_notarized N;
coin = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL;
if ( (ASSETCHAINS_SYMBOL[0] == 0 && height > 814000) && NOTARY_PUBKEY33[0] != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 )
if ( IS_KOMODO_NOTARY != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 )
{
if ( ASSETCHAINS_SYMBOL[0] == 0 && height > 814000 && counter++ < 10 )
if ( counter++ < 100 )
printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest);
}
else if ( strcmp(symbol,coin) == 0 )
{
if ( 0 && NOTARY_PUBKEY33[0] != 0 && verified != 0 )
if ( 0 && IS_KOMODO_NOTARY != 0 && verified != 0 )
fprintf(stderr,"validated [%s] ht.%d notarized %d\n",coin,height,notarizedheight);
memset(&N,0,sizeof(N));
N.blockhash = notarized_hash;

4
src/komodo_globals.h

@ -47,8 +47,8 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND;
int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33];
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC;
char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096];
uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT;

17
src/komodo_utils.h

@ -1502,14 +1502,26 @@ char *argv0names[] =
void komodo_args(char *argv0)
{
extern int64_t MAX_MONEY;
extern const char *Notaries_elected1[][2];
std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0;
IS_KOMODO_NOTARY = GetBoolArg("-notary", false);
if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 )
fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n");
DONATION_PUBKEY = GetArg("-donation", "");
NOTARY_PUBKEY = GetArg("-pubkey", "");
if ( strlen(NOTARY_PUBKEY.c_str()) == 66 )
{
USE_EXTERNAL_PUBKEY = 1;
if ( IS_KOMODO_NOTARY == 0 )
{
for (i=0; i<64; i++)
if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 )
{
IS_KOMODO_NOTARY = 1;
fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]);
break;
}
}
//KOMODO_PAX = 1;
} //else KOMODO_PAX = GetArg("-pax",0);
name = GetArg("-ac_name","");
@ -1528,6 +1540,7 @@ void komodo_args(char *argv0)
}
}
ASSETCHAINS_CC = GetArg("-ac_cc",0);
ASSETCHAINS_PUBLIC = GetArg("-ac_public",0);
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
{
printf("KOMODO_REWIND %d\n",KOMODO_REWIND);
@ -1566,7 +1579,7 @@ void komodo_args(char *argv0)
ASSETCHAINS_COMMISSION = 0;
printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n");
}
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 )
if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 )
{
fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]);
extraptr = extrabuf;
@ -1575,7 +1588,7 @@ void komodo_args(char *argv0)
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY);
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffffff) << 40);
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | (ASSETCHAINS_PUBLIC & 0xff);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val);
}
addn = GetArg("-seednode","");

10
src/main.cpp

@ -1109,6 +1109,11 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio
// Ensure that joinsplit values are well-formed
BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit)
{
if ( ASSETCHAINS_PUBLIC != 0 )
{
return state.DoS(100, error("CheckTransaction(): this is a public chain, no privacy allowed"),
REJECT_INVALID, "bad-txns-acprivacy-chain");
}
if (joinsplit.vpub_old < 0) {
return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_old negative"),
REJECT_INVALID, "bad-txns-vpub_old-negative");
@ -1737,6 +1742,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW)
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern uint32_t ASSETCHAINS_MAGIC;
extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY;
extern uint8_t ASSETCHAINS_PUBLIC;
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
@ -2952,7 +2958,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)",
block.vtx[0].GetValueOut(), blockReward),
REJECT_INVALID, "bad-cb-amount");
} else if ( NOTARY_PUBKEY33[0] != 0 )
} else if ( IS_KOMODO_NOTARY != 0 )
fprintf(stderr,"allow nHeight.%d coinbase %.8f vs %.8f interest %.8f\n",(int32_t)pindex->nHeight,dstr(block.vtx[0].GetValueOut()),dstr(blockReward),dstr(sum));
}
if (!control.Wait())
@ -6110,7 +6116,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
}
pfrom->PushMessage("headers", vHeaders);
}
/*else if ( NOTARY_PUBKEY33[0] != 0 )
/*else if ( IS_KOMODO_NOTARY != 0 )
{
static uint32_t counter;
if ( counter++ < 3 )

38
src/miner.cpp

@ -418,7 +418,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
//pblock->nTime = blocktime + 1;
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 && GetArg("-genproclimit", 0) == 0 )
{
uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr;
CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
@ -443,6 +443,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
txNew.vout.resize(1);
txNew.vout[0].scriptPubKey = scriptPubKeyIn;
txNew.vout[0].nValue = GetBlockSubsidy(nHeight,chainparams.GetConsensus());
if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 )
txNew.vout[0].nValue += 5000;
txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime());
txNew.nExpiryHeight = 0;
// Add fees
@ -475,14 +477,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
// Fill in header
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
pblock->hashReserved = uint256();
if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 )
if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || GetArg("-genproclimit", 0) > 0 )
{
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
}
pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && My_notaryid >= 0 )
if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 )
{
uint32_t r;
CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1);
@ -875,7 +877,7 @@ void static BitcoinMiner()
if ( i == 33 )
externalflag = 1;
else externalflag = 0;
if ( NOTARY_PUBKEY33[0] != 0 )
if ( IS_KOMODO_NOTARY != 0 )
{
for (i=1; i<66; i++)
if ( memcmp(pubkeys[i],pubkeys[0],33) == 0 )
@ -909,7 +911,7 @@ void static BitcoinMiner()
} //else fprintf(stderr,"duplicate at j.%d\n",j);
} else Mining_start = 0;
} else Mining_start = 0;
if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 )
if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 )
{
int32_t percPoS,z;
/*if ( Mining_height <= 100 )
@ -947,7 +949,7 @@ void static BitcoinMiner()
// (x_1, x_2, ...) = A(I, V, n, k)
LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString());
arith_uint256 hashTarget;
if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 )
if ( GetArg("-genproclimit", 0) > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 )
hashTarget = HASHTarget_POW;
else hashTarget = HASHTarget;
std::function<bool(std::vector<unsigned char>)> validBlock =
@ -975,7 +977,7 @@ void static BitcoinMiner()
fprintf(stderr," POW\n");*/
if ( h > hashTarget )
return false;
if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() )
if ( B.nTime > GetAdjustedTime() )
{
fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime()));
while ( GetAdjustedTime() < B.nTime-2 )
@ -990,7 +992,7 @@ void static BitcoinMiner()
}
if ( ASSETCHAINS_STAKED == 0 )
{
if ( NOTARY_PUBKEY33[0] != 0 )
if ( IS_KOMODO_NOTARY != 0 )
{
int32_t r;
if ( (r= ((Mining_height + NOTARY_PUBKEY33[16]) % 64) / 8) > 0 )
@ -999,18 +1001,12 @@ void static BitcoinMiner()
}
else
{
if ( NOTARY_PUBKEY33[0] != 0 )
{
while ( GetAdjustedTime() < B.nTime )
sleep(1);
}
else
{
uint256 tmp = B.GetHash();
int32_t z; for (z=31; z>=0; z--)
fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]);
fprintf(stderr," mined block!\n");
}
while ( GetAdjustedTime() < B.nTime )
sleep(1);
uint256 tmp = B.GetHash();
int32_t z; for (z=31; z>=0; z--)
fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]);
fprintf(stderr," mined block!\n");
}
CValidationState state;
if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false))
@ -1043,8 +1039,6 @@ void static BitcoinMiner()
ehSolverRuns.increment();
throw boost::thread_interrupted();
}
//if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 )
// sleep(1800);
return true;
};
std::function<bool(EhSolverCancelCheck)> cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) {

2
src/wallet/rpcwallet.cpp

@ -4652,7 +4652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i];
txNew.vin[0].prevout.hash = revtxid;
txNew.vin[0].prevout.n = *utxovoutp;
txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
txNew.vout[0].nValue = *utxovaluep - txfee;
txNew.nLockTime = earliest;
CTransaction txNewConst(txNew);

10
src/wallet/wallet.cpp

@ -43,6 +43,7 @@ bool fPayAtLeastCustomFee = true;
extern int32_t KOMODO_EXCHANGEWALLET;
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
extern std::string DONATION_PUBKEY;
/**
* Fees smaller than this (in satoshi) are considered zero fee (for transaction creation)
@ -2789,6 +2790,15 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
//fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN);
//interest = 0; // interest2 also
//}
if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 )
{
CScript scriptDonation = CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG;
CTxOut newTxOut(interest2,scriptDonation);
int32_t nDonationPosRet = txNew.vout.size() - 1; // dont change first or last
vector<CTxOut>::iterator position = txNew.vout.begin()+nDonationPosRet;
txNew.vout.insert(position, newTxOut);
interest2 = 0;
}
CAmount nChange = (nValueIn - nValue + interest2);
//fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN);
if (nSubtractFeeFromAmount == 0)

Loading…
Cancel
Save