Bitcoin Core 31.99.0
P2P Digital Currency
bitcoinkernel.cpp
Go to the documentation of this file.
1// Copyright (c) 2022-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#define BITCOINKERNEL_BUILD
6
8
9#include <chain.h>
10#include <coins.h>
12#include <dbwrapper.h>
13#include <kernel/caches.h>
14#include <kernel/chainparams.h>
15#include <kernel/checks.h>
16#include <kernel/context.h>
18#include <kernel/warning.h>
19#include <logging.h>
20#include <node/blockstorage.h>
21#include <node/chainstate.h>
22#include <primitives/block.h>
24#include <script/interpreter.h>
25#include <script/script.h>
26#include <serialize.h>
27#include <streams.h>
28#include <sync.h>
29#include <uint256.h>
30#include <undo.h>
31#include <util/check.h>
32#include <util/fs.h>
33#include <util/result.h>
35#include <util/task_runner.h>
36#include <util/translation.h>
37#include <validation.h>
38#include <validationinterface.h>
39
40#include <cstddef>
41#include <cstring>
42#include <exception>
43#include <functional>
44#include <list>
45#include <memory>
46#include <span>
47#include <stdexcept>
48#include <string>
49#include <tuple>
50#include <utility>
51#include <vector>
52
53namespace Consensus {
54struct Params;
55} // namespace Consensus
56
59
60// Define G_TRANSLATION_FUN symbol in libbitcoinkernel library so users of the
61// library aren't required to export this symbol
62extern const TranslateFn G_TRANSLATION_FUN{nullptr};
63
65
66namespace {
67
68bool is_valid_flag_combination(script_verify_flags flags)
69{
71 if (flags & SCRIPT_VERIFY_WITNESS && ~flags & SCRIPT_VERIFY_P2SH) return false;
72 return true;
73}
74
75class WriterStream
76{
77private:
78 btck_WriteBytes m_writer;
79 void* m_user_data;
80
81public:
82 WriterStream(btck_WriteBytes writer, void* user_data)
83 : m_writer{writer}, m_user_data{user_data} {}
84
85 //
86 // Stream subset
87 //
88 void write(std::span<const std::byte> src)
89 {
90 if (m_writer(src.data(), src.size(), m_user_data) != 0) {
91 throw std::runtime_error("Failed to write serialization data");
92 }
93 }
94
95 template <typename T>
96 WriterStream& operator<<(const T& obj)
97 {
98 ::Serialize(*this, obj);
99 return *this;
100 }
101};
102
103template <typename C, typename CPP>
104struct Handle {
105 static C* ref(CPP* cpp_type)
106 {
107 return reinterpret_cast<C*>(cpp_type);
108 }
109
110 static const C* ref(const CPP* cpp_type)
111 {
112 return reinterpret_cast<const C*>(cpp_type);
113 }
114
115 template <typename... Args>
116 static C* create(Args&&... args)
117 {
118 auto cpp_obj{std::make_unique<CPP>(std::forward<Args>(args)...)};
119 return ref(cpp_obj.release());
120 }
121
122 static C* copy(const C* ptr)
123 {
124 auto cpp_obj{std::make_unique<CPP>(get(ptr))};
125 return ref(cpp_obj.release());
126 }
127
128 static const CPP& get(const C* ptr)
129 {
130 return *reinterpret_cast<const CPP*>(ptr);
131 }
132
133 static CPP& get(C* ptr)
134 {
135 return *reinterpret_cast<CPP*>(ptr);
136 }
137
138 static void operator delete(void* ptr)
139 {
140 delete reinterpret_cast<CPP*>(ptr);
141 }
142};
143
144} // namespace
145
146struct btck_BlockTreeEntry: Handle<btck_BlockTreeEntry, CBlockIndex> {};
147struct btck_Block : Handle<btck_Block, std::shared_ptr<const CBlock>> {};
148struct btck_BlockValidationState : Handle<btck_BlockValidationState, BlockValidationState> {};
149
150namespace {
151
152BCLog::Level get_bclog_level(btck_LogLevel level)
153{
154 switch (level) {
155 case btck_LogLevel_INFO: {
156 return BCLog::Level::Info;
157 }
158 case btck_LogLevel_DEBUG: {
159 return BCLog::Level::Debug;
160 }
161 case btck_LogLevel_TRACE: {
162 return BCLog::Level::Trace;
163 }
164 }
165 assert(false);
166}
167
168BCLog::LogFlags get_bclog_flag(btck_LogCategory category)
169{
170 switch (category) {
173 }
176 }
179 }
182 }
185 }
188 }
191 }
194 }
197 }
200 }
203 }
204 }
205 assert(false);
206}
207
209{
210 switch (state) {
217 } // no default case, so the compiler can warn about missing cases
218 assert(false);
219}
220
221btck_Warning cast_btck_warning(kernel::Warning warning)
222{
223 switch (warning) {
228 } // no default case, so the compiler can warn about missing cases
229 assert(false);
230}
231
232struct LoggingConnection {
233 std::unique_ptr<std::list<std::function<void(const std::string&)>>::iterator> m_connection;
234 void* m_user_data;
235 std::function<void(void* user_data)> m_deleter;
236
237 LoggingConnection(btck_LogCallback callback, void* user_data, btck_DestroyCallback user_data_destroy_callback)
238 {
239 LOCK(cs_main);
240
241 auto connection{LogInstance().PushBackCallback([callback, user_data](const std::string& str) { callback(user_data, str.c_str(), str.length()); })};
242
243 // Only start logging if we just added the connection.
244 if (LogInstance().NumConnections() == 1 && !LogInstance().StartLogging()) {
245 LogError("Logger start failed.");
246 LogInstance().DeleteCallback(connection);
247 if (user_data && user_data_destroy_callback) {
248 user_data_destroy_callback(user_data);
249 }
250 throw std::runtime_error("Failed to start logging");
251 }
252
253 m_connection = std::make_unique<std::list<std::function<void(const std::string&)>>::iterator>(connection);
254 m_user_data = user_data;
255 m_deleter = user_data_destroy_callback;
256
257 LogDebug(BCLog::KERNEL, "Logger connected.");
258 }
259
260 ~LoggingConnection()
261 {
262 LOCK(cs_main);
263 LogDebug(BCLog::KERNEL, "Logger disconnecting.");
264
265 // Switch back to buffering by calling DisconnectTestLogger if the
266 // connection that we are about to remove is the last one.
267 if (LogInstance().NumConnections() == 1) {
269 } else {
271 }
272
273 m_connection.reset();
274 if (m_user_data && m_deleter) {
275 m_deleter(m_user_data);
276 }
277 }
278};
279
280class KernelNotifications final : public kernel::Notifications
281{
282private:
284
285public:
286 KernelNotifications(btck_NotificationInterfaceCallbacks cbs)
287 : m_cbs{cbs}
288 {
289 }
290
291 ~KernelNotifications()
292 {
293 if (m_cbs.user_data && m_cbs.user_data_destroy) {
294 m_cbs.user_data_destroy(m_cbs.user_data);
295 }
296 m_cbs.user_data_destroy = nullptr;
297 m_cbs.user_data = nullptr;
298 }
299
300 kernel::InterruptResult blockTip(SynchronizationState state, const CBlockIndex& index, double verification_progress) override
301 {
302 if (m_cbs.block_tip) m_cbs.block_tip(m_cbs.user_data, cast_state(state), btck_BlockTreeEntry::ref(&index), verification_progress);
303 return {};
304 }
305 void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override
306 {
307 if (m_cbs.header_tip) m_cbs.header_tip(m_cbs.user_data, cast_state(state), height, timestamp, presync ? 1 : 0);
308 }
309 void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override
310 {
311 if (m_cbs.progress) m_cbs.progress(m_cbs.user_data, title.original.c_str(), title.original.length(), progress_percent, resume_possible ? 1 : 0);
312 }
313 void warningSet(kernel::Warning id, const bilingual_str& message) override
314 {
315 if (m_cbs.warning_set) m_cbs.warning_set(m_cbs.user_data, cast_btck_warning(id), message.original.c_str(), message.original.length());
316 }
317 void warningUnset(kernel::Warning id) override
318 {
319 if (m_cbs.warning_unset) m_cbs.warning_unset(m_cbs.user_data, cast_btck_warning(id));
320 }
321 void flushError(const bilingual_str& message) override
322 {
323 if (m_cbs.flush_error) m_cbs.flush_error(m_cbs.user_data, message.original.c_str(), message.original.length());
324 }
325 void fatalError(const bilingual_str& message) override
326 {
327 if (m_cbs.fatal_error) m_cbs.fatal_error(m_cbs.user_data, message.original.c_str(), message.original.length());
328 }
329};
330
331class KernelValidationInterface final : public CValidationInterface
332{
333public:
335
336 explicit KernelValidationInterface(const btck_ValidationInterfaceCallbacks vi_cbs) : m_cbs{vi_cbs} {}
337
338 ~KernelValidationInterface()
339 {
340 if (m_cbs.user_data && m_cbs.user_data_destroy) {
341 m_cbs.user_data_destroy(m_cbs.user_data);
342 }
343 m_cbs.user_data = nullptr;
344 m_cbs.user_data_destroy = nullptr;
345 }
346
347protected:
348 void BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& stateIn) override
349 {
350 if (m_cbs.block_checked) {
351 m_cbs.block_checked(m_cbs.user_data,
352 btck_Block::copy(btck_Block::ref(&block)),
353 btck_BlockValidationState::ref(&stateIn));
354 }
355 }
356
357 void NewPoWValidBlock(const CBlockIndex* pindex, const std::shared_ptr<const CBlock>& block) override
358 {
359 if (m_cbs.pow_valid_block) {
360 m_cbs.pow_valid_block(m_cbs.user_data,
361 btck_Block::copy(btck_Block::ref(&block)),
362 btck_BlockTreeEntry::ref(pindex));
363 }
364 }
365
366 void BlockConnected(const ChainstateRole& role, const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override
367 {
368 if (m_cbs.block_connected) {
369 m_cbs.block_connected(m_cbs.user_data,
370 btck_Block::copy(btck_Block::ref(&block)),
371 btck_BlockTreeEntry::ref(pindex));
372 }
373 }
374
375 void BlockDisconnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override
376 {
377 if (m_cbs.block_disconnected) {
378 m_cbs.block_disconnected(m_cbs.user_data,
379 btck_Block::copy(btck_Block::ref(&block)),
380 btck_BlockTreeEntry::ref(pindex));
381 }
382 }
383};
384
385struct ContextOptions {
386 mutable Mutex m_mutex;
387 std::unique_ptr<const CChainParams> m_chainparams GUARDED_BY(m_mutex);
388 std::shared_ptr<KernelNotifications> m_notifications GUARDED_BY(m_mutex);
389 std::shared_ptr<KernelValidationInterface> m_validation_interface GUARDED_BY(m_mutex);
390};
391
392class Context
393{
394public:
395 std::unique_ptr<kernel::Context> m_context;
396
397 std::shared_ptr<KernelNotifications> m_notifications;
398
399 std::unique_ptr<util::SignalInterrupt> m_interrupt;
400
401 std::unique_ptr<ValidationSignals> m_signals;
402
403 std::unique_ptr<const CChainParams> m_chainparams;
404
405 std::shared_ptr<KernelValidationInterface> m_validation_interface;
406
407 Context(const ContextOptions* options, bool& sane)
408 : m_context{std::make_unique<kernel::Context>()},
409 m_interrupt{std::make_unique<util::SignalInterrupt>()}
410 {
411 if (options) {
412 LOCK(options->m_mutex);
413 if (options->m_chainparams) {
414 m_chainparams = std::make_unique<const CChainParams>(*options->m_chainparams);
415 }
416 if (options->m_notifications) {
417 m_notifications = options->m_notifications;
418 }
419 if (options->m_validation_interface) {
420 m_signals = std::make_unique<ValidationSignals>(std::make_unique<ImmediateTaskRunner>());
421 m_validation_interface = options->m_validation_interface;
422 m_signals->RegisterSharedValidationInterface(m_validation_interface);
423 }
424 }
425
426 if (!m_chainparams) {
427 m_chainparams = CChainParams::Main();
428 }
429 if (!m_notifications) {
430 m_notifications = std::make_shared<KernelNotifications>(btck_NotificationInterfaceCallbacks{
431 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr});
432 }
433
435 sane = false;
436 }
437 }
438
439 ~Context()
440 {
441 if (m_signals) {
442 m_signals->UnregisterSharedValidationInterface(m_validation_interface);
443 }
444 }
445};
446
448struct ChainstateManagerOptions {
449 mutable Mutex m_mutex;
450 ChainstateManager::Options m_chainman_options GUARDED_BY(m_mutex);
451 node::BlockManager::Options m_blockman_options GUARDED_BY(m_mutex);
452 std::shared_ptr<const Context> m_context;
453 node::ChainstateLoadOptions m_chainstate_load_options GUARDED_BY(m_mutex);
454
455 ChainstateManagerOptions(const std::shared_ptr<const Context>& context, const fs::path& data_dir, const fs::path& blocks_dir)
456 : m_chainman_options{ChainstateManager::Options{
457 .chainparams = *context->m_chainparams,
458 .datadir = data_dir,
459 .notifications = *context->m_notifications,
460 .signals = context->m_signals.get()}},
461 m_blockman_options{node::BlockManager::Options{
462 .chainparams = *context->m_chainparams,
463 .blocks_dir = blocks_dir,
464 .notifications = *context->m_notifications,
465 .block_tree_db_params = DBParams{
466 .path = data_dir / "blocks" / "index",
467 .cache_bytes = kernel::CacheSizes{DEFAULT_KERNEL_CACHE}.block_tree_db,
468 }}},
469 m_context{context}, m_chainstate_load_options{node::ChainstateLoadOptions{}}
470 {
471 }
472};
473
474struct ChainMan {
475 std::unique_ptr<ChainstateManager> m_chainman;
476 std::shared_ptr<const Context> m_context;
477
478 ChainMan(std::unique_ptr<ChainstateManager> chainman, std::shared_ptr<const Context> context)
479 : m_chainman(std::move(chainman)), m_context(std::move(context)) {}
480};
481
482} // namespace
483
484struct btck_Transaction : Handle<btck_Transaction, std::shared_ptr<const CTransaction>> {};
485struct btck_TransactionOutput : Handle<btck_TransactionOutput, CTxOut> {};
486struct btck_ScriptPubkey : Handle<btck_ScriptPubkey, CScript> {};
487struct btck_LoggingConnection : Handle<btck_LoggingConnection, LoggingConnection> {};
488struct btck_ContextOptions : Handle<btck_ContextOptions, ContextOptions> {};
489struct btck_Context : Handle<btck_Context, std::shared_ptr<const Context>> {};
490struct btck_ChainParameters : Handle<btck_ChainParameters, CChainParams> {};
491struct btck_ChainstateManagerOptions : Handle<btck_ChainstateManagerOptions, ChainstateManagerOptions> {};
492struct btck_ChainstateManager : Handle<btck_ChainstateManager, ChainMan> {};
493struct btck_Chain : Handle<btck_Chain, CChain> {};
494struct btck_BlockSpentOutputs : Handle<btck_BlockSpentOutputs, std::shared_ptr<CBlockUndo>> {};
495struct btck_TransactionSpentOutputs : Handle<btck_TransactionSpentOutputs, CTxUndo> {};
496struct btck_Coin : Handle<btck_Coin, Coin> {};
497struct btck_BlockHash : Handle<btck_BlockHash, uint256> {};
498struct btck_TransactionInput : Handle<btck_TransactionInput, CTxIn> {};
499struct btck_TransactionOutPoint: Handle<btck_TransactionOutPoint, COutPoint> {};
500struct btck_Txid: Handle<btck_Txid, Txid> {};
501struct btck_PrecomputedTransactionData : Handle<btck_PrecomputedTransactionData, PrecomputedTransactionData> {};
502struct btck_BlockHeader: Handle<btck_BlockHeader, CBlockHeader> {};
503struct btck_ConsensusParams: Handle<btck_ConsensusParams, Consensus::Params> {};
504
505btck_Transaction* btck_transaction_create(const void* raw_transaction, size_t raw_transaction_len)
506{
507 if (raw_transaction == nullptr && raw_transaction_len != 0) {
508 return nullptr;
509 }
510 try {
511 SpanReader stream{std::span{reinterpret_cast<const std::byte*>(raw_transaction), raw_transaction_len}};
512 return btck_Transaction::create(std::make_shared<const CTransaction>(deserialize, TX_WITH_WITNESS, stream));
513 } catch (...) {
514 return nullptr;
515 }
516}
517
519{
520 return btck_Transaction::get(transaction)->vout.size();
521}
522
523const btck_TransactionOutput* btck_transaction_get_output_at(const btck_Transaction* transaction, size_t output_index)
524{
525 const CTransaction& tx = *btck_Transaction::get(transaction);
526 assert(output_index < tx.vout.size());
527 return btck_TransactionOutput::ref(&tx.vout[output_index]);
528}
529
531{
532 return btck_Transaction::get(transaction)->vin.size();
533}
534
535const btck_TransactionInput* btck_transaction_get_input_at(const btck_Transaction* transaction, size_t input_index)
536{
537 assert(input_index < btck_Transaction::get(transaction)->vin.size());
538 return btck_TransactionInput::ref(&btck_Transaction::get(transaction)->vin[input_index]);
539}
540
542{
543 return btck_Transaction::get(transaction)->nLockTime;
544}
545
547{
548 return btck_Txid::ref(&btck_Transaction::get(transaction)->GetHash());
549}
550
552{
553 return btck_Transaction::copy(transaction);
554}
555
556int btck_transaction_to_bytes(const btck_Transaction* transaction, btck_WriteBytes writer, void* user_data)
557{
558 try {
559 WriterStream ws{writer, user_data};
560 ws << TX_WITH_WITNESS(btck_Transaction::get(transaction));
561 return 0;
562 } catch (...) {
563 return -1;
564 }
565}
566
568{
569 delete transaction;
570}
571
572btck_ScriptPubkey* btck_script_pubkey_create(const void* script_pubkey, size_t script_pubkey_len)
573{
574 if (script_pubkey == nullptr && script_pubkey_len != 0) {
575 return nullptr;
576 }
577 auto data = std::span{reinterpret_cast<const uint8_t*>(script_pubkey), script_pubkey_len};
578 return btck_ScriptPubkey::create(data.begin(), data.end());
579}
580
581int btck_script_pubkey_to_bytes(const btck_ScriptPubkey* script_pubkey_, btck_WriteBytes writer, void* user_data)
582{
583 const auto& script_pubkey{btck_ScriptPubkey::get(script_pubkey_)};
584 return writer(script_pubkey.data(), script_pubkey.size(), user_data);
585}
586
588{
589 return btck_ScriptPubkey::copy(script_pubkey);
590}
591
593{
594 delete script_pubkey;
595}
596
598{
599 return btck_TransactionOutput::create(amount, btck_ScriptPubkey::get(script_pubkey));
600}
601
603{
604 return btck_TransactionOutput::copy(output);
605}
606
608{
609 return btck_ScriptPubkey::ref(&btck_TransactionOutput::get(output).scriptPubKey);
610}
611
613{
614 return btck_TransactionOutput::get(output).nValue;
615}
616
618{
619 delete output;
620}
621
623 const btck_Transaction* tx_to,
624 const btck_TransactionOutput** spent_outputs_, size_t spent_outputs_len)
625{
626 try {
627 const CTransaction& tx{*btck_Transaction::get(tx_to)};
628 auto txdata{btck_PrecomputedTransactionData::create()};
629 if (spent_outputs_ != nullptr && spent_outputs_len > 0) {
630 assert(spent_outputs_len == tx.vin.size());
631 std::vector<CTxOut> spent_outputs;
632 spent_outputs.reserve(spent_outputs_len);
633 for (size_t i = 0; i < spent_outputs_len; i++) {
634 const CTxOut& tx_out{btck_TransactionOutput::get(spent_outputs_[i])};
635 spent_outputs.push_back(tx_out);
636 }
637 btck_PrecomputedTransactionData::get(txdata).Init(tx, std::move(spent_outputs));
638 } else {
639 btck_PrecomputedTransactionData::get(txdata).Init(tx, {});
640 }
641
642 return txdata;
643 } catch (...) {
644 return nullptr;
645 }
646}
647
649{
650 return btck_PrecomputedTransactionData::copy(precomputed_txdata);
651}
652
654{
655 delete precomputed_txdata;
656}
657
659 const int64_t amount,
660 const btck_Transaction* tx_to,
661 const btck_PrecomputedTransactionData* precomputed_txdata,
662 const unsigned int input_index,
665{
666 // Assert that all specified flags are part of the interface before continuing
668
669 if (!is_valid_flag_combination(script_verify_flags::from_int(flags))) {
671 return 0;
672 }
673
674 const CTransaction& tx{*btck_Transaction::get(tx_to)};
675 assert(input_index < tx.vin.size());
676
677 const PrecomputedTransactionData& txdata{precomputed_txdata ? btck_PrecomputedTransactionData::get(precomputed_txdata) : PrecomputedTransactionData(tx)};
678
679 if (flags & btck_ScriptVerificationFlags_TAPROOT && txdata.m_spent_outputs.empty()) {
681 return 0;
682 }
683
684 if (status) *status = btck_ScriptVerifyStatus_OK;
685
686 bool result = VerifyScript(tx.vin[input_index].scriptSig,
687 btck_ScriptPubkey::get(script_pubkey),
688 &tx.vin[input_index].scriptWitness,
690 TransactionSignatureChecker(&tx, input_index, amount, txdata, MissingDataBehavior::FAIL),
691 nullptr);
692 return result ? 1 : 0;
693}
694
696{
697 return btck_TransactionInput::copy(input);
698}
699
701{
702 return btck_TransactionOutPoint::ref(&btck_TransactionInput::get(input).prevout);
703}
704
706{
707 return btck_TransactionInput::get(input).nSequence;
708}
709
711{
712 delete input;
713}
714
716{
717 return btck_TransactionOutPoint::copy(out_point);
718}
719
721{
722 return btck_TransactionOutPoint::get(out_point).n;
723}
724
726{
727 return btck_Txid::ref(&btck_TransactionOutPoint::get(out_point).hash);
728}
729
731{
732 delete out_point;
733}
734
736{
737 return btck_Txid::copy(txid);
738}
739
740void btck_txid_to_bytes(const btck_Txid* txid, unsigned char output[32])
741{
742 std::memcpy(output, btck_Txid::get(txid).begin(), 32);
743}
744
745int btck_txid_equals(const btck_Txid* txid1, const btck_Txid* txid2)
746{
747 return btck_Txid::get(txid1) == btck_Txid::get(txid2);
748}
749
751{
752 delete txid;
753}
754
756{
757 LOCK(cs_main);
763}
764
766{
767 LOCK(cs_main);
768 if (category == btck_LogCategory_ALL) {
769 LogInstance().SetLogLevel(get_bclog_level(level));
770 }
771
772 LogInstance().AddCategoryLogLevel(get_bclog_flag(category), get_bclog_level(level));
773}
774
776{
777 LogInstance().EnableCategory(get_bclog_flag(category));
778}
779
781{
782 LogInstance().DisableCategory(get_bclog_flag(category));
783}
784
786{
788}
789
791{
792 try {
793 return btck_LoggingConnection::create(callback, user_data, user_data_destroy_callback);
794 } catch (const std::exception&) {
795 return nullptr;
796 }
797}
798
800{
801 delete connection;
802}
803
805{
806 switch (chain_type) {
808 return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::Main().release()));
809 }
811 return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::TestNet().release()));
812 }
814 return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::TestNet4().release()));
815 }
817 return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::SigNet({}).release()));
818 }
820 return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::RegTest({}).release()));
821 }
822 }
823 assert(false);
824}
825
827{
828 return btck_ChainParameters::copy(chain_parameters);
829}
830
832{
833 return btck_ConsensusParams::ref(&btck_ChainParameters::get(chain_parameters).GetConsensus());
834}
835
837{
838 delete chain_parameters;
839}
840
842{
843 return btck_ContextOptions::create();
844}
845
847{
848 // Copy the chainparams, so the caller can free it again
849 LOCK(btck_ContextOptions::get(options).m_mutex);
850 btck_ContextOptions::get(options).m_chainparams = std::make_unique<const CChainParams>(btck_ChainParameters::get(chain_parameters));
851}
852
854{
855 // The KernelNotifications are copy-initialized, so the caller can free them again.
856 LOCK(btck_ContextOptions::get(options).m_mutex);
857 btck_ContextOptions::get(options).m_notifications = std::make_shared<KernelNotifications>(notifications);
858}
859
861{
862 LOCK(btck_ContextOptions::get(options).m_mutex);
863 btck_ContextOptions::get(options).m_validation_interface = std::make_shared<KernelValidationInterface>(vi_cbs);
864}
865
867{
868 delete options;
869}
870
872{
873 bool sane{true};
874 const ContextOptions* opts = options ? &btck_ContextOptions::get(options) : nullptr;
875 auto context{std::make_shared<const Context>(opts, sane)};
876 if (!sane) {
877 LogError("Kernel context sanity check failed.");
878 return nullptr;
879 }
880 return btck_Context::create(context);
881}
882
884{
885 return btck_Context::copy(context);
886}
887
889{
890 return (*btck_Context::get(context)->m_interrupt)() ? 0 : -1;
891}
892
894{
895 delete context;
896}
897
899{
900 if (!btck_BlockTreeEntry::get(entry).pprev) {
901 LogInfo("Genesis block has no previous.");
902 return nullptr;
903 }
904
905 return btck_BlockTreeEntry::ref(btck_BlockTreeEntry::get(entry).pprev);
906}
907
909{
910 return btck_BlockValidationState::create();
911}
912
914{
915 return btck_BlockValidationState::copy(state);
916}
917
919{
920 delete state;
921}
922
924{
925 auto& block_validation_state = btck_BlockValidationState::get(block_validation_state_);
926 if (block_validation_state.IsValid()) return btck_ValidationMode_VALID;
927 if (block_validation_state.IsInvalid()) return btck_ValidationMode_INVALID;
929}
930
932{
933 auto& block_validation_state = btck_BlockValidationState::get(block_validation_state_);
934 switch (block_validation_state.GetResult()) {
953 } // no default case, so the compiler can warn about missing cases
954 assert(false);
955}
956
957btck_ChainstateManagerOptions* btck_chainstate_manager_options_create(const btck_Context* context, const char* data_dir, size_t data_dir_len, const char* blocks_dir, size_t blocks_dir_len)
958{
959 if (data_dir == nullptr || data_dir_len == 0 || blocks_dir == nullptr || blocks_dir_len == 0) {
960 LogError("Failed to create chainstate manager options: dir must be non-null and non-empty");
961 return nullptr;
962 }
963 try {
964 fs::path abs_data_dir{fs::absolute(fs::PathFromString({data_dir, data_dir_len}))};
965 fs::create_directories(abs_data_dir);
966 fs::path abs_blocks_dir{fs::absolute(fs::PathFromString({blocks_dir, blocks_dir_len}))};
967 fs::create_directories(abs_blocks_dir);
968 return btck_ChainstateManagerOptions::create(btck_Context::get(context), abs_data_dir, abs_blocks_dir);
969 } catch (const std::exception& e) {
970 LogError("Failed to create chainstate manager options: %s", e.what());
971 return nullptr;
972 }
973}
974
976{
977 LOCK(btck_ChainstateManagerOptions::get(opts).m_mutex);
978 btck_ChainstateManagerOptions::get(opts).m_chainman_options.worker_threads_num = worker_threads;
979}
980
982{
983 delete options;
984}
985
986int btck_chainstate_manager_options_set_wipe_dbs(btck_ChainstateManagerOptions* chainman_opts, int wipe_block_tree_db, int wipe_chainstate_db)
987{
988 if (wipe_block_tree_db == 1 && wipe_chainstate_db != 1) {
989 LogError("Wiping the block tree db without also wiping the chainstate db is currently unsupported.");
990 return -1;
991 }
992 auto& opts{btck_ChainstateManagerOptions::get(chainman_opts)};
993 LOCK(opts.m_mutex);
994 opts.m_blockman_options.block_tree_db_params.wipe_data = wipe_block_tree_db == 1;
995 opts.m_chainstate_load_options.wipe_chainstate_db = wipe_chainstate_db == 1;
996 return 0;
997}
998
1000 btck_ChainstateManagerOptions* chainman_opts,
1001 int block_tree_db_in_memory)
1002{
1003 auto& opts{btck_ChainstateManagerOptions::get(chainman_opts)};
1004 LOCK(opts.m_mutex);
1005 opts.m_blockman_options.block_tree_db_params.memory_only = block_tree_db_in_memory == 1;
1006}
1007
1009 btck_ChainstateManagerOptions* chainman_opts,
1010 int chainstate_db_in_memory)
1011{
1012 auto& opts{btck_ChainstateManagerOptions::get(chainman_opts)};
1013 LOCK(opts.m_mutex);
1014 opts.m_chainstate_load_options.coins_db_in_memory = chainstate_db_in_memory == 1;
1015}
1016
1018 const btck_ChainstateManagerOptions* chainman_opts)
1019{
1020 auto& opts{btck_ChainstateManagerOptions::get(chainman_opts)};
1021 std::unique_ptr<ChainstateManager> chainman;
1022 try {
1023 LOCK(opts.m_mutex);
1024 chainman = std::make_unique<ChainstateManager>(*opts.m_context->m_interrupt, opts.m_chainman_options, opts.m_blockman_options);
1025 } catch (const std::exception& e) {
1026 LogError("Failed to create chainstate manager: %s", e.what());
1027 return nullptr;
1028 }
1029
1030 try {
1031 const auto chainstate_load_opts{WITH_LOCK(opts.m_mutex, return opts.m_chainstate_load_options)};
1032
1034 auto [status, chainstate_err]{node::LoadChainstate(*chainman, cache_sizes, chainstate_load_opts)};
1036 LogError("Failed to load chain state from your data directory: %s", chainstate_err.original);
1037 return nullptr;
1038 }
1039 std::tie(status, chainstate_err) = node::VerifyLoadedChainstate(*chainman, chainstate_load_opts);
1041 LogError("Failed to verify loaded chain state from your datadir: %s", chainstate_err.original);
1042 return nullptr;
1043 }
1044 if (auto result = chainman->ActivateBestChains(); !result) {
1045 LogError("%s", util::ErrorString(result).original);
1046 return nullptr;
1047 }
1048 } catch (const std::exception& e) {
1049 LogError("Failed to load chainstate: %s", e.what());
1050 return nullptr;
1051 }
1052
1053 return btck_ChainstateManager::create(std::move(chainman), opts.m_context);
1054}
1055
1057{
1058 auto block_index = WITH_LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex(),
1059 return btck_ChainstateManager::get(chainman).m_chainman->m_blockman.LookupBlockIndex(btck_BlockHash::get(block_hash)));
1060 if (!block_index) {
1061 LogDebug(BCLog::KERNEL, "A block with the given hash is not indexed.");
1062 return nullptr;
1063 }
1064 return btck_BlockTreeEntry::ref(block_index);
1065}
1066
1068{
1069 auto& chainman = *btck_ChainstateManager::get(chainstate_manager).m_chainman;
1070 return btck_BlockTreeEntry::ref(WITH_LOCK(chainman.GetMutex(), return chainman.m_best_header));
1071}
1072
1074{
1075 {
1076 LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex());
1077 for (const auto& chainstate : btck_ChainstateManager::get(chainman).m_chainman->m_chainstates) {
1078 if (chainstate->CanFlushToDisk()) {
1079 chainstate->ForceFlushStateToDisk();
1080 chainstate->ResetCoinsViews();
1081 }
1082 }
1083 }
1084
1085 delete chainman;
1086}
1087
1088int btck_chainstate_manager_import_blocks(btck_ChainstateManager* chainman, const char** block_file_paths_data, size_t* block_file_paths_lens, size_t block_file_paths_data_len)
1089{
1090 try {
1091 std::vector<fs::path> import_files;
1092 import_files.reserve(block_file_paths_data_len);
1093 for (uint32_t i = 0; i < block_file_paths_data_len; i++) {
1094 if (block_file_paths_data[i] != nullptr) {
1095 import_files.emplace_back(std::string{block_file_paths_data[i], block_file_paths_lens[i]}.c_str());
1096 }
1097 }
1098 auto& chainman_ref{*btck_ChainstateManager::get(chainman).m_chainman};
1099 node::ImportBlocks(chainman_ref, import_files);
1100 WITH_LOCK(::cs_main, chainman_ref.UpdateIBDStatus());
1101 } catch (const std::exception& e) {
1102 LogError("Failed to import blocks: %s", e.what());
1103 return -1;
1104 }
1105 return 0;
1106}
1107
1108btck_Block* btck_block_create(const void* raw_block, size_t raw_block_length)
1109{
1110 if (raw_block == nullptr && raw_block_length != 0) {
1111 return nullptr;
1112 }
1113 auto block{std::make_shared<CBlock>()};
1114
1115 SpanReader stream{std::span{reinterpret_cast<const std::byte*>(raw_block), raw_block_length}};
1116
1117 try {
1118 stream >> TX_WITH_WITNESS(*block);
1119 } catch (...) {
1120 LogDebug(BCLog::KERNEL, "Block decode failed.");
1121 return nullptr;
1122 }
1123
1124 return btck_Block::create(block);
1125}
1126
1128{
1129 return btck_Block::copy(block);
1130}
1131
1132int btck_block_check(const btck_Block* block, const btck_ConsensusParams* consensus_params, btck_BlockCheckFlags flags, btck_BlockValidationState* validation_state)
1133{
1134 auto& state = btck_BlockValidationState::get(validation_state);
1135 state = BlockValidationState{};
1136
1137 const bool check_pow = (flags & btck_BlockCheckFlags_POW) != 0;
1138 const bool check_merkle = (flags & btck_BlockCheckFlags_MERKLE) != 0;
1139
1140 const bool result = CheckBlock(*btck_Block::get(block), state, btck_ConsensusParams::get(consensus_params), /*fCheckPOW=*/check_pow, /*fCheckMerkleRoot=*/check_merkle);
1141
1142 return result ? 1 : 0;
1143}
1144
1146{
1147 return btck_Block::get(block)->vtx.size();
1148}
1149
1151{
1152 assert(index < btck_Block::get(block)->vtx.size());
1153 return btck_Transaction::ref(&btck_Block::get(block)->vtx[index]);
1154}
1155
1157{
1158 const auto& block_ptr = btck_Block::get(block);
1159 return btck_BlockHeader::create(static_cast<const CBlockHeader&>(*block_ptr));
1160}
1161
1162int btck_block_to_bytes(const btck_Block* block, btck_WriteBytes writer, void* user_data)
1163{
1164 try {
1165 WriterStream ws{writer, user_data};
1166 ws << TX_WITH_WITNESS(*btck_Block::get(block));
1167 return 0;
1168 } catch (...) {
1169 return -1;
1170 }
1171}
1172
1174{
1175 return btck_BlockHash::create(btck_Block::get(block)->GetHash());
1176}
1177
1179{
1180 delete block;
1181}
1182
1184{
1185 auto block{std::make_shared<CBlock>()};
1186 if (!btck_ChainstateManager::get(chainman).m_chainman->m_blockman.ReadBlock(*block, btck_BlockTreeEntry::get(entry))) {
1187 LogError("Failed to read block.");
1188 return nullptr;
1189 }
1190 return btck_Block::create(block);
1191}
1192
1194{
1195 return btck_BlockHeader::create(btck_BlockTreeEntry::get(entry).GetBlockHeader());
1196}
1197
1199{
1200 return btck_BlockTreeEntry::get(entry).nHeight;
1201}
1202
1204{
1205 return btck_BlockHash::ref(btck_BlockTreeEntry::get(entry).phashBlock);
1206}
1207
1209{
1210 return &btck_BlockTreeEntry::get(entry1) == &btck_BlockTreeEntry::get(entry2);
1211}
1212
1213btck_BlockHash* btck_block_hash_create(const unsigned char block_hash[32])
1214{
1215 return btck_BlockHash::create(std::span<const unsigned char>{block_hash, 32});
1216}
1217
1219{
1220 return btck_BlockHash::copy(block_hash);
1221}
1222
1223void btck_block_hash_to_bytes(const btck_BlockHash* block_hash, unsigned char output[32])
1224{
1225 std::memcpy(output, btck_BlockHash::get(block_hash).begin(), 32);
1226}
1227
1229{
1230 return btck_BlockHash::get(hash1) == btck_BlockHash::get(hash2);
1231}
1232
1234{
1235 delete hash;
1236}
1237
1239{
1240 auto block_undo{std::make_shared<CBlockUndo>()};
1241 if (btck_BlockTreeEntry::get(entry).nHeight < 1) {
1242 LogDebug(BCLog::KERNEL, "The genesis block does not have any spent outputs.");
1243 return btck_BlockSpentOutputs::create(block_undo);
1244 }
1245 if (!btck_ChainstateManager::get(chainman).m_chainman->m_blockman.ReadBlockUndo(*block_undo, btck_BlockTreeEntry::get(entry))) {
1246 LogError("Failed to read block spent outputs data.");
1247 return nullptr;
1248 }
1249 return btck_BlockSpentOutputs::create(block_undo);
1250}
1251
1253{
1254 return btck_BlockSpentOutputs::copy(block_spent_outputs);
1255}
1256
1258{
1259 return btck_BlockSpentOutputs::get(block_spent_outputs)->vtxundo.size();
1260}
1261
1263{
1264 assert(transaction_index < btck_BlockSpentOutputs::get(block_spent_outputs)->vtxundo.size());
1265 const auto* tx_undo{&btck_BlockSpentOutputs::get(block_spent_outputs)->vtxundo.at(transaction_index)};
1266 return btck_TransactionSpentOutputs::ref(tx_undo);
1267}
1268
1270{
1271 delete block_spent_outputs;
1272}
1273
1275{
1276 return btck_TransactionSpentOutputs::copy(transaction_spent_outputs);
1277}
1278
1280{
1281 return btck_TransactionSpentOutputs::get(transaction_spent_outputs).vprevout.size();
1282}
1283
1285{
1286 delete transaction_spent_outputs;
1287}
1288
1289const btck_Coin* btck_transaction_spent_outputs_get_coin_at(const btck_TransactionSpentOutputs* transaction_spent_outputs, size_t coin_index)
1290{
1291 assert(coin_index < btck_TransactionSpentOutputs::get(transaction_spent_outputs).vprevout.size());
1292 const Coin* coin{&btck_TransactionSpentOutputs::get(transaction_spent_outputs).vprevout.at(coin_index)};
1293 return btck_Coin::ref(coin);
1294}
1295
1297{
1298 return btck_Coin::copy(coin);
1299}
1300
1302{
1303 return btck_Coin::get(coin).nHeight;
1304}
1305
1307{
1308 return btck_Coin::get(coin).IsCoinBase() ? 1 : 0;
1309}
1310
1312{
1313 return btck_TransactionOutput::ref(&btck_Coin::get(coin).out);
1314}
1315
1317{
1318 delete coin;
1319}
1320
1322 btck_ChainstateManager* chainman,
1323 const btck_Block* block,
1324 int* _new_block)
1325{
1326 bool new_block;
1327 auto result = btck_ChainstateManager::get(chainman).m_chainman->ProcessNewBlock(btck_Block::get(block), /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block);
1328 if (_new_block) {
1329 *_new_block = new_block ? 1 : 0;
1330 }
1331 return result ? 0 : -1;
1332}
1333
1335 btck_ChainstateManager* chainstate_manager,
1336 const btck_BlockHeader* header,
1338{
1339 try {
1340 auto& chainman = btck_ChainstateManager::get(chainstate_manager).m_chainman;
1341 auto result = chainman->ProcessNewBlockHeaders({&btck_BlockHeader::get(header), 1}, /*min_pow_checked=*/true, btck_BlockValidationState::get(state), /*ppindex=*/nullptr);
1342
1343 return result ? 0 : -1;
1344 } catch (const std::exception& e) {
1345 LogError("Failed to process block header: %s", e.what());
1346 return -1;
1347 }
1348}
1349
1351{
1352 return btck_Chain::ref(&WITH_LOCK(btck_ChainstateManager::get(chainman).m_chainman->GetMutex(), return btck_ChainstateManager::get(chainman).m_chainman->ActiveChain()));
1353}
1354
1356{
1357 LOCK(::cs_main);
1358 return btck_Chain::get(chain).Height();
1359}
1360
1361const btck_BlockTreeEntry* btck_chain_get_by_height(const btck_Chain* chain, int32_t height)
1362{
1363 LOCK(::cs_main);
1364 return btck_BlockTreeEntry::ref(btck_Chain::get(chain)[height]);
1365}
1366
1368{
1369 LOCK(::cs_main);
1370 return btck_Chain::get(chain).Contains(&btck_BlockTreeEntry::get(entry)) ? 1 : 0;
1371}
1372
1373btck_BlockHeader* btck_block_header_create(const void* raw_block_header, size_t raw_block_header_len)
1374{
1375 if (raw_block_header == nullptr && raw_block_header_len != 0) {
1376 return nullptr;
1377 }
1378 auto header{std::make_unique<CBlockHeader>()};
1379 SpanReader stream{std::span{reinterpret_cast<const std::byte*>(raw_block_header), raw_block_header_len}};
1380
1381 try {
1382 stream >> *header;
1383 } catch (...) {
1384 LogError("Block header decode failed.");
1385 return nullptr;
1386 }
1387
1388 return btck_BlockHeader::ref(header.release());
1389}
1390
1392{
1393 return btck_BlockHeader::copy(header);
1394}
1395
1397{
1398 return btck_BlockHash::create(btck_BlockHeader::get(header).GetHash());
1399}
1400
1402{
1403 return btck_BlockHash::ref(&btck_BlockHeader::get(header).hashPrevBlock);
1404}
1405
1407{
1408 return btck_BlockHeader::get(header).nTime;
1409}
1410
1412{
1413 return btck_BlockHeader::get(header).nBits;
1414}
1415
1417{
1418 return btck_BlockHeader::get(header).nVersion;
1419}
1420
1422{
1423 return btck_BlockHeader::get(header).nNonce;
1424}
1425
1426int btck_block_header_to_bytes(const btck_BlockHeader* header, unsigned char output[80])
1427{
1428 try {
1429 SpanWriter{std::as_writable_bytes(std::span{output, 80})} << btck_BlockHeader::get(header);
1430 return 0;
1431 } catch (...) {
1432 return -1;
1433 }
1434}
1435
1437{
1438 delete header;
1439}
int flags
Definition: bitcoin-tx.cpp:530
ArgsManager & args
Definition: bitcoind.cpp:278
int btck_block_to_bytes(const btck_Block *block, btck_WriteBytes writer, void *user_data)
btck_ScriptPubkey * btck_script_pubkey_copy(const btck_ScriptPubkey *script_pubkey)
Copy a script pubkey.
void btck_logging_disable()
This disables the global internal logger.
btck_BlockHash * btck_block_hash_copy(const btck_BlockHash *block_hash)
Copy a block hash.
void btck_txid_destroy(btck_Txid *txid)
Destroy the txid.
int btck_script_pubkey_to_bytes(const btck_ScriptPubkey *script_pubkey_, btck_WriteBytes writer, void *user_data)
void btck_script_pubkey_destroy(btck_ScriptPubkey *script_pubkey)
Destroy the script pubkey.
int btck_chainstate_manager_import_blocks(btck_ChainstateManager *chainman, const char **block_file_paths_data, size_t *block_file_paths_lens, size_t block_file_paths_data_len)
Triggers the start of a reindex if the wipe options were previously set for the chainstate manager.
const btck_Coin * btck_transaction_spent_outputs_get_coin_at(const btck_TransactionSpentOutputs *transaction_spent_outputs, size_t coin_index)
Returns a coin contained in the transaction spent outputs at a certain index.
const btck_TransactionInput * btck_transaction_get_input_at(const btck_Transaction *transaction, size_t input_index)
Get the transaction input at the provided index.
void btck_logging_enable_category(btck_LogCategory category)
Enable a specific log category for the global internal logger.
uint32_t btck_coin_confirmation_height(const btck_Coin *coin)
Returns the block height where the transaction that created this coin was included in.
void btck_context_destroy(btck_Context *context)
Destroy the context.
void btck_context_options_set_notifications(btck_ContextOptions *options, btck_NotificationInterfaceCallbacks notifications)
Set the kernel notifications for the context options.
btck_ContextOptions * btck_context_options_create()
Creates an empty context options.
void btck_transaction_destroy(btck_Transaction *transaction)
Destroy the transaction.
btck_PrecomputedTransactionData * btck_precomputed_transaction_data_create(const btck_Transaction *tx_to, const btck_TransactionOutput **spent_outputs_, size_t spent_outputs_len)
Create precomputed transaction data for script verification.
int64_t btck_transaction_output_get_amount(const btck_TransactionOutput *output)
Get the amount in the output.
void btck_chainstate_manager_options_update_chainstate_db_in_memory(btck_ChainstateManagerOptions *chainman_opts, int chainstate_db_in_memory)
Sets chainstate db in memory in the options.
uint32_t btck_block_header_get_nonce(const btck_BlockHeader *header)
Get the nonce from btck_BlockHeader.
const btck_Txid * btck_transaction_out_point_get_txid(const btck_TransactionOutPoint *out_point)
Get the txid from the transaction out point.
void btck_logging_disable_category(btck_LogCategory category)
Disable a specific log category for the global internal logger.
btck_BlockValidationState * btck_block_validation_state_create()
Create a new btck_BlockValidationState.
void btck_transaction_spent_outputs_destroy(btck_TransactionSpentOutputs *transaction_spent_outputs)
Destroy the transaction spent outputs.
const btck_BlockTreeEntry * btck_block_tree_entry_get_previous(const btck_BlockTreeEntry *entry)
Returns the previous block tree entry in the tree, or null if the current block tree entry is the gen...
void btck_chain_parameters_destroy(btck_ChainParameters *chain_parameters)
Destroy the chain parameters.
size_t btck_transaction_count_outputs(const btck_Transaction *transaction)
Get the number of outputs of a transaction.
void btck_block_destroy(btck_Block *block)
Destroy the block.
btck_ScriptPubkey * btck_script_pubkey_create(const void *script_pubkey, size_t script_pubkey_len)
Create a script pubkey from serialized data.
btck_Context * btck_context_copy(const btck_Context *context)
Copy the context.
const btck_BlockTreeEntry * btck_chainstate_manager_get_best_entry(const btck_ChainstateManager *chainstate_manager)
Get the btck_BlockTreeEntry whose associated btck_BlockHeader has the most known cumulative proof of ...
btck_ChainParameters * btck_chain_parameters_create(const btck_ChainType chain_type)
Creates a chain parameters struct with default parameters based on the passed in chain type.
int32_t btck_block_header_get_version(const btck_BlockHeader *header)
Get the version from btck_BlockHeader.
btck_ValidationMode btck_block_validation_state_get_validation_mode(const btck_BlockValidationState *block_validation_state_)
Returns the validation mode from an opaque btck_BlockValidationState pointer.
btck_Block * btck_block_create(const void *raw_block, size_t raw_block_length)
Parse a serialized raw block into a new block object.
void btck_chainstate_manager_options_update_block_tree_db_in_memory(btck_ChainstateManagerOptions *chainman_opts, int block_tree_db_in_memory)
Sets block tree db in memory in the options.
static const kernel::Context btck_context_static
btck_ChainParameters * btck_chain_parameters_copy(const btck_ChainParameters *chain_parameters)
Copy the chain parameters.
int btck_block_tree_entry_equals(const btck_BlockTreeEntry *entry1, const btck_BlockTreeEntry *entry2)
uint32_t btck_block_header_get_bits(const btck_BlockHeader *header)
Get the nBits difficulty target from btck_BlockHeader.
int32_t btck_chain_get_height(const btck_Chain *chain)
Return the height of the tip of the chain.
btck_BlockHeader * btck_block_get_header(const btck_Block *block)
Get the btck_BlockHeader from the block.
size_t btck_block_count_transactions(const btck_Block *block)
Count the number of transactions contained in a block.
void btck_context_options_destroy(btck_ContextOptions *options)
Destroy the context options.
btck_LoggingConnection * btck_logging_connection_create(btck_LogCallback callback, void *user_data, btck_DestroyCallback user_data_destroy_callback)
Start logging messages through the provided callback.
btck_BlockHeader * btck_block_header_copy(const btck_BlockHeader *header)
Copy a btck_BlockHeader.
int btck_script_pubkey_verify(const btck_ScriptPubkey *script_pubkey, const int64_t amount, const btck_Transaction *tx_to, const btck_PrecomputedTransactionData *precomputed_txdata, const unsigned int input_index, const btck_ScriptVerificationFlags flags, btck_ScriptVerifyStatus *status)
btck_BlockSpentOutputs * btck_block_spent_outputs_copy(const btck_BlockSpentOutputs *block_spent_outputs)
Copy a block's spent outputs.
void btck_precomputed_transaction_data_destroy(btck_PrecomputedTransactionData *precomputed_txdata)
Destroy the precomputed transaction data.
const btck_TransactionOutPoint * btck_transaction_input_get_out_point(const btck_TransactionInput *input)
Get the transaction out point.
btck_BlockSpentOutputs * btck_block_spent_outputs_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
btck_ChainstateManager * btck_chainstate_manager_create(const btck_ChainstateManagerOptions *chainman_opts)
Create a chainstate manager.
void btck_block_validation_state_destroy(btck_BlockValidationState *state)
Destroy the btck_BlockValidationState.
btck_BlockHash * btck_block_get_hash(const btck_Block *block)
Calculate and return the hash of a block.
btck_Txid * btck_txid_copy(const btck_Txid *txid)
Copy a txid.
const btck_TransactionSpentOutputs * btck_block_spent_outputs_get_transaction_spent_outputs_at(const btck_BlockSpentOutputs *block_spent_outputs, size_t transaction_index)
Returns a transaction spent outputs contained in the block spent outputs at a certain index.
btck_Context * btck_context_create(const btck_ContextOptions *options)
Create a new kernel context.
const btck_TransactionOutput * btck_coin_get_output(const btck_Coin *coin)
Return the transaction output of a coin.
void btck_transaction_out_point_destroy(btck_TransactionOutPoint *out_point)
Destroy the transaction out point.
uint32_t btck_transaction_get_locktime(const btck_Transaction *transaction)
Get a transaction's nLockTime value.
int btck_coin_is_coinbase(const btck_Coin *coin)
Returns whether the containing transaction was a coinbase.
void btck_txid_to_bytes(const btck_Txid *txid, unsigned char output[32])
void btck_block_hash_destroy(btck_BlockHash *hash)
Destroy the block hash.
int btck_chainstate_manager_options_set_wipe_dbs(btck_ChainstateManagerOptions *chainman_opts, int wipe_block_tree_db, int wipe_chainstate_db)
Sets wipe db in the options.
btck_BlockHeader * btck_block_tree_entry_get_block_header(const btck_BlockTreeEntry *entry)
Return the btck_BlockHeader associated with this entry.
int btck_context_interrupt(btck_Context *context)
Interrupt can be used to halt long-running validation functions like when reindexing,...
const btck_ConsensusParams * btck_chain_parameters_get_consensus_params(const btck_ChainParameters *chain_parameters)
Get btck_ConsensusParams from btck_ChainParameters.
void btck_transaction_input_destroy(btck_TransactionInput *input)
Destroy the transaction input.
const btck_TransactionOutput * btck_transaction_get_output_at(const btck_Transaction *transaction, size_t output_index)
Get the transaction outputs at the provided index.
const btck_BlockTreeEntry * btck_chain_get_by_height(const btck_Chain *chain, int32_t height)
Retrieve a block tree entry by its height in the currently active chain.
void btck_logging_set_level_category(btck_LogCategory category, btck_LogLevel level)
Set the log level of the global internal logger.
void btck_coin_destroy(btck_Coin *coin)
Destroy the coin.
void btck_context_options_set_chainparams(btck_ContextOptions *options, const btck_ChainParameters *chain_parameters)
int btck_block_header_to_bytes(const btck_BlockHeader *header, unsigned char output[80])
btck_BlockHeader * btck_block_header_create(const void *raw_block_header, size_t raw_block_header_len)
Create a btck_BlockHeader from serialized data.
uint32_t btck_block_header_get_timestamp(const btck_BlockHeader *header)
Get the timestamp from btck_BlockHeader.
void btck_block_header_destroy(btck_BlockHeader *header)
Destroy the btck_BlockHeader.
btck_PrecomputedTransactionData * btck_precomputed_transaction_data_copy(const btck_PrecomputedTransactionData *precomputed_txdata)
Copy precomputed transaction data.
btck_BlockHash * btck_block_hash_create(const unsigned char block_hash[32])
Create a block hash from its raw data.
btck_BlockHash * btck_block_header_get_hash(const btck_BlockHeader *header)
Get the btck_BlockHash.
int btck_chainstate_manager_process_block_header(btck_ChainstateManager *chainstate_manager, const btck_BlockHeader *header, btck_BlockValidationState *state)
const TranslateFn G_TRANSLATION_FUN
Definition: bitcoin-cli.cpp:57
void btck_context_options_set_validation_interface(btck_ContextOptions *options, btck_ValidationInterfaceCallbacks vi_cbs)
Set the validation interface callbacks for the context options.
uint32_t btck_transaction_out_point_get_index(const btck_TransactionOutPoint *out_point)
Get the output position from the transaction out point.
const btck_BlockHash * btck_block_header_get_prev_hash(const btck_BlockHeader *header)
Get the previous btck_BlockHash from btck_BlockHeader.
btck_Block * btck_block_read(const btck_ChainstateManager *chainman, const btck_BlockTreeEntry *entry)
const btck_Txid * btck_transaction_get_txid(const btck_Transaction *transaction)
Get the txid of a transaction.
btck_TransactionOutPoint * btck_transaction_out_point_copy(const btck_TransactionOutPoint *out_point)
Copy a transaction out point.
btck_TransactionInput * btck_transaction_input_copy(const btck_TransactionInput *input)
Copy a transaction input.
int btck_chain_contains(const btck_Chain *chain, const btck_BlockTreeEntry *entry)
const btck_BlockTreeEntry * btck_chainstate_manager_get_block_tree_entry_by_hash(const btck_ChainstateManager *chainman, const btck_BlockHash *block_hash)
size_t btck_block_spent_outputs_count(const btck_BlockSpentOutputs *block_spent_outputs)
Returns the number of transaction spent outputs whose data is contained in block spent outputs.
btck_TransactionOutput * btck_transaction_output_copy(const btck_TransactionOutput *output)
Copy a transaction output.
int btck_block_hash_equals(const btck_BlockHash *hash1, const btck_BlockHash *hash2)
void btck_logging_connection_destroy(btck_LoggingConnection *connection)
Stop logging and destroy the logging connection.
btck_TransactionSpentOutputs * btck_transaction_spent_outputs_copy(const btck_TransactionSpentOutputs *transaction_spent_outputs)
Copy a transaction's spent outputs.
int32_t btck_block_tree_entry_get_height(const btck_BlockTreeEntry *entry)
Return the height of a certain block tree entry.
void btck_block_spent_outputs_destroy(btck_BlockSpentOutputs *block_spent_outputs)
Destroy the block spent outputs.
const btck_ScriptPubkey * btck_transaction_output_get_script_pubkey(const btck_TransactionOutput *output)
Get the script pubkey of the output.
int btck_chainstate_manager_process_block(btck_ChainstateManager *chainman, const btck_Block *block, int *_new_block)
size_t btck_transaction_count_inputs(const btck_Transaction *transaction)
Get the number of inputs of a transaction.
int btck_block_check(const btck_Block *block, const btck_ConsensusParams *consensus_params, btck_BlockCheckFlags flags, btck_BlockValidationState *validation_state)
int btck_txid_equals(const btck_Txid *txid1, const btck_Txid *txid2)
btck_Block * btck_block_copy(const btck_Block *block)
Copy a block.
void btck_chainstate_manager_destroy(btck_ChainstateManager *chainman)
Destroy the chainstate manager.
void btck_chainstate_manager_options_destroy(btck_ChainstateManagerOptions *options)
Destroy the chainstate manager options.
btck_Transaction * btck_transaction_create(const void *raw_transaction, size_t raw_transaction_len)
Create a new transaction from the serialized data.
btck_Coin * btck_coin_copy(const btck_Coin *coin)
Copy a coin.
const btck_BlockHash * btck_block_tree_entry_get_block_hash(const btck_BlockTreeEntry *entry)
Return the block hash associated with a block tree entry.
void btck_logging_set_options(const btck_LoggingOptions options)
Set some options for the global internal logger.
void btck_chainstate_manager_options_set_worker_threads_num(btck_ChainstateManagerOptions *opts, int worker_threads)
Set the number of available worker threads used during validation.
int btck_transaction_to_bytes(const btck_Transaction *transaction, btck_WriteBytes writer, void *user_data)
btck_TransactionOutput * btck_transaction_output_create(const btck_ScriptPubkey *script_pubkey, int64_t amount)
Create a transaction output from a script pubkey and an amount.
btck_Transaction * btck_transaction_copy(const btck_Transaction *transaction)
Copy a transaction.
const btck_Transaction * btck_block_get_transaction_at(const btck_Block *block, size_t index)
Get the transaction at the provided index.
const btck_Chain * btck_chainstate_manager_get_active_chain(const btck_ChainstateManager *chainman)
Returns the best known currently active chain.
btck_ChainstateManagerOptions * btck_chainstate_manager_options_create(const btck_Context *context, const char *data_dir, size_t data_dir_len, const char *blocks_dir, size_t blocks_dir_len)
Create options for the chainstate manager.
btck_BlockValidationResult btck_block_validation_state_get_block_validation_result(const btck_BlockValidationState *block_validation_state_)
Returns the validation result from an opaque btck_BlockValidationState pointer.
btck_BlockValidationState * btck_block_validation_state_copy(const btck_BlockValidationState *state)
Copies the btck_BlockValidationState.
void btck_block_hash_to_bytes(const btck_BlockHash *block_hash, unsigned char output[32])
uint32_t btck_transaction_input_get_sequence(const btck_TransactionInput *input)
Get a transaction input's nSequence value.
void btck_transaction_output_destroy(btck_TransactionOutput *output)
Destroy the transaction output.
size_t btck_transaction_spent_outputs_count(const btck_TransactionSpentOutputs *transaction_spent_outputs)
Returns the number of previous transaction outputs contained in the transaction spent outputs data.
#define btck_ChainType_REGTEST
uint8_t btck_LogLevel
The level at which logs should be produced.
int(* btck_WriteBytes)(const void *bytes, size_t size, void *userdata)
Function signature for serializing data.
#define btck_ChainType_MAINNET
#define btck_BlockValidationResult_HEADER_LOW_WORK
the block header may be on a too-little-work chain
#define btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED
uint8_t btck_ChainType
#define btck_BlockValidationResult_INVALID_PREV
A block this one builds on is invalid.
#define btck_BlockCheckFlags_MERKLE
verify merkle root (and mutation detection)
#define btck_LogCategory_MEMPOOL
#define btck_LogLevel_TRACE
#define btck_ChainType_TESTNET
#define btck_SynchronizationState_INIT_REINDEX
void(* btck_LogCallback)(void *user_data, const char *message, size_t message_len)
Callback function types.
#define btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION
The flags were combined in an invalid way.
uint32_t btck_BlockValidationResult
A granular "reason" why a block was invalid.
#define btck_LogCategory_BENCH
uint8_t btck_ValidationMode
Whether a validated data structure is valid, invalid, or an error was encountered during processing.
#define btck_ScriptVerificationFlags_ALL
#define btck_LogCategory_PRUNE
uint8_t btck_SynchronizationState
Current sync state passed to tip changed callbacks.
#define btck_ChainType_TESTNET_4
#define btck_LogCategory_COINDB
#define btck_ScriptVerificationFlags_TAPROOT
enable TAPROOT (BIPs 341 & 342)
#define btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED
The taproot flag was set, so valid spent_outputs have to be provided.
#define btck_BlockCheckFlags_POW
run CheckProofOfWork via CheckBlockHeader
void(* btck_DestroyCallback)(void *user_data)
Function signature for freeing user data.
uint32_t btck_ScriptVerificationFlags
Script verification flags that may be composed with each other.
#define btck_LogCategory_VALIDATION
#define btck_LogCategory_REINDEX
#define btck_LogLevel_DEBUG
#define btck_ScriptVerifyStatus_OK
#define btck_LogCategory_RAND
#define btck_BlockValidationResult_CONSENSUS
invalid by consensus rules (excluding any below reasons)
#define btck_BlockValidationResult_UNSET
initial value. Block has not yet been rejected
#define btck_SynchronizationState_POST_INIT
#define btck_BlockValidationResult_MISSING_PREV
We don't have the previous block the checked one is built on.
#define btck_LogCategory_ALL
uint8_t btck_ScriptVerifyStatus
A collection of status codes that may be issued by the script verify function.
#define btck_ValidationMode_INTERNAL_ERROR
uint8_t btck_LogCategory
A collection of logging categories that may be encountered by kernel code.
#define btck_ValidationMode_INVALID
#define btck_ChainType_SIGNET
uint32_t btck_BlockCheckFlags
Bitflags to control context-free block checks (optional).
#define btck_BlockValidationResult_INVALID_HEADER
invalid proof of work or time too old
uint8_t btck_Warning
Possible warning types issued by validation.
#define btck_BlockValidationResult_TIME_FUTURE
block timestamp was > 2 hours in the future (or our clock is bad)
#define btck_LogCategory_LEVELDB
#define btck_BlockValidationResult_CACHED_INVALID
this block was cached as being invalid and we didn't store the reason why
#define btck_Warning_LARGE_WORK_INVALID_CHAIN
#define btck_LogLevel_INFO
#define btck_LogCategory_BLOCKSTORAGE
#define btck_ValidationMode_VALID
#define btck_LogCategory_KERNEL
#define btck_BlockValidationResult_MUTATED
the block's data didn't match the data committed to by the PoW
#define btck_SynchronizationState_INIT_DOWNLOAD
const CChainParams & Params()
Return the currently selected parameters.
bool m_always_print_category_level
Definition: logging.h:185
bool m_log_sourcelocations
Definition: logging.h:184
void SetLogLevel(Level level)
Definition: logging.h:261
size_t NumConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:216
bool m_log_time_micros
Definition: logging.h:182
bool m_log_threadnames
Definition: logging.h:183
std::list< std::function< void(conststd::string &)> >::iterator PushBackCallback(std::function< void(const std::string &)> fun) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Connect a slot to the print signal and return the connection.
Definition: logging.h:202
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Disable logging This offers a slight speedup and slightly smaller memory usage compared to leaving th...
Definition: logging.cpp:111
bool StartLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Start logging (and flush all buffered messages)
Definition: logging.cpp:54
void EnableCategory(LogFlags flag)
Definition: logging.cpp:123
void AddCategoryLogLevel(LogFlags category, Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:253
bool m_log_timestamps
Definition: logging.h:181
void DeleteCallback(std::list< std::function< void(const std::string &)> >::iterator it) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Delete a connection.
Definition: logging.h:210
void DisconnectTestLogger() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Only for testing.
Definition: logging.cpp:98
void DisableCategory(LogFlags flag)
Definition: logging.cpp:137
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:27
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:94
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:77
static std::unique_ptr< const CChainParams > Main()
static std::unique_ptr< const CChainParams > RegTest(const RegTestOptions &options)
static std::unique_ptr< const CChainParams > TestNet()
static std::unique_ptr< const CChainParams > TestNet4()
static std::unique_ptr< const CChainParams > SigNet(const SigNetOptions &options)
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
const std::vector< CTxOut > vout
Definition: transaction.h:292
An output of a transaction.
Definition: transaction.h:140
Implement this to subscribe to events generated in validation and mempool.
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &block)
Notifies listeners that a block which builds directly on our current tip has been received and connec...
virtual void BlockChecked(const std::shared_ptr< const CBlock > &, const BlockValidationState &)
Notifies listeners of a block validation result.
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being disconnected Provides the block that was disconnected.
virtual void BlockConnected(const kernel::ChainstateRole &role, const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being connected.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition: validation.h:940
A UTXO entry.
Definition: coins.h:35
Minimal stream for reading from an existing byte array by std::span.
Definition: streams.h:83
Minimal stream for writing to an existing span of bytes.
Definition: streams.h:130
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Register subscriber.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > callbacks)
Unregister subscriber.
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 fatalError(const bilingual_str &message)
The fatal error notification is sent to notify the user when an error occurs in kernel code that can'...
virtual void warningSet(Warning id, const bilingual_str &message)
virtual void progress(const bilingual_str &title, int progress_percent, bool resume_possible)
virtual InterruptResult blockTip(SynchronizationState state, const CBlockIndex &index, double verification_progress)
virtual void flushError(const bilingual_str &message)
The flush error notification is sent to notify the user that an error occurred while flushing block d...
virtual void warningUnset(Warning id)
static constexpr script_verify_flags from_int(value_type f)
Definition: verify_flags.h:35
NumConnections
Definition: clientmodel.h:48
btcsignals::scoped_connection m_connection
Definition: interfaces.cpp:30
@ 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
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
static path absolute(const path &p)
Definition: fs.h:89
static path PathFromString(const std::string &string)
Convert byte string to path object.
Definition: fs.h:185
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
@ FAIL
Just act as if the signature was invalid.
Context m_context
Definition: protocol.cpp:141
static constexpr size_t DEFAULT_KERNEL_CACHE
Suggested default amount of cache reserved for the kernel (bytes)
Definition: caches.h:13
#define LogInfo(...)
Definition: log.h:97
#define LogError(...)
Definition: log.h:99
#define LogDebug(category,...)
Definition: log.h:117
BCLog::Logger & LogInstance()
Definition: logging.cpp:26
unsigned int nHeight
LogFlags
Definition: categories.h:14
@ RAND
Definition: categories.h:29
@ BLOCKSTORAGE
Definition: categories.h:43
@ COINDB
Definition: categories.h:34
@ REINDEX
Definition: categories.h:27
@ ALL
Definition: categories.h:49
@ LEVELDB
Definition: categories.h:36
@ VALIDATION
Definition: categories.h:37
@ PRUNE
Definition: categories.h:30
@ MEMPOOL
Definition: categories.h:18
@ BENCH
Definition: categories.h:20
@ KERNEL
Definition: categories.h:47
Transaction validation functions.
std::ostream & operator<<(std::ostream &os, BigO const &bigO)
std::variant< std::monostate, Interrupted > InterruptResult
Simple result type for functions that need to propagate an interrupt status and don't have other retu...
Warning
Definition: warning.h:9
util::Result< void > SanityChecks(const Context &)
Ensure a usable environment with all necessary library support.
Definition: checks.cpp:15
Definition: messages.h:21
ChainstateLoadResult LoadChainstate(ChainstateManager &chainman, const CacheSizes &cache_sizes, const ChainstateLoadOptions &options)
Definition: chainstate.cpp:150
ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager &chainman, const ChainstateLoadOptions &options)
Definition: chainstate.cpp:239
void ImportBlocks(ChainstateManager &chainman, std::span< const fs::path > import_paths)
Definition: common.h:30
Level
Definition: log.h:43
bilingual_str ErrorString(const Result< T > &result)
Definition: result.h:93
ValidationSignals & m_signals
Definition: interfaces.cpp:504
std::shared_ptr< Chain::Notifications > m_notifications
Definition: interfaces.cpp:485
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:180
void Serialize(Stream &, V)=delete
constexpr deserialize_type deserialize
Definition: serialize.h:51
Application-specific storage settings.
Definition: dbwrapper.h:33
Bilingual messages:
Definition: translation.h:24
std::string original
Definition: translation.h:25
Options controlling the format of log messages.
int always_print_category_levels
Prepend the log category and level to log messages.
int log_time_micros
Log timestamps in microsecond precision.
int log_threadnames
Prepend the name of the thread to log messages.
int log_sourcelocations
Prepend the source location to log messages.
int log_timestamps
Prepend a timestamp to log messages.
A struct for holding the kernel notification callbacks.
btck_NotifyWarningUnset warning_unset
A previous condition leading to the issuance of a warning is no longer given.
btck_NotifyBlockTip block_tip
The chain's tip was updated to the provided block entry.
btck_NotifyWarningSet warning_set
A warning issued by the kernel library during validation.
btck_NotifyFlushError flush_error
An error encountered when flushing data to disk.
btck_NotifyProgress progress
Reports on current block synchronization progress.
btck_NotifyFatalError fatal_error
An unrecoverable system error encountered by the library.
btck_DestroyCallback user_data_destroy
Frees the provided user data structure.
void * user_data
Holds a user-defined opaque structure that is passed to the notification callbacks.
btck_NotifyHeaderTip header_tip
A new best block header was added.
Holds the validation interface callbacks.
btck_DestroyCallback user_data_destroy
Frees the provided user data structure.
btck_ValidationInterfaceBlockConnected block_connected
Called when a block is valid and has now been connected to the best chain.
btck_ValidationInterfaceBlockChecked block_checked
Called when a new block has been fully validated.
btck_ValidationInterfaceBlockDisconnected block_disconnected
Called during a re-org when a block has been removed from the best chain.
void * user_data
Holds a user-defined opaque structure that is passed to the validation interface callbacks.
btck_ValidationInterfacePoWValidBlock pow_valid_block
Called when a new block extends the header chain and has a valid transaction and segwit merkle root.
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
Information about chainstate that notifications are sent from.
Definition: types.h:18
Context struct holding the kernel library's logically global state, and passed to external libbitcoin...
Definition: context.h:16
#define LOCK(cs)
Definition: sync.h:268
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:299
This header provides an interface and simple implementation for a task runner.
#define GUARDED_BY(x)
Definition: threadsafety.h:37
std::function< std::string(const char *)> TranslateFn
Translate a message to the native language of the user.
Definition: translation.h:16
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
Functions for validating blocks and updating the block tree.
assert(!tx.IsCoinBase())
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:93