Skip to content

Commit

Permalink
Merge pull request #193 from KiraCore/release/v0.4.39
Browse files Browse the repository at this point in the history
release/v0.4.39 -> master
  • Loading branch information
asmodat authored Sep 12, 2023
2 parents 6658542 + 2935648 commit 6981553
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 52 deletions.
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Features:

* Fix staking-pool endpoint and valoper endpoint issues
* Fix identity record querying issues
* Implement custom denom and bech32 prefix
* Bump sekai version to v0.3.29
2 changes: 1 addition & 1 deletion common/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func WrapResponse(w http.ResponseWriter, request types.InterxRequest, response t
}
}

// ServeGRPC is a function to server GRPC
// ServeGRPC is a function to serve GRPC
func ServeGRPC(r *http.Request, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) {
recorder := httptest.NewRecorder()
gwCosmosmux.ServeHTTP(recorder, r)
Expand Down
4 changes: 2 additions & 2 deletions config/constants.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package config

const (
InterxVersion = "v0.4.38"
SekaiVersion = "v0.3.27"
InterxVersion = "v0.4.39"
SekaiVersion = "v0.3.29"
CosmosVersion = "v0.45.10"

QueryDashboard = "/api/dashboard"
Expand Down
187 changes: 143 additions & 44 deletions config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"

Expand All @@ -13,6 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
bytesize "github.com/inhies/go-bytesize"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/sr25519"
Expand Down Expand Up @@ -59,12 +62,54 @@ func LoadMnemonic(mnemonic string) string {
return TrimMnemonic(mnemonicFromFile(mnemonic))
}

// LoadConfig is a function to load interx configurations from a given file
func LoadConfig(configFilePath string) {
sekaiappparams.SetConfig()
// serveGRPC is a function to serve GRPC
func serveGRPC(r *http.Request, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) {
recorder := httptest.NewRecorder()
gwCosmosmux.ServeHTTP(recorder, r)
resp := recorder.Result()

Config = InterxConfig{}
result := new(interface{})
if json.NewDecoder(resp.Body).Decode(result) == nil {
if resp.StatusCode == http.StatusOK {
return result, nil, resp.StatusCode
}

return nil, result, resp.StatusCode
}

return nil, nil, resp.StatusCode
}

// LoadAddressAndDenom is a function to load addresses and migrate config using custom bech32 and denom prefixes
func LoadAddressAndDenom(configFilePath string, gwCosmosmux *runtime.ServeMux, rpcAddr string, gatewayAddr string) {
request, _ := http.NewRequest("GET", "http://"+gatewayAddr+"/kira/gov/custom_prefixes", nil)
response, failure, _ := serveGRPC(request, gwCosmosmux)

if response == nil {
panic(failure)
}

byteData, err := json.Marshal(response)
if err != nil {
panic(err)
}
result := map[string]string{}
err = json.Unmarshal(byteData, &result)
if err != nil {
panic(err)
}

bech32Prefix := result["bech32Prefix"]
defaultDenom := result["defaultDenom"]
sekaiappparams.DefaultDenom = defaultDenom
sekaiappparams.AccountAddressPrefix = bech32Prefix
sekaiappparams.AccountPubKeyPrefix = bech32Prefix + "pub"
sekaiappparams.ValidatorAddressPrefix = bech32Prefix + "valoper"
sekaiappparams.ValidatorPubKeyPrefix = bech32Prefix + "valoperpub"
sekaiappparams.ConsNodeAddressPrefix = bech32Prefix + "valcons"
sekaiappparams.ConsNodePubKeyPrefix = bech32Prefix + "valconspub"

sekaiappparams.SetConfig()
file, err := ioutil.ReadFile(configFilePath)
if err != nil {
fmt.Println("Invalid configuration: {}", err)
Expand All @@ -79,21 +124,8 @@ func LoadConfig(configFilePath string) {
panic(err)
}

// Interx Main Configuration
Config.InterxVersion = InterxVersion
Config.ServeHTTPS = configFromFile.ServeHTTPS
Config.GRPC = configFromFile.GRPC
Config.RPC = configFromFile.RPC
Config.PORT = configFromFile.PORT
//=============== interx address ===============
Config.Mnemonic = LoadMnemonic(configFromFile.MnemonicFile)

Config.Node = configFromFile.Node

fmt.Println("Interx Version: ", Config.InterxVersion)
fmt.Println("Interx GRPC: ", Config.GRPC)
fmt.Println("Interx RPC : ", Config.RPC)
fmt.Println("Interx PORT: ", Config.PORT)

if !bip39.IsMnemonicValid(Config.Mnemonic) {
fmt.Println("Invalid Interx Mnemonic: ", Config.Mnemonic)
panic("Invalid Interx Mnemonic")
Expand All @@ -113,40 +145,33 @@ func LoadConfig(configFilePath string) {
Config.PubKey = Config.PrivKey.PubKey()
Config.Address = sdk.MustBech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), Config.PubKey.Address())

Config.AddrBooks = strings.Split(configFromFile.AddrBooks, ",")
Config.NodeKey, err = p2p.LoadOrGenNodeKey(configFromFile.NodeKey)
if err != nil {
panic(err)
}

Config.TxModes = strings.Split(configFromFile.TxModes, ",")
if len(Config.TxModes) == 0 {
Config.TxModes = strings.Split("sync,async,block", ",")
}

// Display mnemonic and keys
// fmt.Println("Interx Mnemonic : ", Config.Mnemonic)
fmt.Println("Interx Address : ", Config.Address)
fmt.Println("Interx Public Key: ", Config.PubKey.String())

Config.NodeDiscovery = configFromFile.NodeDiscovery
//=============== faucet address ===============

Config.Block.StatusSync = configFromFile.Block.StatusSync
Config.Block.HaltedAvgBlockTimes = configFromFile.Block.HaltedAvgBlockTimes
amount, found := configFromFile.Faucet.FaucetAmounts["ukex"]
if found {
configFromFile.Faucet.FaucetAmounts[defaultDenom] = amount
delete(configFromFile.Faucet.FaucetAmounts, "ukex")
}

Config.Cache.CacheDir = configFromFile.Cache.CacheDir
Config.Cache.MaxCacheSize = parseSizeString(configFromFile.Cache.MaxCacheSize)
Config.Cache.CachingDuration = configFromFile.Cache.CachingDuration
Config.Cache.DownloadFileSizeLimitation = parseSizeString(configFromFile.Cache.DownloadFileSizeLimitation)
amount, found = configFromFile.Faucet.FaucetMinimumAmounts["ukex"]
if found {
configFromFile.Faucet.FaucetMinimumAmounts[defaultDenom] = amount
delete(configFromFile.Faucet.FaucetMinimumAmounts, "ukex")
}

// Display cache configurations
fmt.Println("Interx Block StatusSync : ", Config.Block.StatusSync)
fmt.Println("Halted Avg Block Times : ", Config.Block.HaltedAvgBlockTimes)
amount, found = configFromFile.Faucet.FeeAmounts["ukex"]
if found {
configFromFile.Faucet.FeeAmounts[defaultDenom] = amount
delete(configFromFile.Faucet.FeeAmounts, "ukex")
}

fmt.Println("Interx Cache CacheDir : ", Config.Cache.CacheDir)
fmt.Println("Interx Cache MaxCacheSize : ", Config.Cache.MaxCacheSize)
fmt.Println("Interx Cache CachingDuration : ", Config.Cache.CachingDuration)
fmt.Println("Interx Cache DownloadFileSizeLimitation: ", Config.Cache.DownloadFileSizeLimitation)
for denom, coinStr := range configFromFile.Faucet.FeeAmounts {
configFromFile.Faucet.FeeAmounts[denom] = strings.ReplaceAll(coinStr, "ukex", defaultDenom)
}

// Faucet Configuration
Config.Faucet = FaucetConfig{
Expand Down Expand Up @@ -186,6 +211,80 @@ func LoadConfig(configFilePath string) {
fmt.Println("Interx Faucet FeeAmounts : ", Config.Faucet.FeeAmounts)
fmt.Println("Interx Faucet TimeLimit : ", Config.Faucet.TimeLimit)

// save denom changes to config
bytes, err := json.MarshalIndent(&configFromFile, "", " ")
if err != nil {
panic(err)
}

err = ioutil.WriteFile(configFilePath, bytes, 0644)
if err != nil {
panic(err)
}
}

// LoadConfig is a function to load interx configurations from a given file
func LoadConfig(configFilePath string) {
Config = InterxConfig{}

file, err := ioutil.ReadFile(configFilePath)
if err != nil {
fmt.Println("Invalid configuration: {}", err)
panic(err)
}

configFromFile := InterxConfigFromFile{}

err = json.Unmarshal([]byte(file), &configFromFile)
if err != nil {
fmt.Println("Invalid configuration: {}", err)
panic(err)
}

// Interx Main Configuration
Config.InterxVersion = InterxVersion
Config.ServeHTTPS = configFromFile.ServeHTTPS
Config.GRPC = configFromFile.GRPC
Config.RPC = configFromFile.RPC
Config.PORT = configFromFile.PORT

Config.Node = configFromFile.Node

fmt.Println("Interx Version: ", Config.InterxVersion)
fmt.Println("Interx GRPC: ", Config.GRPC)
fmt.Println("Interx RPC : ", Config.RPC)
fmt.Println("Interx PORT: ", Config.PORT)

Config.AddrBooks = strings.Split(configFromFile.AddrBooks, ",")
Config.NodeKey, err = p2p.LoadOrGenNodeKey(configFromFile.NodeKey)
if err != nil {
panic(err)
}

Config.TxModes = strings.Split(configFromFile.TxModes, ",")
if len(Config.TxModes) == 0 {
Config.TxModes = strings.Split("sync,async,block", ",")
}

Config.NodeDiscovery = configFromFile.NodeDiscovery

Config.Block.StatusSync = configFromFile.Block.StatusSync
Config.Block.HaltedAvgBlockTimes = configFromFile.Block.HaltedAvgBlockTimes

Config.Cache.CacheDir = configFromFile.Cache.CacheDir
Config.Cache.MaxCacheSize = parseSizeString(configFromFile.Cache.MaxCacheSize)
Config.Cache.CachingDuration = configFromFile.Cache.CachingDuration
Config.Cache.DownloadFileSizeLimitation = parseSizeString(configFromFile.Cache.DownloadFileSizeLimitation)

// Display cache configurations
fmt.Println("Interx Block StatusSync : ", Config.Block.StatusSync)
fmt.Println("Halted Avg Block Times : ", Config.Block.HaltedAvgBlockTimes)

fmt.Println("Interx Cache CacheDir : ", Config.Cache.CacheDir)
fmt.Println("Interx Cache MaxCacheSize : ", Config.Cache.MaxCacheSize)
fmt.Println("Interx Cache CachingDuration : ", Config.Cache.CachingDuration)
fmt.Println("Interx Cache DownloadFileSizeLimitation: ", Config.Cache.DownloadFileSizeLimitation)

// RPC Configuration
Config.RPCMethods = getRPCSettings()

Expand Down
1 change: 1 addition & 0 deletions gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func Run(configFilePath string, log grpclog.LoggerV2) error {
Handler: c.Handler(router),
}

config.LoadAddressAndDenom(configFilePath, gwCosmosmux, rpcAddr, gatewayAddr)
tasks.RunTasks(gwCosmosmux, rpcAddr, gatewayAddr)

if serveHTTPS {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/KeisukeYamashita/go-jsonrpc v1.0.1
github.com/KiraCore/sekai v0.3.27
github.com/KiraCore/sekai v0.3.29
github.com/btcsuite/btcd v0.22.1
github.com/cosmos/cosmos-sdk v0.45.10
github.com/cosmos/go-bip39 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ github.com/HdrHistogram/hdrhistogram-go v1.1.0/go.mod h1:yDgFjdqOqDEKOvasDdhWNXY
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/KeisukeYamashita/go-jsonrpc v1.0.1 h1:mkg8th2I7C1y3tnAsxroQbmQcXEZ22AkQ5pazRd/KDM=
github.com/KeisukeYamashita/go-jsonrpc v1.0.1/go.mod h1:NyiYd1oDwaSsIflCju5dKRvLdG5rZ/I4E07ygRYYmgc=
github.com/KiraCore/sekai v0.3.27 h1:5rdlMrl4ZFNab8F+U5rJADYy5R598ustnx85AHthlpw=
github.com/KiraCore/sekai v0.3.27/go.mod h1:qQG8mK2ybhKqa6DW+btiUni4qN8OQTa5eoL49HZcNHg=
github.com/KiraCore/sekai v0.3.29 h1:m08pcagGw7vFHOP7VfF+elBu632Z8/jItp1IznOQpaw=
github.com/KiraCore/sekai v0.3.29/go.mod h1:qQG8mK2ybhKqa6DW+btiUni4qN8OQTa5eoL49HZcNHg=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
Expand Down

0 comments on commit 6981553

Please sign in to comment.