Skip to content

Commit

Permalink
adjust getInturn relayer api
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Nov 3, 2023
1 parent 347c4b5 commit cf2884a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
7 changes: 6 additions & 1 deletion assembler/bsc_assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types"
"time"

"github.com/bnb-chain/greenfield-relayer/common"
Expand Down Expand Up @@ -59,7 +60,11 @@ func (a *BSCAssembler) assemblePackagesAndClaimForOracleChannel(channelId types.
}

func (a *BSCAssembler) process(channelId types.ChannelId) error {
inturnRelayer, err := a.greenfieldExecutor.GetInturnRelayer()
claimSrcChain := oracletypes.CLAIM_SRC_CHAIN_BSC
if a.config.BSCConfig.IsOpCrossChain() {
claimSrcChain = oracletypes.CLAIM_SRC_CHAIN_OP_BNB
}
inturnRelayer, err := a.greenfieldExecutor.GetInturnRelayer(claimSrcChain)
if err != nil {
return fmt.Errorf("failed to get inturn relayer, err=%s", err.Error())
}
Expand Down
6 changes: 4 additions & 2 deletions executor/greenfield_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,12 @@ func (e *GreenfieldExecutor) ClaimPackages(client *GreenfieldClient, payloadBts
return txRes.TxHash, nil
}

func (e *GreenfieldExecutor) GetInturnRelayer() (*oracletypes.QueryInturnRelayerResponse, error) {
func (e *GreenfieldExecutor) GetInturnRelayer(srcChain oracletypes.ClaimSrcChain) (*oracletypes.QueryInturnRelayerResponse, error) {
ctx, cancel := context.WithTimeout(context.Background(), RPCTimeout)
defer cancel()
return e.GetGnfdClient().GetInturnRelayer(ctx, &oracletypes.QueryInturnRelayerRequest{})
return e.GetGnfdClient().GetInturnRelayer(ctx, &oracletypes.QueryInturnRelayerRequest{
ClaimSrcChain: srcChain,
})
}

func (e *GreenfieldExecutor) QueryVotesByEventHashAndType(eventHash []byte, eventType votepool.EventType) ([]*votepool.Vote, error) {
Expand Down
28 changes: 17 additions & 11 deletions executor/greenfield_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
sdk "github.com/cosmos/cosmos-sdk/types"
oracletypes "github.com/cosmos/cosmos-sdk/x/oracle/types"
"testing"

cbfttypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -39,7 +40,11 @@ func TestGetNextSendSequenceForChannel(t *testing.T) {

func TestGetInturnRelayer(t *testing.T) {
e := GnfdExecutor()
relayer, err := e.GetInturnRelayer()
relayer, err := e.GetInturnRelayer(oracletypes.CLAIM_SRC_CHAIN_BSC)
require.NoError(t, err)
t.Log(relayer)

relayer, err = e.GetInturnRelayer(oracletypes.CLAIM_SRC_CHAIN_OP_BNB)
require.NoError(t, err)
t.Log(relayer)
}
Expand All @@ -59,29 +64,30 @@ func TestGetLatestValidators(t *testing.T) {

func TestGetConsensusStatus(t *testing.T) {
e := GnfdExecutor()
validators, err := e.GetGnfdClient().GetValidatorsByHeight(context.Background(), 1)
height := int64(1)
validators, err := e.GetGnfdClient().GetValidatorsByHeight(context.Background(), height)
assert.NoError(t, err)
b, _, err := e.GetBlockAndBlockResultAtHeight(1)
b, _, err := e.GetBlockAndBlockResultAtHeight(height)
assert.NoError(t, err)
t.Logf("NexValidator Hash: %s", hex.EncodeToString(b.NextValidatorsHash))
t.Logf("NexValidator Hash: %s", hexutil.Encode(b.NextValidatorsHash))
for i, validator := range validators {
t.Logf("validator %d", i)
t.Logf("validator pubkey %s", hexutil.Encode(validator.PubKey.Bytes()))
t.Logf("validator votingpower %d", validator.VotingPower)
t.Logf("relayeraddress %s", hex.EncodeToString(validator.RelayerAddress))
t.Logf("relayer bls pub key %s", hex.EncodeToString(validator.BlsKey))
t.Logf("relayeraddress %s", hexutil.Encode(validator.RelayerAddress))
t.Logf("relayer bls pub key %s", hexutil.Encode(validator.BlsKey))
}
cs, err := getCysString(e)
cs, err := getCysString(e, height)
assert.NoError(t, err)
t.Logf("consensus: %s", cs)
}

func getCysString(e *GreenfieldExecutor) (string, error) {
validators, err := e.GetGnfdClient().GetValidatorsByHeight(context.Background(), 1)
func getCysString(e *GreenfieldExecutor, height int64) (string, error) {
validators, err := e.GetGnfdClient().GetValidatorsByHeight(context.Background(), height)
if err != nil {
return "", err
}
block, err := e.GetGnfdClient().GetBlockByHeight(context.Background(), 1)
block, err := e.GetGnfdClient().GetBlockByHeight(context.Background(), height)
if err != nil {
return "", err
}
Expand All @@ -97,5 +103,5 @@ func getCysString(e *GreenfieldExecutor) (string, error) {
if err != nil {
return "", err
}
return hex.EncodeToString(csBytes), nil
return hexutil.Encode(csBytes), nil
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/avast/retry-go/v4 v4.3.1
github.com/aws/aws-sdk-go v1.40.45
github.com/bnb-chain/greenfield v1.0.0
github.com/bnb-chain/greenfield v1.0.2-0.20231102075513-12abbd906b00
github.com/bnb-chain/greenfield-go-sdk v1.0.0
github.com/cometbft/cometbft v0.37.2
github.com/cosmos/cosmos-sdk v0.47.3
Expand Down Expand Up @@ -174,11 +174,11 @@ require (
replace (
cosmossdk.io/api => github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210
cosmossdk.io/math => github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/consensys/gnark-crypto => github.com/consensys/gnark-crypto v0.7.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.0.2-0.20231102075210-cfdba889e18c
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,16 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+WjiTceGBHIoTvn60HIbs7Hm7bcHjyrSqYB9c=
github.com/bnb-chain/greenfield v1.0.0 h1:eg8jFKfbM8ZBKYJ40MZvZtJMtbIcM17tnd7OvAoMC7g=
github.com/bnb-chain/greenfield v1.0.0/go.mod h1:HAUcv20wBECrbyvVvtoAgvpeedr6plgz3m75FJ7Xxdg=
github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr3LCn5/XlcgDWr8=
github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield v1.0.2-0.20231102075513-12abbd906b00 h1:XQnQPCMSNFMQE6TqhXTh2+QqEzLMLYFpsQG+9xNzcdE=
github.com/bnb-chain/greenfield v1.0.2-0.20231102075513-12abbd906b00/go.mod h1:2ZBI8QMEm1/m96wk2OYngTxWSSU4H658kFyIreWU+vk=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62 h1:pakuREXV/XfWNwgsTXUQwYirem12Tt+2LGGHIar0z8o=
github.com/bnb-chain/greenfield-cometbft v0.0.0-20231030090949-99ef7dbd1e62/go.mod h1:43yICrTxu90VjEUpQN23bsqi9mua5m5sFQq/ekHwN9s=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f h1:zJvB2wCd80DQ9Nh/ZNQiP8MrHygSpDoav7OzHyIi/pM=
github.com/bnb-chain/greenfield-common/go v0.0.0-20230830120314-a54ffd6da39f/go.mod h1:it3JJVHeG9Wp4QED2GkY/7V9Qo3BuPdoC5/4/U6ecJM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0 h1:hWRvYunA4Um19gwL1SVfMwN9l431ROC7XZ+A5+xM/Bk=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.0/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.2-0.20231102075210-cfdba889e18c h1:DEut70ce1M3FeDdMvYafGCGzTpE3a4GHWNaJskOsAoY=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.2-0.20231102075210-cfdba889e18c/go.mod h1:ZWyfWX032fdHkICmEoJwylfqmL+Atf/QNVS8GzJq1Kc=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down

0 comments on commit cf2884a

Please sign in to comment.