mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 13:21:20 +00:00
Add Network to SignBytes, to prevent network clashes
This commit is contained in:
@ -545,7 +545,7 @@ OUTER_LOOP:
|
|||||||
type PeerRoundState struct {
|
type PeerRoundState struct {
|
||||||
Height uint // Height peer is at
|
Height uint // Height peer is at
|
||||||
Round uint // Round peer is at
|
Round uint // Round peer is at
|
||||||
Step RoundStep // Step peer is at
|
Step RoundStepType // Step peer is at
|
||||||
StartTime time.Time // Estimated start of round 0 at this height
|
StartTime time.Time // Estimated start of round 0 at this height
|
||||||
Proposal bool // True if peer has proposal for this round
|
Proposal bool // True if peer has proposal for this round
|
||||||
ProposalBlockParts types.PartSetHeader //
|
ProposalBlockParts types.PartSetHeader //
|
||||||
@ -790,7 +790,7 @@ func DecodeMessage(bz []byte) (msgType byte, msg ConsensusMessage, err error) {
|
|||||||
type NewRoundStepMessage struct {
|
type NewRoundStepMessage struct {
|
||||||
Height uint
|
Height uint
|
||||||
Round uint
|
Round uint
|
||||||
Step RoundStep
|
Step RoundStepType
|
||||||
SecondsSinceStartTime uint
|
SecondsSinceStartTime uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,20 +88,20 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RoundStep enum type
|
// RoundStepType enum type
|
||||||
|
|
||||||
type RoundStep uint8
|
type RoundStepType uint8 // These must be numeric, ordered.
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RoundStepNewHeight = RoundStep(0x00) // Round0 for new height started, wait til CommitTime + Delta
|
RoundStepNewHeight = RoundStepType(0x01) // Round0 for new height started, wait til CommitTime + Delta
|
||||||
RoundStepNewRound = RoundStep(0x01) // Pseudostep, immediately goes to RoundStepPropose
|
RoundStepNewRound = RoundStepType(0x02) // Pseudostep, immediately goes to RoundStepPropose
|
||||||
RoundStepPropose = RoundStep(0x10) // Did propose, gossip proposal
|
RoundStepPropose = RoundStepType(0x03) // Did propose, gossip proposal
|
||||||
RoundStepPrevote = RoundStep(0x11) // Did prevote, gossip prevotes
|
RoundStepPrevote = RoundStepType(0x04) // Did prevote, gossip prevotes
|
||||||
RoundStepPrecommit = RoundStep(0x12) // Did precommit, gossip precommits
|
RoundStepPrecommit = RoundStepType(0x05) // Did precommit, gossip precommits
|
||||||
RoundStepCommit = RoundStep(0x20) // Entered commit state machine
|
RoundStepCommit = RoundStepType(0x06) // Entered commit state machine
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rs RoundStep) String() string {
|
func (rs RoundStepType) String() string {
|
||||||
switch rs {
|
switch rs {
|
||||||
case RoundStepNewHeight:
|
case RoundStepNewHeight:
|
||||||
return "RoundStepNewHeight"
|
return "RoundStepNewHeight"
|
||||||
@ -123,15 +123,15 @@ func (rs RoundStep) String() string {
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// RoundAction enum type
|
// RoundAction enum type
|
||||||
|
|
||||||
type RoundActionType uint8
|
type RoundActionType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RoundActionPropose = RoundActionType(0xA0) // Propose and goto RoundStepPropose
|
RoundActionPropose = RoundActionType("PR") // Propose and goto RoundStepPropose
|
||||||
RoundActionPrevote = RoundActionType(0xA1) // Prevote and goto RoundStepPrevote
|
RoundActionPrevote = RoundActionType("PV") // Prevote and goto RoundStepPrevote
|
||||||
RoundActionPrecommit = RoundActionType(0xA2) // Precommit and goto RoundStepPrecommit
|
RoundActionPrecommit = RoundActionType("PC") // Precommit and goto RoundStepPrecommit
|
||||||
RoundActionTryCommit = RoundActionType(0xC0) // Goto RoundStepCommit, or RoundStepPropose for next round.
|
RoundActionTryCommit = RoundActionType("TC") // Goto RoundStepCommit, or RoundStepPropose for next round.
|
||||||
RoundActionCommit = RoundActionType(0xC1) // Goto RoundStepCommit upon +2/3 commits
|
RoundActionCommit = RoundActionType("CM") // Goto RoundStepCommit upon +2/3 commits
|
||||||
RoundActionTryFinalize = RoundActionType(0xC2) // Maybe goto RoundStepPropose for next round.
|
RoundActionTryFinalize = RoundActionType("TF") // Maybe goto RoundStepPropose for next round.
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rat RoundActionType) String() string {
|
func (rat RoundActionType) String() string {
|
||||||
@ -171,7 +171,7 @@ func (ra RoundAction) String() string {
|
|||||||
type RoundState struct {
|
type RoundState struct {
|
||||||
Height uint // Height we are working on
|
Height uint // Height we are working on
|
||||||
Round uint
|
Round uint
|
||||||
Step RoundStep
|
Step RoundStepType
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
CommitTime time.Time // Time when +2/3 commits were found
|
CommitTime time.Time // Time when +2/3 commits were found
|
||||||
Validators *sm.ValidatorSet
|
Validators *sm.ValidatorSet
|
||||||
|
@ -82,7 +82,7 @@ func TestRunActionPropose(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkRoundState(t *testing.T, rs *RoundState,
|
func checkRoundState(t *testing.T, rs *RoundState,
|
||||||
height uint, round uint, step RoundStep) {
|
height uint, round uint, step RoundStepType) {
|
||||||
if rs.Height != height {
|
if rs.Height != height {
|
||||||
t.Errorf("rs.Height should be %v, got %v", height, rs.Height)
|
t.Errorf("rs.Height should be %v, got %v", height, rs.Height)
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/account"
|
"github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
|
"github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ func (p *Proposal) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (p *Proposal) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteUvarint(p.Height, w, n, err)
|
binary.WriteUvarint(p.Height, w, n, err)
|
||||||
binary.WriteUvarint(p.Round, w, n, err)
|
binary.WriteUvarint(p.Round, w, n, err)
|
||||||
binary.WriteBinary(p.BlockParts, w, n, err)
|
binary.WriteBinary(p.BlockParts, w, n, err)
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
flow "code.google.com/p/mxk/go1/flowcontrol"
|
flow "code.google.com/p/mxk/go1/flowcontrol"
|
||||||
"github.com/tendermint/log15"
|
//"github.com/tendermint/log15"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
@ -365,18 +365,20 @@ FOR_LOOP:
|
|||||||
// Block until .recvMonitor says we can read.
|
// Block until .recvMonitor says we can read.
|
||||||
c.recvMonitor.Limit(maxMsgPacketSize, atomic.LoadInt64(&c.recvRate), true)
|
c.recvMonitor.Limit(maxMsgPacketSize, atomic.LoadInt64(&c.recvRate), true)
|
||||||
|
|
||||||
// Peek into bufReader for debugging
|
/*
|
||||||
if numBytes := c.bufReader.Buffered(); numBytes > 0 {
|
// Peek into bufReader for debugging
|
||||||
log.Debug("Peek connection buffer", "numBytes", numBytes, "bytes", log15.Lazy{func() []byte {
|
if numBytes := c.bufReader.Buffered(); numBytes > 0 {
|
||||||
bytes, err := c.bufReader.Peek(MinInt(numBytes, 100))
|
log.Debug("Peek connection buffer", "numBytes", numBytes, "bytes", log15.Lazy{func() []byte {
|
||||||
if err == nil {
|
bytes, err := c.bufReader.Peek(MinInt(numBytes, 100))
|
||||||
return bytes
|
if err == nil {
|
||||||
} else {
|
return bytes
|
||||||
log.Warn("Error peeking connection buffer", "error", err)
|
} else {
|
||||||
return nil
|
log.Warn("Error peeking connection buffer", "error", err)
|
||||||
}
|
return nil
|
||||||
}})
|
}
|
||||||
}
|
}})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Read packet type
|
// Read packet type
|
||||||
var n int64
|
var n int64
|
||||||
@ -417,7 +419,7 @@ FOR_LOOP:
|
|||||||
}
|
}
|
||||||
msgBytes := channel.recvMsgPacket(pkt)
|
msgBytes := channel.recvMsgPacket(pkt)
|
||||||
if msgBytes != nil {
|
if msgBytes != nil {
|
||||||
log.Debug("Received bytes", "chId", pkt.ChannelId, "msgBytes", msgBytes)
|
//log.Debug("Received bytes", "chId", pkt.ChannelId, "msgBytes", msgBytes)
|
||||||
c.onReceive(pkt.ChannelId, msgBytes)
|
c.onReceive(pkt.ChannelId, msgBytes)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -287,8 +287,7 @@ func (sw *Switch) listenerRoutine(l Listener) {
|
|||||||
// New inbound connection!
|
// New inbound connection!
|
||||||
peer, err := sw.AddPeerWithConnection(inConn, false)
|
peer, err := sw.AddPeerWithConnection(inConn, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("Ignoring error from inbound connection: %v\n%v",
|
log.Info(Fmt("Ignoring error from inbound connection: %v\n%v", peer, err))
|
||||||
peer, err)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// NOTE: We don't yet have the external address of the
|
// NOTE: We don't yet have the external address of the
|
||||||
|
@ -25,7 +25,7 @@ func StartHTTPServer(listenAddr string, handler http.Handler) {
|
|||||||
netListener,
|
netListener,
|
||||||
RecoverAndLogHandler(handler),
|
RecoverAndLogHandler(handler),
|
||||||
)
|
)
|
||||||
log.Crit("RPC HTTPServer stopped", "result", res)
|
log.Crit("RPC HTTP server stopped", "result", res)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) {
|
|||||||
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
buf, n, err := new(bytes.Buffer), new(int64), new(error)
|
||||||
binary.WriteJSON(res, buf, n, err)
|
binary.WriteJSON(res, buf, n, err)
|
||||||
if *err != nil {
|
if *err != nil {
|
||||||
log.Warn("Failed to write JSON RPCResponse", "error", err)
|
log.Warn("Failed to write RPC response", "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@ -70,7 +70,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
|
|||||||
WriteRPCResponse(rww, res)
|
WriteRPCResponse(rww, res)
|
||||||
} else {
|
} else {
|
||||||
// For the rest,
|
// For the rest,
|
||||||
log.Error("Panic in HTTP handler", "error", e, "stack", string(debug.Stack()))
|
log.Error("Panic in RPC HTTP handler", "error", e, "stack", string(debug.Stack()))
|
||||||
rww.WriteHeader(http.StatusInternalServerError)
|
rww.WriteHeader(http.StatusInternalServerError)
|
||||||
WriteRPCResponse(rww, NewRPCResponse(nil, Fmt("Internal Server Error: %v", e)))
|
WriteRPCResponse(rww, NewRPCResponse(nil, Fmt("Internal Server Error: %v", e)))
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
|
|||||||
if rww.Status == -1 {
|
if rww.Status == -1 {
|
||||||
rww.Status = 200
|
rww.Status = 200
|
||||||
}
|
}
|
||||||
log.Debug("Served HTTP response",
|
log.Debug("Served RPC HTTP response",
|
||||||
"method", r.Method, "url", r.URL,
|
"method", r.Method, "url", r.URL,
|
||||||
"status", rww.Status, "duration", durationMS,
|
"status", rww.Status, "duration", durationMS,
|
||||||
"remoteAddr", r.RemoteAddr,
|
"remoteAddr", r.RemoteAddr,
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/account"
|
"github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
"github.com/tendermint/tendermint/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -133,6 +134,7 @@ type SendTx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (tx *SendTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteUvarint(uint(len(tx.Inputs)), w, n, err)
|
binary.WriteUvarint(uint(len(tx.Inputs)), w, n, err)
|
||||||
for _, in := range tx.Inputs {
|
for _, in := range tx.Inputs {
|
||||||
in.WriteSignBytes(w, n, err)
|
in.WriteSignBytes(w, n, err)
|
||||||
@ -158,6 +160,7 @@ type CallTx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *CallTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (tx *CallTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
tx.Input.WriteSignBytes(w, n, err)
|
tx.Input.WriteSignBytes(w, n, err)
|
||||||
binary.WriteByteSlice(tx.Address, w, n, err)
|
binary.WriteByteSlice(tx.Address, w, n, err)
|
||||||
binary.WriteUint64(tx.GasLimit, w, n, err)
|
binary.WriteUint64(tx.GasLimit, w, n, err)
|
||||||
@ -178,6 +181,7 @@ type BondTx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (tx *BondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteBinary(tx.PubKey, w, n, err)
|
binary.WriteBinary(tx.PubKey, w, n, err)
|
||||||
binary.WriteUvarint(uint(len(tx.Inputs)), w, n, err)
|
binary.WriteUvarint(uint(len(tx.Inputs)), w, n, err)
|
||||||
for _, in := range tx.Inputs {
|
for _, in := range tx.Inputs {
|
||||||
@ -202,6 +206,7 @@ type UnbondTx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (tx *UnbondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteByteSlice(tx.Address, w, n, err)
|
binary.WriteByteSlice(tx.Address, w, n, err)
|
||||||
binary.WriteUvarint(tx.Height, w, n, err)
|
binary.WriteUvarint(tx.Height, w, n, err)
|
||||||
}
|
}
|
||||||
@ -219,6 +224,7 @@ type RebondTx struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (tx *RebondTx) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteByteSlice(tx.Address, w, n, err)
|
binary.WriteByteSlice(tx.Address, w, n, err)
|
||||||
binary.WriteUvarint(tx.Height, w, n, err)
|
binary.WriteUvarint(tx.Height, w, n, err)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/account"
|
"github.com/tendermint/tendermint/account"
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
"github.com/tendermint/tendermint/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -46,6 +47,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) {
|
||||||
|
binary.WriteString(config.App().GetString("Network"), w, n, err)
|
||||||
binary.WriteUvarint(vote.Height, w, n, err)
|
binary.WriteUvarint(vote.Height, w, n, err)
|
||||||
binary.WriteUvarint(vote.Round, w, n, err)
|
binary.WriteUvarint(vote.Round, w, n, err)
|
||||||
binary.WriteByte(vote.Type, w, n, err)
|
binary.WriteByte(vote.Type, w, n, err)
|
||||||
|
Reference in New Issue
Block a user