From 190b04fcbcadf4807c5c2bb0ef9e528bbff62e32 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 21 Oct 2019 16:34:25 -0400 Subject: add NewTxPoolHeadEvent --- core/events.go | 3 +++ core/tx_pool.go | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'core') diff --git a/core/events.go b/core/events.go index 09e9180..aa58d08 100644 --- a/core/events.go +++ b/core/events.go @@ -24,6 +24,9 @@ import ( // NewTxsEvent is posted when a batch of transactions enter the transaction pool. type NewTxsEvent struct{ Txs []*types.Transaction } +// NewTxPoolHeadEvent is posted when the pool head is updated. +type NewTxPoolHeadEvent struct{ block *types.Block } + // PendingLogsEvent is posted pre mining and notifies of pending logs. type PendingLogsEvent struct { Logs []*types.Log diff --git a/core/tx_pool.go b/core/tx_pool.go index caabd5c..3454936 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -213,6 +213,7 @@ type TxPool struct { chain blockChain gasPrice *big.Int txFeed event.Feed + headFeed event.Feed scope event.SubscriptionScope signer types.Signer mu sync.RWMutex @@ -328,6 +329,7 @@ func (pool *TxPool) loop() { if ev.Block != nil { pool.requestReset(head.Header(), ev.Block.Header()) head = ev.Block + pool.headFeed.Send(NewTxPoolHeadEvent{head}) } // System shutdown. @@ -398,6 +400,12 @@ func (pool *TxPool) SubscribeNewTxsEvent(ch chan<- NewTxsEvent) event.Subscripti return pool.scope.Track(pool.txFeed.Subscribe(ch)) } +// SubscribeNewHeadEvent registers a subscription of NewHeadEvent and +// starts sending event to the given channel. +func (pool *TxPool) SubscribeNewHeadEvent(ch chan<- NewTxPoolHeadEvent) event.Subscription { + return pool.scope.Track(pool.headFeed.Subscribe(ch)) +} + // GasPrice returns the current gas price enforced by the transaction pool. func (pool *TxPool) GasPrice() *big.Int { pool.mu.RLock() -- cgit v1.2.3-70-g09d2