From 58539886adcd2aecaab9a3c3826be794fb438059 Mon Sep 17 00:00:00 2001 From: kamilsa Date: Tue, 5 Sep 2023 18:16:56 +0600 Subject: [PATCH] Comment assert, add zombienet test This commit includes changes for dispute finality handling and experimentation on transaction pool implementation. The changes implemented in the core/dispute_coordinator/impl/dispute_coordinator_impl.cpp file remove all debugging statements to improve readability and ensure cleaner code. Some adjustments have also been made to improve efficiency and avoid unnecessary computations. In the file core/transaction_pool/impl/transaction_pool_impl.cpp, a commented assertion has been added, signifying a pending fix on issue #1786. Furthermore, configuration files for the zombienet had been deployed focusing on dispute resilience within the parachain validators' network layer. These configurations will prompt validation nodes to report any discrepancies on the chain, ensuring the integrity of the block records. These modifications are crucial for maintaining the stability, security, and efficiency of the blockchain system. --- .../grandpa/impl/voting_round_impl.cpp | 106 +++++++++++------- .../grandpa/impl/voting_round_impl.hpp | 3 +- core/consensus/grandpa/voting_round.hpp | 2 +- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/core/consensus/grandpa/impl/voting_round_impl.cpp b/core/consensus/grandpa/impl/voting_round_impl.cpp index 32f7b43f14..d6126894c9 100644 --- a/core/consensus/grandpa/impl/voting_round_impl.cpp +++ b/core/consensus/grandpa/impl/voting_round_impl.cpp @@ -227,8 +227,13 @@ namespace kagome::consensus::grandpa { SL_DEBUG(logger_, "Round #{}: Start round", round_number_); - pending_timer_handle_ = - scheduler_->scheduleWithHandle([&] { pending(); }, pending_interval_); + pending_timer_handle_ = scheduler_->scheduleWithHandle( + [wp = weak_from_this()] { + if (auto self = wp.lock()) { + self->pending(); + } + }, + pending_interval_); sendNeighborMessage(); @@ -281,20 +286,26 @@ namespace kagome::consensus::grandpa { } stage_timer_handle_ = scheduler_->scheduleWithHandle( - [&] { - if (stage_ == Stage::PREVOTE_RUNS) { - SL_DEBUG(logger_, - "Round #{}: Time of prevote stage is out", - round_number_); - endPrevoteStage(); + [wp = weak_from_this()] { + if (auto self = wp.lock()) { + if (self->stage_ == Stage::PREVOTE_RUNS) { + SL_DEBUG(self->logger_, + "Round #{}: Time of prevote stage is out", + self->round_number_); + self->endPrevoteStage(); + } } }, toMilliseconds(duration_ * 2 - (scheduler_->now() - start_time_))); - on_complete_handler_ = [this] { - if (stage_ == Stage::PREVOTE_RUNS) { - SL_DEBUG(logger_, "Round #{}: Became completable", round_number_); - endPrevoteStage(); + on_complete_handler_ = [wp = weak_from_this()] { + if (auto self = wp.lock()) { + if (self->stage_ == Stage::PREVOTE_RUNS) { + SL_DEBUG(self->logger_, + "Round #{}: Became completable", + self->round_number_); + self->endPrevoteStage(); + } } }; @@ -346,20 +357,26 @@ namespace kagome::consensus::grandpa { } stage_timer_handle_ = scheduler_->scheduleWithHandle( - [&] { - if (stage_ == Stage::PRECOMMIT_RUNS) { - SL_DEBUG(logger_, - "Round #{}: Time of precommit stage is out", - round_number_); - endPrecommitStage(); + [wp = weak_from_this()] { + if (auto self = wp.lock()) { + if (self->stage_ == Stage::PRECOMMIT_RUNS) { + SL_DEBUG(self->logger_, + "Round #{}: Time of precommit stage is out", + self->round_number_); + self->endPrecommitStage(); + } } }, toMilliseconds(duration_ * 4 - (scheduler_->now() - start_time_))); - on_complete_handler_ = [this] { - if (stage_ == Stage::PRECOMMIT_RUNS) { - SL_DEBUG(logger_, "Round #{}: Became completable", round_number_); - endPrecommitStage(); + on_complete_handler_ = [wp = weak_from_this()] { + if (auto self = wp.lock()) { + if (self->stage_ == Stage::PRECOMMIT_RUNS) { + SL_DEBUG(self->logger_, + "Round #{}: Became completable", + self->round_number_); + self->endPrecommitStage(); + } } }; @@ -430,19 +447,21 @@ namespace kagome::consensus::grandpa { SL_DEBUG(logger_, "Round #{}: Start final stage", round_number_); - on_complete_handler_ = [&] { - const bool is_ready_to_end = - finalized_.has_value() - and finalized_->number - >= (previous_round_ - ? previous_round_->bestFinalCandidate().number - : last_finalized_block_.number); - - if (is_ready_to_end) { - SL_DEBUG(logger_, - "Round #{}: Conditions for final stage are met", - round_number_); - endWaitingStage(); + on_complete_handler_ = [wp = weak_from_this()] { + if (auto self = wp.lock()) { + const bool is_ready_to_end = + self->finalized_.has_value() + and self->finalized_->number + >= (self->previous_round_ + ? self->previous_round_->bestFinalCandidate().number + : self->last_finalized_block_.number); + + if (is_ready_to_end) { + SL_DEBUG(self->logger_, + "Round #{}: Conditions for final stage are met", + self->round_number_); + self->endWaitingStage(); + } } }; @@ -1086,9 +1105,11 @@ namespace kagome::consensus::grandpa { need_to_update_estimate = true; } if (prevote_ghost_) { - scheduler_->schedule([&] { - if (stage_ == Stage::PRECOMMIT_WAITS_FOR_PREVOTES) { - endPrecommitStage(); + scheduler_->schedule([wp = weak_from_this()] { + if (auto self = wp.lock()) { + if (self->stage_ == Stage::PRECOMMIT_WAITS_FOR_PREVOTES) { + self->endPrecommitStage(); + } } }); } @@ -1609,7 +1630,12 @@ namespace kagome::consensus::grandpa { SL_DEBUG(logger_, "Resend votes of recent rounds"); resend(shared_from_this()); - pending_timer_handle_ = - scheduler_->scheduleWithHandle([&] { pending(); }, pending_interval_); + pending_timer_handle_ = scheduler_->scheduleWithHandle( + [wp = weak_from_this()] { + if (auto self = wp.lock()) { + self->pending(); + } + }, + pending_interval_); } } // namespace kagome::consensus::grandpa diff --git a/core/consensus/grandpa/impl/voting_round_impl.hpp b/core/consensus/grandpa/impl/voting_round_impl.hpp index 17d26412a8..aba3ffe98e 100644 --- a/core/consensus/grandpa/impl/voting_round_impl.hpp +++ b/core/consensus/grandpa/impl/voting_round_impl.hpp @@ -25,7 +25,8 @@ namespace kagome::consensus::grandpa { namespace kagome::consensus::grandpa { - class VotingRoundImpl : public VotingRound { + class VotingRoundImpl : public VotingRound, + public std::enable_shared_from_this { private: VotingRoundImpl(const std::shared_ptr &grandpa, const GrandpaConfig &config, diff --git a/core/consensus/grandpa/voting_round.hpp b/core/consensus/grandpa/voting_round.hpp index 0f5ebb349a..d83b907611 100644 --- a/core/consensus/grandpa/voting_round.hpp +++ b/core/consensus/grandpa/voting_round.hpp @@ -15,7 +15,7 @@ namespace kagome::consensus::grandpa { /** * Handles execution of one grandpa round. For details @see VotingRoundImpl */ - class VotingRound : public std::enable_shared_from_this { + class VotingRound { public: virtual ~VotingRound() = default;