Skip to content

Commit

Permalink
Merge pull request #553 from evoskuil/master
Browse files Browse the repository at this point in the history
Simplify assertions, make subscribe_events accessible to protocols.
  • Loading branch information
evoskuil authored Mar 6, 2024
2 parents ed1e564 + 8149f4d commit b0b1f54
Show file tree
Hide file tree
Showing 35 changed files with 273 additions and 266 deletions.
16 changes: 8 additions & 8 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,55 +45,55 @@ set( CMAKE_CXX_STANDARD_REQUIRED ON )
# Warn on all stuff.
check_cxx_compiler_flag( "-Wall" HAS_FLAG_WALL )
if ( HAS_FLAG_WALL )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wall> )
add_compile_options( "-Wall" )
else()
message( FATAL_ERROR "Compiler does not support -Wall" )
endif()

# Warn on extra stuff.
check_cxx_compiler_flag( "-Wextra" HAS_FLAG_WEXTRA )
if ( HAS_FLAG_WEXTRA )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wextra> )
add_compile_options( "-Wextra" )
else()
message( FATAL_ERROR "Compiler does not support -Wextra" )
endif()

# Disallow warning on style order of declarations.
check_cxx_compiler_flag( "-Wno-reorder" HAS_FLAG_WNO-REORDER )
if ( HAS_FLAG_WNO-REORDER )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-reorder> )
add_compile_options( "-Wno-reorder" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-reorder" )
endif()

# Suppress warning for incomplete field initialization.
check_cxx_compiler_flag( "-Wno-missing-field-initializers" HAS_FLAG_WNO-MISSING-FIELD-INITIALIZERS )
if ( HAS_FLAG_WNO-MISSING-FIELD-INITIALIZERS )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-missing-field-initializers> )
add_compile_options( "-Wno-missing-field-initializers" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-missing-field-initializers" )
endif()

# Conform to style.
check_cxx_compiler_flag( "-Wno-missing-braces" HAS_FLAG_WNO-MISSING-BRACES )
if ( HAS_FLAG_WNO-MISSING-BRACES )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-missing-braces> )
add_compile_options( "-Wno-missing-braces" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-missing-braces" )
endif()

# Ignore comments within comments or commenting of backslash extended lines.
check_cxx_compiler_flag( "-Wno-comment" HAS_FLAG_WNO-COMMENT )
if ( HAS_FLAG_WNO-COMMENT )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-comment> )
add_compile_options( "-Wno-comment" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-comment" )
endif()

# Suppress warning for copy of implicitly generated copy constructor.
check_cxx_compiler_flag( "-Wno-deprecated-copy" HAS_FLAG_WNO-DEPRECATED-COPY )
if ( HAS_FLAG_WNO-DEPRECATED-COPY )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-deprecated-copy> )
add_compile_options( "-Wno-deprecated-copy" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-deprecated-copy" )
endif()
Expand All @@ -102,7 +102,7 @@ endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
check_cxx_compiler_flag( "-Wno-mismatched-tags" HAS_FLAG_WNO-MISMATCHED-TAGS )
if ( HAS_FLAG_WNO-MISMATCHED-TAGS )
add_compile_options( $<$<COMPILE_LANGUAGE:CXX>:-Wno-mismatched-tags> )
add_compile_options( "-Wno-mismatched-tags" )
else()
message( FATAL_ERROR "Compiler does not support -Wno-mismatched-tags" )
endif()
Expand Down
4 changes: 2 additions & 2 deletions builds/cmake/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
"description": "Factored size optimization settings.",
"hidden": true,
"cacheVariables": {
"CMAKE_C_FLAGS": "$env{CMAKE_C_FLAGS} -Os",
"CMAKE_CXX_FLAGS": "$env{CMAKE_CXX_FLAGS} -Os"
"CMAKE_C_FLAGS": "$env{CMAKE_C_FLAGS} -Os -s",
"CMAKE_CXX_FLAGS": "$env{CMAKE_CXX_FLAGS} -Os -s"
}
},
{
Expand Down
11 changes: 6 additions & 5 deletions include/bitcoin/node/chasers/chaser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class full_node;
/// Unlike protocols chasers can stop the node.
/// Logging is currently disabled so that logging is kept to the protocols.
class BCN_API chaser
//// : public network::reporter
: public network::reporter
{
public:
enum class chase
Expand Down Expand Up @@ -142,9 +142,10 @@ class BCN_API chaser
bool node_stranded() const NOEXCEPT;

/// Subscribe to chaser events.
code subscribe_event(event_handler&& handler) NOEXCEPT;
/// Call from chaser start() methods (node strand).
code subscribe_events(event_handler&& handler) NOEXCEPT;

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

private:
Expand All @@ -158,8 +159,8 @@ class BCN_API chaser
event_subscriber& subscriber_;
};

#define SUBSCRIBE_EVENT(method, ...) \
subscribe_event(BIND(method, __VA_ARGS__))
#define SUBSCRIBE_EVENTS(method, ...) \
subscribe_events(BIND(method, __VA_ARGS__))

} // namespace node
} // namespace libbitcoin
Expand Down
8 changes: 6 additions & 2 deletions include/bitcoin/node/chasers/chaser_check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BCN_API chaser_check
: public chaser
{
public:
typedef std::shared_ptr<database::context_map> map_ptr;
typedef std::shared_ptr<database::associations> map_ptr;
typedef std::function<void(const code&, const map_ptr&)> handler;

DELETE_COPY_MOVE(chaser_check);
Expand All @@ -50,6 +50,7 @@ class BCN_API chaser_check
network::result_handler&& handler) NOEXCEPT;

