Skip to content

Commit

Permalink
버그 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hoonkii authored and junbeomlee committed Aug 18, 2018
1 parent 4dc4d67 commit 654185c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions consensus/pbft/api/state_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ func (cApi StateApi) StartConsensus(userId pbft.MemberID, proposedBlock pbft.Pro
return ConsensusCreateError
}

createdConsensus, err := pbft.CreateConsensus(peerList, proposedBlock)
createdState, err := pbft.NewState(peerList, proposedBlock)
if err != nil {
return err
}

if err := cApi.repo.Save(*createdConsensus); err != nil {
if err := cApi.repo.Save(*createdState); err != nil {
return err
}

createdPrePrepareMsg := pbft.NewPrePrepareMsg(createdConsensus)
createdPrePrepareMsg := pbft.NewPrePrepareMsg(createdState)
if err := cApi.propagateService.BroadcastPrePrepareMsg(*createdPrePrepareMsg); err != nil {
return err
}
createdConsensus.Start()
createdState.Start()

return nil
}
Expand All @@ -82,65 +82,65 @@ func (cApi StateApi) HandlePrePrepareMsg(msg pbft.PrePrepareMsg) error {
return pbft.InvalidLeaderIdError
}

constructedConsensus, err := pbft.ConstructConsensus(msg)
builtState, err := pbft.BuildState(msg)
if err != nil {
return err
}

if err := cApi.repo.Save(*constructedConsensus); err != nil {
if err := cApi.repo.Save(*builtState); err != nil {
return err
}

prepareMsg := pbft.NewPrepareMsg(constructedConsensus)
prepareMsg := pbft.NewPrepareMsg(builtState)
if err := cApi.propagateService.BroadcastPrepareMsg(*prepareMsg); err != nil {
return err
}
constructedConsensus.ToPrepareStage()
builtState.ToPrepareStage()

return nil
}

func (cApi StateApi) HandlePrepareMsg(msg pbft.PrepareMsg) error {

loadedConsensus, err := cApi.repo.Load()
loadedState, err := cApi.repo.Load()
if err != nil {
return err
}

if err := loadedConsensus.SavePrepareMsg(&msg); err != nil {
if err := loadedState.SavePrepareMsg(&msg); err != nil {
return err
}

if !loadedConsensus.CheckPrepareCondition() {
if !loadedState.CheckPrepareCondition() {
return nil
}

newCommitMsg := pbft.NewCommitMsg(loadedConsensus)
newCommitMsg := pbft.NewCommitMsg(loadedState)
if err := cApi.propagateService.BroadcastCommitMsg(*newCommitMsg); err != nil {
return err
}
loadedConsensus.ToCommitStage()
loadedState.ToCommitStage()

return nil
}

func (cApi StateApi) HandleCommitMsg(msg pbft.CommitMsg) error {

loadedConsensus, err := cApi.repo.Load()
loadedState, err := cApi.repo.Load()

if err != nil {
return err
}

if err := loadedConsensus.SaveCommitMsg(&msg); err != nil {
if err := loadedState.SaveCommitMsg(&msg); err != nil {
return err
}

if !loadedConsensus.CheckCommitCondition() {
if !loadedState.CheckCommitCondition() {
return nil
}

if err := cApi.confirmService.ConfirmBlock(loadedConsensus.Block); err != nil {
if err := cApi.confirmService.ConfirmBlock(loadedState.Block); err != nil {
return err
}
cApi.repo.Remove()
Expand Down

0 comments on commit 654185c

Please sign in to comment.