Skip to content

Commit b0619ce

Browse files
yiweichijonastheiscolinlyguocolinlyguo
authored
feat: forward txs to sequencer (#1208)
* add flags to disable broadcast and receiving of tx gossip respectively * feat: support forward txs to sequencer * fix: config * chore: auto version bump [bot] * chore: auto version bump [bot] * add comments * fix: forward tx logic * chore: auto version bump [bot] * fix: comment typo * chore: auto version bump [bot] * chore: auto version bump [bot] * run goimport * fix another file * fix: comments * chore: auto version bump [bot] * feat: retain transaction before forwording * chore: auto version bump [bot] --------- Co-authored-by: jonastheis <[email protected]> Co-authored-by: colin <[email protected]> Co-authored-by: colinlyguo <[email protected]>
1 parent b951416 commit b0619ce

File tree

7 files changed

+62
-4
lines changed

7 files changed

+62
-4
lines changed

cmd/geth/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ var (
178178
utils.ShadowforkPeersFlag,
179179
utils.TxGossipBroadcastDisabledFlag,
180180
utils.TxGossipReceivingDisabledFlag,
181+
utils.TxGossipSequencerHTTPFlag,
181182
utils.DASyncEnabledFlag,
182183
utils.DAMissingHeaderFieldsBaseURLFlag,
183184
utils.DABlockNativeAPIEndpointFlag,

cmd/geth/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
252252
utils.CircuitCapacityCheckWorkersFlag,
253253
utils.TxGossipBroadcastDisabledFlag,
254254
utils.TxGossipReceivingDisabledFlag,
255+
utils.TxGossipSequencerHTTPFlag,
255256
},
256257
},
257258
{

cmd/utils/flags.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,17 @@ var (
895895

896896
// Tx gossip settings
897897
TxGossipBroadcastDisabledFlag = cli.BoolFlag{
898-
Name: "txgossip.disablebroadcast",
898+
Name: "gossip.disablebroadcast",
899899
Usage: "Disable gossip broadcast transactions to other peers",
900900
}
901901
TxGossipReceivingDisabledFlag = cli.BoolFlag{
902-
Name: "txgossip.disablereceiving",
902+
Name: "gossip.disablereceiving",
903903
Usage: "Disable gossip receiving transactions from other peers",
904904
}
905+
TxGossipSequencerHTTPFlag = &cli.StringFlag{
906+
Name: "gossip.sequencerhttp",
907+
Usage: "Sequencer mempool HTTP endpoint",
908+
}
905909

906910
// DA syncing settings
907911
DASyncEnabledFlag = cli.BoolFlag{
@@ -1823,6 +1827,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18231827
cfg.TxGossipReceivingDisabled = ctx.GlobalBool(TxGossipReceivingDisabledFlag.Name)
18241828
log.Info("Transaction gossip receiving disabled", "disabled", cfg.TxGossipReceivingDisabled)
18251829
}
1830+
// Only configure sequencer http flag if we're running in verifier mode i.e. --mine is disabled.
1831+
if ctx.IsSet(TxGossipSequencerHTTPFlag.Name) && !ctx.IsSet(MiningEnabledFlag.Name) {
1832+
cfg.TxGossipSequencerHTTP = ctx.String(TxGossipSequencerHTTPFlag.Name)
1833+
}
18261834

18271835
// Cap the cache allowance and tune the garbage collector
18281836
mem, err := gopsutil.VirtualMemory()

eth/api_backend.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (
4446
type 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

264267
func (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
}

eth/backend.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ type Ethereum struct {
113113
p2pServer *p2p.Server
114114

115115
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
116+
117+
// Scroll additions
118+
sequencerRPCService *rpc.Client
116119
}
117120

118121
// New creates a new Ethereum object (including the
@@ -303,7 +306,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
303306
// Some of the extraData is used with Clique consensus (before EuclidV2). After EuclidV2 we use SystemContract consensus where this is overridden when creating a block.
304307
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
305308

306-
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
309+
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, config.TxGossipReceivingDisabled, eth, nil}
307310
if eth.APIBackend.allowUnprotectedTxs {
308311
log.Info("Unprotected transactions allowed")
309312
}
@@ -314,6 +317,16 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
314317
gpoParams.DefaultBasePrice = new(big.Int).SetUint64(config.TxPool.PriceLimit)
315318
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
316319

320+
if config.TxGossipSequencerHTTP != "" {
321+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
322+
client, err := rpc.DialContext(ctx, config.TxGossipSequencerHTTP)
323+
cancel()
324+
if err != nil {
325+
return nil, fmt.Errorf("cannot initialize rollup sequencer client: %w", err)
326+
}
327+
eth.sequencerRPCService = client
328+
}
329+
317330
// Setup DNS discovery iterators.
318331
dnsclient := dnsdisc.NewClient(dnsdisc.Config{})
319332
eth.ethDialCandidates, err = dnsclient.NewIterator(eth.config.EthDiscoveryURLs...)
@@ -702,6 +715,9 @@ func (s *Ethereum) Stop() error {
702715
}
703716
s.blockchain.Stop()
704717
s.engine.Close()
718+
if s.sequencerRPCService != nil {
719+
s.sequencerRPCService.Close()
720+
}
705721
rawdb.PopUncleanShutdownMarker(s.chainDb)
706722
s.chainDb.Close()
707723
s.eventMux.Stop()

eth/ethconfig/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ type Config struct {
233233

234234
TxGossipBroadcastDisabled bool
235235
TxGossipReceivingDisabled bool
236+
TxGossipSequencerHTTP string
236237
}
237238

238239
// CreateConsensusEngine creates a consensus engine for the given chain configuration.

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 = 66 // Patch version component of the current release
27+
VersionPatch = 67 // 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)