Skip to content

Commit

Permalink
Merged absent commits from komodo-master 20-25 Apr 2018.
Browse files Browse the repository at this point in the history
  • Loading branch information
ip-gpu committed Apr 25, 2018
1 parent fad6da5 commit 3722101
Show file tree
Hide file tree
Showing 17 changed files with 681 additions and 652 deletions.
6 changes: 5 additions & 1 deletion src/cryptoconditions/src/cryptoconditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
#include "src/eval.c"
#include "src/json_rpc.c"
#include <cJSON.h>
#include <malloc.h>
#ifdef __LP64__
#include <stdlib.h>
#else
#include <malloc.h> // Index into CTransaction.vjoinsplit
#endif

struct CCType *CCTypeRegistry[] = {
&CC_PreimageType,
Expand Down
6 changes: 5 additions & 1 deletion src/cryptoconditions/src/json_rpc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "cryptoconditions.h"
#include "internal.h"
#include <cJSON.h>
#include <malloc.h>
#ifdef __LP64__
#include <stdlib.h>
#else
#include <malloc.h> // Index into CTransaction.vjoinsplit
#endif

static cJSON *jsonCondition(CC *cond) {
cJSON *root = cJSON_CreateObject();
Expand Down
520 changes: 3 additions & 517 deletions src/komodo_gateway.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/komodo_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct komodo_state KOMODO_STATES[34];
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,ASSETCHAINS_CC;
int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE=1,ASSETCHAINS_CC;
std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY;
uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33];

Expand Down
336 changes: 324 additions & 12 deletions src/komodo_komodod.h

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ r1cs_ppzksnark_keypair<ppT> r1cs_ppzksnark_generator(
template<typename ppT>
r1cs_ppzksnark_proof<ppT> r1cs_ppzksnark_prover(const r1cs_ppzksnark_proving_key<ppT> &pk,
const r1cs_ppzksnark_primary_input<ppT> &primary_input,
const r1cs_ppzksnark_auxiliary_input<ppT> &auxiliary_input,
const r1cs_ppzksnark_constraint_system<ppT> &constraint_system);
const r1cs_ppzksnark_auxiliary_input<ppT> &auxiliary_input);

template<typename ppT>
r1cs_ppzksnark_proof<ppT> r1cs_ppzksnark_prover_streaming(std::ifstream &proving_key_file,
Expand Down
371 changes: 279 additions & 92 deletions src/main.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals);
* @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location.
* @return True if state.IsValid()
*/
bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp);
bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp);
/** Check whether enough disk space is available for an incoming block */
bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
/** Open a block file (blk?????.dat) */
Expand Down Expand Up @@ -451,8 +451,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = false);

/** Context-independent validity checks */
bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state,
bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state,
libzcash::ProofVerifier& verifier,
bool fCheckPOW = true, bool fCheckMerkleRoot = true);

Expand All @@ -470,8 +470,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
* - The only caller of AcceptBlock verifies JoinSplit proofs elsewhere.
* If dbp is non-NULL, the file is known to already reside on disk
*/
bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp);
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);
bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp);
bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL);

/**
* When there are blocks in the active chain with missing data (e.g. if the
Expand Down
12 changes: 6 additions & 6 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int32_t komodo_is_issuer();
int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo);
int32_t komodo_isrealtime(int32_t *kmdheightp);
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(CMutableTransaction &txNew,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)
Expand Down Expand Up @@ -417,7 +417,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
#endif
LogPrintf("%d ",(int32_t)(pblock->nTime - GetAdjustedTime()));
}
//fprintf(stderr,"finished waiting\n");
//LogPrintf("finished waiting\n");
//sleep(pblock->nTime - GetAdjustedTime());
}

Expand Down Expand Up @@ -461,7 +461,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
}*/

