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 <reverse_iterator.h> | #include <reverse_iterator.h> | ||||
#include <scheduler.h> | #include <scheduler.h> | ||||
#include <util/bitmanip.h> | #include <util/bitmanip.h> | ||||
#include <util/strencodings.h> | |||||
#include <util/translation.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 184 Lines • ▼ Show 20 Lines | if (argsman.IsArgSet("-avaproof")) { | ||||
} | } | ||||
masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | masterKey = DecodeSecret(argsman.GetArg("-avamasterkey", "")); | ||||
if (!masterKey.IsValid()) { | if (!masterKey.IsValid()) { | ||||
error = _("the avalanche master key is invalid"); | error = _("the avalanche master key is invalid"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
std::string avaproof = argsman.GetArg("-avaproof", ""); | |||||
if (!IsHexNumber(avaproof)) { | |||||
error = strprintf(_("invalid non-hexadecimal avalanche proof [%s]"), | |||||
avaproof); | |||||
return nullptr; | |||||
} | |||||
deadalnix: Put this in the try block so that the string is kept around needlessly. | |||||
peerData = std::make_unique<PeerData>(); | peerData = std::make_unique<PeerData>(); | ||||
{ | try { | ||||
// The proof. | CDataStream stream(ParseHex(avaproof), SER_NETWORK, 0); | ||||
CDataStream stream(ParseHex(argsman.GetArg("-avaproof", "")), | |||||
SER_NETWORK, 0); | |||||
stream >> peerData->proof; | stream >> peerData->proof; | ||||
} catch (const std::exception &e) { | |||||
error = strprintf(_("the avalanche proof is ill-formed [%s]: %s"), | |||||
deadalnixUnsubmitted Not Done Inline ActionsDo these error messages look like other error messages in init.cpp ? I don't think they do. deadalnix: Do these error messages look like other error messages in init.cpp ? I don't think they do. | |||||
avaproof, e.what()); | |||||
return nullptr; | |||||
} | } | ||||
ProofValidationState proof_state; | ProofValidationState proof_state; | ||||
if (!peerData->proof.verify(proof_state)) { | if (!peerData->proof.verify(proof_state)) { | ||||
switch (proof_state.GetResult()) { | switch (proof_state.GetResult()) { | ||||
case ProofValidationResult::NO_STAKE: | case ProofValidationResult::NO_STAKE: | ||||
error = _("the avalanche proof has no stake"); | error = _("the avalanche proof has no stake"); | ||||
return nullptr; | return nullptr; | ||||
Show All 13 Lines | if (argsman.IsArgSet("-avaproof")) { | ||||
AVALANCHE_MAX_PROOF_STAKES); | AVALANCHE_MAX_PROOF_STAKES); | ||||
return nullptr; | return nullptr; | ||||
default: | default: | ||||
error = _("the avalanche proof is invalid"); | error = _("the avalanche proof is invalid"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
if (masterKey.GetPubKey() != peerData->proof.getMaster()) { | |||||
error = _("the master key does not match the proof public key"); | |||||
return nullptr; | |||||
} | |||||
// Generate the delegation to the session key. | // Generate the delegation to the session key. | ||||
DelegationBuilder dgb(peerData->proof); | DelegationBuilder dgb(peerData->proof); | ||||
if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { | if (sessionKey.GetPubKey() != peerData->proof.getMaster()) { | ||||
dgb.addLevel(masterKey, sessionKey.GetPubKey()); | dgb.addLevel(masterKey, sessionKey.GetPubKey()); | ||||
} | } | ||||
peerData->delegation = dgb.build(); | peerData->delegation = dgb.build(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 428 Lines • Show Last 20 Lines |
Put this in the try block so that the string is kept around needlessly.