Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
- This file was added.
// Copyright (c) 2018 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.h" | |||||
#include "chain.h" | |||||
#include "netmessagemaker.h" | |||||
#include "scheduler.h" | |||||
bool AvalancheProcessor::addBlockToReconcile(const CBlockIndex *pindex) { | |||||
return vote_records.getWriteView() | |||||
->insert(std::make_pair(pindex->GetBlockHash(), VoteRecord())) | |||||
.second; | |||||
} | |||||
static const VoteRecord * | |||||
GetRecord(const RWCollection<std::map<uint256, VoteRecord>> &vote_records, | |||||
const CBlockIndex *pindex) { | |||||
auto r = vote_records.getReadView(); | |||||
auto it = r->find(pindex->GetBlockHash()); | |||||
if (it == r.end()) { | |||||
return nullptr; | |||||
} | |||||
return &it->second; | |||||
} | |||||
bool AvalancheProcessor::isAccepted(const CBlockIndex *pindex) const { | |||||
if (auto vr = GetRecord(vote_records, pindex)) { | |||||
return vr->isValid(); | |||||
} | |||||
return false; | |||||
} | |||||
bool AvalancheProcessor::hasFinalized(const CBlockIndex *pindex) const { | |||||
if (auto vr = GetRecord(vote_records, pindex)) { | |||||
return vr->hasFinalized(); | |||||
} | |||||
return false; | |||||
} | |||||
bool AvalancheProcessor::registerVotes(const AvalancheResponse &response) { | |||||
const std::vector<AvalancheVote> &votes = response.GetVotes(); | |||||
// Register votes. | |||||
auto w = vote_records.getWriteView(); | |||||
for (auto &v : votes) { | |||||
w[v.GetHash()].registerVote(v.IsValid()); | |||||
} | |||||
return true; | |||||
} |