Skip to content

Commit

Permalink
Fixing anonymity set construction for new sets. (#1189)
Browse files Browse the repository at this point in the history
* Run batch verify when shuttown

* Small optimization when using coincontrol

* Fixing anonymity set generation
  • Loading branch information
levonpetrosyan93 committed May 17, 2023
1 parent 9d1ca73 commit 13034c0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void Shutdown()
llmq::StopLLMQSystem();

BatchProofContainer::get_instance()->finalize();
BatchProofContainer::get_instance()->verify();

#ifdef ENABLE_WALLET
if (pwalletMain)
Expand Down
41 changes: 24 additions & 17 deletions src/lelantus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ static bool CheckLelantusSpendSerial(
return true;
}

/*
* Util funtions
*/
size_t CountCoinInBlock(CBlockIndex *index, int id) {
return index->lelantusMintedPubCoins.count(id) > 0
? index->lelantusMintedPubCoins[id].size() : 0;
}

std::vector<unsigned char> GetAnonymitySetHash(CBlockIndex *index, int group_id, bool generation = false) {
std::vector<unsigned char> out_hash;
Expand Down Expand Up @@ -502,17 +509,25 @@ bool CheckLelantusJoinSplitTransaction(
// This list of public coins is required by function "Verify" of JoinSplit.

while (true) {
if(index->lelantusMintedPubCoins.count(idAndHash.first) > 0) {
BOOST_FOREACH(
const auto& pubCoinValue,
index->lelantusMintedPubCoins[idAndHash.first]) {
// skip mints from blacklist if nLelantusFixesStartBlock is passed
if (chainActive.Height() >= ::Params().GetConsensus().nLelantusFixesStartBlock) {
if (::Params().GetConsensus().lelantusBlacklist.count(pubCoinValue.first.getValue()) > 0) {
continue;
int id = 0;
if (CountCoinInBlock(index, idAndHash.first)) {
id = idAndHash.first;
} else if (CountCoinInBlock(index, idAndHash.first - 1)) {
id = idAndHash.first - 1;
}
if (id) {
if(index->lelantusMintedPubCoins.count(id) > 0) {
BOOST_FOREACH(
const auto& pubCoinValue,
index->lelantusMintedPubCoins[id]) {
// skip mints from blacklist if nLelantusFixesStartBlock is passed
if (chainActive.Height() >= ::Params().GetConsensus().nLelantusFixesStartBlock) {
if (::Params().GetConsensus().lelantusBlacklist.count(pubCoinValue.first.getValue()) > 0) {
continue;
}
}
anonymity_set.push_back(pubCoinValue.first);
}
anonymity_set.push_back(pubCoinValue.first);
}
}
if (index == coinGroup.firstBlock)
Expand Down Expand Up @@ -1053,14 +1068,6 @@ void CLelantusTxInfo::Complete() {
fInfoIsComplete = true;
}

/*
* Util funtions
*/
size_t CountCoinInBlock(CBlockIndex *index, int id) {
return index->lelantusMintedPubCoins.count(id) > 0
? index->lelantusMintedPubCoins[id].size() : 0;
}

/******************************************************************************/
// CLelantusState::Containers
/******************************************************************************/
Expand Down
32 changes: 16 additions & 16 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3031,6 +3031,22 @@ std::list<CLelantusEntry> CWallet::GetAvailableLelantusCoins(const CCoinControl
if (coin.IsUsed)
return true;

COutPoint outPoint;
lelantus::PublicCoin pubCoin(coin.value);
lelantus::GetOutPoint(outPoint, pubCoin);

if(lockedCoins.count(outPoint) > 0){
return true;
}

if(coinControl != NULL){
if(coinControl->HasSelected()){
if(!coinControl->IsSelected(outPoint)){
return true;
}
}
}

int coinHeight, coinId;
std::tie(coinHeight, coinId) = state->GetMintedCoinHeightAndId(lelantus::PublicCoin(coin.value));

Expand Down Expand Up @@ -3062,22 +3078,6 @@ std::list<CLelantusEntry> CWallet::GetAvailableLelantusCoins(const CCoinControl
return true;
}

COutPoint outPoint;
lelantus::PublicCoin pubCoin(coin.value);
lelantus::GetOutPoint(outPoint, pubCoin);

if(lockedCoins.count(outPoint) > 0){
return true;
}

if(coinControl != NULL){
if(coinControl->HasSelected()){
if(!coinControl->IsSelected(outPoint)){
return true;
}
}
}

return false;
});

Expand Down

0 comments on commit 13034c0

Please sign in to comment.