43int main(
int argc,
char *argv[]) {
52 std::cerr <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
53 <<
"Display DATADIR information, and process hex-encoded "
54 "blocks on standard input."
57 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
58 "ONLY, AND EXPECTED TO"
60 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
86 [&] { scheduler.serviceQueue(); });
89 scheduler.scheduleEvery(
94 std::chrono::minutes{1});
101 std::cout <<
"Block tip changed" << std::endl;
104 bool presync)
override {
105 std::cout <<
"Header tip changed: " << height <<
", " << timestamp
106 <<
", " << presync << std::endl;
109 bool resume_possible)
override {
110 std::cout <<
"Progress: " << title.
original <<
", "
111 << progress_percent <<
", " << resume_possible
114 void warning(
const std::string &warning)
override {
115 std::cout <<
"Warning: " << warning << std::endl;
117 void flushError(
const std::string &debug_message)
override {
118 std::cerr <<
"Error flushing block data to disk: " << debug_message
121 void fatalError(
const std::string &debug_message,
123 std::cerr <<
"Error: " << debug_message << std::endl;
124 std::cerr << (user_message.
empty()
125 ?
"A fatal internal error occurred."
130 auto notifications = std::make_unique<KernelNotifications>();
135 .datadir = abs_datadir,
137 .notifications = *notifications,
140 .
chainparams = chainman_opts.config.GetChainParams(),
141 .blocks_dir = abs_datadir /
"blocks",
142 .notifications = chainman_opts.notifications,
152 std::cerr <<
"Failed to load Chain state from your datadir."
158 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
166 if (!chainstate->ActivateBestChain(state,
nullptr)) {
167 std::cerr <<
"Failed to connect best block (" << state.
ToString()
175 <<
"Hello! I'm going to print out some information about your datadir."
178 LOCK(chainman.GetMutex());
180 <<
"Path: " << abs_datadir << std::endl
183 << std::noboolalpha << std::endl
185 <<
"Snapshot Active: " << std::boolalpha
186 << chainman.IsSnapshotActive() << std::noboolalpha
189 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
191 <<
"Active IBD: " << std::boolalpha
192 << chainman.IsInitialBlockDownload() << std::noboolalpha
196 std::cout <<
"\t" << tip->
ToString() << std::endl;
200 for (std::string line; std::getline(std::cin, line);) {
202 std::cerr <<
"Empty line found" << std::endl;
206 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
207 CBlock &block = *blockptr;
210 std::cerr <<
"Block decode failed" << std::endl;
214 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
215 std::cerr <<
"Block does not start with a coinbase" << std::endl;
223 chainman.m_blockman.LookupBlockIndex(hash);
226 std::cerr <<
"Duplicate" << std::endl;
229 if (pindex->nStatus.hasFailed()) {
230 std::cerr <<
"Duplicate-invalid" << std::endl;
258 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
260 bool accepted = chainman.ProcessNewBlock(blockptr,
265 if (!new_block && accepted) {
266 std::cerr <<
"Duplicate" << std::endl;
270 std::cerr <<
"Inconclusive" << std::endl;
273 std::cout << sc->state.ToString() << std::endl;
274 switch (sc->state.GetResult()) {
276 std::cerr <<
"Initial value. Block has not yet been rejected"
281 <<
"the block header may be on a too-little-work chain"
285 std::cerr <<
"Invalid by consensus rules (excluding any below "
290 std::cerr <<
"This block was cached as being invalid and we "
291 "didn't store the reason why"
295 std::cerr <<
"Invalid proof of work or time too old"
299 std::cerr <<
"The block's data didn't match the data committed "
304 std::cerr <<
"We don't have the previous block the checked one "
309 std::cerr <<
"A block this one builds on is invalid"
313 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
318 std::cerr <<
"The block failed to meet one of our checkpoints"
328 if (chainman.m_thread_load.joinable()) {
329 chainman.m_thread_load.join();
336 for (
Chainstate *chainstate : chainman.GetAll()) {
337 if (chainstate->CanFlushToDisk()) {
338 chainstate->ForceFlushStateToDisk();
339 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 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
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 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.