Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions builds/gnu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ src_libbitcoin_node_la_SOURCES = \
${srcdir}/../../src/full_node.cpp \
${srcdir}/../../src/rolling_bloom_filter.cpp \
${srcdir}/../../src/settings.cpp \
${srcdir}/../../src/solo_spans.cpp \
${srcdir}/../../src/channels/channel_peer.cpp \
${srcdir}/../../src/chasers/chaser.cpp \
${srcdir}/../../src/chasers/chaser_confirm.cpp \
Expand Down Expand Up @@ -141,6 +142,7 @@ include_bitcoin_node_HEADERS = \
${srcdir}/../../include/bitcoin/node/preprocessor.hpp \
${srcdir}/../../include/bitcoin/node/rolling_bloom_filter.hpp \
${srcdir}/../../include/bitcoin/node/settings.hpp \
${srcdir}/../../include/bitcoin/node/solo_spans.hpp \
include/bitcoin/node/version.hpp

include_bitcoin_node_channelsdir = \
Expand Down Expand Up @@ -243,6 +245,7 @@ test_libbitcoin_node_test_SOURCES = \
${srcdir}/../../test/main.cpp \
${srcdir}/../../test/rolling_bloom_filter.cpp \
${srcdir}/../../test/settings.cpp \
${srcdir}/../../test/solo_spans.cpp \
${srcdir}/../../test/test.cpp \
${srcdir}/../../test/chasers/chaser.cpp \
${srcdir}/../../test/chasers/chaser_confirm.cpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<ClCompile Include="..\..\..\..\test\rolling_bloom_filter.cpp" />
<ClCompile Include="..\..\..\..\test\sessions\session.cpp" />
<ClCompile Include="..\..\..\..\test\settings.cpp" />
<ClCompile Include="..\..\..\..\test\solo_spans.cpp" />
<ClCompile Include="..\..\..\..\test\test.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<ClCompile Include="..\..\..\..\test\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\solo_spans.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\test\test.cpp">
<Filter>src</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<ClCompile Include="..\..\..\..\src\sessions\session_manual.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session_outbound.cpp" />
<ClCompile Include="..\..\..\..\src\settings.cpp" />
<ClCompile Include="..\..\..\..\src\solo_spans.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\include\bitcoin\node.hpp" />
Expand Down Expand Up @@ -222,6 +223,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\solo_spans.hpp" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\include\bitcoin\node\impl\sessions\session_peer.ipp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
<ClCompile Include="..\..\..\..\src\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\solo_spans.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\include\bitcoin\node.hpp">
Expand Down Expand Up @@ -374,6 +377,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\solo_spans.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\build\include\bitcoin\node\version.hpp">
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <bitcoin/node/preprocessor.hpp>
#include <bitcoin/node/rolling_bloom_filter.hpp>
#include <bitcoin/node/settings.hpp>
#include <bitcoin/node/solo_spans.hpp>
#include <bitcoin/node/version.hpp>
#include <bitcoin/node/channels/channel.hpp>
#include <bitcoin/node/channels/channel_peer.hpp>
Expand Down
20 changes: 16 additions & 4 deletions include/bitcoin/node/chase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,15 @@ enum class chase
/// -----------------------------------------------------------------------

/// A current block has been organized.
/// Issued by 'confirm' and handled by 'protocol_header/block_out'.
/// Issued by 'confirm' and handled by 'transaction',
/// 'protocol_header/block_out'.
block,

/// The store has been pruned (once, following the first current block).
/// A current block has been settled in the pool.
/// Issued by 'transaction' and handled by 'snapshot'.
block_settled,

/// The store has been pruned (once, following the first settled block).
/// Issued by 'snapshot' and handled by 'transaction'.
pruned,

Expand All @@ -173,10 +178,10 @@ enum class chase
/// -----------------------------------------------------------------------

/// A transaction has been added to the pool.
/// Issued by 'transaction' and handled by 'template'.
/// Issued by 'transaction' and handled by 'protocol_transaction_out'.
transaction,

/// A candidate block (template) has been created.
/// A candidate block (template) has been created, upon request.
/// Issued by 'template' and handled by [miners].
template_,

Expand Down Expand Up @@ -329,6 +334,12 @@ struct block
header_t link;
};

struct block_settled
{
static constexpr chase id{ chase::block_settled };
header_t link;
};

