Skip to content

Commit

Permalink
Merge pull request #608 from evoskuil/master
Browse files Browse the repository at this point in the history
Change event subscription model.
  • Loading branch information
evoskuil committed May 8, 2024
2 parents 94d6c6e + 4ddb84f commit 73f8b71
Show file tree
Hide file tree
Showing 30 changed files with 407 additions and 230 deletions.
40 changes: 16 additions & 24 deletions console/executor.cpp
Expand Up @@ -55,40 +55,43 @@ const std::unordered_map<uint8_t, bool> executor::defined_
{
{ levels::application, true },
{ levels::news, levels::news_defined },
{ levels::objects, levels::objects_defined },
{ levels::session, levels::session_defined },
{ levels::protocol, levels::protocol_defined },
{ levels::proxy, levels::proxy_defined },
{ levels::wire, levels::wire_defined },
{ levels::remote, levels::remote_defined },
{ levels::fault, levels::fault_defined },
{ levels::quit, levels::quit_defined }
{ levels::quit, levels::quit_defined },
{ levels::objects, levels::objects_defined },
{ levels::verbose, levels::verbose_defined },
};
const std::unordered_map<uint8_t, std::string> executor::display_
{
{ levels::application, "toggle Application" },
{ levels::news, "toggle News" },
{ levels::objects, "toggle Objects" },
{ levels::session, "toggle Session" },
{ levels::protocol, "toggle Protocol" },
{ levels::proxy, "toggle proXy" },
{ levels::wire, "toggle Wire shark" }, // not implemented
{ levels::remote, "toggle Remote fault" },
{ levels::fault, "toggle internal Fault" },
{ levels::quit, "toggle Quitting" }
{ levels::wire, "toggle Wire" }, // unused
{ levels::remote, "toggle Remote" },
{ levels::fault, "toggle Fault" },
{ levels::quit, "toggle Quitting" },
{ levels::objects, "toggle Objects" },
{ levels::verbose, "toggle Verbose" }
};
const std::unordered_map<std::string, uint8_t> executor::keys_
{
{ "a", levels::application },
{ "n", levels::news },
{ "o", levels::objects },
{ "s", levels::session },
{ "p", levels::protocol },
{ "x", levels::proxy },
{ "w", levels::wire },
{ "r", levels::remote },
{ "f", levels::fault },
{ "q", levels::quit }
{ "q", levels::quit },
{ "o", levels::objects },
{ "v", levels::verbose }
};
const std::unordered_map<uint8_t, std::string> executor::fired_
{
Expand Down Expand Up @@ -332,7 +335,7 @@ void executor::measure_size() const
query_.get_top_candidate() %
encode_hash(query_.get_header_key(query_.to_candidate(query_.get_top_candidate()))) %
query_.get_top_associated() %
query_.get_unassociated_count() %
(query_.get_top_candidate() - query_.get_unassociated_count()) %
query_.get_confirmed_size() %
query_.get_candidate_size());

Expand Down Expand Up @@ -1895,7 +1898,7 @@ bool executor::do_initchain()
query_.get_top_candidate() %
encode_hash(query_.get_header_key(query_.to_candidate(query_.get_top_candidate()))) %
query_.get_top_associated() %
query_.get_unassociated_count() %
(query_.get_top_candidate() - query_.get_unassociated_count()) %
query_.get_confirmed_size() %
query_.get_candidate_size());

Expand Down Expand Up @@ -2404,16 +2407,6 @@ void executor::subscribe_capture()
});
}

// TODO: these are not the same as log events, rename one of them.
void executor::subscribe_events()
{
// This is synchronous and requires the strand.
// TODO: make protected and create public asynchronous subscribe_events.
////node_->subscribe_events([&](const code&, node::chase, node::event_link)
////{
////});
}

void executor::subscribe_connect()
{
node_->subscribe_connect([&](const code&, const channel::ptr&)
Expand Down Expand Up @@ -2573,7 +2566,7 @@ bool executor::do_run()
query_.get_top_candidate() %
encode_hash(query_.get_header_key(query_.to_candidate(query_.get_top_candidate()))) %
query_.get_top_associated() %
query_.get_unassociated_count() %
(query_.get_top_candidate() - query_.get_unassociated_count()) %
query_.get_confirmed_size() %
query_.get_candidate_size());

Expand All @@ -2582,7 +2575,6 @@ bool executor::do_run()
node_ = std::make_shared<full_node>(query_, metadata_.configured, log_);

// Subscribe node.
subscribe_events();
subscribe_connect();
subscribe_close();

Expand Down Expand Up @@ -2634,7 +2626,7 @@ bool executor::do_run()
query_.get_top_candidate() %
encode_hash(query_.get_header_key(query_.to_candidate(query_.get_top_candidate()))) %
query_.get_top_associated() %
query_.get_unassociated_count() %
(query_.get_top_candidate() - query_.get_unassociated_count()) %
query_.get_confirmed_size() %
query_.get_candidate_size());

