Skip to content

Commit

Permalink
Merge pull request #540 from evoskuil/master
Browse files Browse the repository at this point in the history
Pass result handler to organize methods.
  • Loading branch information
evoskuil authored Feb 22, 2024
2 parents 2c3d7a3 + 8125c5f commit d40c236
Show file tree
Hide file tree
Showing 30 changed files with 691 additions and 286 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ src_libbitcoin_node_la_SOURCES = \
src/chasers/chaser_transaction.cpp \
src/protocols/protocol.cpp \
src/protocols/protocol_block_in.cpp \
src/protocols/protocol_block_in_31800.cpp \
src/protocols/protocol_block_out.cpp \
src/protocols/protocol_header_in_31800.cpp \
src/protocols/protocol_header_in_70012.cpp \
Expand Down Expand Up @@ -141,6 +142,7 @@ include_bitcoin_node_protocolsdir = ${includedir}/bitcoin/node/protocols
include_bitcoin_node_protocols_HEADERS = \
include/bitcoin/node/protocols/protocol.hpp \
include/bitcoin/node/protocols/protocol_block_in.hpp \
include/bitcoin/node/protocols/protocol_block_in_31800.hpp \
include/bitcoin/node/protocols/protocol_block_out.hpp \
include/bitcoin/node/protocols/protocol_header_in_31800.hpp \
include/bitcoin/node/protocols/protocol_header_in_70012.hpp \
Expand Down
1 change: 1 addition & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/chasers/chaser_transaction.cpp"
"../../src/protocols/protocol.cpp"
"../../src/protocols/protocol_block_in.cpp"
"../../src/protocols/protocol_block_in_31800.cpp"
"../../src/protocols/protocol_block_out.cpp"
"../../src/protocols/protocol_header_in_31800.cpp"
"../../src/protocols/protocol_header_in_70012.cpp"
Expand Down
2 changes: 2 additions & 0 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<ClCompile Include="..\..\..\..\src\parser.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_31800.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_out.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_header_in_31800.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_header_in_70012.cpp" />
Expand Down Expand Up @@ -118,6 +119,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\parser.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_31800.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_out.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_header_in_31800.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_header_in_70012.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in_31800.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_out.cpp">
<Filter>src\protocols</Filter>
</ClCompile>
Expand Down Expand Up @@ -173,6 +176,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in.hpp">
<Filter>include\bitcoin\node\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in_31800.hpp">
<Filter>include\bitcoin\node\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_out.hpp">
<Filter>include\bitcoin\node\protocols</Filter>
</ClInclude>
Expand Down
40 changes: 15 additions & 25 deletions data/bn.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ bip66_freeze = 363725
bip34_freeze = 227931
# The activation time for bip16 in unix time, defaults to 1333238400 (use 1329264000 for testnet).
bip16_activation_time = 1333238400
# The hash:height checkpoint for bip34 activation, defaults to 000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8:227931 (use 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8:21111 for testnet).
bip34_active_checkpoint = 000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8:227931
# The hash:height checkpoint for bip9 bit0 activation, defaults to 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5:419328 (use 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb:770112 for testnet).
bip9_bit0_active_checkpoint = 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5:419328
# The hash:height checkpoint for bip9 bit1 activation, defaults to 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893:481824 (use 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca:834624 for testnet).
Expand Down Expand Up @@ -159,32 +157,24 @@ block_buffer_limit = 0
# Enable neutrino filter storage and related compact filter query response, defaults to false.
bip158 = false
# A hash:height checkpoint, multiple entries allowed, defaults shown.
checkpoint = 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f:0
checkpoint = 0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d:11111
checkpoint = 000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6:33333
checkpoint = 00000000001e1b4903550a0b96e9a9405c8a95f387162e4944e8d9fbe501cd6a:68555
checkpoint = 00000000006a49b14bcf27462068f1264c961f11fa2e0eddd2be0791e1d4124a:70567
checkpoint = 0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20:74000
checkpoint = 00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97:105000
checkpoint = 000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553:118000
checkpoint = 00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe:134444
checkpoint = 000000000000033b512028abb90e1626d8b346fd0ed598ac0a3c371138dce2bd:140700
checkpoint = 000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763:168000
checkpoint = 000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317:193000
checkpoint = 000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e:210000
checkpoint = 00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e:216116
checkpoint = 00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932:225430
checkpoint = 000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214:250000
checkpoint = 0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40:279000
checkpoint = 00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983:295000
checkpoint = 0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40:279000
checkpoint = 000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214:250000
checkpoint = 00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932:225430
checkpoint = 00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e:216116
checkpoint = 000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e:210000
checkpoint = 000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317:193000
checkpoint = 000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763:168000
checkpoint = 00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe:134444
checkpoint = 000000000000774a7f8a7a12dc906ddb9e17e75d684f15e00f8767f9e8f36553:118000
checkpoint = 00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97:105000
checkpoint = 0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20:74000
checkpoint = 000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6:33333
checkpoint = 0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d:11111
checkpoint = 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f:0
# Testnet checkpoints.
#checkpoint = 000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70:546
#checkpoint = 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943:0
#checkpoint = 00000000009e2958c15ff9290d571bf9459e93b19765c6801ddeccadbb160a1e:100000
#checkpoint = 0000000000287bffd321963ef05feab753ebe274e1d78b2fd4e2bfe9ad3aa6f2:200000
#checkpoint = 000000000000226f7618566e70a2b5e020e29579b46743f05348427239bf41a1:300000
#checkpoint = 000000000598cbbb1e79057b79eef828c495d4fc31050e6b179c57d07d00367c:400000
#checkpoint = 000000000001a7c0aaa2630fbb2c0e476aafffc60f82177375b2aaa22209f606:500000
#checkpoint = 000000000000624f06c69d3a9fe8d25e0a9030569128d63ad1b704bbb3059a16:600000

