aboutsummaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/chain.cpp11
-rw-r--r--src/kernel/chain.h20
-rw-r--r--src/kernel/chainparams.cpp37
-rw-r--r--src/kernel/chainparams.h26
4 files changed, 77 insertions, 17 deletions
diff --git a/src/kernel/chain.cpp b/src/kernel/chain.cpp
index 1c877866d0..318c956b38 100644
--- a/src/kernel/chain.cpp
+++ b/src/kernel/chain.cpp
@@ -4,6 +4,7 @@
#include <chain.h>
#include <interfaces/chain.h>
+#include <kernel/chain.h>
#include <sync.h>
#include <uint256.h>
@@ -25,3 +26,13 @@ interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data
return info;
}
} // namespace kernel
+
+std::ostream& operator<<(std::ostream& os, const ChainstateRole& role) {
+ switch(role) {
+ case ChainstateRole::NORMAL: os << "normal"; break;
+ case ChainstateRole::ASSUMEDVALID: os << "assumedvalid"; break;
+ case ChainstateRole::BACKGROUND: os << "background"; break;
+ default: os.setstate(std::ios_base::failbit);
+ }
+ return os;
+}
diff --git a/src/kernel/chain.h b/src/kernel/chain.h
index f0750f8266..feba24a557 100644
--- a/src/kernel/chain.h
+++ b/src/kernel/chain.h
@@ -5,6 +5,8 @@
#ifndef BITCOIN_KERNEL_CHAIN_H
#define BITCOIN_KERNEL_CHAIN_H
+#include<iostream>
+
class CBlock;
class CBlockIndex;
namespace interfaces {
@@ -14,6 +16,24 @@ struct BlockInfo;
namespace kernel {
//! Return data from block index.
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* block_index, const CBlock* data = nullptr);
+
} // namespace kernel
+//! This enum describes the various roles a specific Chainstate instance can take.
+//! Other parts of the system sometimes need to vary in behavior depending on the
+//! existence of a background validation chainstate, e.g. when building indexes.
+enum class ChainstateRole {
+ // Single chainstate in use, "normal" IBD mode.
+ NORMAL,
+
+ // Doing IBD-style validation in the background. Implies use of an assumed-valid
+ // chainstate.
+ BACKGROUND,
+
+ // Active assumed-valid chainstate. Implies use of a background IBD chainstate.
+ ASSUMEDVALID,
+};
+
+std::ostream& operator<<(std::ostream& os, const ChainstateRole& role);
+
#endif // BITCOIN_KERNEL_CHAIN_H
diff --git a/src/kernel/chainparams.cpp b/src/kernel/chainparams.cpp
index 7e69c097a6..5e893a3f58 100644
--- a/src/kernel/chainparams.cpp
+++ b/src/kernel/chainparams.cpp
@@ -172,8 +172,8 @@ public:
}
};
- m_assumeutxo_data = MapAssumeutxo{
- // TODO to be specified in a future patch.
+ m_assumeutxo_data = {
+ // TODO to be specified in a future patch.
};
chainTxData = ChainTxData{
@@ -266,8 +266,13 @@ public:
}
};
- m_assumeutxo_data = MapAssumeutxo{
- // TODO to be specified in a future patch.
+ m_assumeutxo_data = {
+ {
+ .height = 2'500'000,
+ .hash_serialized = AssumeutxoHash{uint256S("0x2a8fdefef3bf75fa00540ccaaaba4b5281bea94229327bdb0f7416ef1e7a645c")},
+ .nChainTx = 66484552,
+ .blockhash = uint256S("0x0000000000000093bcb68c03a9a168ae252572d348a2eaeba2cdf9231d73206f")
+ }
};
chainTxData = ChainTxData{
@@ -370,6 +375,15 @@ public:
vFixedSeeds.clear();
+ m_assumeutxo_data = {
+ {
+ .height = 160'000,
+ .hash_serialized = AssumeutxoHash{uint256S("0x5225141cb62dee63ab3be95f9b03d60801f264010b1816d4bd00618b2736e7be")},
+ .nChainTx = 2289496,
+ .blockhash = uint256S("0x0000003ca3c99aff040f2563c2ad8f8ec88bd0fd6b8f0895cfaf1ef90353a62c")
+ }
+ };
+
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
@@ -477,14 +491,19 @@ public:
}
};
- m_assumeutxo_data = MapAssumeutxo{
+ m_assumeutxo_data = {
{
- 110,
- {AssumeutxoHash{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618")}, 110},
+ .height = 110,
+ .hash_serialized = AssumeutxoHash{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618")},
+ .nChainTx = 110,
+ .blockhash = uint256S("0x696e92821f65549c7ee134edceeeeaaa4105647a3c4fd9f298c0aec0ab50425c")
},
{
- 200,
- {AssumeutxoHash{uint256S("0x51c8d11d8b5c1de51543c579736e786aa2736206d1e11e627568029ce092cf62")}, 200},
+ // For use by test/functional/feature_assumeutxo.py
+ .height = 299,
+ .hash_serialized = AssumeutxoHash{uint256S("0xef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0")},
+ .nChainTx = 300,
+ .blockhash = uint256S("0x7e0517ef3ea6ecbed9117858e42eedc8eb39e8698a38dcbd1b3962a283233f4c")
},
};
diff --git a/src/kernel/chainparams.h b/src/kernel/chainparams.h
index ec1697493c..7a5539bc71 100644
--- a/src/kernel/chainparams.h
+++ b/src/kernel/chainparams.h
@@ -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;
};