diff --git a/core/backend.go b/core/backend.go index dc21691..3b86088 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) 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 78bc980..3750f82 100644 --- a/core/ibft.go +++ b/core/ibft.go @@ -323,6 +323,10 @@ func (i *IBFT) RunSequence(ctx context.Context, h uint64) { for { view := i.state.getView() + if err := i.backend.StartRound(view); err != nil { + i.log.Error("failed to handle start round callback on backend", "round", view.Round, "err", err) + } + 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..90adef7 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) error 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,14 @@ func (m mockBackend) GetVotingPowers(height uint64) (map[string]*big.Int, error) return map[string]*big.Int{}, nil } +func (m mockBackend) StartRound(view *proto.View) error { + if m.startRoundFn != nil { + return m.startRoundFn(view) + } + + return nil +} + // Define delegation methods type multicastFnDelegate func(*proto.Message)