From 5658cfb52cf451cdcf1c7fffec16d98193ec58de Mon Sep 17 00:00:00 2001 From: Tomasz Polaczyk Date: Wed, 27 Sep 2023 11:58:16 +0200 Subject: [PATCH 1/2] Fix collators rotating 1 block too early --- node/src/service.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/node/src/service.rs b/node/src/service.rs index 099cc5da3..fccbda63d 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -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 { From 2734f75445f897878d45341bdb16c41a1604b8c8 Mon Sep 17 00:00:00 2001 From: Tomasz Polaczyk Date: Wed, 27 Sep 2023 13:03:59 +0200 Subject: [PATCH 2/2] Fix zombienet tests --- test/suites/para/test_tanssi_containers.ts | 3 +++ test/suites/warp-sync/test_warp_sync.ts | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/suites/para/test_tanssi_containers.ts b/test/suites/para/test_tanssi_containers.ts index fab928647..e3249c40b 100644 --- a/test/suites/para/test_tanssi_containers.ts +++ b/test/suites/para/test_tanssi_containers.ts @@ -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(); diff --git a/test/suites/warp-sync/test_warp_sync.ts b/test/suites/warp-sync/test_warp_sync.ts index 6d105f298..d8fa7fd0b 100644 --- a/test/suites/warp-sync/test_warp_sync.ts +++ b/test/suites/warp-sync/test_warp_sync.ts @@ -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; @@ -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 = []; @@ -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"));