44int main(
int argc,
char *argv[]) {
53 std::cerr <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
54 <<
"Display DATADIR information, and process hex-encoded "
55 "blocks on standard input."
58 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
59 "ONLY, AND EXPECTED TO"
61 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
88 [&] { scheduler.serviceQueue(); });
91 scheduler.scheduleEvery(
96 std::chrono::minutes{1});
103 std::cout <<
"Block tip changed" << std::endl;
106 bool presync)
override {
107 std::cout <<
"Header tip changed: " << height <<
", " << timestamp
108 <<
", " << presync << std::endl;
111 bool resume_possible)
override {
112 std::cout <<
"Progress: " << title.
original <<
", "
113 << progress_percent <<
", " << resume_possible
116 void warning(
const std::string &warning)
override {
117 std::cout <<
"Warning: " << warning << std::endl;
119 void flushError(
const std::string &debug_message)
override {
120 std::cerr <<
"Error flushing block data to disk: " << debug_message
123 void fatalError(
const std::string &debug_message,
125 std::cerr <<
"Error: " << debug_message << std::endl;
126 std::cerr << (user_message.
empty()
127 ?
"A fatal internal error occurred."
132 auto notifications = std::make_unique<KernelNotifications>();
139 .notifications = *notifications,
142 .
chainparams = chainman_opts.config.GetChainParams(),
144 .notifications = chainman_opts.notifications,
154 std::cerr <<
"Failed to load Chain state from your datadir."
160 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
168 if (!chainstate->ActivateBestChain(state,
nullptr)) {
169 std::cerr <<
"Failed to connect best block (" << state.
ToString()
177 <<
"Hello! I'm going to print out some information about your datadir."
180 LOCK(chainman.GetMutex());
185 << std::noboolalpha << std::endl
187 <<
"Snapshot Active: " << std::boolalpha
188 << chainman.IsSnapshotActive() << std::noboolalpha
191 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
193 <<
"Active IBD: " << std::boolalpha
194 << chainman.IsInitialBlockDownload() << std::noboolalpha
198 std::cout <<
"\t" << tip->
ToString() << std::endl;
202 for (std::string line; std::getline(std::cin, line);) {
204 std::cerr <<
"Empty line found" << std::endl;
208 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
209 CBlock &block = *blockptr;
212 std::cerr <<
"Block decode failed" << std::endl;
216 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
217 std::cerr <<
"Block does not start with a coinbase" << std::endl;
225 chainman.m_blockman.LookupBlockIndex(hash);
228 std::cerr <<
"Duplicate" << std::endl;
231 if (pindex->nStatus.hasFailed()) {
232 std::cerr <<
"Duplicate-invalid" << std::endl;
260 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
262 bool accepted = chainman.ProcessNewBlock(blockptr,
267 if (!new_block && accepted) {
268 std::cerr <<
"Duplicate" << std::endl;
272 std::cerr <<
"Inconclusive" << std::endl;
275 std::cout << sc->state.ToString() << std::endl;
276 switch (sc->state.GetResult()) {
278 std::cerr <<
"Initial value. Block has not yet been rejected"
283 <<
"the block header may be on a too-little-work chain"
287 std::cerr <<
"Invalid by consensus rules (excluding any below "
292 std::cerr <<
"This block was cached as being invalid and we "
293 "didn't store the reason why"
297 std::cerr <<
"Invalid proof of work or time too old"
301 std::cerr <<
"The block's data didn't match the data committed "
306 std::cerr <<
"We don't have the previous block the checked one "
311 std::cerr <<
"A block this one builds on is invalid"
315 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
320 std::cerr <<
"The block failed to meet one of our checkpoints"
330 if (chainman.m_thread_load.joinable()) {
331 chainman.m_thread_load.join();
338 for (
Chainstate *chainstate : chainman.GetAll()) {
339 if (chainstate->CanFlushToDisk()) {
340 chainstate->ForceFlushStateToDisk();
341 chainstate->ResetCoinsViews();
int main(int argc, char *argv[])
@ SCRIPTS
Scripts & signatures ok.
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given BIP70 chain name.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
fs::path GetBlocksDirPath() const
Get blocks directory path.
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
This offers a slight speedup and slightly smaller memory usage compared to leaving the logging system...
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
bool IsValid(enum BlockValidity nUpTo=BlockValidity::TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
std::string ToString() const
static std::unique_ptr< const CChainParams > Main(const ChainOptions &options)
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once)
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
Simple class for background tasks that should be run periodically or once "after a while".
std::thread m_service_thread
Implement this to subscribe to events generated in validation.
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...
virtual void SetChainParams(const CChainParams chainParamsIn)=0
std::string ToString() const
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 flushError(const std::string &debug_message)
The flush error notification is sent to notify the user that an error occurred while flushing block d...
virtual void fatalError(const std::string &debug_message, const bilingual_str &user_message={})
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
virtual void warning(const std::string &warning)
virtual void progress(const bilingual_str &title, int progress_percent, bool resume_possible)
virtual void 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
const Config & GetConfig()
@ BLOCK_CHECKPOINT
the block failed to meet one of our checkpoints
@ 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 constexpr int64_t DEFAULT_KERNEL_CACHE
Suggested default amount of cache reserved for the kernel (bytes)
BCLog::Logger & LogInstance()
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...
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)
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
std::atomic_bool fReindex
void TraceThread(std::string_view thread_name, std::function< void()> thread_func)
A wrapper for do-something-once thread functions.
void RandAddPeriodic() noexcept
Gather entropy from various expensive sources, and feed them to the PRNG state.
A BlockHash is a unqiue identifier for a block.
static time_point now() noexcept
Return current system time or mocked time, if set.
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...
Context struct holding the kernel library's logically global state, and passed to external libbitcoin...
std::function< bool()> check_interrupt
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
SynchronizationState
Current sync state passed to tip changed callbacks.
CMainSignals & GetMainSignals()
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.