From 5a94a7725e87b54e9fd63b4ccbd3c63556f37247 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Mon, 8 Jan 2024 18:41:59 +0330 Subject: [PATCH] blobs should work in api methods --- internal/ethapi/api.go | 17 ++++++++++++++++ internal/ethapi/transaction_args.go | 31 ++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c0b28e4b69..8714f989d6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -55,6 +55,8 @@ import ( // allowed to produce in order to speed up calculations. const estimateGasErrorRatio = 0.015 +var errBlobTxNotSupported = errors.New("blob-tx not supported") + // EthereumAPI provides an API to access Ethereum related information. type EthereumAPI struct { b Backend @@ -468,11 +470,15 @@ func (s *PersonalAccountAPI) SendTransaction(ctx context.Context, args Transacti s.nonceLock.LockAddr(args.from()) defer s.nonceLock.UnlockAddr(args.from()) } + if args.BlobVersionedHashes != nil { + return common.Hash{}, errBlobTxNotSupported + } signed, err := s.signTransaction(ctx, &args, passwd) if err != nil { log.Warn("Failed transaction send attempt", "from", args.from(), "to", args.To, "value", args.Value.ToInt(), "err", err) return common.Hash{}, err } + 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) { 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 { 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 // value is capped by both `args.Gas` (if non-nil & non-zero) and the backend's RPCGasCap // 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) { bNrOrHash := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) if blockNrOrHash != nil { @@ -1809,6 +1819,9 @@ func (s *TransactionAPI) SendTransaction(ctx context.Context, args TransactionAr s.nonceLock.LockAddr(args.from()) defer s.nonceLock.UnlockAddr(args.from()) } + if args.BlobVersionedHashes != nil { + return common.Hash{}, errBlobTxNotSupported + } // Set some sanity defaults and terminate on failure 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 tx := args.toTransaction() + // TODO: fill in blob proofs, commitments data, err := tx.MarshalBinary() if err != nil { 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) { 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 { return nil, errors.New("nonce not specified") } diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index d88f6d3364..a62eb1821a 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rpc" + "github.com/holiman/uint256" ) // TransactionArgs represents the arguments to construct a new transaction @@ -273,9 +274,10 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (* gas = globalGasCap } var ( - gasPrice *big.Int - gasFeeCap *big.Int - gasTipCap *big.Int + gasPrice *big.Int + gasFeeCap *big.Int + gasTipCap *big.Int + blobGasFeeCap *big.Int ) if baseFee == nil { // 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) if args.Value != nil { value = args.Value.ToInt() @@ -326,6 +331,8 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (* GasTipCap: gasTipCap, Data: data, AccessList: accessList, + BlobGasFeeCap: blobGasFeeCap, + BlobHashes: args.BlobVersionedHashes, SkipAccountChecks: true, } return msg, nil @@ -336,6 +343,24 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (* func (args *TransactionArgs) toTransaction() *types.Transaction { var data types.TxData 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: al := types.AccessList{} if args.AccessList != nil {