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
2 changes: 1 addition & 1 deletion ci/dash/lint-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ iwyu_tool.py \
"src/compat" \
"src/dbwrapper.cpp" \
"src/init" \
"src/kernel/mempool_persist.cpp" \
"src/kernel" \
"src/node/chainstate.cpp" \
"src/node/minisketchwrapper.cpp" \
"src/policy/feerate.cpp" \
Expand Down
9 changes: 5 additions & 4 deletions doc/design/assumeutxo.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ be of use.

Chainstate within the system goes through a number of phases when UTXO snapshots are
used, as managed by `ChainstateManager`. At various points there can be multiple
`CChainState` objects in existence to facilitate both maintaining the network tip and
`Chainstate` objects in existence to facilitate both maintaining the network tip and
performing historical validation of the assumed-valid chain.

It is worth noting that though there are multiple separate chainstates, those
Expand All @@ -53,7 +53,7 @@ data.

### "Normal" operation via initial block download

`ChainstateManager` manages a single CChainState object, for which
`ChainstateManager` manages a single Chainstate object, for which
`m_snapshot_blockhash` is null. This chainstate is (maybe obviously)
considered active. This is the "traditional" mode of operation for dashd.

Expand All @@ -76,8 +76,9 @@ original chainstate remains in use as active.

Once the snapshot chainstate is loaded and validated, it is promoted to active
chainstate and a sync to tip begins. A new chainstate directory is created in the
datadir for the snapshot chainstate called
`chainstate_[SHA256 blockhash of snapshot base block]`.
datadir for the snapshot chainstate called `chainstate_snapshot`. When this directory
is present in the datadir, the snapshot chainstate will be detected and loaded as
active on node startup (via `DetectSnapshotChainstate()`).
Comment thread
thepastaclaw marked this conversation as resolved.

| | |
| ---------- | ----------- |
Expand Down
4 changes: 2 additions & 2 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ void CTxMemPool::UpdateTransactionsFromBlock(...)

```C++
// validation.h
class CChainState
class Chainstate
{
protected:
...
Expand All @@ -1055,7 +1055,7 @@ public:
}

// validation.cpp
bool CChainState::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
bool Chainstate::PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
{
AssertLockNotHeld(m_chainstate_mutex);
AssertLockNotHeld(::cs_main);
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ libbitcoin_node_a_SOURCES = \
node/sync_manager.cpp \
node/transaction.cpp \
node/txreconciliation.cpp \
node/utxo_snapshot.cpp \
noui.cpp \
policy/fees.cpp \
policy/fees_args.cpp \
Expand Down Expand Up @@ -1316,6 +1317,7 @@ libdashkernel_la_SOURCES = \
node/chainstate.cpp \
node/interface_ui.cpp \
node/transaction.cpp \
node/utxo_snapshot.cpp \
policy/feerate.cpp \
policy/fees.cpp \
policy/packages.cpp \
Expand Down
2 changes: 1 addition & 1 deletion src/bench/load_external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void LoadExternalBlockFile(benchmark::Bench& bench)
fclose(file);
}

CChainState& chainstate{testing_setup->m_node.chainman->ActiveChainstate()};
Chainstate& chainstate{testing_setup->m_node.chainman->ActiveChainstate()};
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
FlatFilePos pos;
bench.run([&] {
Expand Down
44 changes: 18 additions & 26 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <masternode/meta.h>
#include <masternode/sync.h>
#include <node/blockstorage.h>
#include <node/caches.h>
#include <node/chainstate.h>
#include <scheduler.h>
#include <script/sigcache.h>
Expand Down Expand Up @@ -101,8 +102,16 @@ int main(int argc, char* argv[])

std::unique_ptr<LLMQContext> llmq_ctx;
std::unique_ptr<CChainstateHelper> chain_helper;
auto rv = node::LoadChainstate(/*fReset=*/false,
std::ref(chainman),
node::CacheSizes cache_sizes;
cache_sizes.block_tree_db = 2 << 20;
cache_sizes.coins_db = 2 << 22;
cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22);
node::ChainstateLoadOptions options;
options.bls_threads = 1;
options.worker_count = 1;
options.max_recsigs_age = 1;
options.check_interrupt = [] { return false; };
auto [status, error] = node::LoadChainstate(chainman,
metaman,
sporkman,
chainlocks,
Expand All @@ -111,38 +120,21 @@ int main(int argc, char* argv[])
dmnman,
evodb,
llmq_ctx,
/*mempool=*/nullptr,
gArgs.GetDataDirNet(),
/*fPruneMode=*/false,
/*fReindexChainState=*/false,
2 << 20,
2 << 22,
(450 << 20) - (2 << 20) - (2 << 22),
/*block_tree_db_in_memory=*/false,
/*coins_db_in_memory=*/false,
/*dash_dbs_in_memory=*/false,
/*bls_threads=*/1,
/*worker_count=*/1,
/*max_recsigs_age=*/1,
/*shutdown_requested=*/[]() { return false; },
/*coins_error_cb=*/[]() {});
if (rv.has_value()) {
cache_sizes,
options);
if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to load Chain state from your datadir." << std::endl;
goto epilogue;
} else {
auto maybe_verify_error = node::VerifyLoadedChainstate(std::ref(chainman),
*evodb,
false,
false,
DEFAULT_CHECKBLOCKS,
DEFAULT_CHECKLEVEL);
if (maybe_verify_error.has_value()) {
std::tie(status, error) = node::VerifyLoadedChainstate(std::ref(chainman), *evodb, options);
if (status != node::ChainstateLoadStatus::SUCCESS) {
std::cerr << "Failed to verify loaded Chain state from your datadir." << std::endl;
goto epilogue;
}
}

for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
for (Chainstate* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
BlockValidationState state;
if (!chainstate->ActivateBestChain(state, nullptr)) {
std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl;
Expand Down Expand Up @@ -283,7 +275,7 @@ int main(int argc, char* argv[])
GetMainSignals().FlushBackgroundCallbacks();
{
LOCK(cs_main);
for (CChainState* chainstate : chainman.GetAll()) {
for (Chainstate* chainstate : chainman.GetAll()) {
if (chainstate->CanFlushToDisk()) {
chainstate->ForceFlushStateToDisk();
chainstate->ResetCoinsViews();
Expand Down
2 changes: 1 addition & 1 deletion src/chainlock/signing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
using node::ReadBlockFromDisk;

namespace chainlock {
ChainLockSigner::ChainLockSigner(CChainState& chainstate, const chainlock::Chainlocks& chainlocks,
ChainLockSigner::ChainLockSigner(Chainstate& chainstate, const chainlock::Chainlocks& chainlocks,
ChainlockHandler& clhandler, const llmq::CInstantSendManager& isman,
const llmq::CQuorumManager& qman, llmq::CSigningManager& sigman,
llmq::CSigSharesManager& shareman, const CMasternodeSync& mn_sync) :
Expand Down
4 changes: 2 additions & 2 deletions src/chainlock/signing.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChainlockHandler;
class ChainLockSigner final : public llmq::CRecoveredSigsListener, public CValidationInterface
{
private:
CChainState& m_chainstate;
Chainstate& m_chainstate;
const chainlock::Chainlocks& m_chainlocks;
ChainlockHandler& m_clhandler;
const llmq::CInstantSendManager& m_isman;
Expand Down Expand Up @@ -58,7 +58,7 @@ class ChainLockSigner final : public llmq::CRecoveredSigsListener, public CValid
ChainLockSigner() = delete;
ChainLockSigner(const ChainLockSigner&) = delete;
ChainLockSigner& operator=(const ChainLockSigner&) = delete;
explicit ChainLockSigner(CChainState& chainstate, const chainlock::Chainlocks& chainlocks,
explicit ChainLockSigner(Chainstate& chainstate, const chainlock::Chainlocks& chainlocks,
ChainlockHandler& clhandler, const llmq::CInstantSendManager& isman,
const llmq::CQuorumManager& qman, llmq::CSigningManager& sigman,
llmq::CSigSharesManager& shareman, const CMasternodeSync& mn_sync);
Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ CCoinJoinClientManager::CCoinJoinClientManager(const std::shared_ptr<wallet::CWa

CCoinJoinClientManager::~CCoinJoinClientManager() = default;

void CCoinJoinClientManager::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
void CCoinJoinClientManager::ProcessMessage(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
{
if (!CCoinJoinClientOptions::IsEnabled()) return;
if (!m_mn_sync.IsBlockchainSynced()) return;
Expand Down Expand Up @@ -89,7 +89,7 @@ CCoinJoinClientSession::CCoinJoinClientSession(const std::shared_ptr<CWallet>& w
m_isman{isman}
{}

void CCoinJoinClientSession::ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
void CCoinJoinClientSession::ProcessMessage(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv)
{
if (!CCoinJoinClientOptions::IsEnabled()) return;
if (!m_mn_sync.IsBlockchainSynced()) return;
Expand Down Expand Up @@ -443,7 +443,7 @@ void CCoinJoinClientSession::ProcessPoolStateUpdate(CCoinJoinStatusUpdate psssup
// check it to make sure it's what we want, then sign it if we agree.
// If we refuse to sign, it's possible we'll be charged collateral
//
bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew)
bool CCoinJoinClientSession::SignFinalTransaction(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew)
{
if (!CCoinJoinClientOptions::IsEnabled()) return false;

Expand Down
6 changes: 3 additions & 3 deletions src/coinjoin/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
void CompletedTransaction(PoolMessage nMessageID);

/// As a client, check and sign the final transaction
bool SignFinalTransaction(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);
bool SignFinalTransaction(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, const CTransaction& finalTransactionNew) EXCLUSIVE_LOCKS_REQUIRED(!cs_coinjoin);

void RelayIn(const CCoinJoinEntry& entry, CConnman& connman) const;

Expand All @@ -128,7 +128,7 @@ class CCoinJoinClientSession : public CCoinJoinBaseSession
CDeterministicMNManager& dmnman, CMasternodeMetaMan& mn_metaman,
const CMasternodeSync& mn_sync, const llmq::CInstantSendManager& isman);

void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv);
void ProcessMessage(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv);

void UnlockCoins();

Expand Down Expand Up @@ -193,7 +193,7 @@ class CCoinJoinClientManager : public interfaces::CoinJoin::Client
const llmq::CInstantSendManager& isman, CoinJoinQueueManager* queueman);
~CCoinJoinClientManager();

void ProcessMessage(CNode& peer, CChainState& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);
void ProcessMessage(CNode& peer, Chainstate& active_chainstate, CConnman& connman, const CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

bool GetMixingMasternodesInfo(std::vector<CDeterministicMNCPtr>& vecDmnsRet) const EXCLUSIVE_LOCKS_REQUIRED(!cs_deqsessions);

Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/coinjoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ std::string CCoinJoinBaseSession::GetStateString() const
}
}

bool CCoinJoinBaseSession::IsValidInOuts(CChainState& active_chainstate, const llmq::CInstantSendManager& isman,
bool CCoinJoinBaseSession::IsValidInOuts(Chainstate& active_chainstate, const llmq::CInstantSendManager& isman,
const CTxMemPool& mempool, const std::vector<CTxIn>& vin,
const std::vector<CTxOut>& vout, PoolMessage& nMessageIDRet,
bool* fConsumeCollateralRet) const
Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/coinjoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <univalue.h>

class CChainState;
class Chainstate;
class CBLSPublicKey;
class CBlockIndex;
class ChainstateManager;
Expand Down Expand Up @@ -304,7 +304,7 @@ class CCoinJoinBaseSession

virtual void SetNull() EXCLUSIVE_LOCKS_REQUIRED(cs_coinjoin);

bool IsValidInOuts(CChainState& active_chainstate, const llmq::CInstantSendManager& isman,
bool IsValidInOuts(Chainstate& active_chainstate, const llmq::CInstantSendManager& isman,
const CTxMemPool& mempool, const std::vector<CTxIn>& vin, const std::vector<CTxOut>& vout,
PoolMessage& nMessageIDRet, bool* fConsumeCollateralRet) const;

Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/walletman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CJWalletManagerImpl final : public CJWalletManager
public:
bool hasQueue(const uint256& hash) const override;
bool doForClient(const std::string& name, const std::function<void(CCoinJoinClientManager&)>& func) override EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet_manager_map);
MessageProcessingResult processMessage(CNode& peer, CChainState& chainstate, CConnman& connman, CTxMemPool& mempool,
MessageProcessingResult processMessage(CNode& peer, Chainstate& chainstate, CConnman& connman, CTxMemPool& mempool,
std::string_view msg_type, CDataStream& vRecv) override EXCLUSIVE_LOCKS_REQUIRED(!cs_ProcessDSQueue, !cs_wallet_manager_map);
std::optional<CCoinJoinQueue> getQueueFromHash(const uint256& hash) const override;
std::optional<int> getQueueSize() const override;
Expand Down Expand Up @@ -205,7 +205,7 @@ void CJWalletManagerImpl::DoMaintenance(CConnman& connman)
}
}

MessageProcessingResult CJWalletManagerImpl::processMessage(CNode& pfrom, CChainState& chainstate, CConnman& connman,
MessageProcessingResult CJWalletManagerImpl::processMessage(CNode& pfrom, Chainstate& chainstate, CConnman& connman,
CTxMemPool& mempool, std::string_view msg_type,
CDataStream& vRecv)
{
Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/walletman.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <string_view>

class CBlockIndex;
class CChainState;
class Chainstate;
class CCoinJoinClientManager;
class CCoinJoinQueue;
class CConnman;
Expand Down Expand Up @@ -51,7 +51,7 @@ class CJWalletManager : public CValidationInterface
//! Execute func under the wallet manager lock for the client identified by name.
//! Returns true if the client was found and func was called, false otherwise.
virtual bool doForClient(const std::string& name, const std::function<void(CCoinJoinClientManager&)>& func) = 0;
virtual MessageProcessingResult processMessage(CNode& peer, CChainState& chainstate, CConnman& connman,
virtual MessageProcessingResult processMessage(CNode& peer, Chainstate& chainstate, CConnman& connman,
CTxMemPool& mempool, std::string_view msg_type, CDataStream& vRecv) = 0;
virtual std::optional<CCoinJoinQueue> getQueueFromHash(const uint256& hash) const = 0;
virtual std::optional<int> getQueueSize() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static leveldb::Options GetOptions(size_t nCacheSize)
}

CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool obfuscate)
: m_name{fs::PathToString(path.stem())}
: m_name{fs::PathToString(path.stem())}, m_path{path}, m_is_memory{fMemory}
{
penv = nullptr;
readoptions.verify_checksums = true;
Expand Down
18 changes: 18 additions & 0 deletions src/dbwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class dbwrapper_error : public std::runtime_error

class CDBWrapper;

namespace dbwrapper {
using leveldb::DestroyDB;
}

/** These should be considered an implementation detail of the specific database.
*/
namespace dbwrapper_private {
Expand Down Expand Up @@ -250,6 +254,12 @@ class CDBWrapper

std::vector<unsigned char> CreateObfuscateKey() const;

//! path to filesystem storage
const fs::path m_path;

//! whether or not the database resides in memory
bool m_is_memory;

public:
/**
* @param[in] path Location in the filesystem where leveldb data will be stored.
Expand Down Expand Up @@ -325,6 +335,14 @@ class CDBWrapper
return WriteBatch(batch, fSync);
}

//! @returns filesystem path to the on-disk data.
std::optional<fs::path> StoragePath() {
if (m_is_memory) {
return {};
}
return m_path;
}

template <typename K>
bool Exists(const K& key) const
{
Expand Down
2 changes: 1 addition & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void BaseIndex::Interrupt()
m_interrupt();
}

bool BaseIndex::Start(CChainState& active_chainstate)
bool BaseIndex::Start(Chainstate& active_chainstate)
{
m_chainstate = &active_chainstate;
// Need to register this ValidationInterface before running Init(), so that
Expand Down
6 changes: 3 additions & 3 deletions src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class CBlock;
class CBlockIndex;
class CChainState;
class Chainstate;

struct IndexSummary {
std::string name;
Expand Down Expand Up @@ -86,7 +86,7 @@ class BaseIndex : public CValidationInterface
virtual bool AllowPrune() const = 0;

protected:
CChainState* m_chainstate{nullptr};
Chainstate* m_chainstate{nullptr};

void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;

Expand Down Expand Up @@ -142,7 +142,7 @@ class BaseIndex : public CValidationInterface

/// Start initializes the sync state and registers the instance as a
/// ValidationInterface so that it stays in sync with blockchain updates.
[[nodiscard]] bool Start(CChainState& active_chainstate);
[[nodiscard]] bool Start(Chainstate& active_chainstate);

/// Stops the instance from staying in sync with blockchain updates.
void Stop();
Expand Down
Loading