mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 13:55:17 +00:00
Align Vote/Proposal fields with canonical order and fields (#2730)
* reorder fields * add TestVoteString & update tests * remove redundant info from Proposal.String() * update spec * revert changes on vote.String() -> more human friendly
This commit is contained in:
committed by
Ethan Buchman
parent
60437953ac
commit
a530352f61
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@@ -408,14 +408,14 @@
|
|||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:fd98d154bf152ad5a49600ede7d7341851bcdfe358b9b82e5ccdba818618167c"
|
digest = "1:5207b4bc950fd0e45544263103af3e119c94fba6717f9d61931f7a19a7c0706a"
|
||||||
name = "golang.org/x/sys"
|
name = "golang.org/x/sys"
|
||||||
packages = [
|
packages = [
|
||||||
"cpu",
|
"cpu",
|
||||||
"unix",
|
"unix",
|
||||||
]
|
]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "2772b66316d2c587efeb188dcd5ebc6987656e84"
|
revision = "f7626d0b1519d8323581a047ca8b372ebf28de9a"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
|
digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18"
|
||||||
@@ -446,7 +446,7 @@
|
|||||||
name = "google.golang.org/genproto"
|
name = "google.golang.org/genproto"
|
||||||
packages = ["googleapis/rpc/status"]
|
packages = ["googleapis/rpc/status"]
|
||||||
pruneopts = "UT"
|
pruneopts = "UT"
|
||||||
revision = "94acd270e44e65579b9ee3cdab25034d33fed608"
|
revision = "b69ba1387ce2108ac9bc8e8e5e5a46e7d5c72313"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:2dab32a43451e320e49608ff4542fdfc653c95dcc35d0065ec9c6c3dd540ed74"
|
digest = "1:2dab32a43451e320e49608ff4542fdfc653c95dcc35d0065ec9c6c3dd540ed74"
|
||||||
|
|||||||
@@ -146,14 +146,14 @@ The vote includes information about the validator signing it.
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type Vote struct {
|
type Vote struct {
|
||||||
ValidatorAddress []byte
|
Type SignedMsgType // byte
|
||||||
ValidatorIndex int
|
Height int64
|
||||||
Height int64
|
Round int
|
||||||
Round int
|
Timestamp time.Time
|
||||||
Timestamp Time
|
BlockID BlockID
|
||||||
Type int8
|
ValidatorAddress Address
|
||||||
BlockID BlockID
|
ValidatorIndex int
|
||||||
Signature []byte
|
Signature []byte
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,12 @@ var (
|
|||||||
// to be considered valid. It may depend on votes from a previous round,
|
// 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.
|
// a so-called Proof-of-Lock (POL) round, as noted in the POLRound and POLBlockID.
|
||||||
type Proposal struct {
|
type Proposal struct {
|
||||||
|
Type SignedMsgType
|
||||||
Height int64 `json:"height"`
|
Height int64 `json:"height"`
|
||||||
Round int `json:"round"`
|
Round int `json:"round"`
|
||||||
|
POLRound int `json:"pol_round"` // -1 if null.
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
||||||
POLRound int `json:"pol_round"` // -1 if null.
|
|
||||||
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
||||||
Signature []byte `json:"signature"`
|
Signature []byte `json:"signature"`
|
||||||
}
|
}
|
||||||
@@ -33,11 +34,12 @@ type Proposal struct {
|
|||||||
// If there is no POLRound, polRound should be -1.
|
// If there is no POLRound, polRound should be -1.
|
||||||
func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
|
func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
|
||||||
return &Proposal{
|
return &Proposal{
|
||||||
|
Type: ProposalType,
|
||||||
Height: height,
|
Height: height,
|
||||||
Round: round,
|
Round: round,
|
||||||
|
POLRound: polRound,
|
||||||
Timestamp: tmtime.Now(),
|
Timestamp: tmtime.Now(),
|
||||||
BlockPartsHeader: blockPartsHeader,
|
BlockPartsHeader: blockPartsHeader,
|
||||||
POLRound: polRound,
|
|
||||||
POLBlockID: polBlockID,
|
POLBlockID: polBlockID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +47,13 @@ func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRou
|
|||||||
// String returns a string representation of the Proposal.
|
// String returns a string representation of the Proposal.
|
||||||
func (p *Proposal) String() string {
|
func (p *Proposal) String() string {
|
||||||
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}",
|
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}",
|
||||||
p.Height, p.Round, p.BlockPartsHeader, p.POLRound,
|
p.Height,
|
||||||
|
p.Round,
|
||||||
|
p.BlockPartsHeader,
|
||||||
|
p.POLRound,
|
||||||
p.POLBlockID,
|
p.POLBlockID,
|
||||||
cmn.Fingerprint(p.Signature), CanonicalTime(p.Timestamp))
|
cmn.Fingerprint(p.Signature),
|
||||||
|
CanonicalTime(p.Timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignBytes returns the Proposal bytes for signing
|
// SignBytes returns the Proposal bytes for signing
|
||||||
|
|||||||
@@ -48,13 +48,13 @@ type Address = crypto.Address
|
|||||||
|
|
||||||
// Represents a prevote, precommit, or commit vote from validators for consensus.
|
// Represents a prevote, precommit, or commit vote from validators for consensus.
|
||||||
type Vote struct {
|
type Vote struct {
|
||||||
ValidatorAddress Address `json:"validator_address"`
|
Type SignedMsgType `json:"type"`
|
||||||
ValidatorIndex int `json:"validator_index"`
|
|
||||||
Height int64 `json:"height"`
|
Height int64 `json:"height"`
|
||||||
Round int `json:"round"`
|
Round int `json:"round"`
|
||||||
Timestamp time.Time `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Type SignedMsgType `json:"type"`
|
|
||||||
BlockID BlockID `json:"block_id"` // zero if vote is nil.
|
BlockID BlockID `json:"block_id"` // zero if vote is nil.
|
||||||
|
ValidatorAddress Address `json:"validator_address"`
|
||||||
|
ValidatorIndex int `json:"validator_index"`
|
||||||
Signature []byte `json:"signature"`
|
Signature []byte `json:"signature"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,8 @@ func (vote *Vote) String() string {
|
|||||||
typeString,
|
typeString,
|
||||||
cmn.Fingerprint(vote.BlockID.Hash),
|
cmn.Fingerprint(vote.BlockID.Hash),
|
||||||
cmn.Fingerprint(vote.Signature),
|
cmn.Fingerprint(vote.Signature),
|
||||||
CanonicalTime(vote.Timestamp))
|
CanonicalTime(vote.Timestamp),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
|
func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
|
||||||
|
|||||||
@@ -26,12 +26,10 @@ func exampleVote(t byte) *Vote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &Vote{
|
return &Vote{
|
||||||
ValidatorAddress: tmhash.Sum([]byte("validator_address")),
|
Type: SignedMsgType(t),
|
||||||
ValidatorIndex: 56789,
|
Height: 12345,
|
||||||
Height: 12345,
|
Round: 2,
|
||||||
Round: 2,
|
Timestamp: stamp,
|
||||||
Timestamp: stamp,
|
|
||||||
Type: SignedMsgType(t),
|
|
||||||
BlockID: BlockID{
|
BlockID: BlockID{
|
||||||
Hash: tmhash.Sum([]byte("blockID_hash")),
|
Hash: tmhash.Sum([]byte("blockID_hash")),
|
||||||
PartsHeader: PartSetHeader{
|
PartsHeader: PartSetHeader{
|
||||||
@@ -39,6 +37,8 @@ func exampleVote(t byte) *Vote {
|
|||||||
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
|
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
ValidatorAddress: tmhash.Sum([]byte("validator_address")),
|
||||||
|
ValidatorIndex: 56789,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,3 +235,17 @@ func TestMaxVoteBytes(t *testing.T) {
|
|||||||
|
|
||||||
assert.EqualValues(t, MaxVoteBytes, len(bz))
|
assert.EqualValues(t, MaxVoteBytes, len(bz))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVoteString(t *testing.T) {
|
||||||
|
str := examplePrecommit().String()
|
||||||
|
expected := `Vote{56789:6AF1F4111082 12345/02/2(Precommit) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}`
|
||||||
|
if str != expected {
|
||||||
|
t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str)
|
||||||
|
}
|
||||||
|
|
||||||
|
str2 := examplePrevote().String()
|
||||||
|
expected = `Vote{56789:6AF1F4111082 12345/02/1(Prevote) 8B01023386C3 000000000000 @ 2017-12-25T03:00:01.234Z}`
|
||||||
|
if str2 != expected {
|
||||||
|
t.Errorf("Got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user