36 int main(
int argc,
char *argv[]) {
39 std::cerr <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
40 <<
"Display DATADIR information, and process hex-encoded "
41 "blocks on standard input."
44 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
45 "ONLY, AND EXPECTED TO"
47 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
69 validation_cache_sizes.script_execution_cache_bytes));
75 [&] { scheduler.serviceQueue(); });
78 scheduler.scheduleEvery(
83 std::chrono::minutes{1});
94 .
chainparams = chainman_opts.config.GetChainParams(),
101 cache_sizes.
coins = (450 << 20) - (2 << 20) - (2 << 22);
106 std::cerr <<
"Failed to load Chain state from your datadir."
112 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
120 if (!chainstate->ActivateBestChain(state,
nullptr)) {
121 std::cerr <<
"Failed to connect best block (" << state.
ToString()
129 <<
"Hello! I'm going to print out some information about your datadir."
132 LOCK(chainman.GetMutex());
137 << std::noboolalpha << std::endl
139 <<
"Snapshot Active: " << std::boolalpha
140 << chainman.IsSnapshotActive() << std::noboolalpha
143 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
145 <<
"Active IBD: " << std::boolalpha
146 << chainman.ActiveChainstate().IsInitialBlockDownload()
147 << std::noboolalpha << std::endl;
150 std::cout <<
"\t" << tip->
ToString() << std::endl;
154 for (std::string line; std::getline(std::cin, line);) {
156 std::cerr <<
"Empty line found" << std::endl;
160 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
161 CBlock &block = *blockptr;
164 std::cerr <<
"Block decode failed" << std::endl;
168 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
169 std::cerr <<
"Block does not start with a coinbase" << std::endl;
177 chainman.m_blockman.LookupBlockIndex(hash);
180 std::cerr <<
"Duplicate" << std::endl;
183 if (pindex->nStatus.hasFailed()) {
184 std::cerr <<
"Duplicate-invalid" << std::endl;
212 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
214 bool accepted = chainman.ProcessNewBlock(blockptr,
219 if (!new_block && accepted) {
220 std::cerr <<
"Duplicate" << std::endl;
224 std::cerr <<
"Inconclusive" << std::endl;
227 std::cout << sc->state.ToString() << std::endl;
228 switch (sc->state.GetResult()) {
230 std::cerr <<
"Initial value. Block has not yet been rejected"
235 <<
"the block header may be on a too-little-work chain"
239 std::cerr <<
"Invalid by consensus rules (excluding any below "
244 std::cerr <<
"This block was cached as being invalid and we "
245 "didn't store the reason why"
249 std::cerr <<
"Invalid proof of work or time too old"
253 std::cerr <<
"The block's data didn't match the data committed "
258 std::cerr <<
"We don't have the previous block the checked one "
263 std::cerr <<
"A block this one builds on is invalid"
267 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
272 std::cerr <<
"The block failed to meet one of our checkpoints"
282 if (chainman.m_load_block.joinable()) {
283 chainman.m_load_block.join();
290 for (
Chainstate *chainstate : chainman.GetAll()) {
291 if (chainstate->CanFlushToDisk()) {
292 chainstate->ForceFlushStateToDisk();
293 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)
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
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
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...
std::string ToString() const
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.
Common init functions shared by bitcoin-node, bitcoin-wallet, etc.
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...
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.
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.
bool error(const char *fmt, const Args &...args)
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
CMainSignals & GetMainSignals()
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.