mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 16:17:11 +00:00
pass chainID through sign interfaces
This commit is contained in:
+2
-2
@@ -38,7 +38,7 @@ func (pol *POL) Verify(valSet *sm.ValidatorSet) error {
|
||||
}
|
||||
|
||||
talliedVotingPower := uint64(0)
|
||||
prevoteDoc := account.SignBytes(&types.Vote{
|
||||
prevoteDoc := account.SignBytes(config.GetString("chain_id"), &types.Vote{
|
||||
Height: pol.Height, Round: pol.Round, Type: types.VoteTypePrevote,
|
||||
BlockHash: pol.BlockHash,
|
||||
BlockParts: pol.BlockParts,
|
||||
@@ -55,7 +55,7 @@ func (pol *POL) Verify(valSet *sm.ValidatorSet) error {
|
||||
|
||||
// Commit vote?
|
||||
if vote.Round < pol.Round {
|
||||
voteDoc = account.SignBytes(&types.Vote{
|
||||
voteDoc = account.SignBytes(config.GetString("chain_id"), &types.Vote{
|
||||
Height: pol.Height, Round: vote.Round, Type: types.VoteTypeCommit,
|
||||
BlockHash: pol.BlockHash,
|
||||
BlockParts: pol.BlockParts,
|
||||
|
||||
@@ -3,8 +3,8 @@ package consensus
|
||||
import (
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"bytes"
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
// Returns the POLVoteSignature pointer, so you can modify it afterwards.
|
||||
func signAddPOLVoteSignature(val *sm.PrivValidator, valSet *sm.ValidatorSet, vote *types.Vote, pol *POL) *POLVoteSignature {
|
||||
vote = vote.Copy()
|
||||
err := val.SignVote(vote)
|
||||
err := val.SignVote(config.GetString("chain_id"), vote)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
+6
-6
@@ -16,7 +16,7 @@ Consensus State Machine Overview:
|
||||
* The NewHeight is a transition period after the height is incremented,
|
||||
where the node still receives late commits before potentially proposing.
|
||||
The height should be incremented because a block had been
|
||||
"committed by the chain_id", and clients should see that
|
||||
"committed by the network", and clients should see that
|
||||
reflected as a new height.
|
||||
|
||||
+-------------------------------------+
|
||||
@@ -536,7 +536,7 @@ func (cs *ConsensusState) updateToState(state *sm.State, contiguous bool) {
|
||||
Address: cs.privValidator.Address,
|
||||
Height: cs.Height,
|
||||
}
|
||||
err := cs.privValidator.SignRebondTx(rebondTx)
|
||||
err := cs.privValidator.SignRebondTx(cs.state.ChainID, rebondTx)
|
||||
if err == nil {
|
||||
err := cs.mempoolReactor.BroadcastTx(rebondTx)
|
||||
if err != nil {
|
||||
@@ -656,7 +656,7 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) {
|
||||
txs := cs.mempoolReactor.Mempool.GetProposalTxs()
|
||||
block = &types.Block{
|
||||
Header: &types.Header{
|
||||
ChainID: config.GetString("chain_id"),
|
||||
ChainID: cs.state.ChainID,
|
||||
Height: cs.Height,
|
||||
Time: time.Now(),
|
||||
Fees: 0, // TODO fees
|
||||
@@ -688,7 +688,7 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) {
|
||||
|
||||
// Make proposal
|
||||
proposal := NewProposal(cs.Height, cs.Round, blockParts.Header(), polParts.Header())
|
||||
err := cs.privValidator.SignProposal(proposal)
|
||||
err := cs.privValidator.SignProposal(cs.state.ChainID, proposal)
|
||||
if err == nil {
|
||||
log.Info("Signed and set proposal", "height", cs.Height, "round", cs.Round, "proposal", proposal)
|
||||
log.Debug(Fmt("Signed and set proposal block: %v", block))
|
||||
@@ -939,7 +939,7 @@ func (cs *ConsensusState) SetProposal(proposal *Proposal) error {
|
||||
}
|
||||
|
||||
// Verify signature
|
||||
if !cs.Validators.Proposer().PubKey.VerifyBytes(account.SignBytes(proposal), proposal.Signature) {
|
||||
if !cs.Validators.Proposer().PubKey.VerifyBytes(account.SignBytes(cs.state.ChainID, proposal), proposal.Signature) {
|
||||
return ErrInvalidProposalSignature
|
||||
}
|
||||
|
||||
@@ -1111,7 +1111,7 @@ func (cs *ConsensusState) signAddVote(type_ byte, hash []byte, header types.Part
|
||||
BlockHash: hash,
|
||||
BlockParts: header,
|
||||
}
|
||||
err := cs.privValidator.SignVote(vote)
|
||||
err := cs.privValidator.SignVote(cs.state.ChainID, vote)
|
||||
if err == nil {
|
||||
log.Info("Signed and added vote", "height", cs.Height, "round", cs.Round, "vote", vote)
|
||||
cs.addVote(cs.privValidator.Address, vote)
|
||||
|
||||
@@ -16,7 +16,7 @@ func TestSetupRound(t *testing.T) {
|
||||
voteTypes := []byte{types.VoteTypePrevote, types.VoteTypePrecommit, types.VoteTypeCommit}
|
||||
for _, voteType := range voteTypes {
|
||||
vote := &types.Vote{Height: 1, Round: 0, Type: voteType} // nil vote
|
||||
err := val0.SignVote(vote)
|
||||
err := val0.SignVote(cs.state.ChainID, vote)
|
||||
if err != nil {
|
||||
t.Error("Error signing vote: %v", err)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestRunActionPrecommitCommitFinalize(t *testing.T) {
|
||||
BlockHash: cs.ProposalBlock.Hash(),
|
||||
BlockParts: cs.ProposalBlockParts.Header(),
|
||||
}
|
||||
err := privValidators[i].SignVote(vote)
|
||||
err := privValidators[i].SignVote(cs.state.ChainID, vote)
|
||||
if err != nil {
|
||||
t.Error("Error signing vote: %v", err)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ func TestRunActionPrecommitCommitFinalize(t *testing.T) {
|
||||
BlockHash: cs.ProposalBlock.Hash(),
|
||||
BlockParts: cs.ProposalBlockParts.Header(),
|
||||
}
|
||||
err := privValidators[i].SignVote(vote)
|
||||
err := privValidators[i].SignVote(cs.state.ChainID, vote)
|
||||
if err != nil {
|
||||
t.Error("Error signing vote: %v", err)
|
||||
}
|
||||
@@ -192,7 +192,7 @@ func TestRunActionPrecommitCommitFinalize(t *testing.T) {
|
||||
BlockHash: cs.ProposalBlock.Hash(),
|
||||
BlockParts: cs.ProposalBlockParts.Header(),
|
||||
}
|
||||
err := privValidators[i].SignVote(vote)
|
||||
err := privValidators[i].SignVote(cs.state.ChainID, vote)
|
||||
if err != nil {
|
||||
t.Error("Error signing vote: %v", err)
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ func (p *Proposal) String() string {
|
||||
p.BlockParts, p.POLParts, p.Signature)
|
||||
}
|
||||
|
||||
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||
func (p *Proposal) WriteSignBytes(chainID string, w io.Writer, n *int64, err *error) {
|
||||
// We hex encode the chain_id name so we don't deal with escaping issues.
|
||||
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
|
||||
binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, chainID)), w, n, err)
|
||||
binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
|
||||
p.BlockParts.WriteSignBytes(w, n, err)
|
||||
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestProposalSignable(t *testing.T) {
|
||||
POLParts: types.PartSetHeader{222, []byte("polparts")},
|
||||
Signature: nil,
|
||||
}
|
||||
signBytes := account.SignBytes(proposal)
|
||||
signBytes := account.SignBytes(config.GetString("chain_id"), proposal)
|
||||
signStr := string(signBytes)
|
||||
expected := Fmt(`{"chain_id":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`,
|
||||
config.GetString("chain_id"))
|
||||
|
||||
@@ -93,7 +93,7 @@ func (voteSet *VoteSet) Add(address []byte, vote *types.Vote) (bool, uint, error
|
||||
}
|
||||
|
||||
// Check signature.
|
||||
if !val.PubKey.VerifyBytes(account.SignBytes(vote), vote.Signature) {
|
||||
if !val.PubKey.VerifyBytes(account.SignBytes(config.GetString("chain_id"), vote), vote.Signature) {
|
||||
// Bad signature.
|
||||
return false, 0, types.ErrVoteInvalidSignature
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/common/test"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
"github.com/tendermint/tendermint/types"
|
||||
|
||||
"testing"
|
||||
@@ -50,7 +50,7 @@ func withBlockParts(vote *types.Vote, blockParts types.PartSetHeader) *types.Vot
|
||||
}
|
||||
|
||||
func signAddVote(privVal *sm.PrivValidator, vote *types.Vote, voteSet *VoteSet) (bool, error) {
|
||||
privVal.SignVoteUnsafe(vote)
|
||||
privVal.SignVoteUnsafe(config.GetString("chain_id"), vote)
|
||||
added, _, err := voteSet.Add(privVal.Address, vote)
|
||||
return added, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user