Skip to content

Commit

Permalink
fix warnings (#1932)
Browse files Browse the repository at this point in the history
Signed-off-by: iceseer <iceseer@gmail.com>
  • Loading branch information
iceseer authored Jan 17, 2024
1 parent 9cac834 commit 7e43d5e
Show file tree
Hide file tree
Showing 31 changed files with 108 additions and 97 deletions.
2 changes: 1 addition & 1 deletion core/api/service/impl/api_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace kagome::api {
bool ApiServiceImpl::prepare() {
for (const auto &listener : listeners_) {
auto on_new_session =
[wp = weak_from_this()](const sptr<Session> &session) mutable {
[wp{weak_from_this()}](const sptr<Session> &session) mutable {
auto self = wp.lock();
if (!self) {
return;
Expand Down
6 changes: 3 additions & 3 deletions core/api/transport/impl/ws/ws_listener_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ namespace kagome::api {
}

void WsListenerImpl::acceptOnce() {
auto get_id = [weak = weak_from_this()]() -> Session::SessionId {
auto get_id = [weak{weak_from_this()}]() -> Session::SessionId {
if (auto self = weak.lock()) {
return self->next_session_id_++;
}
return 0;
};
new_session_ = std::make_shared<SessionImpl>(
*context_, get_id, on_new_session_, allow_unsafe_, session_config_);
auto session_stopped_handler = [wp = weak_from_this()] {
auto session_stopped_handler = [wp{weak_from_this()}] {
if (auto self = wp.lock()) {
self->closed_session_->inc();
--self->active_connections_;
Expand All @@ -112,7 +112,7 @@ namespace kagome::api {
}
};

auto on_accept = [wp = weak_from_this(),
auto on_accept = [wp{weak_from_this()},
session_stopped_handler](boost::system::error_code ec) {
if (auto self = wp.lock()) {
if (not ec) {
Expand Down
2 changes: 1 addition & 1 deletion core/application/impl/app_configuration_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace kagome::application {
// clang-format on

class AppConfigurationImpl final : public AppConfiguration {
using FilePtr = std::unique_ptr<std::FILE, decltype(&std::fclose)>;
using FilePtr = std::unique_ptr<std::FILE, int (*)(FILE *)>;

public:
explicit AppConfigurationImpl(log::Logger logger);
Expand Down
2 changes: 1 addition & 1 deletion core/authority_discovery/query/query_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace kagome::authority_discovery {
queue_.pop_back();

common::Buffer hash{crypto::sha256(authority)};
scheduler_->schedule([=, this, wp = weak_from_this()] {
scheduler_->schedule([=, this, wp{weak_from_this()}] {
if (auto self = wp.lock()) {
std::ignore = kademlia_->getValue(
hash, [=, this](outcome::result<std::vector<uint8_t>> res) {
Expand Down
1 change: 1 addition & 0 deletions core/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ namespace kagome::blockchain {
.extrinsic_event_key_repo_ = std::move(extrinsic_event_key_repo),
.justification_storage_policy_ =
std::move(justification_storage_policy),
.genesis_block_hash_ = {},
.blocks_pruning_ = {app_config.blocksPruning(), finalized.number},
}},
main_thread_{std::move(main_thread)} {
Expand Down
3 changes: 2 additions & 1 deletion core/consensus/babe/impl/babe_lottery_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace kagome::consensus::babe {
auto &config = *config_res.value();

keypair_ = session_keys_->getBabeKeyPair(config.authorities);
if(!keypair_) {
if (!keypair_) {
return false;
}

Expand Down Expand Up @@ -129,6 +129,7 @@ namespace kagome::consensus::babe {
.slot_type = SlotType::SecondaryPlain,
.authority_index = keypair_->second,
.keypair = keypair_->first,
.vrf_output = {},
};
}
} // namespace kagome::consensus::babe
4 changes: 2 additions & 2 deletions core/consensus/grandpa/impl/grandpa_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ namespace kagome::consensus::grandpa {

// Timer to send neighbor message if round does not change long time (1 min)
fallback_timer_handle_ = scheduler_->scheduleWithHandle(
[wp = weak_from_this()] {
[wp{weak_from_this()}] {
auto self = wp.lock();
if (not self) {
return;
Expand Down Expand Up @@ -505,7 +505,7 @@ namespace kagome::consensus::grandpa {
peer_id,
network::CatchUpRequest{msg.round_number - 1, msg.voter_set_id});
catchup_request_timer_handle_ = scheduler_->scheduleWithHandle(
[wp = weak_from_this()] {
[wp{weak_from_this()}] {
auto self = wp.lock();
if (not self) {
return;
Expand Down
2 changes: 1 addition & 1 deletion core/consensus/grandpa/impl/voting_round_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ namespace kagome::consensus::grandpa {

if (can_start_next_round) {
scheduler_->schedule(
[grandpa_wp = std::move(grandpa_), round_wp = weak_from_this()] {
[grandpa_wp = std::move(grandpa_), round_wp{weak_from_this()}] {
if (auto grandpa = grandpa_wp.lock()) {
if (auto round = round_wp.lock()) {
grandpa->tryExecuteNextRound(round);
Expand Down
14 changes: 7 additions & 7 deletions core/consensus/timeline/impl/timeline_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ namespace kagome::consensus {
synchronizer_->syncByBlockHeader(
announce.header,
peer_id,
[wp = weak_from_this(), announce = announce, peer_id](
[wp{weak_from_this()}, announce = announce, peer_id](
outcome::result<primitives::BlockInfo> block_res) mutable {
if (auto self = wp.lock()) {
if (block_res.has_error()) {
Expand Down Expand Up @@ -491,7 +491,7 @@ namespace kagome::consensus {
auto is_ran = synchronizer_->syncByBlockInfo(
target_block,
peer_id,
[wp = weak_from_this(), block = target_block, peer_id](
[wp{weak_from_this()}, block = target_block, peer_id](
outcome::result<primitives::BlockInfo> res) {
if (auto self = wp.lock()) {
if (res.has_error()) {
Expand Down Expand Up @@ -607,7 +607,7 @@ namespace kagome::consensus {
synchronizer_->syncState(
peer_id,
block_at_state,
[wp = weak_from_this(), block_at_state, peer_id](auto res) mutable {
[wp{weak_from_this()}, block_at_state, peer_id](auto res) mutable {
if (auto self = wp.lock()) {
if (res.has_error()) {
SL_WARN(self->log_,
Expand Down Expand Up @@ -676,7 +676,7 @@ namespace kagome::consensus {
remains_ms.count() / 1000.);

scheduler_->schedule(
[wp = weak_from_this()] {
[wp{weak_from_this()}] {
if (auto self = wp.lock()) {
self->runSlot();
}
Expand Down Expand Up @@ -721,8 +721,8 @@ namespace kagome::consensus {
}
}

static const auto &block_production_error_category =
make_error_code(SlotLeadershipError{}).category();
static const auto ec = make_error_code(SlotLeadershipError{});
static const auto &block_production_error_category = ec.category();

/// Try to run block production here
auto consensus = consensus_selector_->getProductionConsensus(best_block_);
Expand Down Expand Up @@ -758,7 +758,7 @@ namespace kagome::consensus {

// everything is OK: wait for the end of the slot
scheduler_->schedule(
[wp = weak_from_this()] {
[wp{weak_from_this()}] {
if (auto self = wp.lock()) {
self->runSlot();
}
Expand Down
3 changes: 2 additions & 1 deletion core/dispute_coordinator/impl/chain_scraper_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace kagome::dispute {

// Ancestors block numbers are consecutive in the descending order.
for (size_t i = 0; i < ancestors.size(); ++i) {
OUTCOME_TRY(fn({activated.number - i - 1, ancestors[i]}));
OUTCOME_TRY(fn(
{activated.number - primitives::BlockNumber(i) - 1, ancestors[i]}));
}

last_observed_blocks_.put(activated.hash, Empty{});
Expand Down
6 changes: 3 additions & 3 deletions core/dispute_coordinator/impl/dispute_coordinator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ namespace kagome::dispute {
waiting_for_active_disputes_.emplace(
WaitForActiveDisputesState{sessions_updated});

internal_context_->execute([wp = weak_from_this()] {
internal_context_->execute([wp{weak_from_this()}] {
// https://github.com/paritytech/polkadot/blob/40974fb99c86f5c341105b7db53c7aa0df707d66/node/network/dispute-distribution/src/sender/mod.rs#L219
if (auto self = wp.lock()) {
self->getActiveDisputes([wp](auto active_disputes_res) {
Expand Down Expand Up @@ -2062,7 +2062,7 @@ namespace kagome::dispute {
primitives::BlockInfo last(base_number, base_hash);

if (not descriptions.empty()) {
last = {last.number + descriptions.size(),
last = {last.number + primitives::BlockNumber(descriptions.size()),
descriptions.back().block_hash};
}

Expand Down Expand Up @@ -2162,7 +2162,7 @@ namespace kagome::dispute {
rate_limit_timer_.emplace(int_pool_->io_context());

rate_limit_timer_->expiresAfter(kReceiveRateLimit);
rate_limit_timer_->asyncWait([wp = weak_from_this()](auto &&ec) {
rate_limit_timer_->asyncWait([wp{weak_from_this()}](auto &&ec) {
if (auto self = wp.lock()) {
if (ec) {
SL_ERROR(self->log_,
Expand Down
29 changes: 14 additions & 15 deletions core/dispute_coordinator/impl/sending_dispute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,20 @@ namespace kagome::dispute {

for (auto &[authority_id, peer_id] : receivers) {
deliveries_.emplace(authority_id, DeliveryStatus::Pending);
protocol->doRequest(peer_id,
request_,
[wp = weak_from_this(),
authority_id(authority_id)](auto res) mutable {
if (auto self = wp.lock()) {
if (res.has_value()) {
self->deliveries_[authority_id] =
DeliveryStatus::Succeeded;
} else {
// LOG Can't sent dispute request to peer {}
self->deliveries_.erase(authority_id);
self->has_failed_sends_ = true;
}
}
});
protocol->doRequest(
peer_id,
request_,
[wp{weak_from_this()}, authority_id(authority_id)](auto res) mutable {
if (auto self = wp.lock()) {
if (res.has_value()) {
self->deliveries_[authority_id] = DeliveryStatus::Succeeded;
} else {
// LOG Can't sent dispute request to peer {}
self->deliveries_.erase(authority_id);
self->has_failed_sends_ = true;
}
}
});
}

// SL_TRACE(log_, "Requests dispatched. Sent {} requests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace kagome::dispute {
ParticipationRequest request, primitives::BlockHash recent_head) {
if (running_participations_.emplace(request.candidate_hash).second) {
// https://github.com/paritytech/polkadot/blob/40974fb99c86f5c341105b7db53c7aa0df707d66/node/core/dispute-coordinator/src/participation/mod.rs#L256
internal_context_->execute([wp = weak_from_this(),
internal_context_->execute([wp{weak_from_this()},
request{std::move(request)},
recent_head{std::move(recent_head)}]() {
if (auto self = wp.lock()) {
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace kagome::dispute {
ctx->request.candidate_receipt,
ctx->request.session,
std::nullopt,
[wp = weak_from_this(), ctx, cb = std::move(cb)](auto res_opt) mutable {
[wp{weak_from_this()}, ctx, cb = std::move(cb)](auto res_opt) mutable {
if (auto self = wp.lock()) {
if (not res_opt.has_value()) {
cb(ParticipationOutcome::Unavailable);
Expand Down
2 changes: 1 addition & 1 deletion core/metrics/impl/exposer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace kagome::metrics {
std::placeholders::_1,
std::placeholders::_2));

auto on_accept = [wp = weak_from_this()](boost::system::error_code ec) {
auto on_accept = [wp{weak_from_this()}](boost::system::error_code ec) {
if (auto self = wp.lock()) {
if (not ec) {
self->new_session_->start();
Expand Down
6 changes: 3 additions & 3 deletions core/network/beefy/beefy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace kagome::network {

void Beefy::onJustification(const primitives::BlockHash &block_hash,
primitives::Justification raw) {
strand_->post([weak = weak_from_this(), block_hash, raw = std::move(raw)] {
strand_->post([weak{weak_from_this()}, block_hash, raw = std::move(raw)] {
if (auto self = weak.lock()) {
std::ignore = self->onJustificationOutcome(block_hash, std::move(raw));
}
Expand All @@ -109,7 +109,7 @@ namespace kagome::network {
}

void Beefy::onMessage(consensus::beefy::BeefyGossipMessage message) {
strand_->post([weak = weak_from_this(), message = std::move(message)] {
strand_->post([weak{weak_from_this()}, message = std::move(message)] {
if (auto self = weak.lock()) {
self->onMessageStrand(std::move(message));
}
Expand Down Expand Up @@ -230,7 +230,7 @@ namespace kagome::network {
});
}
});
strand_->post([weak = weak_from_this()] {
strand_->post([weak{weak_from_this()}] {
if (auto self = weak.lock()) {
std::ignore = self->update();
}
Expand Down
20 changes: 11 additions & 9 deletions core/network/impl/peer_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace kagome::network {
add_peer_handle_ =
host_.getBus()
.getChannel<libp2p::event::protocol::kademlia::PeerAddedChannel>()
.subscribe([wp = weak_from_this()](const PeerId &peer_id) {
.subscribe([wp{weak_from_this()}](const PeerId &peer_id) {
if (auto self = wp.lock()) {
if (auto rating =
self->reputation_repository_->reputation(peer_id);
Expand All @@ -168,7 +168,7 @@ namespace kagome::network {
peer_disconnected_handler_ =
host_.getBus()
.getChannel<libp2p::event::network::OnPeerDisconnectedChannel>()
.subscribe([wp = weak_from_this()](const PeerId &peer_id) {
.subscribe([wp{weak_from_this()}](const PeerId &peer_id) {
if (auto self = wp.lock()) {
SL_DEBUG(self->log_,
"OnPeerDisconnectedChannel handler from peer {}",
Expand All @@ -186,7 +186,7 @@ namespace kagome::network {
}
});

identify_->onIdentifyReceived([wp = weak_from_this()](
identify_->onIdentifyReceived([wp{weak_from_this()}](
const PeerId &peer_id) {
if (auto self = wp.lock()) {
SL_DEBUG(self->log_, "Identify received from peer {}", peer_id);
Expand Down Expand Up @@ -265,8 +265,10 @@ namespace kagome::network {
const network::CollatorPublicKey &collator_id,
network::ParachainId para_id) {
if (auto it = peer_states_.find(peer_id); it != peer_states_.end()) {
it->second.collator_state =
CollatorState{.parachain_id = para_id, .collator_id = collator_id};
it->second.collator_state = CollatorState{
.parachain_id = para_id,
.collator_id = collator_id,
};
it->second.time = clock_->now();
}

Expand Down Expand Up @@ -393,7 +395,7 @@ namespace kagome::network {
const auto aligning_period = app_config_.peeringConfig().aligningPeriod;

align_timer_ = scheduler_->scheduleWithHandle(
[wp = weak_from_this()] {
[wp{weak_from_this()}] {
if (auto self = wp.lock()) {
self->align();
}
Expand Down Expand Up @@ -430,7 +432,7 @@ namespace kagome::network {

host_.connect(
peer_info,
[wp = weak_from_this(), peer_id](auto res) mutable {
[wp{weak_from_this()}, peer_id](auto res) mutable {
auto self = wp.lock();
if (not self) {
return;
Expand Down Expand Up @@ -509,7 +511,7 @@ namespace kagome::network {

ping_protocol->startPinging(
conn,
[wp = weak_from_this(), peer_id, conn](
[wp{weak_from_this()}, peer_id, conn](
outcome::result<std::shared_ptr<
libp2p::protocol::PingClientSession>> session_res) {
if (auto self = wp.lock()) {
Expand Down Expand Up @@ -606,7 +608,7 @@ namespace kagome::network {
stream_engine_,
block_announce_protocol,
peer_info,
[wp = weak_from_this(),
[wp{weak_from_this()},
peer_info,
protocol = block_announce_protocol,
connection,
Expand Down
4 changes: 3 additions & 1 deletion core/network/impl/peer_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ namespace kagome::network {
.finalized_number_ =
self->block_tree_.get()->getLastFinalized().number,
},
.new_head = (*value).get()});
.new_head = (*value).get(),
.lost = {},
});
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions core/network/impl/protocols/grandpa_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace kagome::network {
bool GrandpaProtocol::start() {
auto stream = std::make_shared<LoopbackStream>(own_info_, io_context_);
stream_engine_->addBidirectional(stream, shared_from_this());
auto on_message = [weak = weak_from_this(),
auto on_message = [weak{weak_from_this()},
peer_id = own_info_.id](GrandpaMessage message) {
auto self = weak.lock();
if (not self) {
Expand Down Expand Up @@ -457,7 +457,7 @@ namespace kagome::network {
}

scheduler_->schedule(
[wp = weak_from_this(), round_id, peer_id] {
[wp{weak_from_this()}, round_id, peer_id] {
if (auto self = wp.lock()) {
self->recent_catchup_requests_by_round_.erase(round_id);
self->recent_catchup_requests_by_peer_.erase(peer_id);
Expand Down
Loading

0 comments on commit 7e43d5e

Please sign in to comment.