Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove babe delay #1629

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions core/consensus/babe/impl/babe_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,6 @@ namespace kagome::consensus::babe {
}
} while (rewind_slots);

// Slot processing begins in 1/3 slot time after start
auto finish_time = babe_util_->slotStartTime(current_slot_)
+ babe_config_repo_->slotDuration() / 3;

SL_VERBOSE(log_,
"Starting a slot {} in epoch {} (remains {:.2f} sec.)",
current_slot_,
Expand All @@ -774,15 +770,7 @@ namespace kagome::consensus::babe {
.count()
/ 1000.);

// everything is OK: wait for the end of the slot
timer_->expiresAt(finish_time);
timer_->asyncWait([this, now](auto &&ec) {
if (ec) {
log_->error("error happened while waiting on the timer: {}", ec);
return;
}
processSlot(now);
});
processSlot(now);
}

void BabeImpl::processSlot(clock::SystemClock::TimePoint slot_timestamp) {
Expand Down
20 changes: 3 additions & 17 deletions test/core/consensus/babe/babe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,13 @@ TEST_F(BabeTest, Success) {
auto breaker = [](const boost::system::error_code &ec) {
throw std::logic_error("Must not be called");
};
std::function<void(const boost::system::error_code &ec)> on_process_slot_1 =
breaker;
std::function<void(const boost::system::error_code &ec)> on_run_slot_2 =
breaker;
std::function<void(const boost::system::error_code &ec)> on_process_slot_2 =
breaker;
std::function<void(const boost::system::error_code &ec)> on_run_slot_3 =
breaker;
EXPECT_CALL(*timer_, asyncWait(_))
.InSequence(s)
.WillOnce(testing::SaveArg<0>(&on_process_slot_1))
.WillOnce(testing::SaveArg<0>(&on_run_slot_2))
.WillOnce(testing::SaveArg<0>(&on_process_slot_2))
.WillOnce(testing::SaveArg<0>(&on_run_slot_3));
EXPECT_CALL(*timer_, expiresAt(_)).WillRepeatedly(Return());

Expand Down Expand Up @@ -362,9 +356,7 @@ TEST_F(BabeTest, Success) {
.WillOnce(CheckBlockHeader(created_block_.header));

babe_->runEpoch(epoch_);
ASSERT_NO_THROW(on_process_slot_1({}));
ASSERT_NO_THROW(on_run_slot_2({}));
ASSERT_NO_THROW(on_process_slot_2({}));
}

/**
Expand All @@ -374,23 +366,17 @@ TEST_F(BabeTest, Success) {
*/
TEST_F(BabeTest, NotAuthority) {
EXPECT_CALL(*clock_, now());
EXPECT_CALL(*babe_config_repo_, slotDuration());
EXPECT_CALL(*babe_util_, slotFinishTime(_)).Times(testing::AnyNumber());
EXPECT_CALL(*babe_util_, syncEpoch(_));
EXPECT_CALL(*timer_, expiresAt(_));
std::function<void(const boost::system::error_code &)> process_slot;
EXPECT_CALL(*timer_, asyncWait(_))
.WillOnce(testing::SaveArg<0>(&process_slot));
babe_->runEpoch(epoch_);

EXPECT_CALL(*block_tree_, bestLeaf()).WillRepeatedly(Return(best_leaf));
EXPECT_CALL(*block_tree_, getBlockHeader(best_block_hash_))
.WillOnce(Return(best_block_header_));
EXPECT_CALL(*babe_util_, syncEpoch(_));
EXPECT_CALL(*babe_util_, syncEpoch(_)).Times(2);
EXPECT_CALL(*babe_util_, slotStartTime(_));

expected_epoch_digest.authorities.clear();
EXPECT_CALL(*timer_, expiresAt(_));
EXPECT_CALL(*timer_, asyncWait(_));
process_slot({});

babe_->runEpoch(epoch_);
}