43int main(
int argc,
char *argv[]) {
46 std::cerr <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
47 <<
"Display DATADIR information, and process hex-encoded "
48 "blocks on standard input."
51 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
52 "ONLY, AND EXPECTED TO"
54 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
83 validation_cache_sizes.script_execution_cache_bytes));
89 [&] { scheduler.serviceQueue(); });
92 scheduler.scheduleEvery(
97 std::chrono::minutes{1});
104 std::cout <<
"Block tip changed" << std::endl;
107 bool presync)
override {
108 std::cout <<
"Header tip changed: " << height <<
", " << timestamp
109 <<
", " << presync << std::endl;
112 bool resume_possible)
override {
113 std::cout <<
"Progress: " << title.
original <<
", "
114 << progress_percent <<
", " << resume_possible
117 void warning(
const std::string &warning)
override {
118 std::cout <<
"Warning: " << warning << std::endl;
121 auto notifications = std::make_unique<KernelNotifications>();
128 .notifications = *notifications,
131 .
chainparams = chainman_opts.config.GetChainParams(),
139 cache_sizes.
coins = (450 << 20) - (2 << 20) - (2 << 22);
144 std::cerr <<
"Failed to load Chain state from your datadir."
150 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
158 if (!chainstate->ActivateBestChain(state,
nullptr)) {
159 std::cerr <<
"Failed to connect best block (" << state.
ToString()
167 <<
"Hello! I'm going to print out some information about your datadir."
170 LOCK(chainman.GetMutex());
175 << std::noboolalpha << std::endl
177 <<
"Snapshot Active: " << std::boolalpha
178 << chainman.IsSnapshotActive() << std::noboolalpha
181 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
183 <<
"Active IBD: " << std::boolalpha
184 << chainman.IsInitialBlockDownload() << std::noboolalpha
188 std::cout <<
"\t" << tip->
ToString() << std::endl;
192 for (std::string line; std::getline(std::cin, line);) {
194 std::cerr <<
"Empty line found" << std::endl;
198 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
199 CBlock &block = *blockptr;
202 std::cerr <<
"Block decode failed" << std::endl;
206 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
207 std::cerr <<
"Block does not start with a coinbase" << std::endl;
215 chainman.m_blockman.LookupBlockIndex(hash);
218 std::cerr <<
"Duplicate" << std::endl;
221 if (pindex->nStatus.hasFailed()) {
222 std::cerr <<
"Duplicate-invalid" << std::endl;
250 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
252 bool accepted = chainman.ProcessNewBlock(blockptr,
257 if (!new_block && accepted) {
258 std::cerr <<
"Duplicate" << std::endl;
262 std::cerr <<
"Inconclusive" << std::endl;
265 std::cout << sc->state.ToString() << std::endl;
266 switch (sc->state.GetResult()) {
268 std::cerr <<
"Initial value. Block has not yet been rejected"
273 <<
"the block header may be on a too-little-work chain"
277 std::cerr <<
"Invalid by consensus rules (excluding any below "
282 std::cerr <<
"This block was cached as being invalid and we "
283 "didn't store the reason why"
287 std::cerr <<
"Invalid proof of work or time too old"
291 std::cerr <<
"The block's data didn't match the data committed "
296 std::cerr <<
"We don't have the previous block the checked one "
301 std::cerr <<
"A block this one builds on is invalid"
305 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
310 std::cerr <<
"The block failed to meet one of our checkpoints"
320 if (chainman.m_thread_load.joinable()) {
321 chainman.m_thread_load.join();
328 for (
Chainstate *chainstate : chainman.GetAll()) {
329 if (chainstate->CanFlushToDisk()) {
330 chainstate->ForceFlushStateToDisk();
331 chainstate->ResetCoinsViews();
int main(int argc, char *argv[])
@ 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.
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.
bool error(const char *fmt, const Args &...args)
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)
This sequence can have 4 types of outcomes:
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.
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...
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.