Skip to content

Commit

Permalink
Updated (#430)
Browse files Browse the repository at this point in the history
* fix the ending of view change (#424)

Signed-off-by: Hagar Meir <[email protected]>

* sync avoid write to view change channel (#425)

Signed-off-by: Hagar Meir <[email protected]>

* fixing view change (#427)

* fixing view change

Signed-off-by: Hagar Meir <[email protected]>

* test view data

Signed-off-by: Hagar Meir <[email protected]>

* test new view

Signed-off-by: Hagar Meir <[email protected]>

* after review

Signed-off-by: Hagar Meir <[email protected]>

* update protos

Signed-off-by: Hagar Meir <[email protected]>

* change comment

* add return reconfig in test

Signed-off-by: Hagar Meir <[email protected]>
  • Loading branch information
yacovm authored Mar 5, 2020
1 parent 7f87020 commit 019e9af
Show file tree
Hide file tree
Showing 7 changed files with 899 additions and 300 deletions.
52 changes: 25 additions & 27 deletions internal/bft/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,11 @@ func (c *Controller) run() {
case <-c.leaderToken:
c.propose()
case <-c.syncChan:
c.sync()
view, seq := c.sync()
c.MaybePruneRevokedRequests()
if view > 0 || seq > 0 {
c.changeView(view, seq)
}
}
}
}
Expand All @@ -453,7 +456,7 @@ func (c *Controller) decide(d decision) {
}
}

func (c *Controller) sync() {
func (c *Controller) sync() (viewNum uint64, seq uint64) {
// Block any concurrent sync attempt.
c.grabSyncToken()
// At exit, enable sync once more, but ignore
Expand All @@ -471,7 +474,7 @@ func (c *Controller) sync() {
c.Logger.Infof("Synchronizer returned with proposal metadata nil")
response := c.fetchState()
if response == nil {
return
return 0, 0
}
if response.View > 0 && response.Seq == 1 {
c.Logger.Infof("The collected state is with view %d and sequence %d", response.View, response.Seq)
Expand All @@ -487,17 +490,17 @@ func (c *Controller) sync() {
c.Logger.Panicf("Failed to save message to state, error: %v", err)
}
c.ViewChanger.InformNewView(response.View, 0)
c.viewChange <- viewInfo{viewNumber: response.View, proposalSeq: 1}
return response.View, 1
}
return
return 0, 0
}
md := &protos.ViewMetadata{}
if err := proto.Unmarshal(decision.Proposal.Metadata, md); err != nil {
c.Logger.Panicf("Controller was unable to unmarshal the proposal metadata returned by the Synchronizer")
}
if md.ViewId < c.currViewNumber {
c.Logger.Infof("Synchronizer returned with view number %d but the controller is at view number %d", md.ViewId, c.currViewNumber)
return
return 0, 0
}
c.Logger.Infof("Synchronized to view %d and sequence %d with verification sequence %d", md.ViewId, md.LatestSequence, decision.Proposal.VerificationSequence)

Expand All @@ -522,10 +525,12 @@ func (c *Controller) sync() {
}
}

c.Logger.Debugf("Node %d is setting the checkpoint after sync to view %d and seq %d", c.ID, md.ViewId, md.LatestSequence)
c.Checkpoint.Set(decision.Proposal, decision.Signatures)
c.verificationSequence = uint64(decision.Proposal.VerificationSequence)
c.Logger.Debugf("Node %d is informing the view changer after sync of view %d and seq %d", c.ID, md.ViewId, md.LatestSequence)
c.ViewChanger.InformNewView(view, md.LatestSequence)
c.viewChange <- viewInfo{viewNumber: view, proposalSeq: md.LatestSequence + 1}
return view, md.LatestSequence + 1
}

func (c *Controller) fetchState() *types.ViewAndSeq {
Expand Down Expand Up @@ -585,21 +590,18 @@ func (c *Controller) relinquishLeaderToken() {
}
}

func (c *Controller) syncOnStart(startViewNumber uint64, startProposalSequence uint64) viewInfo {
c.sync()
func (c *Controller) syncOnStart(startViewNumber uint64, startProposalSequence uint64) (viewNum uint64, seq uint64) {
syncView, syncSeq := c.sync()
c.MaybePruneRevokedRequests()
info := viewInfo{startViewNumber, startProposalSequence}
select {
case newViewSeq := <-c.viewChange:
if newViewSeq.viewNumber > startViewNumber {
info.viewNumber = newViewSeq.viewNumber
}
if newViewSeq.proposalSeq > startProposalSequence {
info.proposalSeq = newViewSeq.proposalSeq
}
default:
viewNum = startViewNumber
seq = startProposalSequence
if syncView > startViewNumber {
viewNum = syncView
}
return info
if syncSeq > startProposalSequence {
seq = syncSeq
}
return viewNum, seq
}

// Start the controller
Expand All @@ -618,16 +620,12 @@ func (c *Controller) Start(startViewNumber uint64, startProposalSequence uint64,
c.Logger.Debugf("The number of nodes (N) is %d, F is %d, and the quorum size is %d", c.N, F, Q)
c.quorum = Q

info := viewInfo{
viewNumber: startViewNumber,
proposalSeq: startProposalSequence,
}
if syncOnStart {
info = c.syncOnStart(startViewNumber, startProposalSequence)
startViewNumber, startProposalSequence = c.syncOnStart(startViewNumber, startProposalSequence)
}

c.currViewNumber = info.viewNumber
c.startView(info.proposalSeq)
c.currViewNumber = startViewNumber
c.startView(startProposalSequence)
if iAm, _ := c.iAmTheLeader(); iAm {
c.acquireLeaderToken()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/bft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func MsgToString(m *protos.Message) string {
case *protos.Message_NewView:
return newViewToString(m.GetNewView())
case *protos.Message_ViewData:
return viewDataToString(m.GetViewData())
return signedViewDataToString(m.GetViewData())
case *protos.Message_HeartBeat:
return heartBeatToString(m.GetHeartBeat())
case *protos.Message_HeartBeatResponse:
Expand Down Expand Up @@ -288,7 +288,7 @@ func newViewToString(nv *protos.NewView) string {
buff := bytes.Buffer{}
buff.WriteString("< NewView with ")
for i, svd := range nv.SignedViewData {
buff.WriteString(viewDataToString(svd))
buff.WriteString(signedViewDataToString(svd))
if i == len(nv.SignedViewData)-1 {
break
}
Expand All @@ -298,7 +298,7 @@ func newViewToString(nv *protos.NewView) string {
return buff.String()
}

func viewDataToString(svd *protos.SignedViewData) string {
func signedViewDataToString(svd *protos.SignedViewData) string {
if svd == nil {
return "empty ViewData"
}
Expand Down
Loading

0 comments on commit 019e9af

Please sign in to comment.