DE-labtory / it-chain

Lightweight & Customizable Block Chain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[consensus] refactor HandleLeaderDeletedEvent

zeroFruit opened this issue · comments

Componet
consensus

Assignee
.

Proposal Detail

func (l *LeaderEventHandler) HandlerLeaderDeletedEvent(_ event.LeaderDeleted) {
	iLogger.Infof(nil, "[PBFT] Leader Deleted, Start Elect Leader With RAFT")

	representatives := l.electionApi.GetParliament().GetRepresentatives()

	ids := make([]string, 0)
	for _, rep := range representatives {
		ids = append(ids, rep.ID)
	}

	if len(representatives) < 3 {
		l.electionApi.SetLeader(common.FindEarliestString(ids))
		return
	}

	go l.electionApi.ElectLeaderWithRaft()
}

Encapsulate logic into ElectionApi.ElectLeaderWithRaft

Reference
.