Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
// Copyright (c) 2018-2019 The Bitcoin developers | // Copyright (c) 2018-2019 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/processor.h> | #include <avalanche/processor.h> | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <key_io.h> // For DecodeSecret | #include <key_io.h> // For DecodeSecret | ||||
#include <net_processing.h> // For Misbehaving | |||||
#include <netmessagemaker.h> | #include <netmessagemaker.h> | ||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/bitmanip.h> | #include <util/bitmanip.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <chrono> | #include <chrono> | ||||
#include <tuple> | #include <tuple> | ||||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | bool Processor::registerVotes(NodeId nodeid, const Response &response, | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
{ | { | ||||
// Check that the query exists. | // Check that the query exists. | ||||
auto w = queries.getWriteView(); | auto w = queries.getWriteView(); | ||||
auto it = w->find(std::make_tuple(nodeid, response.getRound())); | auto it = w->find(std::make_tuple(nodeid, response.getRound())); | ||||
if (it == w.end()) { | if (it == w.end()) { | ||||
// NB: The request may be old, so we don't increase banscore. | LOCK(cs_main); | ||||
Misbehaving(nodeid, 2, "unexpcted-ava-response"); | |||||
return false; | return false; | ||||
} | } | ||||
invs = std::move(it->invs); | invs = std::move(it->invs); | ||||
w->erase(it); | w->erase(it); | ||||
} | } | ||||
// Verify that the request and the vote are consistent. | // Verify that the request and the vote are consistent. | ||||
const std::vector<Vote> &votes = response.GetVotes(); | const std::vector<Vote> &votes = response.GetVotes(); | ||||
size_t size = invs.size(); | size_t size = invs.size(); | ||||
if (votes.size() != size) { | if (votes.size() != size) { | ||||
// TODO: increase banscore for inconsistent response. | LOCK(cs_main); | ||||
// NB: This isn't timeout but actually node misbehaving. | Misbehaving(nodeid, 100, "invalid-ava-response-size"); | ||||
return false; | return false; | ||||
} | } | ||||
for (size_t i = 0; i < size; i++) { | for (size_t i = 0; i < size; i++) { | ||||
if (invs[i].hash != votes[i].GetHash()) { | if (invs[i].hash != votes[i].GetHash()) { | ||||
// TODO: increase banscore for inconsistent response. | LOCK(cs_main); | ||||
// NB: This isn't timeout but actually node misbehaving. | Misbehaving(nodeid, 100, "invalid-ava-response-content"); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
std::map<CBlockIndex *, Vote> responseIndex; | std::map<CBlockIndex *, Vote> responseIndex; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
▲ Show 20 Lines • Show All 229 Lines • Show Last 20 Lines |