struct pruned
{
static constexpr chase id{ chase::pruned };
Expand Down Expand Up @@ -398,6 +409,7 @@ using event_value = std::variant
chases::confirmable,
chases::unconfirmable,
chases::block,
chases::block_settled,
chases::pruned,
chases::stale,
chases::organized,
Expand Down
21 changes: 7 additions & 14 deletions include/bitcoin/node/chasers/chaser_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace node {

class full_node;

/// Construct template blocks upon modification of the transaction DAG.
/// Construct template blocks upon request.
class BCN_API chaser_template
: public chaser
{
Expand All @@ -38,27 +38,20 @@ class BCN_API chaser_template

code start() NOEXCEPT override;

/// The latest template of pooled txs, parents first, and its height.
/// A template of pooled txs built upon the request, parents first, and
/// its height.
virtual void get_template(template_handler&& handler) NOEXCEPT;

protected:
virtual bool handle_chase(const code& ec, event_value value) NOEXCEPT;

virtual void do_update() NOEXCEPT;
virtual void do_get_template(const template_handler& handler) NOEXCEPT;

private:
void build() NOEXCEPT;
void handle_build(const code& ec, size_t height,
const database::tx_links& links) NOEXCEPT;
const database::tx_links& links,
const template_handler& handler) NOEXCEPT;
void do_build(const code& ec, size_t height,
const database::tx_links& links) NOEXCEPT;

// These are protected by strand.
database::tx_links links_{};
size_t height_{};
bool building_{};
bool stale_{};
const database::tx_links& links,
const template_handler& handler) NOEXCEPT;
};

} // namespace node
Expand Down
81 changes: 67 additions & 14 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef LIBBITCOIN_NODE_CHASERS_CHASER_TRANSACTION_HPP
#define LIBBITCOIN_NODE_CHASERS_CHASER_TRANSACTION_HPP

#include <chrono>
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>

Expand All @@ -40,45 +41,78 @@ class BCN_API chaser_transaction
void stopping(const code& ec) NOEXCEPT override;
void stop() NOEXCEPT override;

/// Validate and archive a submitted package, accepted as a whole.
/// The package is only validated when test, so nothing is archived.
/// Validate and archive a submitted set, admitted prefix by prefix until
/// one tx fails. The set is only validated when test, nothing archived.
virtual void submit(const system::chain::transactions_cptr& txs,
bool test, submit_handler&& handler) NOEXCEPT;

/// Validate and archive an announced set, admitted prefix by prefix, a tx
/// that is not accepted passed over (the first such failure reported).
virtual void submit_announced(
const system::chain::transactions_cptr& txs,
submit_handler&& handler) NOEXCEPT;

/// Validate, archive and associate the txs of an identified compact block,
/// in block order, the txs filling the terminal links.
virtual void submit_compact(const system::chain::transactions_cptr& txs,
const database::tx_links& links, const database::header_link& link,
submit_handler&& handler) NOEXCEPT;

/// Archive and associate the txs of an identified block. Not pooling, on
/// the calling thread, returning true with the code. Pooling, on the
/// strand with compact blocks, returning false and handling the code
/// (thread safe).
virtual bool archive_block(code& ec,
const system::chain::view::block::cptr& block,
const database::header_link& link, bool strong, bool bypass,
size_t height, bool prune, network::result_handler&& handler) NOEXCEPT;

/// Build a template of pooled txs, parents first, and its height.
virtual void build_template(template_handler&& handler) NOEXCEPT;

/// Lowest rate (per virtual kilobyte) confirmed by the target block.
virtual void estimate(size_t target, estimate_mode mode,
estimate_handler&& handler) NOEXCEPT;

/// Subscribe to pool scans (notified on the strand).
virtual void subscribe_pool(pool_notifier&& handler) NOEXCEPT;

protected:
using chaser::broadcast;

virtual bool handle_chase(const code& ec, event_value value) NOEXCEPT;

virtual void do_submit(const system::chain::transactions_cptr& txs,
bool test, const submit_handler& handler) NOEXCEPT;
bool test, bool announced, const submit_handler& handler) NOEXCEPT;
virtual void do_submit_compact(
const system::chain::transactions_cptr& txs,
const database::tx_links& links, const database::header_link& link,
const submit_handler& handler) NOEXCEPT;
virtual void do_archive_block(
const system::chain::view::block::cptr& block,
const database::header_link& link, bool strong, bool bypass,
size_t height, bool prune,
const network::result_handler& handler) NOEXCEPT;
virtual void do_build_template(const template_handler& handler) NOEXCEPT;
virtual void do_estimate(size_t target, estimate_mode mode,
const estimate_handler& handler) NOEXCEPT;

/// Recompute the pool context, closing the pool if not current, and map
/// scan starts: built once current, extended by block until pooling, and
/// Recompute the pool context and sweep the index by it if due, closing
/// the pool if not current or the context is not reusable, and map scan
/// starts: built once current, extended by block until pooling, and
/// remapped when a block archived before the latch is organized.
virtual void do_bump() NOEXCEPT;

