Skip to content

Commit

Permalink
Unify jsonrpc.RPCTransaction & ethapi.RPCTransaction (#13575)
Browse files Browse the repository at this point in the history
`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 #13371.
  • Loading branch information
yperbasis authored Jan 27, 2025
1 parent 15d09ba commit 5ebd0ae
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 878 deletions.
4 changes: 2 additions & 2 deletions cmd/devnet/blocks/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions cmd/devnet/blocks/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/devnet/contracts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/devnet/requests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cmd/devnet/requests/nopgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/devnet/requests/request_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions cmd/devnet/requests/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/devnet/services/polygon/proofgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/devnet/services/polygon/proofgenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5ebd0ae

Please sign in to comment.