Skip to content

Commit 35bc5a9

Browse files
jonastheisyiweichi
andauthored
refactor: make tx forwarding to sequencer non-blocking if tx pool is enabled (#1227)
* make sequencer forwarding non-blocking if tx pool is enabled * chore: auto version bump [bot] * address review comments * chore: auto version bump [bot] * fix: blob client beacon node do http request with context (#1228) * fix: beacon node client request with context * chore: auto version bump [bot] --------- Co-authored-by: Morty <[email protected]>
1 parent 4c967ae commit 35bc5a9

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

eth/api_backend.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package eth
1919
import (
2020
"context"
2121
"errors"
22+
"fmt"
2223
"math/big"
2324
"time"
2425

@@ -277,16 +278,35 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
277278

278279
// Forward to remote sequencer RPC
279280
if b.eth.sequencerRPCService != nil {
280-
signedTxData, err := signedTx.MarshalBinary()
281-
if err != nil {
281+
// If the transaction pool is disabled, then we need to make sure that we send the transaction to the sequencer RPC synchronously.
282+
if b.disableTxPool {
283+
err = b.sendToSequencer(ctx, signedTx)
284+
if err != nil {
285+
log.Warn("failed to forward tx to sequencer", "tx", signedTx.Hash(), "err", err)
286+
}
282287
return err
283288
}
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
289+
290+
// If the transaction pool is enabled, we send the transaction to the sequencer RPC asynchronously as this is
291+
// additional to the public mempool.
292+
go func() {
293+
err := b.sendToSequencer(ctx, signedTx)
294+
if err != nil {
295+
log.Warn("failed to forward tx to sequencer", "tx", signedTx.Hash(), "err", err)
288296
}
289-
}
297+
}()
298+
}
299+
300+
return nil
301+
}
302+
303+
func (b *EthAPIBackend) sendToSequencer(ctx context.Context, signedTx *types.Transaction) error {
304+
signedTxData, err := signedTx.MarshalBinary()
305+
if err != nil {
306+
return fmt.Errorf("failed to marshal signed tx: %w", err)
307+
}
308+
if err = b.eth.sequencerRPCService.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(signedTxData)); err != nil {
309+
return fmt.Errorf("eth_sendRawTransaction to sequencer RPC failed: %w", err)
290310
}
291311

292312
return nil

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 8 // Minor version component of the current release
27-
VersionPatch = 75 // Patch version component of the current release
27+
VersionPatch = 76 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)