Skip to content

Commit

Permalink
Merge pull request #76 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: Prepare for release v0.2.4-alpha.2
  • Loading branch information
alexgao001 authored Aug 17, 2023
2 parents 3232c5c + d35e3c0 commit f57c2de
Show file tree
Hide file tree
Showing 48 changed files with 2,320 additions and 528 deletions.
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Report a bug
about: Something with greenfield-relayer is not working as expected
title: ''
labels: 'type:bug'
assignees: ''
---

#### System information

Relayer version: (if getting from release page)
OS & Version: Windows/Linux/OSX
Commit hash : (if `develop`)

#### Expected behaviour


#### Actual behaviour


#### Steps to reproduce the behaviour


#### Backtrace

````
[backtrace]
````

When submitting logs: please submit them as text and not screenshots.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Request a feature
about: Report a missing feature - e.g. as a step before submitting a PR
title: ''
labels: 'type:feature'
assignees: ''
---

# Rationale

Why should this feature exist?
What are the use-cases?

# Implementation

Do you have ideas regarding the implementation of this feature?
Are you willing to implement this feature?
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Ask a question
about: Something is unclear
title: ''
labels: 'type:docs'
assignees: ''
---

This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation. For general questions please use [discord](https://discord.gg/bnbchain).
15 changes: 9 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ on:
- master
- develop
pull_request:
branches:
- master
- develop
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.20.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
GOPRIVATE: github.com/bnb-chain
steps:
- uses: actions/setup-go@v3
with:
go-version: [1.20.x]
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3

- run: go env -w GOPRIVATE="github.com/bnb-chain/*"
Expand Down Expand Up @@ -47,6 +50,6 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.50.0
version: latest
skip-pkg-cache: true
args: --timeout=99m
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Go version above 1.20
"bls_private_key": "your_private_key",
"chain_id": 18, // greenfield oracle module defines this
"start_height": 1,
"number_of_blocks_for_finality": 0,
"monitor_channel_list": [1,2,3,4,5,6],
"gas_limit": 1000,
"fee_amount": 5000000000000,
Expand All @@ -64,7 +63,7 @@ Go version above 1.20
],
"private_key": "your_private_key",
"gas_limit": 4700000,
"gas_price": 20000000000,
"gas_price": 10000000000,
"number_of_blocks_for_finality": 2,
"start_height": 0,
"chain_id": 714
Expand All @@ -74,8 +73,8 @@ Go version above 1.20
2. Config crosschain and greenfield light client smart contracts addresses, others can keep default value.
```
"relay_config": {
"bsc_to_greenfield_inturn_relayer_timeout": 90,
"greenfield_to_bsc_inturn_relayer_timeout": 45,
"bsc_to_greenfield_inturn_relayer_timeout": 40,
"greenfield_to_bsc_inturn_relayer_timeout": 30,
"greenfield_sequence_update_latency": 8,
"bsc_sequence_update_latency": 12,
"greenfield_event_type_cross_chain": "cosmos.crosschain.v1.EventCrossChain",
Expand Down Expand Up @@ -168,7 +167,7 @@ docker run --name gnfd-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -d mysql:8

Create schema in MySQL client:

```shell
```mysql
CREATE SCHEMA IF NOT EXISTS `greenfield-relayer` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
```

