44 std::cerr <<
"Usage: " <<
argv[0] <<
" DATADIR" << std::endl
45 <<
"Display DATADIR information, and process hex-encoded "
46 "blocks on standard input."
49 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
50 "ONLY, AND EXPECTED TO"
52 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
83 [&] { scheduler.serviceQueue(); });
86 scheduler.scheduleEvery(
91 std::chrono::minutes{1});
98 std::cout <<
"Block tip changed" << std::endl;
102 std::cout <<
"Header tip changed: " << height <<
", " <<
timestamp
103 <<
", " <<
presync << std::endl;
107 std::cout <<
"Progress: " << title.
original <<
", "
111 void warning(
const std::string &warning)
override {
112 std::cout <<
"Warning: " << warning << std::endl;
115 auto notifications = std::make_unique<KernelNotifications>();
122 .notifications = *notifications,
133 cache_sizes.coins = (450 << 20) - (2 << 20) - (2 << 22);
138 std::cerr <<
"Failed to load Chain state from your datadir."
144 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
152 if (!
chainstate->ActivateBestChain(state,
nullptr)) {
153 std::cerr <<
"Failed to connect best block (" << state.
ToString()
161 <<
"Hello! I'm going to print out some information about your datadir."
164 LOCK(chainman.GetMutex());
169 << std::noboolalpha << std::endl
171 <<
"Snapshot Active: " << std::boolalpha
172 << chainman.IsSnapshotActive() << std::noboolalpha
175 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
177 <<
"Active IBD: " << std::boolalpha
178 << chainman.ActiveChainstate().IsInitialBlockDownload()
179 << std::noboolalpha << std::endl;
186 for (std::string line; std::getline(std::cin, line);) {
188 std::cerr <<
"Empty line found" << std::endl;
192 std::shared_ptr<CBlock>
blockptr = std::make_shared<CBlock>();
196 std::cerr <<
"Block decode failed" << std::endl;
200 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
201 std::cerr <<
"Block does not start with a coinbase" << std::endl;
209 chainman.m_blockman.LookupBlockIndex(hash);
212 std::cerr <<
"Duplicate" << std::endl;
215 if (pindex->nStatus.hasFailed()) {
216 std::cerr <<
"Duplicate-invalid" << std::endl;
244 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
252 std::cerr <<
"Duplicate" << std::endl;
256 std::cerr <<
"Inconclusive" << std::endl;
259 std::cout << sc->state.ToString() << std::endl;
260 switch (sc->state.GetResult()) {
262 std::cerr <<
"Initial value. Block has not yet been rejected"
267 <<
"the block header may be on a too-little-work chain"
271 std::cerr <<
"Invalid by consensus rules (excluding any below "
276 std::cerr <<
"This block was cached as being invalid and we "
277 "didn't store the reason why"
281 std::cerr <<
"Invalid proof of work or time too old"
285 std::cerr <<
"The block's data didn't match the data committed "
290 std::cerr <<
"We don't have the previous block the checked one "
295 std::cerr <<
"A block this one builds on is invalid"
299 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
304 std::cerr <<
"The block failed to meet one of our checkpoints"
314 if (chainman.m_load_block.joinable()) {
315 chainman.m_load_block.join();
@ SCRIPTS
Scripts & signatures ok.
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given BIP70 chain name.
#define Assert(val)
Identity function.
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.
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
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 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.
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.
Common init functions shared by bitcoin-node, bitcoin-wallet, etc.
bool error(const char *fmt, const Args &...args)
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
void TraceThread(const char *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.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
bool InitScriptExecutionCache(size_t max_size_bytes)
Initializes the script-execution cache.
bool InitSignatureCache(size_t max_size_bytes)
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...
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.