Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into andrew/consolidate_cr…
Browse files Browse the repository at this point in the history
…eate_node_container
  • Loading branch information
agouin committed Mar 23, 2023
2 parents 9f73336 + b74ff72 commit 5f829b4
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 39 deletions.
2 changes: 2 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type ChainNode struct {
// Ports set during StartContainer.
hostRPCPort string
hostGRPCPort string

preStartListeners dockerutil.Listeners
}

func NewChainNode(log *zap.Logger, validator bool, chain *CosmosChain, dockerClient *dockerclient.Client, networkID string, testName string, image ibc.DockerImage, index int) *ChainNode {
Expand Down
4 changes: 3 additions & 1 deletion chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,15 @@ func (c *CosmosChain) GetGasFeesInNativeDenom(gasPaid int64) int64 {
return int64(fees)
}

func (c *CosmosChain) UpgradeVersion(ctx context.Context, cli *client.Client, version string) {
func (c *CosmosChain) UpgradeVersion(ctx context.Context, cli *client.Client, containerRepo, version string) {
c.cfg.Images[0].Version = version
for _, n := range c.Validators {
n.Image.Version = version
n.Image.Repository = containerRepo
}
for _, n := range c.FullNodes {
n.Image.Version = version
n.Image.Repository = containerRepo
}
c.pullImages(ctx, cli)
}
Expand Down
2 changes: 2 additions & 0 deletions chain/penumbra/penumbra_app_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type PenumbraAppNode struct {
// Set during StartContainer.
hostRPCPort string
hostGRPCPort string

preStartListeners dockerutil.Listeners
}

const (
Expand Down
2 changes: 2 additions & 0 deletions chain/polkadot/parachain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type ParachainNode struct {
api *gsrpc.SubstrateAPI
hostWsPort string
hostRpcPort string

preStartListeners dockerutil.Listeners
}

type ParachainNodes []*ParachainNode
Expand Down
2 changes: 2 additions & 0 deletions chain/polkadot/relay_chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type RelayChainNode struct {
api *gsrpc.SubstrateAPI
hostWsPort string
hostRpcPort string

preStartListeners dockerutil.Listeners
}

type RelayChainNodes []*RelayChainNode
Expand Down
6 changes: 3 additions & 3 deletions examples/cosmos/chain_upgrade_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
)

func TestJunoUpgradeIBC(t *testing.T) {
CosmosChainUpgradeIBCTest(t, "juno", "v6.0.0", "v8.0.0", "multiverse")
CosmosChainUpgradeIBCTest(t, "juno", "v6.0.0", "ghcr.io/strangelove-ventures/heighliner/juno", "v8.0.0", "multiverse")
}

func CosmosChainUpgradeIBCTest(t *testing.T, chainName, initialVersion, upgradeVersion string, upgradeName string) {
func CosmosChainUpgradeIBCTest(t *testing.T, chainName, initialVersion, upgradeContainerRepo, upgradeVersion string, upgradeName string) {
if testing.Short() {
t.Skip("skipping in short mode")
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func CosmosChainUpgradeIBCTest(t *testing.T, chainName, initialVersion, upgradeV
require.NoError(t, err, "error stopping node(s)")

// upgrade version on all nodes
chain.UpgradeVersion(ctx, client, upgradeVersion)
chain.UpgradeVersion(ctx, client, upgradeContainerRepo, upgradeVersion)

// start all nodes back up.
// validators reach consensus on first block after upgrade height
Expand Down
6 changes: 3 additions & 3 deletions examples/cosmos/chain_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const (
)

func TestJunoUpgrade(t *testing.T) {
CosmosChainUpgradeTest(t, "juno", "v6.0.0", "v8.0.0", "multiverse")
CosmosChainUpgradeTest(t, "juno", "v6.0.0", "ghcr.io/strangelove-ventures/heighliner/juno", "v8.0.0", "multiverse")
}

func CosmosChainUpgradeTest(t *testing.T, chainName, initialVersion, upgradeVersion string, upgradeName string) {
func CosmosChainUpgradeTest(t *testing.T, chainName, initialVersion, upgradeContainerRepo, upgradeVersion, upgradeName string) {
if testing.Short() {
t.Skip("skipping in short mode")
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func CosmosChainUpgradeTest(t *testing.T, chainName, initialVersion, upgradeVers
require.NoError(t, err, "error stopping node(s)")

// upgrade version on all nodes
chain.UpgradeVersion(ctx, client, upgradeVersion)
chain.UpgradeVersion(ctx, client, upgradeContainerRepo, upgradeVersion)

// start all nodes back up.
// validators reach consensus on first block after upgrade height
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/cometbft/cometbft v0.37.0
github.com/cosmos/cosmos-sdk v0.47.0
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v7 v7.0.0-rc1
github.com/cosmos/ibc-go/v7 v7.0.0
github.com/davecgh/go-spew v1.1.1
github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0
github.com/docker/docker v20.10.19+incompatible
Expand All @@ -31,7 +31,7 @@ require (
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.7.0
golang.org/x/sync v0.1.0
golang.org/x/tools v0.6.0
golang.org/x/tools v0.7.0
google.golang.org/grpc v1.53.0
gopkg.in/yaml.v3 v3.0.1
modernc.org/sqlite v1.21.0
Expand Down Expand Up @@ -202,7 +202,7 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/goleak v1.1.12 // indirect
golang.org/x/exp v0.0.0-20230310171629-522b1b587ee0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.6.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ github.com/cosmos/gogoproto v1.4.6 h1:Ee7z15dWJaGlgM2rWrK8N2IX7PQcuccu8oG68jp5RL
github.com/cosmos/gogoproto v1.4.6/go.mod h1:VS/ASYmPgv6zkPKLjR9EB91lwbLHOzaGCirmKKhncfI=
github.com/cosmos/iavl v0.20.0 h1:fTVznVlepH0KK8NyKq8w+U7c2L6jofa27aFX6YGlm38=
github.com/cosmos/iavl v0.20.0/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
github.com/cosmos/ibc-go/v7 v7.0.0-rc1 h1:+HokO9GDqWNmjKSLGSC1WjcqjOdDIeSmNGuXQFSHMQE=
github.com/cosmos/ibc-go/v7 v7.0.0-rc1/go.mod h1:wpKGb+lqAnxwThgS3LoCPgDEFNAPVX+1YIQCAJcePcM=
github.com/cosmos/ibc-go/v7 v7.0.0 h1:j4kyywlG0hhDmT9FmSaR5iCIka7Pz7kJTxGWY1nlV9Q=
github.com/cosmos/ibc-go/v7 v7.0.0/go.mod h1:BFh8nKWjr5zeR2OZfhkzdgDzj1+KjRn3aJLpwapStj8=
github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab h1:I9ialKTQo7248V827Bba4OuKPmk+FPzmTVHsLXaIJWw=
github.com/cosmos/ics23/go v0.9.1-0.20221207100636-b1abd8678aab/go.mod h1:2CwqasX5dSD7Hbp/9b6lhK6BwoBDCBldx7gPKRukR60=
github.com/cosmos/ledger-cosmos-go v0.12.1 h1:sMBxza5p/rNK/06nBSNmsI/WDqI0pVJFVNihy1Y984w=
Expand Down Expand Up @@ -1307,8 +1307,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1623,8 +1623,8 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
34 changes: 11 additions & 23 deletions internal/dockerutil/startcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,25 @@ package dockerutil

import (
"context"
"errors"
"time"

"github.com/avast/retry-go/v4"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)

// StartContainer attempts to start the container with the given ID.
// If the request times out, it retries a certain number of times before failing.
// Any other failure modes stop immediately.
func StartContainer(ctx context.Context, cli *client.Client, id string) error {
return retry.Do(
func() error {
retryCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
// add a deadline for the request if the calling context does not provide one
if _, hasDeadline := ctx.Deadline(); !hasDeadline {
var cancel func()
ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
defer cancel()
}

err := cli.ContainerStart(retryCtx, id, types.ContainerStartOptions{})
if err != nil {
// One special case: retryCtx timed out and the outer ctx didn't.
if errors.Is(err, context.DeadlineExceeded) && ctx.Err() == nil {
return err
}
err := cli.ContainerStart(ctx, id, types.ContainerStartOptions{})
if err != nil {
return err
}

// Otherwise, assume the error cannot be retried.
return retry.Unrecoverable(err)
}

return nil
},
retry.Context(ctx),
retry.DelayType(retry.FixedDelay),
)
return nil
}

0 comments on commit 5f829b4

Please sign in to comment.