chainparams: add blockhash to AssumeutxoData

This allows us to reference assumeutxo configuration by blockhash as
well as height; this is helpful in future changes when we want to
reference assumeutxo configurations before the block index is loaded.
This commit is contained in:
James O'Beirne
2023-05-25 13:05:27 -04:00
parent c711ca186f
commit 434495a8c1
7 changed files with 49 additions and 49 deletions

View File

@@ -12,6 +12,7 @@
#include <uint256.h>
#include <util/chaintype.h>
#include <util/hash_type.h>
#include <util/vector.h>
#include <cstdint>
#include <iterator>
@@ -44,17 +45,21 @@ struct AssumeutxoHash : public BaseHash<uint256> {
* as valid.
*/
struct AssumeutxoData {
int height;
//! The expected hash of the deserialized UTXO set.
const AssumeutxoHash hash_serialized;
AssumeutxoHash hash_serialized;
//! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
//!
//! We need to hardcode the value here because this is computed cumulatively using block data,
//! which we do not necessarily have at the time of snapshot load.
const unsigned int nChainTx;
};
unsigned int nChainTx;
using MapAssumeutxo = std::map<int, const AssumeutxoData>;
//! The hash of the base block for this snapshot. Used to refer to assumeutxo data
//! prior to having a loaded blockindex.
uint256 blockhash;
};
/**
* Holds various statistics on transactions within a chain. Used to estimate
@@ -114,9 +119,14 @@ public:
const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
const CCheckpointData& Checkpoints() const { return checkpointData; }
//! Get allowed assumeutxo configuration.
//! @see ChainstateManager
const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
{
return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.height == height; });
}
std::optional<AssumeutxoData> AssumeutxoForBlockhash(const uint256& blockhash) const
{
return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.blockhash == blockhash; });
}
const ChainTxData& TxData() const { return chainTxData; }
@@ -169,7 +179,7 @@ protected:
bool fDefaultConsistencyChecks;
bool m_is_mockable_chain;
CCheckpointData checkpointData;
MapAssumeutxo m_assumeutxo_data;
std::vector<AssumeutxoData> m_assumeutxo_data;
ChainTxData chainTxData;
};