Skip to content

Commit

Permalink
Merge pull request #532 from evoskuil/master
Browse files Browse the repository at this point in the history
Remove -blockchain dependency, work on chaser stubs.
  • Loading branch information
evoskuil authored Feb 13, 2024
2 parents 3b84598 + 478b79c commit 8e437a2
Show file tree
Hide file tree
Showing 28 changed files with 216 additions and 86 deletions.
1 change: 0 additions & 1 deletion console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,6 @@ bool executor::do_version()
log_.stop();
console(format(BN_VERSION_MESSAGE)
% LIBBITCOIN_NODE_VERSION
% LIBBITCOIN_BLOCKCHAIN_VERSION
% LIBBITCOIN_DATABASE_VERSION
% LIBBITCOIN_NETWORK_VERSION
% LIBBITCOIN_SYSTEM_VERSION);
Expand Down
1 change: 0 additions & 1 deletion console/localize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ namespace node {
"\nVersion Information\n" \
"----------------------------\n" \
"libbitcoin-node: %1%\n" \
"libbitcoin-blockchain: %2%\n" \
"libbitcoin-database: %3%\n" \
"libbitcoin-network: %4%\n" \
"libbitcoin-system: %5%"
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Maintainers: Do not include this header internal to this library.
*/

#include <bitcoin/blockchain.hpp>
////#include <bitcoin/blockchain.hpp>
#include <bitcoin/network.hpp>
#include <bitcoin/node/configuration.hpp>
#include <bitcoin/node/define.hpp>
Expand Down
19 changes: 14 additions & 5 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef LIBBITCOIN_NODE_CHASERS_CHASER_HPP
#define LIBBITCOIN_NODE_CHASERS_CHASER_HPP

#include <variant>
#include <bitcoin/database.hpp>
#include <bitcoin/network.hpp>
#include <bitcoin/node/define.hpp>

Expand Down Expand Up @@ -71,7 +73,11 @@ class BCN_API chaser
stop
};

typedef network::subscriber<chase> event_subscriber;
typedef database::store<database::map> store;
typedef database::query<store> query;

typedef std::variant<int32_t, int64_t> link;
typedef network::subscriber<chase, link> event_subscriber;
typedef event_subscriber::handler event_handler;
DELETE_COPY_MOVE(chaser);

Expand All @@ -82,8 +88,8 @@ class BCN_API chaser
chaser(full_node& node) NOEXCEPT;
~chaser() NOEXCEPT;

/// Close the node.
void close(const code& ec) NOEXCEPT;
/// Thread safe synchronous archival interface.
query& archive() const NOEXCEPT;

/// The chaser's strand.
network::asio::strand& strand() NOEXCEPT;
Expand All @@ -95,10 +101,13 @@ class BCN_API chaser
code subscribe(event_handler&& handler) NOEXCEPT;

/// Set chaser event (does not require network strand).
void notify(const code& ec, chase value) NOEXCEPT;
void notify(const code& ec, chase event_, link value) NOEXCEPT;

/// Close the node.
void close(const code& ec) NOEXCEPT;

private:
void do_notify(const code& ec, chase value) NOEXCEPT;
void do_notify(const code& ec, chase event_, link value) NOEXCEPT;

// These are thread safe (mostly).
full_node& node_;
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_candidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class BCN_API chaser_candidate
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;
void handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
};

} // namespace node
Expand Down
6 changes: 4 additions & 2 deletions 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;

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

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class BCN_API chaser_confirm
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;
void handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
};

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/chasers/chaser_connect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class BCN_API chaser_connect
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;
void handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
};

} // namespace node
Expand Down
12 changes: 10 additions & 2 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@ class BCN_API chaser_header

chaser_header(full_node& node) NOEXCEPT;

void store(const system::chain::header::cptr& header) NOEXCEPT;

private:
void handle_event(const code& ec, chase value) NOEXCEPT;
void do_handle_event(const code& ec, chase value) NOEXCEPT;
bool is_current(const system::chain::header& header) const NOEXCEPT;
bool is_strong(const system::chain::header& header) const 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;

const network::wall_clock::duration currency_window_;
std::vector<system::chain::header::cptr> chain_{};
};

} // namespace node
Expand Down
6 changes: 4 additions & 2 deletions include/bitcoin/node/chasers/chaser_transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class BCN_API chaser_transaction

chaser_transaction(full_node& node) NOEXCEPT;

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

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

} // namespace node
Expand Down
5 changes: 3 additions & 2 deletions include/bitcoin/node/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#ifndef LIBBITCOIN_NODE_CONFIGURATION_HPP
#define LIBBITCOIN_NODE_CONFIGURATION_HPP

#include <bitcoin/blockchain.hpp>
////#include <bitcoin/blockchain.hpp>
#include <bitcoin/database.hpp>
#include <bitcoin/network.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/settings.hpp>
Expand Down Expand Up @@ -71,7 +72,7 @@ class BCN_API configuration
/// Settings.
log::settings log;
node::settings node;
blockchain::settings chain;
////blockchain::settings chain;
database::settings database;
network::settings network;
system::settings bitcoin;
Expand Down
8 changes: 8 additions & 0 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ class BCN_API full_node
/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;

