From 469fcd876195ce7cb53fc92619e5e94735946cd9 Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Fri, 19 Jul 2019 11:47:42 +0800 Subject: [PATCH 1/7] get shardchainconfig from rpc rest cli interface --- cmd/info_cmd.go | 30 +++++++++++++++++++++++++++++- cmd/utils/ont.go | 18 ++++++++++++++++++ consensus/vbft/config/config.go | 8 ++++++++ http/base/actor/ledger.go | 11 +++++++++++ http/base/error/error.go | 1 + http/base/rest/interfaces.go | 23 +++++++++++++++++++++++ http/base/rpc/interfaces.go | 31 +++++++++++++++++++++++++++++++ http/restful/restful/server.go | 2 ++ 8 files changed, 123 insertions(+), 1 deletion(-) diff --git a/cmd/info_cmd.go b/cmd/info_cmd.go index 6624d6bf01..9a9b1ffb22 100644 --- a/cmd/info_cmd.go +++ b/cmd/info_cmd.go @@ -21,11 +21,12 @@ package cmd import ( "encoding/hex" "fmt" + "strconv" + "github.com/ontio/ontology/cmd/utils" "github.com/ontio/ontology/core/types" httpcom "github.com/ontio/ontology/http/base/common" "github.com/urfave/cli" - "strconv" ) var InfoCommand = cli.Command{ @@ -92,6 +93,16 @@ var InfoCommand = cli.Command{ utils.RPCPortFlag, }, }, + { + Action: getShardChainConfig, + Name: "shardChainConfig", + Usage: "Display chain config by shardID,block height", + ArgsUsage: "", + Description: `Display shard chainconfig by shardID,block height`, + Flags: []cli.Flag{ + utils.RPCPortFlag, + }, + }, }, Description: `Query information command can query information such as blocks, transactions, and transaction executions. You can use the ./Ontology info block --help command to view help information.`, @@ -257,3 +268,20 @@ func showTx(ctx *cli.Context) error { PrintJsonObject(txInfo) return nil } + +func getShardChainConfig(ctx *cli.Context) error { + SetRpcPort(ctx) + if ctx.NArg() < 2 { + PrintErrorMsg("Missing argument. shardID,height expected.") + cli.ShowSubcommandHelp(ctx) + return nil + } + shardID, _ := strconv.ParseUint(ctx.Args().First(), 10, 32) + height, _ := strconv.ParseUint(ctx.Args().Get(1), 10, 32) + chainConfig, err := utils.GetShardChainConfig(uint64(shardID), height) + if err != nil { + return fmt.Errorf("GetShardChainConfig err:%s", err) + } + PrintJsonObject(chainConfig) + return nil +} diff --git a/cmd/utils/ont.go b/cmd/utils/ont.go index fbdcc32a21..7c3e7edf62 100644 --- a/cmd/utils/ont.go +++ b/cmd/utils/ont.go @@ -24,6 +24,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + vconfig "github.com/ontio/ontology/consensus/vbft/config" "math/rand" "sort" "strconv" @@ -621,6 +622,23 @@ func GetTxHeight(txHash string) (uint32, error) { return height, nil } +func GetShardChainConfig(shardID uint64, height uint64) (*vconfig.ChainConfig, error) { + data, ontErr := sendRpcRequest("getshardChainConfig", []interface{}{shardID, height}) + if ontErr != nil { + switch ontErr.ErrorCode { + case ERROR_INVALID_PARAMS: + return nil, fmt.Errorf("cannot find shard chainconfig by sharID:%d,height:%d", shardID, height) + } + return nil, ontErr.Error + } + cfg := &vconfig.ChainConfig{} + err := json.Unmarshal(data, &cfg) + if err != nil { + return nil, fmt.Errorf("json.Unmarshal error:%s", err) + } + return cfg, nil +} + func DeployContract( gasPrice, gasLimit uint64, diff --git a/consensus/vbft/config/config.go b/consensus/vbft/config/config.go index 55d0d08d3e..53c78acc60 100644 --- a/consensus/vbft/config/config.go +++ b/consensus/vbft/config/config.go @@ -101,6 +101,14 @@ func (cc *ChainConfig) Serialize(w io.Writer) error { return nil } +func (cc *ChainConfig) ToArray() ([]byte, error) { + data, err := json.Marshal(cc) + if err != nil { + return nil, err + } + return data, nil +} + func (pc *PeerConfig) Serialize(w io.Writer) error { if err := serialization.WriteUint32(w, pc.Index); err != nil { return fmt.Errorf("ChainConfig peer index length serialization failed %s", err) diff --git a/http/base/actor/ledger.go b/http/base/actor/ledger.go index 8078e49463..8c7632e758 100644 --- a/http/base/actor/ledger.go +++ b/http/base/actor/ledger.go @@ -20,6 +20,8 @@ package actor import ( "github.com/ontio/ontology/common" + "github.com/ontio/ontology/consensus/utils" + vconfig "github.com/ontio/ontology/consensus/vbft/config" "github.com/ontio/ontology/core/chainmgr/xshard_state" "github.com/ontio/ontology/core/ledger" "github.com/ontio/ontology/core/payload" @@ -113,3 +115,12 @@ func GetEventNotifyByHeight(height uint32) ([]*event.ExecuteNotify, error) { func GetMerkleProof(proofHeight uint32, rootHeight uint32) ([]common.Uint256, error) { return ledger.DefLedger.GetMerkleProof(proofHeight, rootHeight) } + +//GetShardChainConfig +func GetShardChainConfig(shardID common.ShardID, height uint32) (*vconfig.ChainConfig, error) { + if ledger.DefLedger.ParentLedger != nil { + return utils.GetShardConfigByShardID(ledger.DefLedger.ParentLedger, shardID, height) + } else { + return nil, nil + } +} diff --git a/http/base/error/error.go b/http/base/error/error.go index 946b2071d8..a859b9b8fe 100644 --- a/http/base/error/error.go +++ b/http/base/error/error.go @@ -39,6 +39,7 @@ const ( UNKNOWN_ASSET int64 = 44002 UNKNOWN_BLOCK int64 = 44003 UNKNOWN_CONTRACT int64 = 44004 + UNKNOWN_CHAINCONFIG int64 = 44005 INTERNAL_ERROR int64 = 45001 SMARTCODE_ERROR int64 = 47001 diff --git a/http/base/rest/interfaces.go b/http/base/rest/interfaces.go index 32a9d157bc..40a7470d66 100644 --- a/http/base/rest/interfaces.go +++ b/http/base/rest/interfaces.go @@ -565,6 +565,29 @@ func GetShardTxState(cmd map[string]interface{}) map[string]interface{} { return resp } +func GetShardChainConfig(cmd map[string]interface{}) map[string]interface{} { + resp := ResponsePack(berr.SUCCESS) + id, ok := cmd["shardID"].(uint32) + if !ok { + return ResponsePack(berr.INVALID_PARAMS) + } + height, ok := cmd["height"].(uint32) + if !ok { + return ResponsePack(berr.INVALID_PARAMS) + } + shardID, err := common.NewShardID(uint64(id)) + if err != nil { + return ResponsePack(berr.INTERNAL_ERROR) + } + chainConfig, err := bactor.GetShardChainConfig(shardID, height) + if err != nil { + return ResponsePack(berr.INTERNAL_ERROR) + } + value, err := chainConfig.ToArray() + resp["Result"] = common.ToHexString(value) + return resp +} + //get balance of address func GetBalance(cmd map[string]interface{}) map[string]interface{} { resp := ResponsePack(berr.SUCCESS) diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index a5e10323cf..4fb5c7ecd1 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -764,3 +764,34 @@ func GetGrantOng(params []interface{}) map[string]interface{} { } return responseSuccess(rsp) } + +//get shard chainconfig +func GetShardChainConfig(params []interface{}) map[string]interface{} { + if len(params) < 2 { + return responsePack(berr.INVALID_PARAMS, nil) + } + var shardID common.ShardID + var height uint32 + switch params[0].(type) { + case float64: + id := uint32(params[0].(float64)) + shardId, err := common.NewShardID(uint64(id)) + if err != nil { + return responsePack(berr.INVALID_PARAMS, "") + } + shardID = shardId + } + switch params[1].(type) { + case float64: + height = uint32(params[0].(float64)) + } + chainConfig, err := bactor.GetShardChainConfig(shardID, height) + if err != nil { + return responsePack(berr.UNKNOWN_CHAINCONFIG, "") + } + data, err := chainConfig.ToArray() + if err != nil { + return responsePack(berr.UNKNOWN_CHAINCONFIG, "") + } + return responseSuccess(common.ToHexString(data)) +} diff --git a/http/restful/restful/server.go b/http/restful/restful/server.go index 2c7ff37b25..c2e5b42863 100644 --- a/http/restful/restful/server.go +++ b/http/restful/restful/server.go @@ -66,6 +66,7 @@ const ( GET_SHARD_STORAGE = "/api/v1/shardstorage/:shardid/:hash/:key" GET_SHARD_TX_STATE_NID = "/api/v1/shardtxstate/:txhash/:notifyid" GET_SHARD_TX_STATE = "/api/v1/shardtxstate/:txhash" + GET_SHARD_CHAIN_CONFIG = "/api/v1/shardchainconfig/:shardid/:height" GET_BALANCE = "/api/v1/balance/:addr" GET_CONTRACT_STATE = "/api/v1/contract/:hash" GET_SMTCOCE_EVT_TXS = "/api/v1/smartcode/event/transactions/:height" @@ -157,6 +158,7 @@ func (this *restServer) registryMethod() { GET_SHARD_STORAGE: {name: "getshardstorage", handler: rest.GetShardStorage}, GET_SHARD_TX_STATE_NID: {name: "getshardtxstate", handler: rest.GetShardTxState}, GET_SHARD_TX_STATE: {name: "getshardtxstate", handler: rest.GetShardTxState}, + GET_SHARD_CHAIN_CONFIG: {name: "getshardchainconfig", handler: rest.GetShardChainConfig}, GET_BALANCE: {name: "getbalance", handler: rest.GetBalance}, GET_ALLOWANCE: {name: "getallowance", handler: rest.GetAllowance}, GET_MERKLE_PROOF: {name: "getmerkleproof", handler: rest.GetMerkleProof}, From 13a7ff7f2cbf95989978516e84099c446c4efeda Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Fri, 19 Jul 2019 14:18:36 +0800 Subject: [PATCH 2/7] fix params --- http/base/rpc/interfaces.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index 4fb5c7ecd1..674ccc1518 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -783,7 +783,7 @@ func GetShardChainConfig(params []interface{}) map[string]interface{} { } switch params[1].(type) { case float64: - height = uint32(params[0].(float64)) + height = uint32(params[1].(float64)) } chainConfig, err := bactor.GetShardChainConfig(shardID, height) if err != nil { From 41b592eca1fd207e876a62132897b869736886d4 Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Fri, 19 Jul 2019 21:54:27 +0800 Subject: [PATCH 3/7] add getshardchainconfig interface description --- cmd/utils/ont.go | 7 ++++--- consensus/vbft/config/config.go | 8 -------- docs/specifications/restful_api_CN.md | 9 +++++++++ docs/specifications/rpc_api.md | 17 +++++++++++++++-- docs/specifications/rpc_api_CN.md | 18 ++++++++++++++++++ docs/specifications/websocket_api.md | 1 + docs/specifications/websocket_api_CN.md | 1 + http/base/rest/interfaces.go | 19 +++++++++++++------ http/base/rpc/interfaces.go | 6 +----- http/jsonrpc/rpc_server.go | 1 + http/restful/restful/server.go | 4 ++++ http/websocket/websocket/server.go | 1 + 12 files changed, 68 insertions(+), 24 deletions(-) diff --git a/cmd/utils/ont.go b/cmd/utils/ont.go index 7c3e7edf62..000ce53e09 100644 --- a/cmd/utils/ont.go +++ b/cmd/utils/ont.go @@ -24,13 +24,14 @@ import ( "encoding/hex" "encoding/json" "fmt" - vconfig "github.com/ontio/ontology/consensus/vbft/config" "math/rand" "sort" "strconv" "strings" "time" + vconfig "github.com/ontio/ontology/consensus/vbft/config" + "github.com/ontio/ontology-crypto/keypair" sig "github.com/ontio/ontology-crypto/signature" "github.com/ontio/ontology/account" @@ -623,7 +624,7 @@ func GetTxHeight(txHash string) (uint32, error) { } func GetShardChainConfig(shardID uint64, height uint64) (*vconfig.ChainConfig, error) { - data, ontErr := sendRpcRequest("getshardChainConfig", []interface{}{shardID, height}) + data, ontErr := sendRpcRequest("getshardchainconfig", []interface{}{shardID, height}) if ontErr != nil { switch ontErr.ErrorCode { case ERROR_INVALID_PARAMS: @@ -632,7 +633,7 @@ func GetShardChainConfig(shardID uint64, height uint64) (*vconfig.ChainConfig, e return nil, ontErr.Error } cfg := &vconfig.ChainConfig{} - err := json.Unmarshal(data, &cfg) + err := json.Unmarshal(data, cfg) if err != nil { return nil, fmt.Errorf("json.Unmarshal error:%s", err) } diff --git a/consensus/vbft/config/config.go b/consensus/vbft/config/config.go index 53c78acc60..55d0d08d3e 100644 --- a/consensus/vbft/config/config.go +++ b/consensus/vbft/config/config.go @@ -101,14 +101,6 @@ func (cc *ChainConfig) Serialize(w io.Writer) error { return nil } -func (cc *ChainConfig) ToArray() ([]byte, error) { - data, err := json.Marshal(cc) - if err != nil { - return nil, err - } - return data, nil -} - func (pc *PeerConfig) Serialize(w io.Writer) error { if err := serialization.WriteUint32(w, pc.Index); err != nil { return fmt.Errorf("ChainConfig peer index length serialization failed %s", err) diff --git a/docs/specifications/restful_api_CN.md b/docs/specifications/restful_api_CN.md index 09ab06bb2e..2aba7a1983 100644 --- a/docs/specifications/restful_api_CN.md +++ b/docs/specifications/restful_api_CN.md @@ -49,6 +49,7 @@ | [get_grantong](#23-get_grantong) | GET /api/v1/grantong/:addr | 得到grant ong | | [get_shard_smtcode_evts](#24-get_shard_smtcode_evts) | GET /api/v1/shard/smartcode/event/txhash/:sourcetxhash | 通过source交易哈希得到该交易调用的shard交易的事件 | | [get_shard_tx_state](#25-get_shard_tx_state) | GET /api/v1/shardtxstate/:txhash/:notifyid | 通过txhash和notifyid查询txstate | +| [get_shard_chainconfig](#26-get_shard_chainconfig) | GET/api/v1/shardchainconfig/:shardid/:height| 得到 shardchainconfig | ### 1 get_conn_count @@ -1024,6 +1025,14 @@ curl -i http://127.0.0.1:30334/api/v1/shardtxstate/fb64410d900a237ee63502af33f68 } ``` +### 26 get_shard_chainconfig + +获取 shardchainconfig. + +GET +``` +/api/v1/shardchainconfig/:shardid/:height +``` ## 错误代码 | Field | Type | Description | diff --git a/docs/specifications/rpc_api.md b/docs/specifications/rpc_api.md index 4b8da32c37..87ba56aa4c 100644 --- a/docs/specifications/rpc_api.md +++ b/docs/specifications/rpc_api.md @@ -99,7 +99,7 @@ There are some description of parameter used in rpc: | [getgrantong](#22-getgrantong) | | Get grant ong | | | [getshardsmartcodeevent](#23-getshardsmartcodeevent) | | Get shard smart contract event | | | [getshardtxstate](#24-getshardtxstate) | | Get tx state | | - +| [getshardchainconfig](#25-getshardchainconfig) | shardid,height | get chainconfig by shardid and height| | ### 1. getbestblockhash Get the hash of the highest height block in the main chain. @@ -1259,8 +1259,21 @@ Response: } } } -``` +#### 25. getshardchainconfig + +get shard chainconfig by shardid and height. + +#### Example + +``` +{ + "jsonrpc": "2.0", + "method": "getshardchainconfig", + "params": [1,12], + "id": 0 +} +``` ## Error Code diff --git a/docs/specifications/rpc_api_CN.md b/docs/specifications/rpc_api_CN.md index 9598bbc93e..61ec5a312a 100644 --- a/docs/specifications/rpc_api_CN.md +++ b/docs/specifications/rpc_api_CN.md @@ -99,6 +99,7 @@ | [getgrantong](#22-getgrantong) | | 获取 grant ong | | | [getshardsmartcodeevent](#23-getshardsmartcodeevent) | | 获取 shard smart contract event | | | [getshardtxstate](#24-getshardtxstate) | | 获取tx state | | +| [getshardchainconfig](#25-getshardchainconfig) | shardid,height | 获取指定shard chainconfig | | ### 1. getbestblockhash @@ -1273,6 +1274,23 @@ Response: } ``` +#### 25. getshardchainconfig + +获取指定shard chainconfig. + +#### Example + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "getshardchainconfig", + "params": [1,12], + "id": 0 +} +``` + ## 错误代码 错误码定义 diff --git a/docs/specifications/websocket_api.md b/docs/specifications/websocket_api.md index e6efcd1ddb..941c5fe9a9 100644 --- a/docs/specifications/websocket_api.md +++ b/docs/specifications/websocket_api.md @@ -51,6 +51,7 @@ This document describes the Websocket api format for the ws/wss used in the Onch | [getversion](#24-getversion) | | get the version information of the node | | [getnetworkid](#25-getnetworkid) | | get the network id | | [getgrantong](#26-getgrantong) | | get grant ong | +| [getshardchainconfig](#27-getshardchainconfig) |shardid,height | get shard chainconfig | ### 1. heartbeat If don't send heartbeat, the session expire after 5min. diff --git a/docs/specifications/websocket_api_CN.md b/docs/specifications/websocket_api_CN.md index 575cadc41a..debb3c5483 100644 --- a/docs/specifications/websocket_api_CN.md +++ b/docs/specifications/websocket_api_CN.md @@ -51,6 +51,7 @@ | [getversion](#24-getversion) | | 得到版本信息 | | [getnetworkid](#25-getnetworkid) | | 得到network id | | [getgrantong](#26-getgrantong) | | 得到grant ong | +| [getshardchainconfig](#27-getshardchainconfig) |shardid,height | 获取指定 shard chainconfig | ### 1. heartbeat diff --git a/http/base/rest/interfaces.go b/http/base/rest/interfaces.go index 40a7470d66..7174153684 100644 --- a/http/base/rest/interfaces.go +++ b/http/base/rest/interfaces.go @@ -567,24 +567,31 @@ func GetShardTxState(cmd map[string]interface{}) map[string]interface{} { func GetShardChainConfig(cmd map[string]interface{}) map[string]interface{} { resp := ResponsePack(berr.SUCCESS) - id, ok := cmd["shardID"].(uint32) + idStr, ok := cmd["ShardID"].(string) if !ok { return ResponsePack(berr.INVALID_PARAMS) } - height, ok := cmd["height"].(uint32) + id, err := strconv.ParseUint(idStr, 10, 32) + if err != nil { + return ResponsePack(berr.INVALID_PARAMS) + } + heightStr, ok := cmd["Height"].(string) if !ok { return ResponsePack(berr.INVALID_PARAMS) } - shardID, err := common.NewShardID(uint64(id)) + height, err := strconv.ParseInt(heightStr, 10, 64) + if err != nil { + return ResponsePack(berr.INVALID_PARAMS) + } + shardID, err := common.NewShardID(id) if err != nil { return ResponsePack(berr.INTERNAL_ERROR) } - chainConfig, err := bactor.GetShardChainConfig(shardID, height) + chainConfig, err := bactor.GetShardChainConfig(shardID, uint32(height)) if err != nil { return ResponsePack(berr.INTERNAL_ERROR) } - value, err := chainConfig.ToArray() - resp["Result"] = common.ToHexString(value) + resp["Result"] = chainConfig return resp } diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index 674ccc1518..71acf0e9d2 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -789,9 +789,5 @@ func GetShardChainConfig(params []interface{}) map[string]interface{} { if err != nil { return responsePack(berr.UNKNOWN_CHAINCONFIG, "") } - data, err := chainConfig.ToArray() - if err != nil { - return responsePack(berr.UNKNOWN_CHAINCONFIG, "") - } - return responseSuccess(common.ToHexString(data)) + return responseSuccess(chainConfig) } diff --git a/http/jsonrpc/rpc_server.go b/http/jsonrpc/rpc_server.go index 3742e871a6..acb7102104 100644 --- a/http/jsonrpc/rpc_server.go +++ b/http/jsonrpc/rpc_server.go @@ -65,6 +65,7 @@ func StartRPCServer() error { rpc.HandleFunc("getshardstorage", rpc.GetShardStorage) rpc.HandleFunc("getshardtxstate", rpc.GetShardTxState) + rpc.HandleFunc("getshardchainconfig", rpc.GetShardChainConfig) err := http.ListenAndServe(":"+strconv.Itoa(int(cfg.DefConfig.Rpc.HttpJsonPort)), nil) if err != nil { return fmt.Errorf("ListenAndServe error:%s", err) diff --git a/http/restful/restful/server.go b/http/restful/restful/server.go index c2e5b42863..bcae101154 100644 --- a/http/restful/restful/server.go +++ b/http/restful/restful/server.go @@ -207,6 +207,8 @@ func (this *restServer) getPath(url string) string { return GET_SHARD_TX_STATE_NID } else if strings.Contains(url, strings.TrimRight(GET_SHARD_TX_STATE, ":txhash")) { return GET_SHARD_TX_STATE + } else if strings.Contains(url, strings.TrimRight(GET_SHARD_CHAIN_CONFIG, ":shardid/:height")) { + return GET_SHARD_CHAIN_CONFIG } else if strings.Contains(url, strings.TrimRight(GET_STORAGE, ":hash/:key")) { return GET_STORAGE } else if strings.Contains(url, strings.TrimRight(GET_BALANCE, ":addr")) { @@ -252,6 +254,8 @@ func (this *restServer) getParams(r *http.Request, url string, req map[string]in req["TxHash"], req["NotifyId"] = getParam(r, "txhash"), getParam(r, "notifyid") case GET_SHARD_TX_STATE: req["TxHash"] = getParam(r, "txhash") + case GET_SHARD_CHAIN_CONFIG: + req["ShardID"], req["Height"] = getParam(r, "shardid"), getParam(r, "height") case GET_SMTCOCE_EVT_TXS: req["Height"] = getParam(r, "height") case GET_SMTCOCE_EVTS: diff --git a/http/websocket/websocket/server.go b/http/websocket/websocket/server.go index 429efe940f..11168b7551 100644 --- a/http/websocket/websocket/server.go +++ b/http/websocket/websocket/server.go @@ -197,6 +197,7 @@ func (self *WsServer) registryMethod() { "getstorage": {handler: rest.GetStorage}, "getshardstorage": {handler: rest.GetShardStorage}, "getshardtxstate": {handler: rest.GetShardTxState}, + "getshardchainconfig": {handler: rest.GetShardChainConfig}, "getallowance": {handler: rest.GetAllowance}, "getmerkleproof": {handler: rest.GetMerkleProof}, "getblocktxsbyheight": {handler: rest.GetBlockTxsByHeight}, From caca6895210f3bca3e0a49f792d3db820e78f278 Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Mon, 22 Jul 2019 10:58:26 +0800 Subject: [PATCH 4/7] modify some comment --- cmd/info_cmd.go | 14 ++++++++++---- cmd/utils/ont.go | 9 ++------- http/base/rpc/interfaces.go | 4 ++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cmd/info_cmd.go b/cmd/info_cmd.go index 9a9b1ffb22..e800deb6ba 100644 --- a/cmd/info_cmd.go +++ b/cmd/info_cmd.go @@ -98,7 +98,7 @@ var InfoCommand = cli.Command{ Name: "shardChainConfig", Usage: "Display chain config by shardID,block height", ArgsUsage: "", - Description: `Display shard chainconfig by shardID,block height`, + Description: `Display shard chain config by shardID,block height`, Flags: []cli.Flag{ utils.RPCPortFlag, }, @@ -276,9 +276,15 @@ func getShardChainConfig(ctx *cli.Context) error { cli.ShowSubcommandHelp(ctx) return nil } - shardID, _ := strconv.ParseUint(ctx.Args().First(), 10, 32) - height, _ := strconv.ParseUint(ctx.Args().Get(1), 10, 32) - chainConfig, err := utils.GetShardChainConfig(uint64(shardID), height) + shardID, err := strconv.ParseUint(ctx.Args().First(), 10, 64) + if err != nil { + return fmt.Errorf("ParseUint shardID error:%s", err) + } + height, err := strconv.ParseUint(ctx.Args().Get(1), 10, 32) + if err != nil { + return fmt.Errorf("ParseUint height error:%s", err) + } + chainConfig, err := utils.GetShardChainConfig(shardID, height) if err != nil { return fmt.Errorf("GetShardChainConfig err:%s", err) } diff --git a/cmd/utils/ont.go b/cmd/utils/ont.go index 000ce53e09..98e2682f25 100644 --- a/cmd/utils/ont.go +++ b/cmd/utils/ont.go @@ -30,14 +30,13 @@ import ( "strings" "time" - vconfig "github.com/ontio/ontology/consensus/vbft/config" - "github.com/ontio/ontology-crypto/keypair" sig "github.com/ontio/ontology-crypto/signature" "github.com/ontio/ontology/account" "github.com/ontio/ontology/common" "github.com/ontio/ontology/common/constants" "github.com/ontio/ontology/common/serialization" + vconfig "github.com/ontio/ontology/consensus/vbft/config" "github.com/ontio/ontology/core/payload" "github.com/ontio/ontology/core/signature" "github.com/ontio/ontology/core/types" @@ -626,11 +625,7 @@ func GetTxHeight(txHash string) (uint32, error) { func GetShardChainConfig(shardID uint64, height uint64) (*vconfig.ChainConfig, error) { data, ontErr := sendRpcRequest("getshardchainconfig", []interface{}{shardID, height}) if ontErr != nil { - switch ontErr.ErrorCode { - case ERROR_INVALID_PARAMS: - return nil, fmt.Errorf("cannot find shard chainconfig by sharID:%d,height:%d", shardID, height) - } - return nil, ontErr.Error + return nil, fmt.Errorf("getshardchainconfig shardID:%d,height:%d,err:%s", shardID, height, ontErr.Error) } cfg := &vconfig.ChainConfig{} err := json.Unmarshal(data, cfg) diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index 71acf0e9d2..0664379f86 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -780,10 +780,14 @@ func GetShardChainConfig(params []interface{}) map[string]interface{} { return responsePack(berr.INVALID_PARAMS, "") } shardID = shardId + default: + return responsePack(berr.INVALID_PARAMS, "") } switch params[1].(type) { case float64: height = uint32(params[1].(float64)) + default: + return responsePack(berr.INVALID_PARAMS, "") } chainConfig, err := bactor.GetShardChainConfig(shardID, height) if err != nil { From 6291df63188c29b83b60553378b2de757b36a36f Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Mon, 22 Jul 2019 11:44:36 +0800 Subject: [PATCH 5/7] modify height type --- cmd/info_cmd.go | 2 +- cmd/utils/ont.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/info_cmd.go b/cmd/info_cmd.go index e800deb6ba..999c0fce42 100644 --- a/cmd/info_cmd.go +++ b/cmd/info_cmd.go @@ -284,7 +284,7 @@ func getShardChainConfig(ctx *cli.Context) error { if err != nil { return fmt.Errorf("ParseUint height error:%s", err) } - chainConfig, err := utils.GetShardChainConfig(shardID, height) + chainConfig, err := utils.GetShardChainConfig(shardID, uint32(height)) if err != nil { return fmt.Errorf("GetShardChainConfig err:%s", err) } diff --git a/cmd/utils/ont.go b/cmd/utils/ont.go index 98e2682f25..dbde0f5789 100644 --- a/cmd/utils/ont.go +++ b/cmd/utils/ont.go @@ -622,7 +622,7 @@ func GetTxHeight(txHash string) (uint32, error) { return height, nil } -func GetShardChainConfig(shardID uint64, height uint64) (*vconfig.ChainConfig, error) { +func GetShardChainConfig(shardID uint64, height uint32) (*vconfig.ChainConfig, error) { data, ontErr := sendRpcRequest("getshardchainconfig", []interface{}{shardID, height}) if ontErr != nil { return nil, fmt.Errorf("getshardchainconfig shardID:%d,height:%d,err:%s", shardID, height, ontErr.Error) From 13fa11840fb75189fa46e5ef5e81ce57894c3ce7 Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Mon, 22 Jul 2019 12:06:45 +0800 Subject: [PATCH 6/7] fix comment --- http/base/rest/interfaces.go | 4 ++-- http/base/rpc/interfaces.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/http/base/rest/interfaces.go b/http/base/rest/interfaces.go index 7174153684..015ec1c917 100644 --- a/http/base/rest/interfaces.go +++ b/http/base/rest/interfaces.go @@ -571,7 +571,7 @@ func GetShardChainConfig(cmd map[string]interface{}) map[string]interface{} { if !ok { return ResponsePack(berr.INVALID_PARAMS) } - id, err := strconv.ParseUint(idStr, 10, 32) + id, err := strconv.ParseUint(idStr, 10, 64) if err != nil { return ResponsePack(berr.INVALID_PARAMS) } @@ -579,7 +579,7 @@ func GetShardChainConfig(cmd map[string]interface{}) map[string]interface{} { if !ok { return ResponsePack(berr.INVALID_PARAMS) } - height, err := strconv.ParseInt(heightStr, 10, 64) + height, err := strconv.ParseUint(heightStr, 10, 32) if err != nil { return ResponsePack(berr.INVALID_PARAMS) } diff --git a/http/base/rpc/interfaces.go b/http/base/rpc/interfaces.go index 0664379f86..591729d9d1 100644 --- a/http/base/rpc/interfaces.go +++ b/http/base/rpc/interfaces.go @@ -774,8 +774,8 @@ func GetShardChainConfig(params []interface{}) map[string]interface{} { var height uint32 switch params[0].(type) { case float64: - id := uint32(params[0].(float64)) - shardId, err := common.NewShardID(uint64(id)) + id := uint64(params[0].(float64)) + shardId, err := common.NewShardID(id) if err != nil { return responsePack(berr.INVALID_PARAMS, "") } From 03099a40ca58ef7a25014e416ca8d0a63f86e2d2 Mon Sep 17 00:00:00 2001 From: JunXi Xie Date: Tue, 30 Jul 2019 10:19:59 +0800 Subject: [PATCH 7/7] fix files conflicts --- docs/specifications/rpc_api.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/specifications/rpc_api.md b/docs/specifications/rpc_api.md index 87ba56aa4c..96053d188d 100644 --- a/docs/specifications/rpc_api.md +++ b/docs/specifications/rpc_api.md @@ -1259,6 +1259,7 @@ Response: } } } +``` #### 25. getshardchainconfig