mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-28 18:55:42 +00:00
Initial pass at bft_fix_2 completion
This commit is contained in:
@@ -191,6 +191,7 @@ type Commit struct {
|
||||
// NOTE: The Precommits are in order of address to preserve the bonded ValidatorSet order.
|
||||
// Any peer with a block can gossip precommits by index with a peer without recalculating the
|
||||
// active ValidatorSet.
|
||||
BlockID BlockID `json:"blockID"`
|
||||
Precommits []*Vote `json:"precommits"`
|
||||
|
||||
// Volatile
|
||||
@@ -262,6 +263,9 @@ func (commit *Commit) IsCommit() bool {
|
||||
}
|
||||
|
||||
func (commit *Commit) ValidateBasic() error {
|
||||
if commit.BlockID.IsZero() {
|
||||
return errors.New("Commit cannot be for nil block")
|
||||
}
|
||||
if len(commit.Precommits) == 0 {
|
||||
return errors.New("No precommits in commit")
|
||||
}
|
||||
@@ -310,8 +314,10 @@ func (commit *Commit) StringIndented(indent string) string {
|
||||
precommitStrings[i] = precommit.String()
|
||||
}
|
||||
return fmt.Sprintf(`Commit{
|
||||
%s BlockID: %v
|
||||
%s Precommits: %v
|
||||
%s}#%X`,
|
||||
indent, commit.BlockID,
|
||||
indent, strings.Join(precommitStrings, "\n"+indent+" "),
|
||||
indent, commit.hash)
|
||||
}
|
||||
|
||||
+18
-6
@@ -27,6 +27,24 @@ func (err *ErrVoteConflictingVotes) Error() string {
|
||||
return "Conflicting votes"
|
||||
}
|
||||
|
||||
// Types of votes
|
||||
// TODO Make a new type "VoteType"
|
||||
const (
|
||||
VoteTypePrevote = byte(0x01)
|
||||
VoteTypePrecommit = byte(0x02)
|
||||
)
|
||||
|
||||
func IsVoteTypeValid(type_ byte) bool {
|
||||
switch type_ {
|
||||
case VoteTypePrevote:
|
||||
return true
|
||||
case VoteTypePrecommit:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Represents a prevote, precommit, or commit vote from validators for consensus.
|
||||
type Vote struct {
|
||||
ValidatorAddress []byte `json:"validator_address"`
|
||||
@@ -38,12 +56,6 @@ type Vote struct {
|
||||
Signature crypto.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
// Types of votes
|
||||
const (
|
||||
VoteTypePrevote = byte(0x01)
|
||||
VoteTypePrecommit = byte(0x02)
|
||||
)
|
||||
|
||||
func (vote *Vote) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
|
||||
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
||||
wire.WriteTo([]byte(`,"vote":{"block_id":`), w, n, err)
|
||||
|
||||
+17
-2
@@ -317,6 +317,19 @@ func (voteSet *VoteSet) BitArray() *BitArray {
|
||||
return voteSet.votesBitArray.Copy()
|
||||
}
|
||||
|
||||
func (voteSet *VoteSet) BitArrayByBlockID(blockID BlockID) *BitArray {
|
||||
if voteSet == nil {
|
||||
return nil
|
||||
}
|
||||
voteSet.mtx.Lock()
|
||||
defer voteSet.mtx.Unlock()
|
||||
votesByBlock, ok := voteSet.votesByBlock[blockID.Key()]
|
||||
if ok {
|
||||
return votesByBlock.bitArray
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NOTE: if validator has conflicting votes, picks random.
|
||||
func (voteSet *VoteSet) GetByIndex(valIndex int) *Vote {
|
||||
voteSet.mtx.Lock()
|
||||
@@ -429,9 +442,11 @@ func (voteSet *VoteSet) MakeCommit() *Commit {
|
||||
}
|
||||
|
||||
// For every validator, get the precommit
|
||||
maj23Votes := voteSet.votesByBlock[voteSet.maj23.Key()]
|
||||
votesCopy := make([]*Vote, len(voteSet.votes))
|
||||
copy(votesCopy, voteSet.votes)
|
||||
return &Commit{
|
||||
Precommits: maj23Votes.votes,
|
||||
BlockID: *voteSet.maj23,
|
||||
Precommits: votesCopy,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user