From 5f1b5d3b340c33b91aea657ed52489457f72a74a Mon Sep 17 00:00:00 2001 From: samliok Date: Mon, 14 Sep 2026 16:32:57 -0400 Subject: [PATCH] Drop messages delivered to an Instance before Start A validator broadcasts a finalization only after indexing the block, so a node created on that commit can receive the message before Start has run. HandleMessage now drops such messages instead of falling through with neither an epoch nor a non-validator set. --- instance.go | 5 +++++ instance_test.go | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/instance.go b/instance.go index 873bdeb3..22feccab 100644 --- a/instance.go +++ b/instance.go @@ -308,6 +308,11 @@ func (i *Instance) HandleMessage(msg *common.Message, from common.NodeID) error default: } + if !i.started { + i.Config.Logger.Debug("Instance has not started, dropping message") + return nil + } + // We need to artificially wire the MSM and the cache to the block, // in order to intercept the Verify() call. switch { diff --git a/instance_test.go b/instance_test.go index b6985fcf..736172b0 100644 --- a/instance_test.go +++ b/instance_test.go @@ -135,6 +135,23 @@ func TestNonValidatorBecomesValidator(t *testing.T) { assertExpectedNodeIds(t, finalization.QC.Signers(), newValidatorSet.NodeIDs()) } +// TestInstanceDropsMessagesBeforeStart asserts that a message delivered before Start +// is dropped without error. A validator broadcasts the finalization only after +// indexing the block, so a node created on that commit can receive it before starting. +func TestInstanceDropsMessagesBeforeStart(t *testing.T) { + validator := newNodeMapping(1) + pChain := newTestPChain([]metadata.NodeBLSMapping{validator}) + instance := NewInstance(Config{ + PlatformChain: pChain, + Storage: newTestStorageWithGenesis(t), + Logger: testutil.MakeLogger(t, 1), + ID: validator.NodeID[:], + }) + + msg := &common.Message{Finalization: &common.Finalization{}} + require.NoError(t, instance.HandleMessage(msg, validator.NodeID[:])) +} + // TestValidator_ValidatorSetNotChanged tests that a P-chain height increase // that does not have a unique validator set, does not create a new epoch func TestValidator_ValidatorSetNotChanged(t *testing.T) {