29 std::vector<std::byte> bytes;
30 bytes.reserve(hex.length() / 2);
32 for (
size_t i{0}; i < hex.length(); i += 2) {
34 auto [ptr,
ec] = std::from_chars(hex.data() + i, hex.data() + i + 2,
byte_value, 16);
36 if (
ec != std::errc{} || ptr != hex.data() + i + 2) {
37 throw std::invalid_argument(
"Invalid hex character");
39 bytes.push_back(
static_cast<std::byte
>(
byte_value));
49 std::cout <<
"kernel: " << entry.
Timestamp().time_since_epoch().count()
67 case ValidationMode::VALID: {
68 std::cout <<
"Valid block" << std::endl;
71 case ValidationMode::INVALID: {
72 std::cout <<
"Invalid block: ";
75 case BlockValidationResult::UNSET:
76 std::cout <<
"initial value. Block has not yet been rejected" << std::endl;
78 case BlockValidationResult::HEADER_LOW_WORK:
79 std::cout <<
"the block header may be on a too-little-work chain" << std::endl;
81 case BlockValidationResult::CONSENSUS:
82 std::cout <<
"invalid by consensus rules" << std::endl;
84 case BlockValidationResult::CACHED_INVALID:
85 std::cout <<
"this block was cached as being invalid and we didn't store the reason why" << std::endl;
87 case BlockValidationResult::INVALID_HEADER:
88 std::cout <<
"invalid proof of work or time too old" << std::endl;
90 case BlockValidationResult::MUTATED:
91 std::cout <<
"the block's data didn't match the data committed to by the PoW" << std::endl;
93 case BlockValidationResult::MISSING_PREV:
94 std::cout <<
"We don't have the previous block the checked one is built on" << std::endl;
96 case BlockValidationResult::INVALID_PREV:
97 std::cout <<
"A block this one builds on is invalid" << std::endl;
99 case BlockValidationResult::TIME_FUTURE:
100 std::cout <<
"block timestamp was > 2 hours in the future (or our clock is bad)" << std::endl;
105 case ValidationMode::INTERNAL_ERROR: {
106 std::cout <<
"Internal error" << std::endl;
118 std::cout <<
"Block tip changed" << std::endl;
123 std::cout <<
"Made progress: " << title <<
" " <<
progress_percent <<
"%" << std::endl;
128 std::cout << message << std::endl;
133 std::cout <<
"Warning unset: " <<
static_cast<std::underlying_type_t<Warning>
>(
warning) << std::endl;
138 std::cout << error << std::endl;
143 std::cout << error << std::endl;
153 <<
"Usage: " <<
argv[0] <<
" [-regtest] DATADIR" << std::endl
154 <<
"Display DATADIR information, and process hex-encoded blocks on standard input." << std::endl
155 <<
"Uses mainnet parameters by default, regtest with -regtest flag" << std::endl
157 <<
"IMPORTANT: THIS EXECUTABLE IS EXPERIMENTAL, FOR TESTING ONLY, AND EXPECTED TO" << std::endl
158 <<
" BREAK IN FUTURE VERSIONS. DO NOT USE ON YOUR ACTUAL DATADIR." << std::endl;
168 options.SetChainParams(params);
170 options.SetNotifications(std::make_shared<TestKernelNotifications>());
171 options.SetValidationInterface(std::make_shared<TestValidationInterface>());
178 std::unique_ptr<ChainMan> chainman;
181 }
catch (std::exception&) {
182 std::cerr <<
"Failed to instantiate ChainMan, exiting" << std::endl;
186 std::cout <<
"Enter the block you want to validate on the next line:" << std::endl;
188 for (std::string line; std::getline(std::cin, line);) {
190 std::cerr <<
"Empty line found, try again:" << std::endl;
195 std::unique_ptr<Block> block;
197 block = std::make_unique<Block>(
raw_block);
198 }
catch (std::exception&) {
199 std::cerr <<
"Block decode failed, try again:" << std::endl;
206 std::cerr <<
"Block has not yet been rejected" << std::endl;
208 std::cerr <<
"Block was not accepted" << std::endl;
211 std::cerr <<
"Block is a duplicate" << std::endl;
std::vector< std::byte > hex_string_to_byte_vec(std::string_view hex)
void LogMessage(const LogEntry &entry)
void FlushErrorHandler(std::string_view error) override
void FatalErrorHandler(std::string_view error) override
void WarningUnsetHandler(Warning warning) override
void WarningSetHandler(Warning warning, std::string_view message) override
void ProgressHandler(std::string_view title, int progress_percent, bool resume_possible) override
void BlockTipHandler(SynchronizationState, const BlockTreeEntry, double) override
TestValidationInterface()=default
std::optional< std::string > m_expected_valid_block
void BlockChecked(Block block, BlockValidationStateView state) override
ValidationMode GetValidationMode() const
BlockValidationResult GetBlockValidationResult() const
void SetWorkerThreads(int worker_threads)
Non-owning view over a btck_LogEntry.
LogCategory Category() const
std::string_view Message() const
std::chrono::sys_time< std::chrono::nanoseconds > Timestamp() const
constexpr std::string_view Name(LogLevel level) noexcept
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.