From 87b5838967eacd029299c84c4fa5dba1aff5f641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Tue, 23 Apr 2024 13:00:44 +0200 Subject: [PATCH 1/3] Introduce StartRound function to the backend --- core/backend.go | 3 +++ core/ibft.go | 2 ++ core/mock_test.go | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/core/backend.go b/core/backend.go index dc21691..8a95f3d 100644 --- a/core/backend.go +++ b/core/backend.go @@ -62,6 +62,9 @@ type Backend interface { Verifier ValidatorBackend + // StartRound notifies the backend implementation whenever new round is about to start + StartRound(view *proto.View) + // BuildProposal builds a new proposal for the given view (height and round) BuildProposal(view *proto.View) []byte diff --git a/core/ibft.go b/core/ibft.go index 78bc980..4608087 100644 --- a/core/ibft.go +++ b/core/ibft.go @@ -323,6 +323,8 @@ func (i *IBFT) RunSequence(ctx context.Context, h uint64) { for { view := i.state.getView() + i.backend.StartRound(view) + i.log.Info("round started", "round", view.Round) currentRound := view.Round diff --git a/core/mock_test.go b/core/mock_test.go index aedebd0..342f84e 100644 --- a/core/mock_test.go +++ b/core/mock_test.go @@ -64,6 +64,7 @@ type buildRoundChangeMessageDelegate func( type insertProposalDelegate func(*proto.Proposal, []*messages.CommittedSeal) type idDelegate func() []byte type getVotingPowerDelegate func(uint64) (map[string]*big.Int, error) +type startRoundDelegate func(*proto.View) var _ Backend = &mockBackend{} @@ -83,6 +84,7 @@ type mockBackend struct { insertProposalFn insertProposalDelegate idFn idDelegate getVotingPowerFn getVotingPowerDelegate + startRoundFn startRoundDelegate } func (m mockBackend) ID() []byte { @@ -202,6 +204,12 @@ func (m mockBackend) GetVotingPowers(height uint64) (map[string]*big.Int, error) return map[string]*big.Int{}, nil } +func (m mockBackend) StartRound(view *proto.View) { + if m.startRoundFn != nil { + m.startRoundFn(view) + } +} + // Define delegation methods type multicastFnDelegate func(*proto.Message) From ffd0b6cc9dd3f01220db0ca70cbc71c9bbd4ec0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Wed, 24 Apr 2024 10:21:02 +0200 Subject: [PATCH 2/3] Add error to the StartRound signature --- core/backend.go | 2 +- core/ibft.go | 6 +++++- core/mock_test.go | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/backend.go b/core/backend.go index 8a95f3d..3b86088 100644 --- a/core/backend.go +++ b/core/backend.go @@ -63,7 +63,7 @@ type Backend interface { ValidatorBackend // StartRound notifies the backend implementation whenever new round is about to start - StartRound(view *proto.View) + StartRound(view *proto.View) error // BuildProposal builds a new proposal for the given view (height and round) BuildProposal(view *proto.View) []byte diff --git a/core/ibft.go b/core/ibft.go index 4608087..809b710 100644 --- a/core/ibft.go +++ b/core/ibft.go @@ -323,7 +323,11 @@ func (i *IBFT) RunSequence(ctx context.Context, h uint64) { for { view := i.state.getView() - i.backend.StartRound(view) + if err := i.backend.StartRound(view); err != nil { + i.log.Error("failed to start round on backend, aborting sequence...", "round", view.Round, "err", err) + + return + } i.log.Info("round started", "round", view.Round) diff --git a/core/mock_test.go b/core/mock_test.go index 342f84e..90adef7 100644 --- a/core/mock_test.go +++ b/core/mock_test.go @@ -64,7 +64,7 @@ type buildRoundChangeMessageDelegate func( type insertProposalDelegate func(*proto.Proposal, []*messages.CommittedSeal) type idDelegate func() []byte type getVotingPowerDelegate func(uint64) (map[string]*big.Int, error) -type startRoundDelegate func(*proto.View) +type startRoundDelegate func(*proto.View) error var _ Backend = &mockBackend{} @@ -204,10 +204,12 @@ func (m mockBackend) GetVotingPowers(height uint64) (map[string]*big.Int, error) return map[string]*big.Int{}, nil } -func (m mockBackend) StartRound(view *proto.View) { +func (m mockBackend) StartRound(view *proto.View) error { if m.startRoundFn != nil { - m.startRoundFn(view) + return m.startRoundFn(view) } + + return nil } // Define delegation methods From 3310f0b4b82043db51059193a101fc6c25abf262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Wed, 24 Apr 2024 10:32:15 +0200 Subject: [PATCH 3/3] Remove sequence aborting --- core/ibft.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/ibft.go b/core/ibft.go index 809b710..3750f82 100644 --- a/core/ibft.go +++ b/core/ibft.go @@ -324,9 +324,7 @@ func (i *IBFT) RunSequence(ctx context.Context, h uint64) { view := i.state.getView() if err := i.backend.StartRound(view); err != nil { - i.log.Error("failed to start round on backend, aborting sequence...", "round", view.Round, "err", err) - - return + i.log.Error("failed to handle start round callback on backend", "round", view.Round, "err", err) } i.log.Info("round started", "round", view.Round)