pblock->vtx[0] = txNew;
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 )
if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock *)&pblocktemplate->block)) != 0 )
{
int32_t i; uint8_t *ptr;
txNew.vout.resize(2);
Expand Down Expand Up @@ -494,8 +494,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 )
{
pblock->nTime = pindexPrev->nTime + 60;
LogPrintf("block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 )
//LogPrintf("block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 )
#ifndef _WIN32
sleep(1);
#else
Expand Down Expand Up @@ -666,7 +666,7 @@ static bool ProcessBlockFound(CBlock* pblock)

// Process this block the same as if we had received it from another node
CValidationState state;
if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
return error("KomodoMiner: ProcessNewBlock, block not accepted");

TrackMinedBlock(pblock->GetHash());
Expand Down
4 changes: 4 additions & 0 deletions src/paymentdisclosure.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ struct PaymentDisclosurePayload {
uint8_t version; // 0 = experimental, 1 = first production version, etc.
uint256 esk; // zcash/NoteEncryption.cpp
uint256 txid; // primitives/transaction.h
#ifdef __LP64__
uint64_t js;
#else
size_t js; // Index into CTransaction.vjoinsplit
#endif
uint8_t n; // Index into JSDescription fields of length ZC_NUM_JS_OUTPUTS
libzcash::PaymentAddress zaddr; // zcash/Address.hpp
std::string message; // parameter to RPC call
Expand Down
14 changes: 7 additions & 7 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
if ( height == 0 )
{
height = komodo_currentheight() + 1;
//fprintf(stderr,"set height to %d\n",height);
//LogPrintf("set height to %d\n",height);
}
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
{
Expand All @@ -156,7 +156,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
}
if ( nonz == 0 )
{
//fprintf(stderr,"ht.%d null pubkey checkproof return\n",height);
//LogPrintf("ht.%d null pubkey checkproof return\n",height);
return(true); // will come back via different path with pubkey set
}
flag = komodo_eligiblenotary(pubkeys,mids,blocktimes,&nonzpkeys,height);
Expand All @@ -179,7 +179,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
}
if ( (flag != 0 || special2 > 0) && special2 != -2 )
{
//fprintf(stderr,"EASY MINING ht.%d\n",height);
//LogPrintf("EASY MINING ht.%d\n",height);
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
}
}
Expand Down Expand Up @@ -215,11 +215,11 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
}
}
/*for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&hash)[i]);
fprintf(stderr," hash vs ");
LogPrintf("%02x",((uint8_t *)&hash)[i]);
LogPrintf(" hash vs ");
for (i=31; i>=0; i--)
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
fprintf(stderr," height.%d notaryid.%d PoW valid\n",height,notaryid);*/
LogPrintf("%02x",((uint8_t *)&bnTarget)[i]);
LogPrintf(" height.%d notaryid.%d PoW valid\n",height,notaryid);*/
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/rpcmining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ UniValue generate(const UniValue& params, bool fHelp)
}
endloop:
CValidationState state;
if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL))
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
++nHeight;
blockHashes.push_back(pblock->GetHash().GetHex());
Expand Down Expand Up @@ -807,7 +807,7 @@ UniValue submitblock(const UniValue& params, bool fHelp)
CValidationState state;
submitblock_StateCatcher sc(block.GetHash());
RegisterValidationInterface(&sc);
bool fAccepted = ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL);
bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL);
UnregisterValidationInterface(&sc);
if (fBlockPresent)
{
Expand Down
4 changes: 4 additions & 0 deletions src/rpcmisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ UniValue jumblr_deposit(const UniValue& params, bool fHelp)
{
string addr = params[0].get_str();
if ( (retval= Jumblr_depositaddradd((char *)addr.c_str())) >= 0 )
{
result.push_back(Pair("result", retval));
JUMBLR_PAUSE = 0;
}
else result.push_back(Pair("error", retval));
} else result.push_back(Pair("error", "invalid address"));
return(result);
Expand All @@ -222,6 +225,7 @@ UniValue jumblr_secret(const UniValue& params, bool fHelp)
retval = Jumblr_secretaddradd((char *)addr.c_str());
result.push_back(Pair("result", "success"));
result.push_back(Pair("num", retval));
JUMBLR_PAUSE = 0;
} else result.push_back(Pair("error", "invalid address"));
return(result);
}
Expand Down
6 changes: 5 additions & 1 deletion src/wallet/asyncrpcoperation_mergetoaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,13 @@ UniValue AsyncRPCOperation_mergetoaddress::perform_joinsplit(
// Generate the proof, this can take over a minute.
boost::array<libzcash::JSInput, ZC_NUM_JS_INPUTS> inputs{info.vjsin[0], info.vjsin[1]};
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs{info.vjsout[0], info.vjsout[1]};
#ifdef __LP64__
boost::array<uint64_t, ZC_NUM_JS_INPUTS> inputMap;
boost::array<uint64_t, ZC_NUM_JS_OUTPUTS> outputMap;
#else
boost::array<size_t, ZC_NUM_JS_INPUTS> inputMap;
boost::array<size_t, ZC_NUM_JS_OUTPUTS> outputMap;

#endif
uint256 esk; // payment disclosure - secret

JSDescription jsdesc = JSDescription::Randomized(
Expand Down
5 changes: 5 additions & 0 deletions src/wallet/asyncrpcoperation_shieldcoinbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,13 @@ UniValue AsyncRPCOperation_shieldcoinbase::perform_joinsplit(ShieldCoinbaseJSInf
{info.vjsin[0], info.vjsin[1]};
boost::array<libzcash::JSOutput, ZC_NUM_JS_OUTPUTS> outputs
{info.vjsout[0], info.vjsout[1]};
#ifdef __LP64__
boost::array<uint64_t, ZC_NUM_JS_INPUTS> inputMap;
boost::array<uint64_t, ZC_NUM_JS_OUTPUTS> outputMap;
#else
boost::array<size_t, ZC_NUM_JS_INPUTS> inputMap;
boost::array<size_t, ZC_NUM_JS_OUTPUTS> outputMap;
#endif

uint256 esk; // payment disclosure - secret

Expand Down
28 changes: 24 additions & 4 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,7 +3959,11 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
CAmount shieldedValue = 0;
CAmount remainingValue = 0;
size_t estimatedTxSize = 2000; // 1802 joinsplit description + tx overhead + wiggle room
#ifdef __LP64__
uint64_t utxoCounter = 0;
#else
size_t utxoCounter = 0;
#endif
bool maxedOutFlag = false;
size_t mempoolLimit = (nLimit != 0) ? nLimit : (size_t)GetArg("-mempooltxinputlimit", 0);

Expand Down Expand Up @@ -4015,7 +4019,11 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp)
}
}

