core: Add rejected feed

Any rejected transactions are sent through the rejected feed
This commit is contained in:
Austin Roberts 2020-04-06 16:29:09 -05:00
parent 4ce83632e9
commit 644d8c8f35
2 changed files with 10 additions and 6 deletions

View file

@ -30,10 +30,10 @@ type DropTxsEvent struct{
Reason string
}
// RejectedTxsEvent is posted when a batch of transactions are removed from the transaction pool
type RejectedTxsEvent struct{
Txs []*types.Transaction
Reason string
// RejectedTxEvent is posted when a transaction is rejected from entering the transaction pool
type RejectedTxEvent struct{
Tx *types.Transaction
Reason error
}
// NewMinedBlockEvent is posted when a block has been imported.

View file

@ -428,9 +428,9 @@ func (pool *TxPool) SubscribeDropTxsEvent(ch chan<- DropTxsEvent) event.Subscrip
return pool.scope.Track(pool.dropTxFeed.Subscribe(ch))
}
// SubscribeRejectedTxsEvent registers a subscription of RejectedTxsEvent and
// SubscribeRejectedTxsEvent registers a subscription of RejectedTxEvent and
// starts sending event to the given channel.
func (pool *TxPool) SubscribeRejectedTxsEvent(ch chan<- RejectedTxsEvent) event.Subscription {
func (pool *TxPool) SubscribeRejectedTxsEvent(ch chan<- RejectedTxEvent) event.Subscription {
return pool.scope.Track(pool.rejectTxFeed.Subscribe(ch))
}
@ -853,6 +853,10 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
for errs[nilSlot] != nil {
nilSlot++
}
pool.rejectTxFeed.Send(RejectedTxEvent{
Tx: txs[nilSlot],
Reason: err,
})
errs[nilSlot] = err
}
// Reorg the pool internals if needed and return