Skip to content

Commit

Permalink
Introduce StartRound function to the backend (#95)
Browse files Browse the repository at this point in the history
* Introduce StartRound function to the backend

* Add error to the StartRound signature

* Remove sequence aborting
  • Loading branch information
Stefan-Ethernal authored Apr 24, 2024
1 parent 5a229e5 commit 1e0f56f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions core/ibft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions core/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand All @@ -83,6 +84,7 @@ type mockBackend struct {
insertProposalFn insertProposalDelegate
idFn idDelegate
getVotingPowerFn getVotingPowerDelegate
startRoundFn startRoundDelegate
}

func (m mockBackend) ID() []byte {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 1e0f56f

Please sign in to comment.