From 0e69844e8c9c06ddfa44b7923cc7af981352e6be Mon Sep 17 00:00:00 2001 From: alex v Date: Sat, 20 Feb 2021 21:05:54 +0100 Subject: [PATCH] Prevent adding duplicated inputs from candidates (#798) --- src/blsct/aggregationsession.cpp | 11 +++++++++++ src/primitives/transaction.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/blsct/aggregationsession.cpp b/src/blsct/aggregationsession.cpp index 4395c4c20..34100bac6 100644 --- a/src/blsct/aggregationsession.cpp +++ b/src/blsct/aggregationsession.cpp @@ -179,6 +179,8 @@ bool AggregationSession::SelectCandidates(CandidateTransaction &ret) unsigned int i = 0; unsigned int nSelected = 0; + std::set setSeen; + while (nSelected < nSelect && i < vTransactionCandidates.size()) { if (!inputs->HaveInputs(vTransactionCandidates[i].tx)) @@ -203,6 +205,15 @@ bool AggregationSession::SelectCandidates(CandidateTransaction &ret) { COutPoint prevOut = vTransactionCandidates[i].tx.vin[j].prevout; + if (setSeen.count(prevOut.GetHash())) + { + i++; + fShouldIContinue = true; + break; + } + + setSeen.insert(prevOut.GetHash()); + if (pwalletMain->mapWallet.count(prevOut.hash)) { auto prevTx = pwalletMain->mapWallet[prevOut.hash]; diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 4366cec72..13a9f6db3 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -62,6 +62,11 @@ class COutPoint return !(a == b); } + uint256 GetHash() const + { + return SerializeHash(*this, SER_GETHASH, SERIALIZE_TRANSACTION_NO_WITNESS); + } + std::string ToString() const; };