Commit c65c1f88 authored by zhiqiangxu's avatar zhiqiangxu Committed by GitHub

support EstimateGas for blob tx (#12086)

parent de46c9af
...@@ -349,34 +349,39 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (* ...@@ -349,34 +349,39 @@ func (m *SimpleTxManager) craftTx(ctx context.Context, candidate TxCandidate) (*
gasLimit := candidate.GasLimit gasLimit := candidate.GasLimit
var sidecar *types.BlobTxSidecar
var blobHashes []common.Hash
if len(candidate.Blobs) > 0 {
if candidate.To == nil {
return nil, errors.New("blob txs cannot deploy contracts")
}
if sidecar, blobHashes, err = MakeSidecar(candidate.Blobs); err != nil {
return nil, fmt.Errorf("failed to make sidecar: %w", err)
}
}
// If the gas limit is set, we can use that as the gas // If the gas limit is set, we can use that as the gas
if gasLimit == 0 { if gasLimit == 0 {
// Calculate the intrinsic gas for the transaction // Calculate the intrinsic gas for the transaction
gas, err := m.backend.EstimateGas(ctx, ethereum.CallMsg{ callMsg := ethereum.CallMsg{
From: m.cfg.From, From: m.cfg.From,
To: candidate.To, To: candidate.To,
GasTipCap: gasTipCap, GasTipCap: gasTipCap,
GasFeeCap: gasFeeCap, GasFeeCap: gasFeeCap,
Data: candidate.TxData, Data: candidate.TxData,
Value: candidate.Value, Value: candidate.Value,
}) }
if len(blobHashes) > 0 {
callMsg.BlobGasFeeCap = blobBaseFee
callMsg.BlobHashes = blobHashes
}
gas, err := m.backend.EstimateGas(ctx, callMsg)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", errutil.TryAddRevertReason(err)) return nil, fmt.Errorf("failed to estimate gas: %w", errutil.TryAddRevertReason(err))
} }
gasLimit = gas gasLimit = gas
} }
var sidecar *types.BlobTxSidecar
var blobHashes []common.Hash
if len(candidate.Blobs) > 0 {
if candidate.To == nil {
return nil, errors.New("blob txs cannot deploy contracts")
}
if sidecar, blobHashes, err = MakeSidecar(candidate.Blobs); err != nil {
return nil, fmt.Errorf("failed to make sidecar: %w", err)
}
}
var txMessage types.TxData var txMessage types.TxData
if sidecar != nil { if sidecar != nil {
if blobBaseFee == nil { if blobBaseFee == nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment