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

Fix collators rotating 1 block too early #275

Merged
merged 2 commits into from
Sep 28, 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
4 changes: 3 additions & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ pub fn build_check_assigned_para_id(
spawner: impl SpawnEssentialNamed,
) {
// Subscribe to new blocks in order to react to para id assignment
let mut import_notifications = client.import_notification_stream();
// This must be the stream of finalized blocks, otherwise the collators may rotate to a
// different chain before the block is finalized, and that could lead to a stalled chain
let mut import_notifications = client.finality_notification_stream();

let check_assigned_para_id_task = async move {
while let Some(msg) = import_notifications.next().await {
Expand Down
3 changes: 3 additions & 0 deletions test/suites/para/test_tanssi_containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ describeSuite({
expect(await directoryExists(container2002DbPath)).to.be.false;
// The node starts one session before the container chain is in registered list
await waitSessions(context, paraApi, 1);
// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
await context.waitBlock(3, "Tanssi");
expect(await directoryExists(container2002DbPath)).to.be.true;
// Not registered yet, still pending
const registered4 = await paraApi.query.registrar.registeredParaIds();
Expand Down
11 changes: 9 additions & 2 deletions test/suites/warp-sync/test_warp_sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ describeSuite({

expect(allCollators).to.deep.equal(expectedAllCollators);

// The node detects assignment when the block is finalized, but "waitSessions" ignores finality.
// So wait a few blocks more hoping that the current block will be finalized by then.
await context.waitBlock(3, "Tanssi");

// Collator2000-02 container chain db should have been deleted
expect(await directoryExists(container200002DbPath)).to.be.false;

Expand All @@ -204,7 +208,7 @@ describeSuite({
title: "Collator1000-03 is producing blocks on Container 2000",
timeout: 300000,
test: async function () {
const blockStart = (await container2000Api.rpc.chain.getBlock()).block.header.number.toNumber();
const blockStart = (await container2000Api.rpc.chain.getBlock()).block.header.number.toNumber() - 3;
// Wait up to 8 blocks, giving the new collator 4 chances to build a block
const blockEnd = blockStart + 8;
const authors = [];
Expand All @@ -222,7 +226,10 @@ describeSuite({
if (author == getKeyringNimbusIdHex("Collator1000-03")) {
break;
}
await context.waitBlock(1, "Container2000");
const currentBlock = (await container2000Api.rpc.chain.getBlock()).block.header.number.toNumber();
if (currentBlock == blockNumber) {
await context.waitBlock(1, "Container2000");
}
}

expect(authors).to.contain(getKeyringNimbusIdHex("Collator1000-03"));
Expand Down