Skip to content

Commit

Permalink
Merge pull request #144 from icon-project/fix/concurrent-map
Browse files Browse the repository at this point in the history
fix: bugs and enhancements from stress testing
  • Loading branch information
debendraoli authored Mar 22, 2024
2 parents 578fefa + c6b5955 commit 6585ee9
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 147 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,35 @@ Encrypt the keystore file:
aws kms encrypt --key-id <insert-key-id-here> --plaintext fileb://$HOME/.centralized-relay/keystore/0x2.icon/0x0B958dd815195F73d6B9B91bFDF1639457678FEb.json --output text --query CiphertextBlob | base64 -d > "$HOME/keystore/0x2.icon/0x0B958dd815195F73d6B9B91bFDF1639457678FEb"
```

Move the encrypted wallet passphrase to the new location:

```shell
mv $HOME/keystore/0x2.icon/0x0B958dd815195F73d6B9B91bFDF1639457678FEb.password $HOME/.centralized relay/keystore/0x2.icon/0x0B958dd815195F73d6B9B91bFDF1639457678FEb.pass
```

### Additional Information

- All the keystore relayer files are located in the `keystore` directory.
`ls $HOME/.centralized-relay/keystore`

- The version `1.0.0` keystore files for chain are located in the inside the its `nid` directory in a following format:
`keystore/<nid>/<wallet-address>.json`

## [1.1.1] - 2024-03-21

### Added

- Websocket support for evm chain

### Fixed

- AWS Region detection
- Static binary build

## [1.1.2] - 2024-03-22

### Fixed

- Region detection for AWS
- Priority 0 (high) for `start-height` evm
- Panic too many packets map access
7 changes: 4 additions & 3 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

jsoniter "github.com/json-iterator/go"

"github.com/icon-project/centralized-relay/relayer"
"github.com/spf13/cobra"
"go.uber.org/zap"
Expand Down Expand Up @@ -67,7 +68,7 @@ $ %s ch l`, appName, appName)),
fmt.Fprintln(cmd.OutOrStdout(), string(out))
return nil
case jsn:
out, err := json.Marshal(configs)
out, err := jsoniter.Marshal(configs)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,7 +148,7 @@ func addChainFromFile(a *appState, chainName string, file string) error {
return err
}

if err = json.Unmarshal(byt, &pcw); err != nil {
if err = jsoniter.Unmarshal(byt, &pcw); err != nil {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"os"
"path"
"reflect"
"strings"

jsoniter "github.com/json-iterator/go"

"github.com/icon-project/centralized-relay/relayer/chains/wasm"

"github.com/icon-project/centralized-relay/relayer"
Expand Down Expand Up @@ -71,7 +72,7 @@ $ %s cfg list`, appName, a.homePath, appName)),
case yml && jsn:
return fmt.Errorf("can't pass both --json and --yaml, must pick one")
case jsn:
out, err := json.Marshal(a.config.Wrapped())
out, err := jsoniter.Marshal(a.config.Wrapped())
if err != nil {
return err
}
Expand Down Expand Up @@ -264,7 +265,7 @@ func UnmarshalJSONProviderConfig(data []byte, customTypes map[string]reflect.Typ
m := map[string]any{
"icon": reflect.TypeOf(icon.Config{}),
}
if err := json.Unmarshal(data, &m); err != nil {
if err := jsoniter.Unmarshal(data, &m); err != nil {
return nil, err
}

Expand All @@ -274,12 +275,12 @@ func UnmarshalJSONProviderConfig(data []byte, customTypes map[string]reflect.Typ
provCfg = reflect.New(ty).Interface().(provider.Config)
}

valueBytes, err := json.Marshal(m["value"])
valueBytes, err := jsoniter.Marshal(m["value"])
if err != nil {
return nil, err
}

return provCfg, json.Unmarshal(valueBytes, &provCfg)
return provCfg, jsoniter.Unmarshal(valueBytes, &provCfg)
}

// Note: chainId and chainName is basically the same
Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ Chain specific configurations.
| gas-adjustment | The gas adjustment value. | --- | 1.5 | float |
| min-gas-amount | The minimum gas amount limit for the transcation to process. | 20000 | 20000 | int |
| max-gas-amount | The maximum gas limit for the transcation. | 4000000 | 4000000 | int |
| block-interval | The block interval for the chain. | > 0s | 6s | duration |
| tx-confirmation-interval | The transaction confirmation interval for the chain. | > 0s | 6s | duration |
| block-interval | The block interval for the chain. | > 0 | 6s | duration |
| tx-confirmation-interval | The transaction confirmation interval for the chain. | > 0 | 6s | duration |
| broadcast-mode | The broadcast mode for the chain. | `sync`, `async`, `block` | `sync` | string |
| sign-mode | The sign mode for the chain. | `SIGN_MODE_DIRECT`, `SIGN_MODE_LEGACY_AMINO_JSON` | `SIGN_MODE_DIRECT` | string |
| simulate | Whether to use simulation before transcation. | `true`, `false` | `true` | bool |
Expand Down
10 changes: 5 additions & 5 deletions docs/keystore.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The `keystore` command is used to manage your Ethereum keystore.
## Usage

```bash
centralized-rly keystore <command> [options]
centralized-relay keystore <command> [options]

Commands:
create Create a keystore
Expand All @@ -21,7 +21,7 @@ Options:
### `create`

```bash
keytore create [flags]
keystore create [flags]

Flags:
-c, --chain string The chain for which to create the keystore
Expand Down Expand Up @@ -60,17 +60,17 @@ Flags:
### Create a keystore

```bash
centralized-rly keystore create --chain=0x2.icon --password=12345678
centralized-relay keystore create --chain=0x2.icon --password=12345678
```

### Import a keystore

```bash
centralized-rly keystore import --chain=0x2.icon --keystore=./keystore.json --password=12345678
centralized-relay keystore import --chain=0x2.icon --keystore=./keystore.json --password=12345678
```

### Use a keystore

```bash
centralized-rly keystore use --chain=0x2.icon --address=0x1234567890
centralized-relay keystore use --chain=0x2.icon --address=0x1234567890
```
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/echo/v4 v4.11.3 // indirect
github.com/labstack/gommon v0.4.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
github.com/prometheus/client_golang v1.17.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
5 changes: 3 additions & 2 deletions relayer/chain.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package relayer

import (
"encoding/json"
"fmt"

jsoniter "github.com/json-iterator/go"

"github.com/icon-project/centralized-relay/relayer/provider"
"go.uber.org/zap"
)
Expand All @@ -26,7 +27,7 @@ func NewChain(log *zap.Logger, prov provider.ChainProvider, debug bool) *Chain {
}

func (c *Chain) String() string {
out, _ := json.Marshal(c)
out, _ := jsoniter.Marshal(c)
return string(out)
}

Expand Down
9 changes: 4 additions & 5 deletions relayer/chains/evm/event_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package evm

import (
"encoding/hex"
"encoding/json"
"fmt"
"testing"

jsoniter "github.com/json-iterator/go"

ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/icon-project/centralized-relay/relayer/events"
providerTypes "github.com/icon-project/centralized-relay/relayer/types"
"github.com/stretchr/testify/assert"
)

func TestParseEventLog(t *testing.T) {

expected := providerTypes.Message{
Dst: "icon",
Src: "eth",
Expand All @@ -25,7 +25,7 @@ func TestParseEventLog(t *testing.T) {

data, _ := hex.DecodeString("7b2261646472657373223a22307830313635383738613539346361323535333338616466613464343834343966363932343265623866222c22746f70696373223a5b22307836646262623563383331383936373065303636643238316466633337643964656435313332616635643634303163666338333163373439396562373735663364225d2c2264617461223a22307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303630303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030613030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030613030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303034363936333666366530303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303536333638363536333662303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030222c22626c6f636b4e756d626572223a223078666464222c227472616e73616374696f6e48617368223a22307838633134616639663665333533346637643739383131323239353431383838653539346237373462373735656637303962633230623537353338373466616262222c227472616e73616374696f6e496e646578223a22307830222c22626c6f636b48617368223a22307831623635346561336663373063366538343532346261633238636139373838623761653461333563623934333363326334336537316633396264346134623337222c226c6f67496e646578223a22307830222c2272656d6f766564223a66616c73657d")
var log ethTypes.Log
err := json.Unmarshal(data, &log)
err := jsoniter.Unmarshal(data, &log)
assert.NoError(t, err)

pro, err := MockEvmProvider("")
Expand All @@ -35,7 +35,6 @@ func TestParseEventLog(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expected, msg)
fmt.Println(msg)

}

// func TestFilterLog(t *testing.T) {
Expand All @@ -54,7 +53,7 @@ func TestParseEventLog(t *testing.T) {

// for _, m := range log {
// fmt.Println("transaction log ", m)
// b, _ := json.Marshal(m)
// b, _ := jsoniter.Marshal(m)

// fmt.Printf("log data: %x", b)
// msg, err := pro.client.ParseMessage(m)
Expand Down
12 changes: 6 additions & 6 deletions relayer/chains/evm/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,16 @@ func (p *Provider) startFromHeight(ctx context.Context, lastSavedHeight uint64)
)
}

// priority1: lastsaveheight from db
if lastSavedHeight != 0 && lastSavedHeight < latestQueryHeight {
return lastSavedHeight, nil
}

// priority2: startHeight from config
// priority1: startHeight from config
if p.cfg.StartHeight != 0 && p.cfg.StartHeight < latestQueryHeight {
return p.cfg.StartHeight, nil
}

// priority2: lastsaveheight from db
if lastSavedHeight != 0 && lastSavedHeight < latestQueryHeight {
return lastSavedHeight, nil
}

// priority3: latest height
return latestQueryHeight, nil
}
Expand Down
7 changes: 4 additions & 3 deletions relayer/chains/icon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"log"
Expand All @@ -16,6 +15,8 @@ import (
"sync"
"time"

jsoniter "github.com/json-iterator/go"

"github.com/icon-project/centralized-relay/relayer/chains/icon/types"
providerTypes "github.com/icon-project/centralized-relay/relayer/types"
"go.uber.org/zap"
Expand Down Expand Up @@ -77,7 +78,7 @@ var txSerializeExcludes = map[string]bool{"signature": true}

func (c *Client) SignTransaction(w module.Wallet, p *types.TransactionParam) error {
p.Timestamp = types.NewHexInt(time.Now().UnixNano() / int64(time.Microsecond))
js, err := json.Marshal(p)
js, err := jsoniter.Marshal(p)
if err != nil {
return err
}
Expand Down Expand Up @@ -380,7 +381,7 @@ func (c *Client) wsRead(conn *websocket.Conn, respPtr interface{}) error {
if mt == websocket.CloseMessage {
return io.EOF
}
return json.NewDecoder(r).Decode(respPtr)
return jsoniter.NewDecoder(r).Decode(respPtr)
}

func (c *Client) wsReadJSONLoop(ctx context.Context, conn *websocket.Conn, respPtr interface{}, cb types.WsReadCallback) error {
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/icon/msg.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package icon

import (
"encoding/json"
jsoniter "github.com/json-iterator/go"

"github.com/icon-project/centralized-relay/relayer/chains/icon/types"
)
Expand All @@ -19,7 +19,7 @@ func (m *IconMessage) Type() string {
}

func (m *IconMessage) MsgBytes() ([]byte, error) {
return json.Marshal(m.Params)
return jsoniter.Marshal(m.Params)
}

func (p *Provider) NewIconMessage(address types.Address, msg interface{}, method string) *IconMessage {
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/icon/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Config struct {
StartHeight uint64 `json:"start-height" yaml:"start-height"` // would be of highest priority
BlockInterval string `json:"block-interval" yaml:"block-interval"`
Contracts relayerTypes.ContractConfigMap `json:"contracts" yaml:"contracts"`
NetworkID uint `json:"network-id" yaml:"network-id"`
NetworkID int64 `json:"network-id" yaml:"network-id"`
FinalityBlock uint64 `json:"finality-block" yaml:"finality-block"`
NID string `json:"nid" yaml:"nid"`
StepMin int64 `json:"step-min" yaml:"step-min"`
Expand Down
4 changes: 2 additions & 2 deletions relayer/chains/icon/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (p *Provider) SendTransaction(ctx context.Context, msg *IconMessage) ([]byt

txParam := types.TransactionParam{
Version: types.NewHexInt(JsonrpcApiVersion),
FromAddress: types.Address(wallet.Address().String()),
FromAddress: types.NewAddress(wallet.Address().Bytes()),
ToAddress: msg.Address,
NetworkID: types.NewHexInt(int64(p.cfg.NetworkID)),
NetworkID: types.NewHexInt(p.cfg.NetworkID),
DataType: "call",
Data: types.CallData{
Method: msg.Method,
Expand Down
5 changes: 3 additions & 2 deletions relayer/chains/wasm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package wasm

import (
"context"
"encoding/json"
"strconv"

jsoniter "github.com/json-iterator/go"

wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cometbft/cometbft/rpc/client/http"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
Expand Down Expand Up @@ -216,7 +217,7 @@ func (c *Client) GetFee(ctx context.Context, addr string, queryData []byte) (uin

var feeStr string

if err := json.Unmarshal(res.Data, &feeStr); err != nil {
if err := jsoniter.Unmarshal(res.Data, &feeStr); err != nil {
return 0, err
}
fee, err := strconv.ParseUint(feeStr, 10, strconv.IntSize)
Expand Down
Loading

0 comments on commit 6585ee9

Please sign in to comment.