Skip to content

Commit

Permalink
Merge branch 'main' into steve/thorchain
Browse files Browse the repository at this point in the history
  • Loading branch information
misko9 authored Aug 21, 2024
2 parents 7e3f0d0 + 3ea6fbc commit 70ae530
Show file tree
Hide file tree
Showing 12 changed files with 578 additions and 33 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/local-interchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@ jobs:
name: local-ic
path: ~/go/bin/local-ic

bash-e2e:
name: bash
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./local-interchain
strategy:
fail-fast: false

steps:
- name: checkout chain
uses: actions/checkout@v4

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start background ibc local-interchain
run: /tmp/local-ic start juno_ibc --api-port 8080 &

- name: Run Bash Script
run: |
cd bash
bash ./test.bash
- name: Cleanup
run: killall local-ic && exit 0

rust-e2e:
name: rust
needs: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
# run tests
- name: run unit tests
# -short flag purposefully omitted because there are some longer unit tests
run: go test -race -timeout 10m -failfast -p 2 $(go list ./... | grep -v /cmd | grep -v /examples)
run: go test -race -timeout 30m -failfast -p 2 $(go list ./... | grep -v /cmd | grep -v /examples)
15 changes: 12 additions & 3 deletions chain/cosmos/module_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,28 @@ func (tn *ChainNode) SlashingUnJail(ctx context.Context, keyName string) error {
func (c *CosmosChain) SlashingQueryParams(ctx context.Context) (*slashingtypes.Params, error) {
res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn).
Params(ctx, &slashingtypes.QueryParamsRequest{})
return &res.Params, err
if err != nil {
return nil, err
}
return &res.Params, nil
}

// SlashingSigningInfo returns signing info for a validator
func (c *CosmosChain) SlashingQuerySigningInfo(ctx context.Context, consAddress string) (*slashingtypes.ValidatorSigningInfo, error) {
res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn).
SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: consAddress})
return &res.ValSigningInfo, err
if err != nil {
return nil, err
}
return &res.ValSigningInfo, nil
}

// SlashingSigningInfos returns all signing infos
func (c *CosmosChain) SlashingQuerySigningInfos(ctx context.Context) ([]slashingtypes.ValidatorSigningInfo, error) {
res, err := slashingtypes.NewQueryClient(c.GetNode().GrpcConn).
SigningInfos(ctx, &slashingtypes.QuerySigningInfosRequest{})
return res.Info, err
if err != nil {
return nil, err
}
return res.Info, nil
}
70 changes: 56 additions & 14 deletions chain/cosmos/module_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,103 +84,145 @@ func (tn *ChainNode) StakingCreateValidatorFile(
func (c *CosmosChain) StakingQueryDelegation(ctx context.Context, valAddr string, delegator string) (*stakingtypes.DelegationResponse, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
Delegation(ctx, &stakingtypes.QueryDelegationRequest{DelegatorAddr: delegator, ValidatorAddr: valAddr})
return res.DelegationResponse, err
if err != nil {
return nil, err
}
return res.DelegationResponse, nil
}

// StakingQueryDelegations returns all delegations for a delegator.
func (c *CosmosChain) StakingQueryDelegations(ctx context.Context, delegator string) ([]stakingtypes.DelegationResponse, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
DelegatorDelegations(ctx, &stakingtypes.QueryDelegatorDelegationsRequest{DelegatorAddr: delegator, Pagination: nil})
return res.DelegationResponses, err
if err != nil {
return nil, err
}
return res.DelegationResponses, nil
}

// StakingQueryDelegationsTo returns all delegations to a validator.
func (c *CosmosChain) StakingQueryDelegationsTo(ctx context.Context, validator string) ([]*stakingtypes.DelegationResponse, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
ValidatorDelegations(ctx, &stakingtypes.QueryValidatorDelegationsRequest{ValidatorAddr: validator})
if err != nil {
return nil, err
}

var delegations []*stakingtypes.DelegationResponse
for _, d := range res.DelegationResponses {
delegations = append(delegations, &d)
}

return delegations, err
return delegations, nil
}

// StakingQueryDelegatorValidator returns a validator for a delegator.
func (c *CosmosChain) StakingQueryDelegatorValidator(ctx context.Context, delegator string, validator string) (*stakingtypes.Validator, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
DelegatorValidator(ctx, &stakingtypes.QueryDelegatorValidatorRequest{DelegatorAddr: delegator, ValidatorAddr: validator})
return &res.Validator, err
if err != nil {
return nil, err
}
return &res.Validator, nil
}

// StakingQueryDelegatorValidators returns all validators for a delegator.
func (c *CosmosChain) StakingQueryDelegatorValidators(ctx context.Context, delegator string) ([]stakingtypes.Validator, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
DelegatorValidators(ctx, &stakingtypes.QueryDelegatorValidatorsRequest{DelegatorAddr: delegator})
return res.Validators, err
if err != nil {
return nil, err
}
return res.Validators, nil
}

// StakingQueryHistoricalInfo returns the historical info at the given height.
func (c *CosmosChain) StakingQueryHistoricalInfo(ctx context.Context, height int64) (*stakingtypes.HistoricalInfo, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
HistoricalInfo(ctx, &stakingtypes.QueryHistoricalInfoRequest{Height: height})
return res.Hist, err
if err != nil {
return nil, err
}
return res.Hist, nil
}

// StakingQueryParams returns the staking parameters.
func (c *CosmosChain) StakingQueryParams(ctx context.Context) (*stakingtypes.Params, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
Params(ctx, &stakingtypes.QueryParamsRequest{})
return &res.Params, err
if err != nil {
return nil, err
}
return &res.Params, nil
}

// StakingQueryPool returns the current staking pool values.
func (c *CosmosChain) StakingQueryPool(ctx context.Context) (*stakingtypes.Pool, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
Pool(ctx, &stakingtypes.QueryPoolRequest{})
return &res.Pool, err
if err != nil {
return nil, err
}
return &res.Pool, nil
}

// StakingQueryRedelegation returns a redelegation.
func (c *CosmosChain) StakingQueryRedelegation(ctx context.Context, delegator string, srcValAddr string, dstValAddr string) ([]stakingtypes.RedelegationResponse, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
Redelegations(ctx, &stakingtypes.QueryRedelegationsRequest{DelegatorAddr: delegator, SrcValidatorAddr: srcValAddr, DstValidatorAddr: dstValAddr})
return res.RedelegationResponses, err
if err != nil {
return nil, err
}
return res.RedelegationResponses, nil
}

// StakingQueryUnbondingDelegation returns an unbonding delegation.
func (c *CosmosChain) StakingQueryUnbondingDelegation(ctx context.Context, delegator string, validator string) (*stakingtypes.UnbondingDelegation, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
UnbondingDelegation(ctx, &stakingtypes.QueryUnbondingDelegationRequest{DelegatorAddr: delegator, ValidatorAddr: validator})
return &res.Unbond, err
if err != nil {
return nil, err
}
return &res.Unbond, nil
}

// StakingQueryUnbondingDelegations returns all unbonding delegations for a delegator.
func (c *CosmosChain) StakingQueryUnbondingDelegations(ctx context.Context, delegator string) ([]stakingtypes.UnbondingDelegation, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
DelegatorUnbondingDelegations(ctx, &stakingtypes.QueryDelegatorUnbondingDelegationsRequest{DelegatorAddr: delegator})
return res.UnbondingResponses, err
if err != nil {
return nil, err
}
return res.UnbondingResponses, nil
}

// StakingQueryUnbondingDelegationsFrom returns all unbonding delegations from a validator.
func (c *CosmosChain) StakingQueryUnbondingDelegationsFrom(ctx context.Context, validator string) ([]stakingtypes.UnbondingDelegation, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
ValidatorUnbondingDelegations(ctx, &stakingtypes.QueryValidatorUnbondingDelegationsRequest{ValidatorAddr: validator})
return res.UnbondingResponses, err
if err != nil {
return nil, err
}
return res.UnbondingResponses, nil
}

// StakingQueryValidator returns a validator.
func (c *CosmosChain) StakingQueryValidator(ctx context.Context, validator string) (*stakingtypes.Validator, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).
Validator(ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: validator})
return &res.Validator, err
if err != nil {
return nil, err
}
return &res.Validator, nil
}

// StakingQueryValidators returns all validators.
func (c *CosmosChain) StakingQueryValidators(ctx context.Context, status string) ([]stakingtypes.Validator, error) {
res, err := stakingtypes.NewQueryClient(c.GetNode().GrpcConn).Validators(ctx, &stakingtypes.QueryValidatorsRequest{
Status: status,
})
return res.Validators, err
if err != nil {
return nil, err
}
return res.Validators, nil
}
6 changes: 3 additions & 3 deletions ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ type PathUpdateOptions struct {
}

type ICSConfig struct {
ProviderVerOverride string `yaml:"provider,omitempty" json:"provider,omitempty"`
ConsumerVerOverride string `yaml:"consumer,omitempty" json:"consumer,omitempty"`
ConsumerCopyProviderKey func(int) bool
ProviderVerOverride string `yaml:"provider,omitempty" json:"provider,omitempty"`
ConsumerVerOverride string `yaml:"consumer,omitempty" json:"consumer,omitempty"`
ConsumerCopyProviderKey func(int) bool `yaml:"-" json:"-"`
}

// GenesisConfig is used to start a chain from a pre-defined genesis state.
Expand Down
91 changes: 91 additions & 0 deletions interchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -255,6 +256,96 @@ func TestCosmosChain_BroadcastTx_HermesRelayer(t *testing.T) {
broadcastTxCosmosChainTest(t, ibc.Hermes)
}

func TestInterchain_ConcurrentRelayerOps(t *testing.T) {
type relayerTest struct {
relayer ibc.RelayerImplementation
name string
}

const (
denom = "uatom"
chains = 4
)

relayers := []relayerTest{
{
relayer: ibc.CosmosRly,
name: "Cosmos Relayer",
},
{
relayer: ibc.Hermes,
name: "Hermes",
},
}

numFullNodes := 0
numValidators := 1

for _, rly := range relayers {
rly := rly
t.Run(rly.name, func(t *testing.T) {
client, network := interchaintest.DockerSetup(t)
f, err := interchaintest.CreateLogFile(fmt.Sprintf("%d.json", time.Now().Unix()))
require.NoError(t, err)
// Reporter/logs
rep := testreporter.NewReporter(f)
eRep := rep.RelayerExecReporter(t)
ctx := context.Background()

chainSpecs := make([]*interchaintest.ChainSpec, chains)
for i := 0; i < chains; i++ {
chainSpecs[i] = &interchaintest.ChainSpec{
Name: "gaia",
ChainName: fmt.Sprintf("g%d", i+1),
Version: "v7.0.1",
NumValidators: &numValidators,
NumFullNodes: &numFullNodes,
ChainConfig: ibc.ChainConfig{
GasPrices: "0" + denom,
Denom: denom,
},
}
}
r := interchaintest.NewBuiltinRelayerFactory(rly.relayer, zaptest.NewLogger(t)).Build(
t, client, network,
)

cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), chainSpecs)
chains, err := cf.Chains(t.Name())
require.NoError(t, err)
ic := interchaintest.NewInterchain()
for _, chain := range chains {
require.NoError(t, err)
ic.AddChain(chain)
}
ic.AddRelayer(r, "relayer")
for i, chainI := range chains {
for j := i + 1; j < len(chains); j++ {
ic.AddLink(interchaintest.InterchainLink{
Chain1: chainI,
Chain2: chains[j],
Relayer: r,
Path: getIBCPath(chainI, chains[j]),
})
}
}
err = ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{
TestName: t.Name(),
Client: client,
NetworkID: network,
})
require.NoError(t, err)
t.Cleanup(func() {
ic.Close()
})
})
}
}

func getIBCPath(chainA, chainB ibc.Chain) string {
return chainA.Config().ChainID + "-" + chainB.Config().ChainID
}

func broadcastTxCosmosChainTest(t *testing.T, relayerImpl ibc.RelayerImplementation) {
if testing.Short() {
t.Skip("skipping in short mode")
Expand Down
Loading

0 comments on commit 70ae530

Please sign in to comment.