Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions deployment/data-feeds/changeset/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package changeset
import (
"context"
"fmt"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/sethvargo/go-retry"

proxy "github.com/smartcontractkit/chainlink-evm/gethwrappers/data-feeds/generated/aggregator_proxy"
bundleproxy "github.com/smartcontractkit/chainlink-evm/gethwrappers/data-feeds/generated/bundle_aggregator_proxy"
Expand All @@ -18,6 +21,26 @@ import (
"github.com/smartcontractkit/chainlink/deployment/data-feeds/changeset/types"
)

func waitForContractCode(ctx context.Context, client cldf_evm.OnchainClient, tx *ethtypes.Transaction) (common.Address, error) {
receipt, err := client.TransactionReceipt(ctx, tx.Hash())
if err != nil {
return common.Address{}, fmt.Errorf("failed to get tx receipt: %w", err)
}
addr := receipt.ContractAddress

err = retry.Do(ctx, retry.WithMaxDuration(90*time.Second, retry.WithCappedDuration(30*time.Second, retry.NewFibonacci(5*time.Second))), func(ctx context.Context) error {
code, err := client.CodeAt(ctx, addr, receipt.BlockNumber)
if err != nil {
return retry.RetryableError(err)
}
if len(code) == 0 {
return retry.RetryableError(fmt.Errorf("no contract code at %s (block %s) yet", addr, receipt.BlockNumber))
}
return nil
})
return addr, err
}

func DeployCache(chain cldf_evm.Chain, labels []string) (*types.DeployCacheResponse, error) {
cacheAddr, tx, cacheContract, err := cache.DeployDataFeedsCache(chain.DeployerKey, chain.Client)
if err != nil {
Expand All @@ -29,9 +52,7 @@ func DeployCache(chain cldf_evm.Chain, labels []string) (*types.DeployCacheRespo
return nil, fmt.Errorf("failed to confirm DataFeedsCache: %w", err)
}

// WaitDeployed polls until contract code is available at the deployed address.
_, err = bind.WaitDeployed(context.Background(), chain.Client, tx)
if err != nil {
if _, err := waitForContractCode(context.Background(), chain.Client, tx); err != nil {
return nil, fmt.Errorf("failed to verify DataFeedsCache deployment: %w", err)
}

Expand Down Expand Up @@ -69,9 +90,7 @@ func DeployAggregatorProxy(chain cldf_evm.Chain, aggregator common.Address, acce
return nil, fmt.Errorf("failed to confirm AggregatorProxy: %w", err)
}

// WaitDeployed polls until contract code is available at the deployed address.
_, err = bind.WaitDeployed(context.Background(), chain.Client, tx)
if err != nil {
if _, err := waitForContractCode(context.Background(), chain.Client, tx); err != nil {
return nil, fmt.Errorf("failed to verify AggregatorProxy deployment: %w", err)
}

Expand Down Expand Up @@ -124,9 +143,9 @@ func DeployBundleAggregatorProxy(lggr logger.Logger, chain cldf_evm.Chain, aggre
"blockNumber", blockNum,
"predictedAddress", proxyAddr.Hex())

deployedAddr, err := bind.WaitDeployed(context.Background(), chain.Client, tx)
deployedAddr, err := waitForContractCode(context.Background(), chain.Client, tx)
if err != nil {
return nil, fmt.Errorf("failed to deploy BundleAggregatorProxy: %w", err)
return nil, fmt.Errorf("failed to verify BundleAggregatorProxy deployment: %w", err)
}

if deployedAddr != proxyAddr {
Expand All @@ -138,16 +157,9 @@ func DeployBundleAggregatorProxy(lggr logger.Logger, chain cldf_evm.Chain, aggre
proxyAddr = deployedAddr
}

code, err := chain.Client.CodeAt(context.Background(), proxyAddr, nil)
if err != nil {
return nil, fmt.Errorf("failed to read code at BundleAggregatorProxy address %s: %w", proxyAddr, err)
}

lggr.Debugw("BundleAggregatorProxy deployed and code verified",
"chainSelector", chain.Selector,
"address", proxyAddr.Hex(),
"txHash", tx.Hash().Hex(),
"codeSize", len(code))
"address", proxyAddr.Hex())

proxyContract, err := bundleproxy.NewBundleAggregatorProxy(proxyAddr, chain.Client)
if err != nil {
Expand Down
Loading