protected:
virtual void handle_put_hashes(const code&) NOEXCEPT;
virtual void handle_header(height_t branch_point) NOEXCEPT;
virtual void handle_event(const code& ec, chase event_,
link value) NOEXCEPT;
Expand All @@ -58,8 +59,11 @@ class BCN_API chaser_check
virtual void do_put_hashes(const map_ptr& map,
const network::result_handler& handler) NOEXCEPT;

// This is thread safe.
const size_t inventory_;

// This is protected by strand.
map_ptr map_{};
database::associations map_{};
};

} // namespace node
Expand Down
12 changes: 9 additions & 3 deletions include/bitcoin/node/protocols/protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,25 @@ class BCN_API protocol
virtual void organize(const system::chain::header::cptr& header,
chaser::organize_handler&& handler) NOEXCEPT;

/// Organize a validated block.
/// Organize a checked block.
virtual void organize(const system::chain::block::cptr& block,
chaser::organize_handler&& handler) NOEXCEPT;

/// Manage download queue.
/// Get block hashes for blocks to download.
virtual void get_hashes(chaser_check::handler&& handler) NOEXCEPT;

/// Submit block hashes for blocks not downloaded.
virtual void put_hashes(const chaser_check::map_ptr& map,
network::result_handler&& handler) NOEXCEPT;

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

/// Subscribe to chaser events.
virtual void async_subscribe_events(
chaser::event_handler&& handler) NOEXCEPT;

/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;

Expand Down
5 changes: 4 additions & 1 deletion include/bitcoin/node/protocols/protocol_block_in_31800.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BCN_API protocol_block_in_31800
type_id::witness_block : type_id::block),
performance_timer_(std::make_shared<network::deadline>(session.log,
channel->strand(), session.config().node.sample_period())),
map_(std::make_shared<database::context_map>())
map_(std::make_shared<database::associations>())
{
}
BC_POP_WARNING()
Expand Down Expand Up @@ -84,6 +84,9 @@ class BCN_API protocol_block_in_31800
const map_ptr& map) NOEXCEPT;

private:
void reset_performance() NOEXCEPT;
void set_performance(uint64_t rate) NOEXCEPT;

void do_handle_performance(const code& ec) NOEXCEPT;
network::messages::get_data create_get_data(
const map_ptr& map) const NOEXCEPT;
Expand Down
15 changes: 10 additions & 5 deletions include/bitcoin/node/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_HPP
#define LIBBITCOIN_NODE_SESSIONS_SESSION_HPP

#include <memory>
#include <bitcoin/network.hpp>
#include <bitcoin/node/chasers/chasers.hpp>
#include <bitcoin/node/define.hpp>
Expand All @@ -27,7 +28,8 @@
namespace libbitcoin {
namespace node {

/// Common session context.
/// Common session context, presumes will be joined with network::session.
/// This could be templatized on the sibling, but there only one implemented.
class BCN_API session
{
public:
Expand All @@ -50,25 +52,28 @@ class BCN_API session
virtual void put_hashes(const chaser_check::map_ptr& map,
network::result_handler&& handler) NOEXCEPT;

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

/// Subscribe to chaser events.
virtual void async_subscribe_events(
chaser::event_handler&& handler) NOEXCEPT;

/// Configuration settings for all libraries.
const configuration& config() const NOEXCEPT;

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

protected:

/// Construct/destruct the session.
session(full_node& node) NOEXCEPT;

/// Asserts that session is stopped.
~session() NOEXCEPT;

private:
void do_subscribe_events(const chaser::event_handler& handler) NOEXCEPT;

// This is thread safe (mostly).
full_node& node_;
};
Expand Down
5 changes: 4 additions & 1 deletion include/bitcoin/node/sessions/session_outbound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ class BCN_API session_outbound
void do_performance(uint64_t channel, uint64_t speed,
const network::result_handler& handler) NOEXCEPT;

// This is thread safe.
const float allowed_deviation_;

// This is protected by strand.
std::unordered_map<uint64_t, double> speeds_;
std::unordered_map<uint64_t, double> speeds_{};
};

} // namespace node
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class BCN_API settings

