Skip to content

Commit

Permalink
Add RPC to force round timeout (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Cortesi authored and celo-ci-bot-user committed Jan 10, 2020
1 parent c234c8f commit 970c82d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions consensus/istanbul/backend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,21 @@ func (api *API) GetValEnodeTable() (map[string]*vet.ValEnodeEntryInfo, error) {

// GetCurrentRoundState retrieves the current IBFT RoundState
func (api *API) GetCurrentRoundState() (*core.RoundStateSummary, error) {
if !api.istanbul.coreStarted {
return nil, istanbul.ErrStoppedEngine
}
return api.istanbul.core.CurrentRoundState().Summary(), nil
}

// GetCurrentRoundState retrieves the current IBFT RoundState
func (api *API) ForceRoundChange() (bool, error) {
if !api.istanbul.coreStarted {
return false, istanbul.ErrStoppedEngine
}
api.istanbul.core.ForceRoundChange()
return true, nil
}

// TODO(kevjue) - implement this
// ProxyInfo retrieves all the information we know about each individual proxy node
/* func (api *PublicAdminAPI) ProxyInfo() ([]*p2p.PeerInfo, error) {
Expand Down
6 changes: 6 additions & 0 deletions consensus/istanbul/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ func (c *core) ParentCommits() MessageSet {
return c.current.ParentCommits()
}

func (c *core) ForceRoundChange() {
// timeout current DesiredView
view := &istanbul.View{Sequence: c.current.Sequence(), Round: c.current.DesiredRound()}
c.sendEvent(timeoutAndMoveToNextRoundEvent{view})
}

// PrepareCommittedSeal returns a committed seal for the given hash and round number.
func PrepareCommittedSeal(hash common.Hash, round *big.Int) []byte {
var buf bytes.Buffer
Expand Down
8 changes: 4 additions & 4 deletions consensus/istanbul/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ func (c *core) handleCheckedMsg(msg *istanbul.Message, src istanbul.Validator) e
return errInvalidMessage
}

func (c *core) handleTimeoutAndMoveToNextRound(desiredView *istanbul.View) error {
logger := c.newLogger("func", "handleTimeoutAndMoveToNextRound", "set_at_seq", desiredView.Sequence, "set_at_desiredRound", desiredView.Round)
func (c *core) handleTimeoutAndMoveToNextRound(timedOutView *istanbul.View) error {
logger := c.newLogger("func", "handleTimeoutAndMoveToNextRound", "timed_out_seq", timedOutView.Sequence, "timed_out_round", timedOutView.Round)

// Avoid races where message is enqueued then a later event advances sequence or desired round.
if c.current.Sequence().Cmp(desiredView.Sequence) != 0 || c.current.DesiredRound().Cmp(desiredView.Round) != 0 {
if c.current.Sequence().Cmp(timedOutView.Sequence) != 0 || c.current.DesiredRound().Cmp(timedOutView.Round) != 0 {
logger.Trace("Timed out but now on a different view")
return nil
}

logger.Debug("Timed out, trying to wait for next round")
nextRound := new(big.Int).Add(desiredView.Round, common.Big1)
nextRound := new(big.Int).Add(timedOutView.Round, common.Big1)
return c.waitForDesiredRound(nextRound)
}

Expand Down
4 changes: 4 additions & 0 deletions consensus/istanbul/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import (
type Engine interface {
Start() error
Stop() error
// CurrentView returns the current view or nil if none
CurrentView() *istanbul.View
// CurrentRoundState returns the current roundState or nil if none
CurrentRoundState() RoundState
SetAddress(common.Address)
// Validator -> CommittedSeal from Parent Block
ParentCommits() MessageSet
// ForceRoundChange will force round change to the current desiredRound + 1
ForceRoundChange()
}

// State represents the IBFT state
Expand Down

0 comments on commit 970c82d

Please sign in to comment.