/// Pool the unpooled txs of a reorganized block.
/// Retain the pool subscription.
virtual void do_subscribe_pool(const pool_notifier& handler) NOEXCEPT;

/// Apply the organized block to the pool index, then bump.
virtual void do_organized(header_t link) NOEXCEPT;

/// Announce the current block as settled in the pool.
virtual void do_block(header_t link) NOEXCEPT;

/// Apply the reorganized block to the pool index and pool its unpooled txs.
virtual void do_reorganized(header_t link) NOEXCEPT;

/// Raise the arrivals floor above the pruned block.
Expand All @@ -95,9 +129,10 @@ class BCN_API chaser_transaction
static size_t to_rate(const system::chain::transaction& tx) NOEXCEPT;
system::pool::algorithm::totals_t block_limit() const NOEXCEPT;

code validate(size_t& index, const system::chain::transaction_cptrs& txs,
const std::vector<bool>& stored) NOEXCEPT;
code check(const system::chain::transaction_cptrs& txs,
const std::vector<bool>& stored, bool announced) NOEXCEPT;
code accept(const system::chain::transaction& tx) NOEXCEPT;
code admit(const system::chain::transaction& tx, uint32_t time) NOEXCEPT;
code validate(const system::chain::transaction& tx,
const system::chain::context& ctx) NOEXCEPT;
database::tx_link to_stored(
Expand All @@ -108,21 +143,39 @@ class BCN_API chaser_transaction
const code& ec) NOEXCEPT;
void broadcast(const system::chain::transaction& tx) const NOEXCEPT;
void start_scan(bool remap) NOEXCEPT;
uint64_t arriving(uint64_t rate, estimate_mode mode) const NOEXCEPT;

/// A validation under the context holds at a later block.
bool reusable(const system::chain::context& ctx) const NOEXCEPT;

/// A validation under the context holds under the pool context.
bool is_sufficient(const system::chain::context& ctx) const NOEXCEPT;

/// Sweep the index by the pool context if due, false on store failure.
bool sweep() NOEXCEPT;
static uint64_t arriving(const query::pool_arrivals& arrivals,
uint64_t rate, estimate_mode mode) NOEXCEPT;

/// Notify pool subscribers of the scan, timed from its start, and fire
/// its event (other than for coverage, which fires only when it clears).
using time_point = std::chrono::steady_clock::time_point;
static time_point now() NOEXCEPT;
void report(pool_scan scan, const time_point& start) NOEXCEPT;

/// Fire the event with the microseconds since the start.
void fire_span(events event, const time_point& start) NOEXCEPT;

// These are thread safe.
network::threadpool scan_threadpool_;
stopper stopping_{};
std::atomic_bool pooling_{};
std::atomic<size_t> writers_{};

// These are protected by strand.
pool_subscriber subscriber_{};
system::chain::context pool_{};
query::pool_projection projection_{};
query::pool_arrivals arrivals_{};
size_t floor_{};
bool pooling_{};
bool due_{ true };
bool scanning_{};
bool projected_{};
bool arrived_{};
};

} // namespace node
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/chasers/chaser_validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <atomic>
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/solo_spans.hpp>

namespace libbitcoin {
namespace node {
Expand Down Expand Up @@ -168,6 +169,7 @@ class BCN_API chaser_validate
// These are thread safe.
network::io::strand validation_strand_;
atomic_counter validate_backlog_{};
solo_spans validating_{};
std::atomic_bool disk_recovering_{};
std::atomic_bool window_archived_{};
std::atomic_bool maximum_posted_{};
Expand Down
36 changes: 36 additions & 0 deletions include/bitcoin/node/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,42 @@ typedef network::desubscriber<object_key, event_value> event_subscriber;
typedef event_subscriber::handler event_notifier;
typedef event_subscriber::completer event_completer;

/// Scans of the pool.
enum class pool_scan : uint8_t
{
/// Coverage of an incoming set.
coverage,

/// Index write of an admitted tx.
admission,

/// Index transition of an organized block.
block_in,

/// Index transition of a reorganized block.
block_out,

/// Index sweep of the pool context.
context,

/// Template.
template_,

/// Fee projection.
projection
};

/// A scan of the pool and what it did.
struct pool_event
{
pool_scan scan{};
system::pool::report_t report{};
};

/// Pool unsubscriber.
typedef network::unsubscriber<pool_event> pool_subscriber;
typedef pool_subscriber::handler pool_notifier;

// Inventory messages.
using type_id = network::messages::peer::inventory_item::type_id;

Expand Down
Loading
Loading