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