Skip to content

Commit 4c5c0bd

Browse files
committed
Add option to disable sync of mempool transactions
1 parent d771291 commit 4c5c0bd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

bchain/coins/eth/ethrpc.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Configuration struct {
5050
ProcessInternalTransactions bool `json:"processInternalTransactions"`
5151
ProcessZeroInternalTransactions bool `json:"processZeroInternalTransactions"`
5252
ConsensusNodeVersionURL string `json:"consensusNodeVersion"`
53+
DisableMempoolSync bool `json:"disableMempoolSync,omitempty"`
5354
}
5455

5556
// EthereumRPC is an interface to JSON-RPC eth service.
@@ -174,7 +175,7 @@ func (b *EthereumRPC) Initialize() error {
174175
func (b *EthereumRPC) CreateMempool(chain bchain.BlockChain) (bchain.Mempool, error) {
175176
if b.Mempool == nil {
176177
b.Mempool = bchain.NewMempoolEthereumType(chain, b.ChainConfig.MempoolTxTimeoutHours, b.ChainConfig.QueryBackendOnMempoolResync)
177-
glog.Info("mempool created, MempoolTxTimeoutHours=", b.ChainConfig.MempoolTxTimeoutHours, ", QueryBackendOnMempoolResync=", b.ChainConfig.QueryBackendOnMempoolResync)
178+
glog.Info("mempool created, MempoolTxTimeoutHours=", b.ChainConfig.MempoolTxTimeoutHours, ", QueryBackendOnMempoolResync=", b.ChainConfig.QueryBackendOnMempoolResync, ", DisableMempoolSync=", b.ChainConfig.DisableMempoolSync)
178179
}
179180
return b.Mempool, nil
180181
}
@@ -263,21 +264,23 @@ func (b *EthereumRPC) subscribeEvents() error {
263264
}
264265
}()
265266

266-
// new mempool transaction subscription
267-
if err := b.subscribe(func() (bchain.EVMClientSubscription, error) {
268-
// invalidate the previous subscription - it is either the first one or there was an error
269-
b.newTxSubscription = nil
270-
ctx, cancel := context.WithTimeout(context.Background(), b.Timeout)
271-
defer cancel()
272-
sub, err := b.RPC.EthSubscribe(ctx, b.NewTx.Channel(), "newPendingTransactions")
273-
if err != nil {
274-
return nil, errors.Annotatef(err, "EthSubscribe newPendingTransactions")
267+
if !b.ChainConfig.DisableMempoolSync {
268+
// new mempool transaction subscription
269+
if err := b.subscribe(func() (bchain.EVMClientSubscription, error) {
270+
// invalidate the previous subscription - it is either the first one or there was an error
271+
b.newTxSubscription = nil
272+
ctx, cancel := context.WithTimeout(context.Background(), b.Timeout)
273+
defer cancel()
274+
sub, err := b.RPC.EthSubscribe(ctx, b.NewTx.Channel(), "newPendingTransactions")
275+
if err != nil {
276+
return nil, errors.Annotatef(err, "EthSubscribe newPendingTransactions")
277+
}
278+
b.newTxSubscription = sub
279+
glog.Info("Subscribed to newPendingTransactions")
280+
return sub, nil
281+
}); err != nil {
282+
return err
275283
}
276-
b.newTxSubscription = sub
277-
glog.Info("Subscribed to newPendingTransactions")
278-
return sub, nil
279-
}); err != nil {
280-
return err
281284
}
282285

283286
return nil

0 commit comments

Comments
 (0)