Skip to content

Commit

Permalink
Fix block production (#1821)
Browse files Browse the repository at this point in the history
fix: chain-spec for two local validators
fix: update block hash after sealing

Signed-off-by: Dmitriy Khaustov aka xDimon <khaustov.dm@gmail.com>
  • Loading branch information
xDimon authored Oct 3, 2023
1 parent 965aaf0 commit 5265373
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 4 additions & 0 deletions core/consensus/babe/impl/babe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ namespace kagome::consensus::babe {
BOOST_ASSERT(ctx.keypair != nullptr);

// Calculate and save hash, 'cause it's new produced block
// Note: it is temporary hash significant for signing
primitives::calculateBlockHash(
const_cast<primitives::BlockHeader &>(block.header), *hasher_);

Expand Down Expand Up @@ -505,6 +506,9 @@ namespace kagome::consensus::babe {
// add seal digest item
block.header.digest.emplace_back(seal_res.value());

// Calculate and save hash, 'cause seal digest was added
primitives::calculateBlockHash(block.header, *hasher_);

if (clock_.now() > slots_util_.get()->slotFinishTime(
ctx.slot + kMaxBlockSlotsOvertime)) {
SL_WARN(log_,
Expand Down
23 changes: 13 additions & 10 deletions core/consensus/timeline/impl/timeline_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,17 +549,20 @@ namespace kagome::consensus {
BOOST_ASSERT_MSG(header_opt.has_value(), "Just added block; deq");
const auto &header = header_opt.value();

auto consensus = consensus_selector_->getProductionConsensus(block);
[[likely]] if (header.number != 0) {
auto consensus = consensus_selector_->getProductionConsensus(block);

auto slot_res = consensus->getSlot(header);
if (not slot_res.has_value()) {
return;
}
if (slots_util_->timeToSlot(clock_.now()) > slot_res.value() + 1) {
current_state_ = SyncState::WAIT_REMOTE_STATUS;
state_sub_engine_->notify(
primitives::events::SyncStateEventType::kSyncState, current_state_);
return;
auto slot_res = consensus->getSlot(header);
if (not slot_res.has_value()) {
return;
}
if (slots_util_->timeToSlot(clock_.now()) > slot_res.value() + 1) {
current_state_ = SyncState::WAIT_REMOTE_STATUS;
state_sub_engine_->notify(
primitives::events::SyncStateEventType::kSyncState,
current_state_);
return;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/network/testchain.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"id": "local_testnet",
"chainType": "Local",
"bootNodes": [
"/ip4/127.0.0.1/tcp/11122/ws/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV",
"/ip4/127.0.0.1/tcp/11222/ws/p2p/12D3KooWKzGMnzpdQQFGvxVEBYKQuyttE3KjigvBAwXy7hZtdHqs"
"/ip4/127.0.0.1/tcp/11122/p2p/12D3KooWEgUjBV5FJAuBSoNMRYFRHjV7PjZwRQ7b43EKX9g7D6xV",
"/ip4/127.0.0.1/tcp/11222/p2p/12D3KooWKzGMnzpdQQFGvxVEBYKQuyttE3KjigvBAwXy7hZtdHqs"
],
"telemetryEndpoints": null,
"protocolId": "dot",
Expand Down

0 comments on commit 5265373

Please sign in to comment.