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/delegationbuilder.h> | #include <avalanche/delegationbuilder.h> | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <chain.h> | #include <chain.h> | ||||
#include <key_io.h> // For DecodeSecret | #include <key_io.h> // For DecodeSecret | ||||
#include <net_processing.h> // For ::PeerManager | #include <net_processing.h> // For ::PeerManager | ||||
#include <netmessagemaker.h> | #include <netmessagemaker.h> | ||||
#include <node/ui_interface.h> | |||||
#include <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/bitmanip.h> | #include <util/bitmanip.h> | ||||
#include <util/translation.h> | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <chrono> | #include <chrono> | ||||
#include <tuple> | #include <tuple> | ||||
/** | /** | ||||
* Run the avalanche event loop every 10ms. | * Run the avalanche event loop every 10ms. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | void updatedBlockTip() override { | ||||
m_processor->peerManager->getPeerId(m_processor->peerData->proof); | m_processor->peerManager->getPeerId(m_processor->peerData->proof); | ||||
m_processor->mustRegisterProof = false; | m_processor->mustRegisterProof = false; | ||||
} | } | ||||
m_processor->peerManager->updatedBlockTip(); | m_processor->peerManager->updatedBlockTip(); | ||||
} | } | ||||
}; | }; | ||||
Processor *Processor::MakeProcessor(interfaces::Chain &chain, | |||||
deadalnix: There is no reason to not return a unique pointer here. | |||||
CConnman *connmanIn, | |||||
NodePeerManager *nodePeerManagerIn) { | |||||
// If avalanche is enabled and a proof is supplied, make sure it does | |||||
// not contain garbage. At this point the validity of the utxos cannot | |||||
// be checked, so only basic verification is performed. | |||||
if (gArgs.IsArgSet("-avaproof")) { | |||||
Proof proof; | |||||
CDataStream stream(ParseHex(gArgs.GetArg("-avaproof", "")), SER_NETWORK, | |||||
0); | |||||
stream >> proof; | |||||
deadalnixUnsubmitted Not Done Inline ActionsThis and the constructor are doing this. One of them shouldn't. deadalnix: This and the constructor are doing this. One of them shouldn't. | |||||
ProofValidationState proof_state; | |||||
if (!proof.verify(proof_state)) { | |||||
switch (proof_state.GetResult()) { | |||||
case avalanche::ProofValidationResult::NO_STAKE: | |||||
InitError(_("the avalanche proof has no stake")); | |||||
break; | |||||
case avalanche::ProofValidationResult::DUST_THRESOLD: | |||||
InitError(_("the avalanche proof stake is too low")); | |||||
break; | |||||
case avalanche::ProofValidationResult::DUPLICATE_STAKE: | |||||
InitError(_("the avalanche proof has duplicated stake")); | |||||
break; | |||||
case avalanche::ProofValidationResult::INVALID_SIGNATURE: | |||||
InitError( | |||||
_("the avalanche proof has invalid stake signatures")); | |||||
break; | |||||
case avalanche::ProofValidationResult::TOO_MANY_UTXOS: | |||||
InitError(_("the avalanche proof has too many utxos")); | |||||
deadalnixUnsubmitted Not Done Inline ActionsNow this method constructs a Processor. It has nothing to do with initialization anymore. if it did, it would be setting g_avalanche and doing other avalanche related initialization procedures, which it doesn't. deadalnix: Now this method constructs a Processor. It has nothing to do with initialization anymore. if it… | |||||
break; | |||||
default: | |||||
InitError(_("the avalanche proof is invalid")); | |||||
} | |||||
return nullptr; | |||||
} | |||||
} | |||||
Processor *proc = new Processor(chain, connmanIn, nodePeerManagerIn); | |||||
deadalnixUnsubmitted Not Done Inline ActionsYou are not using the proof you just de-serialized. As it turns out it happens that the constructor will deserialize the same way right now. But this is fragile. You don't want your code to happen to work. You want your code to work by design. deadalnix: You are not using the proof you just de-serialized. As it turns out it happens that the… | |||||
return proc; | |||||
} | |||||
Processor::Processor(interfaces::Chain &chain, CConnman *connmanIn, | Processor::Processor(interfaces::Chain &chain, CConnman *connmanIn, | ||||
NodePeerManager *nodePeerManagerIn) | NodePeerManager *nodePeerManagerIn) | ||||
: connman(connmanIn), nodePeerManager(nodePeerManagerIn), | : connman(connmanIn), nodePeerManager(nodePeerManagerIn), | ||||
queryTimeoutDuration(AVALANCHE_DEFAULT_QUERY_TIMEOUT), round(0), | queryTimeoutDuration(AVALANCHE_DEFAULT_QUERY_TIMEOUT), round(0), | ||||
peerManager(std::make_unique<PeerManager>()) { | peerManager(std::make_unique<PeerManager>()) { | ||||
if (gArgs.IsArgSet("-avasessionkey")) { | if (gArgs.IsArgSet("-avasessionkey")) { | ||||
sessionKey = DecodeSecret(gArgs.GetArg("-avasessionkey", "")); | sessionKey = DecodeSecret(gArgs.GetArg("-avasessionkey", "")); | ||||
} else { | } else { | ||||
▲ Show 20 Lines • Show All 453 Lines • Show Last 20 Lines |
There is no reason to not return a unique pointer here.