From fd3b6aa6efe2d8e26e082f7dca1da4a7f4b406e5 Mon Sep 17 00:00:00 2001 From: presstab Date: Tue, 31 Oct 2017 11:32:08 -0600 Subject: [PATCH] Add memory only accumulator tracking for unit tests. --- src/accumulators.cpp | 12 ++++++++++-- src/accumulators.h | 2 +- src/test/zerocoin_implementation_tests.cpp | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/accumulators.cpp b/src/accumulators.cpp index 493aff41aae58..e6a2a53777b9d 100644 --- a/src/accumulators.cpp +++ b/src/accumulators.cpp @@ -32,8 +32,16 @@ uint32_t GetChecksum(const CBigNum &bnValue) return hash.Get32(); } -bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, CBigNum& bnAccValue) +bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, bool fMemoryOnly, CBigNum& bnAccValue) { + if (mapAccumulatorValues.count(nChecksum)) { + bnAccValue = mapAccumulatorValues.at(nChecksum); + return true; + } + + if (fMemoryOnly) + return false; + if (!zerocoinDB->ReadAccumulatorValue(nChecksum, bnAccValue)) { bnAccValue = 0; } @@ -44,7 +52,7 @@ bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, CBigNum& bnAccValue) bool GetAccumulatorValueFromDB(uint256 nCheckpoint, CoinDenomination denom, CBigNum& bnAccValue) { uint32_t nChecksum = ParseChecksum(nCheckpoint, denom); - return GetAccumulatorValueFromChecksum(nChecksum, bnAccValue); + return GetAccumulatorValueFromChecksum(nChecksum, false, bnAccValue); } void AddAccumulatorChecksum(const uint32_t nChecksum, const CBigNum &bnValue, bool fMemoryOnly) diff --git a/src/accumulators.h b/src/accumulators.h index 8bb7a0fd3678f..3c7c00aa5869f 100644 --- a/src/accumulators.h +++ b/src/accumulators.h @@ -13,7 +13,7 @@ bool GenerateAccumulatorWitness(const libzerocoin::PublicCoin &coin, libzerocoin::Accumulator& accumulator, libzerocoin::AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, std::string& strError); bool GetAccumulatorValueFromDB(uint256 nCheckpoint, libzerocoin::CoinDenomination denom, CBigNum& bnAccValue); -bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, CBigNum& bnAccValue); +bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, bool fMemoryOnly, CBigNum& bnAccValue); void AddAccumulatorChecksum(const uint32_t nChecksum, const CBigNum &bnValue, bool fMemoryOnly); bool CalculateAccumulatorCheckpoint(int nHeight, uint256& nCheckpoint); bool LoadAccumulatorValuesFromDB(const uint256 nCheckpoint); diff --git a/src/test/zerocoin_implementation_tests.cpp b/src/test/zerocoin_implementation_tests.cpp index 14827b8e6c136..46e7f3d7f2845 100644 --- a/src/test/zerocoin_implementation_tests.cpp +++ b/src/test/zerocoin_implementation_tests.cpp @@ -135,7 +135,7 @@ bool CheckZerocoinSpendNoDB(const CTransaction tx, string& strError) //see if we have record of the accumulator used in the spend tx CBigNum bnAccumulatorValue = 0; - if (!GetAccumulatorValueFromChecksum(newSpend.getAccumulatorChecksum(), bnAccumulatorValue)) { + if (!GetAccumulatorValueFromChecksum(newSpend.getAccumulatorChecksum(), true, bnAccumulatorValue)) { strError = "Zerocoinspend could not find accumulator associated with checksum"; return false; }