mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 21:01:21 +00:00
fixes from review
This commit is contained in:
@ -174,6 +174,26 @@ func (hvs *HeightVoteSet) getVoteSet(round int, type_ byte) *types.VoteSet {
|
||||
}
|
||||
}
|
||||
|
||||
// If a peer claims that it has 2/3 majority for given blockKey, call this.
|
||||
// NOTE: if there are too many peers, or too much peer churn,
|
||||
// this can cause memory issues.
|
||||
// TODO: implement ability to remove peers too
|
||||
func (hvs *HeightVoteSet) SetPeerMaj23(round int, type_ byte, peerID p2p.ID, blockID types.BlockID) error {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
if !types.IsVoteTypeValid(type_) {
|
||||
return fmt.Errorf("SetPeerMaj23: Invalid vote type %v", type_)
|
||||
}
|
||||
voteSet := hvs.getVoteSet(round, type_)
|
||||
if voteSet == nil {
|
||||
return nil // something we don't know about yet
|
||||
}
|
||||
return voteSet.SetPeerMaj23(types.P2PID(peerID), blockID)
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// string and json
|
||||
|
||||
func (hvs *HeightVoteSet) String() string {
|
||||
return hvs.StringIndented("")
|
||||
}
|
||||
@ -207,29 +227,20 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string {
|
||||
indent)
|
||||
}
|
||||
|
||||
// `"__xx_xx____x:46/100:0.46"`
|
||||
type roundVotes struct {
|
||||
Round int `json:"round"`
|
||||
Prevotes []string `json:"prevotes"`
|
||||
PrevotesBitArray string `json:"prevotes_bit_array"`
|
||||
Precommits []string `json:"precommits"`
|
||||
PrecommitsBitArray string `json:"precommits_bit_array"`
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
|
||||
roundsVotes := hvs.toRoundVotes()
|
||||
return cdc.MarshalJSON(roundsVotes)
|
||||
allVotes := hvs.toAllRoundVotes()
|
||||
return cdc.MarshalJSON(allVotes)
|
||||
}
|
||||
|
||||
func (hvs *HeightVoteSet) toRoundVotes() []roundVotes {
|
||||
func (hvs *HeightVoteSet) toAllRoundVotes() []roundVotes {
|
||||
totalRounds := hvs.round + 1
|
||||
roundsVotes := make([]roundVotes, totalRounds)
|
||||
allVotes := make([]roundVotes, totalRounds)
|
||||
// rounds 0 ~ hvs.round inclusive
|
||||
for round := 0; round < totalRounds; round++ {
|
||||
roundsVotes[round] = roundVotes{
|
||||
allVotes[round] = roundVotes{
|
||||
Round: round,
|
||||
Prevotes: hvs.roundVoteSets[round].Prevotes.VoteStrings(),
|
||||
PrevotesBitArray: hvs.roundVoteSets[round].Prevotes.BitArrayString(),
|
||||
@ -238,22 +249,13 @@ func (hvs *HeightVoteSet) toRoundVotes() []roundVotes {
|
||||
}
|
||||
}
|
||||
// TODO: all other peer catchup rounds
|
||||
return roundsVotes
|
||||
return allVotes
|
||||
}
|
||||
|
||||
// If a peer claims that it has 2/3 majority for given blockKey, call this.
|
||||
// NOTE: if there are too many peers, or too much peer churn,
|
||||
// this can cause memory issues.
|
||||
// TODO: implement ability to remove peers too
|
||||
func (hvs *HeightVoteSet) SetPeerMaj23(round int, type_ byte, peerID p2p.ID, blockID types.BlockID) error {
|
||||
hvs.mtx.Lock()
|
||||
defer hvs.mtx.Unlock()
|
||||
if !types.IsVoteTypeValid(type_) {
|
||||
return fmt.Errorf("SetPeerMaj23: Invalid vote type %v", type_)
|
||||
}
|
||||
voteSet := hvs.getVoteSet(round, type_)
|
||||
if voteSet == nil {
|
||||
return nil // something we don't know about yet
|
||||
}
|
||||
return voteSet.SetPeerMaj23(types.P2PID(peerID), blockID)
|
||||
type roundVotes struct {
|
||||
Round int `json:"round"`
|
||||
Prevotes []string `json:"prevotes"`
|
||||
PrevotesBitArray string `json:"prevotes_bit_array"`
|
||||
Precommits []string `json:"precommits"`
|
||||
PrecommitsBitArray string `json:"precommits_bit_array"`
|
||||
}
|
||||
|
@ -79,6 +79,7 @@ type RoundState struct {
|
||||
LastValidators *types.ValidatorSet `json:"last_validators"`
|
||||
}
|
||||
|
||||
// Compressed version of the RoundState for use in RPC
|
||||
type RoundStateSimple struct {
|
||||
HeightRoundStep string `json:"height/round/step"`
|
||||
StartTime time.Time `json:"start_time"`
|
||||
@ -88,8 +89,12 @@ type RoundStateSimple struct {
|
||||
Votes json.RawMessage `json:"height_vote_set"`
|
||||
}
|
||||
|
||||
// Compress the RoundState to RoundStateSimple
|
||||
func (rs *RoundState) RoundStateSimple() RoundStateSimple {
|
||||
votesJSON, _ := rs.Votes.MarshalJSON() // TODO err
|
||||
votesJSON, err := rs.Votes.MarshalJSON()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return RoundStateSimple{
|
||||
HeightRoundStep: fmt.Sprintf("%d/%d/%d", rs.Height, rs.Round, rs.Step),
|
||||
StartTime: rs.StartTime,
|
||||
|
Reference in New Issue
Block a user