add logic to propagate extended commits (#8433)

This commit is contained in:
Callum Waters
2022-10-24 12:30:52 +02:00
parent c095798bd9
commit 574fc51efa
16 changed files with 345 additions and 161 deletions

View File

@@ -381,8 +381,8 @@ func VotesToProto(votes []*Vote) []*tmproto.Vote {
return res
}
// FromProto converts a proto generetad type to a handwritten type
// return type, nil if everything converts safely, otherwise nil, error
// VoteFromProto attempts to convert the given serialization (Protobuf) type to
// our Vote domain type. A basic validation check is also performed.
func VoteFromProto(pv *tmproto.Vote) (*Vote, error) {
if pv == nil {
return nil, errors.New("nil vote")

View File

@@ -2,6 +2,7 @@ package types
import (
"bytes"
"errors"
"fmt"
"strings"
@@ -213,8 +214,17 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
}
// Check signature.
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {
return false, fmt.Errorf("failed to verify vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
if voteSet.extensionsEnabled {
if err := vote.VerifyVoteAndExtension(voteSet.chainID, val.PubKey); err != nil {
return false, fmt.Errorf("failed to verify vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
}
} else {
if err := vote.Verify(voteSet.chainID, val.PubKey); err != nil {
return false, fmt.Errorf("failed to verify vote with ChainID %s and PubKey %s: %w", voteSet.chainID, val.PubKey, err)
}
if len(vote.ExtensionSignature) > 0 || len(vote.Extension) > 0 {
return false, errors.New("unexpected vote extension data present in vote")
}
}
// Add vote and get conflicting vote if any.