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
2 changes: 1 addition & 1 deletion .github/workflows/ci-expanded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ jobs:

warnings:
needs: [ gnu, musl, cmake, presets, msvc ]
if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }}
if: ${{ success() && github.event_name == 'push' }}
continue-on-error: true
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ jobs:

warnings:
needs: [ gnu, cmake, presets, msvc ]
if: ${{ !cancelled() && (github.event_name != 'pull_request' || github.event.action != 'closed') }}
if: ${{ success() && github.event_name == 'push' }}
continue-on-error: true
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ if ( MSVC )
add_compile_options(
/W4
/permissive-
/Zc:inline
/bigobj
/Zc:__cplusplus
/Zc:preprocessor
Expand Down
1 change: 1 addition & 0 deletions builds/gnu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ src_libbitcoin_node_la_SOURCES = \
${srcdir}/../../src/chasers/chaser_template.cpp \
${srcdir}/../../src/chasers/chaser_transaction.cpp \
${srcdir}/../../src/chasers/chaser_transaction_compact.cpp \
${srcdir}/../../src/chasers/chaser_transaction_context.cpp \
${srcdir}/../../src/chasers/chaser_transaction_query.cpp \
${srcdir}/../../src/chasers/chaser_transaction_relay.cpp \
${srcdir}/../../src/chasers/chaser_transaction_submit.cpp \
Expand Down
1 change: 1 addition & 0 deletions builds/msvc/properties/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<WarningLevel>Level4</WarningLevel>
<ExternalWarningLevel>Level4</ExternalWarningLevel>
<ConformanceMode>true</ConformanceMode>
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
<LanguageStandard_C>stdc11</LanguageStandard_C>
<EnforceTypeConversionRules>true</EnforceTypeConversionRules>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
Expand Down
1 change: 1 addition & 0 deletions builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClCompile Include="..\..\..\..\src\chasers\chaser_template.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_compact.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_context.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_query.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_relay.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_submit.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_compact.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_context.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\chasers\chaser_transaction_query.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
Expand Down
138 changes: 96 additions & 42 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ class BCN_API chaser_transaction
protected:
using chaser::broadcast;

/// Post a method in base or derived class in parallel (use PARALLEL).
template <class Derived, typename Method, typename... Args>
inline auto parallel(Method&& method, Args&&... args) NOEXCEPT
{
return network::io::post(validation_threadpool_.service(),
BIND_TO(method, args));
}

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

virtual void do_submit(const system::chain::transactions_cptr& txs,
Expand Down Expand Up @@ -190,14 +198,20 @@ class BCN_API chaser_transaction
bool stranded() const NOEXCEPT override;

private:
/// A set under submission, its running set and outcome.
// A set under submission, its running set and outcome.
struct submission
{
system::chain::transactions_cptr txs;
size_t slot;
uint32_t time;
bool test;
bool announced;
submit_handler handler{};
system::chain::context ctx{};
std::chrono::steady_clock::time_point begin{};
std::vector<size_t> reserved{};
std::vector<code> accepted{};
code checked{};
std::vector<bool> stored{};
std::vector<size_t> sigops_of{};
std::unordered_set<system::hash_digest> held{};
Expand All @@ -211,15 +225,27 @@ class BCN_API chaser_transaction
bool cleared{};
code failure{};
};
using submission_ptr = std::shared_ptr<submission>;
using submission_ptrs = std::vector<submission_ptr>;
using hash_set = std::unordered_set<system::hash_digest>;
using row_marks = std::vector<uint64_t>;
using rate_slots = std::array<uint64_t, relay_slots>;
using key_slots = std::array<object_key, relay_slots>;

static size_t to_rate(const system::chain::transaction& tx) NOEXCEPT;
system::pool::algorithm::totals_t block_limit() const NOEXCEPT;

/// Chain state of top, the held state advanced by top, else from store.
// Chain state of top, the held state advanced by top, else from store.
system::chain::chain_state::cptr top_state(const database::header_link& top,
size_t height) NOEXCEPT;

/// Submission steps.
// Submission steps.
void enter(const submission_ptr& set) NOEXCEPT;
void do_validate(const submission_ptr& set) NOEXCEPT;
void do_validated(const submission_ptr& set) NOEXCEPT;
void complete(const submission_ptr& set, const code& ec,
size_t index) NOEXCEPT;
bool is_dependent(const submission& set) const NOEXCEPT;
void hold(submission& set) NOEXCEPT;
bool spends_held(const submission& set,
const system::chain::transaction& tx) const NOEXCEPT;
Expand All @@ -232,7 +258,8 @@ class BCN_API chaser_transaction
code clear(size_t& at, submission& set, size_t index) NOEXCEPT;

code check(const system::chain::transaction_cptrs& txs,
const std::vector<bool>& stored, bool announced) NOEXCEPT;
const std::vector<bool>& stored, bool announced,
const system::chain::context& ctx) NOEXCEPT;
code accept(const system::chain::transaction& tx,
const system::chain::context& ctx) NOEXCEPT;
code admit(database::tx_link& out, const system::chain::transaction& tx,
Expand All @@ -252,55 +279,99 @@ class BCN_API chaser_transaction
void start_scan(bool remap) NOEXCEPT;
void start_revalidation() NOEXCEPT;

/// Relay txs with their unconfirmed ancestry, marked held by origin, to
/// each slot whose rate the sum of rows it lacks clears.
// Relay txs with their unconfirmed ancestry, marked held by origin, to
// each slot whose rate the sum of rows it lacks clears.
bool relay(const database::tx_links& links, size_t origin,
uint64_t slots, object_key key={}) NOEXCEPT;

/// Relay confirmable txs in row order, each with ancestry slot lacks, where
/// that clears slot's rate.
// Relay confirmable txs in row order, each with ancestry slot lacks, where
// that clears slot's rate.
bool sweep_relay(size_t slot) NOEXCEPT;

/// Owe slot a sweep, made now unless swept since last block.
// Owe slot a sweep, made now unless swept since last block.
void owe_relay(size_t slot) NOEXCEPT;

/// Relaying slots owed a sweep and not swept since last block.
// Relaying slots owed a sweep and not swept since last block.
uint64_t sweepable() const NOEXCEPT;

/// The marks of the pool row, grown with the table.
// The marks of the pool row, grown with the table.
uint64_t& marks(size_t row) NOEXCEPT;

/// The pool index follows blocks (pooling store and relay enabled).
// The pool index follows blocks (pooling store and relay enabled).
bool is_indexing() const NOEXCEPT;

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

/// Set pooled spenders of block's txs not validated, parent pool top.
// Set pooled spenders of block's txs not validated, parent pool top.
bool unvalidate(header_t link) NOEXCEPT;

/// Pool block's unpooled txs under its context, false if faulted.
// Pool block's unpooled txs under its context, false if faulted.
bool repool(header_t link) NOEXCEPT;

/// A validation under the context holds under the pool context.
// 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.
// 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 scan, timed from its start, and fire its
/// event (other than for coverage, which fires only when it clears).
// Notify pool subscribers of 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.
// Fire the event with the microseconds since the start.
void fire_span(events event, const time_point& start) NOEXCEPT;

// This is not thread safe.
// Pool context, its chain position and the sweep that follows it.
struct context_state
{
system::chain::context pool{};
system::chain::chain_state::cptr state{};
system::hash_digest previous{};
database::header_link top{};
size_t floor{};
bool due{ true };
bool revalidating{};
bool unvalidated{};
system::chain::context retried{};
};

// Projection held across estimates and the arrivals it draws on.
struct estimate_state
{
bool estimating{};
bool arrived{};
time_point estimated{};
query::pool_projection projection{};
query::pool_arrivals arrivals{};
};

// Relay slots, their rates and keys, and the marks of the pool rows.
struct relay_state
{
row_marks marks{};
rate_slots rates{};
key_slots keys{};
uint64_t relaying{};
uint64_t owed{};
uint64_t swept{};
bool sweeping{};
};

// Txs under validation, and sets waiting on them.
struct submit_state
{
hash_set validating{};
submission_ptrs waiting{};
};

// These are not thread safe.
network::threadpool transaction_threadpool_;
network::threadpool validation_threadpool_;

// These are thread safe.
network::io::strand transaction_strand_;
Expand All @@ -316,28 +387,11 @@ class BCN_API chaser_transaction

// These are protected by strand.
pool_subscriber subscriber_{};
system::chain::context pool_{};
system::chain::chain_state::cptr state_{};
system::hash_digest previous_{};
database::header_link top_{};
size_t floor_{};
bool due_{ true };
context_state context_{};
estimate_state estimate_{};
relay_state relay_{};
submit_state submit_{};
bool scanning_{};
bool revalidating_{};
bool unvalidated_{};
bool estimating_{};
bool arrived_{};
time_point estimated_{};
query::pool_projection projection_{};
query::pool_arrivals arrivals_{};
system::chain::context retried_{};
std::vector<uint64_t> marks_{};
std::array<uint64_t, relay_slots> rates_{};
std::array<object_key, relay_slots> keys_{};
uint64_t relaying_{};
uint64_t owed_{};
uint64_t swept_{};
bool sweeping_{};
};

} // namespace node
Expand Down
17 changes: 15 additions & 2 deletions include/bitcoin/node/protocols/protocol_transaction_out_70013.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,41 @@ class BCN_API protocol_transaction_out_70013
protocol_transaction_out_70013(const auto& session,
const network::channel::ptr& channel) NOEXCEPT
: protocol_transaction_out_70001(session, channel),
network::tracker<protocol_transaction_out_70013>(session->log)
network::tracker<protocol_transaction_out_70013>(session->log),
fee_timer_(to_bool(session->node_settings().fee_filter_minutes) ?
system::emplace_shared<network::deadline>(session->log,
channel->strand(),
session->node_settings().fee_filter_period()) : nullptr)
{
}

