From 551664c57a5411ebfc91b2d9590a183730d52c0e Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 13 Feb 2024 10:31:15 -0500 Subject: [PATCH] Stub in chaser event handlers. --- .../bitcoin/node/chasers/chaser_candidate.hpp | 2 ++ include/bitcoin/node/chasers/chaser_check.hpp | 4 ++- .../bitcoin/node/chasers/chaser_confirm.hpp | 2 ++ .../bitcoin/node/chasers/chaser_connect.hpp | 2 ++ .../bitcoin/node/chasers/chaser_header.hpp | 3 ++ .../node/chasers/chaser_transaction.hpp | 3 ++ src/chasers/chaser_candidate.cpp | 21 ++++++++++++-- src/chasers/chaser_check.cpp | 28 ++++++++++++++---- src/chasers/chaser_confirm.cpp | 21 ++++++++++++-- src/chasers/chaser_connect.cpp | 21 ++++++++++++-- src/chasers/chaser_header.cpp | 10 ++++++- src/chasers/chaser_transaction.cpp | 29 +++++++++++++++++-- 12 files changed, 126 insertions(+), 20 deletions(-) diff --git a/include/bitcoin/node/chasers/chaser_candidate.hpp b/include/bitcoin/node/chasers/chaser_candidate.hpp index e5760a6c..b73f7593 100644 --- a/include/bitcoin/node/chasers/chaser_candidate.hpp +++ b/include/bitcoin/node/chasers/chaser_candidate.hpp @@ -38,6 +38,8 @@ class BCN_API chaser_candidate chaser_candidate(full_node& node) NOEXCEPT; private: + void handle_start() NOEXCEPT; + void handle_transaction() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; }; diff --git a/include/bitcoin/node/chasers/chaser_check.hpp b/include/bitcoin/node/chasers/chaser_check.hpp index 59b7891c..35d51f49 100644 --- a/include/bitcoin/node/chasers/chaser_check.hpp +++ b/include/bitcoin/node/chasers/chaser_check.hpp @@ -37,9 +37,11 @@ class BCN_API chaser_check chaser_check(full_node& node) NOEXCEPT; - void store(const system::chain::block::cptr& block) NOEXCEPT; + void checked(const system::chain::block::cptr& block) NOEXCEPT; private: + void handle_start() NOEXCEPT; + void handle_header() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; }; diff --git a/include/bitcoin/node/chasers/chaser_confirm.hpp b/include/bitcoin/node/chasers/chaser_confirm.hpp index 54a54c8e..7d0cc122 100644 --- a/include/bitcoin/node/chasers/chaser_confirm.hpp +++ b/include/bitcoin/node/chasers/chaser_confirm.hpp @@ -38,6 +38,8 @@ class BCN_API chaser_confirm chaser_confirm(full_node& node) NOEXCEPT; private: + void handle_start() NOEXCEPT; + void handle_connected() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; }; diff --git a/include/bitcoin/node/chasers/chaser_connect.hpp b/include/bitcoin/node/chasers/chaser_connect.hpp index 08d7579a..47c76283 100644 --- a/include/bitcoin/node/chasers/chaser_connect.hpp +++ b/include/bitcoin/node/chasers/chaser_connect.hpp @@ -38,6 +38,8 @@ class BCN_API chaser_connect chaser_connect(full_node& node) NOEXCEPT; private: + void handle_start() NOEXCEPT; + void handle_checked() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; }; diff --git a/include/bitcoin/node/chasers/chaser_header.hpp b/include/bitcoin/node/chasers/chaser_header.hpp index 02e3cd80..bfe046f5 100644 --- a/include/bitcoin/node/chasers/chaser_header.hpp +++ b/include/bitcoin/node/chasers/chaser_header.hpp @@ -42,10 +42,13 @@ class BCN_API chaser_header private: bool is_current(const system::chain::header& header) const NOEXCEPT; bool is_strong(const system::chain::header& header) const NOEXCEPT; + + void handle_start() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_store(const system::chain::header::cptr& header) NOEXCEPT; + // These are protected by strand. const network::wall_clock::duration currency_window_; std::vector chain_{}; }; diff --git a/include/bitcoin/node/chasers/chaser_transaction.hpp b/include/bitcoin/node/chasers/chaser_transaction.hpp index b674b746..53fa4d0d 100644 --- a/include/bitcoin/node/chasers/chaser_transaction.hpp +++ b/include/bitcoin/node/chasers/chaser_transaction.hpp @@ -40,8 +40,11 @@ class BCN_API chaser_transaction void store(const system::chain::transaction::cptr& block) NOEXCEPT; private: + void handle_start() NOEXCEPT; + void handle_confirmed() NOEXCEPT; void handle_event(const code& ec, chase event_, link value) NOEXCEPT; void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT; + void do_store(const system::chain::transaction::cptr& header) NOEXCEPT; }; } // namespace node diff --git a/src/chasers/chaser_candidate.cpp b/src/chasers/chaser_candidate.cpp index 82c8cd5e..e69e2c3e 100644 --- a/src/chasers/chaser_candidate.cpp +++ b/src/chasers/chaser_candidate.cpp @@ -50,23 +50,38 @@ void chaser_candidate::do_handle_event(const code& ec, chase event_, { BC_ASSERT_MSG(stranded(), "chaser_candidate"); - // The code should be error::service_stopped when error::stop is set. if (ec) return; switch (event_) { case chase::start: - // TODO: initialize. + { + handle_start(); break; + } case chase::transaction: - // TODO: handle transaction graph change (may issue 'candidate'). + { + handle_transaction(); break; + } default: return; } } +// TODO: initialize candidate state. +void chaser_candidate::handle_start() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_candidate"); +} + +// TODO: handle transaction graph change (may issue 'candidate'). +void chaser_candidate::handle_transaction() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_candidate"); +} + BC_POP_WARNING() } // namespace database diff --git a/src/chasers/chaser_check.cpp b/src/chasers/chaser_check.cpp index 6aee01f7..830bea7b 100644 --- a/src/chasers/chaser_check.cpp +++ b/src/chasers/chaser_check.cpp @@ -50,27 +50,43 @@ void chaser_check::do_handle_event(const code& ec, chase event_, link) NOEXCEPT { BC_ASSERT_MSG(stranded(), "chaser_check"); - // The code should be error::service_stopped when error::stop is set. if (ec) return; switch (event_) { case chase::start: - // TODO: initialize. + { + handle_start(); break; + } case chase::header: - // TODO: handle the new strong branch (may issue 'checked'). + { + handle_header(); break; + } default: return; } } -void chaser_check::store(const block::cptr&) NOEXCEPT +// TODO: initialize check state. +void chaser_check::handle_start() NOEXCEPT { - // Push checked block into store and issue checked event so that connect - // can connect the next blocks in order, as applicable. + BC_ASSERT_MSG(stranded(), "chaser_check"); +} + +// TODO: handle the new strong branch (may issue 'checked'). +void chaser_check::handle_header() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_check"); +} + +// TODO: pass link? +void chaser_check::checked(const block::cptr&) NOEXCEPT +{ + // Push checked block into store and issue 'checked' event so that connect + // can connect the next blocks in order. Executes in caller thread. } BC_POP_WARNING() diff --git a/src/chasers/chaser_confirm.cpp b/src/chasers/chaser_confirm.cpp index 8be08ac1..ff78dd33 100644 --- a/src/chasers/chaser_confirm.cpp +++ b/src/chasers/chaser_confirm.cpp @@ -50,23 +50,38 @@ void chaser_confirm::do_handle_event(const code& ec, chase event_, { BC_ASSERT_MSG(stranded(), "chaser_confirm"); - // The code should be error::service_stopped when error::stop is set. if (ec) return; switch (event_) { case chase::start: - // TODO: initialize. + { + handle_start(); break; + } case chase::connected: - // TODO: handle new strong connected branch (may issue 'confirmed'). + { + handle_connected(); break; + } default: return; } } +// TODO: initialize confirm state. +void chaser_confirm::handle_start() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_confirm"); +} + +// TODO: handle new strong connected branch (may issue 'confirmed'). +void chaser_confirm::handle_connected() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_confirm"); +} + BC_POP_WARNING() } // namespace database diff --git a/src/chasers/chaser_connect.cpp b/src/chasers/chaser_connect.cpp index 9a67b63a..e6f0cf73 100644 --- a/src/chasers/chaser_connect.cpp +++ b/src/chasers/chaser_connect.cpp @@ -50,23 +50,38 @@ void chaser_connect::do_handle_event(const code& ec, chase event_, { BC_ASSERT_MSG(stranded(), "chaser_connect"); - // The code should be error::service_stopped when error::stop is set. if (ec) return; switch (event_) { case chase::start: - // TODO: initialize. + { + handle_start(); break; + } case chase::checked: - // TODO: handle the new checked blocks (may issue 'connected'). + { + handle_checked(); break; + } default: return; } } +// TODO: initialize connect state. +void chaser_connect::handle_start() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_connect"); +} + +// TODO: handle the new checked blocks (may issue 'connected'). +void chaser_connect::handle_checked() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_connect"); +} + BC_POP_WARNING() } // namespace database diff --git a/src/chasers/chaser_header.cpp b/src/chasers/chaser_header.cpp index b26c8836..c2d45358 100644 --- a/src/chasers/chaser_header.cpp +++ b/src/chasers/chaser_header.cpp @@ -60,13 +60,21 @@ void chaser_header::do_handle_event(const code& ec, chase event_, link) NOEXCEPT switch (event_) { case chase::start: - // TODO: initialize header tree from store. + { + handle_start(); break; + } default: return; } } +// TODO: initialize header tree from store, log and stop on error. +void chaser_header::handle_start() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_header"); +} + // private bool chaser_header::is_current(const header& header) const NOEXCEPT { diff --git a/src/chasers/chaser_transaction.cpp b/src/chasers/chaser_transaction.cpp index ac518384..7069dcb5 100644 --- a/src/chasers/chaser_transaction.cpp +++ b/src/chasers/chaser_transaction.cpp @@ -51,29 +51,52 @@ void chaser_transaction::do_handle_event(const code& ec, chase event_, { BC_ASSERT_MSG(stranded(), "chaser_transaction"); - // The code should be error::service_stopped when error::stop is set. if (ec) return; switch (event_) { case chase::start: - // TODO: initialize. + { + handle_start(); break; + } case chase::confirmed: - // TODO: handle the new confirmed blocks (may issue 'transaction'). + { + handle_confirmed(); break; + } default: return; } } +// TODO: initialize tx graph from store, log and stop on error. +void chaser_transaction::handle_start() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_transaction"); +} + +// TODO: handle the new confirmed blocks (may issue 'transaction'). +void chaser_transaction::handle_confirmed() NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_transaction"); +} + void chaser_transaction::store(const transaction::cptr&) NOEXCEPT { // Push new checked tx into store and update DAG. Issue transaction event // so that candidate may construct a new template. } +// private +void chaser_transaction::do_store(const transaction::cptr&) NOEXCEPT +{ + BC_ASSERT_MSG(stranded(), "chaser_transaction"); + + // TODO: validate and store transaction. +} + BC_POP_WARNING() } // namespace database