diff --git a/internal/consensus/state.go b/internal/consensus/state.go index 32810e5e55..b328d25eb8 100644 --- a/internal/consensus/state.go +++ b/internal/consensus/state.go @@ -1330,7 +1330,8 @@ func (cs *State) createProposalBlock(ctx context.Context) (*types.Block, error) case ok && lastCommitAsVs.HasTwoThirdsMajority(): // Make the commit from LastCommit. _, blsKey := cs.privValidatorPubKey.(*bls12381.PubKey) - canBeAggregated := blsKey && + _, blsKey2 := cs.privValidatorPubKey.(bls12381.PubKey) + canBeAggregated := (blsKey || blsKey2) && cs.state.Validators.AllKeysHaveSameType() if canBeAggregated { if !cs.isPBTSEnabled(cs.Height) { @@ -2604,13 +2605,13 @@ func (cs *State) AddCommit(commit *types.Commit, peerID p2p.ID) (added bool, err extEnabled := cs.isVoteExtensionsEnabled(commit.Height) if extEnabled { // We don't support receiving commits with vote extensions enabled ATM. - cs.Logger.Error("Received commit with vote extension for height %v (extensions disabled) from peer ID %s", commit.Height, peerID) + cs.Logger.Error("Received commit with vote extensions enabled", "height", commit.Height, "peer_ID", peerID) return added, err } if !commit.HasAggregatedSignature() { // Only accept aggregated commits - cs.Logger.Error("Received non aggregated commit for height %v from peer ID %s", commit.Height, peerID) + cs.Logger.Error("Received non aggregated commit", "commit", commit.Height, "peer_ID", peerID, "commit", commit) return added, err } // No need to check blockID. If the commit is valid, 2/3 of the voting power has signed it. diff --git a/types/block.go b/types/block.go index e82a2f0de9..a5500185f3 100644 --- a/types/block.go +++ b/types/block.go @@ -865,11 +865,12 @@ type Commit struct { BlockID BlockID `json:"block_id"` Signatures []CommitSig `json:"signatures"` - bitArray *bits.BitArray // Memoized in first call to corresponding method. // NOTE: can't memoize in constructor because constructor isn't used for // unmarshaling. - hash cmtbytes.HexBytes + hash cmtbytes.HexBytes + bitArray *bits.BitArray + mtx cmtsync.Mutex // Protects hash and bitArray. } var _ VoteSetReader = (*Commit)(nil) @@ -878,8 +879,12 @@ var _ VoteSetReader = (*Commit)(nil) func (commit *Commit) Clone() *Commit { sigs := make([]CommitSig, len(commit.Signatures)) copy(sigs, commit.Signatures) - commCopy := *commit - commCopy.Signatures = sigs + commCopy := Commit{ + Height: commit.Height, + Round: commit.Round, + BlockID: commit.BlockID, + Signatures: sigs, + } return &commCopy } @@ -909,6 +914,8 @@ func (commit *Commit) Size() int { // this extended commit. // Implements VoteSetReader. func (commit *Commit) BitArray() *bits.BitArray { + commit.mtx.Lock() + defer commit.mtx.Unlock() if commit.bitArray == nil { initialBitFn := func(i int) bool { // TODO: need to check the BlockID otherwise we could be counting conflicts, @@ -1010,6 +1017,8 @@ func (commit *Commit) Hash() cmtbytes.HexBytes { if commit == nil { return nil } + commit.mtx.Lock() + defer commit.mtx.Unlock() if commit.hash == nil { bs := make([][]byte, len(commit.Signatures)) for i, commitSig := range commit.Signatures { @@ -1055,6 +1064,9 @@ func (commit *Commit) StringIndented(indent string) string { for i, commitSig := range commit.Signatures { commitSigStrings[i] = commitSig.String() } + commit.mtx.Lock() + hash := commit.hash + commit.mtx.Unlock() return fmt.Sprintf(`Commit{ %s Height: %d %s Round: %d @@ -1067,7 +1079,7 @@ func (commit *Commit) StringIndented(indent string) string { indent, commit.BlockID, indent, indent, strings.Join(commitSigStrings, "\n"+indent+" "), - indent, commit.hash) + indent, hash) } // ToProto converts Commit to protobuf.