Skip to content

Commit bef617a

Browse files
authored
Merge branch 'develop' into feat-broadcast-blocks-to-all-peers
2 parents 6483948 + b0619ce commit bef617a

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

cmd/utils/flags.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,6 +1837,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
18371837
cfg.GossipBroadcastToAllCap = ctx.GlobalInt(GossipBroadcastToAllCapFlag.Name)
18381838
log.Info("Gossip broadcast to all enabled", "enabled", cfg.GossipBroadcastToAllEnabled, "cap", cfg.GossipBroadcastToAllCap)
18391839
}
1840+
// Only configure sequencer http flag if we're running in verifier mode i.e. --mine is disabled.
1841+
if ctx.IsSet(TxGossipSequencerHTTPFlag.Name) && !ctx.IsSet(MiningEnabledFlag.Name) {
1842+
cfg.TxGossipSequencerHTTP = ctx.String(TxGossipSequencerHTTPFlag.Name)
1843+
}
18401844

18411845
// Cap the cache allowance and tune the garbage collector
18421846
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
@@ -305,7 +308,7 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
305308
// 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.
306309
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
307310

308-
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
311+
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, config.TxGossipReceivingDisabled, eth, nil}
309312
if eth.APIBackend.allowUnprotectedTxs {
310313
log.Info("Unprotected transactions allowed")
311314
}
@@ -316,6 +319,16 @@ func New(stack *node.Node, config *ethconfig.Config, l1Client l1.Client) (*Ether
316319
gpoParams.DefaultBasePrice = new(big.Int).SetUint64(config.TxPool.PriceLimit)
317320
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
318321

322+
if config.TxGossipSequencerHTTP != "" {
323+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
324+
client, err := rpc.DialContext(ctx, config.TxGossipSequencerHTTP)
325+
cancel()
326+
if err != nil {
327+
return nil, fmt.Errorf("cannot initialize rollup sequencer client: %w", err)
328+
}
329+
eth.sequencerRPCService = client
330+
}
331+
319332
// Setup DNS discovery iterators.
320333
dnsclient := dnsdisc.NewClient(dnsdisc.Config{})
321334
eth.ethDialCandidates, err = dnsclient.NewIterator(eth.config.EthDiscoveryURLs...)
@@ -704,6 +717,9 @@ func (s *Ethereum) Stop() error {
704717
}
705718
s.blockchain.Stop()
706719
s.engine.Close()
720+
if s.sequencerRPCService != nil {
721+
s.sequencerRPCService.Close()
722+
}
707723
rawdb.PopUncleanShutdownMarker(s.chainDb)
708724
s.chainDb.Close()
709725
s.eventMux.Stop()

0 commit comments

Comments
 (0)