Merge pull request #5698 from knst/v20-fix-todo-2

fix: TODO related fixes for post-v20 release
This commit is contained in:
PastaPastaPasta 2023-11-19 10:14:13 -06:00 committed by GitHub
commit 105acfd5fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 44 additions and 130 deletions

View File

@ -259,7 +259,7 @@ void CCoinsViewCache::ReallocateCache()
::new (&cacheCoins) CCoinsMap();
}
static const size_t MAX_OUTPUTS_PER_BLOCK = MaxBlockSize() / ::GetSerializeSize(CTxOut(), PROTOCOL_VERSION); // TODO: merge with similar definition in undo.h.
static const size_t MAX_OUTPUTS_PER_BLOCK = MaxBlockSize() / ::GetSerializeSize(CTxOut(), PROTOCOL_VERSION);
const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
{

View File

@ -4,18 +4,17 @@
#include <consensus/tx_verify.h>
#include <consensus/consensus.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <consensus/validation.h>
#include <evo/assetlocktx.h>
#include <tinyformat.h>
// TODO remove the following dependencies
#include <chain.h>
#include <coins.h>
#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <evo/assetlocktx.h>
#include <primitives/transaction.h>
#include <script/interpreter.h>
#include <tinyformat.h>
#include <util/moneystr.h>
bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
{
if (tx.nLockTime == 0)

View File

@ -464,25 +464,13 @@ public:
return false;
}
if (curIsParent) {
try {
// TODO try to avoid this copy (we need a stream that allows reading from external buffers)
CDataStream ssKey = parentKey;
ssKey >> key;
} catch (const std::exception&) {
return false;
}
return true;
} else {
try {
// TODO try to avoid this copy (we need a stream that allows reading from external buffers)
CDataStream ssKey = transactionIt->first;
ssKey >> key;
} catch (const std::exception&) {
return false;
}
return true;
try {
// TODO try to avoid copy transactionIt->first (we need a stream that allows reading from external buffers)
(curIsParent ? parentKey : CDataStream{transactionIt->first}) >> key;
} catch (const std::exception&) {
return false;
}
return true;
}
CDataStream GetKey() {

View File

@ -98,14 +98,6 @@ void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionR
void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
{
// TODO: Temporarily ensure that mempool removals are notified before
// connected transactions. This shouldn't matter, but the abandoned
// state of transactions in our wallet is currently cleared when we
// receive another notification and there is a race condition where
// notification of a connected conflict might cause an outside process
// to abandon a transaction and then have it inadvertently cleared by
// the notification that the conflicted transaction was evicted.
llmq_ctx->isman->BlockConnected(pblock, pindex);
llmq_ctx->clhandler->BlockConnected(pblock, pindex);
CCoinJoin::BlockConnected(pblock, pindex);

View File

@ -95,12 +95,11 @@ UniValue CSimplifiedMNListEntry::ToJson(bool extended) const
return obj;
}
// TODO: Invistigate if we can delete this constructor
CSimplifiedMNList::CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& smlEntries)
{
mnList.resize(smlEntries.size());
for (size_t i = 0; i < smlEntries.size(); i++) {
mnList[i] = std::make_unique<CSimplifiedMNListEntry>(smlEntries[i]);
mnList.reserve(smlEntries.size());
for (const auto& entry : smlEntries) {
mnList.emplace_back(std::make_unique<CSimplifiedMNListEntry>(entry));
}
std::sort(mnList.begin(), mnList.end(), [&](const std::unique_ptr<CSimplifiedMNListEntry>& a, const std::unique_ptr<CSimplifiedMNListEntry>& b) {
@ -110,11 +109,9 @@ CSimplifiedMNList::CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>&
CSimplifiedMNList::CSimplifiedMNList(const CDeterministicMNList& dmnList)
{
mnList.resize(dmnList.GetAllMNsCount());
size_t i = 0;
dmnList.ForEachMN(false, [this, &i](auto& dmn) {
mnList[i++] = std::make_unique<CSimplifiedMNListEntry>(dmn);
mnList.reserve(dmnList.GetAllMNsCount());
dmnList.ForEachMN(false, [this](auto& dmn) {
mnList.emplace_back(std::make_unique<CSimplifiedMNListEntry>(dmn));
});
std::sort(mnList.begin(), mnList.end(), [&](const std::unique_ptr<CSimplifiedMNListEntry>& a, const std::unique_ptr<CSimplifiedMNListEntry>& b) {

View File

@ -100,9 +100,11 @@ public:
std::vector<std::unique_ptr<CSimplifiedMNListEntry>> mnList;
CSimplifiedMNList() = default;
explicit CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& smlEntries);
explicit CSimplifiedMNList(const CDeterministicMNList& dmnList);
// This constructor from std::vector is used in unit-tests
explicit CSimplifiedMNList(const std::vector<CSimplifiedMNListEntry>& smlEntries);
uint256 CalcMerkleRoot(bool* pmutated = nullptr) const;
bool operator==(const CSimplifiedMNList& rhs) const;
};

View File

@ -354,10 +354,8 @@ bool CSuperblockManager::GetSuperblockPayments(CGovernanceManager& governanceMan
CTxDestination dest;
ExtractDestination(payment.script, dest);
// TODO: PRINT NICE N.N DASH OUTPUT
LogPrint(BCLog::GOBJECT, "CSuperblockManager::GetSuperblockPayments -- NEW Superblock: output %d (addr %s, amount %lld)\n",
i, EncodeDestination(dest), payment.nAmount);
LogPrint(BCLog::GOBJECT, "CSuperblockManager::GetSuperblockPayments -- NEW Superblock: output %d (addr %s, amount %d.%08d)\n",
i, EncodeDestination(dest), payment.nAmount / COIN, payment.nAmount % COIN);
} else {
LogPrint(BCLog::GOBJECT, "CSuperblockManager::GetSuperblockPayments -- Payment not found\n");
}

View File

@ -2074,11 +2074,6 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
break;
}
if (!llmq::quorumBlockProcessor->UpgradeDB()) {
strLoadError = _("Error upgrading evo database");
break;
}
for (CChainState* chainstate : chainman.GetAll()) {
if (!is_coinsview_empty(chainstate)) {
uiInterface.InitMessage(_("Verifying blocks...").translated);

View File

@ -15,7 +15,6 @@
#include <consensus/validation.h>
#include <net.h>
#include <net_processing.h>
#include <node/blockstorage.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <saltedhasher.h>
@ -353,64 +352,6 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null<const C
return true;
}
// TODO remove this with 0.15.0
bool CQuorumBlockProcessor::UpgradeDB()
{
LOCK(cs_main);
if (m_chainstate.m_chain.Tip() == nullptr) {
// should have no records
return m_evoDb.IsEmpty();
}
uint256 bestBlock;
if (m_evoDb.GetRawDB().Read(DB_BEST_BLOCK_UPGRADE, bestBlock) && bestBlock == m_chainstate.m_chain.Tip()->GetBlockHash()) {
return true;
}
LogPrintf("CQuorumBlockProcessor::%s -- Upgrading DB...\n", __func__);
if (m_chainstate.m_chain.Height() >= Params().GetConsensus().DIP0003EnforcementHeight) {
const auto* pindex = m_chainstate.m_chain[Params().GetConsensus().DIP0003EnforcementHeight];
while (pindex != nullptr) {
if (fPruneMode && ((pindex->nStatus & BLOCK_HAVE_DATA) == 0)) {
// Too late, we already pruned blocks we needed to reprocess commitments
return false;
}
CBlock block;
bool r = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
assert(r);
std::multimap<Consensus::LLMQType, CFinalCommitment> qcs;
BlockValidationState dummyState;
GetCommitmentsFromBlock(block, pindex, qcs, dummyState);
for (const auto& p : qcs) {
const auto& qc = p.second;
if (qc.IsNull()) {
continue;
}
const auto* pQuorumBaseBlockIndex = m_chainstate.m_blockman.LookupBlockIndex(qc.quorumHash);
m_evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash()));
const auto& llmq_params_opt = GetLLMQParams(qc.llmqType);
assert(llmq_params_opt.has_value());
if (llmq::utils::IsQuorumRotationEnabled(llmq_params_opt.value(), pQuorumBaseBlockIndex)) {
m_evoDb.GetRawDB().Write(BuildInversedHeightKeyIndexed(qc.llmqType, pindex->nHeight, int(qc.quorumIndex)), pQuorumBaseBlockIndex->nHeight);
} else {
m_evoDb.GetRawDB().Write(BuildInversedHeightKey(qc.llmqType, pindex->nHeight), pQuorumBaseBlockIndex->nHeight);
}
}
m_evoDb.GetRawDB().Write(DB_BEST_BLOCK_UPGRADE, pindex->GetBlockHash());
pindex = m_chainstate.m_chain.Next(pindex);
}
}
LogPrintf("CQuorumBlockProcessor::%s -- Upgrade done...\n", __func__);
return true;
}
bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex, std::multimap<Consensus::LLMQType, CFinalCommitment>& ret, BlockValidationState& state)
{
AssertLockHeld(cs_main);

View File

@ -41,7 +41,6 @@ private:
CEvoDB& m_evoDb;
const std::unique_ptr<PeerManager>& m_peerman;
// TODO cleanup
mutable RecursiveMutex minableCommitmentsCs;
std::map<std::pair<Consensus::LLMQType, uint256>, uint256> minableCommitmentsByQuorum GUARDED_BY(minableCommitmentsCs);
std::map<uint256, CFinalCommitment> minableCommitments GUARDED_BY(minableCommitmentsCs);
@ -51,8 +50,6 @@ private:
public:
explicit CQuorumBlockProcessor(CChainState& chainstate, CConnman& _connman, CEvoDB& evoDb, const std::unique_ptr<PeerManager>& peerman);
bool UpgradeDB();
void ProcessMessage(const CNode& peer, std::string_view msg_type, CDataStream& vRecv);
bool ProcessBlock(const CBlock& block, gsl::not_null<const CBlockIndex*> pindex, BlockValidationState& state, bool fJustCheck, bool fBLSChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main);

View File

@ -686,7 +686,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const
qj.proTxHash = myProTxHash;
qj.contributions.reserve(forMembers.size());
for (const auto i : irange::range(members.size())) {
for (const uint32_t i : irange::range(members.size())) {
const auto& m = members[i];
if (forMembers.count(m->dmn->proTxHash) == 0) {
continue;
@ -700,7 +700,7 @@ void CDKGSession::SendJustification(CDKGPendingMessages& pendingMessages, const
skContribution.MakeNewKey();
}
qj.contributions.emplace_back(i, skContribution);
qj.contributions.emplace_back(CDKGJustification::Contribution{i, skContribution});
}
if (ShouldSimulateError(DKGError::type::JUSTIFY_OMIT)) {
@ -747,19 +747,19 @@ bool CDKGSession::PreVerifyMessage(const CDKGJustification& qj, bool& retBan) co
std::set<size_t> contributionsSet;
for (const auto& p : qj.contributions) {
if (p.first > members.size()) {
if (p.index > members.size()) {
logger.Batch("invalid contribution index");
retBan = true;
return false;
}
if (!contributionsSet.emplace(p.first).second) {
if (!contributionsSet.emplace(p.index).second) {
logger.Batch("duplicate contribution index");
retBan = true;
return false;
}
const auto& skShare = p.second;
const auto& skShare = p.key;
if (!skShare.IsValid()) {
logger.Batch("invalid contribution");
retBan = true;
@ -822,7 +822,7 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj, bool& retBan)
}
for (const auto& p : qj.contributions) {
const auto& member2 = members[p.first];
const auto& member2 = members[p.index];
if (member->complaintsFromOthers.count(member2->dmn->proTxHash) == 0) {
logger.Batch("got justification from %s for %s even though he didn't complain",
@ -837,17 +837,15 @@ void CDKGSession::ReceiveMessage(const CDKGJustification& qj, bool& retBan)
cxxtimer::Timer t1(true);
std::list<std::future<bool>> futures;
for (const auto& p : qj.contributions) {
const auto& member2 = members[p.first];
const auto& skContribution = p.second;
for (const auto& [index, skContribution] : qj.contributions) {
const auto& member2 = members[index];
// watch out to not bail out before these async calls finish (they rely on valid references)
futures.emplace_back(blsWorker.AsyncVerifyContributionShare(member2->id, receivedVvecs[member->idx], skContribution));
}
auto resultIt = futures.begin();
for (const auto& p : qj.contributions) {
const auto& member2 = members[p.first];
const auto& skContribution = p.second;
for (const auto& [index, skContribution] : qj.contributions) {
const auto& member2 = members[index];
bool result = (resultIt++)->get();
if (!result) {

View File

@ -121,8 +121,15 @@ public:
Consensus::LLMQType llmqType;
uint256 quorumHash;
uint256 proTxHash;
// TODO make this pair a struct with named fields
std::vector<std::pair<uint32_t, CBLSSecretKey>> contributions;
struct Contribution {
uint32_t index;
CBLSSecretKey key;
SERIALIZE_METHODS(Contribution, obj)
{
READWRITE(obj.index, obj.key);
}
};
std::vector<Contribution> contributions;
CBLSSignature sig;
public: