40 int main(
int argc,
char* argv[])
45 <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
46 <<
"Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl
48 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl
49 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
70 ValidationSignals validation_signals{std::make_unique<util::ImmediateTaskRunner>()};
77 std::cout <<
"Block tip changed" << std::endl;
82 std::cout <<
"Header tip changed: " << height <<
", " << timestamp <<
", " << presync << std::endl;
86 std::cout <<
"Progress: " << title.
original <<
", " << progress_percent <<
", " << resume_possible << std::endl;
90 std::cout <<
"Warning: " << warning.
original << std::endl;
94 std::cerr <<
"Error flushing block data to disk: " << message.
original << std::endl;
98 std::cerr <<
"Error: " << message.
original << std::endl;
101 auto notifications = std::make_unique<KernelNotifications>();
108 .datadir = abs_datadir,
109 .notifications = *notifications,
110 .signals = &validation_signals,
114 .blocks_dir = abs_datadir /
"blocks",
115 .notifications = chainman_opts.notifications,
123 cache_sizes.
coins = (450 << 20) - (2 << 20) - (2 << 22);
127 std::cerr <<
"Failed to load Chain state from your datadir." << std::endl;
132 std::cerr <<
"Failed to verify loaded Chain state from your datadir." << std::endl;
139 if (!chainstate->ActivateBestChain(state,
nullptr)) {
140 std::cerr <<
"Failed to connect best block (" << state.
ToString() <<
")" << std::endl;
147 <<
"Hello! I'm going to print out some information about your datadir." << std::endl
149 <<
"Path: " << abs_datadir << std::endl;
151 LOCK(chainman.GetMutex());
153 <<
"\t" <<
"Reindexing: " << std::boolalpha <<
node::fReindex.load() << std::noboolalpha << std::endl
154 <<
"\t" <<
"Snapshot Active: " << std::boolalpha << chainman.IsSnapshotActive() << std::noboolalpha << std::endl
155 <<
"\t" <<
"Active Height: " << chainman.ActiveHeight() << std::endl
156 <<
"\t" <<
"Active IBD: " << std::boolalpha << chainman.IsInitialBlockDownload() << std::noboolalpha << std::endl;
159 std::cout <<
"\t" << tip->
ToString() << std::endl;
163 for (std::string line; std::getline(std::cin, line);) {
165 std::cerr <<
"Empty line found" << std::endl;
169 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
170 CBlock& block = *blockptr;
173 std::cerr <<
"Block decode failed" << std::endl;
177 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
178 std::cerr <<
"Block does not start with a coinbase" << std::endl;
185 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
188 std::cerr <<
"duplicate" << std::endl;
192 std::cerr <<
"duplicate-invalid" << std::endl;
202 chainman.UpdateUncommittedBlockStructures(block, pindex);
227 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
228 validation_signals.RegisterSharedValidationInterface(sc);
229 bool accepted = chainman.ProcessNewBlock(blockptr,
true,
true, &new_block);
230 validation_signals.UnregisterSharedValidationInterface(sc);
231 if (!new_block && accepted) {
232 std::cerr <<
"duplicate" << std::endl;
236 std::cerr <<
"inconclusive" << std::endl;
239 std::cout << sc->state.ToString() << std::endl;
240 switch (sc->state.GetResult()) {
242 std::cerr <<
"initial value. Block has not yet been rejected" << std::endl;
245 std::cerr <<
"the block header may be on a too-little-work chain" << std::endl;
248 std::cerr <<
"invalid by consensus rules (excluding any below reasons)" << std::endl;
251 std::cerr <<
"Invalid by a change to consensus rules more recent than SegWit." << std::endl;
254 std::cerr <<
"this block was cached as being invalid and we didn't store the reason why" << std::endl;
257 std::cerr <<
"invalid proof of work or time too old" << std::endl;
260 std::cerr <<
"the block's data didn't match the data committed to by the PoW" << std::endl;
263 std::cerr <<
"We don't have the previous block the checked one is built on" << std::endl;
266 std::cerr <<
"A block this one builds on is invalid" << std::endl;
269 std::cerr <<
"block timestamp was > 2 hours in the future (or our clock is bad)" << std::endl;
272 std::cerr <<
"the block failed to meet one of our checkpoints" << std::endl;
280 if (chainman.m_thread_load.joinable()) chainman.m_thread_load.join();
282 validation_signals.FlushBackgroundCallbacks();
285 for (
Chainstate* chainstate : chainman.GetAll()) {
286 if (chainstate->CanFlushToDisk()) {
287 chainstate->ForceFlushStateToDisk();
288 chainstate->ResetCoinsViews();
int main(int argc, char *argv[])
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok.
#define Assert(val)
Identity function.
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
std::string ToString() const
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
static std::unique_ptr< const CChainParams > Main()
Implement this to subscribe to events generated in validation and mempool.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
std::string ToString() const
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
A base class defining functions for notifying about certain kernel events.
virtual void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
virtual void fatalError(const bilingual_str &message)
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
virtual void warning(const bilingual_str &warning)
virtual void progress(const bilingual_str &title, int progress_percent, bool resume_possible)
virtual void flushError(const bilingual_str &message)
The flush error notification is sent to notify the user that an error occurred while flushing block d...
virtual InterruptResult blockTip(SynchronizationState state, CBlockIndex &index)
void BlockChecked(const CBlock &block, const BlockValidationState &stateIn) override
Notifies listeners of a block validation result.
submitblock_StateCatcher(const uint256 &hashIn)
BlockValidationState state
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
@ BLOCK_CHECKPOINT
the block failed to meet one of our checkpoints
@ BLOCK_RECENT_CONSENSUS_CHANGE
Invalid by a change to consensus rules more recent than SegWit.
@ BLOCK_HEADER_LOW_WORK
the block header may be on a too-little-work chain
@ BLOCK_INVALID_HEADER
invalid proof of work or time too old
@ BLOCK_CACHED_INVALID
this block was cached as being invalid and we didn't store the reason why
@ BLOCK_CONSENSUS
invalid by consensus rules (excluding any below reasons)
@ BLOCK_MISSING_PREV
We don't have the previous block the checked one is built on.
@ BLOCK_INVALID_PREV
A block this one builds on is invalid.
@ BLOCK_MUTATED
the block's data didn't match the data committed to by the PoW
@ BLOCK_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
@ BLOCK_RESULT_UNSET
initial value. Block has not yet been rejected
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
static path absolute(const path &p)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
util::Result< void > SanityChecks(const Context &)
Ensure a usable environment with all necessary library support.
ChainstateLoadResult LoadChainstate(ChainstateManager &chainman, const CacheSizes &cache_sizes, const ChainstateLoadOptions &options)
This sequence can have 4 types of outcomes:
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
std::atomic_bool fReindex
bool InitSignatureCache(size_t max_size_bytes)
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
const CChainParams & chainparams
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
const CChainParams & chainparams
Context struct holding the kernel library's logically global state, and passed to external libbitcoin...
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
This header provides an interface and simple implementation for a task runner.
bool InitScriptExecutionCache(size_t max_size_bytes)
Initializes the script-execution cache.
SynchronizationState
Current sync state passed to tip changed callbacks.