Skip to content

Commit

Permalink
Merge pull request #69 from KiraCore/v0.4.6
Browse files Browse the repository at this point in the history
v0.4.6 -> master
  • Loading branch information
fantasyup authored Apr 26, 2022
2 parents 8ba9efe + 85df899 commit 530f712
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 115 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,18 @@ POST http://0.0.0.0:11000/api/cosmos/txs
| contact | `string` | Email address or URL to a submission form |
| validator-node-id | `string` | node id of your validator node (required if you want your node to be present in the network visualizer) |
| sentry-node-id | `string` | comma separated list of sentry node ids (required if you want your nodes to be present in the network visualizer) |

## Caching Configurations of RPC methods

### `/api/rpc_methods` contains caching information for all endpoints
- caching_blocks: integer defining number of blocks that the response data will be preserved
- caching_time: integer defining time in seconds that the response data will be preserved for
- caching_enabled: boolean if caching is enabled or not
Here `0` represents no caching, `-1` represents infinit caching, `positive integer` represetns the caching time or number of blocks
Remember this settings when you set/update manually from `config.json`.

### Additionally `config.json` file contains `cache-size-limit` config param which represents the cache size limit in bytes. If cache reaches the limit, it will randomly delete folders/files.

### How to update caching configurations
All caching configurations are set in `config.json` file.
`config.json` file includes `rpc_methods` field and there you can set/update caching config of each endpoint.
2 changes: 1 addition & 1 deletion config/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config

