diff --git a/alert/alert.go b/alert/alert.go index 70393dd7..c4763309 100644 --- a/alert/alert.go +++ b/alert/alert.go @@ -15,7 +15,7 @@ func Alert(message string) { log.Error(" ALERT \n" + message) now := time.Now().Unix() 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 { message = fmt.Sprintf("%v (+%v more since)", message, alertCountSince) alertCountSince = 0 diff --git a/config/tendermint/config.go b/config/tendermint/config.go index 32be222a..17dbfc9e 100644 --- a/config/tendermint/config.go +++ b/config/tendermint/config.go @@ -51,13 +51,13 @@ func GetConfig(rootDir string) cfg.Config { } // Set defaults or panic - if !mapConfig.IsSet("network") { - Exit("Must set 'network'") + if mapConfig.IsSet("chain_id") { + Exit("Cannot set 'chain_id' via config.toml") } if mapConfig.IsSet("version") { 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("genesis_file", rootDir+"/genesis.json") 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. # For more information, see https://github.com/toml-lang/toml -network = "tendermint_testnet_5" moniker = "__MONIKER__" node_laddr = "0.0.0.0:46656" seeds = "goldenalchemist.chaintest.net:46656" @@ -98,6 +97,7 @@ func defaultConfig(moniker string) (defaultConfig string) { } var defaultGenesis = `{ + "chain_id": "tendermint_testnet_5", "accounts": [ { "address": "F81CB9ED0A868BD961C4F5BBC0E39B763B89FCB6", diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 7f78a3c2..418f026d 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -60,13 +60,13 @@ func GetConfig(rootDir string) cfg.Config { } // Set defaults or panic - if !mapConfig.IsSet("network") { - Exit("Must set 'network'") + if mapConfig.IsSet("chain_id") { + Exit("Cannot set 'chain_id' via config.toml") } if mapConfig.IsSet("version") { 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("genesis_file", rootDir+"/genesis.json") 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. # For more information, see https://github.com/toml-lang/toml -network = "tendermint_test" moniker = "__MONIKER__" node_laddr = "0.0.0.0:36656" seeds = "" @@ -106,6 +105,7 @@ func defaultConfig(moniker string) (defaultConfig string) { } var defaultGenesis = `{ + "chain_id" : "tendermint_test", "accounts": [ { "address": "1D7A91CB32F758A02EBB9BE1FB6F8DEE56F90D42", diff --git a/consensus/state.go b/consensus/state.go index 6b6d4ae2..0f75f531 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -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 network", and clients should see that + "committed by the chain_id", and clients should see that reflected as a new height. +-------------------------------------+ @@ -656,7 +656,7 @@ func (cs *ConsensusState) RunActionPropose(height uint, round uint) { txs := cs.mempoolReactor.Mempool.GetProposalTxs() block = &types.Block{ Header: &types.Header{ - Network: config.GetString("network"), + ChainID: config.GetString("chain_id"), Height: cs.Height, Time: time.Now(), Fees: 0, // TODO fees diff --git a/consensus/types/proposal.go b/consensus/types/proposal.go index 0d6e018c..642fa59f 100644 --- a/consensus/types/proposal.go +++ b/consensus/types/proposal.go @@ -39,8 +39,8 @@ func (p *Proposal) String() string { } 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // 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(`,"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) diff --git a/consensus/types/proposal_test.go b/consensus/types/proposal_test.go index fea9f079..cef57faf 100644 --- a/consensus/types/proposal_test.go +++ b/consensus/types/proposal_test.go @@ -19,8 +19,8 @@ func TestProposalSignable(t *testing.T) { } signBytes := account.SignBytes(proposal) signStr := string(signBytes) - expected := Fmt(`{"network":"%X","proposal":{"block_parts":{"hash":"626C6F636B7061727473","total":111},"height":12345,"pol_parts":{"hash":"706F6C7061727473","total":222},"round":23456}}`, - config.GetString("network")) + 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")) if signStr != expected { t.Errorf("Got unexpected sign string for SendTx. Expected:\n%v\nGot:\n%v", expected, signStr) } diff --git a/crawler/crawl.go b/crawler/crawl.go index a3e5cf72..b337d320 100644 --- a/crawler/crawl.go +++ b/crawler/crawl.go @@ -20,7 +20,7 @@ const ( //--------------------------------------------------------------------------------------- // crawler.Node -// A node is a peer on the network. +// A node is a peer on the network type Node struct { Host string P2PPort uint16 @@ -32,7 +32,7 @@ type Node struct { client *NodeClient LastSeen time.Time - Network string + ChainID string BlockHeight uint BlockHistory map[uint]time.Time // when we saw each block NetInfo *rpctypes.ResponseNetInfo @@ -47,10 +47,10 @@ func (n *Node) Address() string { 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) { n.LastSeen = time.Now() - n.Network = status.Network + n.ChainID = status.ChainID n.BlockHeight = status.LatestBlockHeight n.NetInfo = netinfo // n.Validator diff --git a/node/id.go b/node/id.go index b65ea4ac..2d52213f 100644 --- a/node/id.go +++ b/node/id.go @@ -18,7 +18,7 @@ type PrivNodeID struct { type NodeGreeting struct { NodeID Version string - Network string + ChainID string Message string Time time.Time } diff --git a/node/node.go b/node/node.go index ed0816a0..aa6eb124 100644 --- a/node/node.go +++ b/node/node.go @@ -56,6 +56,8 @@ func NewNode() *Node { state = sm.MakeGenesisStateFromFile(stateDB, config.GetString("genesis_file")) state.Save() } + // add the chainid to the global config + config.Set("chain_id", state.ChainID) // Get PrivValidator var privValidator *sm.PrivValidator @@ -212,7 +214,7 @@ func (n *Node) EventSwitch() *events.EventSwitch { func makeNodeInfo(sw *p2p.Switch) *types.NodeInfo { nodeInfo := &types.NodeInfo{ - Network: config.GetString("network"), + ChainID: config.GetString("chain_id"), Moniker: config.GetString("moniker"), Version: config.GetString("version"), } diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 98bf4b4d..209defcc 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -76,13 +76,13 @@ func makeSwitchPair(t testing.TB, initSwitch func(*Switch) *Switch) (*Switch, *S s1 := initSwitch(NewSwitch()) s1.SetNodeInfo(&types.NodeInfo{ Moniker: "switch1", - Network: "testing", + ChainID: "testing", Version: "123.123.123", }) s2 := initSwitch(NewSwitch()) s2.SetNodeInfo(&types.NodeInfo{ Moniker: "switch2", - Network: "testing", + ChainID: "testing", Version: "123.123.123", }) diff --git a/rpc/core/net.go b/rpc/core/net.go index 22811ddd..842602a2 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -1,6 +1,8 @@ package core import ( + "io/ioutil" + dbm "github.com/tendermint/tendermint/db" ctypes "github.com/tendermint/tendermint/rpc/core/types" sm "github.com/tendermint/tendermint/state" @@ -27,7 +29,7 @@ func Status() (*ctypes.ResponseStatus, error) { return &ctypes.ResponseStatus{ Moniker: config.GetString("moniker"), - Network: config.GetString("network"), + ChainID: config.GetString("chain_id"), Version: config.GetString("version"), GenesisHash: genesisHash, PubKey: privValidator.PubKey, @@ -57,3 +59,14 @@ func NetInfo() (*ctypes.ResponseNetInfo, error) { Peers: peers, }, 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 +} diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 3934fcaa..9239695f 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -66,7 +66,7 @@ type Receipt struct { type ResponseStatus struct { Moniker string `json:"moniker"` - Network string `json:"network"` + ChainID string `json:"chain_id"` Version string `json:"version"` GenesisHash []byte `json:"genesis_hash"` PubKey account.PubKey `json:"pub_key"` diff --git a/rpc/core_client/client_methods.go b/rpc/core_client/client_methods.go index e9593b18..aa48dcff 100644 --- a/rpc/core_client/client_methods.go +++ b/rpc/core_client/client_methods.go @@ -21,6 +21,7 @@ type Client interface { DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) + Genesis() (*string, error) GetAccount(address []byte) (*ctypes.ResponseGetAccount, error) GetBlock(height uint) (*ctypes.ResponseGetBlock, error) GetStorage(address []byte, key []byte) (*ctypes.ResponseGetStorage, error) @@ -242,6 +243,36 @@ func (c *ClientHTTP) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) { 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) { values, err := argsToURLValues([]string{"address"}, address) if err != nil { @@ -701,6 +732,33 @@ func (c *ClientJSON) GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error) { 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) { request := rpctypes.RPCRequest{ JSONRPC: "2.0", diff --git a/rpc/test/tests.go b/rpc/test/tests.go index 40819e0b..7a172c2c 100644 --- a/rpc/test/tests.go +++ b/rpc/test/tests.go @@ -15,9 +15,9 @@ func testStatus(t *testing.T, typ string) { if err != nil { t.Fatal(err) } - if resp.Network != config.GetString("network") { - t.Fatal(fmt.Errorf("Network mismatch: got %s expected %s", - resp.Network, config.Get("network"))) + if resp.ChainID != config.GetString("chain_id") { + t.Fatal(fmt.Errorf("ChainID mismatch: got %s expected %s", + resp.ChainID, config.Get("chain_id"))) } } diff --git a/state/genesis.go b/state/genesis.go index f43c22ef..691597ce 100644 --- a/state/genesis.go +++ b/state/genesis.go @@ -25,6 +25,7 @@ type GenesisValidator struct { type GenesisDoc struct { GenesisTime time.Time `json:"genesis_time"` + ChainID string `json:"chain_id"` Accounts []GenesisAccount `json:"accounts"` Validators []GenesisValidator `json:"validators"` } @@ -105,6 +106,7 @@ func MakeGenesisState(db dbm.DB, genDoc *GenesisDoc) *State { return &State{ DB: db, + ChainID: genDoc.ChainID, LastBlockHeight: 0, LastBlockHash: nil, LastBlockParts: types.PartSetHeader{}, diff --git a/state/state.go b/state/state.go index 182d2692..13bd7d74 100644 --- a/state/state.go +++ b/state/state.go @@ -26,6 +26,7 @@ var ( // NOTE: not goroutine-safe. type State struct { DB dbm.DB + ChainID string LastBlockHeight uint LastBlockHash []byte LastBlockParts types.PartSetHeader @@ -46,6 +47,7 @@ func LoadState(db dbm.DB) *State { return nil } else { 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.LastBlockHash = binary.ReadByteSlice(r, n, err) s.LastBlockParts = binary.ReadBinary(types.PartSetHeader{}, r, n, err).(types.PartSetHeader) @@ -71,6 +73,7 @@ func (s *State) Save() { s.accounts.Save() s.validatorInfos.Save() 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.WriteByteSlice(s.LastBlockHash, buf, n, err) binary.WriteBinary(s.LastBlockParts, buf, n, err) @@ -92,6 +95,7 @@ func (s *State) Save() { func (s *State) Copy() *State { return &State{ DB: s.DB, + ChainID: s.ChainID, LastBlockHeight: s.LastBlockHeight, LastBlockHash: s.LastBlockHash, LastBlockParts: s.LastBlockParts, diff --git a/state/state_test.go b/state/state_test.go index d11c5cc5..1885c8f1 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -65,7 +65,7 @@ func TestCopyState(t *testing.T) { func makeBlock(t *testing.T, state *State, commits []types.Commit, txs []types.Tx) *types.Block { block := &types.Block{ Header: &types.Header{ - Network: "tendermint_test", + ChainID: "tendermint_test", Height: state.LastBlockHeight + 1, Time: state.LastBlockTime.Add(time.Minute), Fees: 0, diff --git a/types/block.go b/types/block.go index 8ef46950..25de6dd1 100644 --- a/types/block.go +++ b/types/block.go @@ -23,8 +23,8 @@ type Block struct { // Basic validation that doesn't involve state data. func (b *Block) ValidateBasic(lastBlockHeight uint, lastBlockHash []byte, lastBlockParts PartSetHeader, lastBlockTime time.Time) error { - if b.Network != config.GetString("network") { - return errors.New("Wrong Block.Header.Network") + if b.ChainID != config.GetString("chain_id") { + return errors.New("Wrong Block.Header.ChainID") } if b.Height != lastBlockHeight+1 { return errors.New("Wrong Block.Header.Height") @@ -122,7 +122,7 @@ func (b *Block) StringShort() string { //----------------------------------------------------------------------------- type Header struct { - Network string `json:"network"` + ChainID string `json:"chain_id"` Height uint `json:"height"` Time time.Time `json:"time"` Fees uint64 `json:"fees"` @@ -154,7 +154,7 @@ func (h *Header) StringIndented(indent string) string { return "nil-Header" } return fmt.Sprintf(`Header{ -%s Network: %v +%s ChainID: %v %s Height: %v %s Time: %v %s Fees: %v @@ -163,7 +163,7 @@ func (h *Header) StringIndented(indent string) string { %s LastBlockParts: %v %s StateHash: %X %s}#%X`, - indent, h.Network, + indent, h.ChainID, indent, h.Height, indent, h.Time, indent, h.Fees, diff --git a/types/node.go b/types/node.go index b42e4bbb..8cb1255a 100644 --- a/types/node.go +++ b/types/node.go @@ -7,7 +7,7 @@ import ( type NodeInfo struct { Moniker string `json:"moniker"` - Network string `json:"network"` + ChainID string `json:"chain_id"` Version string `json:"version"` 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) } - // nodes must be on the same network - if ni.Network != no.Network { - return fmt.Errorf("Peer is on a different network. Got %v, expected %v", no.Network, ni.Network) + // nodes must be on the same chain_id + if ni.ChainID != no.ChainID { + return fmt.Errorf("Peer is on a different chain_id. Got %v, expected %v", no.ChainID, ni.ChainID) } return nil diff --git a/types/tx.go b/types/tx.go index 3331eafa..00fe34d7 100644 --- a/types/tx.go +++ b/types/tx.go @@ -130,8 +130,8 @@ type SendTx struct { } 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // We hex encode the chain_id 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(`,"tx":[%v,{"inputs":[`, TxTypeSend)), w, n, err) for i, in := range tx.Inputs { in.WriteSignBytes(w, n, err) @@ -164,8 +164,8 @@ type CallTx struct { } 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // We hex encode the chain_id 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(`,"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) tx.Input.WriteSignBytes(w, n, err) @@ -186,8 +186,8 @@ type BondTx struct { } 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // We hex encode the chain_id 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(`,"tx":[%v,{"inputs":[`, TxTypeBond)), w, n, err) for i, in := range tx.Inputs { in.WriteSignBytes(w, n, err) @@ -220,8 +220,8 @@ type UnbondTx struct { } 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // We hex encode the chain_id 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(`,"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) { - // We hex encode the network name so we don't deal with escaping issues. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // We hex encode the chain_id 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(`,"tx":[%v,{"address":"%X","height":%v}]}`, TxTypeRebond, tx.Address, tx.Height)), w, n, err) } diff --git a/types/tx_test.go b/types/tx_test.go index edc5b868..88d8204f 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -35,8 +35,8 @@ func TestSendTxSignable(t *testing.T) { } signBytes := account.SignBytes(sendTx) 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}]}]}`, - config.GetString("network")) + 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("chain_id")) if signStr != expected { 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) 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}}]}`, - config.GetString("network")) + 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("chain_id")) if signStr != expected { 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) 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}]}]}`, - config.GetString("network")) + 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("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for BondTx") } @@ -106,8 +106,8 @@ func TestUnbondTxSignable(t *testing.T) { } signBytes := account.SignBytes(unbondTx) signStr := string(signBytes) - expected := Fmt(`{"network":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`, - config.GetString("network")) + expected := Fmt(`{"chain_id":"%X","tx":[18,{"address":"6164647265737331","height":111}]}`, + config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for UnbondTx") } @@ -120,8 +120,8 @@ func TestRebondTxSignable(t *testing.T) { } signBytes := account.SignBytes(rebondTx) signStr := string(signBytes) - expected := Fmt(`{"network":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`, - config.GetString("network")) + expected := Fmt(`{"chain_id":"%X","tx":[19,{"address":"6164647265737331","height":111}]}`, + config.GetString("chain_id")) if signStr != expected { t.Errorf("Got unexpected sign string for RebondTx") } diff --git a/types/vote.go b/types/vote.go index f9ed0f9d..d733f72d 100644 --- a/types/vote.go +++ b/types/vote.go @@ -46,8 +46,8 @@ const ( ) 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. - binary.WriteTo([]byte(Fmt(`{"network":"%X"`, config.GetString("network"))), w, n, err) + // 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(`,"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) }