Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/proof.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 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/proof.h> | #include <avalanche/proof.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <coins.h> | #include <coins.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
#include <script/standard.h> | #include <script/standard.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <validation.h> // For g_chainman | |||||
#include <tinyformat.h> | #include <tinyformat.h> | ||||
#include <numeric> | #include <numeric> | ||||
#include <unordered_set> | #include <unordered_set> | ||||
namespace avalanche { | namespace avalanche { | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | for (const SignedStake &ss : stakes) { | ||||
"invalid-stake-signature", | "invalid-stake-signature", | ||||
strprintf("TxId: %s", s.getUTXO().GetTxId().ToString())); | strprintf("TxId: %s", s.getUTXO().GetTxId().ToString())); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool Proof::verify(ProofValidationState &state, const CCoinsView &view) const { | bool Proof::verify(ProofValidationState &state, | ||||
const ChainstateManager &chainman) const { | |||||
AssertLockHeld(cs_main); | |||||
if (!verify(state)) { | if (!verify(state)) { | ||||
// state is set by verify. | // state is set by verify. | ||||
return false; | return false; | ||||
} | } | ||||
const int64_t activeHeight = | const int64_t activeHeight = chainman.ActiveHeight(); | ||||
WITH_LOCK(cs_main, return g_chainman.ActiveHeight()); | |||||
const int64_t stakeUtxoMinConfirmations = | const int64_t stakeUtxoMinConfirmations = | ||||
gArgs.GetArg("-avaproofstakeutxoconfirmations", | gArgs.GetArg("-avaproofstakeutxoconfirmations", | ||||
AVALANCHE_DEFAULT_STAKE_UTXO_CONFIRMATIONS); | AVALANCHE_DEFAULT_STAKE_UTXO_CONFIRMATIONS); | ||||
for (const SignedStake &ss : stakes) { | for (const SignedStake &ss : stakes) { | ||||
const Stake &s = ss.getStake(); | const Stake &s = ss.getStake(); | ||||
const COutPoint &utxo = s.getUTXO(); | const COutPoint &utxo = s.getUTXO(); | ||||
Coin coin; | Coin coin; | ||||
if (!view.GetCoin(utxo, coin)) { | if (!chainman.ActiveChainstate().CoinsTip().GetCoin(utxo, coin)) { | ||||
// The coins are not in the UTXO set. | // The coins are not in the UTXO set. | ||||
return state.Invalid(ProofValidationResult::MISSING_UTXO, | return state.Invalid(ProofValidationResult::MISSING_UTXO, | ||||
"utxo-missing-or-spent"); | "utxo-missing-or-spent"); | ||||
} | } | ||||
if ((s.getHeight() + stakeUtxoMinConfirmations - 1) > activeHeight) { | if ((s.getHeight() + stakeUtxoMinConfirmations - 1) > activeHeight) { | ||||
return state.Invalid( | return state.Invalid( | ||||
ProofValidationResult::IMMATURE_UTXO, "immature-utxo", | ProofValidationResult::IMMATURE_UTXO, "immature-utxo", | ||||
▲ Show 20 Lines • Show All 57 Lines • Show Last 20 Lines |