Browse Source

Add Network to SignBytes, to prevent network clashes

pull/57/head
Jae Kwon 10 years ago
parent
commit
2ba6f86f2e
9 changed files with 51 additions and 40 deletions
  1. +2
    -2
      consensus/reactor.go
  2. +17
    -17
      consensus/state.go
  3. +1
    -1
      consensus/state_test.go
  4. +2
    -0
      consensus/types/proposal.go
  5. +16
    -14
      p2p/connection.go
  6. +1
    -2
      p2p/switch.go
  7. +4
    -4
      rpc/http_server.go
  8. +6
    -0
      types/tx.go
  9. +2
    -0
      types/vote.go

+ 2
- 2
consensus/reactor.go View File

@ -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
} }


+ 17
- 17
consensus/state.go View File

@ -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
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 { 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
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 { 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


+ 1
- 1
consensus/state_test.go View File

@ -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)
} }


+ 2
- 0
consensus/types/proposal.go View File

@ -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)


+ 16
- 14
p2p/connection.go View File

@ -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 {
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 // 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:


+ 1
- 2
p2p/switch.go View File

@ -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",
peer, err)
log.Info(Fmt("Ignoring error from inbound connection: %v\n%v", 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


+ 4
- 4
rpc/http_server.go View File

@ -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,


+ 6
- 0
types/tx.go View File

@ -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)
} }


+ 2
- 0
types/vote.go View File

@ -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)


Loading…
Cancel
Save