42int main(
int argc,
char *argv[]) {
51 std::cerr <<
"Usage: " << argv[0] <<
" DATADIR" << std::endl
52 <<
"Display DATADIR information, and process hex-encoded "
53 "blocks on standard input."
56 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING "
57 "ONLY, AND EXPECTED TO"
59 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR "
82 std::make_unique<util::ImmediateTaskRunner>()};
88 std::cout <<
"Block tip changed" << std::endl;
92 bool presync)
override {
93 std::cout <<
"Header tip changed: " << height <<
", " << timestamp
94 <<
", " << presync << std::endl;
97 bool resume_possible)
override {
98 std::cout <<
"Progress: " << title.
original <<
", "
99 << progress_percent <<
", " << resume_possible
102 void warning(
const std::string &warning)
override {
103 std::cout <<
"Warning: " << warning << std::endl;
105 void flushError(
const std::string &debug_message)
override {
106 std::cerr <<
"Error flushing block data to disk: " << debug_message
109 void fatalError(
const std::string &debug_message,
111 std::cerr <<
"Error: " << debug_message << std::endl;
112 std::cerr << (user_message.
empty()
113 ?
"A fatal internal error occurred."
118 auto notifications = std::make_unique<KernelNotifications>();
123 .datadir = abs_datadir,
125 .notifications = *notifications,
126 .signals = &validation_signals,
129 .
chainparams = chainman_opts.config.GetChainParams(),
130 .blocks_dir = abs_datadir /
"blocks",
131 .notifications = chainman_opts.notifications,
141 std::cerr <<
"Failed to load Chain state from your datadir."
147 std::cerr <<
"Failed to verify loaded Chain state from your datadir."
155 if (!chainstate->ActivateBestChain(state,
nullptr)) {
156 std::cerr <<
"Failed to connect best block (" << state.
ToString()
164 <<
"Hello! I'm going to print out some information about your datadir."
167 LOCK(chainman.GetMutex());
169 <<
"Path: " << abs_datadir << std::endl
171 <<
"Reindexing: " << std::boolalpha
172 << chainman.m_blockman.m_reindexing.load() << std::noboolalpha
175 <<
"Snapshot Active: " << std::boolalpha
176 << chainman.IsSnapshotActive() << std::noboolalpha
179 <<
"Active Height: " << chainman.ActiveHeight() << std::endl
181 <<
"Active IBD: " << std::boolalpha
182 << chainman.IsInitialBlockDownload() << std::noboolalpha
186 std::cout <<
"\t" << tip->
ToString() << std::endl;
190 for (std::string line; std::getline(std::cin, line);) {
192 std::cerr <<
"Empty line found" << std::endl;
196 std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>();
197 CBlock &block = *blockptr;
200 std::cerr <<
"Block decode failed" << std::endl;
204 if (block.
vtx.empty() || !block.
vtx[0]->IsCoinBase()) {
205 std::cerr <<
"Block does not start with a coinbase" << std::endl;
213 chainman.m_blockman.LookupBlockIndex(hash);
216 std::cerr <<
"Duplicate" << std::endl;
219 if (pindex->nStatus.hasFailed()) {
220 std::cerr <<
"Duplicate-invalid" << std::endl;
248 auto sc = std::make_shared<submitblock_StateCatcher>(block.
GetHash());
249 validation_signals.RegisterSharedValidationInterface(sc);
250 bool accepted = chainman.ProcessNewBlock(
251 blockptr,
true,
true,
253 validation_signals.UnregisterSharedValidationInterface(sc);
254 if (!new_block && accepted) {
255 std::cerr <<
"Duplicate" << std::endl;
259 std::cerr <<
"Inconclusive" << std::endl;
262 std::cout << sc->state.ToString() << std::endl;
263 switch (sc->state.GetResult()) {
265 std::cerr <<
"Initial value. Block has not yet been rejected"
270 <<
"the block header may be on a too-little-work chain"
274 std::cerr <<
"Invalid by consensus rules (excluding any below "
279 std::cerr <<
"This block was cached as being invalid and we "
280 "didn't store the reason why"
284 std::cerr <<
"Invalid proof of work or time too old"
288 std::cerr <<
"The block's data didn't match the data committed "
293 std::cerr <<
"We don't have the previous block the checked one "
298 std::cerr <<
"A block this one builds on is invalid"
302 std::cerr <<
"Block timestamp was > 2 hours in the future (or "
307 std::cerr <<
"The block failed to meet one of our checkpoints"
316 if (chainman.m_thread_load.joinable()) {
317 chainman.m_thread_load.join();
320 validation_signals.FlushBackgroundCallbacks();
323 for (
Chainstate *chainstate : chainman.GetAll()) {
324 if (chainstate->CanFlushToDisk()) {
325 chainstate->ForceFlushStateToDisk();
326 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)
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 InterruptResult 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...
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
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)
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.
This header provides an interface and simple implementation for a task runner.
SynchronizationState
Current sync state passed to tip changed callbacks.