Skip to content

Commit

Permalink
Consensus halt fix (#94)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
goran-ethernal authored Apr 24, 2024
1 parent 1e0f56f commit 00f7637
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
13 changes: 8 additions & 5 deletions core/ibft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 5 additions & 4 deletions core/ibft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)
}
Expand Down

0 comments on commit 00f7637

Please sign in to comment.