Skip to content

Commit

Permalink
Stub in chaser event handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Feb 13, 2024
1 parent 8e437a2 commit 551664c
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 20 deletions.
2 changes: 2 additions & 0 deletions include/bitcoin/node/chasers/chaser_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/chasers/chaser_connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<system::chain::header::cptr> chain_{};
};
Expand Down
3 changes: 3 additions & 0 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions src/chasers/chaser_candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 22 additions & 6 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 18 additions & 3 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions src/chasers/chaser_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
29 changes: 26 additions & 3 deletions src/chasers/chaser_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 551664c

Please sign in to comment.