Skip to content

Commit

Permalink
feat(dpos): remove reset consensus logic
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jan 14, 2025
1 parent e585669 commit edfdcde
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
13 changes: 13 additions & 0 deletions dpos/manager/dposmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ func (d *DPOSManager) OnResponseBlocks(id dpeer.PID, blockConfirms []*types.Dpos
}

func (d *DPOSManager) OnRequestConsensus(id dpeer.PID, height uint32) {
// only use reset view
return
if !d.isCurrentArbiter() {
return
}
Expand Down Expand Up @@ -400,6 +402,8 @@ func (d *DPOSManager) OnRecoverTimeout() {
}

func (d *DPOSManager) recoverAbnormalState() bool {
// only use reset view
return false
if d.recoverStarted {
return false
}
Expand Down Expand Up @@ -439,6 +443,8 @@ func (d *DPOSManager) recoverAbnormalState() bool {
}

func (d *DPOSManager) DoRecover() {
// only use reset view
return
if d.consensus.viewOffset == 0 {
log.Info("no need to recover view offset")
return
Expand Down Expand Up @@ -506,6 +512,10 @@ func (d *DPOSManager) OnChangeView() {
log.Info("[TryChangeView] succeed")
}

if d.consensus.currentHeight >= d.chainParams.DPoSConfiguration.ChangeViewV1Height {
return
}

if d.consensus.viewOffset >= maxViewOffset {
m := &dmsg.ResetView{
Sponsor: d.GetPublicKey(),
Expand Down Expand Up @@ -714,6 +724,9 @@ func (d *DPOSManager) OnResponseRevertToDPOSTxReceived(
}

func (d *DPOSManager) OnResponseResetViewReceived(msg *dmsg.ResetView) {
if d.consensus.currentHeight >= d.chainParams.DPoSConfiguration.ChangeViewV1Height {
return
}

if !d.isCurrentArbiter() {
return
Expand Down
18 changes: 9 additions & 9 deletions dpos/manager/dposondutyhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ func (h *DPOSOnDutyHandler) ProcessProposal(id peer.PID, p *payload.DPOSProposal

func (h *DPOSOnDutyHandler) ChangeView(firstBlockHash *common.Uint256) {

if !h.tryCreateInactiveArbitratorsTx() {
b, ok := h.cfg.Manager.GetBlockCache().TryGetValue(*firstBlockHash)
if !ok {
log.Info("[OnViewChanged] get block failed for proposal")
} else {
log.Info("[OnViewChanged] start proposal")
h.proposalDispatcher.CleanProposals(true)
h.proposalDispatcher.StartProposal(b)
}
// if !h.tryCreateInactiveArbitratorsTx() {
b, ok := h.cfg.Manager.GetBlockCache().TryGetValue(*firstBlockHash)
if !ok {
log.Info("[OnViewChanged] get block failed for proposal")
} else {
log.Info("[OnViewChanged] start proposal")
h.proposalDispatcher.CleanProposals(true)
h.proposalDispatcher.StartProposal(b)
}
// }
}

func (h *DPOSOnDutyHandler) TryStartNewConsensus(b *types.Block) bool {
Expand Down
2 changes: 1 addition & 1 deletion dpos/manager/proposaldispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ func (p *ProposalDispatcher) OnResponseResetViewReceived(msg *dmsg.ResetView) {
log.Info("[OnResponseResetViewReceived] signer:", common.BytesToHexString(signer))

if len(p.resetViewRequests) >= p.cfg.Arbitrators.GetArbitersMajorityCount() {
log.Info("[OnResponseResetViewReceived] signer:", common.BytesToHexString(signer))
log.Info("[OnResponseResetViewReceived] enough signers:", len(p.resetViewRequests))
// do reset
p.resetConsensus(p.finishedHeight)
p.resetViewRequests = make(map[string]struct{}, 0)
Expand Down

0 comments on commit edfdcde

Please sign in to comment.