36 int main(
int argc,
char* argv[])
41 <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
42 <<
"Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl
44 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl
45 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
92 cache_sizes.
coins = (450 << 20) - (2 << 20) - (2 << 22);
97 std::cerr <<
"Failed to load Chain state from your datadir." << std::endl;
102 std::cerr <<
"Failed to verify loaded Chain state from your datadir." << std::endl;
109 if (!chainstate->ActivateBestChain(state,
nullptr)) {
110 std::cerr <<
"Failed to connect best block (" << state.
ToString() <<
")" << std::endl;
117 <<
"Hello! I'm going to print out some information about your datadir." << std::endl
120 LOCK(chainman.GetMutex());
122 <<
"\t" <<
"Reindexing: " << std::boolalpha <<
node::fReindex.load() << std::noboolalpha << std::endl
123 <<
"\t" <<
"Snapshot Active: " << std::boolalpha << chainman.IsSnapshotActive() << std::noboolalpha << std::endl
124 <<
"\t" <<
"Active Height: " << chainman.ActiveHeight() << std::endl
125 <<
"\t" <<
"Active IBD: " << std::boolalpha << chainman.ActiveChainstate().IsInitialBlockDownload() << std::noboolalpha << std::endl;
128 std::cout <<
"\t" << tip->
ToString() << std::endl;
132 for (std::string line; std::getline(std::cin, line);) {
134 std::cerr <<
"Empty line found" << std::endl;
138 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
139 CBlock& block = *blockptr;
142 std::cerr <<
"Block decode failed" << std::endl;
146 if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) {
147 std::cerr <<
"Block does not start with a coinbase" << std::endl;
151 uint256 hash = block.GetHash();
154 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
157 std::cerr <<
"duplicate" << std::endl;
161 std::cerr <<
"duplicate-invalid" << std::endl;
169 const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock);
171 chainman.UpdateUncommittedBlockStructures(block, pindex);
196 auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
198 bool accepted = chainman.ProcessNewBlock(blockptr,
true,
true, &new_block);
200 if (!new_block && accepted) {
201 std::cerr <<
"duplicate" << std::endl;
205 std::cerr <<
"inconclusive" << std::endl;
208 std::cout << sc->state.ToString() << std::endl;
209 switch (sc->state.GetResult()) {
211 std::cerr <<
"initial value. Block has not yet been rejected" << std::endl;
214 std::cerr <<
"the block header may be on a too-little-work chain" << std::endl;
217 std::cerr <<
"invalid by consensus rules (excluding any below reasons)" << std::endl;
220 std::cerr <<
"Invalid by a change to consensus rules more recent than SegWit." << std::endl;
223 std::cerr <<
"this block was cached as being invalid and we didn't store the reason why" << std::endl;
226 std::cerr <<
"invalid proof of work or time too old" << std::endl;
229 std::cerr <<
"the block's data didn't match the data committed to by the PoW" << std::endl;
232 std::cerr <<
"We don't have the previous block the checked one is built on" << std::endl;
235 std::cerr <<
"A block this one builds on is invalid" << std::endl;
238 std::cerr <<
"block timestamp was > 2 hours in the future (or our clock is bad)" << std::endl;
241 std::cerr <<
"the block failed to meet one of our checkpoints" << std::endl;
250 if (chainman.m_load_block.joinable()) chainman.m_load_block.join();
256 for (
Chainstate* chainstate : chainman.GetAll()) {
257 if (chainstate->CanFlushToDisk()) {
258 chainstate->ForceFlushStateToDisk();
259 chainstate->ResetCoinsViews();
std::string ToString() const
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
std::atomic_bool fReindex
BlockValidationState state
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
We don't have the previous block the checked one is built on.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
invalid proof of work or time too old
const CChainParams & chainparams
void BlockChecked(const CBlock &block, const BlockValidationState &stateIn) override
Notifies listeners of a block validation result.
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
the block header may be on a too-little-work chain
std::function< bool()> check_interrupt
int main(int argc, char *argv[])
std::optional< bilingual_str > SanityChecks(const Context &)
Ensure a usable environment with all necessary library support.
void RandAddPeriodic() noexcept
Gather entropy from various expensive sources, and feed them to the PRNG state.
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
submitblock_StateCatcher(const uint256 &hashIn)
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
Implement this to subscribe to events generated in validation.
static const std::string MAIN
Chain name strings.
bool InitSignatureCache(size_t max_size_bytes)
initial value. Block has not yet been rejected
Chainstate stores and provides an API to update our local knowledge of the current best chain...
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
this block was cached as being invalid and we didn't store the reason why
std::string ToString() const
the block failed to meet one of our checkpoints
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
CMainSignals & GetMainSignals()
bool InitScriptExecutionCache(size_t max_size_bytes)
Initializes the script-execution cache.
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
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...
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once) ...
invalid by consensus rules (excluding any below reasons)
static time_point now() noexcept
Return current system time or mocked time, if set.
std::thread m_service_thread
the block's data didn't match the data committed to by the PoW
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
A block this one builds on is invalid.
Context struct holding the kernel library's logically global state, and passed to external libbitcoin...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Invalid by a change to consensus rules more recent than SegWit.
block timestamp was > 2 hours in the future (or our clock is bad)
ChainstateLoadResult LoadChainstate(ChainstateManager &chainman, const CacheSizes &cache_sizes, const ChainstateLoadOptions &options)
This sequence can have 4 types of outcomes:
Simple class for background tasks that should be run periodically or once "after a while"...
static path absolute(const path &p)
bool error(const char *fmt, const Args &... args)
#define Assert(val)
Identity function.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
void TraceThread(std::string_view thread_name, std::function< void()> thread_func)
A wrapper for do-something-once thread functions.