network > chain_id, put in genesis.json

This commit is contained in:
Ethan Buchman
2015-05-29 14:13:45 -04:00
parent bb67fe0356
commit 8a2d9525f0
22 changed files with 139 additions and 60 deletions

View File

@ -15,7 +15,7 @@ func Alert(message string) {
log.Error("<!> ALERT <!>\n" + message) log.Error("<!> ALERT <!>\n" + message)
now := time.Now().Unix() now := time.Now().Unix()
if now-lastAlertUnix > int64(config.GetInt("alert_min_interval")) { if now-lastAlertUnix > int64(config.GetInt("alert_min_interval")) {
message = fmt.Sprintf("%v:%v", config.GetString("network"), message) message = fmt.Sprintf("%v:%v", config.GetString("chain_id"), message)
if alertCountSince > 0 { if alertCountSince > 0 {
message = fmt.Sprintf("%v (+%v more since)", message, alertCountSince) message = fmt.Sprintf("%v (+%v more since)", message, alertCountSince)
alertCountSince = 0 alertCountSince = 0

View File

@ -51,13 +51,13 @@ func GetConfig(rootDir string) cfg.Config {
} }
// Set defaults or panic // Set defaults or panic
if !mapConfig.IsSet("network") { if mapConfig.IsSet("chain_id") {
Exit("Must set 'network'") Exit("Cannot set 'chain_id' via config.toml")
} }
if mapConfig.IsSet("version") { if mapConfig.IsSet("version") {
Exit("Cannot set 'version' via config.toml") Exit("Cannot set 'version' via config.toml")
} }
// mapConfig.SetDefault("network", "tendermint_testnet0") mapConfig.SetDefault("chain_id", "tendermint_testnet_5")
mapConfig.SetDefault("version", "0.3.0") // JAE: changed merkle tree persistence format for merkle proofs. mapConfig.SetDefault("version", "0.3.0") // JAE: changed merkle tree persistence format for merkle proofs.
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
mapConfig.SetDefault("moniker", "anonymous") mapConfig.SetDefault("moniker", "anonymous")
@ -82,7 +82,6 @@ func ensureDefault(mapConfig cfg.MapConfig, key string, value interface{}) {
var defaultConfigTmpl = `# This is a TOML config file. var defaultConfigTmpl = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml # For more information, see https://github.com/toml-lang/toml
network = "tendermint_testnet_5"
moniker = "__MONIKER__" moniker = "__MONIKER__"
node_laddr = "0.0.0.0:46656" node_laddr = "0.0.0.0:46656"
seeds = "goldenalchemist.chaintest.net:46656" seeds = "goldenalchemist.chaintest.net:46656"
@ -98,6 +97,7 @@ func defaultConfig(moniker string) (defaultConfig string) {
} }
var defaultGenesis = `{ var defaultGenesis = `{
"chain_id": "tendermint_testnet_5",
"accounts": [ "accounts": [
{ {
"address": "F81CB9ED0A868BD961C4F5BBC0E39B763B89FCB6", "address": "F81CB9ED0A868BD961C4F5BBC0E39B763B89FCB6",

View File

@ -60,13 +60,13 @@ func GetConfig(rootDir string) cfg.Config {
} }
// Set defaults or panic // Set defaults or panic
if !mapConfig.IsSet("network") { if mapConfig.IsSet("chain_id") {
Exit("Must set 'network'") Exit("Cannot set 'chain_id' via config.toml")
} }
if mapConfig.IsSet("version") { if mapConfig.IsSet("version") {
Exit("Cannot set 'version' via config.toml") Exit("Cannot set 'version' via config.toml")
} }
// mapConfig.SetDefault("network", "tendermint_testnet0") mapConfig.SetDefault("chain_id", "tendermint_test")
mapConfig.SetDefault("version", "0.3.0") mapConfig.SetDefault("version", "0.3.0")
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
mapConfig.SetDefault("moniker", "anonymous") mapConfig.SetDefault("moniker", "anonymous")
@ -90,7 +90,6 @@ func ensureDefault(mapConfig cfg.MapConfig, key string, value interface{}) {
var defaultConfigTmpl = `# This is a TOML config file. var defaultConfigTmpl = `# This is a TOML config file.
# For more information, see https://github.com/toml-lang/toml # For more information, see https://github.com/toml-lang/toml
network = "tendermint_test"
moniker = "__MONIKER__" moniker = "__MONIKER__"
node_laddr = "0.0.0.0:36656" node_laddr = "0.0.0.0:36656"
seeds = "" seeds = ""
@ -106,6 +105,7 @@ func defaultConfig(moniker string) (defaultConfig string) {
} }
var defaultGenesis = `{ var defaultGenesis = `{
"chain_id" : "tendermint_test",
"accounts": [ "accounts": [
{ {
"address": "1D7A91CB32F758A02EBB9BE1FB6F8DEE56F90D42", "address": "1D7A91CB32F758A02EBB9BE1FB6F8DEE56F90D42",

View File

@ -16,7 +16,7 @@ Consensus State Machine Overview:
* The NewHeight is a transition period after the height is incremented, * The NewHeight is a transition period after the height is incremented,
where the node still receives late commits before potentially proposing. where the node still receives late commits before potentially proposing.
The height should be incremented because a block had been The height should be incremented because a block had been
"committed by the network", and clients should see that "committed by the chain_id", and clients should see that
reflected as a new height. reflected as a new height.
+-------------------------------------+ +-------------------------------------+
@ -656,7 +656,7 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) {
txs := cs.mempoolReactor.Mempool.GetProposalTxs() txs := cs.mempoolReactor.Mempool.GetProposalTxs()
block = &types.Block{ block = &types.Block{
Header: &types.Header{ Header: &types.Header{
Network: config.GetString("network"), ChainID: config.GetString("chain_id"),
Height: cs.Height, Height: cs.Height,
Time: time.Now(), Time: time.Now(),
Fees: 0, // TODO fees Fees: 0, // TODO fees

View File

@ -39,8 +39,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err) binary.WriteTo([]byte(`,"proposal":{"block_parts":`), w, n, err)
p.BlockParts.WriteSignBytes(w, n, err) p.BlockParts.WriteSignBytes(w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"pol_parts":`, p.Height)), w, n, err)

View File

@ -19,8 +19,8 @@ func TestProposalSignable(t *testing.T) {
} }
signBytes := account.SignBytes(proposal) signBytes := account.SignBytes(proposal)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`, expected := Fmt(`{"chain_id":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { 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 SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
} }

View File

@ -20,7 +20,7 @@ const (
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------
// crawler.Node // crawler.Node
// A node is a peer on the network. // A node is a peer on the network
type Node struct { type Node struct {
Host string Host string
P2PPort uint16 P2PPort uint16
@ -32,7 +32,7 @@ type Node struct {
client *NodeClient client *NodeClient
LastSeen time.Time LastSeen time.Time
Network string ChainID string
BlockHeight uint BlockHeight uint
BlockHistory map[uint]time.Time // when we saw each block BlockHistory map[uint]time.Time // when we saw each block
NetInfo *rpctypes.ResponseNetInfo NetInfo *rpctypes.ResponseNetInfo
@ -47,10 +47,10 @@ func (n *Node) Address() string {
return fmt.Sprintf("%s:%d", n.Host, n.RPCPort) return fmt.Sprintf("%s:%d", n.Host, n.RPCPort)
} }
// Set the basic status and network info for a node from RPC responses // Set the basic status and chain_id info for a node from RPC responses
func (n *Node) SetInfo(status *rpctypes.ResponseStatus, netinfo *rpctypes.ResponseNetInfo) { func (n *Node) SetInfo(status *rpctypes.ResponseStatus, netinfo *rpctypes.ResponseNetInfo) {
n.LastSeen = time.Now() n.LastSeen = time.Now()
n.Network = status.Network n.ChainID = status.ChainID
n.BlockHeight = status.LatestBlockHeight n.BlockHeight = status.LatestBlockHeight
n.NetInfo = netinfo n.NetInfo = netinfo
// n.Validator // n.Validator

View File

@ -18,7 +18,7 @@ type PrivNodeID struct {
type NodeGreeting struct { type NodeGreeting struct {
NodeID NodeID
Version string Version string
Network string ChainID string
Message string Message string
Time time.Time Time time.Time
} }

View File

@ -56,6 +56,8 @@ func NewNode() *Node {
state = sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file")) state = sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file"))
state.Save() state.Save()
} }
// add the chainid to the global config
config.Set("chain_id", state.ChainID)
// Get PrivValidator // Get PrivValidator
var privValidator *sm.PrivValidator var privValidator *sm.PrivValidator
@ -212,7 +214,7 @@ func (n *Node) EventSwitch() *events.EventSwitch {
func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo { func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo {
nodeInfo := &types.NodeInfo{ nodeInfo := &types.NodeInfo{
Network: config.GetString("network"), ChainID: config.GetString("chain_id"),
Moniker: config.GetString("moniker"), Moniker: config.GetString("moniker"),
Version: config.GetString("version"), Version: config.GetString("version"),
} }

View File

@ -76,13 +76,13 @@ func makeSwitchPair(t testing.TB, initSwitch func(*Switch) *Switch) (*Switch, *S
s1 := initSwitch(NewSwitch()) s1 := initSwitch(NewSwitch())
s1.SetNodeInfo(&types.NodeInfo{ s1.SetNodeInfo(&types.NodeInfo{
Moniker: "switch1", Moniker: "switch1",
Network: "testing", ChainID: "testing",
Version: "123.123.123", Version: "123.123.123",
}) })
s2 := initSwitch(NewSwitch()) s2 := initSwitch(NewSwitch())
s2.SetNodeInfo(&types.NodeInfo{ s2.SetNodeInfo(&types.NodeInfo{
Moniker: "switch2", Moniker: "switch2",
Network: "testing", ChainID: "testing",
Version: "123.123.123", Version: "123.123.123",
}) })

View File

@ -1,6 +1,8 @@
package core package core
import ( import (
"io/ioutil"
dbm "github.com/tendermint/tendermint/db" dbm "github.com/tendermint/tendermint/db"
ctypes "github.com/tendermint/tendermint/rpc/core/types" ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
@ -27,7 +29,7 @@ func Status() (*ctypes.ResponseStatus, error) {
return &ctypes.ResponseStatus{ return &ctypes.ResponseStatus{
Moniker: config.GetString("moniker"), Moniker: config.GetString("moniker"),
Network: config.GetString("network"), ChainID: config.GetString("chain_id"),
Version: config.GetString("version"), Version: config.GetString("version"),
GenesisHash: genesisHash, GenesisHash: genesisHash,
PubKey: privValidator.PubKey, PubKey: privValidator.PubKey,
@ -57,3 +59,14 @@ func NetInfo() (*ctypes.ResponseNetInfo, error) {
Peers: peers, Peers: peers,
}, nil }, nil
} }
//-----------------------------------------------------------------------------
// returns pointer because the rpc-gen code returns nil (TODO!)
func Genesis() (*string, error) {
b, err := ioutil.ReadFile(config.GetString("genesis_file"))
if err != nil {
return "", err
}
return &string(b), nil
}

View File

@ -66,7 +66,7 @@ type Receipt struct {
type ResponseStatus struct { type ResponseStatus struct {
Moniker string `json:"moniker"` Moniker string `json:"moniker"`
Network string `json:"network"` ChainID string `json:"chain_id"`
Version string `json:"version"` Version string `json:"version"`
GenesisHash []byte `json:"genesis_hash"` GenesisHash []byte `json:"genesis_hash"`
PubKey account.PubKey `json:"pub_key"` PubKey account.PubKey `json:"pub_key"`

View File

@ -21,6 +21,7 @@ type Client interface {
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error)
Genesis() (*string, error)
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
GetBlock(height uint) (*ctypes.ResponseGetBlock, error) GetBlock(height uint) (*ctypes.ResponseGetBlock, error)
GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error)
@ -242,6 +243,36 @@ func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientHTTP) Genesis() (*string, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["Genesis"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *string `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) { func (c *ClientHTTP) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
values, err := argsToURLValues([]string{"address"}, address) values, err := argsToURLValues([]string{"address"}, address)
if err != nil { if err != nil {
@ -701,6 +732,33 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) {
return response.Result, nil return response.Result, nil
} }
func (c *ClientJSON) Genesis() (*string, error) {
request := rpctypes.RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["Genesis"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *string `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) { func (c *ClientJSON) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) {
request := rpctypes.RPCRequest{ request := rpctypes.RPCRequest{
JSONRPC: "2.0", JSONRPC: "2.0",

View File

@ -15,9 +15,9 @@ func testStatus(t *testing.T, typ string) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if resp.Network != config.GetString("network") { if resp.ChainID != config.GetString("chain_id") {
t.Fatal(fmt.Errorf("Network mismatch: got %s expected %s", t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s",
resp.Network, config.Get("network"))) resp.ChainID, config.Get("chain_id")))
} }
} }

View File

@ -25,6 +25,7 @@ type GenesisValidator struct {
type GenesisDoc struct { type GenesisDoc struct {
GenesisTime time.Time `json:"genesis_time"` GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"`
Accounts []GenesisAccount `json:"accounts"` Accounts []GenesisAccount `json:"accounts"`
Validators []GenesisValidator `json:"validators"` Validators []GenesisValidator `json:"validators"`
} }
@ -105,6 +106,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State {
return &State{ return &State{
DB: db, DB: db,
ChainID: genDoc.ChainID,
LastBlockHeight: 0, LastBlockHeight: 0,
LastBlockHash: nil, LastBlockHash: nil,
LastBlockParts: types.PartSetHeader{}, LastBlockParts: types.PartSetHeader{},

View File

@ -26,6 +26,7 @@ var (
// NOTE: not goroutine-safe. // NOTE: not goroutine-safe.
type State struct { type State struct {
DB dbm.DB DB dbm.DB
ChainID string
LastBlockHeight uint LastBlockHeight uint
LastBlockHash []byte LastBlockHash []byte
LastBlockParts types.PartSetHeader LastBlockParts types.PartSetHeader
@ -46,6 +47,7 @@ func LoadState(db dbm.DB) *State {
return nil return nil
} else { } else {
r, n, err := bytes.NewReader(buf), new(int64), new(error) r, n, err := bytes.NewReader(buf), new(int64), new(error)
s.ChainID = binary.ReadString(r, n, err)
s.LastBlockHeight = binary.ReadUvarint(r, n, err) s.LastBlockHeight = binary.ReadUvarint(r, n, err)
s.LastBlockHash = binary.ReadByteSlice(r, n, err) s.LastBlockHash = binary.ReadByteSlice(r, n, err)
s.LastBlockParts = binary.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader) s.LastBlockParts = binary.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader)
@ -71,6 +73,7 @@ func (s *State) Save() {
s.accounts.Save() s.accounts.Save()
s.validatorInfos.Save() s.validatorInfos.Save()
buf, n, err := new(bytes.Buffer), new(int64), new(error) buf, n, err := new(bytes.Buffer), new(int64), new(error)
binary.WriteString(s.ChainID, buf, n, err)
binary.WriteUvarint(s.LastBlockHeight, buf, n, err) binary.WriteUvarint(s.LastBlockHeight, buf, n, err)
binary.WriteByteSlice(s.LastBlockHash, buf, n, err) binary.WriteByteSlice(s.LastBlockHash, buf, n, err)
binary.WriteBinary(s.LastBlockParts, buf, n, err) binary.WriteBinary(s.LastBlockParts, buf, n, err)
@ -92,6 +95,7 @@ func (s *State) Save() {
func (s *State) Copy() *State { func (s *State) Copy() *State {
return &State{ return &State{
DB: s.DB, DB: s.DB,
ChainID: s.ChainID,
LastBlockHeight: s.LastBlockHeight, LastBlockHeight: s.LastBlockHeight,
LastBlockHash: s.LastBlockHash, LastBlockHash: s.LastBlockHash,
LastBlockParts: s.LastBlockParts, LastBlockParts: s.LastBlockParts,

View File

@ -65,7 +65,7 @@ func TestCopyState(t *testing.T) {
func makeBlock(t *testing.T, state *State, commits []types.Commit, txs []types.Tx) *types.Block { func makeBlock(t *testing.T, state *State, commits []types.Commit, txs []types.Tx) *types.Block {
block := &types.Block{ block := &types.Block{
Header: &types.Header{ Header: &types.Header{
Network: "tendermint_test", ChainID: "tendermint_test",
Height: state.LastBlockHeight + 1, Height: state.LastBlockHeight + 1,
Time: state.LastBlockTime.Add(time.Minute), Time: state.LastBlockTime.Add(time.Minute),
Fees: 0, Fees: 0,

View File

@ -23,8 +23,8 @@ type Block struct {
// Basic validation that doesn't involve state data. // Basic validation that doesn't involve state data.
func (b *Block) ValidateBasic(lastBlockHeight uint, lastBlockHash []byte, func (b *Block) ValidateBasic(lastBlockHeight uint, lastBlockHash []byte,
lastBlockParts PartSetHeader, lastBlockTime time.Time) error { lastBlockParts PartSetHeader, lastBlockTime time.Time) error {
if b.Network != config.GetString("network") { if b.ChainID != config.GetString("chain_id") {
return errors.New("Wrong Block.Header.Network") return errors.New("Wrong Block.Header.ChainID")
} }
if b.Height != lastBlockHeight+1 { if b.Height != lastBlockHeight+1 {
return errors.New("Wrong Block.Header.Height") return errors.New("Wrong Block.Header.Height")
@ -122,7 +122,7 @@ func (b *Block) StringShort() string {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
type Header struct { type Header struct {
Network string `json:"network"` ChainID string `json:"chain_id"`
Height uint `json:"height"` Height uint `json:"height"`
Time time.Time `json:"time"` Time time.Time `json:"time"`
Fees uint64 `json:"fees"` Fees uint64 `json:"fees"`
@ -154,7 +154,7 @@ func (h *Header) StringIndented(indent string) string {
return "nil-Header" return "nil-Header"
} }
return fmt.Sprintf(`Header{ return fmt.Sprintf(`Header{
%s Network: %v %s ChainID: %v
%s Height: %v %s Height: %v
%s Time: %v %s Time: %v
%s Fees: %v %s Fees: %v
@ -163,7 +163,7 @@ func (h *Header) StringIndented(indent string) string {
%s LastBlockParts: %v %s LastBlockParts: %v
%s StateHash: %X %s StateHash: %X
%s}#%X`, %s}#%X`,
indent, h.Network, indent, h.ChainID,
indent, h.Height, indent, h.Height,
indent, h.Time, indent, h.Time,
indent, h.Fees, indent, h.Fees,

View File

@ -7,7 +7,7 @@ import (
type NodeInfo struct { type NodeInfo struct {
Moniker string `json:"moniker"` Moniker string `json:"moniker"`
Network string `json:"network"` ChainID string `json:"chain_id"`
Version string `json:"version"` Version string `json:"version"`
Host string `json:"host"` Host string `json:"host"`
@ -39,9 +39,9 @@ func (ni *NodeInfo) CompatibleWith(no *NodeInfo) error {
return fmt.Errorf("Peer is on a different minor version. Got %v, expected %v", om, im) return fmt.Errorf("Peer is on a different minor version. Got %v, expected %v", om, im)
} }
// nodes must be on the same network // nodes must be on the same chain_id
if ni.Network != no.Network { if ni.ChainID != no.ChainID {
return fmt.Errorf("Peer is on a different network. Got %v, expected %v", no.Network, ni.Network) return fmt.Errorf("Peer is on a different chain_id. Got %v, expected %v", no.ChainID, ni.ChainID)
} }
return nil return nil

View File

@ -130,8 +130,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err)
for i, in := range tx.Inputs { for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err) in.WriteSignBytes(w, n, err)
@ -164,8 +164,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","data":"%X"`, TxTypeCall, tx.Address, tx.Data)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err) binary.WriteTo([]byte(Fmt(`,"fee":%v,"gas_limit":%v,"input":`, tx.Fee, tx.GasLimit)), w, n, err)
tx.Input.WriteSignBytes(w, n, err) tx.Input.WriteSignBytes(w, n, err)
@ -186,8 +186,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err)
for i, in := range tx.Inputs { for i, in := range tx.Inputs {
in.WriteSignBytes(w, n, err) in.WriteSignBytes(w, n, err)
@ -220,8 +220,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeUnbond, tx.Address, tx.Height)), w, n, err)
} }
@ -238,8 +238,8 @@ 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) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) binary.WriteTo([]byte(Fmt(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err)
} }

View File

@ -35,8 +35,8 @@ func TestSendTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(sendTx) signBytes := account.SignBytes(sendTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, expected := Fmt(`{"chain_id":"%X","tx":[1,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"outputs":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { 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 SendTx. Expected:\n%v\nGot:\n%v", expected, signStr)
} }
@ -56,8 +56,8 @@ func TestCallTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(callTx) signBytes := account.SignBytes(callTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`, expected := Fmt(`{"chain_id":"%X","tx":[2,{"address":"636F6E747261637431","data":"6461746131","fee":222,"gas_limit":111,"input":{"address":"696E70757431","amount":12345,"sequence":67890}}]}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr) t.Errorf("Got unexpected sign string for CallTx. Expected:\n%v\nGot:\n%v", expected, signStr)
} }
@ -92,8 +92,8 @@ func TestBondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(bondTx) signBytes := account.SignBytes(bondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`, expected := Fmt(`{"chain_id":"%X","tx":[17,{"inputs":[{"address":"696E70757431","amount":12345,"sequence":67890},{"address":"696E70757432","amount":111,"sequence":222}],"pub_key":[1,"3B6A27BCCEB6A42D62A3A8D02A6F0D73653215771DE243A63AC048A18B59DA29"],"unbond_to":[{"address":"6F757470757431","amount":333},{"address":"6F757470757432","amount":444}]}]}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for BondTx") t.Errorf("Got unexpected sign string for BondTx")
} }
@ -106,8 +106,8 @@ func TestUnbondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(unbondTx) signBytes := account.SignBytes(unbondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`, expected := Fmt(`{"chain_id":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for UnbondTx") t.Errorf("Got unexpected sign string for UnbondTx")
} }
@ -120,8 +120,8 @@ func TestRebondTxSignable(t *testing.T) {
} }
signBytes := account.SignBytes(rebondTx) signBytes := account.SignBytes(rebondTx)
signStr := string(signBytes) signStr := string(signBytes)
expected := Fmt(`{"network":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`, expected := Fmt(`{"chain_id":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`,
config.GetString("network")) config.GetString("chain_id"))
if signStr != expected { if signStr != expected {
t.Errorf("Got unexpected sign string for RebondTx") t.Errorf("Got unexpected sign string for RebondTx")
} }

View File

@ -46,8 +46,8 @@ const (
) )
func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) { func (vote *Vote) WriteSignBytes(w io.Writer, n *int64, err *error) {
// We hex encode the network name so we don't deal with escaping issues. // We hex encode the chain_id name so we don't deal with escaping issues.
binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) binary.WriteTo([]byte(Fmt(`{"chain_id":"%X"`, config.GetString("chain_id"))), w, n, err)
binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err) binary.WriteTo([]byte(Fmt(`,"vote":{"block_hash":"%X","block_parts":%v`, vote.BlockHash, vote.BlockParts)), w, n, err)
binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err) binary.WriteTo([]byte(Fmt(`,"height":%v,"round":%v,"type":%v}}`, vote.Height, vote.Round, vote.Type)), w, n, err)
} }