mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
blobs should work in api methods
This commit is contained in:
parent
64956f846a
commit
5a94a7725e
2 changed files with 45 additions and 3 deletions
|
|
@ -55,6 +55,8 @@ import (
|
||||||
// allowed to produce in order to speed up calculations.
|
// allowed to produce in order to speed up calculations.
|
||||||
const estimateGasErrorRatio = 0.015
|
const estimateGasErrorRatio = 0.015
|
||||||
|
|
||||||
|
var errBlobTxNotSupported = errors.New("blob-tx not supported")
|
||||||
|
|
||||||
// EthereumAPI provides an API to access Ethereum related information.
|
// EthereumAPI provides an API to access Ethereum related information.
|
||||||
type EthereumAPI struct {
|
type EthereumAPI struct {
|
||||||
b Backend
|
b Backend
|
||||||
|
|
@ -468,11 +470,15 @@ func (s *PersonalAccountAPI) SendTransaction(ctx context.Context, args Transacti
|
||||||
s.nonceLock.LockAddr(args.from())
|
s.nonceLock.LockAddr(args.from())
|
||||||
defer s.nonceLock.UnlockAddr(args.from())
|
defer s.nonceLock.UnlockAddr(args.from())
|
||||||
}
|
}
|
||||||
|
if args.BlobVersionedHashes != nil {
|
||||||
|
return common.Hash{}, errBlobTxNotSupported
|
||||||
|
}
|
||||||
signed, err := s.signTransaction(ctx, &args, passwd)
|
signed, err := s.signTransaction(ctx, &args, passwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Failed transaction send attempt", "from", args.from(), "to", args.To, "value", args.Value.ToInt(), "err", err)
|
log.Warn("Failed transaction send attempt", "from", args.from(), "to", args.To, "value", args.Value.ToInt(), "err", err)
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return SubmitTransaction(ctx, s.b, signed)
|
return SubmitTransaction(ctx, s.b, signed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -492,6 +498,9 @@ func (s *PersonalAccountAPI) SignTransaction(ctx context.Context, args Transacti
|
||||||
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
|
if args.GasPrice == nil && (args.MaxFeePerGas == nil || args.MaxPriorityFeePerGas == nil) {
|
||||||
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
||||||
}
|
}
|
||||||
|
if args.BlobVersionedHashes != nil && args.MaxFeePerBlobGas == nil {
|
||||||
|
return nil, errors.New("missing maxFeePerBlobGas")
|
||||||
|
}
|
||||||
if args.Nonce == nil {
|
if args.Nonce == nil {
|
||||||
return nil, errors.New("nonce not specified")
|
return nil, errors.New("nonce not specified")
|
||||||
}
|
}
|
||||||
|
|
@ -1219,6 +1228,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr
|
||||||
// returns error if the transaction would revert or if there are unexpected failures. The returned
|
// returns error if the transaction would revert or if there are unexpected failures. The returned
|
||||||
// value is capped by both `args.Gas` (if non-nil & non-zero) and the backend's RPCGasCap
|
// value is capped by both `args.Gas` (if non-nil & non-zero) and the backend's RPCGasCap
|
||||||
// configuration (if non-zero).
|
// configuration (if non-zero).
|
||||||
|
// Note: Required blob gas is not computed in this method.
|
||||||
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) {
|
func (s *BlockChainAPI) EstimateGas(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride) (hexutil.Uint64, error) {
|
||||||
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
|
||||||
if blockNrOrHash != nil {
|
if blockNrOrHash != nil {
|
||||||
|
|
@ -1809,6 +1819,9 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr
|
||||||
s.nonceLock.LockAddr(args.from())
|
s.nonceLock.LockAddr(args.from())
|
||||||
defer s.nonceLock.UnlockAddr(args.from())
|
defer s.nonceLock.UnlockAddr(args.from())
|
||||||
}
|
}
|
||||||
|
if args.BlobVersionedHashes != nil {
|
||||||
|
return common.Hash{}, errBlobTxNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
// Set some sanity defaults and terminate on failure
|
// Set some sanity defaults and terminate on failure
|
||||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||||
|
|
@ -1834,6 +1847,7 @@ func (s *TransactionAPI) FillTransaction(ctx context.Context, args TransactionAr
|
||||||
}
|
}
|
||||||
// Assemble the transaction and obtain rlp
|
// Assemble the transaction and obtain rlp
|
||||||
tx := args.toTransaction()
|
tx := args.toTransaction()
|
||||||
|
// TODO: fill in blob proofs, commitments
|
||||||
data, err := tx.MarshalBinary()
|
data, err := tx.MarshalBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -1892,6 +1906,9 @@ func (s *TransactionAPI) SignTransaction(ctx context.Context, args TransactionAr
|
||||||
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
|
if args.GasPrice == nil && (args.MaxPriorityFeePerGas == nil || args.MaxFeePerGas == nil) {
|
||||||
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
return nil, errors.New("missing gasPrice or maxFeePerGas/maxPriorityFeePerGas")
|
||||||
}
|
}
|
||||||
|
if args.BlobVersionedHashes != nil && args.MaxFeePerBlobGas == nil {
|
||||||
|
return nil, errors.New("missing maxFeePerBlobGas")
|
||||||
|
}
|
||||||
if args.Nonce == nil {
|
if args.Nonce == nil {
|
||||||
return nil, errors.New("nonce not specified")
|
return nil, errors.New("nonce not specified")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
"github.com/holiman/uint256"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TransactionArgs represents the arguments to construct a new transaction
|
// TransactionArgs represents the arguments to construct a new transaction
|
||||||
|
|
@ -273,9 +274,10 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
|
||||||
gas = globalGasCap
|
gas = globalGasCap
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
gasPrice *big.Int
|
gasPrice *big.Int
|
||||||
gasFeeCap *big.Int
|
gasFeeCap *big.Int
|
||||||
gasTipCap *big.Int
|
gasTipCap *big.Int
|
||||||
|
blobGasFeeCap *big.Int
|
||||||
)
|
)
|
||||||
if baseFee == nil {
|
if baseFee == nil {
|
||||||
// If there's no basefee, then it must be a non-1559 execution
|
// If there's no basefee, then it must be a non-1559 execution
|
||||||
|
|
@ -307,6 +309,9 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if args.MaxFeePerBlobGas != nil {
|
||||||
|
blobGasFeeCap = args.MaxFeePerBlobGas.ToInt()
|
||||||
|
}
|
||||||
value := new(big.Int)
|
value := new(big.Int)
|
||||||
if args.Value != nil {
|
if args.Value != nil {
|
||||||
value = args.Value.ToInt()
|
value = args.Value.ToInt()
|
||||||
|
|
@ -326,6 +331,8 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
|
||||||
GasTipCap: gasTipCap,
|
GasTipCap: gasTipCap,
|
||||||
Data: data,
|
Data: data,
|
||||||
AccessList: accessList,
|
AccessList: accessList,
|
||||||
|
BlobGasFeeCap: blobGasFeeCap,
|
||||||
|
BlobHashes: args.BlobVersionedHashes,
|
||||||
SkipAccountChecks: true,
|
SkipAccountChecks: true,
|
||||||
}
|
}
|
||||||
return msg, nil
|
return msg, nil
|
||||||
|
|
@ -336,6 +343,24 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (*
|
||||||
func (args *TransactionArgs) toTransaction() *types.Transaction {
|
func (args *TransactionArgs) toTransaction() *types.Transaction {
|
||||||
var data types.TxData
|
var data types.TxData
|
||||||
switch {
|
switch {
|
||||||
|
case args.BlobVersionedHashes != nil:
|
||||||
|
al := types.AccessList{}
|
||||||
|
if args.AccessList != nil {
|
||||||
|
al = *args.AccessList
|
||||||
|
}
|
||||||
|
data = &types.BlobTx{
|
||||||
|
To: *args.To,
|
||||||
|
ChainID: uint256.MustFromBig((*big.Int)(args.ChainID)),
|
||||||
|
Nonce: uint64(*args.Nonce),
|
||||||
|
Gas: uint64(*args.Gas),
|
||||||
|
GasFeeCap: uint256.MustFromBig((*big.Int)(args.MaxFeePerGas)),
|
||||||
|
GasTipCap: uint256.MustFromBig((*big.Int)(args.MaxPriorityFeePerGas)),
|
||||||
|
Value: uint256.MustFromBig((*big.Int)(args.Value)),
|
||||||
|
Data: args.data(),
|
||||||
|
AccessList: al,
|
||||||
|
BlobHashes: args.BlobVersionedHashes,
|
||||||
|
BlobFeeCap: uint256.MustFromBig((*big.Int)(args.MaxFeePerBlobGas)),
|
||||||
|
}
|
||||||
case args.MaxFeePerGas != nil:
|
case args.MaxFeePerGas != nil:
|
||||||
al := types.AccessList{}
|
al := types.AccessList{}
|
||||||
if args.AccessList != nil {
|
if args.AccessList != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue