diff --git a/include/bitcoin/node/channels/channel_peer.hpp b/include/bitcoin/node/channels/channel_peer.hpp index 410e8735..5e336b29 100644 --- a/include/bitcoin/node/channels/channel_peer.hpp +++ b/include/bitcoin/node/channels/channel_peer.hpp @@ -53,6 +53,10 @@ class BCN_API channel_peer /// The hash is (probably) known to the peer. bool was_announced(const system::hash_digest& hash) const NOEXCEPT; + /// Peer told not to announce txs (requires strand). + void set_silenced(bool value) NOEXCEPT; + bool silenced() const NOEXCEPT; + /// Set the handler of work offered by the channel's own protocols. void set_downloader(downloader&& handler) NOEXCEPT; @@ -80,6 +84,7 @@ class BCN_API channel_peer // These are protected by strand. rolling_bloom_filter announced_{}; + bool silenced_{}; downloader downloader_{}; }; diff --git a/include/bitcoin/node/chase.hpp b/include/bitcoin/node/chase.hpp index 733f4d13..f612785c 100644 --- a/include/bitcoin/node/chase.hpp +++ b/include/bitcoin/node/chase.hpp @@ -53,11 +53,11 @@ enum class chase /// Issued by 'confirm' and handled by 'snapshot'. snap, - /// Chaser directed to attempt start from its current position. + /// Chaser directed to attempt start from current position. /// Issued by 'organize' and handled by 'download', 'validate', 'confirm'. bump, - /// Channels (all) directed to stop with the given code. + /// Channels (all) directed to stop with given code. /// Issued by 'full_node' and handled by 'observer'. suspend, @@ -85,14 +85,14 @@ enum class chase /// Issued by 'download' and handled by 'block_in_31800'. purge, - /// Channels (all) directed to write work count to the log. + /// Channels (all) directed to write work count to log. /// Issued by 'executor' and handled by 'block_in_31800'. report, /// Candidate Chain. /// ----------------------------------------------------------------------- - /// A new candidate branch exists from given branch point. + /// New candidate branch exists from given branch point. /// Issued by 'header' and handled by 'download'. headers, @@ -100,7 +100,7 @@ enum class chase /// Issued by 'download' and handled by 'block_in_31800'. download, - /// The candidate chain has been reorganized (branched below its top). + /// Candidate chain has been reorganized (branched below its top). /// Issued by 'organize' and handled by 'download', 'validate', 'confirm'. regressed, @@ -111,81 +111,81 @@ enum class chase /// Check/Identify. /// ----------------------------------------------------------------------- - /// A block has been downloaded, checked and stored. + /// Block has been downloaded, checked and stored. /// Issued by 'block_in_31800', handled by 'download', 'validate'. /// Populate is bypassed for checkpoint/milestone blocks. checked, - /// A downloaded block has failed check. + /// Downloaded block has failed check. /// Issued by 'block_in_31800', 'transaction' and handled by 'organize'. unchecked, - /// A downloaded window is completed by check. + /// Downloaded window is completed by check. /// Issued by 'download' and handled by 'validate'. windowed, /// Accept/Connect. /// ----------------------------------------------------------------------- - /// A branch has become valid. + /// Branch has become valid. /// Issued by 'validate' and handled by 'download', 'confirm'. valid, - /// A checked block has failed validation. + /// Checked block has failed validation. /// Issued by 'validate' and handled by 'organize'. unvalid, /// Confirm (block). /// ----------------------------------------------------------------------- - /// A connected block has become confirmable. + /// Connected block has become confirmable. /// Issued by 'confirm' and handled by none. confirmable, - /// A connected block has failed confirmability. + /// Connected block has failed confirmability. /// Issued by 'confirm' and handled by 'organize'. unconfirmable, /// Confirm (chain). /// ----------------------------------------------------------------------- - /// A current block has been organized. + /// Current block has been organized. /// Issued by 'confirm' and handled by 'transaction', /// 'protocol_header/block_out'. block, - /// A current block has been settled in the pool. + /// Current block has been settled in pool. /// Issued by 'transaction' and handled by 'snapshot'. block_settled, - /// The store has been pruned (once, following the first settled block). + /// Store has been pruned (once, following first settled block). /// Issued by 'snapshot' and handled by 'transaction'. pruned, - /// The confirmed chain is no longer current. + /// Confirmed chain is no longer current. /// Issued by 'confirm' and handled by 'protocol_transaction_out'. stale, - /// A confirmable block has been confirmed. + /// Confirmable block has been confirmed. /// Issued by 'confirm' and handled by 'transaction'. organized, - /// A previously confirmed block has been unconfirmed. + /// Previously confirmed block has been unconfirmed. /// Issued by 'confirm' and handled by 'transaction'. reorganized, /// Mining. /// ----------------------------------------------------------------------- - /// A transaction has been added to the pool. + /// Transaction has been added to pool. /// Issued by 'transaction' and handled by [clients]. transaction, - /// A pooled transaction has been relayed to a word of slots, in order. + /// Pooled transaction has been relayed to word of slots, in order. /// Issued by 'transaction' and handled by 'protocol_transaction_out'. relay, - /// A candidate block (template) has been created, upon request. + /// Candidate block (template) has been created, upon request. /// Issued by 'template' and handled by [miners]. template_, diff --git a/include/bitcoin/node/chasers/chaser.hpp b/include/bitcoin/node/chasers/chaser.hpp index ef3efeb0..fad6bee4 100644 --- a/include/bitcoin/node/chasers/chaser.hpp +++ b/include/bitcoin/node/chasers/chaser.hpp @@ -29,10 +29,10 @@ class full_node; /// Abstract base chaser for thread safe chain state management classes. /// Chasers impose order on blockchain/pool construction as necessary. -/// Each chaser operates on its own strand, implemented here, allowing -/// concurrent chaser operations to the extent that threads are available. -/// Events are passed between chasers using the full_node shared notifier. -/// Unlike protocols chasers can stop the node. +/// Each chaser operates on own strand, implemented here, allowing concurrent +/// chaser operations to extent threads are available. +/// Events are passed between chasers using full_node shared notifier. +/// Unlike protocols, chasers can stop node. class BCN_API chaser : public network::reporter { @@ -79,7 +79,7 @@ class BCN_API chaser virtual bool suspended() const NOEXCEPT; /// Suspend all existing and future network connections. - /// A race condition could result in an unsuspended connection. + /// Race condition could result in unsuspended connection. virtual code fault(const code& ec) NOEXCEPT; /// Resume all network connections. diff --git a/include/bitcoin/node/chasers/chaser_download.hpp b/include/bitcoin/node/chasers/chaser_download.hpp index 91f3d579..a098af8a 100644 --- a/include/bitcoin/node/chasers/chaser_download.hpp +++ b/include/bitcoin/node/chasers/chaser_download.hpp @@ -58,8 +58,8 @@ class BCN_API chaser_download virtual void put_hashes(const map_ptr& map, network::result_handler&& handler) NOEXCEPT; - /// Interface for a protocol to obtain the block of a compact block that - /// it did not fill, as work for its own channel (empty if issued before). + /// Interface for protocol to obtain block of compact block it did not fill, + /// as work for its own channel (empty if issued before). virtual void get_unfilled(header_t link, map_handler&& handler) NOEXCEPT; protected: diff --git a/include/bitcoin/node/chasers/chaser_header.hpp b/include/bitcoin/node/chasers/chaser_header.hpp index 832770b3..0a5d3638 100644 --- a/include/bitcoin/node/chasers/chaser_header.hpp +++ b/include/bitcoin/node/chasers/chaser_header.hpp @@ -28,10 +28,10 @@ namespace node { class full_node; -/// Chase down stronger header branches for the candidate chain. -/// Weak branches are retained in a hash table if not store populated. -/// Strong branches reorganize the candidate chain and fire the 'header' event. -/// Headers are validated and proven by the protocol, so all are storable. +/// Chase down stronger header branches for candidate chain. +/// Weak branches are retained in hash table if not store populated. +/// Strong branches reorganize candidate chain and fire 'header' event. +/// Headers are validated and proven by protocol, so all are storable. class BCN_API chaser_header : public chaser { diff --git a/include/bitcoin/node/chasers/chaser_storage.hpp b/include/bitcoin/node/chasers/chaser_storage.hpp index 5b3fd42e..bee78798 100644 --- a/include/bitcoin/node/chasers/chaser_storage.hpp +++ b/include/bitcoin/node/chasers/chaser_storage.hpp @@ -27,7 +27,7 @@ namespace node { class full_node; -/// Monitor storage capacity following a disk full condition. +/// Monitor storage capacity following disk full condition. /// Clear disk full condition and restart network given increased capacity. class BCN_API chaser_storage : public chaser diff --git a/include/bitcoin/node/chasers/chaser_template.hpp b/include/bitcoin/node/chasers/chaser_template.hpp index 7cd5ced5..d85d8521 100644 --- a/include/bitcoin/node/chasers/chaser_template.hpp +++ b/include/bitcoin/node/chasers/chaser_template.hpp @@ -38,8 +38,7 @@ class BCN_API chaser_template code start() NOEXCEPT override; - /// A template of pooled txs built upon the request, parents first, and - /// its height. + /// Template of pooled txs built on request, parents first, and its height. virtual void get_template(template_handler&& handler) NOEXCEPT; protected: diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index 49995b40..a5918cd0 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -44,27 +44,26 @@ class BCN_API chaser_transaction void stopping(const code& ec) NOEXCEPT override; void stop() NOEXCEPT override; - /// Validate and archive a submitted set, admitted prefix by prefix until - /// one tx fails. The set is only validated when test, nothing archived. + /// Validate and archive submitted set, admitted prefix by prefix until one + /// tx fails. 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). + /// Validate and archive announced set, admitted prefix by prefix, tx not + /// accepted passed over (first such failure reported). virtual void submit_announced( const system::chain::transactions_cptr& txs, size_t slot, submit_handler&& handler) NOEXCEPT; - /// Validate, archive and associate the txs of an identified compact block, - /// in block order, the txs filling the terminal links. + /// Validate, archive and associate txs of identified compact block, in + /// block order, txs filling 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). + /// Archive and associate txs of identified block. Not pooling, on calling + /// thread, returning true with code. Pooling, on strand with compact + /// blocks, returning false and handling 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, @@ -91,8 +90,8 @@ class BCN_API chaser_transaction /// Reserve a free slot of the tier, relay_slots if none (thread safe). virtual size_t reserve_relay(relay_tier tier) NOEXCEPT; - /// Start relay to the slot, once its channel is notified of relay. - virtual void activate_relay(size_t slot) NOEXCEPT; + /// Start relay to slot, its channel notified by events key. + virtual void activate_relay(size_t slot, object_key key) NOEXCEPT; /// Release the relay slot, free once cleared from the marks. virtual void release_relay(size_t slot) NOEXCEPT; @@ -132,24 +131,24 @@ class BCN_API chaser_transaction virtual void do_get_confirmable_fees( const confirmable_fees_handler& handler) NOEXCEPT; - /// 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. + /// Recompute pool context and sweep index by it if due, closing pool if not + /// current or context not reusable, and map scan starts: built once + /// current, extended by block until pooling, and remapped when block + /// archived before latch is organized. virtual void do_bump() NOEXCEPT; /// Retain the pool subscription. virtual void do_subscribe_pool(const pool_notifier& handler) NOEXCEPT; /// Relay slot management. - virtual void do_activate_relay(size_t slot) NOEXCEPT; + virtual void do_activate_relay(size_t slot, object_key key) NOEXCEPT; virtual void do_release_relay(size_t slot) NOEXCEPT; virtual void do_set_relay_rate(size_t slot, uint64_t rate) NOEXCEPT; virtual void do_set_relayed(size_t slot, const database::tx_links& links) NOEXCEPT; virtual void do_relay_pool(size_t slot) NOEXCEPT; - /// Sweep the pool to one slot owed a sweep, then post for the next. + /// Sweep pool to one slot owed a sweep, then post for next. virtual void do_sweep_relay() NOEXCEPT; /// Apply the organized block to the pool index, then bump. @@ -243,20 +242,19 @@ class BCN_API chaser_transaction void start_scan(bool remap) NOEXCEPT; void start_revalidation() NOEXCEPT; - /// Relay the txs with their unconfirmed ancestry, marked held by origin, - /// to each of the slots whose rate the sum of the 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) NOEXCEPT; + uint64_t slots, object_key key={}) NOEXCEPT; - /// Relay the confirmable txs in row order, each with the ancestry the - /// slot lacks, where that clears the 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 the slot a sweep, made at once unless it was swept since the last - /// block, and otherwise after the next. + /// Owe slot a sweep, made now unless swept since last block. void owe_relay(size_t slot) NOEXCEPT; - /// The relaying slots owed a sweep and not swept since the 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. @@ -276,8 +274,8 @@ class BCN_API chaser_transaction 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). + /// 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; @@ -316,6 +314,7 @@ class BCN_API chaser_transaction system::chain::context retried_{}; std::vector marks_{}; std::array rates_{}; + std::array keys_{}; uint64_t relaying_{}; uint64_t owed_{}; uint64_t swept_{}; diff --git a/include/bitcoin/node/chasers/chaser_validate.hpp b/include/bitcoin/node/chasers/chaser_validate.hpp index c5a806a3..115e6ab4 100644 --- a/include/bitcoin/node/chasers/chaser_validate.hpp +++ b/include/bitcoin/node/chasers/chaser_validate.hpp @@ -90,9 +90,9 @@ class BCN_API chaser_validate const header_link& link, bool bypass, bool startup=false) NOEXCEPT; /// Batching (lock-free, self-serviced by completing pool threads). - /// Batch state is the store: sig tables carry rows, prevalid table - /// carries the per-block link set (write-through, crash-durable). - /// Tables are banked, commits fill one bank while the other drains. + /// Batch state is store: sig tables carry rows, prevalid table carries + /// per-block link set (write-through, crash-durable). + /// Tables are banked, commits fill one bank while other drains. virtual code start_batch() NOEXCEPT; virtual void process_batch(bool residual) NOEXCEPT; virtual code do_process_batch(bool bank, bool startup) NOEXCEPT; @@ -106,8 +106,8 @@ class BCN_API chaser_validate virtual void exit_capture(bool bank) NOEXCEPT; /// Silent payment batch. - /// Banked and drained independently of signatures, and computed in the - /// drain, after which their blocks can be confirmed if also valid. + /// Banked and drained independently of signatures, computed in drain, after + /// which their blocks can be confirmed if also valid. virtual code start_silent_batch() NOEXCEPT; virtual void process_silent_batch(bool residual) NOEXCEPT; virtual code do_process_silent_batch(bool bank) NOEXCEPT; diff --git a/include/bitcoin/node/error.hpp b/include/bitcoin/node/error.hpp index 173e7a75..9d942aa2 100644 --- a/include/bitcoin/node/error.hpp +++ b/include/bitcoin/node/error.hpp @@ -31,9 +31,9 @@ typedef std::error_code code; namespace error { -/// Asio failures are normalized to the error codes below. -/// Stop by explicit call is mapped to channel_stopped or service_stopped -/// depending on the context. Asio errors returned on cancel calls are ignored. +/// Asio failures are normalized to error codes below. +/// Stop by explicit call mapped to channel_stopped or service_stopped depending +/// on context. Asio errors returned on cancel calls are ignored. enum error_t : uint8_t { /// general diff --git a/include/bitcoin/node/full_node.hpp b/include/bitcoin/node/full_node.hpp index da9b28d4..f5f8a0f6 100644 --- a/include/bitcoin/node/full_node.hpp +++ b/include/bitcoin/node/full_node.hpp @@ -82,25 +82,25 @@ class BCN_API full_node /// Work a proven header branch must reach (candidate or configured). virtual void get_minimum_work(work_handler&& handler) NOEXCEPT; - /// Validate and archive a submitted set, admitted prefix by prefix until - /// one tx fails. The set is only validated when test, nothing archived. + /// Validate and archive submitted set, admitted prefix by prefix until one + /// tx fails. 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). + /// Validate and archive announced set, admitted prefix by prefix, tx not + /// accepted passed over (first such failure reported). virtual void submit_announced( const system::chain::transactions_cptr& txs, size_t slot, submit_handler&& handler) NOEXCEPT; - /// Validate, archive and associate the txs of an identified compact block, - /// in block order, the txs filling the terminal links. + /// Validate, archive and associate txs of identified compact block, in + /// block order, txs filling 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, on the calling - /// thread (true) unless pooling, then on the strand of compact blocks. + /// Archive and associate txs of identified block, on calling thread (true) + /// unless pooling, then on strand of compact blocks. virtual bool archive_block(code& ec, const system::chain::view::block::cptr& block, const database::header_link& link, bool strong, bool bypass, @@ -112,8 +112,7 @@ class BCN_API full_node /// Subscribe to pool scans (notified on the transaction strand). virtual void subscribe_pool(pool_notifier&& handler) NOEXCEPT; - /// A template of pooled txs built upon the request, parents first, and - /// its height. + /// Template of pooled txs built on request, parents first, and its height. virtual void get_template(template_handler&& handler) NOEXCEPT; /// Manage download queue. @@ -128,7 +127,7 @@ class BCN_API full_node /// Reserve (relay_slots if none), activate or release a relay slot. virtual size_t reserve_relay(relay_tier tier) NOEXCEPT; - virtual void activate_relay(size_t slot) NOEXCEPT; + virtual void activate_relay(size_t slot, object_key key) NOEXCEPT; virtual void release_relay(size_t slot) NOEXCEPT; /// Set the fee rate of the relay slot's peer. @@ -168,7 +167,7 @@ class BCN_API full_node bool resume() NOEXCEPT override; /// Suspend all existing and future network connections. - /// A race condition can result in an unsuspended connection. + /// Race condition can result in unsuspended connection. void suspend(const code& ec) NOEXCEPT override; /// Handle a fault that has occurred. diff --git a/include/bitcoin/node/preprocessor.hpp b/include/bitcoin/node/preprocessor.hpp index 4ef49cd8..7fd7d4e4 100644 --- a/include/bitcoin/node/preprocessor.hpp +++ b/include/bitcoin/node/preprocessor.hpp @@ -21,10 +21,9 @@ #include -/// Now we use the generic helper definitions above to define BCN_API -/// and BCN_INTERNAL. BCN_API is used for the public API symbols. It either DLL -/// imports or DLL exports (or does nothing for static build) BCN_INTERNAL is -/// used for non-api symbols. +/// Generic helper definitions above define BCN_API and BCN_INTERNAL. +/// BCN_API for public API symbols, DLL import/export (nothing if static). +/// BCN_INTERNAL for non-api symbols. #if defined BCN_STATIC #define BCN_API #define BCN_INTERNAL diff --git a/include/bitcoin/node/protocols/protocol.hpp b/include/bitcoin/node/protocols/protocol.hpp index b23fe981..da5f10c9 100644 --- a/include/bitcoin/node/protocols/protocol.hpp +++ b/include/bitcoin/node/protocols/protocol.hpp @@ -30,11 +30,11 @@ namespace libbitcoin { namespace node { /// Abstract base for node protocols, thread safe. -/// This node::protocol is not derived from network::protocol, but given the -/// channel constructor parameter is derived from network::channel, the strand -/// is accessible despite lack of bind/post/parallel templates access. This -/// allows event subscription by derived protocols without the need to derive -/// from protocol_peer (which would prevent derivation from service protocols). +/// node::protocol not derived from network::protocol, but given channel +/// constructor parameter derived from network::channel, strand is accessible +/// despite lack of bind/post/parallel templates access. Allows event +/// subscription by derived protocols without deriving from protocol_peer +/// (which would prevent derivation from service protocols). class BCN_API protocol { protected: @@ -94,8 +94,7 @@ class BCN_API protocol virtual void connect(const network::config::endpoint& endpoint, network::net::channel_notifier&& handler) NOEXCEPT; - /// A template of pooled txs built upon the request, parents first, and - /// its height. + /// Template of pooled txs built on request, parents first, and its height. virtual void get_template(template_handler&& handler) NOEXCEPT; /// Lowest rate (per virtual kilobyte) confirmed by the target block. @@ -141,25 +140,25 @@ class BCN_API protocol /// Work a proven header branch must reach (candidate or configured). virtual void get_minimum_work(work_handler&& handler) NOEXCEPT; - /// Validate and archive a submitted set, admitted prefix by prefix until - /// one tx fails. The set is only validated when test, nothing archived. + /// Validate and archive submitted set, admitted prefix by prefix until one + /// tx fails. 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). + /// Validate and archive announced set, admitted prefix by prefix, tx not + /// accepted passed over (first such failure reported). virtual void submit_announced( const system::chain::transactions_cptr& txs, size_t slot, submit_handler&& handler) NOEXCEPT; - /// Validate, archive and associate the txs of an identified compact block, - /// in block order, the txs filling the terminal links. + /// Validate, archive and associate txs of identified compact block, in + /// block order, txs filling 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, on the calling - /// thread (true) unless pooling, then on the strand of compact blocks. + /// Archive and associate txs of identified block, on calling thread (true) + /// unless pooling, then on strand of compact blocks. virtual bool archive_block(code& ec, const system::chain::view::block::cptr& block, const database::header_link& link, bool strong, bool bypass, diff --git a/include/bitcoin/node/protocols/protocol_block_out_106.hpp b/include/bitcoin/node/protocols/protocol_block_out_106.hpp index 42186aaa..b3f21f14 100644 --- a/include/bitcoin/node/protocols/protocol_block_out_106.hpp +++ b/include/bitcoin/node/protocols/protocol_block_out_106.hpp @@ -75,7 +75,7 @@ class BCN_API protocol_block_out_106 virtual bool report_unservable(size_t index, const get_data::cptr& message, const gate_t::ptr& gate) NOEXCEPT; - /// The block is associated, and not pruned by a limited node. + /// The block is associated. bool is_servable(const system::hash_digest& hash, const database::header_link& link) NOEXCEPT; diff --git a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp index b91eb3ba..d07c86e3 100644 --- a/include/bitcoin/node/protocols/protocol_header_in_31800.hpp +++ b/include/bitcoin/node/protocols/protocol_header_in_31800.hpp @@ -25,9 +25,9 @@ namespace libbitcoin { namespace node { -/// Synchronize the peer's header branch, validating and discarding headers -/// until proven (a checkpoint, or exhausted, current and at minimum work). -/// Then get it again and archive as verified against sampled hashes. +/// Synchronize peer's header branch, validating and discarding headers until +/// proven (checkpoint, or exhausted, current and at minimum work). Then get it +/// again and archive as verified against sampled hashes. class BCN_API protocol_header_in_31800 : public node::protocol_peer, protected network::tracker diff --git a/include/bitcoin/node/protocols/protocol_peer.hpp b/include/bitcoin/node/protocols/protocol_peer.hpp index 92890999..9e201abb 100644 --- a/include/bitcoin/node/protocols/protocol_peer.hpp +++ b/include/bitcoin/node/protocols/protocol_peer.hpp @@ -79,10 +79,9 @@ class BCN_API protocol_peer /// The memory pool of the peer is requested once relaying. virtual bool request_mempool() const NOEXCEPT; - /// Reserve, activate or release the channel's relay slot, reserve false - /// if none is free. + /// Reserve (false if none free), activate or release channel relay slot. virtual bool reserve_relay() NOEXCEPT; - virtual void activate_relay() NOEXCEPT; + virtual void activate_relay(object_key key) NOEXCEPT; virtual void release_relay() NOEXCEPT; /// The channel's relay slot, relay_slots if none. @@ -105,7 +104,7 @@ class BCN_API protocol_peer network::result_handler&& handler) const NOEXCEPT; /// Suspend all existing and future network connections. - /// A race condition could result in an unsuspended connection. + /// Race condition could result in unsuspended connection. virtual code fault(const code& ec) NOEXCEPT; /// Announcements. @@ -117,6 +116,10 @@ class BCN_API protocol_peer /// Determine if outgoing block or tx was previously announced by peer. virtual bool was_announced(const system::hash_digest&) const NOEXCEPT; + /// Peer told not to announce txs. + virtual void set_silenced(bool value) NOEXCEPT; + virtual bool silenced() const NOEXCEPT; + /// Currency. /// ----------------------------------------------------------------------- diff --git a/include/bitcoin/node/sessions/session.hpp b/include/bitcoin/node/sessions/session.hpp index 34362ae0..f73dea30 100644 --- a/include/bitcoin/node/sessions/session.hpp +++ b/include/bitcoin/node/sessions/session.hpp @@ -57,25 +57,25 @@ class BCN_API session virtual void prioritize(const system::hash_digest& hash, organize_handler&& handler) NOEXCEPT; - /// Validate and archive a submitted set, admitted prefix by prefix until - /// one tx fails. The set is only validated when test, nothing archived. + /// Validate and archive submitted set, admitted prefix by prefix until one + /// tx fails. 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). + /// Validate and archive announced set, admitted prefix by prefix, tx not + /// accepted passed over (first such failure reported). virtual void submit_announced( const system::chain::transactions_cptr& txs, size_t slot, submit_handler&& handler) NOEXCEPT; - /// Validate, archive and associate the txs of an identified compact block, - /// in block order, the txs filling the terminal links. + /// Validate, archive and associate txs of identified compact block, in + /// block order, txs filling 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, on the calling - /// thread (true) unless pooling, then on the strand of compact blocks. + /// Archive and associate txs of identified block, on calling thread (true) + /// unless pooling, then on strand of compact blocks. virtual bool archive_block(code& ec, const system::chain::view::block::cptr& block, const database::header_link& link, bool strong, bool bypass, @@ -102,7 +102,7 @@ class BCN_API session /// Reserve (relay_slots if none), activate or release a relay slot. virtual size_t reserve_relay() NOEXCEPT; - virtual void activate_relay(size_t slot) NOEXCEPT; + virtual void activate_relay(size_t slot, object_key key) NOEXCEPT; virtual void release_relay(size_t slot) NOEXCEPT; /// Set the fee rate of the relay slot's peer. @@ -145,8 +145,7 @@ class BCN_API session virtual void connect(const network::config::endpoint& endpoint, network::net::channel_notifier&& handler) NOEXCEPT; - /// A template of pooled txs built upon the request, parents first, and - /// its height. + /// Template of pooled txs built on request, parents first, and its height. virtual void get_template(template_handler&& handler) NOEXCEPT; /// Lowest rate (per virtual kilobyte) confirmed by the target block. diff --git a/include/bitcoin/node/sessions/session_peer.hpp b/include/bitcoin/node/sessions/session_peer.hpp index db718334..31d632e1 100644 --- a/include/bitcoin/node/sessions/session_peer.hpp +++ b/include/bitcoin/node/sessions/session_peer.hpp @@ -29,7 +29,7 @@ namespace node { /// Template for network::session derivation with node::session. /// node::session does not derive from network::session (siblings). -/// This avoids the diamond inheritance problem between network/node. +/// Avoids diamond inheritance problem between network/node. template class session_peer : public node::session, diff --git a/include/bitcoin/node/settings.hpp b/include/bitcoin/node/settings.hpp index bb6cac60..3561a1a9 100644 --- a/include/bitcoin/node/settings.hpp +++ b/include/bitcoin/node/settings.hpp @@ -48,6 +48,7 @@ class BCN_API settings uint32_t coinbase_sigops; uint32_t maximum_chunk_depth; uint16_t estimate_cache_seconds; + uint32_t estimate_room; bool thread_priority; /// Helpers. diff --git a/src/channels/channel_peer.cpp b/src/channels/channel_peer.cpp index 0d26b593..c503f523 100644 --- a/src/channels/channel_peer.cpp +++ b/src/channels/channel_peer.cpp @@ -41,6 +41,18 @@ bool channel_peer::was_announced(const hash_digest& hash) const NOEXCEPT return announced_.contains(hash); } +void channel_peer::set_silenced(bool value) NOEXCEPT +{ + BC_ASSERT(stranded()); + silenced_ = value; +} + +bool channel_peer::silenced() const NOEXCEPT +{ + BC_ASSERT(stranded()); + return silenced_; +} + void channel_peer::set_downloader(downloader&& handler) NOEXCEPT { BC_ASSERT(stranded()); diff --git a/src/chasers/chaser_confirm.cpp b/src/chasers/chaser_confirm.cpp index 1f6fa071..f4936c36 100644 --- a/src/chasers/chaser_confirm.cpp +++ b/src/chasers/chaser_confirm.cpp @@ -82,7 +82,7 @@ bool chaser_confirm::handle_chase(const code&, event_value value) NOEXCEPT return false; // Stop generating query during suspension. - // Incoming events may already be flushed to the strand at this point. + // Incoming events may already be flushed to strand at this point. if (suspended()) return true; @@ -212,7 +212,7 @@ void chaser_confirm::do_bumped(height_t) NOEXCEPT } // Compares candidate branch work to confirmed (above fork point). - // A tie is accepted because only prioritization creates one. + // Tie is accepted, as only prioritization creates one. bool strong{}; if (!query.get_strong_fork(strong, work, fork_point, true)) { @@ -396,7 +396,7 @@ bool chaser_confirm::notify_block(const code& ec, size_t height, // private // ---------------------------------------------------------------------------- -// Checkpointed blocks are set strong by archiver, and cannot be reorganized. +// Checkpointed blocks are set strong by archiver, cannot be reorganized. bool chaser_confirm::set_reorganized(const header_link& link, height_t confirmed_height) NOEXCEPT @@ -449,7 +449,8 @@ bool chaser_confirm::set_organized(const header_link& link, if (confirmed_height == maximum_height_) { maximum_height_ = zero; - LOG_ONLY(const hh_mm_ss elapsed{ seconds{ zulu_time() - start_time() } };) + LOG_ONLY(const auto duration = zulu_time() - start_time();) + LOG_ONLY(const hh_mm_ss elapsed{ seconds{ duration } };) LOGN("Organized maximum height [" << confirmed_height << "] in " << std::format("{:02}:{:02}:{:02}", elapsed.hours().count(), elapsed.minutes().count(), elapsed.seconds().count()) << "."); @@ -521,8 +522,8 @@ void chaser_confirm::do_broadcast(const header_link& link, broadcast(emplace_shared(block, organized)); } -// The chain becomes stale at the top block timestamp plus the window, which -// may be sooner than the window, as the block may have been mined earlier. +// Chain becomes stale at top block timestamp plus window, which may be sooner +// than window, as block may have been mined earlier. void chaser_confirm::start_stale_timer() NOEXCEPT { BC_ASSERT(stranded()); diff --git a/src/chasers/chaser_download.cpp b/src/chasers/chaser_download.cpp index 9a1d5681..faf8ac7e 100644 --- a/src/chasers/chaser_download.cpp +++ b/src/chasers/chaser_download.cpp @@ -192,7 +192,7 @@ void chaser_download::stop_tracking() NOEXCEPT ////BC_ASSERT(stranded()); // shared_ptr.reset() is thread safe so can be called at stop. - // Resetting our own pointer allows destruct and call to handle_purged. + // Resetting own pointer allows destruct and call to handle_purged. job_.reset(); } @@ -350,8 +350,7 @@ void chaser_download::do_regressed(height_t branch_point) NOEXCEPT return; // Update position and window, purge outstanding work, and wait on track - // completion. The window must follow the position or the gap it awaits - // is never requested. + // completion. Window must follow position or awaited gap never requested. set_position(std::min(branch_point, position())); requested_ = advanced_ = position(); stop_tracking(); @@ -518,7 +517,7 @@ bool chaser_download::set_map(const map_ptr& map) NOEXCEPT // Get all unassociated block records from start to stop heights. // Groups records into table sets by inventory set size, limited by advance. -// Return the total number of records obtained and set requested_ to last. +// Return total number of records obtained and set requested_ to last. size_t chaser_download::set_unassociated() NOEXCEPT { // Called from start. @@ -540,17 +539,17 @@ size_t chaser_download::set_unassociated() NOEXCEPT return {}; // Due to previous downloads, validation can race ahead of last request. - // The last request (requested_) stops at the last gap in the window, but - // validation continues until the next gap. Start next scan above validated - // not last requested, since all between are already downloaded. - // Bypassed blocks may archive unprobed, so the window must not extend - // above the bypass height until all blocks at/below it are associated. + // Last request (requested_) stops at last gap in window, but validation + // continues until next gap. Start next scan above validated, not last + // requested, since all between are already downloaded. Bypassed blocks may + // archive unprobed, so window must not extend above bypass height until all + // blocks at/below it are associated. const auto& query = archive(); const auto previous = requested_; const auto step = ceilinged_add(position(), maximum_concurrency_); const auto span = std::min(step, maximum_height_); - auto stop = position() < bypass_height_ ? - std::min(span, bypass_height_) : span; + const auto bypass_span = std::min(span, bypass_height_); + auto stop = position() < bypass_height_ ? bypass_span : span; size_t count{}; // Defer download of a current compact top block, awaiting its fill. @@ -607,8 +606,8 @@ void chaser_download::handle_compact_timer(const code& ec) NOEXCEPT do_headers({}); } -// The block is issued once, to the first channel that did not fill it. Other -// work found by the scan is announced to all channels. +// Block is issued once, to first channel that did not fill it. Other work +// found by scan is announced to all channels. void chaser_download::do_get_unfilled(header_t link, const map_handler& handler) NOEXCEPT { diff --git a/src/chasers/chaser_header.cpp b/src/chasers/chaser_header.cpp index 65ec1fdf..0a93e056 100644 --- a/src/chasers/chaser_header.cpp +++ b/src/chasers/chaser_header.cpp @@ -69,10 +69,10 @@ chaser_header::chaser_header(full_node& node) NOEXCEPT code chaser_header::start() NOEXCEPT { // Initialize cache of top candidate chain state. - // Spans full chain to obtain cumulative work. This can be optimized by - // storing it with each header, though the scan is fast. The same occurs - // when a block first branches below the current chain top. Chain work - // is a questionable DoS protection scheme only, so could also toss it. + // Spans full chain to obtain cumulative work. Can be optimized by storing + // it with each header, though scan is fast. Same occurs when block first + // branches below current chain top. Chain work is questionable DoS + // protection scheme only, so could also toss it. const auto& query = archive(); const auto top = query.get_top_candidate(); state_ = query.get_candidate_chain_state(settings_, top); @@ -377,19 +377,19 @@ void chaser_header::do_organize(const header::cptr& header_ptr, { if (!bumped_) { - // If at start the fork point is top of both chains, and next - // candidate is already downloaded, then new header will arrive and - // download will be skipped, resulting in stall until restart at - // which time the start event will advance through all downloaded - // candidates and progress on arrivals. This bumps validation for - // the first current strong header, and for the first following - // each regression, as the candidate above the branch point may - // already be downloaded when reorganizing back to a stored branch. + // If at start fork point is top of both chains, and next candidate + // already downloaded, then new header will arrive and download will + // be skipped, resulting in stall until restart, at which time start + // event will advance through all downloaded candidates and progress + // on arrivals. This bumps validation for first current strong + // header, and for first following each regression, as candidate + // above branch point may already be downloaded when reorganizing + // back to stored branch. notify(error::success, chases::bump{ add1(branch_point) }); bumped_ = true; } - // This prevents download stall, the download chaser races ahead. + // Prevents download stall, download chaser races ahead. // Start block downloads, which upon completion bumps validation. notify(error::success, chases::headers{ branch_point }); } @@ -576,11 +576,10 @@ void chaser_header::do_disorganize(header_t link) NOEXCEPT code chaser_header::duplicate(size_t& height, const hash_digest& hash) const NOEXCEPT { - // With a candidate reorg that drops strong below a valid header chain, - // this will cause a sequence of headers to be bypassed, such that a - // parent of a block that doesn't exist will not be a candidate, which - // result in a failure of get_chain_state, because it depends on candidate - // state. So get_chain_state needs to be chain independent. + // With candidate reorg that drops strong below valid header chain, a + // sequence of headers is bypassed, such that parent of a block that doesn't + // exist will not be candidate, resulting in get_chain_state failure, as it + // depends on candidate state. So get_chain_state must be chain independent. height = max_size_t; const auto& query = archive(); @@ -647,8 +646,8 @@ bool chaser_header::set_organized(const header_link& link, return true; } -// Headers cannot be set strong, that is only when the block is archived. -// Milestone is archived in the header and like checkpoint cannot change. +// Headers cannot be set strong, only when block is archived. +// Milestone is archived in header and, like checkpoint, cannot change. // But unlike checkpointed, milestoned blocks may not be strong chain. code chaser_header::push_header(header_link& link, const header& header, const context& ctx, const uint256_t& work, bool milestone, diff --git a/src/chasers/chaser_snapshot.cpp b/src/chasers/chaser_snapshot.cpp index bc5ad006..fe4bb2ed 100644 --- a/src/chasers/chaser_snapshot.cpp +++ b/src/chasers/chaser_snapshot.cpp @@ -78,7 +78,7 @@ bool chaser_snapshot::handle_chase(const code&, event_value value) NOEXCEPT return false; // Stop generating query during suspension. - // Incoming events may already be flushed to the strand at this point. + // Incoming events may already be flushed to strand at this point. if (suspended()) return true; @@ -155,8 +155,8 @@ void chaser_snapshot::do_prune(header_t link) NOEXCEPT << "(" << full_node::store::tables.at(table) << ")"); })) { - // Prune may fail due to chain not being coalesced following suspend, - // in which case pruning will be attempted on announce until success. + // Prune may fail due to chain not coalesced following suspend, in which + // case pruning is attempted on announce until success. LOGF("Prune deferred, " << ec.message()); if (running && ec == database::error::not_coalesced) diff --git a/src/chasers/chaser_storage.cpp b/src/chasers/chaser_storage.cpp index 35a21c19..40803c73 100644 --- a/src/chasers/chaser_storage.cpp +++ b/src/chasers/chaser_storage.cpp @@ -151,8 +151,8 @@ void chaser_storage::do_reload() NOEXCEPT << "(" << full_node::store::tables.at(table) << ")"); })) { - // A locked reload is a wait (in-flight accessors), not a failure: - // retry on the timer. All other store errors are terminal. + // Locked reload is a wait (in-flight accessors), not a failure: retry + // on timer. All other store errors are terminal. if (ec == database::error::reload_locked) { LOGN("Reload deferred by in-flight accessors."); diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index b5be00ce..f2ea761c 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -139,9 +139,9 @@ bool chaser_transaction::handle_chase(const code&, event_value value) NOEXCEPT return true; } -// The pool is closed until the confirmed chain is current, and closes again if -// currency is lost, though the store latch is one way, since the txs archived -// while it was open outlive it. +// Pool is closed until confirmed chain is current, and closes again if +// currency is lost, though store latch is one way, since txs archived while +// it was open outlive it. void chaser_transaction::do_bump() NOEXCEPT { BC_ASSERT(stranded()); @@ -155,8 +155,7 @@ void chaser_transaction::do_bump() NOEXCEPT auto& query = archive(); if (network_settings().enable_relay) { - // The context is of the block the index was last applied through, as - // the store's top may be above it. + // Context of block last applied to index (store top may be above). size_t height{}; const auto top = top_.is_terminal() ? query.to_top_confirmed() : top_; if (!query.get_height(height, top)) @@ -178,8 +177,7 @@ void chaser_transaction::do_bump() NOEXCEPT const auto previous = pool_; pool_ = chain_state{ *state, system_settings() }.context(); - // A row holds while no flag changes and neither height nor median - // time past falls. + // Row holds unless a flag changes or height or median time past falls. due_ = due_ || pool_.flags != previous.flags || pool_.height < previous.height || pool_.median_time_past < previous.median_time_past; @@ -199,7 +197,7 @@ void chaser_transaction::do_bump() NOEXCEPT if (!opened) floor_ = std::max(floor_, pool_.height); - // Sweeps deferred to the block are now made. + // Make sweeps deferred to block. swept_ = {}; if (!sweeping_) do_sweep_relay(); @@ -210,8 +208,8 @@ void chaser_transaction::do_bump() NOEXCEPT if (!query.silent_enabled() || scanning_) return; - // A complete map reaches genesis, and keeps up with the top until latched. - // Rows of a block archived before the latch may precede mapped starts. + // Complete map reaches genesis, and keeps up with top until latched. + // Rows of a block archived before latch may precede mapped starts. const auto top = query.to_top_confirmed(); const auto unmapped = query.get_scan_start(top).is_terminal(); if (query.get_scan_start(query.to_confirmed(zero)).is_terminal()) @@ -240,8 +238,8 @@ bool chaser_transaction::is_sufficient( database::context::from(ctx)); } -// A sweep remains due while it leaves any row unsatisfied, so that the row is -// restored once the pool context satisfies it. +// Sweep remains due while it leaves any row unsatisfied, so row is restored +// once pool context satisfies it. bool chaser_transaction::sweep() NOEXCEPT { BC_ASSERT(stranded()); @@ -263,8 +261,8 @@ bool chaser_transaction::sweep() NOEXCEPT } // Rows left out by flags are revalidated once per change of flags, and rows -// not validated once per change of the pool context, so a row that fails is -// retried only under another context. +// not validated once per change of pool context, so failing row is retried +// only under another context. void chaser_transaction::start_revalidation() NOEXCEPT { BC_ASSERT(stranded()); @@ -307,9 +305,9 @@ void chaser_transaction::start_revalidation() NOEXCEPT BIND(do_revalidate, std::move(links), pool_)); } -// Revalidation is admission under the context, as confirmation of what a row -// spends may differ from when it was pooled. Sigops are counted under the -// flags of the context, so a tx that passes is counted again. +// Revalidation is admission under context, as confirmation of what a row spends +// may differ from when it was pooled. Sigops are counted under flags of +// context, so a passing tx is counted again. void chaser_transaction::do_revalidate(const database::tx_links& links, const chain::context& ctx) NOEXCEPT { @@ -338,8 +336,8 @@ void chaser_transaction::do_revalidate(const database::tx_links& links, POST(do_revalidated, links, std::move(passed), std::move(sigops), ctx); } -// The pool context may have moved under the revalidation, and a reorganization -// under it may have unvalidated a row that it passed. +// Pool context may have moved under revalidation, and a reorganization under +// it may have unvalidated a row it passed. void chaser_transaction::do_revalidated(const database::tx_links& links, const data_chunk& passed, const std::vector& sigops, const chain::context& ctx) NOEXCEPT @@ -422,8 +420,8 @@ void chaser_transaction::do_scanned(bool mapped) NOEXCEPT do_bump(); } -// Index transitions are applied in the order confirmed, once the store is -// pooling and while relay is enabled, whether or not the pool is open. +// Index transitions are applied in order confirmed, once store is pooling +// and while relay is enabled, whether or not pool is open. void chaser_transaction::do_organized(header_t link) NOEXCEPT { BC_ASSERT(stranded()); @@ -449,8 +447,7 @@ void chaser_transaction::do_organized(header_t link) NOEXCEPT do_bump(); } -// The block was organized before it was announced, so its transition has -// been applied. +// Block organized before announced, so its transition has been applied. void chaser_transaction::do_block(header_t link) NOEXCEPT { BC_ASSERT(stranded()); @@ -460,8 +457,8 @@ void chaser_transaction::do_block(header_t link) NOEXCEPT notify(error::success, chases::block_settled{ link }); } -// Pooled in block order under the block context, excluding any confirmed (by -// another block). +// 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()); @@ -558,8 +555,8 @@ chaser_transaction::time_point chaser_transaction::now() NOEXCEPT return std::chrono::steady_clock::now(); } -// The fee and size are recomputed here, as they are for the package rate and -// for block fees, so the rate could instead be cached on the transaction. +// Fee and size are recomputed here, as for package rate and block fees, so +// rate could instead be cached on transaction. size_t chaser_transaction::to_rate(const chain::transaction& tx) NOEXCEPT { const auto size = tx.virtual_size(); @@ -642,8 +639,7 @@ void chaser_transaction::broadcast(const chain::transaction& tx) const NOEXCEPT broadcast(emplace_shared(view)); } -// A block less its header, largest tx count and declared coinbase weight and -// sigops. +// Block less header, largest tx count, declared coinbase weight and sigops. pool::algorithm::totals_t chaser_transaction::block_limit() const NOEXCEPT { constexpr auto count = variable_size(max_block_size / min_transaction_size); diff --git a/src/chasers/chaser_transaction_compact.cpp b/src/chasers/chaser_transaction_compact.cpp index e4283256..2d655605 100644 --- a/src/chasers/chaser_transaction_compact.cpp +++ b/src/chasers/chaser_transaction_compact.cpp @@ -47,8 +47,8 @@ void chaser_transaction::submit_compact(const transactions_cptr& txs, POST(do_submit_compact, txs, links, link, std::move(handler)); } -// A compact block is not filled while a block archives off the strand, so a -// block that finds the pool closed archives alone. +// Compact block is not filled while a block archives off strand, so a block +// that finds pool closed archives alone. bool chaser_transaction::archive_block(code& ec, const chain::view::block::cptr& block, const database::header_link& link, bool strong, bool bypass, size_t height, bool prune, @@ -132,10 +132,10 @@ void chaser_transaction::do_submit_compact(const transactions_cptr& txs, return true; }; - // Txs are an arbitrary subset of the block, so block checks are deferred to - // validation. Each is archived before the next, so in block order a parent - // is resolved from the store. The coinbase (never a parent within its - // block) is archived last, as validation indexes only txs linked above it. + // Txs are an arbitrary subset of block, so block checks are deferred to + // validation. Each is archived before next, so in block order a parent is + // resolved from store. Coinbase (never a parent within its block) is + // archived last, as validation indexes only txs linked above it. auto filled = links; const auto deferred = filled.front() == terminal; auto index = deferred ? one : zero; @@ -196,8 +196,8 @@ void chaser_transaction::do_archive_block( handler(query.set_code(*block, link, strong, bypass, height, prune)); } -// The stored tx, or validated and archived, pooled under the block context if -// guarded. Each block archives its own coinbase. +// Stored or validated and archived tx, pooled under block context if guarded. +// Each block archives its own coinbase. code chaser_transaction::fill(database::tx_link& out, const chain::transaction& tx, const chain::context& ctx) NOEXCEPT { @@ -258,7 +258,7 @@ code chaser_transaction::fill(database::tx_link& out, return error::success; } -// Pooled at the block's time, a sweep due if its context does not suffice. +// Pooled at block time, sweep due if block context does not suffice. bool chaser_transaction::set_pooled(const database::tx_link& link, const chain::transaction& tx, const chain::context& ctx) NOEXCEPT { @@ -285,9 +285,8 @@ code chaser_transaction::unconfirmable(const database::header_link& link, // validation // ---------------------------------------------------------------------------- -// A block tx is under proof of work, so it is not subject to policy (fee -// rate, guards) and may conflict with unconfirmed txs. It is guarded if it -// also passes the guards of admission, which a pooled tx must. +// Block tx is under proof of work, so not subject to policy (fee rate) and +// may conflict with unconfirmed txs. Guarded if it passes admission guards. code chaser_transaction::validate(bool& guarded, const chain::transaction& tx, const chain::context& ctx) NOEXCEPT { diff --git a/src/chasers/chaser_transaction_query.cpp b/src/chasers/chaser_transaction_query.cpp index 9465ed35..88155b65 100644 --- a/src/chasers/chaser_transaction_query.cpp +++ b/src/chasers/chaser_transaction_query.cpp @@ -233,7 +233,8 @@ void chaser_transaction::do_estimate(size_t target, estimate_mode mode, using algorithm = pool::algorithm; const auto space = limit.size; - const auto rate = algorithm::estimate(projection_, count, space, arrive); + const auto rate = algorithm::estimate(projection_, count, space, + settings.estimate_room, arrive); if (rate == max_uint64) { handler(error::estimate_false, {}); diff --git a/src/chasers/chaser_transaction_relay.cpp b/src/chasers/chaser_transaction_relay.cpp index f5e65d6e..2f0a5be8 100644 --- a/src/chasers/chaser_transaction_relay.cpp +++ b/src/chasers/chaser_transaction_relay.cpp @@ -61,12 +61,12 @@ size_t chaser_transaction::reserve_relay(relay_tier tier) NOEXCEPT return relay_slots; } -void chaser_transaction::activate_relay(size_t slot) NOEXCEPT +void chaser_transaction::activate_relay(size_t slot, object_key key) NOEXCEPT { if (closed() || slot >= relay_slots) return; - POST(do_activate_relay, slot); + POST(do_activate_relay, slot, key); } void chaser_transaction::release_relay(size_t slot) NOEXCEPT @@ -102,11 +102,12 @@ void chaser_transaction::relay_pool(size_t slot) NOEXCEPT POST(do_relay_pool, slot); } -// A slot is relayed to only once its channel is notified of relay, as a tx -// relayed to it before then is marked held by a peer that is not sent it. -void chaser_transaction::do_activate_relay(size_t slot) NOEXCEPT +// Slot is relayed to once its channel is notified, else marks precede sends. +void chaser_transaction::do_activate_relay(size_t slot, + object_key key) NOEXCEPT { BC_ASSERT(stranded()); + keys_.at(slot) = key; set_right_into(relaying_, slot); if (!sweeping_) do_sweep_relay(); @@ -119,6 +120,7 @@ void chaser_transaction::do_release_relay(size_t slot) NOEXCEPT set_right_into(mark, slot, false); rates_.at(slot) = zero; + keys_.at(slot) = {}; set_right_into(relaying_, slot, false); set_right_into(owed_, slot, false); set_right_into(swept_, slot, false); @@ -142,8 +144,7 @@ void chaser_transaction::do_relay_pool(size_t slot) NOEXCEPT } // private -// A sweep is a scan of the pool at a peer's request, so a slot is swept once -// between blocks, and a later request is met after the next block. +// Sweep is a pool scan at peer request, so one per slot between blocks. void chaser_transaction::owe_relay(size_t slot) NOEXCEPT { BC_ASSERT(stranded()); @@ -158,8 +159,7 @@ uint64_t chaser_transaction::sweepable() const NOEXCEPT return bit_and(bit_and(owed_, relaying_), bit_not(swept_)); } -// One slot is swept in a turn of the strand, so other work is not held up by -// the sweeps of many slots. +// One slot swept per strand turn, so sweeps do not hold up other work. void chaser_transaction::do_sweep_relay() NOEXCEPT { BC_ASSERT(stranded()); @@ -198,7 +198,7 @@ bool chaser_transaction::sweep_relay(size_t slot) NOEXCEPT if (row.is_terminal() || get_right(marks(row.value), slot)) continue; - if (!relay({ link }, relay_slots, word)) + if (!relay({ link }, relay_slots, word, keys_.at(slot))) return false; } @@ -219,8 +219,9 @@ void chaser_transaction::do_set_relayed(size_t slot, } // private +// Relay events go to every channel, or with a key only to its own. bool chaser_transaction::relay(const database::tx_links& links, - size_t origin, uint64_t slots) NOEXCEPT + size_t origin, uint64_t slots, object_key key) NOEXCEPT { BC_ASSERT(stranded()); using algorithm = pool::algorithm; @@ -287,9 +288,9 @@ bool chaser_transaction::relay(const database::tx_links& links, for (size_t slot{}; slot < relay_slots; ++slot) { const auto size = sizes.at(slot); - if (!is_zero(size) && size <= limit && - ceilinged_multiply(fees.at(slot), 1'000_u64) >= - ceilinged_multiply(rates_.at(slot), size)) + const auto paid = ceilinged_multiply(fees.at(slot), 1'000_u64); + const auto owed = ceilinged_multiply(rates_.at(slot), size); + if (!is_zero(size) && size <= limit && paid >= owed) set_right_into(clears, slot); } @@ -301,7 +302,11 @@ bool chaser_transaction::relay(const database::tx_links& links, continue; mark = bit_or(mark, word); - notify(error::success, chases::relay{ row.link.value, word }); + const chases::relay event{ row.link.value, word }; + if (is_zero(key)) + notify(error::success, event); + else + notify_one(key, error::success, event); } return true; diff --git a/src/chasers/chaser_transaction_submit.cpp b/src/chasers/chaser_transaction_submit.cpp index e978256c..9f5c7bec 100644 --- a/src/chasers/chaser_transaction_submit.cpp +++ b/src/chasers/chaser_transaction_submit.cpp @@ -37,8 +37,8 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR) // submit // ---------------------------------------------------------------------------- -// The first measured component over a limit, its check, counts and members -// (K candidate, otherwise the pooled wtxid). +// First measured component over a limit, its check, counts and members +// (K candidate, otherwise pooled wtxid). static std::string describe_limit(const node::query& query, const node::query::pool_graph& graph, size_t given, const pool::algorithm::totals_t& limit, size_t maximum_outcomes) NOEXCEPT @@ -124,12 +124,12 @@ void chaser_transaction::submit_announced(const transactions_cptr& txs, } // private -// A set is tested prefix by prefix. The running set is its unstored txs since -// the last prefix to clear, and clears when its coverage does. -// It is then connected and admitted, and the next tx starts another. An -// announced set is a batch, not a package, so a tx of it that is not accepted, -// or that exceeds a pool limit, is passed over as if stored. A tx is accepted -// only if each parent is confirmed, pooled, or accepted before it in the set. +// Set is tested prefix by prefix. Running set is its unstored txs since last +// prefix to clear, and clears when its coverage does. It is then connected +// and admitted, and next tx starts another. Announced set is a batch, not a +// package, so a tx of it not accepted, or exceeding a pool limit, is passed +// over as if stored. A tx is accepted only if each parent is confirmed, +// pooled, or accepted before it in set. void chaser_transaction::do_submit(const transactions_cptr& txs, bool test, bool announced, size_t slot, const submit_handler& handler) NOEXCEPT { @@ -224,8 +224,7 @@ void chaser_transaction::do_submit(const transactions_cptr& txs, bool test, } // private -// A tx of the set is stored if pooled or confirmed (other than a coinbase), -// and if pooled is held by the peer that sent it. +// Set tx is stored if pooled or confirmed (not coinbase), pooled held by peer. void chaser_transaction::hold(submission& set) NOEXCEPT { const auto& query = archive(); @@ -305,7 +304,7 @@ void chaser_transaction::count(submission& set, } // private -// The running set is bounded by a block, and its coverage by the pool limits. +// Running set is bounded by a block, and its coverage by pool limits. code chaser_transaction::extend(bool& covered, submission& set, size_t index) NOEXCEPT { @@ -355,7 +354,7 @@ code chaser_transaction::extend(bool& covered, submission& set, } // private -// The running set before the index, without any tx passed over. +// Running set before index, without any tx passed over. code chaser_transaction::restore(submission& set, size_t index) NOEXCEPT { auto& query = archive(); @@ -380,8 +379,8 @@ code chaser_transaction::restore(submission& set, size_t index) NOEXCEPT } // private -// Script validation is the most costly, so it follows the guards. In a test -// the cleared txs are not pooled, so remain given candidates. +// Script validation is most costly, so it follows guards. In a test, cleared +// txs are not pooled, so remain given candidates. code chaser_transaction::clear(size_t& at, submission& set, size_t index) NOEXCEPT { @@ -432,8 +431,8 @@ code chaser_transaction::clear(size_t& at, submission& set, // validation // ---------------------------------------------------------------------------- -// A tx of an announced set that precedes its parent is not accepted, and -// its txs that spend one point are rivals. +// Tx of announced set preceding its parent is not accepted, and its txs that +// spend one point are rivals. code chaser_transaction::check(const transaction_cptrs& txs, const std::vector& stored, bool announced) NOEXCEPT { @@ -473,8 +472,7 @@ code chaser_transaction::admit(database::tx_link& link, if (!admitted) return fault(error::transaction2); - // A spender pooled again keeps its context, which may not suffice, - // and one not validated for want of this parent may now pass. + // Spender pooled again keeps its context, and may now pass if failed. if (is_nonzero(repooled)) { due_ = true; diff --git a/src/chasers/chaser_validate.cpp b/src/chasers/chaser_validate.cpp index 8b06e7c5..291180b9 100644 --- a/src/chasers/chaser_validate.cpp +++ b/src/chasers/chaser_validate.cpp @@ -105,15 +105,15 @@ bool chaser_validate::handle_chase(const code&, event_value value) NOEXCEPT return true; } - // Record durable state before the suspension gate. A consequence is that - // recovery with window_archived_ drains small batches until next checked. + // Record durable state before suspension gate. Consequently, recovery with + // window_archived_ drains small batches until next checked. if (event_ == chase::windowed) window_archived_.store(true); else if (event_ == chase::checked) window_archived_.store(false); // Stop generating query during suspension. - // Incoming events may already be flushed to the strand at this point. + // Incoming events may already be flushed to strand at this point. if (suspended()) return true; @@ -140,9 +140,9 @@ bool chaser_validate::handle_chase(const code&, event_value value) NOEXCEPT } case chase::windowed: { - // Called directly (not posted): the drain must never depend on - // scheduling, which saturated validations can exhaust for the - // entire window (strand for admission-side control, never for + // Called directly (not posted): drain must never depend on + // scheduling, which saturated validations can exhaust for entire + // window (strand for admission-side control, never for // release-side). process_batch(is_residual()); process_silent_batch(is_residual()); diff --git a/src/chasers/chaser_validate_batch.cpp b/src/chasers/chaser_validate_batch.cpp index 32a5860e..b4de2f14 100644 --- a/src/chasers/chaser_validate_batch.cpp +++ b/src/chasers/chaser_validate_batch.cpp @@ -65,18 +65,18 @@ void chaser_validate::process_batch(bool residual) NOEXCEPT if (draining_.exchange(true)) return; - // Retest under the claim, another drain may have just emptied the bank. - // Losers commit before testing, so the retest after each drain observes - // commits that lost the claim during it. + // Retest under claim, another drain may have just emptied bank. Losers + // commit before testing, so retest after each drain observes commits that + // lost claim during it. while (!closed() && is_mature(residual || is_residual())) { // Admit arriving commits to the other bank (changed only under claim). const auto bank = bank_.load(); bank_.store(!bank); - // Wait for in-flight commits to the bank to complete or abandon on - // close. Bounded: the writer epoch spans only the per-block slab - // commit, and arriving commits go to the other bank. + // Wait for in-flight commits to bank to complete or abandon on close. + // Bounded: writer epoch spans only per-block slab commit, and arriving + // commits go to other bank. while (is_nonzero(writers_.at(to_int(bank)).load())) { if (closed()) @@ -182,10 +182,11 @@ code chaser_validate::purge_batch(bool bank) NOEXCEPT auto& query = archive(); // Purge prevalids before signatures. - return query.purge_prevalids(bank) && - query.purge_ecdsa_signatures(bank) && - query.purge_schnorr_signatures(bank) ? - error::success : error::batch4; + const auto purged = query.purge_prevalids(bank) + && query.purge_ecdsa_signatures(bank) + && query.purge_schnorr_signatures(bank); + + return purged ? error::success : error::batch4; } bool chaser_validate::mark_invalids(header_links& prevalids, @@ -340,17 +341,16 @@ void chaser_validate::process_silent_batch(bool residual) NOEXCEPT if (silent_draining_.exchange(true)) return; - // Retest under the claim, another drain may have just emptied the bank. - // Losers commit before testing, so the retest after each drain observes - // commits that lost the claim during it. + // Retest under claim, another drain may have just emptied bank. Losers + // commit before testing, so retest after each drain observes commits that + // lost claim during it. while (!closed() && is_silent_mature(residual || is_residual())) { // Admit arriving commits to the other bank (changed only under claim). const auto bank = silent_bank_.load(); silent_bank_.store(!bank); - // Wait for in-flight commits to the bank to complete or abandon on - // close. + // Wait for in-flight commits to bank to complete or abandon on close. while (is_nonzero(silent_writers_.at(to_int(bank)).load())) { if (closed()) @@ -420,8 +420,8 @@ code chaser_validate::do_process_silent_batch(bool bank) NOEXCEPT return error::success; } -// Upon store decline the records are set directly, within the commit epoch, -// so that a drain of the bank cannot precede them. +// Upon store decline, records are set directly, within commit epoch, so a drain +// of bank cannot precede them. template bool chaser_validate::commit_silent_(const header_link& link, const Block& block) NOEXCEPT @@ -452,8 +452,8 @@ bool chaser_validate::commit_silent_batch(const header_link& link, return commit_silent_(link, block); } -// A writer admitted to a bank that is then switched retries on the other, so -// that a drain observes every writer of its bank. +// Writer admitted to a bank that is then switched retries on the other, so a +// drain observes every writer of its bank. bool chaser_validate::enter_silent_capture() NOEXCEPT { while (true) @@ -476,8 +476,8 @@ void chaser_validate::exit_silent_capture(bool bank) NOEXCEPT // ---------------------------------------------------------------------------- // protected -// A writer admitted to a bank that is then switched retries on the other, so -// that a drain observes every writer of its bank. +// Writer admitted to a bank that is then switched retries on the other, so a +// drain observes every writer of its bank. bool chaser_validate::enter_capture() NOEXCEPT { while (true) diff --git a/src/chasers/chaser_validate_capture.cpp b/src/chasers/chaser_validate_capture.cpp index e98140e4..f5ad1187 100644 --- a/src/chasers/chaser_validate_capture.cpp +++ b/src/chasers/chaser_validate_capture.cpp @@ -79,11 +79,10 @@ signatures chaser_validate::get_capture(const header_link& link) NOEXCEPT }; } -// Commit this thread's captured signatures as the block's batch rows. All -// batch table state is written inside the commit epoch (turnstile). Upon -// store decline, the rows are verified in place, equivalent to the inline -// evaluation their capture fabricated (batched is cleared so the block -// completes by the non-batched path). +// Commit this thread's captured signatures as block's batch rows. All batch +// table state is written inside commit epoch (turnstile). Upon store decline, +// rows are verified in place, equivalent to inline evaluation their capture +// fabricated (batched is cleared so block completes by non-batched path). code chaser_validate::commit_capture(bool& batched, const header_link& link) NOEXCEPT { @@ -138,9 +137,9 @@ void chaser_validate::clear_capture() NOEXCEPT signatures::schnorr_rows().clear(); } -// Release all threads' accumulator capacity (batching subsided). Safe on the -// strand with an empty backlog: accumulators are populated only within -// validate_block, and the strand is the sole poster of validations. +// Release all threads' accumulator capacity (batching subsided). Safe on +// strand with empty backlog: accumulators are populated only within +// validate_block, and strand is sole poster of validations. void chaser_validate::do_purge_capture() NOEXCEPT { BC_ASSERT(stranded()); diff --git a/src/chasers/chaser_validate_parallel.cpp b/src/chasers/chaser_validate_parallel.cpp index 699c1cab..7e0c33cd 100644 --- a/src/chasers/chaser_validate_parallel.cpp +++ b/src/chasers/chaser_validate_parallel.cpp @@ -63,8 +63,7 @@ void chaser_validate::validate_block(const header_link& link, const auto start = network::logger::now(); const auto current = !bypass && is_current_header(link); - // A block is timed only if validated alone, as concurrent blocks share - // the processor. + // Block timed only if validated alone, as concurrent ones share processor. const auto ticket = validating_.begin(); if (!query.get_context(ctx, link)) @@ -159,8 +158,8 @@ code chaser_validate::populate(chain::view::block& block, if (!archive().get_block_prevouts(prevouts, spends, conflicts, link)) return system::error::missing_previous_output; - // Internal maturity and time locks are verified here because they are - // the only necessary confirmation checks for internal spends. + // Internal maturity and time locks are verified here, as they are the + // only necessary confirmation checks for internal spends. return block.populate(ctx, std::move(prevouts)); } @@ -179,8 +178,8 @@ void chaser_validate::scan_block(const header_link& link, complete_block(ec, link, height, bypass); } -// A bypassed block is read only for its optional indexes, so it is not -// materialized. A filter requires all prevouts, otherwise only those of the +// Bypassed block is read only for its optional indexes, so not materialized. +// Filter requires all prevouts, otherwise only those of // silent payment eligible txs are populated. code chaser_validate::validate_view(const header_link& link, bool filter, bool silent, bool bank) NOEXCEPT @@ -227,8 +226,8 @@ code chaser_validate::complete_view(const header_link& link, bool filter, return query.set_block_valid(link) ? error::success : error::validate10; } -// A block with all txs pooled under a sufficient context requires only block -// checks, performed by the store. Insufficiency implies full validation. +// Block with all txs pooled under a sufficient context requires only block +// checks, performed by store. Insufficiency implies full validation. code chaser_validate::validate_pooled(bool& pooled, const header_link& link, const chain::context& ctx) NOEXCEPT { @@ -240,8 +239,8 @@ code chaser_validate::validate_pooled(bool& pooled, const header_link& link, return error::success; // Store codes are faults, consensus codes imply block invalidity. - return database::error::error_category::contains(ec) ? - error::validate11 : ec; + const auto store_code = database::error::error_category::contains(ec); + return store_code ? error::validate11 : ec; } // A pooled block is valid and SP indexed, so produce only for client filters. @@ -288,9 +287,9 @@ code chaser_validate::validate(bool& batched, bool& capturing, // At least one signature batch was attempted (batch completion). batched = capture.batched; - // Commit (or discard) the captured signatures, marking the block prevalid - // contingent on batch verification. The commit epoch is mutually - // exclusive with batch verification (turnstile). + // Commit (or discard) captured signatures, marking block prevalid + // contingent on batch verification. Commit epoch is mutually exclusive + // with batch verification (turnstile). if (capturing) { if (!ec && batched) diff --git a/src/configuration.cpp b/src/configuration.cpp index aaf0a1ad..b1925747 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -104,8 +104,8 @@ code configuration::initialize() NOEXCEPT return network.initialize(); } -// Unset reserves default to the configured manual peers and outbound -// connections (current connections once reduced). +// Unset reserves default to configured manual peers and outbound connections +// (current connections once reduced). size_t configuration::manual_relay_slots() const NOEXCEPT { size_t reserve = node.manual_relay_slots; diff --git a/src/full_node.cpp b/src/full_node.cpp index 5e40f413..7fd1a1ad 100644 --- a/src/full_node.cpp +++ b/src/full_node.cpp @@ -114,7 +114,7 @@ void full_node::do_run(const result_handler& handler) NOEXCEPT } // Bump sequential chasers to their starting heights. - // This will kick off lagging validations even if not current. + // Kicks off lagging validations even if not current. do_notify(error::success, chases::start{}); // Start services after network is running. @@ -274,9 +274,9 @@ size_t full_node::reserve_relay(relay_tier tier) NOEXCEPT return chaser_transaction_.reserve_relay(tier); } -void full_node::activate_relay(size_t slot) NOEXCEPT +void full_node::activate_relay(size_t slot, object_key key) NOEXCEPT { - chaser_transaction_.activate_relay(slot); + chaser_transaction_.activate_relay(slot, key); } void full_node::release_relay(size_t slot) NOEXCEPT @@ -476,9 +476,9 @@ code full_node::reload(const store::event_handler& handler) NOEXCEPT const auto start = logger::now(); suspend(error::store_reload); - // This will set the store's dirty flag causing increased read activity for - // set(tx/block) due to activation of duplicate detection. The store is - // is however always in a dirty state after startup with non-empty tables. + // Sets store's dirty flag, causing increased read activity for + // set(tx/block) due to activation of duplicate detection. Store is however + // always in a dirty state after startup with non-empty tables. const auto ec = query_.reload([&](auto event, auto table) NOEXCEPT { // Suspend channels that missed previous suspend events. diff --git a/src/protocols/protocol_block_in_31800.cpp b/src/protocols/protocol_block_in_31800.cpp index f7897138..cce16262 100644 --- a/src/protocols/protocol_block_in_31800.cpp +++ b/src/protocols/protocol_block_in_31800.cpp @@ -68,7 +68,7 @@ void protocol_block_in_31800::subscribed(const code& ec, object_key) NOEXCEPT } // Start performance timing and download cycles if candidates are current. - // This prevents a startup delay in which the node waits on a header. + // Prevents startup delay in which node waits on a header. if (is_current_chain(false)) { start_performance(); @@ -109,30 +109,30 @@ bool protocol_block_in_31800::handle_chase(const code&, case chase::split: { // chase::split is posted by notify_one() using subscription key. - // 'value' is the channel that requested a split to obtain work. + // 'value' is channel that requested split to obtain work. POST(do_split, peer_t{}); break; } case chase::stall: { // If this channel has divisible work, split it and stop. - // There are no channels reporting work, either stalled or done. - // This is initiated by any channel notifying chase::starved. + // No channels reporting work, either stalled or done. + // Initiated by any channel notifying chase::starved. POST(do_stall, peer_t{}); break; } case chase::purge: { - // If have work clear it and stop. - // This is initiated by chase::regressed/disorganized. + // If have work, clear it and stop. + // Initiated by chase::regressed/disorganized. POST(do_purge, peer_t{}); break; } case chase::download: { - // There are count blocks to download at/above given header. + // Count blocks to download at/above given header. // chase::headers is only sent for current candidate chain, and this - // chase::download is only sent as a consequence of chase::headers. + // chase::download is only sent as consequence of chase::headers. POST(do_get_downloads, to_payload(value).count); break; } @@ -312,10 +312,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, // Identify block. // ........................................................................ - // Tx commitments and malleation are checked under bypass. Invalidity is - // only stored when a strong header has been stored, later to be found out - // as invalid and not malleable. Stored invalidity prevents repeat - // processing of the same invalid chain but is not necessary or desirable. + // Tx commitments and malleation checked under bypass. Invalidity is only + // stored when a strong header has been stored, later found invalid and not + // malleable. Stored invalidity prevents repeat processing of same invalid + // chain but is not necessary or desirable. if (const auto code = identify(block, it->context, bypass)) { if (code == system::error::invalid_transaction_commitment || @@ -361,8 +361,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec, } // not stranded -// A stored block is announced, and a failure to store one is a fault, whether -// or not its channel has stopped. +// Stored block is announced, and failure to store one is a fault, whether or +// not its channel has stopped. void protocol_block_in_31800::announce(const code& ec, const hash_digest& hash, size_t height) NOEXCEPT { @@ -438,9 +438,9 @@ bool protocol_block_in_31800::archived(const code& ec, return true; } -// Header is checked by header_in, Check/Accept/Connect are called by validate. +// Header is checked by header_in, Check/Accept/Connect called by validate. // While check could be called here, it's more optimal to defer to validate, as -// requiring only identity here allows the use of the simplified view::block. +// requiring only identity here allows use of simplified view::block. code protocol_block_in_31800::identify(const chain::view::block& block, const chain::context& ctx, bool bypass) const NOEXCEPT { diff --git a/src/protocols/protocol_block_out_106.cpp b/src/protocols/protocol_block_out_106.cpp index c2bc40d8..021e7cee 100644 --- a/src/protocols/protocol_block_out_106.cpp +++ b/src/protocols/protocol_block_out_106.cpp @@ -35,10 +35,10 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) BC_PUSH_WARNING(SMART_PTR_NOT_NEEDED) BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR) -// This protocol provides witness support despite 106 being much older than -// bip144. This is because protocols are splot on the version negotiated in the -// p2p handshake. Witness is enabled via a service bit. Protocols should also -// be factored based on relevant service bits but that is not yet implemented. +// Protocol provides witness support despite 106 being much older than bip144, +// as protocols are split on version negotiated in p2p handshake. Witness is +// enabled via a service bit. Protocols should also be factored on relevant +// service bits, but that is not yet implemented. // start/stop // ---------------------------------------------------------------------------- @@ -177,9 +177,8 @@ void protocol_block_out_106::send_block(const code& ec, size_t index, const auto& query = archive(); - // Drain unservable items, skipping non-block inventory. The derived - // protocol accumulates them if it reports them, and otherwise stops the - // channel on the first. + // Drain unservable items, skipping non-block inventory. Derived protocol + // accumulates them if it reports them, otherwise stops channel on first. database::header_link link{}; for (; index < message->items.size(); ++index) { diff --git a/src/protocols/protocol_block_out_70001.cpp b/src/protocols/protocol_block_out_70001.cpp index 2ce81d94..bc1f58b6 100644 --- a/src/protocols/protocol_block_out_70001.cpp +++ b/src/protocols/protocol_block_out_70001.cpp @@ -50,8 +50,8 @@ bool protocol_block_out_70001::handle_unservable( return true; } -// The items are answered and the send loop resumed, as with a block, so -// nothing is produced until the prior write completes. +// Items are answered and send loop resumed, as with a block, so nothing is +// produced until prior write completes. bool protocol_block_out_70001::report_unservable(size_t index, const get_data::cptr& message, const gate_t::ptr& gate) NOEXCEPT { diff --git a/src/protocols/protocol_filter_out_70015.cpp b/src/protocols/protocol_filter_out_70015.cpp index cb08fcfb..0159413c 100644 --- a/src/protocols/protocol_filter_out_70015.cpp +++ b/src/protocols/protocol_filter_out_70015.cpp @@ -83,9 +83,9 @@ bool protocol_filter_out_70015::handle_receive_get_filter_checkpoint( return false; } - // There is no guarantee that this set will be consistent across reorgs. - // However for it to be inconsistent there must be a >= 1000 block reorg. - // If the branch has never been confirmed then filters will not be found. + // No guarantee this set will be consistent across reorgs. + // However, for it to be inconsistent there must be a >= 1000 block reorg. + // If branch has never been confirmed then filters will not be found. client_filter_checkpoint out{}; if (!query.get_filter_heads(out.filter_headers, stop_height, client_filter_checkpoint_interval)) @@ -148,8 +148,8 @@ bool protocol_filter_out_70015::handle_receive_get_filter_headers( return false; } - // The response is assured to represent a consistent branch. - // If the branch has never been confirmed then filters will not be found. + // Response is assured to represent a consistent branch. + // If branch has never been confirmed then filters will not be found. client_filter_headers out{}; if (!query.get_filter_hashes(out.filter_hashes, out.previous_filter_header, stop_link, count)) diff --git a/src/protocols/protocol_header_in_31800.cpp b/src/protocols/protocol_header_in_31800.cpp index 649800a7..6106d9f6 100644 --- a/src/protocols/protocol_header_in_31800.cpp +++ b/src/protocols/protocol_header_in_31800.cpp @@ -131,12 +131,11 @@ void protocol_header_in_31800::synchronize(const headers& message, return; } - // A message that does not extend the branch restarts from the parent of - // its first header. A single header with an unknown parent is an - // announcement from a peer that is ahead, so headers are requested from - // the top candidate. Multiple headers with an unknown parent are a - // response from a peer that does not connect to our locator, so the - // peer is dropped. + // Message that does not extend branch restarts from parent of its first + // header. Single header with unknown parent is an announcement from a peer + // that is ahead, so headers are requested from top candidate. Multiple + // headers with unknown parent are a response from a peer that does not + // connect to locator, so peer is dropped. const auto& first = ptrs.front()->previous_block_hash(); if ((!state_ || first != state_->hash()) && !restart(first)) { @@ -253,8 +252,8 @@ void protocol_header_in_31800::collect(const headers& message, LOGP("Archived headers to [" << encode_hash(previous_) << ":" << height_ << "] from [" << opposite() << "]."); - // Resume synchronization above the proven top (state_ retained), - // which is independent of when the organizer archives it. + // Resume synchronization above proven top (state_ retained), which + // is independent of when organizer archives it. samples_.clear(); milestone_ = zero; archiving_ = false; @@ -391,8 +390,8 @@ void protocol_header_in_31800::handle_organize(const code& ec, << "] from [" << opposite() << "] " << ec.message()); } -// This could be the end of a catch-up sequence, or a singleton announcement. -// The distinction is ultimately arbitrary, but this signals peer completeness. +// Could be end of a catch-up sequence, or a singleton announcement. +// Distinction is ultimately arbitrary, but this signals peer completeness. void protocol_header_in_31800::complete() NOEXCEPT { BC_ASSERT(stranded()); @@ -419,7 +418,7 @@ void protocol_header_in_31800::resynchronize() NOEXCEPT // Inbound (inv). // ---------------------------------------------------------------------------- -// Handle announcement by requesting headers if the last announced is missing. +// Handle announcement by requesting headers if last announced is missing. bool protocol_header_in_31800::handle_receive_inventory(const code& ec, const inventory::cptr& message) NOEXCEPT @@ -449,9 +448,9 @@ bool protocol_header_in_31800::handle_receive_inventory(const code& ec, get_headers protocol_header_in_31800::create_get_headers() const NOEXCEPT { - // Header sync is from the archived (strong) candidate chain. - // Until the header tree is current the candidate chain remains empty. - // So all channels will fully sync from the top candidate at their startup. + // Header sync is from archived (strong) candidate chain. + // Until header tree is current, candidate chain remains empty. + // So all channels fully sync from top candidate at their startup. const auto& query = archive(); const auto index = get_headers::heights(query.get_top_candidate()); return create_get_headers(query.get_candidate_hashes(index)); diff --git a/src/protocols/protocol_header_in_70014.cpp b/src/protocols/protocol_header_in_70014.cpp index 4023277d..5215244a 100644 --- a/src/protocols/protocol_header_in_70014.cpp +++ b/src/protocols/protocol_header_in_70014.cpp @@ -103,7 +103,7 @@ bool protocol_header_in_70014::handle_receive_send_compact(const code& ec, return true; } -// High bandwidth is requested of a peer that signaled compact blocks, once the +// High bandwidth is requested of a peer that signaled compact blocks, once // chain is current, whichever comes last, while a slot is free. void protocol_header_in_70014::upgrade() NOEXCEPT { @@ -271,7 +271,7 @@ void protocol_header_in_70014::collect(const compact_block& message, request(); } -// Prefilled txs by differentially encoded index, short ids in the remaining +// Prefilled txs by differentially encoded index, short ids in remaining // positions (bip152). bool protocol_header_in_70014::decode(fill& block, const compact_block& message) NOEXCEPT @@ -393,8 +393,8 @@ bool protocol_header_in_70014::handle_receive_compact_transactions( return false; } - // The peer's short id for each position must match its own tx. A coinbase - // short id is over its witness serialization, not its null wtxid (bip152). + // Peer's short id for each position must match its own tx. Coinbase short + // id is over its witness serialization, not its null wtxid (bip152). for (size_t index{}; index < txs.size(); ++index) { const auto& tx = txs.at(index); @@ -580,8 +580,8 @@ void protocol_header_in_70014::do_submit_compact(const code& ec, // Unfilled. // ---------------------------------------------------------------------------- -// The block is requested of the peer that announced it, as work of the -// channel's block protocol, and work not taken is returned. +// Block is requested of peer that announced it, as work of channel's block +// protocol, and work not taken is returned. // not stranded void protocol_header_in_70014::handle_unfilled(const code& ec, @@ -614,9 +614,9 @@ void protocol_header_in_70014::restore(const map_ptr& map) NOEXCEPT // Evidence. // ---------------------------------------------------------------------------- -// Evidence of an unidentified compact block is held until the peer's next -// compact block, when it is resolved against the block if then archived. A -// resend of the block in evidence is not filled while it remains unarchived. +// Evidence of an unidentified compact block is held until peer's next compact +// block, when it is resolved against the block if then archived. Resend of +// block in evidence is not filled while it remains unarchived. bool protocol_header_in_70014::resolve( const database::header_link& link) NOEXCEPT { diff --git a/src/protocols/protocol_peer.cpp b/src/protocols/protocol_peer.cpp index 169114a7..3326cfb7 100644 --- a/src/protocols/protocol_peer.cpp +++ b/src/protocols/protocol_peer.cpp @@ -80,9 +80,9 @@ bool protocol_peer::reserve_relay() NOEXCEPT return slot < relay_slots; } -void protocol_peer::activate_relay() NOEXCEPT +void protocol_peer::activate_relay(object_key key) NOEXCEPT { - session_->activate_relay(channel_->relay_slot()); + session_->activate_relay(channel_->relay_slot(), key); } void protocol_peer::release_relay() NOEXCEPT @@ -150,6 +150,16 @@ bool protocol_peer::was_announced(const system::hash_digest& hash) const NOEXCEP return channel_->was_announced(hash); } +void protocol_peer::set_silenced(bool value) NOEXCEPT +{ + channel_->set_silenced(value); +} + +bool protocol_peer::silenced() const NOEXCEPT +{ + return channel_->silenced(); +} + // Compact blocks (bip152 version 2). // ---------------------------------------------------------------------------- diff --git a/src/protocols/protocol_performer.cpp b/src/protocols/protocol_performer.cpp index aceaff0f..fbe2eb65 100644 --- a/src/protocols/protocol_performer.cpp +++ b/src/protocols/protocol_performer.cpp @@ -93,7 +93,7 @@ void protocol_performer::send_performance(uint64_t rate) NOEXCEPT if (enabled_) { - // Must come first as this takes priority as per configuration. + // Must come first, as it takes priority per configuration. // Shared performance manager detects slow and stalled channels. if (deviation_) { diff --git a/src/protocols/protocol_transaction_in_106.cpp b/src/protocols/protocol_transaction_in_106.cpp index 1bcc8f3e..66f8df68 100644 --- a/src/protocols/protocol_transaction_in_106.cpp +++ b/src/protocols/protocol_transaction_in_106.cpp @@ -109,6 +109,10 @@ bool protocol_transaction_in_106::handle_receive_inventory(const code& ec, if (!is_current_chain(true)) return true; + // Peer told not to announce is not asked for its announcements. + if (silenced()) + return true; + const auto getter = create_get_data(*message); if (getter.items.empty()) return true; @@ -121,7 +125,7 @@ bool protocol_transaction_in_106::handle_receive_inventory(const code& ec, } // private -// The txs requested of the announcement are one set, in its order. +// Txs requested of announcement are one set, in its order. get_data protocol_transaction_in_106::create_get_data( const inventory& message) NOEXCEPT { @@ -138,8 +142,7 @@ get_data protocol_transaction_in_106::create_get_data( const auto repeated = was_announced(item.hash); set_announced(item.hash); - // A known tx is held by the peer (a pooled one is marked so, once), - // and a tx is requested once. + // Known tx is held by peer (pooled marked once), tx requested once. const request slot{ sequence, set.hashes.size() }; if (const auto link = to_known(item.hash); !link.is_terminal()) { @@ -183,7 +186,7 @@ void protocol_transaction_in_106::advance(size_t set) NOEXCEPT } // private -// A tx of the set that is yet to arrive is a set of its own when it does. +// Tx of set yet to arrive is a set of its own when it does. void protocol_transaction_in_106::flush() NOEXCEPT { BC_ASSERT(stranded()); @@ -298,15 +301,15 @@ void protocol_transaction_in_106::do_handle_submit(const code& ec, if (stopped() || ec == network::error::service_stopped) return; - // A conflict with an unconfirmed tx is not misbehavior, as the peer - // cannot know what is held here, and a requested tx may be archived from - // another peer before it arrives. An unknown prevout is not misbehavior, - // as announcement order is not constrained and orphans are not pooled. - // A locked tx is final to a peer one block ahead, as locks are evaluated - // against the presumed next block, so neither lock is misbehavior. - // The rate and suspension cannot be advertised below bip133, so a tx that - // violates either is not misbehavior (see protocol_transaction_in_70013). - // The peer cannot know the extent of a conflict component held here. + // Conflict with an unconfirmed tx is not misbehavior, as peer cannot know + // what is held here, and a requested tx may be archived from another peer + // before it arrives. Unknown prevout is not misbehavior, as announcement + // order is not constrained and orphans are not pooled. Locked tx is final + // to a peer one block ahead, as locks are evaluated against presumed next + // block, so neither lock is misbehavior. Rate and suspension cannot be + // advertised below bip133, so a tx violating either is not misbehavior + // (see protocol_transaction_in_70013). Peer cannot know extent of a + // conflict component held here. if (ec && (ec != error::pooling_disabled) && (ec != error::insufficient_fee) && diff --git a/src/protocols/protocol_transaction_in_70013.cpp b/src/protocols/protocol_transaction_in_70013.cpp index 5f378e0f..a87c65e6 100644 --- a/src/protocols/protocol_transaction_in_70013.cpp +++ b/src/protocols/protocol_transaction_in_70013.cpp @@ -34,8 +34,8 @@ BC_PUSH_WARNING(NO_VALUE_OR_CONST_REF_SHARED_PTR) // Submission. // ---------------------------------------------------------------------------- -// bip133: the peer is sent the maximum rate while not current, so any tx then -// is sent against instruction. +// bip133: peer is sent maximum rate while not current, +// so any tx then is sent against instruction. void protocol_transaction_in_70013::do_handle_submit(const code& ec, size_t count, bool whole, const gate_t::ptr& gate) NOEXCEPT { diff --git a/src/protocols/protocol_transaction_out_106.cpp b/src/protocols/protocol_transaction_out_106.cpp index af92d0a2..9dfeb670 100644 --- a/src/protocols/protocol_transaction_out_106.cpp +++ b/src/protocols/protocol_transaction_out_106.cpp @@ -43,8 +43,7 @@ void protocol_transaction_out_106::start() NOEXCEPT if (started()) return; - // A channel with no relay slot is relayed nothing, and stopping has - // already been called for one stopped before its protocols attach. + // No slot implies no relay, stopping already called if stopped at attach. if (!stopped()) reserve_relay(); @@ -55,9 +54,9 @@ void protocol_transaction_out_106::start() NOEXCEPT protocol_peer::start(); } -// The slot is relayed to once the channel is notified of relay. +// Slot is relayed to once channel is notified of relay. void protocol_transaction_out_106::subscribed(const code& ec, - object_key) NOEXCEPT + object_key key) NOEXCEPT { BC_ASSERT(stranded()); @@ -67,7 +66,7 @@ void protocol_transaction_out_106::subscribed(const code& ec, return; } - activate_relay(); + activate_relay(key); } void protocol_transaction_out_106::stopping(const code& ec) NOEXCEPT @@ -241,8 +240,8 @@ void protocol_transaction_out_106::send_transaction(const code& ec, chain::transaction::cptr ptr{}; auto witness = false; - // Drain unservable items, skipping non-tx inventory. The derived protocol - // accumulates them if it reports them, and otherwise stops the channel. + // Drain unservable items, skipping non-tx inventory. Derived protocol + // accumulates them if it reports them, and otherwise stops channel. for (; index < message->items.size(); ++index) { const auto& item = message->items.at(index); @@ -258,9 +257,9 @@ void protocol_transaction_out_106::send_transaction(const code& ec, return; } - // Tx could be always queried with witness and therefore safely cached. - // If can then be serialized according to channel configuration, however - // that is currently fixed to witness as available in the object. + // Tx could always be queried with witness and therefore safely cached. + // It can then be serialized according to channel configuration, however + // that is fixed to witness as available in object. ptr = query.get_transaction(to_transaction(item), witness); if (ptr) break; diff --git a/src/protocols/protocol_transaction_out_70001.cpp b/src/protocols/protocol_transaction_out_70001.cpp index c2c41d03..dfc3885b 100644 --- a/src/protocols/protocol_transaction_out_70001.cpp +++ b/src/protocols/protocol_transaction_out_70001.cpp @@ -49,8 +49,8 @@ bool protocol_transaction_out_70001::handle_unservable( return true; } -// The items are answered and the send loop resumed, as with a transaction, so -// nothing is produced until the prior write completes. +// Items are answered and send loop resumed, as with a transaction, so nothing +// is produced until prior write completes. bool protocol_transaction_out_70001::report_unservable(size_t index, const get_data::cptr& message, const gate_t::ptr& gate) NOEXCEPT { diff --git a/src/protocols/protocol_transaction_out_70013.cpp b/src/protocols/protocol_transaction_out_70013.cpp index 0c5e6a7a..d8548a90 100644 --- a/src/protocols/protocol_transaction_out_70013.cpp +++ b/src/protocols/protocol_transaction_out_70013.cpp @@ -47,7 +47,7 @@ void protocol_transaction_out_70013::start() NOEXCEPT protocol_transaction_out_70001::start(); } -// The peer is told what to send once relay to it is started. +// Peer is told what to send once relay to it starts. void protocol_transaction_out_70013::subscribed(const code& ec, object_key key) NOEXCEPT { @@ -61,8 +61,8 @@ void protocol_transaction_out_70013::subscribed(const code& ec, // Outbound (feefilter). // ---------------------------------------------------------------------------- -// bip133: a relaying channel is sent every tx (coverage decides admission), -// and one with no relay slot, or while not current, is sent nothing. +// bip133: relaying channel is sent every tx (coverage decides admission), and +// one with no relay slot, or while not current, is sent nothing. void protocol_transaction_out_70013::do_send_fee_filter() NOEXCEPT { BC_ASSERT(stranded()); @@ -74,9 +74,10 @@ void protocol_transaction_out_70013::do_send_fee_filter() NOEXCEPT return; sent_fee_ = minimum; + set_silenced(!relaying); NOTIFY(fee_filter{ minimum }, handle_send, _1); - // bip35: the reply follows the zero filter, so it is not filtered. + // bip35: reply follows zero filter, so it is not filtered. // Core drops a mempool sender unless it serves bloom filters or permits // the sender, a restriction outside bip35 (whitelist this node there). if (relaying && !requested_ && request_mempool()) diff --git a/src/sessions/session.cpp b/src/sessions/session.cpp index 5b8cc1bf..561ecc77 100644 --- a/src/sessions/session.cpp +++ b/src/sessions/session.cpp @@ -143,9 +143,9 @@ size_t session::reserve_relay() NOEXCEPT return node_.reserve_relay(relay_tier_()); } -void session::activate_relay(size_t slot) NOEXCEPT +void session::activate_relay(size_t slot, object_key key) NOEXCEPT { - node_.activate_relay(slot); + node_.activate_relay(slot, key); } void session::release_relay(size_t slot) NOEXCEPT diff --git a/src/settings.cpp b/src/settings.cpp index 4345ba39..6f141602 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -36,6 +36,7 @@ settings::transaction_pool::transaction_pool() NOEXCEPT coinbase_sigops{ 400 }, maximum_chunk_depth{ 25 }, estimate_cache_seconds{ 7 }, + estimate_room{ 1'000 }, thread_priority{ true } { } @@ -224,7 +225,7 @@ network::wall_clock::duration settings::currency_window() const NOEXCEPT network::processing_priority settings::thread_priority_() const NOEXCEPT { // medium is "normal" (os default), so true is a behavior change. - // highest is too much, as it makes the opreating system UI unresponsive. + // highest is too much, as it makes operating system UI unresponsive. return thread_priority ? network::processing_priority::high : network::processing_priority::medium; } diff --git a/test/chasers/chaser_confirm.cpp b/test/chasers/chaser_confirm.cpp index 13ffeb60..87baaf51 100644 --- a/test/chasers/chaser_confirm.cpp +++ b/test/chasers/chaser_confirm.cpp @@ -368,7 +368,8 @@ class chase_recorder { public: template - using payload_t = std::remove_cvref_t(std::declval()))>; + using payload_t = std::remove_cvref_t( + std::declval()))>; bool subscribe(full_node& node) { @@ -384,18 +385,25 @@ class chase_recorder subscribed->set_value(); }); - return subscription.wait_for(std::chrono::seconds(10)) == std::future_status::ready; + const auto status = subscription.wait_for(std::chrono::seconds(10)); + return status == std::future_status::ready; } size_t count(chase kind) const { std::lock_guard lock{ mutex_ }; - return std::count_if(events_.cbegin(), events_.cend(), [kind](const auto& value) NOEXCEPT { return to_chase(value) == kind; }); + const auto is_kind = [kind](const auto& value) NOEXCEPT + { + return to_chase(value) == kind; + }; + + return std::count_if(events_.cbegin(), events_.cend(), is_kind); } bool await(chase kind, size_t number=1) const { - const auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(10); + const auto timeout = std::chrono::seconds(10); + const auto deadline = std::chrono::steady_clock::now() + timeout; while (count(kind) < number) { if (std::chrono::steady_clock::now() > deadline) @@ -434,8 +442,8 @@ class chase_recorder std::vector events_{}; }; -// Counts top latency events fired before the unknown event (sentinel). -// Every unsubscription (sentinel or stop code) completes the wait. +// Counts top latency events fired before unknown event (sentinel). +// Every unsubscription (sentinel or stop code) completes wait. class top_recorder { public: @@ -510,7 +518,6 @@ struct confirm_setup_fixture if (configurer) configurer(config); - // The store envelope is derived from the configured chain. config.database.initialize(config.bitcoin, config.node.limited_blocks, config.node.provide_filters, config.node.require_witness, config.node.silent_start_height); @@ -604,7 +611,9 @@ struct confirm_setup_fixture { std::promise posted{}; network::io::post(strand, [&]() NOEXCEPT { posted.set_value(); }); - BC_REQUIRE(posted.get_future().wait_for(std::chrono::seconds(10)) == std::future_status::ready); + auto completion = posted.get_future(); + const auto status = completion.wait_for(std::chrono::seconds(10)); + BC_REQUIRE(status == std::future_status::ready); } /// Complete event dispatch and the chaser work it posted. diff --git a/test/chasers/chaser_header.cpp b/test/chasers/chaser_header.cpp index cea7f6b0..de71f9cf 100644 --- a/test/chasers/chaser_header.cpp +++ b/test/chasers/chaser_header.cpp @@ -71,7 +71,8 @@ static uint256_t work(size_t count) static uint32_t now() { - return system::possible_narrow_and_sign_cast(network::zulu_time()); + const auto zulu = network::zulu_time(); + return system::possible_narrow_and_sign_cast(zulu); } // A node that runs its network without starting its own chasers. @@ -240,7 +241,6 @@ struct chaser_header_setup_fixture if (configure) configure(config); - // The store envelope is derived from the configured chain. config.database.initialize(config.bitcoin, config.node.limited_blocks, config.node.provide_filters, config.node.require_witness, config.node.silent_start_height); @@ -298,10 +298,12 @@ struct chaser_header_setup_fixture { const auto promise = std::make_shared>(); auto future = promise->get_future(); - header_.prioritize(hash, [promise](const code& ec, size_t height) NOEXCEPT + const auto handler = [promise](const code& ec, size_t height) NOEXCEPT { promise->set_value({ ec, height }); - }); + }; + + header_.prioritize(hash, handler); BC_REQUIRE(future.wait_for(await_limit) == std::future_status::ready); return future.get(); @@ -312,10 +314,12 @@ struct chaser_header_setup_fixture { const auto promise = std::make_shared>(); auto future = promise->get_future(); - header_.get_minimum_work([promise](const code&, const uint256_t&) NOEXCEPT + const auto handler = [promise](const code&, const uint256_t&) NOEXCEPT { promise->set_value(); - }); + }; + + header_.get_minimum_work(handler); BC_REQUIRE(future.wait_for(await_limit) == std::future_status::ready); } diff --git a/test/chasers/chaser_template.cpp b/test/chasers/chaser_template.cpp index 585dd2f9..37c5c6b1 100644 --- a/test/chasers/chaser_template.cpp +++ b/test/chasers/chaser_template.cpp @@ -110,7 +110,8 @@ struct chaser_template_setup_fixture using deployment = chain::chain_state::deployment; config.network.enable_relay = true; config.node.currency_window_minutes = 0; - config.bitcoin.bip9_bit0_deployment.start = deployment::always_active; + constexpr auto always = deployment::always_active; + config.bitcoin.bip9_bit0_deployment.start = always; }) { subscribe(); diff --git a/test/chasers/chaser_transaction.cpp b/test/chasers/chaser_transaction.cpp index 09c92419..4cca8500 100644 --- a/test/chasers/chaser_transaction.cpp +++ b/test/chasers/chaser_transaction.cpp @@ -327,8 +327,8 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__reorganized__spender_of_unpooled_parent BC_REQUIRE(restored); } -// The spender is pooled again after its parent, which is admitted and not -// confirmed, and its context is swept before it is revalidated. +// Spender pooled again after parent (admitted, not confirmed), +// its context swept before revalidation. BC_FIXTURE_TEST_CASE(chaser_transaction__reorganized__parent_submitted__spender_swept_then_revalidated, chaser_transaction_single_setup_fixture) { const auto first = spend(parent_value - 1'000); @@ -471,40 +471,48 @@ struct scan_stale_fixture } }; +static bool stored_scan_complete(node::query& query) NOEXCEPT +{ + return stored_scan(query) + && query.set_scan_start(0, 42) + && query.set_scan_start(1, 43); +} + struct scan_complete_fixture : chaser_transaction_scan_setup_fixture { inline scan_complete_fixture() - : chaser_transaction_scan_setup_fixture(false, true, [](node::query& query) - { - return stored_scan(query) - && query.set_scan_start(0, 42) - && query.set_scan_start(1, 43); - }) + : chaser_transaction_scan_setup_fixture(false, true, + stored_scan_complete) { } }; +static bool stored_scan_partial(node::query& query) NOEXCEPT +{ + return stored_scan(query) && query.set_scan_start(1, 43); +} + struct scan_partial_fixture : chaser_transaction_scan_setup_fixture { inline scan_partial_fixture() - : chaser_transaction_scan_setup_fixture(false, true, [](node::query& query) - { - return stored_scan(query) && query.set_scan_start(1, 43); - }) + : chaser_transaction_scan_setup_fixture(false, true, stored_scan_partial) { } }; +static bool stored_scan_unextended(node::query& query) NOEXCEPT +{ + return stored_scan(query) && query.set_scan_start(0, 0); +} + struct scan_unextended_fixture : chaser_transaction_scan_setup_fixture { inline scan_unextended_fixture() - : chaser_transaction_scan_setup_fixture(false, true, [](node::query& query) - { - return stored_scan(query) && query.set_scan_start(0, 0); - }) + : chaser_transaction_scan_setup_fixture(false, true, + stored_scan_unextended) { } }; diff --git a/test/chasers/chaser_transaction_query.cpp b/test/chasers/chaser_transaction_query.cpp index 23146c4c..6e556c98 100644 --- a/test/chasers/chaser_transaction_query.cpp +++ b/test/chasers/chaser_transaction_query.cpp @@ -217,6 +217,15 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__estimate__full_block__above_lowest_take BC_REQUIRE_EQUAL(rate, 16'394u); } +BC_FIXTURE_TEST_CASE(chaser_transaction__estimate__full_block_without_room__estimate_false, chaser_transaction_room_setup_fixture) +{ + const auto first = spend(parent_value - 1'000); + const auto second = spend(first->hash(false), parent_value - 3'000); + const auto result = submit(package({ first, second })); + BC_REQUIRE_EQUAL(result.first, node::error::success); + BC_REQUIRE_EQUAL(estimate(0).first, node::error::estimate_false); +} + BC_FIXTURE_TEST_CASE(chaser_transaction__estimate__open_block__zero, chaser_transaction_single_setup_fixture) { const auto first = spend(parent_value - 1'000); diff --git a/test/chasers/chaser_transaction_relay.cpp b/test/chasers/chaser_transaction_relay.cpp index 08c9299f..339ead9a 100644 --- a/test/chasers/chaser_transaction_relay.cpp +++ b/test/chasers/chaser_transaction_relay.cpp @@ -135,8 +135,8 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__relay__below_rate__not_relayed, chaser_ BC_REQUIRE(recorded(events).empty()); } -// The parent (1,000 satoshis on 60 vbytes) is below the rate, the child -// (20,000) clears it with the parent. +// Parent (1,000 satoshis on 60 vbytes) below rate, +// child (20,000) clears it with parent. BC_FIXTURE_TEST_CASE(chaser_transaction__relay__child_pays_for_parent__both_in_order, chaser_transaction_pooling_setup_fixture) { const auto low = spend(parent_value - 1'000); @@ -234,7 +234,7 @@ BC_FIXTURE_TEST_CASE(chaser_transaction__relay_pool__slot_not_started__swept_whe BC_REQUIRE(recorded(owed).empty()); const auto started = record(); - node_.activate_relay(slot); + node_.activate_relay(slot, relays_->key); BC_REQUIRE(!get_confirmable_txs().first); BC_REQUIRE(recorded(started) == expected); } diff --git a/test/chasers/chaser_transaction_setup_fixture.hpp b/test/chasers/chaser_transaction_setup_fixture.hpp index a2415cc4..f7e694ef 100644 --- a/test/chasers/chaser_transaction_setup_fixture.hpp +++ b/test/chasers/chaser_transaction_setup_fixture.hpp @@ -23,6 +23,7 @@ #include "../functional/p2p_setup_fixture.hpp" #include #include +#include #include using namespace system; @@ -33,7 +34,8 @@ constexpr uint64_t parent_value = 100'000; const hash_digest missing_hash{ 0x42 }; // The flags of the bip9 bit zero deployment. -constexpr auto deployed = chain::flags::bip68_rule | chain::flags::bip112_rule | chain::flags::bip113_rule; +constexpr auto deployed = chain::flags::bip68_rule | chain::flags::bip112_rule + | chain::flags::bip113_rule; // A tx with an anyone-can-spend output. inline const chain::transaction& parent() NOEXCEPT @@ -204,12 +206,22 @@ inline const chain::block& reorganized_block() NOEXCEPT const system::settings bitcoin{ chain::selection::mainnet }; const auto& genesis = bitcoin.genesis_block.header(); const chain::input null{ chain::point{}, chain::script{}, max_uint32 }; - const chain::transaction coinbase{ 1u, chain::inputs{ null }, - chain::outputs{ { 42u, chain::script{} } }, 0u }; - const chain::header header{ 1u, genesis.hash(), null_hash, - add1(genesis.timestamp()), genesis.bits(), 0u }; - static const chain::block instance{ header, - { coinbase, *spend(parent_value) } }; + const chain::transaction coinbase + { + 1u, + chain::inputs{ null }, + chain::outputs{ { 42u, chain::script{} } }, + 0u + }; + const chain::header header + { + 1u, genesis.hash(), null_hash, add1(genesis.timestamp()), + genesis.bits(), 0u + }; + static const chain::block instance + { + header, { coinbase, *spend(parent_value) } + }; return instance; } @@ -246,7 +258,8 @@ struct chaser_transaction_setup_fixture : p2p_setup_fixture(setup, [=](configuration& config) { using deployment = chain::chain_state::deployment; - config.bitcoin.bip9_bit0_deployment.start = deployment::always_active; + constexpr auto always = deployment::always_active; + config.bitcoin.bip9_bit0_deployment.start = always; if (configure) configure(config); }) @@ -279,8 +292,9 @@ struct chaser_transaction_setup_fixture // Reserve a relay slot of the tier and start relay to it. size_t reserve_relaying(node::relay_tier tier=node::relay_tier::manual) { + recording(); const auto slot = node_.reserve_relay(tier); - node_.activate_relay(slot); + node_.activate_relay(slot, relays_->key); return slot; } @@ -294,15 +308,21 @@ struct chaser_transaction_setup_fixture return count; } - // Relay events recorded from subscription until the zero word marker. + // Relay events of fixture subscription, zero word marker completes wait. struct relays { + std::mutex mutex{}; std::vector events{}; - std::promise ended{}; + std::shared_ptr> marked{}; + object_key key{}; }; - std::shared_ptr record() + // Subscribe recorder (once). + void recording() { + if (relays_) + return; + const auto out = std::make_shared(); std::promise subscribed{}; node_.subscribe_chase([out](const code&, event_value value) NOEXCEPT @@ -311,33 +331,57 @@ struct chaser_transaction_setup_fixture return true; const auto& relay = to_payload(value); - if (is_zero(relay.slots)) + std::unique_lock lock{ out->mutex }; + if (is_nonzero(relay.slots)) { - out->ended.set_value(); - return false; + out->events.push_back(relay); + return true; } - out->events.push_back(relay); + if (out->marked) + out->marked->set_value(); + + out->marked.reset(); return true; - }, [&](const code&, object_key) NOEXCEPT + }, [&](const code&, object_key key) NOEXCEPT { + out->key = key; subscribed.set_value(); }); subscribed.get_future().wait(); - return out; + relays_ = out; } - // The recorded relay events as tx hash and slots, ending the record. - using relayed = std::vector>; - relayed recorded(const std::shared_ptr& record) + // Count of relay events recorded, once those notified have arrived. + size_t record() { + recording(); + const auto marked = std::make_shared>(); + auto arrived = marked->get_future(); + { + std::unique_lock lock{ relays_->mutex }; + relays_->marked = marked; + } + node_.notify(node::error::success, chases::relay{ 0, 0 }); - record->ended.get_future().wait(); + arrived.wait(); + std::unique_lock lock{ relays_->mutex }; + return relays_->events.size(); + } + // Relay events since record, as tx hash and slots. + using relayed = std::vector>; + relayed recorded(size_t from) + { + const auto to = record(); relayed out{}; - for (const auto& event: record->events) + std::unique_lock lock{ relays_->mutex }; + for (auto at = from; at < to; ++at) + { + const auto& event = relays_->events.at(at); out.emplace_back(query_.get_tx_key(event.link), event.slots); + } return out; } @@ -597,8 +641,8 @@ struct chaser_transaction_setup_fixture std::vector values{}; }; - // The state is shared, as the subscription may outlive the call. - // Every unsubscription (sentinel or stop code) completes the wait. + // State shared, as subscription may outlive call. + // Every unsubscription (sentinel or stop code) completes wait. const auto shared = std::make_shared(); auto done = shared->done.get_future(); log_.subscribe_events([=](const code& ec, uint8_t event_, @@ -630,6 +674,8 @@ struct chaser_transaction_setup_fixture return shared->values; } + std::shared_ptr relays_{}; + // The pool cell of the tx (absent if it has no row). uint32_t cell(const database::tx_link& link) { @@ -669,8 +715,7 @@ struct chaser_transaction_setup_fixture } } - // The payload of the command if received before the pong of a subsequent - // ping, otherwise empty. + // Payload of command if received before pong of next ping, else empty. data_chunk receive_before_pong(const std::string& command) { send(peer::ping{ 42 }, node_version->value); @@ -863,6 +908,23 @@ struct chaser_transaction_single_setup_fixture config.network.enable_relay = true; config.node.currency_window_minutes = 0; config.node.pool.coinbase_weight = 3'999'348; + config.node.pool.estimate_room = 1; + }) + { + } +}; + +// Block holds one test tx, estimate requires room for two. +struct chaser_transaction_room_setup_fixture + : chaser_transaction_setup_fixture +{ + inline chaser_transaction_room_setup_fixture() + : chaser_transaction_setup_fixture([](configuration& config) + { + config.network.enable_relay = true; + config.node.currency_window_minutes = 0; + config.node.pool.coinbase_weight = 3'999'348; + config.node.pool.estimate_room = 122; }) { } @@ -878,6 +940,7 @@ struct chaser_transaction_held_setup_fixture config.network.enable_relay = true; config.node.currency_window_minutes = 0; config.node.pool.coinbase_weight = 3'999'348; + config.node.pool.estimate_room = 1; config.node.pool.estimate_cache_seconds = max_uint16; }) { @@ -894,6 +957,7 @@ struct chaser_transaction_live_setup_fixture config.network.enable_relay = true; config.node.currency_window_minutes = 0; config.node.pool.coinbase_weight = 3'999'348; + config.node.pool.estimate_room = 1; config.node.pool.estimate_cache_seconds = 0; }) { @@ -922,7 +986,8 @@ struct chaser_transaction_relative_setup_fixture { config.network.enable_relay = true; config.node.currency_window_minutes = 0; - constexpr auto always = chain::chain_state::deployment::always_active; + using deployment = chain::chain_state::deployment; + constexpr auto always = deployment::always_active; config.bitcoin.bip9_bit0_deployment.start = always; }) { diff --git a/test/chasers/chaser_validate.cpp b/test/chasers/chaser_validate.cpp index ca70db16..307a9940 100644 --- a/test/chasers/chaser_validate.cpp +++ b/test/chasers/chaser_validate.cpp @@ -424,7 +424,6 @@ struct validate_setup_fixture system::batched::accelerate(config.node.use_gpu); - // The store envelope is derived from the configured chain. config.database.initialize(config.bitcoin, config.node.limited_blocks, config.node.provide_filters, config.node.require_witness, config.node.silent_start_height); @@ -677,30 +676,35 @@ struct validate_current_overspent_fixture } }; +static void validate_captured(configuration& config) +{ + config.bitcoin.checkpoints.clear(); + config.node.batch_verify = 1; + config.node.cpu_batch_verify = true; + validate_silent_batched(config); +} + struct validate_captured_fixture : validate_setup_fixture { validate_captured_fixture() - : validate_setup_fixture(validate_matured_candidates, [](configuration& config) - { - config.bitcoin.checkpoints.clear(); - config.node.batch_verify = 1; - config.node.cpu_batch_verify = true; - validate_silent_batched(config); - }) + : validate_setup_fixture(validate_matured_candidates, validate_captured) { } }; +static void validate_silent_bypass(configuration& config) +{ + validate_silent_batched(config); + config.node.maximum_height = 2; +} + struct validate_silent_bypass_fixture : validate_setup_fixture { validate_silent_bypass_fixture() - : validate_setup_fixture(validate_silent_candidates, [](configuration& config) - { - validate_silent_batched(config); - config.node.maximum_height = 2; - }) + : validate_setup_fixture(validate_silent_candidates, + validate_silent_bypass) { } }; @@ -721,8 +725,8 @@ struct validate_noncandidates_fixture } }; -// Commits a prevalid to the admitting bank and loses the drain claim during -// the first drain, as a completing validation does. +// Commits prevalid to admitting bank, loses drain claim during first drain, +// as completing validation does. struct validate_drain_accessor : chaser_validate { diff --git a/test/error.cpp b/test/error.cpp index 16113013..b4e6a0d9 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -21,7 +21,7 @@ BC_AUTO_TEST_SUITE(error_tests) // error_t -// These test std::error_code equality operator overrides. +// Test std::error_code equality operator overrides. // general diff --git a/test/functional/p2p.cpp b/test/functional/p2p.cpp index f8cd8591..e68e9945 100644 --- a/test/functional/p2p.cpp +++ b/test/functional/p2p.cpp @@ -189,8 +189,8 @@ struct p2p_regtest_sampled_setup_fixture } }; -// A node with compact blocks enabled and blocks 1 and 2 as unassociated -// candidates, not current. +// Node with compact blocks enabled, +// blocks 1 and 2 unassociated candidates, not current. struct p2p_compact_not_current_setup_fixture : p2p_setup_fixture { diff --git a/test/functional/p2p_compact.cpp b/test/functional/p2p_compact.cpp index 62ee445e..b5515384 100644 --- a/test/functional/p2p_compact.cpp +++ b/test/functional/p2p_compact.cpp @@ -325,9 +325,9 @@ BC_AUTO_TEST_CASE(functional_p2p_compact__compact_block__short_id_mismatch__stop BC_REQUIRE(dropped(pong::command)); } -// An unidentified fill leaves evidence, resolved against the archived block. -// Block 2 remains an unassociated candidate, so the chain never coalesces -// (which would prune the store, suspending the network). +// Unidentified fill leaves evidence, resolved against archived block. +// Block 2 remains unassociated candidate, so chain never coalesces +// (which would prune store, suspending network). BC_FIXTURE_TEST_CASE(functional_p2p_compact__compact_block__unidentified_then_archived__stopped, p2p_compact_candidate_setup_fixture) { BC_REQUIRE(handshake(full_node)); diff --git a/test/functional/p2p_setup_fixture.cpp b/test/functional/p2p_setup_fixture.cpp index d6a8039d..76c918d1 100644 --- a/test/functional/p2p_setup_fixture.cpp +++ b/test/functional/p2p_setup_fixture.cpp @@ -26,8 +26,6 @@ using namespace bc::network::messages::peer; BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) -// The store and the chasers copy settings at construction, so configuration -// precedes them. configuration p2p_setup_fixture::configured(const configurator& configure) { configuration config{ test::node_configuration() }; @@ -54,7 +52,6 @@ configuration p2p_setup_fixture::configured(const configurator& configure) if (configure) configure(config); - // Derived values are computed from the configuration, as at startup. config.database.initialize(config.bitcoin, node_settings.limited_blocks, node_settings.provide_filters, node_settings.require_witness, node_settings.silent_start_height); @@ -121,8 +118,9 @@ void p2p_setup_fixture::send(const std::string& command, const auto head = heading::factory(config_.network.identifier, command, payload); data_chunk frame(heading::size() + payload.size()); - BC_REQUIRE(head.serialize({ frame.data(), - std::next(frame.data(), heading::size()) })); + const auto begin = frame.data(); + const auto end = std::next(begin, heading::size()); + BC_REQUIRE(head.serialize({ begin, end })); std::copy(payload.begin(), payload.end(), std::next(frame.begin(), heading::size())); @@ -164,8 +162,8 @@ object_key p2p_setup_fixture::subscribe() return subscribed.get_future().get(); } -// The state is shared, as the subscription may outlive the call. Either end -// of the subscription (the event or a stop code) completes the wait. +// State shared, as subscription may outlive call. Either end of subscription +// (event or stop code) completes wait. uint64_t p2p_setup_fixture::fired_value(uint8_t event, const std::function& act) { diff --git a/test/functional/p2p_setup_fixture.hpp b/test/functional/p2p_setup_fixture.hpp index 3afa0aa9..7db6261c 100644 --- a/test/functional/p2p_setup_fixture.hpp +++ b/test/functional/p2p_setup_fixture.hpp @@ -58,8 +58,8 @@ class bound_node network::acceptor::ptr acceptor_{}; }; -// Runs a real full node accepting on loopback, with the test acting as the -// remote peer over a raw blocking socket (framing via peer messages). +// Runs real full node accepting on loopback, test acting as remote peer over +// raw blocking socket (framing via peer messages). struct p2p_setup_fixture { DELETE_COPY_MOVE(p2p_setup_fixture); @@ -91,8 +91,7 @@ struct p2p_setup_fixture /// Read framed messages until the command (true) or the terminal. bool received(const std::string& command, const std::string& terminal); - /// Read framed messages, true if the node drops the connection before - /// sending the command. + /// Read framed messages, true if node drops connection before command sent. bool dropped(const std::string& command); /// Perform the version handshake, retains the node's version message. @@ -233,9 +232,9 @@ struct p2p_limited_setup_fixture } }; -// A header is archived before its block is associated, so the header link -// resolves while the block remains absent from the archive. This is the -// steady state of headers-first synchronization. +// Header archived before its block is associated, so header link resolves +// while block remains absent from archive. +// Steady state of headers-first synchronization. struct p2p_unassociated_setup_fixture : p2p_setup_fixture { @@ -253,9 +252,9 @@ struct p2p_unassociated_setup_fixture } }; -// A node with compact blocks enabled and a chain that is always current. -// A candidate above the confirmed top precludes the store prune, which -// suspends the network (dropping the test peer) when the chain coalesces. +// Node with compact blocks enabled and chain always current. Candidate above +// confirmed top precludes store prune, which suspends network (dropping test +// peer) when chain coalesces. struct p2p_compact_setup_fixture : p2p_setup_fixture { @@ -271,7 +270,8 @@ struct p2p_compact_setup_fixture : p2p_setup_fixture(setup, [=](configuration& config) { using deployment = system::chain::chain_state::deployment; - config.bitcoin.bip9_bit0_deployment.start = deployment::always_active; + constexpr auto always = deployment::always_active; + config.bitcoin.bip9_bit0_deployment.start = always; config.network.enable_relay = relay; config.network.enable_compact = true; config.node.currency_window_minutes = currency_window; diff --git a/test/protocols/protocol.cpp b/test/protocols/protocol.cpp index 19068817..cd3cdac5 100644 --- a/test/protocols/protocol.cpp +++ b/test/protocols/protocol.cpp @@ -34,11 +34,12 @@ static chain::header descendant(uint32_t timestamp) // Unfiltered children of genesis, each archived at the height of its timestamp. static bool unfiltered(node::query& query) { - return query.set(descendant(1), database::context{ 0, 1, 0 }, {}, false) && - query.set(descendant(999), database::context{ 0, 999, 0 }, {}, false) && - query.set(descendant(1000), database::context{ 0, 1000, 0 }, {}, false) && - query.set(descendant(1999), database::context{ 0, 1999, 0 }, {}, false) && - query.set(descendant(2000), database::context{ 0, 2000, 0 }, {}, false); + using context = database::context; + return query.set(descendant(1), context{ 0, 1, 0 }, {}, false) + && query.set(descendant(999), context{ 0, 999, 0 }, {}, false) + && query.set(descendant(1000), context{ 0, 1000, 0 }, {}, false) + && query.set(descendant(1999), context{ 0, 1999, 0 }, {}, false) + && query.set(descendant(2000), context{ 0, 2000, 0 }, {}, false); } // Block 1 confirmed, with block 2 a candidate header above it. diff --git a/test/protocols/protocol_transaction.cpp b/test/protocols/protocol_transaction.cpp index 2cf552ce..cf1dfa38 100644 --- a/test/protocols/protocol_transaction.cpp +++ b/test/protocols/protocol_transaction.cpp @@ -521,6 +521,16 @@ BC_FIXTURE_TEST_CASE(protocol_transaction_out__start__no_relay_slot__max_money_f BC_REQUIRE_EQUAL(message->minimum_fee, config_.bitcoin.max_money()); } +BC_FIXTURE_TEST_CASE(protocol_transaction_in__inventory__no_relay_slot__no_get_data, chaser_transaction_pooling_setup_fixture) +{ + reserve_relays(); + BC_REQUIRE(handshake(0, peer::level::maximum_protocol, true)); + BC_REQUIRE(!receive(peer::fee_filter::command).empty()); + + send(peer::inventory{ { { type_id::transaction, spend(parent_value)->hash(false) } } }, node_version->value); + BC_REQUIRE(!received_before_pong(peer::get_data::command)); +} + BC_FIXTURE_TEST_CASE(protocol_transaction_out__submit__announced_by_peer__not_announced, chaser_transaction_pooling_setup_fixture) { BC_REQUIRE(handshake(0, peer::level::maximum_protocol, true)); diff --git a/test/sessions/session.cpp b/test/sessions/session.cpp index a14cece5..116800bc 100644 --- a/test/sessions/session.cpp +++ b/test/sessions/session.cpp @@ -256,7 +256,8 @@ struct session_broadcast_setup_fixture }; // The race completes upon release of the last message reference. - broadcaster->broadcast(std::make_shared(std::make_shared(handler), collect, group), 0); + broadcaster->broadcast(std::make_shared( + std::make_shared(handler), collect, group), 0); return promise.get_future().get(); } diff --git a/test/settings.cpp b/test/settings.cpp index 509039d4..5768f6e4 100644 --- a/test/settings.cpp +++ b/test/settings.cpp @@ -218,6 +218,7 @@ BC_AUTO_TEST_CASE(settings__pool__default__expected) BC_REQUIRE_EQUAL(pool.coinbase_sigops, 400_u32); BC_REQUIRE_EQUAL(pool.maximum_chunk_depth, 25_u32); BC_REQUIRE_EQUAL(pool.estimate_cache_seconds, 7_u16); + BC_REQUIRE_EQUAL(pool.estimate_room, 1'000_u32); BC_REQUIRE(pool.estimate_cache() == steady_clock::duration(seconds(7))); BC_REQUIRE(pool.thread_priority); BC_REQUIRE(pool.thread_priority_() == network::processing_priority::high); diff --git a/test/test.hpp b/test/test.hpp index 95a983dd..3a71a32f 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -136,7 +136,8 @@ inline size_t read(Stream& stream, const Buffers& buffers) NOEXCEPT // A loopback endpoint (an ephemeral port by default). inline network::io::endpoint loopback(uint16_t port=0) NOEXCEPT { - return { system::ip::address{ system::ip::ipv4{ { 127, 0, 0, 1 } } }, port }; + const system::ip::address address{ system::ip::ipv4{ { 127, 0, 0, 1 } } }; + return { address, port }; } // A loopback endpoint on an ephemeral port with no socket bound to it.