const (
InterxVersion = "v0.4.5-rc.4"
InterxVersion = "v0.4.6"
SekaiVersion = "v0.1.26-rc.11"
CosmosVersion = "v0.45.1"

Expand Down
3 changes: 0 additions & 3 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func getRPCSettings() RPCConfig {
func defaultConfig() InterxConfigFromFile {
configFromFile := InterxConfigFromFile{}

configFromFile.Version = InterxVersion
configFromFile.ServeHTTPS = false
configFromFile.GRPC = "dns:///0.0.0.0:9090"
configFromFile.RPC = "http://0.0.0.0:26657"
Expand Down Expand Up @@ -160,7 +159,6 @@ func defaultConfig() InterxConfigFromFile {

// InitConfig is a function to load interx configurations from a given file
func InitConfig(
version string,
configFilePath string,
serveHTTPS bool,
grpc string,
Expand Down Expand Up @@ -193,7 +191,6 @@ func InitConfig(
) {
configFromFile := defaultConfig()

configFromFile.Version = version
configFromFile.ServeHTTPS = serveHTTPS
configFromFile.GRPC = grpc
configFromFile.RPC = rpc
Expand Down
4 changes: 2 additions & 2 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func LoadConfig(configFilePath string) {
}

// Interx Main Configuration
Config.Version = configFromFile.Version
Config.InterxVersion = InterxVersion
Config.ServeHTTPS = configFromFile.ServeHTTPS
Config.GRPC = configFromFile.GRPC
Config.RPC = configFromFile.RPC
Expand All @@ -88,7 +88,7 @@ func LoadConfig(configFilePath string) {

Config.Node = configFromFile.Node

fmt.Println("Interx Version: ", Config.Version)
fmt.Println("Interx Version: ", Config.InterxVersion)
fmt.Println("Interx GRPC: ", Config.GRPC)
fmt.Println("Interx RPC : ", Config.RPC)
fmt.Println("Interx PORT: ", Config.PORT)
Expand Down
4 changes: 2 additions & 2 deletions config/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ type NodeDiscoveryConfig struct {

// InterxConfig is a struct to be used for interx configuration
type InterxConfig struct {
Version string `json:"version"`
InterxVersion string `json:"interx_version"`
SekaiVersion string `json:"sekai_version"`
ServeHTTPS bool `json:"serve_https"`
GRPC string `json:"grpc"`
RPC string `json:"rpc"`
Expand All @@ -77,7 +78,6 @@ type InterxConfig struct {

// InterxConfigFromFile is a struct to be used for interx configuration file
type InterxConfigFromFile struct {
Version string `json:"version"`
ServeHTTPS bool `json:"serve_https"`
GRPC string `json:"grpc"`
RPC string `json:"rpc"`
Expand Down
74 changes: 37 additions & 37 deletions gateway/interx/nodelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ func queryPubP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfac

dest := make([]types.P2PNode, 0)
for _, node := range response.NodeList {
if r.FormValue("synced") == "true" {
if true == node.Synced {
dest = append(dest, node)
}
} else if r.FormValue("synced") == "false" {
if false == node.Synced {
dest = append(dest, node)
if (r.FormValue("synced") == "true" && node.Synced) ||
(r.FormValue("synced") == "false" && !node.Synced) ||
(r.FormValue("synced") != "true" && r.FormValue("synced") != "false") {

behind, _ := strconv.Atoi(r.FormValue("behind"))
if behind == 0 || (node.BlockDiff <= int64(behind) && node.BlockDiff >= -int64(behind)) {
if r.FormValue("unsafe") == "true" || node.Safe {
dest = append(dest, node)
}
}
} else {
dest = append(dest, node)
}
}
response.NodeList = dest
Expand All @@ -87,11 +87,11 @@ func queryPubP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfac
ips := []string{}
for _, node := range response.NodeList {
if r.FormValue("connected") == "true" {
if true == node.Connected {
if node.Connected {
ips = append(ips, node.IP)
}
} else if r.FormValue("connected") == "false" {
if false == node.Connected {
if !node.Connected {
ips = append(ips, node.IP)
}
} else {
Expand All @@ -107,11 +107,11 @@ func queryPubP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfac
for _, node := range response.NodeList {
peer := node.ID + "@" + node.IP + ":" + strconv.Itoa(int(node.Port))
if r.FormValue("connected") == "true" {
if true == node.Connected {
if node.Connected {
peers = append(peers, peer)
}
} else if r.FormValue("connected") == "false" {
if false == node.Connected {
if !node.Connected {
peers = append(peers, peer)
}
} else {
Expand Down Expand Up @@ -193,16 +193,16 @@ func queryPrivP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfa

dest := make([]types.P2PNode, 0)
for _, node := range response.NodeList {
if r.FormValue("synced") == "true" {
if true == node.Synced {
dest = append(dest, node)
}
} else if r.FormValue("synced") == "false" {
if false == node.Synced {
dest = append(dest, node)
if (r.FormValue("synced") == "true" && node.Synced) ||
(r.FormValue("synced") == "false" && !node.Synced) ||
(r.FormValue("synced") != "true" && r.FormValue("synced") != "false") {

behind, _ := strconv.Atoi(r.FormValue("behind"))
if behind == 0 || (node.BlockDiff <= int64(behind) && node.BlockDiff >= -int64(behind)) {
if r.FormValue("unsafe") == "true" || node.Safe {
dest = append(dest, node)
}
}
} else {
dest = append(dest, node)
}
}
response.NodeList = dest
Expand All @@ -213,11 +213,11 @@ func queryPrivP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfa
ips := []string{}
for _, node := range response.NodeList {
if r.FormValue("connected") == "true" {
if true == node.Connected {
if node.Connected {
ips = append(ips, node.IP)
}
} else if r.FormValue("connected") == "false" {
if false == node.Connected {
if !node.Connected {
ips = append(ips, node.IP)
}
} else {
Expand All @@ -233,11 +233,11 @@ func queryPrivP2PNodeList(r *http.Request, rpcAddr string) (interface{}, interfa
for _, node := range response.NodeList {
peer := node.ID + "@" + node.IP + ":" + strconv.Itoa(int(node.Port))
if r.FormValue("connected") == "true" {
if true == node.Connected {
if node.Connected {
peers = append(peers, peer)
}
} else if r.FormValue("connected") == "false" {
if false == node.Connected {
if !node.Connected {
peers = append(peers, peer)
}
} else {
Expand Down Expand Up @@ -302,16 +302,16 @@ func queryInterxList(r *http.Request, rpcAddr string) (interface{}, interface{},

dest := make([]types.InterxNode, 0)
for _, node := range response.NodeList {
if r.FormValue("synced") == "true" {
if true == node.Synced {
dest = append(dest, node)
}
} else if r.FormValue("synced") == "false" {
if false == node.Synced {
dest = append(dest, node)
if (r.FormValue("synced") == "true" && node.Synced) ||
(r.FormValue("synced") == "false" && !node.Synced) ||
(r.FormValue("synced") != "true" && r.FormValue("synced") != "false") {

behind, _ := strconv.Atoi(r.FormValue("behind"))
if behind == 0 || (node.BlockDiff <= int64(behind) && node.BlockDiff >= -int64(behind)) {
if r.FormValue("unsafe") == "true" || node.Safe {
dest = append(dest, node)
}
}
} else {
dest = append(dest, node)
}
}
response.NodeList = dest
Expand Down Expand Up @@ -381,11 +381,11 @@ func querySnapList(r *http.Request, rpcAddr string) (interface{}, interface{}, i
dest := make([]types.SnapNode, 0)
for _, node := range response.NodeList {
if r.FormValue("synced") == "true" {
if true == node.Synced {
if node.Synced {
dest = append(dest, node)
}
} else if r.FormValue("synced") == "false" {
if false == node.Synced {
if !node.Synced {
dest = append(dest, node)
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion gateway/interx/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func queryStatusHandle(rpcAddr string) (interface{}, interface{}, int) {
result.InterxInfo.GenesisChecksum = checksum
result.InterxInfo.ChainID = genesis.ChainID

result.InterxInfo.Version = config.Config.Version
result.InterxInfo.InterxVersion = config.Config.InterxVersion
result.InterxInfo.SekaiVersion = config.Config.SekaiVersion

return result, nil, http.StatusOK
}
Expand Down
41 changes: 4 additions & 37 deletions gateway/rosetta/data/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,47 +102,14 @@ func QueryNetworkListRequest(gwCosmosmux *runtime.ServeMux, rpcAddr string) http
}

func queryNetworkOptionsHandler(r *http.Request, request types.InterxRequest, rpcAddr string, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) {
var req dataapi.NetworkOptionsRequest

err := json.Unmarshal(request.Params, &req)
if err != nil {
common.GetLogger().Error("[rosetta-query-networkoptions] Failed to decode the request: ", err)
return common.RosettaServeError(0, "failed to unmarshal", err.Error(), http.StatusBadRequest)
}

var response dataapi.NetworkOptionsResponse

success, failure, status := common.MakeTendermintRPCRequest(rpcAddr, "/status", "")

if success != nil {
type TempResponse struct {
NodeInfo struct {
Version string `json:"version"`
} `json:"node_info"`
}
result := TempResponse{}

byteData, err := json.Marshal(success)
if err != nil {
common.GetLogger().Error("[rosetta-query-networkoptions] Invalid response format", err)
return common.RosettaServeError(0, "", err.Error(), http.StatusInternalServerError)
}

err = json.Unmarshal(byteData, &result)
if err != nil {
common.GetLogger().Error("[rosetta-query-networkoptions] Invalid response format", err)
return common.RosettaServeError(0, "", err.Error(), http.StatusInternalServerError)
}

response.Version = rosetta.Version{
NodeVersion: result.NodeInfo.Version,
MiddlewareVersion: config.Config.Version,
}

return response, nil, http.StatusOK
response.Version = rosetta.Version{
NodeVersion: config.Config.SekaiVersion,
MiddlewareVersion: config.Config.InterxVersion,
}

return nil, failure, status
return response, nil, http.StatusOK
}

// QueryNetworkOptionsRequest is a function to query network options.
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/sonyarouje/simdb v0.0.0-20181202125413-c2488dfc374a
github.com/tendermint/tendermint v0.34.14
github.com/tyler-smith/go-bip39 v1.0.2
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71
google.golang.org/grpc v1.42.0
google.golang.org/protobuf v1.27.1
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func main() {

homeDir, _ := os.UserHomeDir()
initHomePtr := initCommand.String("home", homeDir+"/.interxd", "The interx configuration path.")
initVersion := initCommand.String("version", config.InterxVersion, "The interxd version")
initServeHTTPS := initCommand.Bool("serve_https", false, "http or https.")
initGrpcPtr := initCommand.String("grpc", "dns:///0.0.0.0:9090", "The grpc endpoint of the sekaid.")
initRPCPtr := initCommand.String("rpc", "http://0.0.0.0:26657", "The rpc endpoint of the sekaid.")
Expand Down Expand Up @@ -124,7 +123,6 @@ func main() {
}

config.InitConfig(
*initVersion,
*initHomePtr+"/config.json",
*initServeHTTPS,
*initGrpcPtr,
Expand Down
Loading

0 comments on commit 530f712

Please sign in to comment.