Expand Down
9 changes: 4 additions & 5 deletions console/executor.hpp
Expand Up @@ -74,7 +74,6 @@ class executor
void subscribe_log(std::ostream& sink);
void subscribe_events(std::ostream& sink);
void subscribe_capture();
void subscribe_events();
void subscribe_connect();
void subscribe_close();

Expand All @@ -99,7 +98,6 @@ class executor
static const std::unordered_map<uint8_t, std::string> fired_;
static const std::unordered_map<database::event_t, std::string> events_;
static const std::unordered_map<database::table_t, std::string> tables_;
static constexpr size_t logs = add1(network::levels::quit);
static std::promise<system::code> stopping_;
static std::atomic_bool cancel_;

Expand All @@ -113,18 +111,19 @@ class executor
std::ostream& output_;
network::logger log_{};
network::capture capture_{ input_, close_ };
std_array<std::atomic_bool, logs> toggle_
std_array<std::atomic_bool, add1(network::levels::verbose)> toggle_
{
true, // application
network::levels::news_defined,
false, //network::levels::objects_defined,
network::levels::session_defined,
false, //network::levels::protocol_defined,
false, //network::levels::proxy_defined,
false, //network::levels::wire_defined,
network::levels::remote_defined,
network::levels::fault_defined,
false // network::levels::quit_defined
false, // network::levels::quit_defined
false, //network::levels::objects_defined,
false //network::levels::verbose_defined
};
};

