mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-03 00:21:20 +00:00
types: remove Version from CanonicalXxx (#2666)
This commit is contained in:
parent
c3384e88e5
commit
e798766a27
@ -307,7 +307,6 @@ We call this encoding the SignBytes. For instance, SignBytes for a vote is the A
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
type CanonicalVote struct {
|
type CanonicalVote struct {
|
||||||
Version uint64 `binary:"fixed64"`
|
|
||||||
Height int64 `binary:"fixed64"`
|
Height int64 `binary:"fixed64"`
|
||||||
Round int64 `binary:"fixed64"`
|
Round int64 `binary:"fixed64"`
|
||||||
VoteType byte
|
VoteType byte
|
||||||
|
@ -23,7 +23,6 @@ type CanonicalPartSetHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CanonicalProposal struct {
|
type CanonicalProposal struct {
|
||||||
Version uint64 `binary:"fixed64"`
|
|
||||||
Height int64 `binary:"fixed64"`
|
Height int64 `binary:"fixed64"`
|
||||||
Round int64 `binary:"fixed64"`
|
Round int64 `binary:"fixed64"`
|
||||||
Type SignedMsgType // type alias for byte
|
Type SignedMsgType // type alias for byte
|
||||||
@ -35,7 +34,6 @@ type CanonicalProposal struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CanonicalVote struct {
|
type CanonicalVote struct {
|
||||||
Version uint64 `binary:"fixed64"`
|
|
||||||
Height int64 `binary:"fixed64"`
|
Height int64 `binary:"fixed64"`
|
||||||
Round int64 `binary:"fixed64"`
|
Round int64 `binary:"fixed64"`
|
||||||
Type SignedMsgType // type alias for byte
|
Type SignedMsgType // type alias for byte
|
||||||
@ -45,9 +43,8 @@ type CanonicalVote struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CanonicalHeartbeat struct {
|
type CanonicalHeartbeat struct {
|
||||||
Version uint64 `binary:"fixed64"`
|
Height int64 `binary:"fixed64"`
|
||||||
Height int64 `binary:"fixed64"`
|
Round int `binary:"fixed64"`
|
||||||
Round int `binary:"fixed64"`
|
|
||||||
Type byte
|
Type byte
|
||||||
Sequence int `binary:"fixed64"`
|
Sequence int `binary:"fixed64"`
|
||||||
ValidatorAddress Address
|
ValidatorAddress Address
|
||||||
@ -74,7 +71,6 @@ func CanonicalizePartSetHeader(psh PartSetHeader) CanonicalPartSetHeader {
|
|||||||
|
|
||||||
func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal {
|
func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal {
|
||||||
return CanonicalProposal{
|
return CanonicalProposal{
|
||||||
Version: 0, // TODO
|
|
||||||
Height: proposal.Height,
|
Height: proposal.Height,
|
||||||
Round: int64(proposal.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
|
Round: int64(proposal.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
|
||||||
Type: ProposalType,
|
Type: ProposalType,
|
||||||
@ -88,7 +84,6 @@ func CanonicalizeProposal(chainID string, proposal *Proposal) CanonicalProposal
|
|||||||
|
|
||||||
func CanonicalizeVote(chainID string, vote *Vote) CanonicalVote {
|
func CanonicalizeVote(chainID string, vote *Vote) CanonicalVote {
|
||||||
return CanonicalVote{
|
return CanonicalVote{
|
||||||
Version: 0, // TODO
|
|
||||||
Height: vote.Height,
|
Height: vote.Height,
|
||||||
Round: int64(vote.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
|
Round: int64(vote.Round), // cast int->int64 to make amino encode it fixed64 (does not work for int)
|
||||||
Type: vote.Type,
|
Type: vote.Type,
|
||||||
@ -100,7 +95,6 @@ func CanonicalizeVote(chainID string, vote *Vote) CanonicalVote {
|
|||||||
|
|
||||||
func CanonicalizeHeartbeat(chainID string, heartbeat *Heartbeat) CanonicalHeartbeat {
|
func CanonicalizeHeartbeat(chainID string, heartbeat *Heartbeat) CanonicalHeartbeat {
|
||||||
return CanonicalHeartbeat{
|
return CanonicalHeartbeat{
|
||||||
Version: 0, // TODO
|
|
||||||
Height: heartbeat.Height,
|
Height: heartbeat.Height,
|
||||||
Round: heartbeat.Round,
|
Round: heartbeat.Round,
|
||||||
Type: byte(HeartbeatType),
|
Type: byte(HeartbeatType),
|
||||||
|
@ -54,8 +54,7 @@ func TestVoteSignable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestVoteSignableTestVectors(t *testing.T) {
|
func TestVoteSignableTestVectors(t *testing.T) {
|
||||||
voteWithVersion := CanonicalizeVote("", &Vote{Height: 1, Round: 1})
|
vote := CanonicalizeVote("", &Vote{Height: 1, Round: 1})
|
||||||
voteWithVersion.Version = 123
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
canonicalVote CanonicalVote
|
canonicalVote CanonicalVote
|
||||||
@ -64,20 +63,20 @@ func TestVoteSignableTestVectors(t *testing.T) {
|
|||||||
{
|
{
|
||||||
CanonicalizeVote("", &Vote{}),
|
CanonicalizeVote("", &Vote{}),
|
||||||
// NOTE: Height and Round are skipped here. This case needs to be considered while parsing.
|
// NOTE: Height and Round are skipped here. This case needs to be considered while parsing.
|
||||||
[]byte{0xb, 0x2a, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
[]byte{0xb, 0x22, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
||||||
},
|
},
|
||||||
// with proper (fixed size) height and round (PreCommit):
|
// with proper (fixed size) height and round (PreCommit):
|
||||||
{
|
{
|
||||||
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrecommitType}),
|
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrecommitType}),
|
||||||
[]byte{
|
[]byte{
|
||||||
0x1f, // total length
|
0x1f, // total length
|
||||||
0x11, // (field_number << 3) | wire_type (version is missing)
|
0x9, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
||||||
0x19, // (field_number << 3) | wire_type
|
0x11, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
||||||
0x20, // (field_number << 3) | wire_type
|
0x18, // (field_number << 3) | wire_type
|
||||||
0x2, // PrecommitType
|
0x2, // PrecommitType
|
||||||
0x2a, // (field_number << 3) | wire_type
|
0x22, // (field_number << 3) | wire_type
|
||||||
// remaining fields (timestamp):
|
// remaining fields (timestamp):
|
||||||
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
||||||
},
|
},
|
||||||
@ -86,29 +85,26 @@ func TestVoteSignableTestVectors(t *testing.T) {
|
|||||||
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrevoteType}),
|
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrevoteType}),
|
||||||
[]byte{
|
[]byte{
|
||||||
0x1f, // total length
|
0x1f, // total length
|
||||||
0x11, // (field_number << 3) | wire_type (version is missing)
|
0x9, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
||||||
0x19, // (field_number << 3) | wire_type
|
0x11, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
||||||
0x20, // (field_number << 3) | wire_type
|
0x18, // (field_number << 3) | wire_type
|
||||||
0x1, // PrevoteType
|
0x1, // PrevoteType
|
||||||
0x2a, // (field_number << 3) | wire_type
|
0x22, // (field_number << 3) | wire_type
|
||||||
// remaining fields (timestamp):
|
// remaining fields (timestamp):
|
||||||
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
||||||
},
|
},
|
||||||
// containing version (empty type)
|
|
||||||
{
|
{
|
||||||
voteWithVersion,
|
vote,
|
||||||
[]byte{
|
[]byte{
|
||||||
0x26, // total length
|
0x1d, // total length
|
||||||
0x9, // (field_number << 3) | wire_type
|
0x9, // (field_number << 3) | wire_type
|
||||||
0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // version (123)
|
|
||||||
0x11, // (field_number << 3) | wire_type
|
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
||||||
0x19, // (field_number << 3) | wire_type
|
0x11, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
||||||
// remaining fields (timestamp):
|
// remaining fields (timestamp):
|
||||||
0x2a,
|
0x22,
|
||||||
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
|
||||||
},
|
},
|
||||||
// containing non-empty chain_id:
|
// containing non-empty chain_id:
|
||||||
@ -116,14 +112,14 @@ func TestVoteSignableTestVectors(t *testing.T) {
|
|||||||
CanonicalizeVote("test_chain_id", &Vote{Height: 1, Round: 1}),
|
CanonicalizeVote("test_chain_id", &Vote{Height: 1, Round: 1}),
|
||||||
[]byte{
|
[]byte{
|
||||||
0x2c, // total length
|
0x2c, // total length
|
||||||
0x11, // (field_number << 3) | wire_type
|
0x9, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
|
||||||
0x19, // (field_number << 3) | wire_type
|
0x11, // (field_number << 3) | wire_type
|
||||||
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
|
||||||
// remaining fields:
|
// remaining fields:
|
||||||
0x2a, // (field_number << 3) | wire_type
|
0x22, // (field_number << 3) | wire_type
|
||||||
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff, // timestamp
|
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff, // timestamp
|
||||||
0x3a, // (field_number << 3) | wire_type
|
0x32, // (field_number << 3) | wire_type
|
||||||
0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID
|
0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user