From 5ebd0ae804152810c2b4dff3c5a27eb4244450a2 Mon Sep 17 00:00:00 2001 From: Andrew Ashikhmin <34320705+yperbasis@users.noreply.github.com> Date: Mon, 27 Jan 2025 15:08:37 +0100 Subject: [PATCH] Unify jsonrpc.RPCTransaction & ethapi.RPCTransaction (#13575) `RPCTransaction` was duplicated between `jsonrpc` & `ethapi`. The `jsonrpc` version was more up-to-date (e.g. it contained EIP-7702 logic), so I left the newer version only and moved it to `ethapi`. See also https://github.com/erigontech/erigon/discussions/13371. --- cmd/devnet/blocks/checks.go | 4 +- cmd/devnet/blocks/waiter.go | 8 +- cmd/devnet/contracts/util.go | 4 +- cmd/devnet/requests/block.go | 8 +- cmd/devnet/requests/nopgenerator.go | 3 +- cmd/devnet/requests/request_generator.go | 3 +- cmd/devnet/requests/transaction.go | 8 +- cmd/devnet/services/polygon/proofgenerator.go | 4 +- .../services/polygon/proofgenerator_test.go | 6 +- cmd/evm/internal/t8ntool/transition.go | 6 +- turbo/adapter/ethapi/api.go | 744 +++--------------- turbo/jsonrpc/eth_api.go | 161 +--- turbo/jsonrpc/eth_txs.go | 30 +- turbo/jsonrpc/otterscan_api.go | 2 +- turbo/jsonrpc/otterscan_search_trace.go | 10 +- turbo/jsonrpc/otterscan_search_v3.go | 7 +- turbo/jsonrpc/txpool_api.go | 41 +- 17 files changed, 171 insertions(+), 878 deletions(-) diff --git a/cmd/devnet/blocks/checks.go b/cmd/devnet/blocks/checks.go index cf4fa0740d8..ad6ec6387dd 100644 --- a/cmd/devnet/blocks/checks.go +++ b/cmd/devnet/blocks/checks.go @@ -22,11 +22,11 @@ import ( "github.com/erigontech/erigon/cmd/devnet/devnet" "github.com/erigontech/erigon/cmd/devnet/requests" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) var CompletionChecker = BlockHandlerFunc( - func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *jsonrpc.RPCTransaction) error { + func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *ethapi.RPCTransaction) error { traceResults, err := node.TraceTransaction(transaction.Hash) if err != nil { diff --git a/cmd/devnet/blocks/waiter.go b/cmd/devnet/blocks/waiter.go index 397adc648b7..9d04f14ee83 100644 --- a/cmd/devnet/blocks/waiter.go +++ b/cmd/devnet/blocks/waiter.go @@ -26,16 +26,16 @@ import ( "github.com/erigontech/erigon/cmd/devnet/requests" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/rpc" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) type BlockHandler interface { - Handle(ctx context.Context, node devnet.Node, block *requests.Block, transaction *jsonrpc.RPCTransaction) error + Handle(ctx context.Context, node devnet.Node, block *requests.Block, transaction *ethapi.RPCTransaction) error } -type BlockHandlerFunc func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *jsonrpc.RPCTransaction) error +type BlockHandlerFunc func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *ethapi.RPCTransaction) error -func (f BlockHandlerFunc) Handle(ctx context.Context, node devnet.Node, block *requests.Block, transaction *jsonrpc.RPCTransaction) error { +func (f BlockHandlerFunc) Handle(ctx context.Context, node devnet.Node, block *requests.Block, transaction *ethapi.RPCTransaction) error { return f(ctx, node, block, transaction) } diff --git a/cmd/devnet/contracts/util.go b/cmd/devnet/contracts/util.go index c1dea2037b9..c6e5dfc49dd 100644 --- a/cmd/devnet/contracts/util.go +++ b/cmd/devnet/contracts/util.go @@ -27,7 +27,7 @@ import ( "github.com/erigontech/erigon/cmd/devnet/requests" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/rpc" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) func TransactOpts(ctx context.Context, sender libcommon.Address) (*bind.TransactOpts, error) { @@ -90,7 +90,7 @@ func DeployWithOps[C any](ctx context.Context, auth *bind.TransactOpts, deploy f } var DeploymentChecker = blocks.BlockHandlerFunc( - func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *jsonrpc.RPCTransaction) error { + func(ctx context.Context, node devnet.Node, block *requests.Block, transaction *ethapi.RPCTransaction) error { if err := blocks.CompletionChecker(ctx, node, block, transaction); err != nil { return nil } diff --git a/cmd/devnet/requests/block.go b/cmd/devnet/requests/block.go index 681c94087bd..d897e7ac878 100644 --- a/cmd/devnet/requests/block.go +++ b/cmd/devnet/requests/block.go @@ -27,7 +27,7 @@ import ( "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/rpc" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) type BlockNumber string @@ -86,7 +86,7 @@ func (b *BlockWithTxHashes) UnmarshalJSON(input []byte) error { type Block struct { BlockWithTxHashes - Transactions []*jsonrpc.RPCTransaction `json:"transactions"` + Transactions []*ethapi.RPCTransaction `json:"transactions"` } func (b *Block) UnmarshalJSON(input []byte) error { @@ -96,8 +96,8 @@ func (b *Block) UnmarshalJSON(input []byte) error { } var bd struct { - Hash libcommon.Hash `json:"hash"` - Transactions []*jsonrpc.RPCTransaction `json:"transactions"` + Hash libcommon.Hash `json:"hash"` + Transactions []*ethapi.RPCTransaction `json:"transactions"` } if err := json.Unmarshal(input, &bd); err != nil { return err diff --git a/cmd/devnet/requests/nopgenerator.go b/cmd/devnet/requests/nopgenerator.go index a2514f548b8..dc175029ba9 100644 --- a/cmd/devnet/requests/nopgenerator.go +++ b/cmd/devnet/requests/nopgenerator.go @@ -28,7 +28,6 @@ import ( "github.com/erigontech/erigon/p2p" "github.com/erigontech/erigon/rpc" "github.com/erigontech/erigon/turbo/adapter/ethapi" - "github.com/erigontech/erigon/turbo/jsonrpc" ) var ErrNotImplemented = errors.New("not implemented") @@ -52,7 +51,7 @@ func (n NopRequestGenerator) GetBlockByNumber(ctx context.Context, blockNum rpc. return nil, ErrNotImplemented } -func (n NopRequestGenerator) GetTransactionByHash(hash libcommon.Hash) (*jsonrpc.RPCTransaction, error) { +func (n NopRequestGenerator) GetTransactionByHash(hash libcommon.Hash) (*ethapi.RPCTransaction, error) { return nil, ErrNotImplemented } diff --git a/cmd/devnet/requests/request_generator.go b/cmd/devnet/requests/request_generator.go index 56d5d4e6016..410918548d3 100644 --- a/cmd/devnet/requests/request_generator.go +++ b/cmd/devnet/requests/request_generator.go @@ -40,7 +40,6 @@ import ( "github.com/erigontech/erigon/p2p" "github.com/erigontech/erigon/rpc" "github.com/erigontech/erigon/turbo/adapter/ethapi" - "github.com/erigontech/erigon/turbo/jsonrpc" ) type callResult struct { @@ -74,7 +73,7 @@ type RequestGenerator interface { GetBalance(address libcommon.Address, blockRef rpc.BlockReference) (*big.Int, error) AdminNodeInfo() (p2p.NodeInfo, error) GetBlockByNumber(ctx context.Context, blockNum rpc.BlockNumber, withTxs bool) (*Block, error) - GetTransactionByHash(hash libcommon.Hash) (*jsonrpc.RPCTransaction, error) + GetTransactionByHash(hash libcommon.Hash) (*ethapi.RPCTransaction, error) GetTransactionReceipt(ctx context.Context, hash libcommon.Hash) (*types.Receipt, error) TraceTransaction(hash libcommon.Hash) ([]TransactionTrace, error) GetTransactionCount(address libcommon.Address, blockRef rpc.BlockReference) (*big.Int, error) diff --git a/cmd/devnet/requests/transaction.go b/cmd/devnet/requests/transaction.go index 01c5b9ec25c..f576503bef5 100644 --- a/cmd/devnet/requests/transaction.go +++ b/cmd/devnet/requests/transaction.go @@ -23,15 +23,13 @@ import ( "fmt" "math/big" - "github.com/erigontech/erigon-lib/common/hexutil" - ethereum "github.com/erigontech/erigon" libcommon "github.com/erigontech/erigon-lib/common" + "github.com/erigontech/erigon-lib/common/hexutil" "github.com/erigontech/erigon-lib/common/hexutility" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/rpc" "github.com/erigontech/erigon/turbo/adapter/ethapi" - "github.com/erigontech/erigon/turbo/jsonrpc" ) type ETHEstimateGas struct { @@ -163,8 +161,8 @@ func (reqGen *requestGenerator) SendTransaction(signedTx types.Transaction) (lib return result, nil } -func (req *requestGenerator) GetTransactionByHash(hash libcommon.Hash) (*jsonrpc.RPCTransaction, error) { - var result jsonrpc.RPCTransaction +func (req *requestGenerator) GetTransactionByHash(hash libcommon.Hash) (*ethapi.RPCTransaction, error) { + var result ethapi.RPCTransaction if err := req.rpcCall(context.Background(), &result, Methods.ETHGetTransactionByHash, hash); err != nil { return nil, err diff --git a/cmd/devnet/services/polygon/proofgenerator.go b/cmd/devnet/services/polygon/proofgenerator.go index 1ce9317b941..a81064404ce 100644 --- a/cmd/devnet/services/polygon/proofgenerator.go +++ b/cmd/devnet/services/polygon/proofgenerator.go @@ -41,7 +41,7 @@ import ( "github.com/erigontech/erigon/core/types" bortypes "github.com/erigontech/erigon/polygon/bor/types" "github.com/erigontech/erigon/rpc" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) var ErrTokenIndexOutOfRange = errors.New("index is grater than the number of tokens in transaction") @@ -122,7 +122,7 @@ func (pg *ProofGenerator) getChainBlockInfo(ctx context.Context, burnTxHash libc var wg sync.WaitGroup var lastChild *big.Int - var burnTransaction *jsonrpc.RPCTransaction + var burnTransaction *ethapi.RPCTransaction var err [2]error // err group diff --git a/cmd/devnet/services/polygon/proofgenerator_test.go b/cmd/devnet/services/polygon/proofgenerator_test.go index aad808047f5..f063872b6b0 100644 --- a/cmd/devnet/services/polygon/proofgenerator_test.go +++ b/cmd/devnet/services/polygon/proofgenerator_test.go @@ -50,7 +50,7 @@ import ( "github.com/erigontech/erigon/params" "github.com/erigontech/erigon/polygon/bor" "github.com/erigontech/erigon/rpc" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" "github.com/erigontech/erigon/turbo/services" "github.com/erigontech/erigon/turbo/stages/mock" "github.com/erigontech/erigon/turbo/transactions" @@ -111,11 +111,11 @@ func (rg *requestGenerator) GetBlockByNumber(ctx context.Context, blockNum rpc.B if bn := int(blockNum.Uint64()); bn < len(rg.chain.Blocks) { block := rg.chain.Blocks[bn] - transactions := make([]*jsonrpc.RPCTransaction, len(block.Transactions())) + transactions := make([]*ethapi.RPCTransaction, len(block.Transactions())) for i, txn := range block.Transactions() { rg.txBlockMap[txn.Hash()] = block - transactions[i] = jsonrpc.NewRPCTransaction(txn, block.Hash(), blockNum.Uint64(), uint64(i), block.BaseFee()) + transactions[i] = ethapi.NewRPCTransaction(txn, block.Hash(), blockNum.Uint64(), uint64(i), block.BaseFee()) } return &requests.Block{ diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 7821505ab1d..e78d16e5c37 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -55,7 +55,7 @@ import ( "github.com/erigontech/erigon/eth/consensuschain" trace_logger "github.com/erigontech/erigon/eth/tracers/logger" "github.com/erigontech/erigon/tests" - "github.com/erigontech/erigon/turbo/jsonrpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) const ( @@ -371,7 +371,7 @@ func (t *txWithKey) UnmarshalJSON(input []byte) error { } // Now, read the transaction itself - var txJson jsonrpc.RPCTransaction + var txJson ethapi.RPCTransaction if err := json.Unmarshal(input, &txJson); err != nil { return err @@ -386,7 +386,7 @@ func (t *txWithKey) UnmarshalJSON(input []byte) error { return nil } -func getTransaction(txJson jsonrpc.RPCTransaction) (types.Transaction, error) { +func getTransaction(txJson ethapi.RPCTransaction) (types.Transaction, error) { gasPrice, value := uint256.NewInt(0), uint256.NewInt(0) var overflow bool var chainId *uint256.Int diff --git a/turbo/adapter/ethapi/api.go b/turbo/adapter/ethapi/api.go index 671284325b1..8026f9b20e7 100644 --- a/turbo/adapter/ethapi/api.go +++ b/turbo/adapter/ethapi/api.go @@ -346,7 +346,7 @@ func RPCMarshalBlockExDeprecated(block *types.Block, inclTx bool, fullTx bool, b if borTx != nil { if fullTx { - transactions = append(transactions, newRPCBorTransaction(borTx, borTxHash, block.Hash(), block.NumberU64(), uint64(len(txs)), block.BaseFee())) + transactions = append(transactions, NewRPCBorTransaction(borTx, borTxHash, block.Hash(), block.NumberU64(), uint64(len(txs)), nil /* chainID */)) } else { transactions = append(transactions, borTxHash) } @@ -370,98 +370,97 @@ func RPCMarshalBlockExDeprecated(block *types.Block, inclTx bool, fullTx bool, b // RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction type RPCTransaction struct { - BlockHash *libcommon.Hash `json:"blockHash"` - BlockNumber *hexutil.Big `json:"blockNumber"` - From libcommon.Address `json:"from"` - Gas hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice,omitempty"` - Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` - FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` - MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` - Hash libcommon.Hash `json:"hash"` - Input hexutility.Bytes `json:"input"` - Nonce hexutil.Uint64 `json:"nonce"` - To *libcommon.Address `json:"to"` - TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` - Value *hexutil.Big `json:"value"` - Type hexutil.Uint64 `json:"type"` - Accesses *types.AccessList `json:"accessList,omitempty"` - ChainID *hexutil.Big `json:"chainId,omitempty"` - V *hexutil.Big `json:"v"` - YParity *hexutil.Big `json:"yParity,omitempty"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` - - BlobVersionedHashes []libcommon.Hash `json:"blobVersionedHashes,omitempty"` -} - -// newRPCTransaction returns a transaction that will serialize to the RPC + BlockHash *libcommon.Hash `json:"blockHash"` + BlockNumber *hexutil.Big `json:"blockNumber"` + From libcommon.Address `json:"from"` + Gas hexutil.Uint64 `json:"gas"` + GasPrice *hexutil.Big `json:"gasPrice,omitempty"` + Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` + FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` + Hash libcommon.Hash `json:"hash"` + Input hexutility.Bytes `json:"input"` + Nonce hexutil.Uint64 `json:"nonce"` + To *libcommon.Address `json:"to"` + TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` + Value *hexutil.Big `json:"value"` + Type hexutil.Uint64 `json:"type"` + Accesses *types.AccessList `json:"accessList,omitempty"` + ChainID *hexutil.Big `json:"chainId,omitempty"` + MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` + BlobVersionedHashes []libcommon.Hash `json:"blobVersionedHashes,omitempty"` + Authorizations *[]types.JsonAuthorization `json:"authorizationList,omitempty"` + V *hexutil.Big `json:"v"` + YParity *hexutil.Big `json:"yParity,omitempty"` + R *hexutil.Big `json:"r"` + S *hexutil.Big `json:"s"` +} + +// NewRPCTransaction returns a transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { +func NewRPCTransaction(txn types.Transaction, blockHash libcommon.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { // Determine the signer. For replay-protected transactions, use the most permissive // signer, because we assume that signers are backwards-compatible with old // transactions. For non-protected transactions, the homestead signer is used // because the return value of ChainId is zero for those transactions. chainId := uint256.NewInt(0) result := &RPCTransaction{ - Type: hexutil.Uint64(tx.Type()), - Gas: hexutil.Uint64(tx.GetGas()), - Hash: tx.Hash(), - Input: hexutility.Bytes(tx.GetData()), - Nonce: hexutil.Uint64(tx.GetNonce()), - To: tx.GetTo(), - Value: (*hexutil.Big)(tx.GetValue().ToBig()), + Type: hexutil.Uint64(txn.Type()), + Gas: hexutil.Uint64(txn.GetGas()), + Hash: txn.Hash(), + Input: hexutility.Bytes(txn.GetData()), + Nonce: hexutil.Uint64(txn.GetNonce()), + To: txn.GetTo(), + Value: (*hexutil.Big)(txn.GetValue().ToBig()), + } + if t, ok := txn.(*types.BlobTxWrapper); ok { + txn = &t.Tx } - switch t := tx.(type) { - case *types.LegacyTx: - chainId = types.DeriveChainId(&t.V) + + v, r, s := txn.RawSignatureValues() + result.V = (*hexutil.Big)(v.ToBig()) + result.R = (*hexutil.Big)(r.ToBig()) + result.S = (*hexutil.Big)(s.ToBig()) + + if txn.Type() == types.LegacyTxType { + chainId = types.DeriveChainId(v) // if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included if !chainId.IsZero() { result.ChainID = (*hexutil.Big)(chainId.ToBig()) } - result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig()) - result.V = (*hexutil.Big)(t.V.ToBig()) - result.R = (*hexutil.Big)(t.R.ToBig()) - result.S = (*hexutil.Big)(t.S.ToBig()) - case *types.AccessListTx: - chainId.Set(t.ChainID) - result.ChainID = (*hexutil.Big)(chainId.ToBig()) - result.GasPrice = (*hexutil.Big)(t.GasPrice.ToBig()) - result.YParity = (*hexutil.Big)(t.V.ToBig()) - result.V = (*hexutil.Big)(t.V.ToBig()) - result.R = (*hexutil.Big)(t.R.ToBig()) - result.S = (*hexutil.Big)(t.S.ToBig()) - result.Accesses = &t.AccessList - case *types.DynamicFeeTransaction: - chainId.Set(t.ChainID) - result.ChainID = (*hexutil.Big)(chainId.ToBig()) - result.Tip = (*hexutil.Big)(t.Tip.ToBig()) - result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig()) - result.YParity = (*hexutil.Big)(t.V.ToBig()) - result.V = (*hexutil.Big)(t.V.ToBig()) - result.R = (*hexutil.Big)(t.R.ToBig()) - result.S = (*hexutil.Big)(t.S.ToBig()) - result.Accesses = &t.AccessList - // if the transaction has been mined, compute the effective gas price - result.GasPrice = computeGasPrice(tx, blockHash, baseFee) - case *types.BlobTx: - chainId.Set(t.ChainID) + result.GasPrice = (*hexutil.Big)(txn.GetPrice().ToBig()) + } else { + chainId.Set(txn.GetChainID()) result.ChainID = (*hexutil.Big)(chainId.ToBig()) - result.Tip = (*hexutil.Big)(t.Tip.ToBig()) - result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig()) - result.YParity = (*hexutil.Big)(t.V.ToBig()) - result.V = (*hexutil.Big)(t.V.ToBig()) - result.R = (*hexutil.Big)(t.R.ToBig()) - result.S = (*hexutil.Big)(t.S.ToBig()) - result.Accesses = &t.AccessList - // if the transaction has been mined, compute the effective gas price - result.GasPrice = computeGasPrice(tx, blockHash, baseFee) - result.MaxFeePerBlobGas = (*hexutil.Big)(t.MaxFeePerBlobGas.ToBig()) - result.BlobVersionedHashes = t.GetBlobHashes() + result.YParity = (*hexutil.Big)(v.ToBig()) + acl := txn.GetAccessList() + result.Accesses = &acl + + if txn.Type() == types.AccessListTxType { + result.GasPrice = (*hexutil.Big)(txn.GetPrice().ToBig()) + } else { + result.GasPrice = computeGasPrice(txn, blockHash, baseFee) + result.Tip = (*hexutil.Big)(txn.GetTip().ToBig()) + result.FeeCap = (*hexutil.Big)(txn.GetFeeCap().ToBig()) + } + + if txn.Type() == types.BlobTxType { + txn.GetBlobGas() + blobTx := txn.(*types.BlobTx) + result.MaxFeePerBlobGas = (*hexutil.Big)(blobTx.MaxFeePerBlobGas.ToBig()) + result.BlobVersionedHashes = blobTx.BlobVersionedHashes + } else if txn.Type() == types.SetCodeTxType { + setCodeTx := txn.(*types.SetCodeTransaction) + ats := make([]types.JsonAuthorization, len(setCodeTx.GetAuthorizations())) + for i, a := range setCodeTx.GetAuthorizations() { + ats[i] = types.JsonAuthorization{}.FromAuthorization(a) + } + result.Authorizations = &ats + } } + signer := types.LatestSignerForChainID(chainId.ToBig()) var err error - result.From, err = tx.Sender(*signer) + result.From, err = txn.Sender(*signer) if err != nil { log.Warn("sender recovery", "err", err) } @@ -473,35 +472,37 @@ func newRPCTransaction(tx types.Transaction, blockHash libcommon.Hash, blockNumb return result } -func computeGasPrice(tx types.Transaction, blockHash libcommon.Hash, baseFee *big.Int) *hexutil.Big { - if baseFee != nil && blockHash != (libcommon.Hash{}) { +func computeGasPrice(txn types.Transaction, blockHash libcommon.Hash, baseFee *big.Int) *hexutil.Big { + fee, overflow := uint256.FromBig(baseFee) + if fee != nil && !overflow && blockHash != (libcommon.Hash{}) { // price = min(tip + baseFee, gasFeeCap) - price := math.BigMin(new(big.Int).Add(tx.GetTip().ToBig(), baseFee), tx.GetFeeCap().ToBig()) - return (*hexutil.Big)(price) + price := math.Min256(new(uint256.Int).Add(txn.GetTip(), fee), txn.GetFeeCap()) + return (*hexutil.Big)(price.ToBig()) } return nil } -// newRPCBorTransaction returns a Bor transaction that will serialize to the RPC +// NewRPCBorTransaction returns a Bor transaction that will serialize to the RPC // representation, with the given location metadata set (if available). -func newRPCBorTransaction(opaqueTx types.Transaction, txHash libcommon.Hash, blockHash libcommon.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { - tx := opaqueTx.(*types.LegacyTx) +func NewRPCBorTransaction(opaqueTxn types.Transaction, txHash libcommon.Hash, blockHash libcommon.Hash, blockNumber uint64, index uint64, chainId *big.Int) *RPCTransaction { + txn := opaqueTxn.(*types.LegacyTx) result := &RPCTransaction{ - Type: hexutil.Uint64(tx.Type()), + Type: hexutil.Uint64(txn.Type()), ChainID: (*hexutil.Big)(new(big.Int)), - GasPrice: (*hexutil.Big)(tx.GasPrice.ToBig()), - Gas: hexutil.Uint64(tx.GetGas()), + GasPrice: (*hexutil.Big)(txn.GasPrice.ToBig()), + Gas: hexutil.Uint64(txn.GetGas()), Hash: txHash, - Input: hexutility.Bytes(tx.GetData()), - Nonce: hexutil.Uint64(tx.GetNonce()), + Input: hexutility.Bytes(txn.GetData()), + Nonce: hexutil.Uint64(txn.GetNonce()), From: libcommon.Address{}, - To: tx.GetTo(), - Value: (*hexutil.Big)(tx.GetValue().ToBig()), + To: txn.GetTo(), + Value: (*hexutil.Big)(txn.GetValue().ToBig()), V: (*hexutil.Big)(big.NewInt(0)), R: (*hexutil.Big)(big.NewInt(0)), S: (*hexutil.Big)(big.NewInt(0)), } if blockHash != (libcommon.Hash{}) { + result.ChainID = (*hexutil.Big)(chainId) result.BlockHash = &blockHash result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber)) result.TransactionIndex = (*hexutil.Uint64)(&index) @@ -509,566 +510,7 @@ func newRPCBorTransaction(opaqueTx types.Transaction, txHash libcommon.Hash, blo return result } -/* -// newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation -func newRPCPendingTransaction(tx types.Transaction) *RPCTransaction { - return newRPCTransaction(tx, libcommon.Hash{}, 0, 0) -} -*/ - -/* -// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransaction { - txs := b.Transactions() - if index >= uint64(len(txs)) { - return nil - } - return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee()) -} -*/ - // newRPCTransactionFromBlockAndTxGivenIndex returns a transaction that will serialize to the RPC representation. func newRPCTransactionFromBlockAndTxGivenIndex(b *types.Block, txn types.Transaction, index uint64) *RPCTransaction { - return newRPCTransaction(txn, b.Hash(), b.NumberU64(), index, b.BaseFee()) -} - -/* -// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index. -func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.Bytes { - txs := b.Transactions() - if index >= uint64(len(txs)) { - return nil - } - var blob bytes.Buffer - if txs[index].Type() != types.LegacyTxType { - if err := blob.WriteByte(txs[index].Type()); err != nil { - panic(err) - } - } - if err := rlp.Encode(&blob, txs[index]); err != nil { - panic(err) - } - return blob.Bytes() -} -*/ - -/* -// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockHash(b *types.Block, hash libcommon.Hash) *RPCTransaction { - for idx, txn := range b.Transactions() { - if tx.Hash() == hash { - return newRPCTransactionFromBlockIndex(b, uint64(idx)) - } - } - return nil -} -*/ - -/* -// PublicTransactionPoolAPI exposes methods for the RPC interface -type PublicTransactionPoolAPI struct { - b Backend - nonceLock *AddrLocker - signer *types.Signer -} - -// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool. -func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI { - // The signer used by the API should always be the 'latest' known one because we expect - // signers to be backwards-compatible with old transactions. - signer := types.LatestSigner(b.ChainConfig()) - return &PublicTransactionPoolAPI{b, nonceLock, signer} -} - -// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number. -func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint { - if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { - n := hexutil.Uint(len(block.Transactions())) - return &n - } - return nil -} - -// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash. -func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash libcommon.Hash) *hexutil.Uint { - if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { - n := hexutil.Uint(len(block.Transactions())) - return &n - } - return nil -} - -// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index. -func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction { - if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index)) - } - return nil -} - -// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index. -func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash libcommon.Hash, index hexutil.Uint) *RPCTransaction { - if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index)) - } - return nil -} - -// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index. -func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) hexutil.Bytes { - if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { - return newRPCRawTransactionFromBlockIndex(block, uint64(index)) - } - return nil -} - -// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index. -func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash libcommon.Hash, index hexutil.Uint) hexutil.Bytes { - if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { - return newRPCRawTransactionFromBlockIndex(block, uint64(index)) - } - return nil -} - -// GetTransactionCount returns the number of transactions the given address has sent for the given block number -func (s *PublicTransactionPoolAPI) GetTransactionCount(ctx context.Context, address libcommon.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Uint64, error) { - // Ask transaction pool for the nonce which includes pending transactions - if blockNr, ok := blockNrOrHash.Number(); ok && blockNr == rpc.PendingBlockNumber { - nonce, err := s.b.GetPoolNonce(ctx, address) - if err != nil { - return nil, err - } - return (*hexutil.Uint64)(&nonce), nil - } - // Resolve block number and use its state to ask for the nonce - state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) - if state == nil || err != nil { - return nil, err - } - nonce := state.GetNonce(address) - return (*hexutil.Uint64)(&nonce), state.Error() -} - -// GetTransactionByHash returns the transaction for the given hash -func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, hash libcommon.Hash) (*RPCTransaction, error) { - // Try to return an already finalized transaction - tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash) - if err != nil { - return nil, err - } - if txn != nil { - return newRPCTransaction(tx, blockHash, blockNumber, index), nil - } - // No finalized transaction, try to retrieve it from the pool - if txn := s.b.GetPoolTransaction(hash); txn != nil { - return newRPCPendingTransaction(tx), nil - } - - // Transaction unknown, return as such - return nil, nil -} - -// GetRawTransactionByHash returns the bytes of the transaction for the given hash. -func (s *PublicTransactionPoolAPI) GetRawTransactionByHash(ctx context.Context, hash libcommon.Hash) (hexutil.Bytes, error) { - // Retrieve a finalized transaction, or a pooled otherwise - tx, _, _, _, err := s.b.GetTransaction(ctx, hash) - if err != nil { - return nil, err - } - if txn == nil { - if txn = s.b.GetPoolTransaction(hash); txn == nil { - // Transaction not found anywhere, abort - return nil, nil - } - } - // Serialize to RLP and return - var blob bytes.Buffer - if tx.Type() != types.LegacyTxType { - if err := blob.WriteByte(tx.Type()); err != nil { - return nil, err - } - } - if err := rlp.Encode(&blob, tx); err != nil { - return nil, err - } - return blob.Bytes(), nil -} - -// GetTransactionReceipt returns the transaction receipt for the given transaction hash. -func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash libcommon.Hash) (map[string]interface{}, error) { - tx, blockHash, blockNumber, index, err := s.b.GetTransaction(ctx, hash) - if err != nil { - return nil, nil - } - receipts, err := s.b.GetReceipts(ctx, blockHash) - if err != nil { - return nil, err - } - if len(receipts) <= int(index) { - return nil, nil - } - receipt := receipts[index] - - // Derive the sender. - signer := types.MakeSigner(s.b.ChainConfig(), blockNumber) - from, _ := tx.Sender(*signer) - - fields := map[string]interface{}{ - "blockHash": blockHash, - "blockNumber": hexutil.Uint64(blockNumber), - "transactionHash": hash, - "transactionIndex": hexutil.Uint64(index), - "from": from, - "to": tx.GetTo(), - "gasUsed": hexutil.Uint64(receipt.GasUsed), - "cumulativeGasUsed": hexutil.Uint64(receipt.CumulativeGasUsed), - "contractAddress": nil, - "logs": receipt.Logs, - "logsBloom": receipt.Bloom, - "type": hexutil.Uint(tx.Type()), - } - - // Assign receipt status or post state. - if len(receipt.PostState) > 0 { - fields["root"] = hexutil.Bytes(receipt.PostState) - } else { - fields["status"] = hexutil.Uint(receipt.Status) - } - if receipt.Logs == nil { - fields["logs"] = [][]*types.Log{} - } - // If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation - if receipt.ContractAddress != (libcommon.Address{}) { - fields["contractAddress"] = receipt.ContractAddress - } - return fields, nil -} - -// SendTxArgs represents the arguments to submit a new transaction into the transaction pool. -type SendTxArgs struct { - From libcommon.Address `json:"from"` - To *libcommon.Address `json:"to"` - Gas *hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice"` - MaxPriorityFeePerGas *hexutil.Big `json:"tip"` - MaxFeePerGas *hexutil.Big `json:"feeCap"` - Value *hexutil.Big `json:"value"` - Nonce *hexutil.Uint64 `json:"nonce"` - // We accept "data" and "input" for backwards-compatibility reasons. "input" is the - // newer name and should be preferred by clients. - Data *hexutil.Bytes `json:"data"` - Input *hexutil.Bytes `json:"input"` - - // For non-legacy transactions - AccessList *types.AccessList `json:"accessList,omitempty"` - ChainID *hexutil.Big `json:"chainId,omitempty"` -} - -// setDefaults fills in default values for unspecified txn fields. -func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error { - if args.GasPrice == nil { - price, err := b.SuggestPrice(ctx) - if err != nil { - return err - } - args.GasPrice = (*hexutil.Big)(price) - } - if args.Value == nil { - args.Value = new(hexutil.Big) - } - if args.Nonce == nil { - nonce, err := b.GetPoolNonce(ctx, args.From) - if err != nil { - return err - } - args.Nonce = (*hexutil.Uint64)(&nonce) - } - if args.Data != nil && args.Input != nil && !bytes.Equal(*args.Data, *args.Input) { - return errors.New(`both "data" and "input" are set and not equal. Please use "input" to pass transaction call data`) - } - if args.To == nil { - // Contract creation - var input []byte - if args.Data != nil { - input = *args.Data - } else if args.Input != nil { - input = *args.Input - } - if len(input) == 0 { - return errors.New(`contract creation without any data provided`) - } - } - - // Estimate the gas usage if necessary. - if args.Gas == nil { - // For backwards-compatibility reason, we try both input and data - // but input is preferred. - input := args.Input - if input == nil { - input = args.Data - } - callArgs := CallArgs{ - From: &args.From, // From shouldn't be nil - To: args.To, - GasPrice: args.GasPrice, - Value: args.Value, - Data: input, - AccessList: args.AccessList, - } - pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) - estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, b.RPCGasCap()) - if err != nil { - return err - } - args.Gas = &estimated - log.Trace("Estimate gas usage automatically", "gas", args.Gas) - } - if args.ChainID == nil { - id := (*hexutil.Big)(b.ChainConfig().ChainID) - args.ChainID = id - } - return nil -} - -// toTransaction converts the arguments to a transaction. -// This assumes that setDefaults has been called. -func (args *SendTxArgs) toTransaction() types.Transaction { - var input []byte - if args.Input != nil { - input = *args.Input - } else if args.Data != nil { - input = *args.Data - } - - var txn types.Transaction - gasPrice, _ := uint256.FromBig((*big.Int)(args.GasPrice)) - value, _ := uint256.FromBig((*big.Int)(args.Value)) - if args.AccessList == nil { - tx = &types.LegacyTx{ - CommonTx: types.CommonTx{ - To: args.To, - Nonce: uint64(*args.Nonce), - Gas: uint64(*args.Gas), - Value: value, - Data: input, - }, - GasPrice: gasPrice, - } - } else { - chainId, _ := uint256.FromBig((*big.Int)(args.ChainID)) - if args.MaxFeePerGas == nil { - tx = &types.AccessListTx{ - LegacyTx: types.LegacyTx{ - CommonTx: types.CommonTx{ - To: args.To, - Nonce: uint64(*args.Nonce), - Gas: uint64(*args.Gas), - Value: value, - Data: input, - }, - GasPrice: gasPrice, - }, - ChainID: chainId, - AccessList: *args.AccessList, - } - } else { - tip, _ := uint256.FromBig((*big.Int)(args.MaxPriorityFeePerGas)) - feeCap, _ := uint256.FromBig((*big.Int)(args.MaxFeePerGas)) - tx = &types.DynamicFeeTransaction{ - CommonTx: types.CommonTx{ - To: args.To, - Nonce: uint64(*args.Nonce), - Gas: uint64(*args.Gas), - Value: value, - Data: input, - }, - MaxPriorityFeePerGas: tip, - MaxFeePerGas: feeCap, - ChainID: chainId, - AccessList: *args.AccessList, - } - } - } - return tx -} - -// SubmitTransaction is a helper function that submits txn to txPool and logs a message. -func SubmitTransaction(ctx context.Context, b Backend, txn types.Transaction) (libcommon.Hash, error) { - // If the transaction fee cap is already specified, ensure the - // fee of the given transaction is _reasonable_. - if err := checkTxFee(tx.GetPrice().ToBig(), tx.GetGas(), b.RPCTxFeeCap()); err != nil { - return libcommon.Hash{}, err - } - if !b.UnprotectedAllowed() && !tx.Protected() { - // Ensure only eip155 signed transactions are submitted if EIP155Required is set. - return libcommon.Hash{}, errors.New("only replay-protected (EIP-155) transactions allowed over RPC") - } - if err := b.SendTx(ctx, tx); err != nil { - return libcommon.Hash{}, err - } - // Print a log with full txn details for manual investigations and interventions - signer := types.MakeSigner(b.ChainConfig(), b.CurrentBlock().Number().Uint64()) - from, err := tx.Sender(*signer) - if err != nil { - return libcommon.Hash{}, err - } - - if tx.GetTo() == nil { - addr := crypto.CreateAddress(from, tx.GetNonce()) - log.Info("Submitted contract creation", "hash", tx.Hash().Hex(), "from", from, "nonce", tx.GetNonce(), "contract", addr.Hex(), "value", tx.GetValue()) - } else { - log.Info("Submitted transaction", "hash", tx.Hash().Hex(), "from", from, "nonce", tx.GetNonce(), "recipient", tx.GetTo(), "value", tx.GetValue()) - } - return tx.Hash(), nil -} - -// FillTransaction fills the defaults (nonce, gas, gasPrice) on a given unsigned transaction, -// and returns it to the caller for further processing (signing + broadcast) -func (s *PublicTransactionPoolAPI) FillTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) { - // Set some sanity defaults and terminate on failure - if err := args.setDefaults(ctx, s.b); err != nil { - return nil, err - } - // Assemble the transaction and obtain rlp - tx := args.toTransaction() - var blob bytes.Buffer - if tx.Type() != types.LegacyTxType { - if err := blob.WriteByte(tx.Type()); err != nil { - return nil, err - } - } - if err := rlp.Encode(&blob, tx); err != nil { - return nil, err - } - return &SignTransactionResult{blob.Bytes(), tx}, nil -} - -// SendRawTransaction will add the signed transaction to the transaction pool. -// The sender is responsible for signing the transaction and using the correct nonce. -func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, input hexutil.Bytes) (libcommon.Hash, error) { - tx, err := types.DecodeTransaction(rlp.NewStream(bytes.NewReader(input), 0)) - if err != nil { - return libcommon.Hash{}, err - } - return SubmitTransaction(ctx, s.b, tx) -} - -// SignTransactionResult represents a RLP encoded signed transaction. -type SignTransactionResult struct { - Raw hexutil.Bytes `json:"raw"` - Tx types.Transaction `json:"tx"` -} - -// PublicDebugAPI is the collection of Ethereum APIs exposed over the public -// debugging endpoint. -type PublicDebugAPI struct { - b Backend -} - -// NewPublicDebugAPI creates a new API definition for the public debug methods -// of the Ethereum service. -func NewPublicDebugAPI(b Backend) *PublicDebugAPI { - return &PublicDebugAPI{b: b} -} - -// GetBlockRlp retrieves the RLP encoded for of a single block. -func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (string, error) { - block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) - if block == nil { - return "", fmt.Errorf("block #%d not found", number) - } - encoded, err := rlp.EncodeToBytes(block) - if err != nil { - return "", err - } - return fmt.Sprintf("%x", encoded), nil -} - -// PrintBlock retrieves a block and returns its pretty printed form. -func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) { - block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) - if block == nil { - return "", fmt.Errorf("block #%d not found", number) - } - return spew.Sdump(block), nil -} - -// SeedHash retrieves the seed hash of a block. -func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string, error) { - block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number)) - if block == nil { - return "", fmt.Errorf("block #%d not found", number) - } - return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil -} - -// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private -// debugging endpoint. -type PrivateDebugAPI struct { - b Backend -} - -// NewPrivateDebugAPI creates a new API definition for the private debug methods -// of the Ethereum service. -func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI { - return &PrivateDebugAPI{b: b} -} - -// ChaindbProperty returns properties of the chain database. -func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) { - return "N/A", nil -} - -// ChaindbCompact flattens the entire key-value database into a single level, -// removing all unused slots and merging all keys. -func (api *PrivateDebugAPI) ChaindbCompact() error { - // Intentionally disabled in Erigon - return nil -} - -// SetHead rewinds the head of the blockchain to a previous block. -func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) { - api.b.SetHead(uint64(number)) -} - -// PublicNetAPI offers network related RPC methods -type PublicNetAPI struct { - net *p2p.Server - networkVersion uint64 -} - -// NewPublicNetAPI creates a new net API instance. -func NewPublicNetAPI(net *p2p.Server, networkVersion uint64) *PublicNetAPI { - return &PublicNetAPI{net, networkVersion} -} - -// Listening returns an indication if the node is listening for network connections. -func (s *PublicNetAPI) Listening() bool { - return true // always listening -} - -// PeerCount returns the number of connected peers -func (s *PublicNetAPI) PeerCount() hexutil.Uint { - return hexutil.Uint(s.net.PeerCount()) -} - -// Version returns the current ethereum protocol version. -func (s *PublicNetAPI) Version() string { - return fmt.Sprintf("%d", s.networkVersion) -} - -// checkTxFee is an internal function used to check whether the fee of -// the given transaction is _reasonable_(under the cap). -func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error { - // Short circuit if there is no cap for transaction fee at all. - if cap == 0 { - return nil - } - feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(params.Ether))) - feeFloat, _ := feeEth.Float64() - if feeFloat > cap { - return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap) - } - return nil + return NewRPCTransaction(txn, b.Hash(), b.NumberU64(), index, b.BaseFee()) } -*/ diff --git a/turbo/jsonrpc/eth_api.go b/turbo/jsonrpc/eth_api.go index 59036487112..c2712b70f91 100644 --- a/turbo/jsonrpc/eth_api.go +++ b/turbo/jsonrpc/eth_api.go @@ -27,7 +27,6 @@ import ( "time" lru "github.com/hashicorp/golang-lru/v2" - "github.com/holiman/uint256" "github.com/erigontech/erigon-lib/chain" "github.com/erigontech/erigon-lib/common" @@ -50,7 +49,7 @@ import ( "github.com/erigontech/erigon/polygon/bor/borcfg" "github.com/erigontech/erigon/polygon/bridge" "github.com/erigontech/erigon/rpc" - ethapi2 "github.com/erigontech/erigon/turbo/adapter/ethapi" + "github.com/erigontech/erigon/turbo/adapter/ethapi" "github.com/erigontech/erigon/turbo/jsonrpc/receipts" "github.com/erigontech/erigon/turbo/rpchelper" "github.com/erigontech/erigon/turbo/services" @@ -65,9 +64,9 @@ type EthAPI interface { GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) (*hexutil.Uint, error) // Transaction related (see ./eth_txs.go) - GetTransactionByHash(ctx context.Context, hash common.Hash) (*RPCTransaction, error) - GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, txIndex hexutil.Uint64) (*RPCTransaction, error) - GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, txIndex hexutil.Uint) (*RPCTransaction, error) + GetTransactionByHash(ctx context.Context, hash common.Hash) (*ethapi.RPCTransaction, error) + GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, txIndex hexutil.Uint64) (*ethapi.RPCTransaction, error) + GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, txIndex hexutil.Uint) (*ethapi.RPCTransaction, error) GetRawTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) (hexutility.Bytes, error) GetRawTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) (hexutility.Bytes, error) GetRawTransactionByHash(ctx context.Context, hash common.Hash) (hexutility.Bytes, error) @@ -107,14 +106,14 @@ type EthAPI interface { GasPrice(_ context.Context) (*hexutil.Big, error) // Sending related (see ./eth_call.go) - Call(ctx context.Context, args ethapi2.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *ethapi2.StateOverrides) (hexutility.Bytes, error) - EstimateGas(ctx context.Context, argsOrNil *ethapi2.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *ethapi2.StateOverrides) (hexutil.Uint64, error) + Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *ethapi.StateOverrides) (hexutility.Bytes, error) + EstimateGas(ctx context.Context, argsOrNil *ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *ethapi.StateOverrides) (hexutil.Uint64, error) SendRawTransaction(ctx context.Context, encodedTx hexutility.Bytes) (common.Hash, error) SendTransaction(_ context.Context, txObject interface{}) (common.Hash, error) Sign(ctx context.Context, _ common.Address, _ hexutility.Bytes) (hexutility.Bytes, error) SignTransaction(_ context.Context, txObject interface{}) (common.Hash, error) GetProof(ctx context.Context, address common.Address, storageKeys []common.Hash, blockNr rpc.BlockNumberOrHash) (*accounts.AccProofResult, error) - CreateAccessList(ctx context.Context, args ethapi2.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, optimizeGas *bool) (*accessListResult, error) + CreateAccessList(ctx context.Context, args ethapi.CallArgs, blockNrOrHash *rpc.BlockNumberOrHash, optimizeGas *bool) (*accessListResult, error) // Mining related (see ./eth_mining.go) Coinbase(ctx context.Context) (common.Address, error) @@ -416,155 +415,13 @@ func NewEthAPI(base *BaseAPI, db kv.TemporalRoDB, eth rpchelper.ApiBackend, txPo } } -// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction -type RPCTransaction struct { - BlockHash *common.Hash `json:"blockHash"` - BlockNumber *hexutil.Big `json:"blockNumber"` - From common.Address `json:"from"` - Gas hexutil.Uint64 `json:"gas"` - GasPrice *hexutil.Big `json:"gasPrice,omitempty"` - Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"` - FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"` - Hash common.Hash `json:"hash"` - Input hexutility.Bytes `json:"input"` - Nonce hexutil.Uint64 `json:"nonce"` - To *common.Address `json:"to"` - TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` - Value *hexutil.Big `json:"value"` - Type hexutil.Uint64 `json:"type"` - Accesses *types.AccessList `json:"accessList,omitempty"` - ChainID *hexutil.Big `json:"chainId,omitempty"` - MaxFeePerBlobGas *hexutil.Big `json:"maxFeePerBlobGas,omitempty"` - BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"` - Authorizations *[]types.JsonAuthorization `json:"authorizationList,omitempty"` - V *hexutil.Big `json:"v"` - YParity *hexutil.Big `json:"yParity,omitempty"` - R *hexutil.Big `json:"r"` - S *hexutil.Big `json:"s"` -} - -// NewRPCTransaction returns a transaction that will serialize to the RPC -// representation, with the given location metadata set (if available). -func NewRPCTransaction(txn types.Transaction, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int) *RPCTransaction { - // Determine the signer. For replay-protected transactions, use the most permissive - // signer, because we assume that signers are backwards-compatible with old - // transactions. For non-protected transactions, the homestead signer is used - // because the return value of ChainId is zero for those transactions. - chainId := uint256.NewInt(0) - result := &RPCTransaction{ - Type: hexutil.Uint64(txn.Type()), - Gas: hexutil.Uint64(txn.GetGas()), - Hash: txn.Hash(), - Input: hexutility.Bytes(txn.GetData()), - Nonce: hexutil.Uint64(txn.GetNonce()), - To: txn.GetTo(), - Value: (*hexutil.Big)(txn.GetValue().ToBig()), - } - if t, ok := txn.(*types.BlobTxWrapper); ok { - txn = &t.Tx - } - - v, r, s := txn.RawSignatureValues() - result.V = (*hexutil.Big)(v.ToBig()) - result.R = (*hexutil.Big)(r.ToBig()) - result.S = (*hexutil.Big)(s.ToBig()) - - if txn.Type() == types.LegacyTxType { - chainId = types.DeriveChainId(v) - // if a legacy transaction has an EIP-155 chain id, include it explicitly, otherwise chain id is not included - if !chainId.IsZero() { - result.ChainID = (*hexutil.Big)(chainId.ToBig()) - } - result.GasPrice = (*hexutil.Big)(txn.GetPrice().ToBig()) - } else { - chainId.Set(txn.GetChainID()) - result.ChainID = (*hexutil.Big)(chainId.ToBig()) - result.YParity = (*hexutil.Big)(v.ToBig()) - acl := txn.GetAccessList() - result.Accesses = &acl - - if txn.Type() == types.AccessListTxType { - result.GasPrice = (*hexutil.Big)(txn.GetPrice().ToBig()) - } else { - result.GasPrice = computeGasPrice(txn, blockHash, baseFee) - result.Tip = (*hexutil.Big)(txn.GetTip().ToBig()) - result.FeeCap = (*hexutil.Big)(txn.GetFeeCap().ToBig()) - } - - if txn.Type() == types.BlobTxType { - txn.GetBlobGas() - blobTx := txn.(*types.BlobTx) - result.MaxFeePerBlobGas = (*hexutil.Big)(blobTx.MaxFeePerBlobGas.ToBig()) - result.BlobVersionedHashes = blobTx.BlobVersionedHashes - } else if txn.Type() == types.SetCodeTxType { - setCodeTx := txn.(*types.SetCodeTransaction) - ats := make([]types.JsonAuthorization, len(setCodeTx.GetAuthorizations())) - for i, a := range setCodeTx.GetAuthorizations() { - ats[i] = types.JsonAuthorization{}.FromAuthorization(a) - } - result.Authorizations = &ats - } - } - - signer := types.LatestSignerForChainID(chainId.ToBig()) - var err error - result.From, err = txn.Sender(*signer) - if err != nil { - log.Warn("sender recovery", "err", err) - } - if blockHash != (common.Hash{}) { - result.BlockHash = &blockHash - result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber)) - result.TransactionIndex = (*hexutil.Uint64)(&index) - } - return result -} - -func computeGasPrice(txn types.Transaction, blockHash common.Hash, baseFee *big.Int) *hexutil.Big { - fee, overflow := uint256.FromBig(baseFee) - if fee != nil && !overflow && blockHash != (common.Hash{}) { - // price = min(tip + baseFee, gasFeeCap) - price := math.Min256(new(uint256.Int).Add(txn.GetTip(), fee), txn.GetFeeCap()) - return (*hexutil.Big)(price.ToBig()) - } - return nil -} - -// newRPCBorTransaction returns a Bor transaction that will serialize to the RPC -// representation, with the given location metadata set (if available). -func newRPCBorTransaction(opaqueTxn types.Transaction, txHash common.Hash, blockHash common.Hash, blockNumber uint64, index uint64, baseFee *big.Int, chainId *big.Int) *RPCTransaction { - txn := opaqueTxn.(*types.LegacyTx) - result := &RPCTransaction{ - Type: hexutil.Uint64(txn.Type()), - ChainID: (*hexutil.Big)(new(big.Int)), - GasPrice: (*hexutil.Big)(txn.GasPrice.ToBig()), - Gas: hexutil.Uint64(txn.GetGas()), - Hash: txHash, - Input: hexutility.Bytes(txn.GetData()), - Nonce: hexutil.Uint64(txn.GetNonce()), - From: common.Address{}, - To: txn.GetTo(), - Value: (*hexutil.Big)(txn.GetValue().ToBig()), - V: (*hexutil.Big)(big.NewInt(0)), - R: (*hexutil.Big)(big.NewInt(0)), - S: (*hexutil.Big)(big.NewInt(0)), - } - if blockHash != (common.Hash{}) { - result.ChainID = (*hexutil.Big)(new(big.Int).SetUint64(chainId.Uint64())) - result.BlockHash = &blockHash - result.BlockNumber = (*hexutil.Big)(new(big.Int).SetUint64(blockNumber)) - result.TransactionIndex = (*hexutil.Uint64)(&index) - } - return result -} - // newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation -func newRPCPendingTransaction(txn types.Transaction, current *types.Header, config *chain.Config) *RPCTransaction { +func newRPCPendingTransaction(txn types.Transaction, current *types.Header, config *chain.Config) *ethapi.RPCTransaction { var baseFee *big.Int if current != nil { baseFee = misc.CalcBaseFee(config, current) } - return NewRPCTransaction(txn, common.Hash{}, 0, 0, baseFee) + return ethapi.NewRPCTransaction(txn, common.Hash{}, 0, 0, baseFee) } // newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index. diff --git a/turbo/jsonrpc/eth_txs.go b/turbo/jsonrpc/eth_txs.go index e08f9bf43dd..155703bcbd1 100644 --- a/turbo/jsonrpc/eth_txs.go +++ b/turbo/jsonrpc/eth_txs.go @@ -22,26 +22,24 @@ import ( "fmt" "math/big" - "github.com/erigontech/erigon-lib/kv/rawdbv3" - "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" - - "github.com/erigontech/erigon-lib/common/hexutil" - "github.com/erigontech/erigon-lib/common" + "github.com/erigontech/erigon-lib/common/hexutil" "github.com/erigontech/erigon-lib/common/hexutility" "github.com/erigontech/erigon-lib/gointerfaces" txpool "github.com/erigontech/erigon-lib/gointerfaces/txpoolproto" types "github.com/erigontech/erigon-lib/gointerfaces/typesproto" - bortypes "github.com/erigontech/erigon/polygon/bor/types" - + "github.com/erigontech/erigon-lib/kv/rawdbv3" "github.com/erigontech/erigon/core/rawdb" types2 "github.com/erigontech/erigon/core/types" + bortypes "github.com/erigontech/erigon/polygon/bor/types" "github.com/erigontech/erigon/rpc" + "github.com/erigontech/erigon/turbo/adapter/ethapi" "github.com/erigontech/erigon/turbo/rpchelper" + "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" ) // GetTransactionByHash implements eth_getTransactionByHash. Returns information about a transaction given the transaction's hash. -func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Hash) (*RPCTransaction, error) { +func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Hash) (*ethapi.RPCTransaction, error) { tx, err := api.db.BeginTemporalRo(ctx) if err != nil { return nil, err @@ -115,10 +113,10 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, txnHash common.Has if err != nil { return nil, err } - return newRPCBorTransaction(borTx, txnHash, blockHash, blockNum, uint64(txCount), baseFee, chainConfig.ChainID), nil + return ethapi.NewRPCBorTransaction(borTx, txnHash, blockHash, blockNum, uint64(txCount), chainConfig.ChainID), nil } - return NewRPCTransaction(txn, blockHash, blockNum, txnIndex, baseFee), nil + return ethapi.NewRPCTransaction(txn, blockHash, blockNum, txnIndex, baseFee), nil } curHeader := rawdb.ReadCurrentHeader(tx) @@ -198,7 +196,7 @@ func (api *APIImpl) GetRawTransactionByHash(ctx context.Context, hash common.Has } // GetTransactionByBlockHashAndIndex implements eth_getTransactionByBlockHashAndIndex. Returns information about a transaction given the block's hash and a transaction index. -func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, txIndex hexutil.Uint64) (*RPCTransaction, error) { +func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, txIndex hexutil.Uint64) (*ethapi.RPCTransaction, error) { tx, err := api.db.BeginTemporalRo(ctx) if err != nil { return nil, err @@ -242,10 +240,10 @@ func (api *APIImpl) GetTransactionByBlockHashAndIndex(ctx context.Context, block return nil, nil // not error } derivedBorTxHash := bortypes.ComputeBorTxHash(block.NumberU64(), block.Hash()) - return newRPCBorTransaction(borTx, derivedBorTxHash, block.Hash(), block.NumberU64(), uint64(txIndex), block.BaseFee(), chainConfig.ChainID), nil + return ethapi.NewRPCBorTransaction(borTx, derivedBorTxHash, block.Hash(), block.NumberU64(), uint64(txIndex), chainConfig.ChainID), nil } - return NewRPCTransaction(txs[txIndex], block.Hash(), block.NumberU64(), uint64(txIndex), block.BaseFee()), nil + return ethapi.NewRPCTransaction(txs[txIndex], block.Hash(), block.NumberU64(), uint64(txIndex), block.BaseFee()), nil } // GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index. @@ -269,7 +267,7 @@ func (api *APIImpl) GetRawTransactionByBlockHashAndIndex(ctx context.Context, bl } // GetTransactionByBlockNumberAndIndex implements eth_getTransactionByBlockNumberAndIndex. Returns information about a transaction given a block number and transaction index. -func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, txIndex hexutil.Uint) (*RPCTransaction, error) { +func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, txIndex hexutil.Uint) (*ethapi.RPCTransaction, error) { tx, err := api.db.BeginTemporalRo(ctx) if err != nil { return nil, err @@ -318,10 +316,10 @@ func (api *APIImpl) GetTransactionByBlockNumberAndIndex(ctx context.Context, blo return nil, nil } derivedBorTxHash := bortypes.ComputeBorTxHash(blockNum, hash) - return newRPCBorTransaction(borTx, derivedBorTxHash, hash, blockNum, uint64(txIndex), block.BaseFee(), chainConfig.ChainID), nil + return ethapi.NewRPCBorTransaction(borTx, derivedBorTxHash, hash, blockNum, uint64(txIndex), chainConfig.ChainID), nil } - return NewRPCTransaction(txs[txIndex], hash, blockNum, uint64(txIndex), block.BaseFee()), nil + return ethapi.NewRPCTransaction(txs[txIndex], hash, blockNum, uint64(txIndex), block.BaseFee()), nil } // GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index. diff --git a/turbo/jsonrpc/otterscan_api.go b/turbo/jsonrpc/otterscan_api.go index 161a8d1388e..69707028a1d 100644 --- a/turbo/jsonrpc/otterscan_api.go +++ b/turbo/jsonrpc/otterscan_api.go @@ -48,7 +48,7 @@ import ( const API_LEVEL = 8 type TransactionsWithReceipts struct { - Txs []*RPCTransaction `json:"txs"` + Txs []*ethapi.RPCTransaction `json:"txs"` Receipts []map[string]interface{} `json:"receipts"` FirstPage bool `json:"firstPage"` LastPage bool `json:"lastPage"` diff --git a/turbo/jsonrpc/otterscan_search_trace.go b/turbo/jsonrpc/otterscan_search_trace.go index 9e7740435e2..2e2ca3909db 100644 --- a/turbo/jsonrpc/otterscan_search_trace.go +++ b/turbo/jsonrpc/otterscan_search_trace.go @@ -20,17 +20,17 @@ import ( "context" "fmt" - "github.com/erigontech/erigon-lib/kv/rawdbv3" - "github.com/erigontech/erigon-lib/log/v3" - "github.com/erigontech/erigon-lib/chain" "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/kv" + "github.com/erigontech/erigon-lib/kv/rawdbv3" + "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon/core" "github.com/erigontech/erigon/core/state" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/core/vm" "github.com/erigontech/erigon/eth/ethutils" + "github.com/erigontech/erigon/turbo/adapter/ethapi" "github.com/erigontech/erigon/turbo/rpchelper" "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" ) @@ -55,7 +55,7 @@ func (api *OtterscanAPIImpl) searchTraceBlock(ctx context.Context, addr common.A } func (api *OtterscanAPIImpl) traceBlock(dbtx kv.TemporalTx, ctx context.Context, blockNum uint64, searchAddr common.Address, chainConfig *chain.Config) (bool, *TransactionsWithReceipts, error) { - rpcTxs := make([]*RPCTransaction, 0) + rpcTxs := make([]*ethapi.RPCTransaction, 0) receipts := make([]map[string]interface{}, 0) // Retrieve the transaction and assemble its EVM context @@ -135,7 +135,7 @@ func (api *OtterscanAPIImpl) traceBlock(dbtx kv.TemporalTx, ctx context.Context, } return false, nil, fmt.Errorf("requested receipt idx %d, but have only %d", idx, len(blockReceipts)) // otherwise return some error for debugging } - rpcTx := NewRPCTransaction(txn, block.Hash(), blockNum, uint64(idx), block.BaseFee()) + rpcTx := ethapi.NewRPCTransaction(txn, block.Hash(), blockNum, uint64(idx), block.BaseFee()) mReceipt := ethutils.MarshalReceipt(blockReceipts[idx], txn, chainConfig, block.HeaderNoCopy(), txn.Hash(), true) mReceipt["timestamp"] = block.Time() rpcTxs = append(rpcTxs, rpcTx) diff --git a/turbo/jsonrpc/otterscan_search_v3.go b/turbo/jsonrpc/otterscan_search_v3.go index b6c179025ed..e9a1ce7919e 100644 --- a/turbo/jsonrpc/otterscan_search_v3.go +++ b/turbo/jsonrpc/otterscan_search_v3.go @@ -28,12 +28,13 @@ import ( "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon/core/types" "github.com/erigontech/erigon/eth/ethutils" + "github.com/erigontech/erigon/turbo/adapter/ethapi" "github.com/erigontech/erigon/turbo/snapshotsync/freezeblocks" ) type txNumsIterFactory func(tx kv.TemporalTx, txNumsReader rawdbv3.TxNumsReader, addr common.Address, fromTxNum int) (*rawdbv3.MapTxNum2BlockNumIter, error) -func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.TemporalTx, txNumsReader rawdbv3.TxNumsReader, iterFactory txNumsIterFactory, addr common.Address, fromTxNum int, pageSize uint16) ([]*RPCTransaction, []map[string]interface{}, bool, error) { +func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.TemporalTx, txNumsReader rawdbv3.TxNumsReader, iterFactory txNumsIterFactory, addr common.Address, fromTxNum int, pageSize uint16) ([]*ethapi.RPCTransaction, []map[string]interface{}, bool, error) { chainConfig, err := api.chainConfig(ctx, tx) if err != nil { return nil, nil, false, err @@ -45,7 +46,7 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo } var block *types.Block - txs := make([]*RPCTransaction, 0, pageSize) + txs := make([]*ethapi.RPCTransaction, 0, pageSize) receipts := make([]map[string]interface{}, 0, pageSize) resultCount := uint16(0) @@ -93,7 +94,7 @@ func (api *OtterscanAPIImpl) buildSearchResults(ctx context.Context, tx kv.Tempo log.Warn("[rpc] txn not found", "blockNum", blockNum, "txIndex", txIndex) continue } - rpcTx := NewRPCTransaction(txn, block.Hash(), blockNum, uint64(txIndex), block.BaseFee()) + rpcTx := ethapi.NewRPCTransaction(txn, block.Hash(), blockNum, uint64(txIndex), block.BaseFee()) txs = append(txs, rpcTx) receipt, err := api.receiptsGenerator.GetReceipt(ctx, chainConfig, tx, block.HeaderNoCopy(), txn, txIndex, txNum+1) diff --git a/turbo/jsonrpc/txpool_api.go b/turbo/jsonrpc/txpool_api.go index ebd47625dbe..db9b495ed9d 100644 --- a/turbo/jsonrpc/txpool_api.go +++ b/turbo/jsonrpc/txpool_api.go @@ -21,21 +21,20 @@ import ( "fmt" "strconv" - "github.com/erigontech/erigon-lib/common/hexutil" - libcommon "github.com/erigontech/erigon-lib/common" + "github.com/erigontech/erigon-lib/common/hexutil" "github.com/erigontech/erigon-lib/gointerfaces" proto_txpool "github.com/erigontech/erigon-lib/gointerfaces/txpoolproto" "github.com/erigontech/erigon-lib/kv" - "github.com/erigontech/erigon/core/rawdb" "github.com/erigontech/erigon/core/types" + "github.com/erigontech/erigon/turbo/adapter/ethapi" ) // TxPoolAPI the interface for the txpool_ RPC commands type TxPoolAPI interface { - Content(ctx context.Context) (map[string]map[string]map[string]*RPCTransaction, error) - ContentFrom(ctx context.Context, addr libcommon.Address) (map[string]map[string]*RPCTransaction, error) + Content(ctx context.Context) (map[string]map[string]map[string]*ethapi.RPCTransaction, error) + ContentFrom(ctx context.Context, addr libcommon.Address) (map[string]map[string]*ethapi.RPCTransaction, error) } // TxPoolAPIImpl data structure to store things needed for net_ commands @@ -54,16 +53,16 @@ func NewTxPoolAPI(base *BaseAPI, db kv.TemporalRoDB, pool proto_txpool.TxpoolCli } } -func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]map[string]*RPCTransaction, error) { +func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]map[string]*ethapi.RPCTransaction, error) { reply, err := api.pool.All(ctx, &proto_txpool.AllRequest{}) if err != nil { return nil, err } - content := map[string]map[string]map[string]*RPCTransaction{ - "pending": make(map[string]map[string]*RPCTransaction), - "baseFee": make(map[string]map[string]*RPCTransaction), - "queued": make(map[string]map[string]*RPCTransaction), + content := map[string]map[string]map[string]*ethapi.RPCTransaction{ + "pending": make(map[string]map[string]*ethapi.RPCTransaction), + "baseFee": make(map[string]map[string]*ethapi.RPCTransaction), + "queued": make(map[string]map[string]*ethapi.RPCTransaction), } pending := make(map[libcommon.Address][]types.Transaction, 8) @@ -110,7 +109,7 @@ func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]ma } // Flatten the pending transactions for account, txs := range pending { - dump := make(map[string]*RPCTransaction) + dump := make(map[string]*ethapi.RPCTransaction) for _, txn := range txs { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) } @@ -118,7 +117,7 @@ func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]ma } // Flatten the baseFee transactions for account, txs := range baseFee { - dump := make(map[string]*RPCTransaction) + dump := make(map[string]*ethapi.RPCTransaction) for _, txn := range txs { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) } @@ -126,7 +125,7 @@ func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]ma } // Flatten the queued transactions for account, txs := range queued { - dump := make(map[string]*RPCTransaction) + dump := make(map[string]*ethapi.RPCTransaction) for _, txn := range txs { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) } @@ -135,16 +134,16 @@ func (api *TxPoolAPIImpl) Content(ctx context.Context) (map[string]map[string]ma return content, nil } -func (api *TxPoolAPIImpl) ContentFrom(ctx context.Context, addr libcommon.Address) (map[string]map[string]*RPCTransaction, error) { +func (api *TxPoolAPIImpl) ContentFrom(ctx context.Context, addr libcommon.Address) (map[string]map[string]*ethapi.RPCTransaction, error) { reply, err := api.pool.All(ctx, &proto_txpool.AllRequest{}) if err != nil { return nil, err } - content := map[string]map[string]*RPCTransaction{ - "pending": make(map[string]*RPCTransaction), - "baseFee": make(map[string]*RPCTransaction), - "queued": make(map[string]*RPCTransaction), + content := map[string]map[string]*ethapi.RPCTransaction{ + "pending": make(map[string]*ethapi.RPCTransaction), + "baseFee": make(map[string]*ethapi.RPCTransaction), + "queued": make(map[string]*ethapi.RPCTransaction), } pending := make([]types.Transaction, 0, 4) @@ -185,19 +184,19 @@ func (api *TxPoolAPIImpl) ContentFrom(ctx context.Context, addr libcommon.Addres return nil, nil } // Flatten the pending transactions - dump := make(map[string]*RPCTransaction) + dump := make(map[string]*ethapi.RPCTransaction) for _, txn := range pending { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) } content["pending"] = dump // Flatten the baseFee transactions - dump = make(map[string]*RPCTransaction) + dump = make(map[string]*ethapi.RPCTransaction) for _, txn := range baseFee { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) } content["baseFee"] = dump // Flatten the queued transactions - dump = make(map[string]*RPCTransaction) + dump = make(map[string]*ethapi.RPCTransaction) for _, txn := range queued { dump[strconv.FormatUint(txn.GetNonce(), 10)] = newRPCPendingTransaction(txn, curHeader, cc) }