diff --git a/src/accumulators.cpp b/src/accumulators.cpp index 7c890d410..4b04372bc 100644 --- a/src/accumulators.cpp +++ b/src/accumulators.cpp @@ -414,7 +414,7 @@ bool GetAccumulatorValue(int& nHeight, const libzerocoin::CoinDenomination denom return true; } -bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator, AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, string& strError, CBlockIndex* pindexCheckpoint) +bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator, AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, string& strError, bool isV1Coin, CBlockIndex* pindexCheckpoint) { LogPrint("zero", "%s: generating\n", __func__); int nLockAttempts = 0; @@ -487,13 +487,19 @@ bool GenerateAccumulatorWitness(const PublicCoin &coin, Accumulator& accumulator bnAccValue = 0; uint256 nCheckpointSpend = chainActive[pindex->nHeight + 10]->nAccumulatorCheckpoint; - if (!GetAccumulatorValueFromDB(nCheckpointSpend, coin.getDenomination(), bnAccValue) || bnAccValue == 0) - return error("%s : failed to find checksum in database for accumulator", __func__); + if (!isV1Coin){ + if (!GetAccumulatorValueFromDB(nCheckpointSpend, coin.getDenomination(), bnAccValue) || bnAccValue == 0) + return error("%s : failed to find checksum in database for accumulator", __func__); - accumulator.setValue(bnAccValue); + accumulator.setValue(bnAccValue); + } break; } + if (isV1Coin){ + AddBlockMintsToAccumulator(coin, nHeightMintAdded, pindex, &accumulator, false); + } + nMintsAdded += AddBlockMintsToAccumulator(coin, nHeightMintAdded, pindex, &witnessAccumulator, true); pindex = chainActive.Next(pindex); @@ -581,7 +587,7 @@ bool CalculateAccumulatorCheckpointWithoutDB(int nHeight, uint256& nCheckpoint, return false; //make sure this block is eligible for accumulation - if (pindex->nHeight < Params().Zerocoin_StartHeight()) { + if (pindex->nHeight < Params().Zerocoin_StartHeight()) { pindex = chainActive[pindex->nHeight + 1]; continue; } diff --git a/src/accumulators.h b/src/accumulators.h index 52c3fd2ad..d4e5b485b 100644 --- a/src/accumulators.h +++ b/src/accumulators.h @@ -17,7 +17,7 @@ class CBlockIndex; std::map GetMintMaturityHeight(); -bool GenerateAccumulatorWitness(const libzerocoin::PublicCoin &coin, libzerocoin::Accumulator& accumulator, libzerocoin::AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, std::string& strError, CBlockIndex* pindexCheckpoint = nullptr); +bool GenerateAccumulatorWitness(const libzerocoin::PublicCoin &coin, libzerocoin::Accumulator& accumulator, libzerocoin::AccumulatorWitness& witness, int nSecurityLevel, int& nMintsAdded, std::string& strError, bool isV1Coin, CBlockIndex* pindexCheckpoint = nullptr); bool GetAccumulatorValueFromDB(uint256 nCheckpoint, libzerocoin::CoinDenomination denom, CBigNum& bnAccValue); bool GetAccumulatorValueFromChecksum(uint32_t nChecksum, bool fMemoryOnly, CBigNum& bnAccValue); void AddAccumulatorChecksum(const uint32_t nChecksum, const CBigNum &bnValue, bool fMemoryOnly); diff --git a/src/wallet.cpp b/src/wallet.cpp index 658025602..850cccb94 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -4762,7 +4762,7 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con libzerocoin::AccumulatorWitness witness(paramsAccumulator, accumulator, pubCoinSelected); string strFailReason = ""; int nMintsAdded = 0; - if (!GenerateAccumulatorWitness(pubCoinSelected, accumulator, witness, nSecurityLevel, nMintsAdded, strFailReason, pindexCheckpoint)) { + if (!GenerateAccumulatorWitness(pubCoinSelected, accumulator, witness, nSecurityLevel, nMintsAdded, strFailReason, isV1Coin, pindexCheckpoint)) { receipt.SetStatus(_("Try to spend with a higher security level to include more coins"), XION_FAILED_ACCUMULATOR_INITIALIZATION); return error("%s : %s", __func__, receipt.GetStatusMessage()); } @@ -4789,7 +4789,13 @@ bool CWallet::MintToTxIn(CZerocoinMint zerocoinSelected, int nSecurityLevel, con uint32_t nChecksum = GetChecksum(accumulator.getValue()); CBigNum bnValue; if (!GetAccumulatorValueFromChecksum(nChecksum, false, bnValue) || bnValue == 0) + { + if (isV1Coin){ + LogPrintf("%s: spending v1 coin\n", __func__); + } else { return error("%s: could not find checksum used for spend\n", __func__); + } + } try { libzerocoin::CoinSpend spend(paramsCoin, paramsAccumulator, privateCoin, accumulator, nChecksum, witness, hashTxOut,