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: 3 additions & 3 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ class BCN_API chaser
const node::settings& node_settings() const NOEXCEPT;

/// Top candidate|confirmed is within configured span from current time.
bool is_current(bool confirmed) const NOEXCEPT;
bool is_current_chain(bool confirmed) const NOEXCEPT;

/// Header timestamp is within configured span from current time.
bool is_current(uint32_t timestamp) const NOEXCEPT;
bool is_current_time(uint32_t timestamp) const NOEXCEPT;

/// Header's timestamp is within configured span from current time.
bool is_current(const database::header_link& link) const NOEXCEPT;
bool is_current_header(const database::header_link& link) const NOEXCEPT;

/// The confirmed chain is confirmed to maximum height or is current.
bool is_recent() const NOEXCEPT;
Expand Down
12 changes: 4 additions & 8 deletions include/bitcoin/node/chasers/chaser_validate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class BCN_API chaser_validate

/// Batching.
virtual code start_batch() NOEXCEPT;
virtual bool process_valids() NOEXCEPT;
virtual void process_batch(bool residual) NOEXCEPT;
virtual bool process_valids(bool residual) NOEXCEPT;
virtual void push_batch(const header_link& link, size_t height) NOEXCEPT;
virtual bool process_invalids(const header_links& invalids) NOEXCEPT;
virtual signatures get_capture(const header_link& link) NOEXCEPT;
Expand All @@ -101,8 +101,7 @@ class BCN_API chaser_validate

// Capture handlers.
void do_log(const system::chain::script& missed) NOEXCEPT;
void do_fire(missed miss, size_t count,
const shared_lock_cptr& lock) NOEXCEPT;
void do_fire(missed miss, size_t count) NOEXCEPT;
bool do_ecdsa(const system::hash_digest& digest,
const system::ec_compressed& point, const system::ec_signature& sign,
const header_link& link) NOEXCEPT;
Expand All @@ -128,21 +127,18 @@ class BCN_API chaser_validate
network::threadpool validation_threadpool_;

// These are thread safe.

// This prevents table updates during batch verify.
stopper stopping_{};
std::shared_mutex mutex_{};

std::atomic<size_t> ecdsa_{};
std::atomic<size_t> schnorr_{};
std::atomic<size_t> multisig_{};
std::atomic<size_t> threshold_{};

std::atomic<size_t> missed_ecdsa_{};
std::atomic<size_t> missed_schnorr_{};
std::atomic<size_t> missed_multisig_{};
std::atomic<size_t> missed_threshold_{};

std::atomic<size_t> backlog_{};

network::asio::strand validation_strand_;
const uint32_t subsidy_interval_;
const uint64_t initial_subsidy_;
Expand Down
4 changes: 1 addition & 3 deletions include/bitcoin/node/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ enum error_t : uint8_t
batch5,
batch6,
batch7,
batch8,
batch9,
batch10
batch8
};

// No current need for error_code equivalence mapping.
Expand Down
8 changes: 6 additions & 2 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,14 @@ class BCN_API full_node
virtual const node::settings& node_settings() const NOEXCEPT;

/// The candidate|confirmed chain is current.
virtual bool is_current(bool confirmed) const NOEXCEPT;
virtual bool is_current_chain(bool confirmed) const NOEXCEPT;

/// The specified timestamp is current.
virtual bool is_current(uint32_t timestamp) const NOEXCEPT;
virtual bool is_current_time(uint32_t timestamp) const NOEXCEPT;

/// Header's timestamp is within configured span from current time.
virtual bool is_current_header(
const database::header_link& link) const NOEXCEPT;