#ifdef __LP64__
uint64_t numUtxos = inputs.size();
#else
size_t numUtxos = inputs.size();
#endif

if (numUtxos == 0) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any coinbase funds to shield.");
Expand Down Expand Up @@ -4252,8 +4260,13 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
CAmount mergedNoteValue = 0;
CAmount remainingUTXOValue = 0;
CAmount remainingNoteValue = 0;
#ifdef __LP64__
uint64_t utxoCounter = 0;
uint64_t noteCounter = 0;
#else
size_t utxoCounter = 0;
size_t noteCounter = 0;
#endif
bool maxedOutUTXOsFlag = false;
bool maxedOutNotesFlag = false;
size_t mempoolLimit = (nUTXOLimit != 0) ? nUTXOLimit : (size_t)GetArg("-mempooltxinputlimit", 0);
Expand Down Expand Up @@ -4340,8 +4353,13 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
}
}

#ifdef __LP64__
uint64_t numUtxos = utxoInputs.size(); //ca333
uint64_t numNotes = noteInputs.size();
#else
size_t numUtxos = utxoInputs.size();
size_t numNotes = noteInputs.size();
#endif

if (numUtxos == 0 && numNotes == 0) {
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Could not find any funds to merge.");
Expand Down Expand Up @@ -4513,7 +4531,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
if ( eligible > 0 )
{
if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CKomodoAddress(address).ToString().c_str()) )
LogPrintf("validation of winning blocktime failed %u -> eligible.%u\n",*blocktimep,eligible);
{
//LogPrintf("validation of winning blocktime failed %u -> eligible.%u\n",*blocktimep,eligible);
}
else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) )
{
earliest = eligible;
Expand Down Expand Up @@ -4552,9 +4572,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
ptr = (uint8_t *)sigdata.scriptSig.data();
siglen = sigdata.scriptSig.size();
for (i=0; i<siglen; i++)
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]);
//fprintf(stderr," siglen.%d\n",siglen);
LogPrintf("best %u from %u, gap %d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep));
utxosig[i] = ptr[i];//, LogPrintf("%02x",ptr[i]);
//LogPrintf(" siglen.%d\n",siglen);
LogPrintf("best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
*blocktimep = earliest;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2915,7 +2915,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
}
else
{
//fprintf(stderr,"use notary pubkey\n");
//LogPrintf("use notary pubkey\n");
scriptChange = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG;
}
}
Expand Down

0 comments on commit 3722101

Please sign in to comment.