Expand Down
108 changes: 54 additions & 54 deletions console/localize.hpp
Expand Up @@ -70,74 +70,74 @@ namespace node {
// --measure
#define BN_MEASURE_SIZES \
"Body sizes...\n" \
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" input :%5%\n" \
" output :%6%\n" \
" puts :%7%\n" \
" candidate:%8%\n" \
" confirmed:%9%\n" \
" spend :%10%\n" \
" strong_tx:%11%\n" \
" valid_tx :%12%\n" \
" valid_bk :%13%\n" \
" address :%14%\n" \
" neutrino :%15%"
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" input :%5%\n" \
" output :%6%\n" \
" puts :%7%\n" \
" candidate :%8%\n" \
" confirmed :%9%\n" \
" spend :%10%\n" \
" strong_tx :%11%\n" \
" valid_tx :%12%\n" \
" valid_bk :%13%\n" \
" address :%14%\n" \
" neutrino :%15%"
#define BN_MEASURE_RECORDS \
"Table records...\n" \
" header :%1%\n" \
" tx :%2%\n" \
" point :%3%\n" \
" candidate:%4%\n" \
" confirmed:%5%\n" \
" spend :%6%\n" \
" strong_tx:%7%\n" \
" address :%8%"
" header :%1%\n" \
" tx :%2%\n" \
" point :%3%\n" \
" candidate :%4%\n" \
" confirmed :%5%\n" \
" spend :%6%\n" \
" strong_tx :%7%\n" \
" address :%8%"
#define BN_MEASURE_SLABS \
"Table slabs..."
#define BN_MEASURE_SLABS_ROW \
" @tx :%1%, inputs:%2%, outputs:%3%"
" @tx :%1%, inputs:%2%, outputs:%3%"
#define BN_MEASURE_STOP \
" input :%1%\n" \
" output :%2%\n" \
" seconds :%3%"
" input :%1%\n" \
" output :%2%\n" \
" seconds :%3%"
#define BN_MEASURE_BUCKETS \
"Head buckets...\n" \
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" spend :%5%\n" \
" strong_tx:%6%\n" \
" valid_tx :%7%\n" \
" valid_bk :%8%\n" \
" address :%9%\n" \
" neutrino :%10%"
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" spend :%5%\n" \
" strong_tx :%6%\n" \
" valid_tx :%7%\n" \
" valid_bk :%8%\n" \
" address :%9%\n" \
" neutrino :%10%"
#define BN_MEASURE_COLLISION_RATES \
"Collision rates...\n" \
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" spend :%5%\n" \
" strong_tx:%6%\n" \
" valid_tx :%7%\n" \
" valid_bk :%8%\n" \
" address :%9%\n" \
" neutrino :%10%"
" header :%1%\n" \
" txs :%2%\n" \
" tx :%3%\n" \
" point :%4%\n" \
" spend :%5%\n" \
" strong_tx :%6%\n" \
" valid_tx :%7%\n" \
" valid_bk :%8%\n" \
" address :%9%\n" \
" neutrino :%10%"
#define BN_MEASURE_PROGRESS_START \
"Thinking..."
#define BN_MEASURE_PROGRESS \
"Progress...\n" \
" fork pt :%1%\n" \
" top conf :%2%:%3%\n" \
" top cand :%4%:%5%\n" \
" top assoc:%6%\n" \
" not assoc:%7%\n" \
" wire conf:%8%\n" \
" wire cand:%9%"
" fork pt :%1%\n" \
" top conf :%2%:%3%\n" \
" top cand :%4%:%5%\n" \
" top assoc :%6%\n" \
" associated:%7%\n" \
" wire conf :%8%\n" \
" wire cand :%9%"

// --read
#define BN_READ_ROW \
Expand Down
9 changes: 5 additions & 4 deletions include/bitcoin/node/chasers/chaser.hpp
Expand Up @@ -68,19 +68,20 @@ class BCN_API chaser
/// -----------------------------------------------------------------------

/// Node threadpool is stopped and may still be joining.
bool closed() const NOEXCEPT;
virtual bool closed() const NOEXCEPT;

/// Suspend all existing and future network connections.
void suspend(const code& ec) const NOEXCEPT;
virtual void suspend(const code& ec) const NOEXCEPT;

/// Events.
/// -----------------------------------------------------------------------

/// Call from chaser start methods (requires node strand).
code subscribe_events(event_handler&& handler) NOEXCEPT;
virtual object_key subscribe_events(event_notifier&& handler) NOEXCEPT;

/// Set event (does not require node strand).
void notify(const code& ec, chase event_, event_link value) const NOEXCEPT;
virtual void notify(const code& ec, chase event_,
event_value value) const NOEXCEPT;

/// Properties.
/// -----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_check.hpp
Expand Up @@ -54,8 +54,8 @@ class BCN_API chaser_check
network::result_handler&& handler) NOEXCEPT;

protected:
virtual void handle_event(const code& ec, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_header(height_t branch_point) NOEXCEPT;
virtual void do_preconfirmable(height_t height) NOEXCEPT;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Expand Up @@ -42,8 +42,8 @@ class BCN_API chaser_confirm
protected:
using header_links = std::vector<database::header_link>;

virtual void handle_event(const code& ec, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_preconfirmed(height_t height) NOEXCEPT;
virtual code confirm(const database::header_link& link,
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_organize.hpp
Expand Up @@ -91,8 +91,8 @@ class chaser_organize
/// -----------------------------------------------------------------------

/// Handle chaser events.
virtual void handle_event(const code&, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code&, chase event_,
event_value value) NOEXCEPT;

/// Reorganize following Block unconfirmability.
virtual void do_disorganize(header_t header) NOEXCEPT;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_preconfirm.hpp
Expand Up @@ -40,8 +40,8 @@ class BCN_API chaser_preconfirm
code start() NOEXCEPT override;

protected:
virtual void handle_event(const code& ec, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_regressed(height_t branch_point) NOEXCEPT;
virtual void do_disorganized(height_t top) NOEXCEPT;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_template.hpp
Expand Up @@ -39,8 +39,8 @@ class BCN_API chaser_template
code start() NOEXCEPT override;

protected:
virtual void handle_event(const code& ec, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_transaction(transaction_t value) NOEXCEPT;
};
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Expand Up @@ -42,8 +42,8 @@ class BCN_API chaser_transaction
virtual void store(const system::chain::transaction::cptr& block) NOEXCEPT;

protected:
virtual void handle_event(const code& ec, chase event_,
event_link value) NOEXCEPT;
virtual bool handle_event(const code& ec, chase event_,
event_value value) NOEXCEPT;

virtual void do_confirmed(header_t link) NOEXCEPT;
virtual void do_store(
Expand Down

0 comments on commit 73f8b71

Please sign in to comment.