Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into fix/kusama_backed_c…
Browse files Browse the repository at this point in the history
…andidates

Signed-off-by: iceseer <[email protected]>

# Conflicts:
#	core/log/formatters/optional.hpp
#	core/parachain/approval/approval_distribution.cpp
#	core/parachain/availability/recovery/recovery_impl.cpp
#	core/parachain/validator/impl/parachain_processor.cpp
#	core/parachain/validator/parachain_processor.hpp
  • Loading branch information
iceseer committed Sep 28, 2024
2 parents 0407c69 + bf3fc8c commit cd60736
Show file tree
Hide file tree
Showing 35 changed files with 554 additions and 255 deletions.
6 changes: 0 additions & 6 deletions core/application/app_configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,6 @@ namespace kagome::application {
*/
virtual bool usePvfSubprocess() const = 0;

/**
* Timeout for Pvf check calls execution.
* Effective only when usePvfSubprocess() == true.
*/
virtual std::chrono::milliseconds pvfSubprocessDeadline() const = 0;

/**
* Max PVF execution threads or processes.
*/
Expand Down
8 changes: 1 addition & 7 deletions core/application/impl/app_configuration_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ namespace kagome::application {
desc.add_options()
("help,h", "show this help message")
("version,v", "show version information")
("logcfg", po::value<std::string>(), "optional, path to config file of logger")
("log,l", po::value<std::vector<std::string>>(),
"Sets a custom logging filter. Syntax is `<target>=<level>`, e.g. -llibp2p=off.\n"
"Log levels (most to least verbose) are trace, debug, verbose, info, warn, error, critical, off. By default, all targets log `info`.\n"
Expand Down Expand Up @@ -898,8 +899,6 @@ namespace kagome::application {
"Number of threads that precompile parachain runtime modules at node startup")
("parachain-single-process", po::bool_switch(),
"Disables spawn of child pvf check processes, thus they could not be aborted by deadline timer")
("parachain-check-deadline", po::value<uint32_t>()->default_value(2000),
"Pvf check subprocess execution deadline in milliseconds")
("pvf-max-workers", po::value<size_t>()->default_value(pvf_max_workers_),
"Max PVF execution threads or processes.")
("insecure-validator-i-know-what-i-do", po::bool_switch(), "Allows a validator to run insecurely outside of Secure Validator Mode.")
Expand Down Expand Up @@ -1520,11 +1519,6 @@ namespace kagome::application {
}
logger_->info("Parachain multi process: {}", use_pvf_subprocess_);

if (auto arg = find_argument<uint32_t>(vm, "parachain-check-deadline");
arg.has_value()) {
pvf_subprocess_deadline_ = std::chrono::milliseconds(*arg);
}

if (auto arg = find_argument<size_t>(vm, "pvf-max-workers")) {
pvf_max_workers_ = *arg;
}
Expand Down
4 changes: 0 additions & 4 deletions core/application/impl/app_configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,6 @@ namespace kagome::application {
bool usePvfSubprocess() const override {
return use_pvf_subprocess_;
}
std::chrono::milliseconds pvfSubprocessDeadline() const override {
return pvf_subprocess_deadline_;
}
size_t pvfMaxWorkers() const override {
return pvf_max_workers_;
}
Expand Down Expand Up @@ -387,7 +384,6 @@ namespace kagome::application {
std::thread::hardware_concurrency() / 2;
bool should_precompile_parachain_modules_{true};
bool use_pvf_subprocess_{true};
std::chrono::milliseconds pvf_subprocess_deadline_{2000};
size_t pvf_max_workers_{
std::max<size_t>(std::thread::hardware_concurrency(), 1)};
bool disable_secure_mode_{false};
Expand Down
6 changes: 2 additions & 4 deletions core/application/impl/kagome_application_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,8 @@ namespace kagome::application {
}

#ifdef __linux__
if (!app_config_->disableSecureMode()
&& app_config_->usePvfSubprocess()
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
&& app_config_->roles().flags.authority) {
if (not app_config_->disableSecureMode() and app_config_->usePvfSubprocess()
and app_config_->roles().isAuthority()) {
auto res = parachain::runSecureModeCheckProcess(
*injector_.injectIoContext(), app_config_->runtimeCacheDirPath());
if (!res) {
Expand Down
2 changes: 1 addition & 1 deletion core/application/modes/precompile_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace kagome::application::mode {
auto code_hash = hasher_->blake2b_256(bytes);
OUTCOME_TRY(config,
parachain::sessionParams(*parachain_api_, block.hash));
OUTCOME_TRY(module_factory_->precompile(code_hash, bytes, config));
OUTCOME_TRY(module_factory_->precompile(code_hash, bytes, config.context_params));
}
return outcome::success();
}
Expand Down
3 changes: 1 addition & 2 deletions core/authority_discovery/publisher/address_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ namespace kagome::authority_discovery {
if (not libp2p_key_) {
return true;
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (not roles_.flags.authority) {
if (not roles_.isAuthority()) {
return true;
}
interval_.start([weak_self{weak_from_this()}] {
Expand Down
7 changes: 3 additions & 4 deletions core/blockchain/impl/block_tree_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,16 @@ namespace kagome::blockchain {

} block_tree_data_;

primitives::events::ExtrinsicSubscriptionEnginePtr
extrinsic_events_engine_ = {};
primitives::events::ChainSubscriptionEnginePtr chain_events_engine_ = {};
primitives::events::ChainSubscriptionEnginePtr chain_events_engine_;
std::shared_ptr<PoolHandler> main_pool_handler_;
primitives::events::ExtrinsicSubscriptionEnginePtr extrinsic_events_engine_;
log::Logger log_ = log::createLogger("BlockTree", "block_tree");

// Metrics
metrics::RegistryPtr metrics_registry_ = metrics::createRegistry();
metrics::Gauge *metric_best_block_height_;
metrics::Gauge *metric_finalized_block_height_;
metrics::Gauge *metric_known_chain_leaves_;
std::shared_ptr<PoolHandler> main_pool_handler_;
telemetry::Telemetry telemetry_ = telemetry::createTelemetryService();
};
} // namespace kagome::blockchain
3 changes: 1 addition & 2 deletions core/consensus/babe/impl/babe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ namespace kagome::consensus::babe {
offchain_worker_pool_(std::move(offchain_worker_pool)),
main_pool_handler_{main_thread_pool.handler(app_state_manager)},
worker_pool_handler_{worker_thread_pool.handler(app_state_manager)},
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
is_validator_by_config_(app_config.roles().flags.authority != 0),
is_validator_by_config_(app_config.roles().isAuthority()),
telemetry_{telemetry::createTelemetryService()} {
BOOST_ASSERT(block_tree_);
BOOST_ASSERT(config_repo_);
Expand Down
3 changes: 1 addition & 2 deletions core/crypto/key_store/session_keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace kagome::crypto {
const KeySuiteStore<T> &store,
const std::vector<A> &authorities,
const Eq &eq) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (not roles_.flags.authority) {
if (not roles_.isAuthority()) {
return std::nullopt;
}
if (cache) {
Expand Down
1 change: 1 addition & 0 deletions core/log/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ add_library(log_configurator
)
target_link_libraries(log_configurator
soralog::configurator_yaml
Boost::program_options
)
kagome_install(log_configurator)
30 changes: 30 additions & 0 deletions core/log/configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "log/configurator.hpp"

#include <boost/program_options.hpp>

namespace kagome::log {

namespace {
Expand Down Expand Up @@ -138,4 +140,32 @@ namespace kagome::log {
Configurator::Configurator(std::shared_ptr<PrevConfigurator> previous,
filesystem::path path)
: ConfiguratorFromYAML(std::move(previous), std::move(path)) {}

std::optional<filesystem::path> Configurator::getLogConfigFile(
int argc, const char **argv) {
namespace po = boost::program_options;
po::options_description desc("General options");
desc.add_options()
// clang-format off
("logcfg", po::value<std::string>(), "optional, path to logging config file")
// clang-format on
;

po::variables_map vm;

po::parsed_options parsed = po::command_line_parser(argc, argv)
.options(desc)
.allow_unregistered()
.run();
po::store(parsed, vm);
po::notify(vm);

if (auto it = vm.find("logcfg"); it != vm.end()) {
if (not it->second.defaulted()) {
return it->second.as<std::string>();
}
}
return std::nullopt;
}

} // namespace kagome::log
3 changes: 3 additions & 0 deletions core/log/configurator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ namespace kagome::log {

explicit Configurator(std::shared_ptr<PrevConfigurator> previous,
filesystem::path path);

static std::optional<filesystem::path> getLogConfigFile(int argc,
const char **argv);
};

} // namespace kagome::log
52 changes: 7 additions & 45 deletions core/log/formatters/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,24 @@

#pragma once

#include <fmt/core.h>
#include <fmt/format.h>

#include <optional>
#include <ranges>
#include <string_view>

#include <boost/optional.hpp>

template <typename T>
struct fmt::formatter<std::optional<T>> {
template <template <typename> class Optional, typename T>
requires std::is_same_v<Optional<T>, std::optional<T>>
or std::is_same_v<Optional<T>, boost::optional<T>>
struct fmt::formatter<Optional<T>> {
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
// Parse the presentation format and store it in the formatter:
auto it = ctx.begin(), end = ctx.end();

// Check if reached the end of the range:
if (it != end && *it != '}') {
throw format_error("invalid format");
}

// Return an iterator past the end of the parsed range:
return it;
}

template <typename FormatContext>
auto format(const std::optional<T> &opt, FormatContext &ctx) const
-> decltype(ctx.out()) {
// ctx.out() is an output iterator to write to.

if (opt.has_value()) {
return fmt::format_to(ctx.out(), "{}", opt.value());
}
static constexpr std::string_view message("<none>");
return std::copy(std::begin(message), std::end(message), ctx.out());
}
};

template <typename T>
struct fmt::formatter<boost::optional<T>> {
// Parses format specifications of the form ['s' | 'l'].
constexpr auto parse(format_parse_context &ctx) -> decltype(ctx.begin()) {
// Parse the presentation format and store it in the formatter:
auto it = ctx.begin(), end = ctx.end();

// Check if reached the end of the range:
if (it != end && *it != '}') {
throw format_error("invalid format");
}

// Return an iterator past the end of the parsed range:
return it;
return ctx.begin();
}

// Formats the BlockInfo using the parsed format specification (presentation)
// stored in this formatter.
template <typename FormatContext>
auto format(const boost::optional<T> &opt, FormatContext &ctx) const
auto format(const Optional<T> &opt, FormatContext &ctx) const
-> decltype(ctx.out()) {
// ctx.out() is an output iterator to write to.

Expand Down
13 changes: 4 additions & 9 deletions core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,7 @@ namespace kagome::network {
network::CollationVersion
proto_version) { // network::CollationVersion::VStaging
/// If validator start validation protocol
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (peer_state.roles.flags.authority) {
if (peer_state.roles.isAuthority()) {
auto validation_protocol = [&]() -> std::shared_ptr<ProtocolBase> {
return router_->getValidationProtocolVStaging();
}();
Expand Down Expand Up @@ -842,16 +841,14 @@ namespace kagome::network {
if (peer_state.has_value()) {
auto &state = peer_state->get();
if (not out) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (state.roles.flags.full == 1) {
if (state.roles.isFull()) {
if (self->countPeers(PeerType::PEER_TYPE_IN)
>= self->app_config_.inPeers()) {
self->connecting_peers_.erase(peer_info.id);
self->disconnectFromPeer(peer_info.id);
return;
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
} else if (state.roles.flags.light == 1) {
} else {
if (self->countPeers(PeerType::PEER_TYPE_IN, IsLight(true))
>= self->app_config_.inPeersLight()) {
self->connecting_peers_.erase(peer_info.id);
Expand Down Expand Up @@ -887,9 +884,7 @@ namespace kagome::network {
}

void PeerManagerImpl::reserveStatusStreams(const PeerId &peer_id) const {
if (auto ps = getPeerState(peer_id);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
ps && ps->get().roles.flags.authority) {
if (auto ps = getPeerState(peer_id); ps && ps->get().roles.isAuthority()) {
auto proto_val_vstaging = router_->getValidationProtocolVStaging();
BOOST_ASSERT_MSG(proto_val_vstaging,
"Router did not provide validation protocol vstaging");
Expand Down
10 changes: 3 additions & 7 deletions core/network/impl/protocols/grandpa_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ namespace kagome::network {

auto filter = [&, &msg = vote_message](const PeerId &peer_id,
const PeerState &info) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (info.roles.flags.light != 0) {
if (info.roles.isLight()) {
return false;
}

Expand Down Expand Up @@ -263,8 +262,7 @@ namespace kagome::network {
}
const auto &info = info_opt.value().get();

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
if (not set_changed and info.roles.flags.light) {
if (not set_changed and info.roles.isLight()) {
return false;
}

Expand Down Expand Up @@ -538,9 +536,7 @@ namespace kagome::network {
if (not predicate(peer, info)) {
return;
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
(info.roles.flags.authority != 0 ? authorities : any)
.emplace_back(peer);
(info.roles.isAuthority() ? authorities : any).emplace_back(peer);
}
});
auto hash = getHash(*message);
Expand Down
Loading

0 comments on commit cd60736

Please sign in to comment.