Skip to content

Commit

Permalink
refactor backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed Jul 7, 2024
1 parent 47e5de2 commit 7a4d911
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
15 changes: 9 additions & 6 deletions interchaintest/helpers/cosmwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

var backoffPolicy = &backoff.ExponentialBackOff{
MaxElapsedTime: time.Minute,
InitialInterval: 500 * time.Millisecond,
Multiplier: 1.5,
MaxInterval: 10 * time.Second,
func newBackoffPolicy() *backoff.ExponentialBackOff {
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = time.Minute
b.InitialInterval = 500 * time.Millisecond
b.Multiplier = 1.5
b.MaxInterval = 10 * time.Second
return b
}

func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, contractAddr, queryMsg string, res interface{}) error {
Expand All @@ -35,11 +37,12 @@ func SmartQueryString(t *testing.T, ctx context.Context, chain *cosmos.CosmosCha

func StoreContract(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, keyname, fileLoc string) string {
var codeId string

err := backoff.Retry(func() error {
var err error
codeId, err = chain.StoreContract(ctx, keyname, fileLoc)
return err
}, backoffPolicy)
}, newBackoffPolicy())

if err != nil {
t.Fatalf("Failed to store contract: %v", err)
Expand Down
14 changes: 7 additions & 7 deletions interchaintest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ import (
tokenfactorytypes "github.com/CosmosContracts/juno/v23/x/tokenfactory/types"
)

var backoffPolicy = &backoff.ExponentialBackOff{
MaxElapsedTime: 5 * time.Minute,
InitialInterval: 1 * time.Second,
Multiplier: 2,
MaxInterval: 30 * time.Second,
}

var (
VotingPeriod = "15s"
MaxDepositPeriod = "10s"
Expand Down Expand Up @@ -132,6 +125,13 @@ func CreateThisBranchChain(t *testing.T, numVals, numFull int) []ibc.Chain {
}

func CreateChainWithCustomConfig(t *testing.T, numVals, numFull int, config ibc.ChainConfig) []ibc.Chain {

backoffPolicy := backoff.NewExponentialBackOff()
backoffPolicy.MaxElapsedTime = 5 * time.Minute
backoffPolicy.InitialInterval = 500 * time.Millisecond
backoffPolicy.Multiplier = 1.5
backoffPolicy.MaxInterval = 10 * time.Second

var chains []ibc.Chain

err := backoff.Retry(func() error {
Expand Down

0 comments on commit 7a4d911

Please sign in to comment.