/// Start protocol (strand required).
void start() NOEXCEPT override;

/// The channel is stopping (called on strand by stop subscription).
void stopping(const code& ec) NOEXCEPT override;

protected:
/// Handle chaser events.
bool handle_chase(const code& ec, event_value value) NOEXCEPT override;
void subscribed(const code& ec, object_key key) NOEXCEPT override;

/// Capture the peer's minimum fee rate for announcements.
/// Capture the peer's minimum fee rate for announcements, a peer that
/// lowers it again within the fee filter period is dropped.
virtual bool handle_receive_fee_filter(const code& ec,
const network::messages::peer::fee_filter::cptr& message) NOEXCEPT;

private:
void do_send_fee_filter() NOEXCEPT;
void handle_fee_timer(const code& ec) NOEXCEPT;

// This is thread safe.
const network::deadline::ptr fee_timer_;

// This is protected by strand.
uint64_t sent_fee_{ max_uint64 };
bool requested_{};
bool lowered_{};
};

} // namespace node
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class BCN_API settings
uint16_t compact_timeout_seconds;
uint8_t compact_missing_percent;
uint32_t currency_window_minutes;
uint16_t fee_filter_minutes;
////uint64_t snapshot_bytes;
////uint32_t snapshot_valid;
////uint32_t snapshot_confirm;
Expand All @@ -112,6 +113,7 @@ class BCN_API settings
virtual network::steady_clock::duration sample_period() const NOEXCEPT;
virtual network::steady_clock::duration compact_timeout() const NOEXCEPT;
virtual network::wall_clock::duration currency_window() const NOEXCEPT;
virtual network::steady_clock::duration fee_filter_period() const NOEXCEPT;
virtual network::processing_priority thread_priority_() const NOEXCEPT;
};

Expand Down
Loading
Loading