Merge remote-tracking branch 'zcash/master' into rebase

# Conflicts:
#	README.md
#	src/Makefile.gtest.include
#	src/chainparams.cpp
#	src/init.cpp
#	src/miner.cpp
#	src/wallet/wallet.cpp
This commit is contained in:
jl777
2016-12-12 12:19:13 +02:00
94 changed files with 3461 additions and 808 deletions

View File

@@ -225,7 +225,15 @@ public:
*/
std::list<ZCIncrementalWitness> witnesses;
/** Block height corresponding to the most current witness. */
/**
* Block height corresponding to the most current witness.
*
* When we first create a CNoteData in CWallet::FindMyNotes, this is set to
* -1 as a placeholder. The next time CWallet::ChainTip is called, we can
* determine what height the witness cache for this note is valid for (even
* if no witnesses were cached), and so can set the correct value in
* CWallet::IncrementNoteWitnesses and CWallet::DecrementNoteWitnesses.
*/
int witnessHeight;
CNoteData() : address(), nullifier(), witnessHeight {-1} { }
@@ -620,41 +628,52 @@ public:
void ClearNoteWitnessCache();
protected:
/**
* pindex is the new tip being connected.
*/
void IncrementNoteWitnesses(const CBlockIndex* pindex,
const CBlock* pblock,
ZCIncrementalMerkleTree& tree);
void DecrementNoteWitnesses();
/**
* pindex is the old tip being disconnected.
*/
void DecrementNoteWitnesses(const CBlockIndex* pindex);
template <typename WalletDB>
void WriteWitnessCache(WalletDB& walletdb) {
void SetBestChainINTERNAL(WalletDB& walletdb, const CBlockLocator& loc) {
if (!walletdb.TxnBegin()) {
// This needs to be done atomically, so don't do it at all
LogPrintf("WriteWitnessCache(): Couldn't start atomic write\n");
LogPrintf("SetBestChain(): Couldn't start atomic write\n");
return;
}
try {
for (std::pair<const uint256, CWalletTx>& wtxItem : mapWallet) {
if (!walletdb.WriteTx(wtxItem.first, wtxItem.second)) {
LogPrintf("WriteWitnessCache(): Failed to write CWalletTx, aborting atomic write\n");
LogPrintf("SetBestChain(): Failed to write CWalletTx, aborting atomic write\n");
walletdb.TxnAbort();
return;
}
}
if (!walletdb.WriteWitnessCacheSize(nWitnessCacheSize)) {
LogPrintf("WriteWitnessCache(): Failed to write nWitnessCacheSize, aborting atomic write\n");
LogPrintf("SetBestChain(): Failed to write nWitnessCacheSize, aborting atomic write\n");
walletdb.TxnAbort();
return;
}
if (!walletdb.WriteBestBlock(loc)) {
LogPrintf("SetBestChain(): Failed to write best block, aborting atomic write\n");
walletdb.TxnAbort();
return;
}
} catch (const std::exception &exc) {
// Unexpected failure
LogPrintf("WriteWitnessCache(): Unexpected error during atomic write:\n");
LogPrintf("SetBestChain(): Unexpected error during atomic write:\n");
LogPrintf("%s\n", exc.what());
walletdb.TxnAbort();
return;
}
if (!walletdb.TxnCommit()) {
// Couldn't commit all to db, but in-memory state is fine
LogPrintf("WriteWitnessCache(): Couldn't commit atomic write\n");
LogPrintf("SetBestChain(): Couldn't commit atomic write\n");
return;
}
}
@@ -944,6 +963,7 @@ public:
CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const;
CAmount GetChange(const CTransaction& tx) const;
void ChainTip(const CBlockIndex *pindex, const CBlock *pblock, ZCIncrementalMerkleTree tree, bool added);
/** Saves witness caches and best block locator to disk. */
void SetBestChain(const CBlockLocator& loc);
DBErrors LoadWallet(bool& fFirstRunRet);