Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
node/txdownloadman_impl.cpp
node/txorphanage.cpp
node/txreconciliation.cpp
node/utxo_snapshot.cpp
node/warnings.cpp
noui.cpp
policy/ephemeral_policy.cpp
Expand Down
22 changes: 6 additions & 16 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,15 @@ enum BlockStatus : uint32_t {
* sigops, size, merkle root. Implies all parents are at least TREE but not necessarily TRANSACTIONS.
*
* If a block's validity is at least VALID_TRANSACTIONS, CBlockIndex::nTx will be set. If a block and all previous
* blocks back to the genesis block or an assumeutxo snapshot block are at least VALID_TRANSACTIONS,
* CBlockIndex::m_chain_tx_count will be set.
* blocks back to the genesis block are at least VALID_TRANSACTIONS, CBlockIndex::m_chain_tx_count will be set.
*/
BLOCK_VALID_TRANSACTIONS = 3,

//! Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends, BIP30.
//! Implies all previous blocks back to the genesis block or an assumeutxo snapshot block are at least VALID_CHAIN.
//! Implies all previous blocks back to the genesis block are at least VALID_CHAIN.
BLOCK_VALID_CHAIN = 4,

//! Scripts & signatures ok. Implies all previous blocks back to the genesis block or an assumeutxo snapshot block
//! are at least VALID_SCRIPTS.
//! Scripts & signatures ok. Implies all previous blocks back to the genesis block are at least VALID_SCRIPTS.
BLOCK_VALID_SCRIPTS = 5,

//! All validity bits.
Expand All @@ -81,8 +79,7 @@ enum BlockStatus : uint32_t {

BLOCK_OPT_WITNESS = 128, //!< block data in blk*.dat was received with a witness-enforcing client

BLOCK_STATUS_RESERVED = 256, //!< Unused flag that was previously set on assumeutxo snapshot blocks and their
//!< ancestors before they were validated, and unset when they were validated.
BLOCK_STATUS_RESERVED = 256, //!< Unused flag retained for backward compatibility with existing block index entries on disk.
};

/** The block chain is a tree shaped structure starting with the
Expand Down Expand Up @@ -124,16 +121,12 @@ class CBlockIndex

//! (memory only) Number of transactions in the chain up to and including this block.
//! This value will be non-zero if this block and all previous blocks back
//! to the genesis block or an assumeutxo snapshot block have reached the
//! VALID_TRANSACTIONS level.
//! to the genesis block have reached the VALID_TRANSACTIONS level.
uint64_t m_chain_tx_count{0};

//! Verification status of this block. See enum BlockStatus
//!
//! Note: this value is modified to show BLOCK_OPT_WITNESS during UTXO snapshot
//! load to avoid a spurious startup failure requiring -reindex.
//! @sa NeedsRedownload
//! @sa ActivateSnapshot
uint32_t nStatus GUARDED_BY(::cs_main){0};

//! block header
Expand Down Expand Up @@ -202,14 +195,11 @@ class CBlockIndex
}

/**
* Check whether this block and all previous blocks back to the genesis block or an assumeutxo snapshot block have
* Check whether this block and all previous blocks back to the genesis block have
* reached VALID_TRANSACTIONS and had transactions downloaded (and stored to disk) at some point.
*
* Does not imply the transactions are consensus-valid (ConnectTip might fail)
* Does not imply the transactions are still stored on disk. (IsBlockPruned might return true)
*
* Note that this will be true for the snapshot base block, if one is loaded, since its m_chain_tx_count value will have
* been set manually based on the related AssumeutxoData entry.
*/
bool HaveNumChainTxs() const { return m_chain_tx_count != 0; }

Expand Down
4 changes: 2 additions & 2 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ class CCoinsViewCache : public CCoinsViewBacked
* Emplace a coin into cacheCoins without performing any checks, marking
* the emplaced coin as dirty.
*
* NOT FOR GENERAL USE. Used only when loading coins from a UTXO snapshot.
* @sa ChainstateManager::PopulateAndValidateSnapshot()
* NOT FOR GENERAL USE. Bypasses normal cache-state bookkeeping; intended
* only for bulk loading paths and tests that have to fabricate coin entries.
*/
void EmplaceCoinInternalDANGER(COutPoint&& outpoint, Coin&& coin);

Expand Down
41 changes: 12 additions & 29 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,8 @@ void Shutdown(NodeContext& node)
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
if (node.chainman) {
LOCK(cs_main);
for (const auto& chainstate : node.chainman->m_chainstates) {
if (chainstate->CanFlushToDisk()) {
chainstate->ForceFlushStateToDisk();
}
if (node.chainman->m_chainstate && node.chainman->m_chainstate->CanFlushToDisk()) {
node.chainman->m_chainstate->ForceFlushStateToDisk();
}
}

Expand All @@ -352,17 +350,13 @@ void Shutdown(NodeContext& node)

// Any future callbacks will be dropped. This should absolutely be safe - if
// missing a callback results in an unrecoverable situation, unclean shutdown
// would too. The only reason to do the above flushes is to let the wallet catch
// up with our current chain to avoid any strange pruning edge cases and make
// next startup faster by avoiding rescan.
// would too.

if (node.chainman) {
LOCK(cs_main);
for (const auto& chainstate : node.chainman->m_chainstates) {
if (chainstate->CanFlushToDisk()) {
chainstate->ForceFlushStateToDisk();
chainstate->ResetCoinsViews();
}
if (node.chainman->m_chainstate && node.chainman->m_chainstate->CanFlushToDisk()) {
node.chainman->m_chainstate->ForceFlushStateToDisk();
node.chainman->m_chainstate->ResetCoinsViews();
}
}

Expand Down Expand Up @@ -500,8 +494,8 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks and enables automatic pruning of old blocks if a target size in MiB is provided. "
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
"(default: 0 = disable pruning blocks, 1 = allow manual pruning via RPC, >=%u = automatically prune block files to stay under the specified target size in MiB)", MIN_DISK_SPACE_FOR_BLOCK_FILES / 1_MiB), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-reindex", "If enabled, wipe chain state and block index, and rebuild them from blk*.dat files on disk. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-reindex-chainstate", "If enabled, wipe chain state, and rebuild it from blk*.dat files on disk. If an assumeutxo snapshot was loaded, its chainstate will be wiped as well. The snapshot can then be reloaded via RPC.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-reindex", "If enabled, wipe chain state and block index, and rebuild them from blk*.dat files on disk.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-reindex-chainstate", "If enabled, wipe chain state, and rebuild it from blk*.dat files on disk.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-settings=<file>", strprintf("Specify path to dynamic settings data file. Can be disabled with -nosettings. File is written at runtime and not meant to be edited by users (use %s instead for custom settings). Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME, BITCOIN_SETTINGS_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
#if HAVE_SYSTEM
argsman.AddArg("-startupnotify=<cmd>", "Execute command on startup.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
Expand Down Expand Up @@ -1298,12 +1292,6 @@ static ChainstateLoadResult InitAndLoadChainstate(
ChainstateManager& chainman = *node.chainman;
if (chainman.m_interrupt) return {ChainstateLoadStatus::INTERRUPTED, {}};

chainman.snapshot_download_completed = [&node]() {
if (!node.chainman->m_blockman.IsPruneMode()) {
LogInfo("[snapshot] re-enabling NODE_NETWORK services");
node.connman->AddLocalServices(NODE_NETWORK);
}
};
node::ChainstateLoadOptions options;
options.mempool = Assert(node.mempool.get());
options.wipe_chainstate_db = do_reindex || do_reindex_chainstate;
Expand Down Expand Up @@ -1803,19 +1791,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
if (chainman.m_blockman.IsPruneMode()) {
if (chainman.m_blockman.m_blockfiles_indexed) {
LOCK(cs_main);
for (const auto& chainstate : chainman.m_chainstates) {
if (chainman.m_chainstate) {
uiInterface.InitMessage(_("Pruning blockstore…"));
chainstate->PruneAndFlush();
chainman.m_chainstate->PruneAndFlush();
}
}
} else {
// Prior to setting NODE_NETWORK, check if we can provide historical blocks.
if (!WITH_LOCK(chainman.GetMutex(), return chainman.HistoricalChainstate())) {
LogInfo("Setting NODE_NETWORK in non-prune mode");
g_local_services = ServiceFlags(g_local_services | NODE_NETWORK);
} else {
LogInfo("Running node in NODE_NETWORK_LIMITED mode until snapshot background sync completes");
}
LogInfo("Setting NODE_NETWORK in non-prune mode");
g_local_services = ServiceFlags(g_local_services | NODE_NETWORK);
}

// ********************************************************* Step 11: import blocks
Expand Down
12 changes: 2 additions & 10 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ enum class RBFTransactionState;
struct bilingual_str;
struct CBlockLocator;
struct FeeCalculation;
namespace kernel {
struct ChainstateRole;
} // namespace kernel
namespace node {
struct NodeContext;
} // namespace node
Expand Down Expand Up @@ -299,10 +296,10 @@ class Chain
virtual ~Notifications() = default;
virtual void transactionAddedToMempool(const CTransactionRef& tx) {}
virtual void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {}
virtual void blockConnected(const kernel::ChainstateRole& role, const BlockInfo& block) {}
virtual void blockConnected(const BlockInfo& block) {}
virtual void blockDisconnected(const BlockInfo& block) {}
virtual void updatedBlockTip() {}
virtual void chainStateFlushed(const kernel::ChainstateRole& role, const CBlockLocator& locator) {}
virtual void chainStateFlushed(const CBlockLocator& locator) {}
};

//! Options specifying which chain notifications are required.
Expand Down Expand Up @@ -373,11 +370,6 @@ class Chain
//! removed transactions and already added new transactions.
virtual void requestMempoolTransactions(Notifications& notifications) = 0;

//! Return true if an assumed-valid snapshot is in use. Note that this
//! returns true even after the snapshot is validated, until the next node
//! restart.
virtual bool hasAssumedValidChain() = 0;

//! Get internal node context. Useful for testing, but not
//! accessible across processes.
virtual node::NodeContext* context() { return nullptr; }
Expand Down
1 change: 0 additions & 1 deletion src/kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ add_library(bitcoinkernel
../logging.cpp
../node/blockstorage.cpp
../node/chainstate.cpp
../node/utxo_snapshot.cpp
../policy/ephemeral_policy.cpp
../policy/feerate.cpp
../policy/packages.cpp
Expand Down
14 changes: 6 additions & 8 deletions src/kernel/bitcoinkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace Consensus {
struct Params;
} // namespace Consensus

using kernel::ChainstateRole;
using util::ImmediateTaskRunner;

// Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the
Expand Down Expand Up @@ -365,7 +364,7 @@ class KernelValidationInterface final : public CValidationInterface
}
}

void BlockConnected(const ChainstateRole& role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override
{
if (m_cbs.block_connected) {
m_cbs.block_connected(m_cbs.user_data,
Expand Down Expand Up @@ -1082,12 +1081,11 @@ const btck_BlockTreeEntry* btck_chainstate_manager_get_best_entry(const btck_Cha
void btck_chainstate_manager_destroy(btck_ChainstateManager* chainman)
{
{
LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex());
for (const auto& chainstate : btck_ChainstateManager::get(chainman).m_chainman->m_chainstates) {
if (chainstate->CanFlushToDisk()) {
chainstate->ForceFlushStateToDisk();
chainstate->ResetCoinsViews();
}
auto& cm{*btck_ChainstateManager::get(chainman).m_chainman};
LOCK(cm.GetMutex());
if (cm.m_chainstate && cm.m_chainstate->CanFlushToDisk()) {
cm.m_chainstate->ForceFlushStateToDisk();
cm.m_chainstate->ResetCoinsViews();
}
}

Expand Down
14 changes: 0 additions & 14 deletions src/kernel/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

#include <chain.h>
#include <kernel/cs_main.h>
#include <kernel/types.h>
#include <sync.h>
#include <uint256.h>

class CBlock;

using kernel::ChainstateRole;

namespace kernel {
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data)
{
Expand All @@ -29,15 +26,4 @@ interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* index, const CBlock* data
info.data = data;
return info;
}

std::ostream& operator<<(std::ostream& os, const ChainstateRole& role) {
if (!role.validated) {
os << "assumedvalid";
} else if (role.historical) {
os << "background";
} else {
os << "normal";
}
return os;
}
} // namespace kernel
4 changes: 0 additions & 4 deletions src/kernel/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include <attributes.h>

#include <iostream>

class CBlock;
class CBlockIndex;
class CBlockUndo;
Expand All @@ -33,10 +31,8 @@ struct BlockInfo {
} // namespace interfaces

namespace kernel {
struct ChainstateRole;
//! Return data from block index.
interfaces::BlockInfo MakeBlockInfo(const CBlockIndex* block_index, const CBlock* data = nullptr);
std::ostream& operator<<(std::ostream& os, const ChainstateRole& role);
} // namespace kernel

#endif // BITCOIN_KERNEL_CHAIN_H
Loading
Loading