[fork]
# Require difficult blocks, defaults to true (use false for testnet).
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <bitcoin/node/chasers/chasers.hpp>
#include <bitcoin/node/protocols/protocol.hpp>
#include <bitcoin/node/protocols/protocol_block_in.hpp>
#include <bitcoin/node/protocols/protocol_block_in_31800.hpp>
#include <bitcoin/node/protocols/protocol_block_out.hpp>
#include <bitcoin/node/protocols/protocol_header_in_31800.hpp>
#include <bitcoin/node/protocols/protocol_header_in_70012.hpp>
Expand Down
7 changes: 3 additions & 4 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class BCN_API chaser
chaser(full_node& node) NOEXCEPT;
~chaser() NOEXCEPT;

/// Node threadpool is stopped and may still be joining.
bool closed() const NOEXCEPT;

/// Node configuration settings.
const node::configuration& config() const NOEXCEPT;

Expand All @@ -120,15 +123,11 @@ class BCN_API chaser
/// Set chaser event (does not require network strand).
void notify(const code& ec, chase event_, link value) NOEXCEPT;

/// Close the node in case of failure.
void stop(const code& ec) NOEXCEPT;

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

// These are thread safe (mostly).
full_node& node_;
const node::configuration& config_;
network::asio::strand strand_;

// This is protected by the network strand.
Expand Down
8 changes: 4 additions & 4 deletions include/bitcoin/node/chasers/chaser_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ class BCN_API chaser_block
virtual code start() NOEXCEPT;

/// Validate and organize next block in sequence relative to caller peer.
/// Causes a fault/stop if preceding blocks have not been stored.
virtual void organize(
const system::chain::block::cptr& block_ptr) NOEXCEPT;
virtual void organize(const system::chain::block::cptr& block_ptr,
network::result_handler&& handler) NOEXCEPT;

protected:
struct validated_block
Expand Down Expand Up @@ -99,7 +98,8 @@ class BCN_API chaser_block

private:
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_organize(const system::chain::block::cptr& block) NOEXCEPT;
void do_organize(const system::chain::block::cptr& block,
const network::result_handler& handler) NOEXCEPT;

// These are thread safe.
const system::chain::checkpoints& checkpoints_;
Expand Down
8 changes: 4 additions & 4 deletions include/bitcoin/node/chasers/chaser_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ class BCN_API chaser_header
virtual code start() NOEXCEPT;

