Skip to content

Commit

Permalink
Fix: retry contract deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Aug 24, 2023
1 parent 147e995 commit ce22b61
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions ethergo/deployer/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package deployer

import (
"context"
"sync"
"testing"
"time"

"github.com/neverlee/keymutex"
"github.com/stretchr/testify/require"
"github.com/synapsecns/sanguine/core/retry"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/contracts"
"sync"
"testing"
)

// ContractDeployer is a contract deployer for a single contract type.
Expand Down Expand Up @@ -151,15 +154,24 @@ func (c *contractRegistryImpl) Deploy(ctx context.Context, contractType contract
deploymentHandle := c.deployers[contractType.ID()]
c.structMux.RUnlock()

deployedContract, err := deploymentHandle.Deploy(ctx)
var deployedContract contracts.DeployedContract
err := retry.WithBackoff(ctx, func(ctx context.Context) (err error) {
deployedContract, err = deploymentHandle.Deploy(ctx)
if err != nil {
return
}
c.backend.WaitForConfirmation(ctx, deployedContract.DeployTx())
err = c.backend.VerifyContract(contractType, deployedContract)
if err != nil {
return
}
logger.Debugf("added contract %s of types %s in tx %s on chain id %s", deployedContract.Address(), contractType.Name(), deployedContract.DeployTx().Hash().String(), deployedContract.ChainID().String())
return
}, retry.WithMax(120*time.Second))
require.Nil(c.tb, err)

c.backend.WaitForConfirmation(ctx, deployedContract.DeployTx())
err = c.backend.VerifyContract(contractType, deployedContract)
if err != nil {
logger.Warnf("got error %s while verifying contract, skipping", err)
}
logger.Debugf("added contract %s of types %s in tx %s on chain id %s", deployedContract.Address(), contractType.Name(), deployedContract.DeployTx().Hash().String(), deployedContract.ChainID().String())

return deployedContract
}
Expand Down

0 comments on commit ce22b61

Please sign in to comment.