From 00f7637226a69dff8d92405f0e12d877886cb7ab Mon Sep 17 00:00:00 2001 From: Goran Rojovic <100121253+goran-ethernal@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:30:31 +0200 Subject: [PATCH] Consensus halt fix (#94) fix --- core/ibft.go | 13 ++++++++----- core/ibft_test.go | 9 +++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/ibft.go b/core/ibft.go index 3750f82..63d14c9 100644 --- a/core/ibft.go +++ b/core/ibft.go @@ -377,6 +377,7 @@ func (i *IBFT) RunSequence(ctx context.Context, h uint64) { // The consensus cycle for the block height is finished. // Stop all running worker threads teardown() + i.insertBlock() return case <-ctxRound.Done(): @@ -557,10 +558,7 @@ func (i *IBFT) runStates(ctx context.Context) { case commit: timeout = i.runCommit(ctx) case fin: - i.runFin() - // Block inserted without any errors, - // sequence is complete - i.signalRoundDone(ctx) + i.runFin(ctx) return } @@ -964,10 +962,15 @@ func (i *IBFT) handleCommit(view *proto.View) bool { } // runFin runs the fin state (block insertion) -func (i *IBFT) runFin() { +func (i *IBFT) runFin(ctx context.Context) { i.log.Debug("enter: fin state") defer i.log.Debug("exit: fin state") + i.signalRoundDone(ctx) +} + +// insertBlock inserts the block +func (i *IBFT) insertBlock() { // Insert the block to the node's underlying // blockchain layer i.backend.InsertProposal( diff --git a/core/ibft_test.go b/core/ibft_test.go index 7aea003..6e9a0fa 100644 --- a/core/ibft_test.go +++ b/core/ibft_test.go @@ -1080,19 +1080,20 @@ func TestRunCommit(t *testing.T) { i.startRound(ctx) i.wg.Wait() + i.insertBlock() // Make sure the node changed the state to fin - assert.Equal(t, fin, i.state.name) + require.Equal(t, fin, i.state.name) // Make sure the inserted proposal was the one present - assert.Equal(t, insertedProposal, correctRoundMessage.proposal.RawProposal) + require.Equal(t, insertedProposal, correctRoundMessage.proposal.RawProposal) // Make sure the inserted committed seals were correct - assert.Equal(t, insertedCommittedSeals, committedSeals) + require.Equal(t, insertedCommittedSeals, committedSeals) // Make sure the proper done channel was notified wg.Wait() - assert.True(t, doneReceived) + require.True(t, doneReceived) }, ) }