/// Properties.
float allowed_deviation;
uint16_t maximum_inventory;
uint16_t sample_period_seconds;
uint32_t currency_window_minutes;

Expand Down
43 changes: 0 additions & 43 deletions install-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,7 @@ build_from_tarball_boost()
display_message "BOOST_OPTIONS : $*"
display_message "--------------------------------------------------------------------"

guessed_toolset=`./tools/build/src/engine/build.sh --guess-toolset`
CXXFLAGS="-w" ./tools/build/src/engine/build.sh ${guessed_toolset} --cxxflags="-w"
cp tools/build/src/engine/b2 .

./bootstrap.sh \
"--with-bjam=./b2" \
"--prefix=$PREFIX" \
"--with-icu=$ICU_PREFIX"

Expand All @@ -896,7 +891,6 @@ build_from_tarball_boost()
"$BOOST_CXXFLAGS" \
"$BOOST_LINKFLAGS" \
"link=$BOOST_LINK" \
"warnings=off" \
"boost.locale.iconv=$BOOST_ICU_ICONV" \
"boost.locale.posix=$BOOST_ICU_POSIX" \
"-sNO_BZIP2=1" \
Expand All @@ -920,42 +914,19 @@ build_from_tarball_boost()
build_all()
{
unpack_from_tarball "$ICU_ARCHIVE" "$ICU_URL" gzip "$BUILD_ICU"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${ICU_FLAGS[@]}"
build_from_tarball "$ICU_ARCHIVE" source "$PARALLEL" "$BUILD_ICU" "${ICU_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS
export CPPFLAGS=$SAVE_CPPFLAGS
unpack_from_tarball "$BOOST_ARCHIVE" "$BOOST_URL" bzip2 "$BUILD_BOOST"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BOOST_FLAGS[@]}"
build_from_tarball_boost "$BOOST_ARCHIVE" "$PARALLEL" "$BUILD_BOOST" "${BOOST_OPTIONS[@]}"
export CPPFLAGS=$SAVE_CPPFLAGS
create_from_github libbitcoin secp256k1 version8 "yes"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${SECP256K1_FLAGS[@]}"
build_from_github secp256k1 "$PARALLEL" false "yes" "${SECP256K1_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS
export CPPFLAGS=$SAVE_CPPFLAGS
create_from_github libbitcoin libbitcoin-system master "yes"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BITCOIN_SYSTEM_FLAGS[@]}"
build_from_github_cmake libbitcoin-system "$PARALLEL" false "yes" "${BITCOIN_SYSTEM_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS_CMAKE "$@"
export CPPFLAGS=$SAVE_CPPFLAGS
create_from_github libbitcoin libbitcoin-network master "yes"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BITCOIN_NETWORK_FLAGS[@]}"
build_from_github_cmake libbitcoin-network "$PARALLEL" false "yes" "${BITCOIN_NETWORK_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS_CMAKE "$@"
export CPPFLAGS=$SAVE_CPPFLAGS
create_from_github libbitcoin libbitcoin-database master "yes"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BITCOIN_DATABASE_FLAGS[@]}"
build_from_github_cmake libbitcoin-database "$PARALLEL" false "yes" "${BITCOIN_DATABASE_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS_CMAKE "$@"
export CPPFLAGS=$SAVE_CPPFLAGS
create_from_github libbitcoin libbitcoin-consensus master "$WITH_BITCOIN_CONSENSUS"
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BITCOIN_CONSENSUS_FLAGS[@]}"
build_from_github_cmake libbitcoin-consensus "$PARALLEL" false "$WITH_BITCOIN_CONSENSUS" "${BITCOIN_CONSENSUS_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS_CMAKE "$@"
export CPPFLAGS=$SAVE_CPPFLAGS
local SAVE_CPPFLAGS="$CPPFLAGS"
export CPPFLAGS="$CPPFLAGS ${BITCOIN_NODE_FLAGS[@]}"
if [[ ! ($CI == true) ]]; then
create_from_github libbitcoin libbitcoin-node master "yes"
build_from_github_cmake libbitcoin-node "$PARALLEL" true "yes" "${BITCOIN_NODE_OPTIONS[@]}" $CUMULATIVE_FILTERED_ARGS_CMAKE "$@"
Expand All @@ -966,7 +937,6 @@ build_all()
pop_directory
pop_directory
fi
export CPPFLAGS=$SAVE_CPPFLAGS
}


Expand All @@ -988,19 +958,6 @@ set_with_boost_prefix

remove_install_options

# Define build flags.
#==============================================================================
# Define icu flags.
#------------------------------------------------------------------------------
ICU_FLAGS=(
"-w")

# Define secp256k1 flags.
#------------------------------------------------------------------------------
SECP256K1_FLAGS=(
"-w")


# Define build options.
#==============================================================================
# Define icu options.
Expand Down
Loading

0 comments on commit b0b1f54

Please sign in to comment.