/// Node configuration settings.
const settings& node_settings() const NOEXCEPT;

/// Thread safe synchronous archival interface.
query& archive() const NOEXCEPT;

/// Obtain reference to the chaser event subscriber.
chaser::event_subscriber& event_subscriber() NOEXCEPT;

protected:

/// Chasers configuration.
/// -----------------------------------------------------------------------
virtual code create_chasers() NOEXCEPT;
virtual void stop_chasers() NOEXCEPT;
virtual void delete_chasers() NOEXCEPT;
Expand All @@ -79,6 +85,8 @@ class BCN_API full_node
network::session_inbound::ptr attach_inbound_session() NOEXCEPT override;
network::session_outbound::ptr attach_outbound_session() NOEXCEPT override;

/// Virtual handlers.
/// -----------------------------------------------------------------------
void do_start(const network::result_handler& handler) NOEXCEPT override;
void do_run(const network::result_handler& handler) NOEXCEPT override;
void do_close() NOEXCEPT override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BCN_API protocol_header_in_31800

protected:
/// Invoked when initial headers sync is current.
virtual void current() NOEXCEPT;
virtual void complete() NOEXCEPT;

/// Recieved incoming headers message.
virtual bool handle_receive_headers(const code& ec,
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/protocols/protocol_header_in_70012.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class BCN_API protocol_header_in_70012
}

protected:
/// Invoked when initial headers sync is current.
void current() NOEXCEPT override;
/// Invoked when initial headers sync is complete.
void complete() NOEXCEPT override;

private:
bool sent_{};
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class BCN_API settings
/// Properties.
float allowed_deviation;
uint16_t sample_period_seconds;
uint32_t currency_window_minutes;

/// Helpers.
virtual network::steady_clock::duration sample_period() const NOEXCEPT;
virtual network::wall_clock::duration currency_window() const NOEXCEPT;
};

} // namespace node
Expand Down
20 changes: 12 additions & 8 deletions src/chasers/chaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ chaser::~chaser() NOEXCEPT
{
}


void chaser::close(const code& ec) NOEXCEPT
chaser::query& chaser::archive() const NOEXCEPT
{
LOGF("Chaser fault, " << ec.message());
node_.close();
return node_.archive();
}

asio::strand& chaser::strand() NOEXCEPT
Expand All @@ -69,17 +67,23 @@ code chaser::subscribe(event_handler&& handler) NOEXCEPT
}

// Posts to network strand (call from chaser strands).
void chaser::notify(const code& ec, chase value) NOEXCEPT
void chaser::notify(const code& ec, chase event_, link value) NOEXCEPT
{
boost::asio::post(node_.strand(),
std::bind(&chaser::do_notify, this, ec, value));
std::bind(&chaser::do_notify, this, ec, event_, value));
}

// Executed on network strand (handler should bounce to chaser strand).
void chaser::do_notify(const code& ec, chase value) NOEXCEPT
void chaser::do_notify(const code& ec, chase event_, link value) NOEXCEPT
{
BC_ASSERT_MSG(node_.stranded(), "chaser");
subscriber_.notify(ec, value);
subscriber_.notify(ec, event_, value);
}

void chaser::close(const code& ec) NOEXCEPT
{
LOGF("Chaser fault, " << ec.message());
node_.close();
}

BC_POP_WARNING()
Expand Down
12 changes: 7 additions & 5 deletions src/chasers/chaser_candidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ 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));
subscribe(std::bind(&chaser_candidate::handle_event, this, _1, _2, _3));
}

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

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

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

switch (value)
switch (event_)
{
case chase::start:
// TODO: initialize.
Expand Down
20 changes: 14 additions & 6 deletions src/chasers/chaser_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

namespace libbitcoin {
namespace node {


using namespace system::chain;
using namespace std::placeholders;

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
Expand All @@ -35,24 +36,25 @@ chaser_check::chaser_check(full_node& node) NOEXCEPT
: chaser(node),
tracker<chaser_check>(node.log)
{
subscribe(std::bind(&chaser_check::handle_event, this, _1, _2));
subscribe(std::bind(&chaser_check::handle_event, this, _1, _2, _3));
}

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

void chaser_check::do_handle_event(const code& ec, chase value) NOEXCEPT
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 (value)
switch (event_)
{
case chase::start:
// TODO: initialize.
Expand All @@ -65,6 +67,12 @@ void chaser_check::do_handle_event(const code& ec, chase value) NOEXCEPT
}
}

void chaser_check::store(const block::cptr&) NOEXCEPT
{
// Push checked block into store and issue checked event so that connect
// can connect the next blocks in order, as applicable.
}

BC_POP_WARNING()

} // namespace database
Expand Down
12 changes: 7 additions & 5 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ 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));
subscribe(std::bind(&chaser_confirm::handle_event, this, _1, _2, _3));
}

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

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

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

switch (value)
switch (event_)
{
case chase::start:
// TODO: initialize.
Expand Down
Loading

0 comments on commit 8e437a2

Please sign in to comment.