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 156 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
bool Proof::verify(ProofValidationState &state, const CCoinsView &view) const { | bool Proof::verify(ProofValidationState &state, const CCoinsView &view) const { | ||||
if (!verify(state)) { | if (!verify(state)) { | ||||
// state is set by verify. | // state is set by verify. | ||||
return false; | return false; | ||||
} | } | ||||
const int64_t activeHeight = | |||||
WITH_LOCK(cs_main, return g_chainman.ActiveHeight()); | |||||
const int64_t stakeUtxoMinConfirmations = | |||||
gArgs.GetArg("-avaproofstakeutxoconfirmations", | |||||
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(); | ||||
if ((s.getHeight() + stakeUtxoMinConfirmations) > activeHeight) { | |||||
return state.Invalid( | |||||
ProofValidationResult::IMMATURE_UTXO, "immature-utxo", | |||||
strprintf("TxId: %s, block height: %d, chaintip height: %d", | |||||
s.getUTXO().GetTxId().ToString(), s.getHeight(), | |||||
activeHeight)); | |||||
} | |||||
Coin coin; | Coin coin; | ||||
if (!view.GetCoin(utxo, coin)) { | if (!view.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.isCoinbase() != coin.IsCoinBase()) { | if (s.isCoinbase() != coin.IsCoinBase()) { | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |