-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: redundant rpcs #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: redundant rpcs #1467
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
45c18d0
feat: cosmos redundant rpcs
joelsmith-2019 f5e8a54
fix command alias
joelsmith-2019 551a801
add backup rpcs from registry
joelsmith-2019 9b1286b
feat: liveliness check for penumbra
joelsmith-2019 e290aa5
Start work on interchaintests
joelsmith-2019 9628ff0
update log levels
joelsmith-2019 6bc0ba7
Use relayer image & get host port via bindings
joelsmith-2019 e1e7e99
Populate config with CLI
joelsmith-2019 dda253e
fix nil pointer ref
joelsmith-2019 1d9d303
retry primary rpc first
joelsmith-2019 9cdbdcc
fix loop variable
joelsmith-2019 31ba93e
poll for acknowledgement
joelsmith-2019 bc60dd5
Merge branch 'main' into joel/backup-rpcs
joelsmith-2019 65b0b8d
Merge branch 'main' into joel/backup-rpcs
reecepbcups File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
package interchaintest_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" | ||
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
relayertest "github.com/cosmos/relayer/v2/interchaintest" | ||
"github.com/strangelove-ventures/interchaintest/v8" | ||
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v8/ibc" | ||
icrelayer "github.com/strangelove-ventures/interchaintest/v8/relayer" | ||
"github.com/strangelove-ventures/interchaintest/v8/relayer/rly" | ||
"github.com/strangelove-ventures/interchaintest/v8/testreporter" | ||
"github.com/strangelove-ventures/interchaintest/v8/testutil" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
// TestBackupRpcs tests the functionality of falling back to secondary RPCs when the primary node goes offline or becomes unresponsive. | ||
func TestBackupRpcs(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
|
||
t.Parallel() | ||
|
||
numVals := 5 | ||
numFullNodes := 0 | ||
|
||
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ | ||
{ | ||
Name: "gaia", | ||
Version: "v7.0.0", | ||
NumValidators: &numVals, | ||
NumFullNodes: &numFullNodes, | ||
|
||
ChainConfig: ibc.ChainConfig{ | ||
GasPrices: "0.0uatom", | ||
}, | ||
}, | ||
{ | ||
Name: "osmosis", | ||
Version: "v11.0.0", | ||
NumValidators: &numVals, | ||
NumFullNodes: &numFullNodes, | ||
ChainConfig: ibc.ChainConfig{ | ||
GasPrices: "0.0uosmo", | ||
}, | ||
}, | ||
}) | ||
|
||
chains, err := cf.Chains(t.Name()) | ||
require.NoError(t, err) | ||
chainA, chainB := chains[0], chains[1] | ||
|
||
ctx := context.Background() | ||
client, network := interchaintest.DockerSetup(t) | ||
|
||
image := relayertest.BuildRelayerImage(t) | ||
rf := interchaintest.NewBuiltinRelayerFactory( | ||
ibc.CosmosRly, | ||
zaptest.NewLogger(t), | ||
icrelayer.CustomDockerImage(image, "latest", "100:1000"), | ||
icrelayer.ImagePull(false), | ||
icrelayer.StartupFlags("--processor", "events", "--block-history", "100"), | ||
) | ||
|
||
r := rf.Build(t, client, network) | ||
|
||
const pathName = "chainA-chainB" | ||
|
||
ic := interchaintest.NewInterchain(). | ||
AddChain(chainA). | ||
AddChain(chainB). | ||
AddRelayer(r, "relayer"). | ||
AddLink(interchaintest.InterchainLink{ | ||
Chain1: chainA, | ||
Chain2: chainB, | ||
Relayer: r, | ||
Path: pathName, | ||
}) | ||
|
||
rep := testreporter.NewNopReporter() | ||
eRep := rep.RelayerExecReporter(t) | ||
|
||
require.NoError(t, ic.Build(ctx, eRep, interchaintest.InterchainBuildOptions{ | ||
TestName: t.Name(), | ||
Client: client, | ||
NetworkID: network, | ||
SkipPathCreation: false, | ||
})) | ||
|
||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
|
||
// Create and fund user accs & assert initial balances. | ||
initBal := sdkmath.NewInt(1_000_000_000_000) | ||
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), initBal, chainA, chainB) | ||
require.NoError(t, testutil.WaitForBlocks(ctx, 2, chainA, chainB)) | ||
|
||
userA := users[0] | ||
userB := users[1] | ||
|
||
userABal, err := chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) | ||
require.NoError(t, err) | ||
require.True(t, initBal.Equal(userABal)) | ||
|
||
userBBal, err := chainB.GetBalance(ctx, userB.FormattedAddress(), chainB.Config().Denom) | ||
require.NoError(t, err) | ||
require.True(t, initBal.Equal(userBBal)) | ||
|
||
rly := r.(*rly.CosmosRelayer) | ||
|
||
// Get all chains | ||
for _, chain := range [](*cosmos.CosmosChain){chainA.(*cosmos.CosmosChain), chainB.(*cosmos.CosmosChain)} { | ||
|
||
addrs := []string{} | ||
|
||
// loop through nodes to collect rpc addrs | ||
for _, node := range chain.Validators { | ||
rpc := fmt.Sprintf("http://%s:26657", node.Name()) | ||
addrs = append(addrs, rpc) | ||
} | ||
|
||
cmd := []string{"rly", "chains", "set-rpc-addr", chain.Config().Name, addrs[numVals-1], "--home", rly.HomeDir()} | ||
res := r.Exec(ctx, eRep, cmd, nil) | ||
require.NoError(t, res.Err) | ||
|
||
cmd = []string{"rly", "chains", "set-backup-rpc-addrs", chain.Config().Name, strings.Join(addrs[:numVals-1], ","), "--home", rly.HomeDir()} | ||
res = r.Exec(ctx, eRep, cmd, nil) | ||
require.NoError(t, res.Err) | ||
} | ||
|
||
err = r.StartRelayer(ctx, eRep, pathName) | ||
require.NoError(t, err) | ||
|
||
t.Cleanup( | ||
func() { | ||
err := r.StopRelayer(ctx, eRep) | ||
if err != nil { | ||
t.Logf("an error occurred while stopping the relayer: %s", err) | ||
} | ||
}, | ||
) | ||
|
||
// Send transfers that should succeed & assert balances. | ||
channels, err := r.GetChannels(ctx, eRep, chainA.Config().ChainID) | ||
require.NoError(t, err) | ||
require.Equal(t, 1, len(channels)) | ||
|
||
channel := channels[0] | ||
|
||
transferAmount := sdkmath.NewInt(1_000) | ||
|
||
transferAB := ibc.WalletAmount{ | ||
Address: userB.FormattedAddress(), | ||
Denom: chainA.Config().Denom, | ||
Amount: transferAmount, | ||
} | ||
|
||
// wait 10 blocks | ||
require.NoError(t, testutil.WaitForBlocks(ctx, 10, chainA, chainB)) | ||
|
||
// turn off last nodes on both chains | ||
val := chainA.(*cosmos.CosmosChain).Validators[numVals-1] | ||
err = val.StopContainer(ctx) | ||
require.NoError(t, err) | ||
|
||
val = chainB.(*cosmos.CosmosChain).Validators[numVals-1] | ||
err = val.StopContainer(ctx) | ||
require.NoError(t, err) | ||
|
||
// wait 10 blocks | ||
require.NoError(t, testutil.WaitForBlocks(ctx, 10, chainA, chainB)) | ||
|
||
// send ibc tx from chain a to b | ||
tx, err := chainA.SendIBCTransfer(ctx, channel.ChannelID, userA.KeyName(), transferAB, ibc.TransferOptions{}) | ||
require.NoError(t, err) | ||
require.NoError(t, tx.Validate()) | ||
|
||
// get chain b height | ||
bHeight, err := chainB.Height(ctx) | ||
require.NoError(t, err) | ||
|
||
// Poll for MsgRecvPacket on b chain | ||
_, err = cosmos.PollForMessage[*chantypes.MsgRecvPacket](ctx, chainB.(*cosmos.CosmosChain), cosmos.DefaultEncoding().InterfaceRegistry, bHeight, bHeight+20, nil) | ||
require.NoError(t, err) | ||
|
||
// get chain a height | ||
aHeight, err := chainA.Height(ctx) | ||
require.NoError(t, err) | ||
|
||
// poll for acknowledge on 'a' chain | ||
_, err = testutil.PollForAck(ctx, chainA.(*cosmos.CosmosChain), aHeight, aHeight+30, tx.Packet) | ||
require.NoError(t, err) | ||
|
||
// Compose the ibc denom for balance assertions on the counterparty and assert balances. | ||
denom := transfertypes.GetPrefixedDenom( | ||
channel.Counterparty.PortID, | ||
channel.Counterparty.ChannelID, | ||
chainA.Config().Denom, | ||
) | ||
trace := transfertypes.ParseDenomTrace(denom) | ||
|
||
// validate user balances on both chains | ||
userABal, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) | ||
require.NoError(t, err) | ||
require.True(t, userABal.Equal(initBal.Sub(transferAmount))) | ||
|
||
userBBal, err = chainB.GetBalance(ctx, userB.FormattedAddress(), trace.IBCDenom()) | ||
require.NoError(t, err) | ||
require.True(t, userBBal.Equal(transferAmount)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.