@@ -3,9 +3,12 @@ package changeset
33import (
44 "context"
55 "fmt"
6+ "time"
67
78 "github.com/ethereum/go-ethereum/accounts/abi/bind"
89 "github.com/ethereum/go-ethereum/common"
10+ ethtypes "github.com/ethereum/go-ethereum/core/types"
11+ "github.com/sethvargo/go-retry"
912
1013 proxy "github.com/smartcontractkit/chainlink-evm/gethwrappers/data-feeds/generated/aggregator_proxy"
1114 bundleproxy "github.com/smartcontractkit/chainlink-evm/gethwrappers/data-feeds/generated/bundle_aggregator_proxy"
@@ -18,6 +21,26 @@ import (
1821 "github.com/smartcontractkit/chainlink/deployment/data-feeds/changeset/types"
1922)
2023
24+ func waitForContractCode (ctx context.Context , client cldf_evm.OnchainClient , tx * ethtypes.Transaction ) (common.Address , error ) {
25+ receipt , err := client .TransactionReceipt (ctx , tx .Hash ())
26+ if err != nil {
27+ return common.Address {}, fmt .Errorf ("failed to get tx receipt: %w" , err )
28+ }
29+ addr := receipt .ContractAddress
30+
31+ err = retry .Do (ctx , retry .WithMaxDuration (90 * time .Second , retry .WithCappedDuration (30 * time .Second , retry .NewFibonacci (5 * time .Second ))), func (ctx context.Context ) error {
32+ code , err := client .CodeAt (ctx , addr , receipt .BlockNumber )
33+ if err != nil {
34+ return retry .RetryableError (err )
35+ }
36+ if len (code ) == 0 {
37+ return retry .RetryableError (fmt .Errorf ("no contract code at %s (block %s) yet" , addr , receipt .BlockNumber ))
38+ }
39+ return nil
40+ })
41+ return addr , err
42+ }
43+
2144func DeployCache (chain cldf_evm.Chain , labels []string ) (* types.DeployCacheResponse , error ) {
2245 cacheAddr , tx , cacheContract , err := cache .DeployDataFeedsCache (chain .DeployerKey , chain .Client )
2346 if err != nil {
@@ -29,9 +52,7 @@ func DeployCache(chain cldf_evm.Chain, labels []string) (*types.DeployCacheRespo
2952 return nil , fmt .Errorf ("failed to confirm DataFeedsCache: %w" , err )
3053 }
3154
32- // WaitDeployed polls until contract code is available at the deployed address.
33- _ , err = bind .WaitDeployed (context .Background (), chain .Client , tx )
34- if err != nil {
55+ if _ , err := waitForContractCode (context .Background (), chain .Client , tx ); err != nil {
3556 return nil , fmt .Errorf ("failed to verify DataFeedsCache deployment: %w" , err )
3657 }
3758
@@ -69,9 +90,7 @@ func DeployAggregatorProxy(chain cldf_evm.Chain, aggregator common.Address, acce
6990 return nil , fmt .Errorf ("failed to confirm AggregatorProxy: %w" , err )
7091 }
7192
72- // WaitDeployed polls until contract code is available at the deployed address.
73- _ , err = bind .WaitDeployed (context .Background (), chain .Client , tx )
74- if err != nil {
93+ if _ , err := waitForContractCode (context .Background (), chain .Client , tx ); err != nil {
7594 return nil , fmt .Errorf ("failed to verify AggregatorProxy deployment: %w" , err )
7695 }
7796
@@ -124,9 +143,9 @@ func DeployBundleAggregatorProxy(lggr logger.Logger, chain cldf_evm.Chain, aggre
124143 "blockNumber" , blockNum ,
125144 "predictedAddress" , proxyAddr .Hex ())
126145
127- deployedAddr , err := bind . WaitDeployed (context .Background (), chain .Client , tx )
146+ deployedAddr , err := waitForContractCode (context .Background (), chain .Client , tx )
128147 if err != nil {
129- return nil , fmt .Errorf ("failed to deploy BundleAggregatorProxy: %w" , err )
148+ return nil , fmt .Errorf ("failed to verify BundleAggregatorProxy deployment : %w" , err )
130149 }
131150
132151 if deployedAddr != proxyAddr {
@@ -138,16 +157,9 @@ func DeployBundleAggregatorProxy(lggr logger.Logger, chain cldf_evm.Chain, aggre
138157 proxyAddr = deployedAddr
139158 }
140159
141- code , err := chain .Client .CodeAt (context .Background (), proxyAddr , nil )
142- if err != nil {
143- return nil , fmt .Errorf ("failed to read code at BundleAggregatorProxy address %s: %w" , proxyAddr , err )
144- }
145-
146160 lggr .Debugw ("BundleAggregatorProxy deployed and code verified" ,
147161 "chainSelector" , chain .Selector ,
148- "address" , proxyAddr .Hex (),
149- "txHash" , tx .Hash ().Hex (),
150- "codeSize" , len (code ))
162+ "address" , proxyAddr .Hex ())
151163
152164 proxyContract , err := bundleproxy .NewBundleAggregatorProxy (proxyAddr , chain .Client )
153165 if err != nil {
0 commit comments