mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 04:41:22 +00:00
crypto: Remove interface from crypto.Signature
Signatures are now []byte, which saves on the number of bytes after amino encoding (squash this) address Ismail's comment
This commit is contained in:
committed by
Ethan Buchman
parent
d6a666b445
commit
f903947ff3
@ -3,7 +3,6 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
)
|
||||
|
||||
@ -13,12 +12,12 @@ import (
|
||||
// json field tags because we always want the JSON
|
||||
// representation to be in its canonical form.
|
||||
type Heartbeat struct {
|
||||
ValidatorAddress Address `json:"validator_address"`
|
||||
ValidatorIndex int `json:"validator_index"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Sequence int `json:"sequence"`
|
||||
Signature crypto.Signature `json:"signature"`
|
||||
ValidatorAddress Address `json:"validator_address"`
|
||||
ValidatorIndex int `json:"validator_index"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Sequence int `json:"sequence"`
|
||||
Signature []byte `json:"signature"`
|
||||
}
|
||||
|
||||
// SignBytes returns the Heartbeat bytes for signing.
|
||||
@ -48,5 +47,6 @@ func (heartbeat *Heartbeat) String() string {
|
||||
|
||||
return fmt.Sprintf("Heartbeat{%v:%X %v/%02d (%v) %v}",
|
||||
heartbeat.ValidatorIndex, cmn.Fingerprint(heartbeat.ValidatorAddress),
|
||||
heartbeat.Height, heartbeat.Round, heartbeat.Sequence, heartbeat.Signature)
|
||||
heartbeat.Height, heartbeat.Round, heartbeat.Sequence,
|
||||
fmt.Sprintf("/%X.../", cmn.Fingerprint(heartbeat.Signature[:])))
|
||||
}
|
||||
|
@ -24,13 +24,13 @@ func TestHeartbeatString(t *testing.T) {
|
||||
require.Contains(t, nilHb.String(), "nil", "expecting a string and no panic")
|
||||
|
||||
hb := &Heartbeat{ValidatorIndex: 1, Height: 11, Round: 2}
|
||||
require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) <nil>}")
|
||||
require.Equal(t, "Heartbeat{1:000000000000 11/02 (0) /000000000000.../}", hb.String())
|
||||
|
||||
var key ed25519.PrivKeyEd25519
|
||||
sig, err := key.Sign([]byte("Tendermint"))
|
||||
require.NoError(t, err)
|
||||
hb.Signature = sig
|
||||
require.Equal(t, hb.String(), "Heartbeat{1:000000000000 11/02 (0) /FF41E371B9BF.../}")
|
||||
require.Equal(t, "Heartbeat{1:000000000000 11/02 (0) /FF41E371B9BF.../}", hb.String())
|
||||
}
|
||||
|
||||
func TestHeartbeatWriteSignBytes(t *testing.T) {
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -19,13 +17,13 @@ var (
|
||||
// to be considered valid. It may depend on votes from a previous round,
|
||||
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
|
||||
type Proposal struct {
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
||||
Signature crypto.Signature `json:"signature"`
|
||||
Height int64 `json:"height"`
|
||||
Round int `json:"round"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
||||
Signature []byte `json:"signature"`
|
||||
}
|
||||
|
||||
// NewProposal returns a new Proposal.
|
||||
|
@ -39,7 +39,7 @@ func TestProposalSignable(t *testing.T) {
|
||||
|
||||
func TestProposalString(t *testing.T) {
|
||||
str := testProposal.String()
|
||||
expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) <nil> @ 2018-02-11T07:09:22.765Z}`
|
||||
expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) [] @ 2018-02-11T07:09:22.765Z}`
|
||||
if str != expected {
|
||||
t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ type pubKeyEddie struct{}
|
||||
|
||||
func (pubKeyEddie) Address() Address { return []byte{} }
|
||||
func (pubKeyEddie) Bytes() []byte { return []byte{} }
|
||||
func (pubKeyEddie) VerifyBytes(msg []byte, sig crypto.Signature) bool { return false }
|
||||
func (pubKeyEddie) VerifyBytes(msg []byte, sig []byte) bool { return false }
|
||||
func (pubKeyEddie) Equals(crypto.PubKey) bool { return false }
|
||||
|
||||
func TestABCIValidatorFromPubKeyAndPower(t *testing.T) {
|
||||
|
@ -68,7 +68,7 @@ type Vote struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Type byte `json:"type"`
|
||||
BlockID BlockID `json:"block_id"` // zero if vote is nil.
|
||||
Signature crypto.Signature `json:"signature"`
|
||||
Signature []byte `json:"signature"`
|
||||
}
|
||||
|
||||
func (vote *Vote) SignBytes(chainID string) []byte {
|
||||
|
@ -179,7 +179,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) {
|
||||
|
||||
// If we already know of this vote, return false.
|
||||
if existing, ok := voteSet.getVote(valIndex, blockKey); ok {
|
||||
if existing.Signature.Equals(vote.Signature) {
|
||||
if bytes.Equal(existing.Signature, vote.Signature) {
|
||||
return false, nil // duplicate
|
||||
}
|
||||
return false, errors.Wrapf(ErrVoteNonDeterministicSignature, "Existing vote: %v; New vote: %v", existing, vote)
|
||||
|
Reference in New Issue
Block a user