/// The confirmed chain is confirmed to maximum height or is current.
virtual bool is_recent() const NOEXCEPT;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void CLASS::do_organize(typename Block::cptr block,

// Delay so headers can get current before block download starts.
// Checking currency before notify also avoids excessive work backlog.
if (is_block() || is_current(header.timestamp()))
if (is_block() || is_current_time(header.timestamp()))
{
if (!bumped_)
{
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/impl/sessions/session_peer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ inline void CLASS::attach_protocols(const channel_ptr& channel) NOEXCEPT

// Ready to relay transactions.
const auto txs_in_out = relay && peer->is_negotiated(level::bip37) &&
(!delay || is_current(true));
(!delay || is_current_chain(true));

// Peer advertises chain (blocks in).
if (peer->is_peer_service(service::node_network))
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BCN_API protocol
virtual const node::settings& node_settings() const NOEXCEPT;

/// The candidate|confirmed chain is current.
virtual bool is_current(bool confirmed) const NOEXCEPT;
virtual bool is_current_chain(bool confirmed) const NOEXCEPT;

/// Methods.
/// -----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BCN_API session
virtual const node::settings& node_settings() const NOEXCEPT;

/// The candidate|confirmed chain is current.
virtual bool is_current(bool confirmed) const NOEXCEPT;
virtual bool is_current_chain(bool confirmed) const NOEXCEPT;

/// The confirmed chain is confirmed to maximum height or is current.
virtual bool is_recent() const NOEXCEPT;
Expand Down
13 changes: 6 additions & 7 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
#include <bitcoin/node/chasers/chaser.hpp>

#include <mutex>
#include <bitcoin/node/configuration.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/full_node.hpp>
Expand Down Expand Up @@ -152,20 +151,20 @@ const node::settings& chaser::node_settings() const NOEXCEPT
return node_.node_settings();
}

bool chaser::is_current(bool confirmed) const NOEXCEPT
bool chaser::is_current_chain(bool confirmed) const NOEXCEPT
{
return node_.is_current(confirmed);
return node_.is_current_chain(confirmed);
}

bool chaser::is_current(uint32_t timestamp) const NOEXCEPT
bool chaser::is_current_time(uint32_t timestamp) const NOEXCEPT
{
return node_.is_current(timestamp);
return node_.is_current_time(timestamp);
}

// get_timestamp error results in false (ok).
bool chaser::is_current(const database::header_link& link) const NOEXCEPT
bool chaser::is_current_header(const database::header_link& link) const NOEXCEPT
{
return node_.is_current(link);
return node_.is_current_header(link);
}

bool chaser::is_recent() const NOEXCEPT
Expand Down
2 changes: 1 addition & 1 deletion src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ size_t chaser_check::set_unassociated() NOEXCEPT

size_t chaser_check::get_inventory_size() const NOEXCEPT
{
if (is_zero(connections_) || !is_current(false))
if (is_zero(connections_) || !is_current_chain(false))
return zero;

const auto& query = archive();
Expand Down
4 changes: 2 additions & 2 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ code chaser_confirm::start() NOEXCEPT
const auto& query = archive();
set_position(query.get_fork());

if (is_current(true))
if (is_current_chain(true))
{
LOGN("Node is current at startup block [" << position() << "].");
}
Expand Down Expand Up @@ -423,7 +423,7 @@ void chaser_confirm::announce(const header_link& link, height_t) NOEXCEPT
BC_ASSERT(stranded());

// Announce newly-organized blocks when confirmed chain is current.
if (is_current(true))
if (is_current_chain(true))
notify(error::success, chase::block, link);
}

Expand Down
2 changes: 1 addition & 1 deletion src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool chaser_header::is_milestone(const chain_state& state) const NOEXCEPT

bool chaser_header::is_current(const chain_state& state) const NOEXCEPT
{
return chaser::is_current(state.timestamp());
return chaser::is_current_time(state.timestamp());
}

bool chaser_header::is_hard(const chain_state& state) const NOEXCEPT
Expand Down
42 changes: 26 additions & 16 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
#include <bitcoin/node/chasers/chaser_validate.hpp>

#include <shared_mutex>
#include <bitcoin/node/chasers/chaser.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/full_node.hpp>
Expand Down Expand Up @@ -293,22 +294,28 @@ code chaser_validate::validate(bool& batched, bool& faulted, bool bypass,
if ((ec = block.accept(ctx, subsidy_interval_, initial_subsidy_)))
return ec;

// Initialize block capture.
// This call is blocked during signature batch evaluation.
const auto capture = get_capture(link);
// This critical section is mutually-exclusive with batch verification.
// ====================================================================
{
const std::shared_lock lock{ mutex_ };

// Sequentially connect block with signature capture (if enabled).
// There is not stop during connect, so a shutdown will wait on the
// completion (block consistency) of all signature captures. However
// the faulted state of a batch is not persisted (because disk full).
if ((ec = block.connect(ctx, capture)))
return ec;
// Initialize block capture.
const auto capture = get_capture(link);

// At least one signature batch was attempted (defer completion).
batched = capture.batched;
// Sequentially connect block with signature capture (if enabled).
// There is not stop during connect, so shutdown will wait on the
// completion (block consistency) of all signature captures. But
// the faulted state of batch is not persisted (because disk full).
if ((ec = block.connect(ctx, capture)))
return ec;

// Threshold batch commit failed, block otherwise passed (retry block).
faulted = capture.faulted;
// At least one signature batch was attempted (defer completion).
batched = capture.batched;

// Threshold batch commit failed, block otherwise passed (retry).
faulted = capture.faulted;
// ================================================================
}

// Prevouts optimize confirmation.
// Block will be retried if batch is faulted.
Expand Down Expand Up @@ -372,9 +379,9 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
// Not failed/invalid/batched/faulted, so block is complete (maybe valid).
notify_block({}, height, link, bypass);

// Arriving here with batch enabled implies that the block is current and
// was not batched. Each such block triggers residual batch processing.
if (batch_enabled_)
// Batch enabled not bypassed implies that the block is current and was
// not batched. Each such block triggers residual batch processing.
if (!bypass && batch_enabled_)
{
POST(process_batch, true);
}
Expand Down Expand Up @@ -403,6 +410,9 @@ void chaser_validate::notify_block(const code& ec, size_t height,

void chaser_validate::stopping(const code& ec) NOEXCEPT
{
// Stop long-running batch validations.
stopping_.store(true);

// Stop threadpool keep-alive, all work must self-terminate to affect join.
validation_threadpool_.stop();
chaser::stopping(ec);
Expand Down
Loading
Loading