Skip to content

Commit

Permalink
Update chaser variant passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 16, 2024
1 parent 93587e6 commit 6d706eb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
25 changes: 15 additions & 10 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,48 @@ class BCN_API chaser
public:
enum class chase
{
/// Initialize chaser state (no data).
/// Initialize chaser state ({}).
start,

/// A new strong branch exists (strong header link).
/// A new strong branch exists (strong height_t).
/// Issued by 'header' and handled by 'check'.
header,

/// A block has been downloaded, checked and stored (header link).
/// A block has been downloaded, checked and stored (header_t).
/// Issued by 'check' and handled by 'connect'.
checked,

/// A branch has been connected (header link).
/// A branch has been connected (header_t|height_t).
/// Issued by 'connect' and handled by 'confirm'.
connected,

/// A branch has been confirmed (top header link).
/// A branch has been confirmed (fork header_t|height_t).
/// Issued by 'confirm' and handled by 'transaction'.
confirmed,

/// A new transaction has been added to the pool (tx link).
/// A new transaction has been added to the pool (transaction_t).
/// Issued by 'transaction' and handled by 'candidate'.
transaction,

/// A new candidate block has been created (data?).
/// A new candidate block has been created (?).
/// Issued by 'candidate' and handled by miners.
candidate,

/// Service is stopping (accompanied by error::service_stopped).
stop
};

typedef database::store<database::map> store;
typedef database::query<store> query;
using height_t = database::height_link::integer;
using header_t = database::header_link::integer;
using transaction_t = database::tx_link::integer;
using flags_t = database::context::flag::integer;

typedef std::variant<int32_t, int64_t> link;
typedef std::variant<uint32_t, uint64_t> link;
typedef network::subscriber<chase, link> event_subscriber;
typedef event_subscriber::handler event_handler;

typedef database::store<database::map> store;
typedef database::query<store> query;
DELETE_COPY_MOVE(chaser);

// TODO: public method to check/store a block.
Expand Down
9 changes: 6 additions & 3 deletions include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ class BCN_API chaser_check

void checked(const system::chain::block::cptr& block) NOEXCEPT;

protected:
virtual void handle_start() NOEXCEPT;
virtual void handle_header(height_t branch_point) NOEXCEPT;
virtual void handle_event(const code& ec, chase event_,
link value) 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;
};

Expand Down
13 changes: 9 additions & 4 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <bitcoin/node/chasers/chaser_check.hpp>

#include <functional>
#include <variant>
#include <bitcoin/network.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/full_node.hpp>
Expand Down Expand Up @@ -46,7 +47,8 @@ void chaser_check::handle_event(const code& ec, chase event_,
std::bind(&chaser_check::do_handle_event, this, ec, event_, value));
}

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

Expand All @@ -62,7 +64,8 @@ void chaser_check::do_handle_event(const code& ec, chase event_, link) NOEXCEPT
}
case chase::header:
{
handle_header();
BC_ASSERT(std::holds_alternative<height_t>(value));
handle_header(std::get<height_t>(value));
break;
}
default:
Expand All @@ -74,15 +77,17 @@ void chaser_check::do_handle_event(const code& ec, chase event_, link) NOEXCEPT
void chaser_check::handle_start() NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_check");
// get_all_unassociated_above(0)
}

// TODO: handle the new strong branch (may issue 'checked').
void chaser_check::handle_header() NOEXCEPT
void chaser_check::handle_header(height_t branch_point) NOEXCEPT
{
BC_ASSERT_MSG(stranded(), "chaser_check");
LOGN("Candidate organization above height (" << branch_point << ").");
// get_all_unassociated_above(branch_point)
}

// TODO: pass link?
void chaser_check::checked(const block::cptr&) NOEXCEPT
{
// Push checked block into store and issue 'checked' event so that connect
Expand Down
3 changes: 0 additions & 3 deletions src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ using namespace network;
using namespace system;
using namespace std::placeholders;

using flags_t = database::context::flag::integer;
using height_t = database::context::block::integer;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_header::chaser_header(full_node& node) NOEXCEPT
Expand Down

0 comments on commit 6d706eb

Please sign in to comment.