Introduce `StartRound` function to the backend (#95)

* Introduce StartRound function to the backend

* Add error to the StartRound signature

* Remove sequence aborting
pull/91/merge
Stefan Negovanović 6 months ago committed by GitHub
parent 5a229e5ab0
commit 1e0f56f229
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      core/backend.go
  2. 4
      core/ibft.go
  3. 10
      core/mock_test.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

@ -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

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

Loading…
Cancel
Save