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] 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)