From b86459a722dcbff00c770ed68f32ed7fd56a85e3 Mon Sep 17 00:00:00 2001 From: Nathan <122502194+NathanBSC@users.noreply.github.com> Date: Thu, 12 Oct 2023 10:20:48 +0800 Subject: [PATCH] core/txpool: ignore nil sub when subpool have been shut down (#1915) Co-authored-by: buddh0 --- core/txpool/txpool.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/txpool/txpool.go b/core/txpool/txpool.go index 24e0c1ce8a..16ddec683a 100644 --- a/core/txpool/txpool.go +++ b/core/txpool/txpool.go @@ -321,7 +321,10 @@ func (p *TxPool) Pending(enforceTips bool) map[common.Address][]*LazyTransaction func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { subs := make([]event.Subscription, len(p.subpools)) for i, subpool := range p.subpools { - subs[i] = subpool.SubscribeTransactions(ch) + sub := subpool.SubscribeTransactions(ch) + if sub != nil { // sub will be nil when subpool have been shut down + subs[i] = sub + } } return p.subs.Track(event.JoinSubscriptions(subs...)) } @@ -331,7 +334,10 @@ func (p *TxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscrip func (p *TxPool) SubscribeReannoTxsEvent(ch chan<- core.ReannoTxsEvent) event.Subscription { subs := make([]event.Subscription, len(p.subpools)) for i, subpool := range p.subpools { - subs[i] = subpool.SubscribeReannoTxsEvent(ch) + sub := subpool.SubscribeReannoTxsEvent(ch) + if sub != nil { // sub will be nil when subpool have been shut down + subs[i] = sub + } } return p.subs.Track(event.JoinSubscriptions(subs...)) }