Update filter_system.go

This commit is contained in:
Ragnar 2025-02-28 16:49:10 +01:00 committed by GitHub
parent dd5634ac32
commit a5e54b6b0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -67,7 +67,6 @@ type Backend interface {
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription
SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
SubscribeRemovedLogsReverseEvent(ch chan<- core.RemovedLogsEvent) event.Subscription
SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription
BloomStatus() (uint64, uint64) BloomStatus() (uint64, uint64)
@ -190,20 +189,18 @@ type EventSystem struct {
sys *FilterSystem sys *FilterSystem
// Subscriptions // Subscriptions
txsSub event.Subscription // Subscription for new transaction event txsSub event.Subscription // Subscription for new transaction event
logsSub event.Subscription // Subscription for new log event logsSub event.Subscription // Subscription for new log event
rmLogsSub event.Subscription // Subscription for removed log event rmLogsSub event.Subscription // Subscription for removed log event
rmLogsReverseSub event.Subscription // Subscription for removed log event in reverse order chainSub event.Subscription // Subscription for new chain event
chainSub event.Subscription // Subscription for new chain event
// Channels // Channels
install chan *subscription // install filter for event notification install chan *subscription // install filter for event notification
uninstall chan *subscription // remove filter for event notification uninstall chan *subscription // remove filter for event notification
txsCh chan core.NewTxsEvent // Channel to receive new transactions event txsCh chan core.NewTxsEvent // Channel to receive new transactions event
logsCh chan []*types.Log // Channel to receive new log event logsCh chan []*types.Log // Channel to receive new log event
rmLogsCh chan core.RemovedLogsEvent // Channel to receive removed log event rmLogsCh chan core.RemovedLogsEvent // Channel to receive removed log event
rmLogsReverseCh chan core.RemovedLogsEvent // Channel to receive removed log event in reverse order chainCh chan core.ChainEvent // Channel to receive new chain event
chainCh chan core.ChainEvent // Channel to receive new chain event
} }
// NewEventSystem creates a new manager that listens for event on the given mux, // NewEventSystem creates a new manager that listens for event on the given mux,
@ -214,26 +211,24 @@ type EventSystem struct {
// or by stopping the given mux. // or by stopping the given mux.
func NewEventSystem(sys *FilterSystem) *EventSystem { func NewEventSystem(sys *FilterSystem) *EventSystem {
m := &EventSystem{ m := &EventSystem{
sys: sys, sys: sys,
backend: sys.backend, backend: sys.backend,
install: make(chan *subscription), install: make(chan *subscription),
uninstall: make(chan *subscription), uninstall: make(chan *subscription),
txsCh: make(chan core.NewTxsEvent, txChanSize), txsCh: make(chan core.NewTxsEvent, txChanSize),
logsCh: make(chan []*types.Log, logsChanSize), logsCh: make(chan []*types.Log, logsChanSize),
rmLogsCh: make(chan core.RemovedLogsEvent, rmLogsChanSize), rmLogsCh: make(chan core.RemovedLogsEvent, rmLogsChanSize),
rmLogsReverseCh: make(chan core.RemovedLogsEvent, rmLogsChanSize), chainCh: make(chan core.ChainEvent, chainEvChanSize),
chainCh: make(chan core.ChainEvent, chainEvChanSize),
} }
// Subscribe events // Subscribe events
m.txsSub = m.backend.SubscribeNewTxsEvent(m.txsCh) m.txsSub = m.backend.SubscribeNewTxsEvent(m.txsCh)
m.logsSub = m.backend.SubscribeLogsEvent(m.logsCh) m.logsSub = m.backend.SubscribeLogsEvent(m.logsCh)
m.rmLogsSub = m.backend.SubscribeRemovedLogsEvent(m.rmLogsCh) m.rmLogsSub = m.backend.SubscribeRemovedLogsEvent(m.rmLogsCh)
m.rmLogsReverseSub = m.backend.SubscribeRemovedLogsReverseEvent(m.rmLogsReverseCh)
m.chainSub = m.backend.SubscribeChainEvent(m.chainCh) m.chainSub = m.backend.SubscribeChainEvent(m.chainCh)
// Make sure none of the subscriptions are empty // Make sure none of the subscriptions are empty
if m.txsSub == nil || m.logsSub == nil || m.rmLogsSub == nil || m.rmLogsReverseSub == nil || m.chainSub == nil { if m.txsSub == nil || m.logsSub == nil || m.rmLogsSub == nil || m.chainSub == nil {
log.Crit("Subscribe for event system failed") log.Crit("Subscribe for event system failed")
} }
@ -407,7 +402,6 @@ func (es *EventSystem) eventLoop() {
es.txsSub.Unsubscribe() es.txsSub.Unsubscribe()
es.logsSub.Unsubscribe() es.logsSub.Unsubscribe()
es.rmLogsSub.Unsubscribe() es.rmLogsSub.Unsubscribe()
es.rmLogsReverseSub.Unsubscribe()
es.chainSub.Unsubscribe() es.chainSub.Unsubscribe()
}() }()
@ -424,8 +418,6 @@ func (es *EventSystem) eventLoop() {
es.handleLogs(index, ev) es.handleLogs(index, ev)
case ev := <-es.rmLogsCh: case ev := <-es.rmLogsCh:
es.handleLogs(index, ev.Logs) es.handleLogs(index, ev.Logs)
case ev := <-es.rmLogsReverseCh:
es.handleLogs(index, ev.Logs)
case ev := <-es.chainCh: case ev := <-es.chainCh:
es.handleChainEvent(index, ev) es.handleChainEvent(index, ev)
@ -444,8 +436,6 @@ func (es *EventSystem) eventLoop() {
return return
case <-es.rmLogsSub.Err(): case <-es.rmLogsSub.Err():
return return
case <-es.rmLogsReverseSub.Err():
return
case <-es.chainSub.Err(): case <-es.chainSub.Err():
return return
} }