Skip to content

Commit

Permalink
distinguish inturn relayers
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Oct 30, 2023
1 parent f5f1749 commit 805fce5
Show file tree
Hide file tree
Showing 23 changed files with 430 additions and 131 deletions.
242 changes: 184 additions & 58 deletions api/cosmos/oracle/v1/query.pulsar.go

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion proto/cosmos/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,22 @@ message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
}

// ClaimSrcChain defines the src chain of a claim
enum ClaimSrcChain {
option (gogoproto.goproto_enum_prefix) = false;
// CLAIM_SRC_CHAIN_UNSPECIFIED
CLAIM_SRC_CHAIN_UNSPECIFIED = 0;
// CLAIM_SRC_CHAIN_BSC defines BSC source chain
CLAIM_SRC_CHAIN_BSC = 1;
// CLAIM_SRC_CHAIN_OP_BNB defines OPBNB source chain
CLAIM_SRC_CHAIN_OP_BNB = 2;
}

// QueryInturnRelayerRequest is the request type for the Query In-turn relayer RPC method.
message QueryInturnRelayerRequest {}
message QueryInturnRelayerRequest {
// ClaimSrcChain defines the src chain of a claim
ClaimSrcChain claim_src_chain = 1;
}

// QueryInturnRelayerResponse is the response type for the Query In-turn relayer RPC method.
message QueryInturnRelayerResponse {
Expand Down
1 change: 1 addition & 0 deletions snapshots/types/snapshot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions tests/e2e/bank/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (s *E2ETestSuite) TestTotalSupplyGRPCHandler() {
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Add(sdk.NewInt(10))),
),
Pagination: &query.PageResponse{
Total: 2,
},
Pagination: &query.PageResponse{},
},
},
{
Expand Down Expand Up @@ -160,7 +158,7 @@ func (s *E2ETestSuite) TestDenomMetadataGRPCHandler() {
Display: "eth",
},
},
Pagination: &query.PageResponse{Total: 2},
Pagination: &query.PageResponse{},
},
},
{
Expand Down Expand Up @@ -244,9 +242,7 @@ func (s *E2ETestSuite) TestBalancesGRPCHandler() {
sdk.NewCoin(fmt.Sprintf("%stoken", val.Moniker), s.cfg.AccountTokens),
sdk.NewCoin(s.cfg.BondDenom, s.cfg.StakingTokens.Sub(s.cfg.BondedTokens)),
),
Pagination: &query.PageResponse{
Total: 2,
},
Pagination: &query.PageResponse{},
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/bank/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (s *E2ETestSuite) TestGetCmdQueryDenomsMetadata() {
Display: "eth",
},
},
Pagination: &query.PageResponse{Total: 2},
Pagination: &query.PageResponse{},
},
},
{
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/staking/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (s *E2ETestSuite) TestGRPCQueryDelegatorDelegations() {
DelegationResponses: types.DelegationResponses{
types.NewDelegationResp(val.Address, val.ValAddress, sdk.NewDecFromInt(cli.DefaultTokens), sdk.NewCoin(sdk.DefaultBondDenom, cli.DefaultTokens)),
},
Pagination: &query.PageResponse{Total: 1},
Pagination: &query.PageResponse{},
},
},
{
Expand All @@ -413,7 +413,7 @@ func (s *E2ETestSuite) TestGRPCQueryDelegatorDelegations() {
&types.QueryDelegatorDelegationsResponse{},
&types.QueryDelegatorDelegationsResponse{
DelegationResponses: types.DelegationResponses{},
Pagination: &query.PageResponse{Total: 0},
Pagination: &query.PageResponse{},
},
},
}
Expand Down Expand Up @@ -592,7 +592,6 @@ func (s *E2ETestSuite) TestGRPCQueryDelegatorValidators() {
} else {
s.Require().NoError(err)
s.Require().Len(validators.Validators, len(s.network.Validators))
s.Require().Equal(int(validators.Pagination.Total), len(s.network.Validators))
}
})
}
Expand Down
9 changes: 9 additions & 0 deletions testutil/testdata/unknonwnproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions types/query/pagination.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions types/tx/signing/signing.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions types/tx/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions x/distribution/types/distribution.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/gashub/types/gashub.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions x/gov/testutil/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ type CrossChainKeeper interface {
GetReceiveSequence(ctx sdk.Context, destChainId sdk.ChainID, channelID sdk.ChannelID) uint64

IsDestChainSupported(chainID sdk.ChainID) bool

GetDestOpChainID() sdk.ChainID
}
14 changes: 14 additions & 0 deletions x/gov/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions x/gov/types/v1/gov.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions x/group/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/oracle/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ func (k Keeper) InturnRelayer(c context.Context, req *types.QueryInturnRelayerRe
}
ctx := sdk.UnwrapSDKContext(c)
_, relayerInterval := k.GetRelayerParams(ctx)
return k.GetInturnRelayer(ctx, relayerInterval)
return k.GetInturnRelayer(ctx, relayerInterval, req.ClaimSrcChain)
}
22 changes: 16 additions & 6 deletions x/oracle/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"encoding/hex"

upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

sdkerrors "cosmossdk.io/errors"
"github.com/cometbft/cometbft/libs/log"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand Down Expand Up @@ -80,7 +82,7 @@ func (k Keeper) GetRelayerRewardShare(ctx sdk.Context) uint32 {
}

// IsRelayerValid returns true if the relayer is valid and allowed to send the claim message
func (k Keeper) IsRelayerValid(ctx sdk.Context, relayer sdk.AccAddress, validators []stakingtypes.Validator, claimTimestamp uint64) (bool, error) {
func (k Keeper) IsRelayerValid(ctx sdk.Context, relayer sdk.AccAddress, validators []stakingtypes.Validator, claimTimestamp uint64, claimSrcChain types.ClaimSrcChain) (bool, error) {
var validatorIndex int64 = -1
var vldr stakingtypes.Validator
for index, validator := range validators {
Expand All @@ -98,7 +100,7 @@ func (k Keeper) IsRelayerValid(ctx sdk.Context, relayer sdk.AccAddress, validato
inturnRelayerTimeout, relayerInterval := k.GetRelayerParams(ctx)

// check whether submitter of msgClaim is an in-turn relayer
inturnRelayerBlsKey, _, err := k.getInturnRelayer(ctx, relayerInterval)
inturnRelayerBlsKey, _, err := k.getInturnRelayer(ctx, relayerInterval, claimSrcChain)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -130,7 +132,12 @@ func (k Keeper) CheckClaim(ctx sdk.Context, claim *types.MsgClaim) (sdk.AccAddre
}
validators := historicalInfo.Valset

isValid, err := k.IsRelayerValid(ctx, relayer, validators, claim.Timestamp)
claimSrcChain := types.CLAIM_SRC_CHAIN_BSC
if ctx.IsUpgraded(upgradetypes.Pampas) && sdk.ChainID(claim.SrcChainId) == k.CrossChainKeeper.GetDestOpChainID() {
claimSrcChain = types.CLAIM_SRC_CHAIN_OP_BNB
}

isValid, err := k.IsRelayerValid(ctx, relayer, validators, claim.Timestamp, claimSrcChain)
if err != nil {
return sdk.AccAddress{}, nil, err
}
Expand Down Expand Up @@ -190,7 +197,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
return params
}

func (k Keeper) getInturnRelayer(ctx sdk.Context, relayerInterval uint64) ([]byte, *types.RelayInterval, error) {
func (k Keeper) getInturnRelayer(ctx sdk.Context, relayerInterval uint64, claimSrcChain types.ClaimSrcChain) ([]byte, *types.RelayInterval, error) {
historicalInfo, ok := k.StakingKeeper.GetHistoricalInfo(ctx, ctx.BlockHeight())
if !ok {
return nil, nil, sdkerrors.Wrapf(types.ErrValidatorSet, "get historical validators failed")
Expand All @@ -211,6 +218,9 @@ func (k Keeper) getInturnRelayer(ctx sdk.Context, relayerInterval uint64) ([]byt
start := curTimeStamp - (remainder - inTurnRelayerIndex*relayerInterval)
end := start + relayerInterval

if claimSrcChain == types.CLAIM_SRC_CHAIN_OP_BNB {
inTurnRelayerIndex = (inTurnRelayerIndex + uint64(validatorsSize/2)) % uint64(validatorsSize)
}
inturnRelayer := validators[inTurnRelayerIndex]

return inturnRelayer.BlsKey, &types.RelayInterval{
Expand All @@ -219,8 +229,8 @@ func (k Keeper) getInturnRelayer(ctx sdk.Context, relayerInterval uint64) ([]byt
}, nil
}

func (k Keeper) GetInturnRelayer(ctx sdk.Context, relayerInterval uint64) (*types.QueryInturnRelayerResponse, error) {
blsKey, interval, err := k.getInturnRelayer(ctx, relayerInterval)
func (k Keeper) GetInturnRelayer(ctx sdk.Context, relayerInterval uint64, claimSrcChain types.ClaimSrcChain) (*types.QueryInturnRelayerResponse, error) {
blsKey, interval, err := k.getInturnRelayer(ctx, relayerInterval, claimSrcChain)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 805fce5

Please sign in to comment.