diff --git a/cmd/rpcdaemon/commands/eth_api.go b/cmd/rpcdaemon/commands/eth_api.go index f5e978732..17c8e7334 100644 --- a/cmd/rpcdaemon/commands/eth_api.go +++ b/cmd/rpcdaemon/commands/eth_api.go @@ -6,7 +6,6 @@ import ( "math/big" "sync" - "github.com/holiman/uint256" rpcfilters "github.com/ledgerwatch/turbo-geth/cmd/rpcdaemon/filters" "github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common/hexutil" @@ -192,7 +191,7 @@ func newRPCTransaction(tx types.Transaction, blockHash common.Hash, blockNumber // signer, because we assume that signers are backwards-compatible with old // transactions. For non-protected transactions, the homestead signer signer is used // because the return value of ChainId is zero for those transactions. - var chainId *uint256.Int + var chainId *big.Int result := &RPCTransaction{ Type: hexutil.Uint64(tx.Type()), Gas: hexutil.Uint64(tx.GetGas()), @@ -204,20 +203,22 @@ func newRPCTransaction(tx types.Transaction, blockHash common.Hash, blockNumber } switch t := tx.(type) { case *types.LegacyTx: - chainId = types.DeriveChainId(&t.V) + chainId = types.DeriveChainId(&t.V).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: - result.ChainID = (*hexutil.Big)(t.ChainID.ToBig()) + chainId = t.ChainID.ToBig() + result.ChainID = (*hexutil.Big)(chainId) 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()) result.Accesses = &t.AccessList case *types.DynamicFeeTransaction: - result.ChainID = (*hexutil.Big)(t.ChainID.ToBig()) + chainId = t.ChainID.ToBig() + result.ChainID = (*hexutil.Big)(chainId) result.Tip = (*hexutil.Big)(t.Tip.ToBig()) result.FeeCap = (*hexutil.Big)(t.FeeCap.ToBig()) result.V = (*hexutil.Big)(t.V.ToBig()) @@ -225,7 +226,7 @@ func newRPCTransaction(tx types.Transaction, blockHash common.Hash, blockNumber result.S = (*hexutil.Big)(t.S.ToBig()) result.Accesses = &t.AccessList } - signer := types.LatestSignerForChainID(chainId.ToBig()) + signer := types.LatestSignerForChainID(chainId) result.From, _ = tx.Sender(*signer) if blockHash != (common.Hash{}) { result.BlockHash = &blockHash diff --git a/cmd/rpcdaemon/commands/eth_txs.go b/cmd/rpcdaemon/commands/eth_txs.go index f58933ea2..68d11bb1b 100644 --- a/cmd/rpcdaemon/commands/eth_txs.go +++ b/cmd/rpcdaemon/commands/eth_txs.go @@ -25,10 +25,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, hash common.Hash) // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash txn, blockHash, blockNumber, txIndex := rawdb.ReadTransaction(tx, hash) - if txn == nil { - return nil, nil // not error, see https://github.com/ledgerwatch/turbo-geth/issues/1645 - } - if tx != nil { + if txn != nil { return newRPCTransaction(txn, blockHash, blockNumber, txIndex), nil } @@ -37,7 +34,7 @@ func (api *APIImpl) GetTransactionByHash(ctx context.Context, hash common.Hash) if err != nil { return nil, err } - if reply.RlpTxs[0] != nil { + if len(reply.RlpTxs[0]) > 0 { txn, err = types2.UnmarshalTransactionFromBinary(reply.RlpTxs[0]) if err != nil { return nil, err @@ -59,10 +56,7 @@ func (api *APIImpl) GetRawTransactionByHash(ctx context.Context, hash common.Has // https://infura.io/docs/ethereum/json-rpc/eth-getTransactionByHash txn, _, _, _ := rawdb.ReadTransaction(tx, hash) - if txn == nil { - return nil, nil // not error, see https://github.com/ledgerwatch/turbo-geth/issues/1645 - } - if tx != nil { + if txn != nil { var buf bytes.Buffer err = txn.MarshalBinary(&buf) return buf.Bytes(), err @@ -73,7 +67,7 @@ func (api *APIImpl) GetRawTransactionByHash(ctx context.Context, hash common.Has if err != nil { return nil, err } - if reply.RlpTxs[0] != nil { + if len(reply.RlpTxs[0]) > 0 { return reply.RlpTxs[0], nil } return nil, nil diff --git a/cmd/rpcdaemon/filters/filters.go b/cmd/rpcdaemon/filters/filters.go index c92bf81dc..642c68b72 100644 --- a/cmd/rpcdaemon/filters/filters.go +++ b/cmd/rpcdaemon/filters/filters.go @@ -57,16 +57,6 @@ func New(ctx context.Context, ethBackend core.ApiBackend, txPool txpool.TxpoolCl } }() - go func() { - if ethBackend == nil { - return - } - if err := ethBackend.Subscribe(ctx, ff.OnNewEvent); err != nil { - log.Warn("rpc filters: error subscribing to events", "err", err) - time.Sleep(time.Second) - } - }() - go func() { if txPool == nil { return @@ -212,14 +202,9 @@ func (ff *Filters) OnNewTx(reply *txpool.OnAddReply) { defer ff.mu.RUnlock() txs := make([]types.Transaction, len(reply.RplTxs)) - reader := bytes.NewReader(nil) - stream := rlp.NewStream(reader, 0) - for i, rplTx := range reply.RplTxs { - reader.Reset(rplTx) - stream.Reset(reader, uint64(len(rplTx))) var decodeErr error - txs[i], decodeErr = types.DecodeTransaction(stream) + txs[i], decodeErr = types.UnmarshalTransactionFromBinary(rplTx) if decodeErr != nil { // ignoring what we can't unmarshal log.Warn("OnNewTx rpc filters, unprocessable payload", "err", decodeErr) diff --git a/ethdb/remote/remotedbserver/txpool.go b/ethdb/remote/remotedbserver/txpool.go index e25948b30..d30a314c1 100644 --- a/ethdb/remote/remotedbserver/txpool.go +++ b/ethdb/remote/remotedbserver/txpool.go @@ -12,7 +12,6 @@ import ( "github.com/ledgerwatch/turbo-geth/gointerfaces" proto_txpool "github.com/ledgerwatch/turbo-geth/gointerfaces/txpool" "github.com/ledgerwatch/turbo-geth/log" - "github.com/ledgerwatch/turbo-geth/rlp" ) type txPool interface { @@ -94,7 +93,7 @@ func (s *TxPoolServer) OnAdd(req *proto_txpool.OnAddRequest, stream proto_txpool rplTxs = rplTxs[:0] for _, tx := range txs.Txs { buf.Reset() - if err := rlp.Encode(&buf, tx); err != nil { + if err := tx.MarshalBinary(&buf); err != nil { log.Warn("error while marshaling a pending transaction", "err", err) return err } @@ -117,7 +116,7 @@ func (s *TxPoolServer) Transactions(ctx context.Context, in *proto_txpool.Transa continue } buf.Reset() - if err := rlp.Encode(buf, txn); err != nil { + if err := txn.MarshalBinary(buf); err != nil { return nil, err } reply.RlpTxs[i] = common.CopyBytes(buf.Bytes())