Expand Down
6 changes: 3 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ func NewApp(cfg *config.Config) *App {
model.InitGreenfieldTables(db)
model.InitVoteTables(db)

metricService := metric.NewMetricService(cfg)

greenfieldDao := dao.NewGreenfieldDao(db)
bscDao := dao.NewBSCDao(db)
voteDao := dao.NewVoteDao(db)
daoManager := dao.NewDaoManager(greenfieldDao, bscDao, voteDao)

greenfieldExecutor := executor.NewGreenfieldExecutor(cfg)
bscExecutor := executor.NewBSCExecutor(cfg)
bscExecutor := executor.NewBSCExecutor(cfg, metricService)

greenfieldExecutor.SetBSCExecutor(bscExecutor)
bscExecutor.SetGreenfieldExecutor(greenfieldExecutor)

metricService := metric.NewMetricService(cfg)

// vote signer
signer := vote.NewVoteSigner(greenfieldExecutor.BlsPrivateKey)

Expand Down
16 changes: 11 additions & 5 deletions assembler/bsc_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package assembler

import (
"bytes"
"cosmossdk.io/errors"
"encoding/hex"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"time"

"cosmossdk.io/errors"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"
oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types"
"time"

"github.com/bnb-chain/greenfield-relayer/common"
"github.com/bnb-chain/greenfield-relayer/config"
Expand Down Expand Up @@ -88,7 +90,7 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error {
}
return nil
}
inTurnRelayerStartSeq, err := a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry()
inTurnRelayerStartSeq, err := a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry(a.getChainId())
if err != nil {
return err
}
Expand All @@ -105,7 +107,7 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error {
a.inturnRelayerSequenceStatus.HasRetrieved = false
// non-inturn relayer retries every 10 second, gets the sequence from chain
time.Sleep(time.Duration(a.config.RelayConfig.GreenfieldSequenceUpdateLatency) * time.Second)
startSeq, err = a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry()
startSeq, err = a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry(a.getChainId())
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +173,7 @@ func (a *BSCAssembler) process(channelId types.ChannelId) error {
return nonceErr
}
a.relayerNonce = newNonce
newNextDeliveryOracleSeq, seqErr := a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry()
newNextDeliveryOracleSeq, seqErr := a.bscExecutor.GetNextDeliveryOracleSequenceWithRetry(a.getChainId())
if seqErr != nil {
return seqErr
}
Expand Down Expand Up @@ -238,3 +240,7 @@ func (a *BSCAssembler) updateMetrics(channelId uint8, nextDeliveryOracleSeq uint
a.metricService.SetNextSendSequenceForChannel(channelId, nextSendOracleSeq)
return nil
}

func (a *BSCAssembler) getChainId() sdk.ChainID {
return sdk.ChainID(a.config.BSCConfig.ChainId)
}
9 changes: 7 additions & 2 deletions assembler/greenfield_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"sync"
"time"

Expand Down Expand Up @@ -148,7 +149,7 @@ func (a *GreenfieldAssembler) process(channelId types.ChannelId, inturnRelayer *
return nil
}
} else {
endSeq, err := a.greenfieldExecutor.GetNextSendSequenceForChannelWithRetry(channelId)
endSeq, err := a.greenfieldExecutor.GetNextSendSequenceForChannelWithRetry(a.getDestChainId(), channelId)
if err != nil {
return err
}
Expand Down Expand Up @@ -233,10 +234,14 @@ func (a *GreenfieldAssembler) getMonitorChannels() []uint8 {

func (a *GreenfieldAssembler) updateMetrics(channelId types.ChannelId, nextDeliverySeq uint64) error {
a.metricService.SetNextReceiveSequenceForChannel(uint8(channelId), nextDeliverySeq)
nextSendSeq, err := a.greenfieldExecutor.GetNextSendSequenceForChannelWithRetry(channelId)
nextSendSeq, err := a.greenfieldExecutor.GetNextSendSequenceForChannelWithRetry(a.getDestChainId(), channelId)
if err != nil {
return err
}
a.metricService.SetNextSendSequenceForChannel(uint8(channelId), nextSendSeq)
return nil
}

func (a *GreenfieldAssembler) getDestChainId() sdk.ChainID {
return sdk.ChainID(a.config.BSCConfig.ChainId)
}
33 changes: 18 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,20 @@ func (cfg *AdminConfig) Validate() {
}

type GreenfieldConfig struct {
KeyType string `json:"key_type"`
AWSRegion string `json:"aws_region"`
AWSSecretName string `json:"aws_secret_name"`
AWSBlsSecretName string `json:"aws_bls_secret_name"`
RPCAddrs []string `json:"rpc_addrs"`
PrivateKey string `json:"private_key"`
BlsPrivateKey string `json:"bls_private_key"`
ChainId uint64 `json:"chain_id"`
StartHeight uint64 `json:"start_height"`
NumberOfBlocksForFinality uint64 `json:"number_of_blocks_for_finality"`
MonitorChannelList []uint8 `json:"monitor_channel_list"`
GasLimit int64 `json:"gas_limit"`
FeeAmount int64 `json:"fee_amount"`
ChainIdString string `json:"chain_id_string"`
UseWebsocket bool `json:"use_websocket"`
KeyType string `json:"key_type"`
AWSRegion string `json:"aws_region"`
AWSSecretName string `json:"aws_secret_name"`
AWSBlsSecretName string `json:"aws_bls_secret_name"`
RPCAddrs []string `json:"rpc_addrs"`
PrivateKey string `json:"private_key"`
BlsPrivateKey string `json:"bls_private_key"`
ChainId uint64 `json:"chain_id"`
StartHeight uint64 `json:"start_height"`
MonitorChannelList []uint8 `json:"monitor_channel_list"`
GasLimit int64 `json:"gas_limit"`
FeeAmount int64 `json:"fee_amount"`
ChainIdString string `json:"chain_id_string"`
UseWebsocket bool `json:"use_websocket"`
}

func (cfg *GreenfieldConfig) Validate() {
Expand Down Expand Up @@ -106,6 +105,9 @@ func (cfg *BSCConfig) Validate() {
if cfg.GasLimit == 0 {
panic("gas_limit of BNB Smart Chain should be larger than 0")
}
if cfg.NumberOfBlocksForFinality < 2 || cfg.NumberOfBlocksForFinality > 21 {
panic("NumberOfBlocksForFinality should be [2, 21]")
}
}

type RelayConfig struct {
Expand All @@ -118,6 +120,7 @@ type RelayConfig struct {
CrossChainPackageEventHex string `json:"cross_chain_package_event_hex"`
CrossChainContractAddr string `json:"cross_chain_contract_addr"`
GreenfieldLightClientContractAddr string `json:"greenfield_light_client_contract_addr"`
RelayerHubContractAddr string `json:"relayer_hub_contract_addr"`
}

func (cfg *RelayConfig) Validate() {
Expand Down
7 changes: 3 additions & 4 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"bls_private_key": "your_private_key",
"chain_id": 1,
"start_height": 1,
"number_of_blocks_for_finality": 0,
"monitor_channel_list": [1,2,3,4,5,6],
"gas_limit": 1000,
"fee_amount": 5000000000000,
Expand All @@ -27,14 +26,14 @@
],
"private_key": "your_private_key",
"gas_limit": 4700000,
"gas_price": 20000000000,
"gas_price": 10000000000,
"number_of_blocks_for_finality": 2,
"start_height": 0,
"chain_id": 714
},
"relay_config": {
"bsc_to_greenfield_inturn_relayer_timeout": 90,
"greenfield_to_bsc_inturn_relayer_timeout": 45,
"bsc_to_greenfield_inturn_relayer_timeout": 40,
"greenfield_to_bsc_inturn_relayer_timeout": 30,
"greenfield_sequence_update_latency": 8,
"bsc_sequence_update_latency": 12,
"greenfield_event_type_cross_chain": "cosmos.crosschain.v1.EventCrossChain",
Expand Down
7 changes: 3 additions & 4 deletions config/local/config_local_0.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"bls_private_key": "your_private_key",
"chain_id": 18,
"start_height": 1,
"number_of_blocks_for_finality": 0,
"monitor_channel_list": [1,2,3,4,5,6],
"gas_limit": 1000,
"fee_amount": 5000000000000,
Expand All @@ -26,14 +25,14 @@
],
"private_key": "your_private_key",
"gas_limit": 4700000,
"gas_price": 20000000000,
"gas_price": 10000000000,
"number_of_blocks_for_finality": 2,
"start_height": 0,
"chain_id": 714
},
"relay_config": {
"bsc_to_greenfield_inturn_relayer_timeout": 90,
"greenfield_to_bsc_inturn_relayer_timeout": 45,
"bsc_to_greenfield_inturn_relayer_timeout": 40,
"greenfield_to_bsc_inturn_relayer_timeout": 30,
"greenfield_sequence_update_latency": 8,
"bsc_sequence_update_latency": 12,
"greenfield_event_type_cross_chain": "cosmos.crosschain.v1.EventCrossChain",
Expand Down
7 changes: 3 additions & 4 deletions config/local/config_local_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"bls_private_key": "your_private_key",
"chain_id": 18,
"start_height": 1,
"number_of_blocks_for_finality": 0,
"monitor_channel_list": [1,2,3,4,5,6],
"gas_limit": 1000,
"fee_amount": 5000000000000,
Expand All @@ -26,14 +25,14 @@
],
"private_key": "your_private_key",
"gas_limit": 4700000,
"gas_price": 20000000000,
"gas_price": 10000000000,
"number_of_blocks_for_finality": 2,
"start_height": 0,
"chain_id": 714
},
"relay_config": {
"bsc_to_greenfield_inturn_relayer_timeout": 90,
"greenfield_to_bsc_inturn_relayer_timeout": 45,
"bsc_to_greenfield_inturn_relayer_timeout": 40,
"greenfield_to_bsc_inturn_relayer_timeout": 30,
"greenfield_sequence_update_latency": 8,
"bsc_sequence_update_latency": 12,
"greenfield_event_type_cross_chain": "cosmos.crosschain.v1.EventCrossChain",
Expand Down
Loading

0 comments on commit f57c2de

Please sign in to comment.