@@ -25,6 +25,7 @@ import (
2525 "github.com/scroll-tech/go-ethereum"
2626 "github.com/scroll-tech/go-ethereum/accounts"
2727 "github.com/scroll-tech/go-ethereum/common"
28+ "github.com/scroll-tech/go-ethereum/common/hexutil"
2829 "github.com/scroll-tech/go-ethereum/consensus"
2930 "github.com/scroll-tech/go-ethereum/core"
3031 "github.com/scroll-tech/go-ethereum/core/bloombits"
@@ -35,6 +36,7 @@ import (
3536 "github.com/scroll-tech/go-ethereum/eth/gasprice"
3637 "github.com/scroll-tech/go-ethereum/ethdb"
3738 "github.com/scroll-tech/go-ethereum/event"
39+ "github.com/scroll-tech/go-ethereum/log"
3840 "github.com/scroll-tech/go-ethereum/miner"
3941 "github.com/scroll-tech/go-ethereum/params"
4042 "github.com/scroll-tech/go-ethereum/rpc"
@@ -44,6 +46,7 @@ import (
4446type EthAPIBackend struct {
4547 extRPCEnabled bool
4648 allowUnprotectedTxs bool
49+ disableTxPool bool
4750 eth * Ethereum
4851 gpo * gasprice.Oracle
4952}
@@ -262,6 +265,34 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
262265}
263266
264267func (b * EthAPIBackend ) SendTx (ctx context.Context , signedTx * types.Transaction ) error {
268+ if signedTx .Type () == types .BlobTxType {
269+ return types .ErrTxTypeNotSupported
270+ }
271+
272+ // Retain tx in local tx pool before forwarding to sequencer rpc, for local RPC usage.
273+ err := b .sendTx (signedTx )
274+ if err != nil {
275+ return err
276+ }
277+
278+ // Forward to remote sequencer RPC
279+ if b .eth .sequencerRPCService != nil {
280+ signedTxData , err := signedTx .MarshalBinary ()
281+ if err != nil {
282+ return err
283+ }
284+ if err = b .eth .sequencerRPCService .CallContext (ctx , nil , "eth_sendRawTransaction" , hexutil .Encode (signedTxData )); err != nil {
285+ log .Warn ("failed to forward tx to sequencer" , "tx" , signedTx .Hash (), "err" , err )
286+ if b .disableTxPool {
287+ return err
288+ }
289+ }
290+ }
291+
292+ return nil
293+ }
294+
295+ func (b * EthAPIBackend ) sendTx (signedTx * types.Transaction ) error {
265296 // will `VerifyFee` & `validateTx` in txPool.AddLocal
266297 return b .eth .txPool .AddLocal (signedTx )
267298}
0 commit comments