Skip to content

Commit

Permalink
Stub in chaser event handler dispatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 11, 2024
1 parent b774448 commit ca387b6
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 5 deletions.
5 changes: 4 additions & 1 deletion include/bitcoin/node/chasers/chaser_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ namespace node {
class full_node;

/// Construct candidate blocks upon modification of the transaction DAG.
/// Notify subscribers with "candidate" event.
class BCN_API chaser_candidate
: public chaser, protected network::tracker<chaser_candidate>
{
public:
typedef std::unique_ptr<chaser_candidate> uptr;

chaser_candidate(full_node& node) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
};

} // namespace node
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ namespace node {
class full_node;

/// Chase down blocks for the candidate header chain.
/// Notify subscribers with "block checked" event.
class BCN_API chaser_check
: public chaser, protected network::tracker<chaser_check>
{
Expand Down
5 changes: 4 additions & 1 deletion include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ namespace node {
class full_node;

/// Chase down valid blocks for confirmation.
/// Notify subscribers with "block confirmed" event.
class BCN_API chaser_confirm
: public chaser, protected network::tracker<chaser_confirm>
{
public:
typedef std::unique_ptr<chaser_confirm> uptr;

chaser_confirm(full_node& node) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
};

} // namespace node
Expand Down
5 changes: 4 additions & 1 deletion include/bitcoin/node/chasers/chaser_connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ namespace node {
class full_node;

/// Chase down blocks in the the candidate header chain for validation.
/// Notify subscribers with the "block connected" event.
class BCN_API chaser_connect
: public chaser, protected network::tracker<chaser_connect>
{
public:
typedef std::unique_ptr<chaser_connect> uptr;

chaser_connect(full_node& node) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
};

} // namespace node
Expand Down
5 changes: 4 additions & 1 deletion include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ namespace node {
class full_node;

/// Chase down stronger header branches for the candidate chain.
/// Notify subscribers with "strong header" event.
class BCN_API chaser_header
: public chaser, protected network::tracker<chaser_header>
{
public:
typedef std::unique_ptr<chaser_header> uptr;

chaser_header(full_node& node) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
};

} // namespace node
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class BCN_API chaser_transaction
typedef std::unique_ptr<chaser_transaction> uptr;

chaser_transaction(full_node& node) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
};

} // namespace node
Expand Down
32 changes: 32 additions & 0 deletions src/chasers/chaser_candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,51 @@
*/
#include <bitcoin/node/chasers/chaser_candidate.hpp>

#include <functional>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/chasers/chaser.hpp>

namespace libbitcoin {
namespace node {

using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_candidate::chaser_candidate(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_candidate>(node.log)
{
subscribe(std::bind(&chaser_candidate::handle_event, this, _1, _2));
}

void chaser_candidate::handle_event(const code& ec, chase value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_candidate::do_handle_event, this, ec, value));
}

void chaser_candidate::do_handle_event(const code& ec, chase value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_candidate");

// The code should be error::service_stopped when error::stop is set.
if (ec)
return;

switch (value)
{
case chase::start:
// TODO: initialize.
break;
case chase::transaction:
// TODO: handle transaction graph change (may issue 'candidate').
break;
default:
return;
}
}

BC_POP_WARNING()
Expand Down
32 changes: 32 additions & 0 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,51 @@
*/
#include <bitcoin/node/chasers/chaser_confirm.hpp>

#include <functional>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/chasers/chaser.hpp>

namespace libbitcoin {
namespace node {

using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_confirm::chaser_confirm(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_confirm>(node.log)
{
subscribe(std::bind(&chaser_confirm::handle_event, this, _1, _2));
}

void chaser_confirm::handle_event(const code& ec, chase value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_confirm::do_handle_event, this, ec, value));
}

void chaser_confirm::do_handle_event(const code& ec, chase value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_confirm");

// The code should be error::service_stopped when error::stop is set.
if (ec)
return;

switch (value)
{
case chase::start:
// TODO: initialize.
break;
case chase::connected:
// TODO: handle new strong connected branch (may issue 'confirmed').
break;
default:
return;
}
}

BC_POP_WARNING()
Expand Down
32 changes: 32 additions & 0 deletions src/chasers/chaser_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,51 @@
*/
#include <bitcoin/node/chasers/chaser_connect.hpp>

#include <functional>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/chasers/chaser.hpp>

namespace libbitcoin {
namespace node {

using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_connect::chaser_connect(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_connect>(node.log)
{
subscribe(std::bind(&chaser_connect::handle_event, this, _1, _2));
}

void chaser_connect::handle_event(const code& ec, chase value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_connect::do_handle_event, this, ec, value));
}

void chaser_connect::do_handle_event(const code& ec, chase value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_connect");

// The code should be error::service_stopped when error::stop is set.
if (ec)
return;

switch (value)
{
case chase::start:
// TODO: initialize.
break;
case chase::checked:
// TODO: handle the new checked blocks (may issue 'connected').
break;
default:
return;
}
}

BC_POP_WARNING()
Expand Down
31 changes: 31 additions & 0 deletions src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,52 @@
*/
#include <bitcoin/node/chasers/chaser_header.hpp>

#include <functional>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/chasers/chaser.hpp>

namespace libbitcoin {
namespace node {

using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_header::chaser_header(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_header>(node.log)
{
subscribe(std::bind(&chaser_header::handle_event, this, _1, _2));
}

void chaser_header::handle_event(const code& ec, chase value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_header::do_handle_event, this, ec, value));
}

void chaser_header::do_handle_event(const code& ec, chase value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_header");

// The code should be error::service_stopped when error::stop is set.
if (ec)
return;

switch (value)
{
case chase::start:
// TODO: initialize.
break;
default:
return;
}
}

// TODO: handle new headers (may issue 'header').

BC_POP_WARNING()

} // namespace database
Expand Down
34 changes: 34 additions & 0 deletions src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,55 @@
*/
#include <bitcoin/node/chasers/chaser_transaction.hpp>

#include <functional>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/chasers/chaser.hpp>

namespace libbitcoin {
namespace node {

using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_transaction::chaser_transaction(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_transaction>(node.log)
{
subscribe(std::bind(&chaser_transaction::handle_event, this, _1, _2));
}

void chaser_transaction::handle_event(const code& ec, chase value) NOEXCEPT
{
boost::asio::post(strand(),
std::bind(&chaser_transaction::do_handle_event, this, ec, value));
}

void chaser_transaction::do_handle_event(const code& ec, chase value) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_transaction");

// The code should be error::service_stopped when error::stop is set.
if (ec)
return;

switch (value)
{
case chase::start:
// TODO: initialize.
break;
case chase::confirmed:
// TODO: handle the new confirmed blocks (may issue 'transaction').
break;
default:
return;
}
}

// TODO: handle the new unconfirmed transactions (may issue 'transaction').

BC_POP_WARNING()

} // namespace database
Expand Down

0 comments on commit ca387b6

Please sign in to comment.