Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | if (auth != expectedPubKey) { | ||||
"The avalanche delegation does not match the expected public key."); | "The avalanche delegation does not match the expected public key."); | ||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
struct Processor::PeerData { | struct Processor::PeerData { | ||||
std::shared_ptr<Proof> proof; | ProofRef proof; | ||||
Delegation delegation; | Delegation delegation; | ||||
}; | }; | ||||
class Processor::NotificationsHandler | class Processor::NotificationsHandler | ||||
: public interfaces::Chain::Notifications { | : public interfaces::Chain::Notifications { | ||||
Processor *m_processor; | Processor *m_processor; | ||||
public: | public: | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | bool isAccepted; | ||||
isAccepted = ::ChainActive().Contains(pindex); | isAccepted = ::ChainActive().Contains(pindex); | ||||
} | } | ||||
return blockVoteRecords.getWriteView() | return blockVoteRecords.getWriteView() | ||||
->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ->insert(std::make_pair(pindex, VoteRecord(isAccepted))) | ||||
.second; | .second; | ||||
} | } | ||||
void Processor::addProofToReconcile(const std::shared_ptr<Proof> &proof, | void Processor::addProofToReconcile(const ProofRef &proof, bool isAccepted) { | ||||
bool isAccepted) { | |||||
// TODO We don't want to accept an infinite number of conflicting proofs. | // TODO We don't want to accept an infinite number of conflicting proofs. | ||||
// They should be some rules to make them expensive and/or limited by | // They should be some rules to make them expensive and/or limited by | ||||
// design. | // design. | ||||
proofVoteRecords.getWriteView()->insert( | proofVoteRecords.getWriteView()->insert( | ||||
std::make_pair(proof, VoteRecord(isAccepted))); | std::make_pair(proof, VoteRecord(isAccepted))); | ||||
} | } | ||||
bool Processor::isAccepted(const CBlockIndex *pindex) const { | bool Processor::isAccepted(const CBlockIndex *pindex) const { | ||||
auto r = blockVoteRecords.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return it->second.isAccepted(); | return it->second.isAccepted(); | ||||
} | } | ||||
bool Processor::isAccepted(const std::shared_ptr<Proof> &proof) const { | bool Processor::isAccepted(const ProofRef &proof) const { | ||||
auto r = proofVoteRecords.getReadView(); | auto r = proofVoteRecords.getReadView(); | ||||
auto it = r->find(proof); | auto it = r->find(proof); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return it->second.isAccepted(); | return it->second.isAccepted(); | ||||
} | } | ||||
int Processor::getConfidence(const CBlockIndex *pindex) const { | int Processor::getConfidence(const CBlockIndex *pindex) const { | ||||
auto r = blockVoteRecords.getReadView(); | auto r = blockVoteRecords.getReadView(); | ||||
auto it = r->find(pindex); | auto it = r->find(pindex); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return -1; | return -1; | ||||
} | } | ||||
return it->second.getConfidence(); | return it->second.getConfidence(); | ||||
} | } | ||||
int Processor::getConfidence(const std::shared_ptr<Proof> &proof) const { | int Processor::getConfidence(const ProofRef &proof) const { | ||||
auto r = proofVoteRecords.getReadView(); | auto r = proofVoteRecords.getReadView(); | ||||
auto it = r->find(proof); | auto it = r->find(proof); | ||||
if (it == r.end()) { | if (it == r.end()) { | ||||
return -1; | return -1; | ||||
} | } | ||||
return it->second.getConfidence(); | return it->second.getConfidence(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < size; i++) { | ||||
if (invs[i].hash != votes[i].GetHash()) { | if (invs[i].hash != votes[i].GetHash()) { | ||||
banscore = 100; | banscore = 100; | ||||
error = "invalid-ava-response-content"; | error = "invalid-ava-response-content"; | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
std::map<CBlockIndex *, Vote> responseIndex; | std::map<CBlockIndex *, Vote> responseIndex; | ||||
std::map<std::shared_ptr<Proof>, Vote> responseProof; | std::map<ProofRef, Vote> responseProof; | ||||
// At this stage we are certain that invs[i] matches votes[i], so we can use | // At this stage we are certain that invs[i] matches votes[i], so we can use | ||||
// the inv type to retrieve what is being voted on. | // the inv type to retrieve what is being voted on. | ||||
for (size_t i = 0; i < size; i++) { | for (size_t i = 0; i < size; i++) { | ||||
if (invs[i].IsMsgBlk()) { | if (invs[i].IsMsgBlk()) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
auto pindex = LookupBlockIndex(BlockHash(votes[i].GetHash())); | auto pindex = LookupBlockIndex(BlockHash(votes[i].GetHash())); | ||||
if (!pindex) { | if (!pindex) { | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | connman->PushMessage(pfrom, CNetMsgMaker(pfrom->GetCommonVersion()) | ||||
.Make(NetMsgType::AVAHELLO, | .Make(NetMsgType::AVAHELLO, | ||||
Hello(peerData->delegation, sig))); | Hello(peerData->delegation, sig))); | ||||
pfrom->AddKnownProof(peerData->delegation.getProofId()); | pfrom->AddKnownProof(peerData->delegation.getProofId()); | ||||
return true; | return true; | ||||
} | } | ||||
std::shared_ptr<Proof> Processor::getLocalProof() const { | ProofRef Processor::getLocalProof() const { | ||||
return peerData ? peerData->proof : nullptr; | return peerData ? peerData->proof : nullptr; | ||||
} | } | ||||
bool Processor::startEventLoop(CScheduler &scheduler) { | bool Processor::startEventLoop(CScheduler &scheduler) { | ||||
return eventLoop.startEventLoop( | return eventLoop.startEventLoop( | ||||
scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); | scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |