Skip to content

Commit

Permalink
Add memory only accumulator tracking for unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
presstab committed Oct 31, 2017
1 parent 5aa1f2e commit fd3b6aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/accumulators.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/zerocoin_implementation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fd3b6aa

Please sign in to comment.