Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proofpool.cpp
- This file was added.
// Copyright (c) 2021 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
#include <avalanche/proofpool.h> | |||||
#include <unordered_set> | |||||
#include <iterator> | |||||
namespace avalanche { | |||||
bool ProofPool::addProof(const ProofRef &proof, std::set<ProofRef> &shifted) { | |||||
bool success = true; | |||||
for (const auto &ss : proof->getStakes()) { | |||||
auto &proofs = utxos[ss.getStake().getUTXO()]; | |||||
deadalnix: Using proof and proofs doesn't help comprehend what this does. | |||||
auto p = proofs.emplace(proof); | |||||
deadalnixUnsubmitted Not Done Inline ActionsI don't think you need emplace here. Just insert. deadalnix: I don't think you need emplace here. Just insert. | |||||
if (!p.second) { | |||||
// Already there | |||||
continue; | |||||
} | |||||
shifted.insert(std::next(p.first), proofs.end()); | |||||
// Trim | |||||
if (proofs.size() > maxProofsPerUtxo) { | |||||
auto pit = std::prev(proofs.end()); | |||||
// Don't keep half baked proofs | |||||
removeProof(*pit); | |||||
} | |||||
assert(proofs.size() <= maxProofsPerUtxo); | |||||
// TODO Use contains after C++20 | |||||
success = success && proofs.count(proof) > 0; | |||||
} | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis whole thing is an order of magnitude more complex than it needs to. Just use an array, and do something akin to for (auto &p : proofs) { if (proof.isbeterthan(p)) { swap(p, proof); } } if p(roof != nullptr) removeProof(proof); But the more I read this, the more I question the whole approach. The complexity is clearly not in proprotions to what this is doing - (effectivel a multimap with some prunning). deadalnix: This whole thing is an order of magnitude more complex than it needs to.
Just use an array… | |||||
return success; | |||||
} | |||||
bool ProofPool::removeProof(const ProofRef &proof) { | |||||
for (const SignedStake &ss : proof->getStakes()) { | |||||
auto it = utxos.find(ss.getStake().getUTXO()); | |||||
if (it == utxos.end()) { | |||||
continue; | |||||
} | |||||
it->second.erase(proof); | |||||
if (it->second.size() == 0) { | |||||
utxos.erase(it); | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
} // namespace avalanche |
Using proof and proofs doesn't help comprehend what this does.