mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-13 03:26:38 +00:00
fix contract deployment by waiting for tx acceptance between individual lib deployments
This commit is contained in:
parent
84f2932b1e
commit
fa8590a5c8
4 changed files with 33 additions and 4 deletions
|
|
@ -77,7 +77,10 @@ var (
|
||||||
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
|
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
|
||||||
}
|
}
|
||||||
{{range $pattern, $name := .Libraries}}
|
{{range $pattern, $name := .Libraries}}
|
||||||
{{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend)
|
{{decapitalise $name}}Addr, tx, _, _ := Deploy{{capitalise $name}}(auth, backend)
|
||||||
|
if err := bind.WaitAccepted(context.Background(), backend, tx.Hash()); err != nil {
|
||||||
|
return common.Address{}, nil, nil err
|
||||||
|
}
|
||||||
{{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:])
|
{{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:])
|
||||||
{{end}}
|
{{end}}
|
||||||
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
|
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ type ContractTransactor interface {
|
||||||
type DeployBackend interface {
|
type DeployBackend interface {
|
||||||
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
|
TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
|
||||||
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
|
CodeAt(ctx context.Context, account common.Address, blockNumber *big.Int) ([]byte, error)
|
||||||
|
TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContractFilterer defines the methods needed to access log events using one-off
|
// ContractFilterer defines the methods needed to access log events using one-off
|
||||||
|
|
|
||||||
|
|
@ -313,7 +313,7 @@ func (c *BoundContract) createDynamicTx(opts *TransactOpts, contract *common.Add
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create the transaction
|
// create the transaction
|
||||||
nonce, err := c.getNonce(opts)
|
nonce, err := c.GetNonce(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -358,7 +358,7 @@ func (c *BoundContract) createLegacyTx(opts *TransactOpts, contract *common.Addr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create the transaction
|
// create the transaction
|
||||||
nonce, err := c.getNonce(opts)
|
nonce, err := c.GetNonce(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +395,7 @@ func (c *BoundContract) estimateGasLimit(opts *TransactOpts, contract *common.Ad
|
||||||
return c.transactor.EstimateGas(ensureContext(opts.Context), msg)
|
return c.transactor.EstimateGas(ensureContext(opts.Context), msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BoundContract) getNonce(opts *TransactOpts) (uint64, error) {
|
func (c *BoundContract) GetNonce(opts *TransactOpts) (uint64, error) {
|
||||||
if opts.Nonce == nil {
|
if opts.Nonce == nil {
|
||||||
return c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
|
return c.transactor.PendingNonceAt(ensureContext(opts.Context), opts.From)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -75,3 +75,28 @@ func WaitDeployed(ctx context.Context, b DeployBackend, hash common.Hash) (commo
|
||||||
}
|
}
|
||||||
return receipt.ContractAddress, err
|
return receipt.ContractAddress, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WaitAccepted(ctx context.Context, d DeployBackend, txHash common.Hash) error {
|
||||||
|
queryTicker := time.NewTicker(time.Second)
|
||||||
|
defer queryTicker.Stop()
|
||||||
|
logger := log.New("hash", txHash)
|
||||||
|
for {
|
||||||
|
_, _, err := d.TransactionByHash(ctx, txHash)
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if errors.Is(err, ethereum.NotFound) { // TODO: check this is emitted
|
||||||
|
logger.Trace("Transaction not yet accepted")
|
||||||
|
} else {
|
||||||
|
logger.Trace("Transaction submission failed", "err", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the next round.
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-queryTicker.C:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue