From c9a943a86ef59bca5679c580d6eb911ad94fae0a Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 10 Jun 2019 10:50:23 +0000 Subject: [PATCH 1/6] add oracles, faucet to DICE; add tokens to COQUI --- src/komodo_utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 93d4f245e..08e821318 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2313,6 +2313,8 @@ void komodo_args(char *argv0) ASSETCHAINS_CCDISABLES[230] = 0; // DICE ASSETCHAINS_CCDISABLES[235] = 0; // CHANNELS ASSETCHAINS_CCDISABLES[236] = 0; // ORACLES + ASSETCHAINS_CCDISABLES[227] = 0; // ASSETS + ASSETCHAINS_CCDISABLES[242] = 0; // TOKENS } if ( strcmp("DION",ASSETCHAINS_SYMBOL) == 0 ) { @@ -2348,7 +2350,9 @@ void komodo_args(char *argv0) if ( strcmp("KMDICE",ASSETCHAINS_SYMBOL) == 0 ) { memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + ASSETCHAINS_CCDISABLES[228] = 0; // FAUCET ASSETCHAINS_CCDISABLES[230] = 0; // DICE + ASSETCHAINS_CCDISABLES[236] = 0; // ORACLES } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); From ce6acf0d00f14b99991bf6bc0969187f62e5eb41 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 10 Jun 2019 20:51:52 +0800 Subject: [PATCH 2/6] Change ccEnable/Disable to macro --- src/cc/CCinclude.h | 2 ++ src/komodo_utils.h | 47 +++++++++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 3681cf2f3..d9f08f624 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -59,6 +59,8 @@ one other technical note is that komodod has the insight-explorer extensions bui #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) +#define CCDISABLE memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)) +#define CCENABLE 0 #ifndef _BITS256 #define _BITS256 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 08e821318..36bbb42fb 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -14,6 +14,7 @@ ******************************************************************************/ #include "komodo_defs.h" #include "key_io.h" +#include "cc/CCinclude.h" #include #ifdef _WIN32 @@ -2299,60 +2300,60 @@ void komodo_args(char *argv0) // Set cc enables for all existing ac_cc chains here. if ( strcmp("AXO",ASSETCHAINS_SYMBOL) == 0 ) { - // No CCs used on this chain yet please ask AXO777 what he needs. - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + // No CCs used on this chain yet. + CCDISABLE; } if ( strcmp("CCL",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + CCDISABLE; } if ( strcmp("COQUI",ASSETCHAINS_SYMBOL) == 0 ) { - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); - ASSETCHAINS_CCDISABLES[230] = 0; // DICE - ASSETCHAINS_CCDISABLES[235] = 0; // CHANNELS - ASSETCHAINS_CCDISABLES[236] = 0; // ORACLES - ASSETCHAINS_CCDISABLES[227] = 0; // ASSETS - ASSETCHAINS_CCDISABLES[242] = 0; // TOKENS + CCDISABLE; + ASSETCHAINS_CCDISABLES[230] = CCENABLE;; // DICE + ASSETCHAINS_CCDISABLES[235] = CCENABLE;; // CHANNELS + ASSETCHAINS_CCDISABLES[236] = CCENABLE;; // ORACLES + ASSETCHAINS_CCDISABLES[227] = CCENABLE;; // ASSETS + ASSETCHAINS_CCDISABLES[242] = CCENABLE;; // TOKENS } if ( strcmp("DION",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + CCDISABLE; } if ( strcmp("EQL",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + CCDISABLE; } if ( strcmp("ILN",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); + CCDISABLE; } if ( strcmp("MORTY",ASSETCHAINS_SYMBOL) == 0 ) { - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); - ASSETCHAINS_CCDISABLES[228] = 0; // FAUCET + CCDISABLE; + ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET } if ( strcmp("RICK",ASSETCHAINS_SYMBOL) == 0 ) { - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); - ASSETCHAINS_CCDISABLES[228] = 1; // FAUCET + CCDISABLE; + ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET } if ( strcmp("SEC",ASSETCHAINS_SYMBOL) == 0 ) { - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); - ASSETCHAINS_CCDISABLES[227] = 0; // ASSETS - ASSETCHAINS_CCDISABLES[242] = 0; // TOKENS + CCDISABLE; + ASSETCHAINS_CCDISABLES[227] = CCENABLE;; // ASSETS + ASSETCHAINS_CCDISABLES[242] = CCENABLE;; // TOKENS } if ( strcmp("KMDICE",ASSETCHAINS_SYMBOL) == 0 ) { - memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)); - ASSETCHAINS_CCDISABLES[228] = 0; // FAUCET - ASSETCHAINS_CCDISABLES[230] = 0; // DICE - ASSETCHAINS_CCDISABLES[236] = 0; // ORACLES + CCDISABLE; + ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET + ASSETCHAINS_CCDISABLES[230] = CCENABLE;; // DICE + ASSETCHAINS_CCDISABLES[236] = CCENABLE;; // ORACLES } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); From fd23e3a914d09d2a6dbdc9997fc84945a96b9712 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 10 Jun 2019 23:30:13 +0800 Subject: [PATCH 3/6] add -ac_ccactivateht=. Fix oracles timestamp activation, to stop loading block from disk for no reason. --- src/cc/eval.cpp | 9 +++++++-- src/cc/oracles.cpp | 7 +------ src/komodo_defs.h | 2 ++ src/komodo_globals.h | 2 ++ src/komodo_utils.h | 23 ++++++++++++++++++++++- src/wallet/rpcwallet.cpp | 9 +++++++-- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index a23a7b16c..c580753cf 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -78,8 +78,13 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) uint8_t ecode = cond->code[0]; if ( ASSETCHAINS_CCDISABLES[ecode] != 0 ) { - fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); - return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + // check if a height activation has been set. + if ( mapHeightEvalActivate[ecode] == 0 || this->GetCurrentHeight() == 0 || mapHeightEvalActivate[ecode] > this->GetCurrentHeight() ) + { + fprintf(stderr,"%s evalcode.%d %02x\n",txTo.GetHash().GetHex().c_str(),ecode,ecode); + fprintf(stderr, "ac_ccactivateht: evalcode.%i activates at height.%i vs current height.%i\n", ecode, mapHeightEvalActivate[ecode], this->GetCurrentHeight()); + return Invalid("disabled-code, -ac_ccenables didnt include this ecode"); + } } std::vector vparams(cond->code+1, cond->code+cond->codeLength); if ( ecode >= EVAL_FIRSTUSER && ecode <= EVAL_LASTUSER ) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index f019ae271..193f66a1a 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -642,11 +642,7 @@ int32_t GetLatestTimestamp(int32_t height) blockHash = chainActive[height]->GetBlockHash(); pindex = mapBlockIndex[blockHash]; - if ( komodo_blockload(block,pindex) == 0 ) - { - return(block.nTime); - } - return(0); + return(pindex->nTime); } bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) @@ -1208,4 +1204,3 @@ UniValue OraclesList() } return(result); } - diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 36e26a310..226600d6f 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -303,6 +303,7 @@ extern int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; extern int32_t ASSETCHAINS_EARLYTXIDCONTRACT; int tx_height( const uint256 &hash ); extern std::vector vWhiteListAddress; +extern std::map mapHeightEvalActivate; void komodo_netevent(std::vector payload); int32_t getacseason(uint32_t timestamp); @@ -333,6 +334,7 @@ uint32_t komodo_heightstamp(int32_t height); int64_t komodo_pricemult(int32_t ind); int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks); uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); +int32_t komodo_currentheight(); #endif diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 9d6d97100..d8e292431 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -115,6 +115,8 @@ int32_t KOMODO_TESTNODE, KOMODO_SNAPSHOT_INTERVAL; CScript KOMODO_EARLYTXID_SCRIPTPUB; int32_t ASSETCHAINS_EARLYTXIDCONTRACT; +std::map mapHeightEvalActivate; + struct komodo_kv *KOMODO_KV; pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 36bbb42fb..4bcd9d7da 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1692,7 +1692,7 @@ int8_t equihash_params_possible(uint64_t n, uint64_t k) void komodo_args(char *argv0) { - std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; + std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[32756],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256], ccEnablesHeight[512]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); memset(ccenables,0,sizeof(ccenables)); @@ -1757,6 +1757,27 @@ void komodo_args(char *argv0) ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); KOMODO_SNAPSHOT_INTERVAL = GetArg("-ac_snapshot",0); Split(GetArg("-ac_nk",""), ASSETCHAINS_NK, 0); + + // -ac_ccactivateht=evalcode,height,evalcode,height,evalcode,height.... + Split(GetArg("-ac_ccactivateht",""), ccEnablesHeight, 0); + // fill map with all eval codes and activation height of 0. + for ( int i = 0; i < 256; i++ ) + mapHeightEvalActivate[i] = 0; + for ( int i = 0; i < 512; i++ ) + { + int32_t ecode = ccEnablesHeight[i]; + int32_t ht = ccEnablesHeight[i+1]; + if ( ecode > 256 ) + fprintf(stderr, "ac_ccactivateht: invalid evalcode.%i must be between 0 and 256.\n", ecode); + else if ( ht > 0 ) + { + // update global map. + mapHeightEvalActivate[ecode] = ht; + fprintf(stderr, "ac_ccactivateht: ecode.%i activates at height.%i\n", ecode, mapHeightEvalActivate[ecode]); + } + i++; + } + if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa5876e23..bf861662f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5342,8 +5342,13 @@ int32_t ensure_CCrequirements(uint8_t evalcode) CCerror = ""; if ( ASSETCHAINS_CCDISABLES[evalcode] != 0 || (evalcode == EVAL_MARMARA && ASSETCHAINS_MARMARA == 0) ) { - fprintf(stderr,"evalcode %d disabled\n",evalcode); - return(-1); + // check if a height activation has been set. + fprintf(stderr, "evalcode.%i activates at height. %i current height.%i\n", evalcode, mapHeightEvalActivate[evalcode], komodo_currentheight()); + if ( mapHeightEvalActivate[evalcode] == 0 || komodo_currentheight() == 0 || mapHeightEvalActivate[evalcode] > komodo_currentheight() ) + { + fprintf(stderr,"evalcode %d disabled\n",evalcode); + return(-1); + } } if ( NOTARY_PUBKEY33[0] == 0 ) { From cab05f7f01889b93aa23d05475b78dc1fde0725d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 10 Jun 2019 23:53:11 +0800 Subject: [PATCH 4/6] fix --- src/cc/CCinclude.h | 4 ++-- src/komodo_utils.h | 50 ++++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index d9f08f624..1d8cf669e 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -59,8 +59,8 @@ one other technical note is that komodod has the insight-explorer extensions bui #define SMALLVAL 0.000000000000001 #define SATOSHIDEN ((uint64_t)100000000L) #define dstr(x) ((double)(x) / SATOSHIDEN) -#define CCDISABLE memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)) -#define CCENABLE 0 +#define CCDISABLEALL memset(ASSETCHAINS_CCDISABLES,1,sizeof(ASSETCHAINS_CCDISABLES)) +#define CCENABLE(x) ASSETCHAINS_CCDISABLES[((uint8_t)x)] = 0 #ifndef _BITS256 #define _BITS256 diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 4bcd9d7da..94ac60515 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2322,59 +2322,61 @@ void komodo_args(char *argv0) if ( strcmp("AXO",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLE; + CCDISABLEALL; } if ( strcmp("CCL",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLE; + CCDISABLEALL; } if ( strcmp("COQUI",ASSETCHAINS_SYMBOL) == 0 ) { - CCDISABLE; - ASSETCHAINS_CCDISABLES[230] = CCENABLE;; // DICE - ASSETCHAINS_CCDISABLES[235] = CCENABLE;; // CHANNELS - ASSETCHAINS_CCDISABLES[236] = CCENABLE;; // ORACLES - ASSETCHAINS_CCDISABLES[227] = CCENABLE;; // ASSETS - ASSETCHAINS_CCDISABLES[242] = CCENABLE;; // TOKENS + CCDISABLEALL; + CCENABLE(EVAL_DICE); + CCENABLE(EVAL_CHANNELS); + CCENABLE(EVAL_ORACLES); + CCENABLE(EVAL_ASSETS); + CCENABLE(EVAL_TOKENS); } if ( strcmp("DION",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLE; + CCDISABLEALL; } + if ( strcmp("EQL",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLE; + CCDISABLEALL; } if ( strcmp("ILN",ASSETCHAINS_SYMBOL) == 0 ) { // No CCs used on this chain yet. - CCDISABLE; + CCDISABLEALL; } - if ( strcmp("MORTY",ASSETCHAINS_SYMBOL) == 0 ) + if ( strcmp("OUR",ASSETCHAINS_SYMBOL) == 0 ) { - CCDISABLE; - ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET + // No CCs used on this chain yet. + CCDISABLEALL; } - if ( strcmp("RICK",ASSETCHAINS_SYMBOL) == 0 ) + if ( strcmp("ZEXO",ASSETCHAINS_SYMBOL) == 0 ) { - CCDISABLE; - ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET + // No CCs used on this chain yet. + CCDISABLEALL; } if ( strcmp("SEC",ASSETCHAINS_SYMBOL) == 0 ) { - CCDISABLE; - ASSETCHAINS_CCDISABLES[227] = CCENABLE;; // ASSETS - ASSETCHAINS_CCDISABLES[242] = CCENABLE;; // TOKENS + CCDISABLEALL; + CCENABLE(EVAL_ASSETS); + CCENABLE(EVAL_TOKENS); + CCENABLE(EVAL_ORACLES); } if ( strcmp("KMDICE",ASSETCHAINS_SYMBOL) == 0 ) { - CCDISABLE; - ASSETCHAINS_CCDISABLES[228] = CCENABLE;; // FAUCET - ASSETCHAINS_CCDISABLES[230] = CCENABLE;; // DICE - ASSETCHAINS_CCDISABLES[236] = CCENABLE;; // ORACLES + CCDISABLEALL; + CCENABLE(EVAL_FAUCET); + CCENABLE(EVAL_DICE); + CCENABLE(EVAL_ORACLES); } } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); From 1403eb6cf7373b662b4e5a2ff8b151ddb2046fed Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 10 Jun 2019 18:18:09 +0200 Subject: [PATCH 5/6] bump version bump version for the hardfork --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index eca4abb36..95c2cc343 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -78,7 +78,7 @@ int8_t StakedNotaryID(std::string ¬aryname, char *Raddress); uint64_t komodo_notarypayamount(int32_t nHeight, int64_t notarycount); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); -#define KOMODO_VERSION "0.3.3b" +#define KOMODO_VERSION "0.4.0a" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From a581ac5e1b6cbbc2c74eb253bb4861b5038e7c7e Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 28 Nov 2018 00:56:42 +0100 Subject: [PATCH 6/6] wallet: Skip transactions with no shielded data in CWallet::SetBestChain() Co-authored-by: Daira Hopwood Closes #3495. --- src/wallet/gtest/test_wallet.cpp | 57 ++++++++++++++++++++++++++++++++ src/wallet/wallet.h | 15 ++++++--- 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 1fe9db11a..676239d0b 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -1680,6 +1680,63 @@ TEST(WalletTests, WriteWitnessCache) { wallet.SetBestChain(walletdb, loc); } +TEST(WalletTests, SetBestChainIgnoresTxsWithoutShieldedData) { + SelectParams(CBaseChainParams::REGTEST); + + TestWallet wallet; + MockWalletDB walletdb; + CBlockLocator loc; + + // Set up transparent address + CKey tsk = DecodeSecret(tSecretRegtest); + wallet.AddKey(tsk); + auto scriptPubKey = GetScriptForDestination(tsk.GetPubKey().GetID()); + + // Set up a Sprout address + auto sk = libzcash::SproutSpendingKey::random(); + wallet.AddSproutSpendingKey(sk); + + // Generate a transparent transaction that is ours + CMutableTransaction t; + t.vout.resize(1); + t.vout[0].nValue = 90*CENT; + t.vout[0].scriptPubKey = scriptPubKey; + CWalletTx wtxTransparent {nullptr, t}; + wallet.AddToWallet(wtxTransparent, true, NULL); + + // Generate a Sprout transaction that is ours + auto wtxSprout = GetValidReceive(sk, 10, true); + auto noteMap = wallet.FindMySproutNotes(wtxSprout); + wtxSprout.SetSproutNoteData(noteMap); + wallet.AddToWallet(wtxSprout, true, NULL); + + // Generate a Sprout transaction that only involves our transparent address + auto sk2 = libzcash::SproutSpendingKey::random(); + auto wtxInput = GetValidReceive(sk2, 10, true); + auto note = GetNote(sk2, wtxInput, 0, 0); + auto wtxTmp = GetValidSpend(sk2, note, 5); + CMutableTransaction mtx {wtxTmp}; + mtx.vout[0].scriptPubKey = scriptPubKey; + CWalletTx wtxSproutTransparent {NULL, mtx}; + wallet.AddToWallet(wtxSproutTransparent, true, NULL); + + EXPECT_CALL(walletdb, TxnBegin()) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteTx(wtxTransparent.GetHash(), wtxTransparent)) + .Times(0); + EXPECT_CALL(walletdb, WriteTx(wtxSprout.GetHash(), wtxSprout)) + .Times(1).WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteTx(wtxSproutTransparent.GetHash(), wtxSproutTransparent)) + .Times(0); + EXPECT_CALL(walletdb, WriteWitnessCacheSize(0)) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, WriteBestBlock(loc)) + .WillOnce(Return(true)); + EXPECT_CALL(walletdb, TxnCommit()) + .WillOnce(Return(true)); + wallet.SetBestChain(walletdb, loc); +} + TEST(WalletTests, UpdateSproutNullifierNoteMap) { TestWallet wallet; uint256 r {GetRandHash()}; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index b00365a77..296e2fa57 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -807,10 +807,17 @@ protected: } try { for (std::pair& wtxItem : mapWallet) { - if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) { - LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n"); - walletdb.TxnAbort(); - return; + auto wtx = wtxItem.second; + // We skip transactions for which mapSproutNoteData and mapSaplingNoteData + // are empty. This covers transactions that have no Sprout or Sapling data + // (i.e. are purely transparent), as well as shielding and unshielding + // transactions in which we only have transparent addresses involved. + if (!(wtx.mapSproutNoteData.empty() && wtx.mapSaplingNoteData.empty())) { + if (!walletdb.WriteTx(wtxItem.first, wtx)) { + LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n"); + walletdb.TxnAbort(); + return; + } } } if (!walletdb.WriteWitnessCacheSize(nWitnessCacheSize)) {