/// Validate and organize next header in sequence relative to caller peer.
/// Causes a fault/stop if preceding headers have not been stored.
virtual void organize(
const system::chain::header::cptr& header_ptr) NOEXCEPT;
virtual void organize(const system::chain::header::cptr& header_ptr,
network::result_handler&& handler) NOEXCEPT;

protected:
struct proposed_header
Expand Down Expand Up @@ -99,7 +98,8 @@ class BCN_API chaser_header

private:
void do_handle_event(const code& ec, chase event_, link value) NOEXCEPT;
void do_organize(const system::chain::header::cptr& header) NOEXCEPT;
void do_organize(const system::chain::header::cptr& header,
const network::result_handler& handler) NOEXCEPT;

// These are thread safe.
const system::chain::checkpoints& checkpoints_;
Expand Down
10 changes: 6 additions & 4 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ class BCN_API full_node
/// Chasers.
/// -----------------------------------------------------------------------

/// Organize a validated header, failures stop the node.
virtual void organize(const system::chain::header::cptr& header) NOEXCEPT;
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated block, failures stop the node.
virtual void organize(const system::chain::block::cptr& block) NOEXCEPT;
/// Organize a validated block.
virtual void organize(const system::chain::block::cptr& block,
network::result_handler&& handler) NOEXCEPT;

/// Properties.
/// -----------------------------------------------------------------------
Expand Down
13 changes: 9 additions & 4 deletions include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,16 @@ class BCN_API protocol
virtual void performance(uint64_t channel, uint64_t speed,
network::result_handler&& handler) const NOEXCEPT;

/// Organize a validated header, failures stop the node.
virtual void organize(const system::chain::header::cptr& header) NOEXCEPT;
/// Organize a validated header.
virtual void organize(const system::chain::header::cptr& header,
network::result_handler&& handler) NOEXCEPT;

/// Organize a validated block, failures stop the node.
virtual void organize(const system::chain::block::cptr& block) NOEXCEPT;
/// Organize a validated block.
virtual void organize(const system::chain::block::cptr& block,
network::result_handler&& handler) NOEXCEPT;

/// Handle organize result.
virtual void handle_organize(const code& ec) NOEXCEPT;

/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;
Expand Down
20 changes: 1 addition & 19 deletions include/bitcoin/node/protocols/protocol_block_in.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,17 @@ class BCN_API protocol_block_in
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
template <typename Session>
protocol_block_in(Session& session,
const channel_ptr& channel, bool report_performance) NOEXCEPT
const channel_ptr& channel) NOEXCEPT
: node::protocol(session, channel),
network::tracker<protocol_block_in>(session.log),
////report_performance_(report_performance &&
//// to_bool(session.config().node.sample_period_seconds)),
block_type_(session.config().network.witness_node() ?
type_id::witness_block : type_id::block)
////performance_timer_(std::make_shared<network::deadline>(session.log,
//// channel->strand(), session.config().node.sample_period()))
{
}
BC_POP_WARNING()

/// Start/stop protocol (strand required).
void start() NOEXCEPT override;
void stopping(const code& ec) NOEXCEPT override;

protected:
struct track
Expand All @@ -73,12 +68,6 @@ class BCN_API protocol_block_in
const network::messages::block::cptr& message,
const track_ptr& tracker) NOEXCEPT;

/////// Handle performance timer event.
////virtual void handle_performance_timer(const code& ec) NOEXCEPT;

/////// Handle result of performance reporting.
////virtual void handle_performance(const code& ec) NOEXCEPT;

/// Invoked when initial blocks sync is complete.
virtual void complete() NOEXCEPT;

Expand All @@ -95,18 +84,11 @@ class BCN_API protocol_block_in
network::messages::get_data create_get_data(
const network::messages::inventory& message) const NOEXCEPT;


////void do_handle_performance(const code& ec) NOEXCEPT;

// Thread safe.
////const bool report_performance_;
const network::messages::inventory::type_id block_type_;

// Protected by strand.
////uint64_t bytes_{ zero };
system::chain::checkpoint top_{};
////network::steady_clock::time_point start_{};
////network::deadline::ptr performance_timer_;
};

} // namespace node
Expand Down
Loading

0 comments on commit d40c236

Please sign in to comment.