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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# gnu
.deps
.dirstamp
Makefile
Makefile.in
.libs
Expand All @@ -28,7 +29,10 @@ builds/gnu/build-aux
builds/gnu/config.*
builds/gnu/configure
builds/gnu/libtool
builds/gnu/.dirstamp
builds/gnu/console
builds/gnu/test
builds/gnu/*.log
builds/gnu/*.trs

# pkg-config pc file from .pc.in
builds/gnu/*.pc
Expand Down
9 changes: 9 additions & 0 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class BCN_API chaser_transaction
/// archived before latch is organized.
virtual void do_bump() NOEXCEPT;

/// Bump, then reorganize blocks popped since pool top, top that of store.
virtual void do_start() NOEXCEPT;

/// Retain the pool subscription.
virtual void do_subscribe_pool(const pool_notifier& handler) NOEXCEPT;

Expand Down Expand Up @@ -266,6 +269,12 @@ class BCN_API chaser_transaction
/// 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.
bool unvalidate(header_t link) NOEXCEPT;

/// 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.
bool is_sufficient(const system::chain::context& ctx) const NOEXCEPT;

Expand Down
28 changes: 26 additions & 2 deletions include/bitcoin/node/protocols/protocol_transaction_in_106.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class BCN_API protocol_transaction_in_106
: node::protocol_peer(session, channel),
network::tracker<protocol_transaction_in_106>(session->log),
tx_type_(session->node_settings().require_witness ?
type_id::witness_tx : type_id::transaction)
type_id::witness_tx : type_id::transaction),
maximum_requests_(system::possible_wide_cast<size_t>(
session->node_settings().pool.maximum_requests)),
request_timer_(system::emplace_shared<network::deadline>(session->log,
channel->strand(), session->node_settings().pool.request_timeout()))
{
}

Expand Down Expand Up @@ -96,8 +100,17 @@ class BCN_API protocol_transaction_in_106
{
size_t set{};
size_t slot{};
size_t id{};
};

/// Requested tx, in order of request.
struct pending
{
system::hash_digest hash{};
size_t id{};
};

using duration = network::deadline::duration;
using requests = std::unordered_map<system::hash_digest, request>;

network::messages::peer::get_data create_get_data(
Expand All @@ -109,13 +122,24 @@ class BCN_API protocol_transaction_in_106
/// Submit the first set as it stands.
void flush() NOEXCEPT;

// This is thread safe.
/// Drop answered requests from order, timing oldest from when it is so.
void settle() NOEXCEPT;
bool is_answered(const pending& entry) const NOEXCEPT;
void start_request_timer(const duration& span) NOEXCEPT;
void handle_request_timer(const code& ec) NOEXCEPT;

// These are thread safe.
const type_id tx_type_;
const size_t maximum_requests_;

// These are protected by strand.
requests requested_{};
std::deque<announcement> sets_{};
std::deque<pending> order_{};
network::steady_clock::time_point oldest_{};
size_t first_{};
size_t next_{};
network::deadline::ptr request_timer_;
};

} // namespace node
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ class BCN_API settings
uint32_t maximum_chunk_depth;
uint16_t estimate_cache_seconds;
uint32_t estimate_room;
uint32_t maximum_requests;
uint16_t request_timeout_seconds;
bool thread_priority;

/// Helpers.
virtual uint64_t minimum_fee_rate_() const NOEXCEPT;
virtual uint64_t cutoff_rate_() const NOEXCEPT;
virtual network::steady_clock::duration estimate_cache() const NOEXCEPT;
virtual network::steady_clock::duration request_timeout() const NOEXCEPT;
virtual network::processing_priority thread_priority_() const NOEXCEPT;
};

Expand Down
80 changes: 64 additions & 16 deletions src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,45 @@ chaser_transaction::chaser_transaction(full_node& node) NOEXCEPT
code chaser_transaction::start() NOEXCEPT
{
SUBSCRIBE_CHASE(handle_chase, _1, _2);
POST(do_bump);
POST(do_start);
return error::success;
}

// Index is rebuilt at open, so only blocks popped since pool top reorganize.
void chaser_transaction::do_start() NOEXCEPT
{
BC_ASSERT(stranded());
do_bump();
if (closed() || !is_indexing())
return;

auto& query = archive();
auto link = query.get_pool_top();
while (!link.is_terminal() && !query.is_confirmed_block(link))
{
if (!unvalidate(link))
{
fault(error::transaction10);
return;
}

if (pooling_ && !repool(link))
return;

link = query.to_parent(link);
}

const auto top = query.to_top_confirmed();
if (query.get_pool_top() != top && !query.set_pool_top(top))
{
fault(error::transaction10);
return;
}

if (!sweep())
fault(error::transaction11);
}

void chaser_transaction::stopping(const code& ec) NOEXCEPT
{
stopping_.store(true);
Expand Down Expand Up @@ -457,8 +492,6 @@ void chaser_transaction::do_block(header_t link) NOEXCEPT
notify(error::success, chases::block_settled{ link });
}

// Pooled in block order under block context,
// excluding any confirmed (by another block).
void chaser_transaction::do_reorganized(header_t link) NOEXCEPT
{
BC_ASSERT(stranded());
Expand All @@ -468,37 +501,53 @@ void chaser_transaction::do_reorganized(header_t link) NOEXCEPT
auto& query = archive();
if (is_indexing())
{
size_t count{};
const auto start = now();
const auto applied = query.set_pool_block(link, false) &&
query.set_pool_unvalidated(count, link);
unvalidate(link);

report(pool_scan::block_out, start);
if (!applied)
{
fault(error::transaction10);
return;
}

unvalidated_ = unvalidated_ || is_nonzero(count);
due_ = due_ || is_nonzero(count);
}

top_ = query.to_parent(link);
do_bump();
if (!pooling_)
return;
if (pooling_ && repool(link) && !sweep())
fault(error::transaction11);
}

// Block's parent becomes pool top with spenders set.
bool chaser_transaction::unvalidate(header_t link) NOEXCEPT
{
BC_ASSERT(stranded());
size_t count{};
if (!archive().set_pool_unvalidated(count, link))
return false;

unvalidated_ = unvalidated_ || is_nonzero(count);
due_ = due_ || is_nonzero(count);
return true;
}

// Pooled in block order under block context,
// excluding any confirmed (by another block).
bool chaser_transaction::repool(header_t link) NOEXCEPT
{
BC_ASSERT(stranded());
auto& query = archive();
chain::context ctx{};
const auto txs = query.to_transactions(link);
if (txs.empty() || !query.get_context(ctx, link))
{
fault(error::transaction7);
return;
return false;
}

if (!reusable(ctx))
return;
return true;

// The coinbase is never pooled.
for (auto it = std::next(txs.cbegin()); it != txs.cend(); ++it)
Expand All @@ -511,22 +560,21 @@ void chaser_transaction::do_reorganized(header_t link) NOEXCEPT
if (!tx || !query.populate_with_metadata(*tx))
{
fault(error::transaction7);
return;
return false;
}

// Block txs are already silent indexed.
if (!set_pooled(fk, *tx, ctx))
{
fault(error::transaction2);
return;
return false;
}

notify(error::success, chases::transaction{ fk });
broadcast(*tx);
}

if (!sweep())
fault(error::transaction11);
return true;
}

// Rows confirmed by the pruned block are not retained by the prune.
Expand Down
Loading
Loading