mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-17 21:44:24 +00:00
Fix proposal sign bytes. Start tracking blockID in POL
This commit is contained in:
+7
-3
@@ -376,9 +376,13 @@ func (blockID BlockID) Key() string {
|
||||
}
|
||||
|
||||
func (blockID BlockID) WriteSignBytes(w io.Writer, n *int, err *error) {
|
||||
wire.WriteTo([]byte(Fmt(`{"hash":"%X","parts":`, blockID.Hash)), w, n, err)
|
||||
blockID.PartsHeader.WriteSignBytes(w, n, err)
|
||||
wire.WriteTo([]byte("}"), w, n, err)
|
||||
if blockID.IsZero() {
|
||||
wire.WriteTo([]byte("null"), w, n, err)
|
||||
} else {
|
||||
wire.WriteTo([]byte(Fmt(`{"hash":"%X","parts":`, blockID.Hash)), w, n, err)
|
||||
blockID.PartsHeader.WriteSignBytes(w, n, err)
|
||||
wire.WriteTo([]byte("}"), w, n, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (blockID BlockID) String() string {
|
||||
|
||||
+9
-5
@@ -19,29 +19,33 @@ type Proposal struct {
|
||||
Height int `json:"height"`
|
||||
Round int `json:"round"`
|
||||
BlockPartsHeader PartSetHeader `json:"block_parts_header"`
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
POLRound int `json:"pol_round"` // -1 if null.
|
||||
POLBlockID BlockID `json:"pol_block_id"` // zero if null.
|
||||
Signature crypto.SignatureEd25519 `json:"signature"`
|
||||
}
|
||||
|
||||
// polRound: -1 if no polRound.
|
||||
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int) *Proposal {
|
||||
func NewProposal(height int, round int, blockPartsHeader PartSetHeader, polRound int, polBlockID BlockID) *Proposal {
|
||||
return &Proposal{
|
||||
Height: height,
|
||||
Round: round,
|
||||
BlockPartsHeader: blockPartsHeader,
|
||||
POLRound: polRound,
|
||||
POLBlockID: polBlockID,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Proposal) String() string {
|
||||
return fmt.Sprintf("Proposal{%v/%v %v %v %v}", p.Height, p.Round,
|
||||
p.BlockPartsHeader, p.POLRound, p.Signature)
|
||||
return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v}", p.Height, p.Round,
|
||||
p.BlockPartsHeader, p.POLRound, p.POLBlockID, p.Signature)
|
||||
}
|
||||
|
||||
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int, err *error) {
|
||||
wire.WriteTo([]byte(Fmt(`{"chain_id":"%s"`, chainID)), w, n, err)
|
||||
wire.WriteTo([]byte(`,"proposal":{"block_parts_header":`), w, n, err)
|
||||
p.BlockPartsHeader.WriteSignBytes(w, n, err)
|
||||
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_round":%v`, p.Height, p.POLRound)), w, n, err)
|
||||
wire.WriteTo([]byte(Fmt(`,"height":%v,"pol_block_id":`, p.Height)), w, n, err)
|
||||
p.POLBlockID.WriteSignBytes(w, n, err)
|
||||
wire.WriteTo([]byte(Fmt(`,"pol_round":%v`, p.POLRound)), w, n, err)
|
||||
wire.WriteTo([]byte(Fmt(`,"round":%v}}`, p.Round)), w, n, err)
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ func TestProposalSignable(t *testing.T) {
|
||||
signBytes := SignBytes("test_chain_id", proposal)
|
||||
signStr := string(signBytes)
|
||||
|
||||
expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_round":-1,"round":23456}}`
|
||||
expected := `{"chain_id":"test_chain_id","proposal":{"block_parts_header":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_block_id":null,"pol_round":-1,"round":23456}}`
|
||||
if signStr != expected {
|
||||
t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
|
||||
t.Errorf("Got unexpected sign string for Proposal. Expected:\n%v\nGot:\n%v", expected, signStr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVoteSignable(t *testing.T) {
|
||||
vote := &Vote{
|
||||
ValidatorAddress: []byte("addr"),
|
||||
ValidatorIndex: 56789,
|
||||
Height: 12345,
|
||||
Round: 23456,
|
||||
Type: byte(2),
|
||||
BlockID: BlockID{
|
||||
Hash: []byte("hash"),
|
||||
PartsHeader: PartSetHeader{
|
||||
Total: 1000000,
|
||||
Hash: []byte("parts_hash"),
|
||||
},
|
||||
},
|
||||
}
|
||||
signBytes := SignBytes("test_chain_id", vote)
|
||||
signStr := string(signBytes)
|
||||
|
||||
expected := `{"chain_id":"test_chain_id","vote":{"block_id":{"hash":"68617368","parts":{"hash":"70617274735F68617368","total":1000000}},"height":12345,"round":23456,"type":2}}`
|
||||
if signStr != expected {
|
||||
// NOTE: when this fails, you probably want to fix up consensus/replay_test too
|
||||
t.Errorf("Got unexpected sign string for Vote. Expected:\n%v\nGot:\n%v", expected, signStr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user