core,eth,internal/ethapi,les: Extend API Backend to subscribe dropped txs

This extends the API Backend interface and respective implementations with
the ability to subscribe to dropped and rejected transactions.
This commit is contained in:
Austin Roberts 2020-04-08 11:03:20 -05:00
parent 644d8c8f35
commit 29e619a95b
4 changed files with 56 additions and 2 deletions

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 RejectedTxEvent and
// SubscribeRejectedTxEvent registers a subscription of RejectedTxEvent and
// starts sending event to the given channel.
func (pool *TxPool) SubscribeRejectedTxsEvent(ch chan<- RejectedTxEvent) event.Subscription {
func (pool *TxPool) SubscribeRejectedTxEvent(ch chan<- RejectedTxEvent) event.Subscription {
return pool.scope.Track(pool.rejectTxFeed.Subscribe(ch))
}

View file

@ -0,0 +1,21 @@
// This file extends the EthAPIBackend with functions for BlockNative's dropped
// transaction feeds.
//
// As this is part of a fork, and not included in core geth, keeping it in a
// separate file helps protect against potential merge conflicts. If this were
// ever to be merged into core geth, it should be relocated to ./api_backend.go
package eth
import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/event"
)
func (b *EthAPIBackend) SubscribeDropTxsEvent(ch chan<- core.DropTxsEvent) event.Subscription {
return b.eth.TxPool().SubscribeDropTxsEvent(ch)
}
func (b *EthAPIBackend) SubscribeRejectedTxEvent(ch chan<- core.RejectedTxEvent) event.Subscription {
return b.eth.TxPool().SubscribeRejectedTxEvent(ch)
}

View file

@ -73,6 +73,8 @@ type Backend interface {
Stats() (pending int, queued int)
TxPoolContent() (map[common.Address]types.Transactions, map[common.Address]types.Transactions)
SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription
SubscribeRejectedTxEvent(chan<- core.RejectedTxEvent) event.Subscription
SubscribeDropTxsEvent(chan<- core.DropTxsEvent) event.Subscription
// Filter API
BloomStatus() (uint64, uint64)

View file

@ -0,0 +1,31 @@
// This file extends the LesApiBackend with functions for BlockNative's dropped
// transaction feeds.
//
// As this is part of a fork, and not included in core geth, keeping it in a
// separate file helps protect against potential merge conflicts. If this were
// ever to be merged into core geth, it should be relocated to ./api_backend.go
package les
import (
"errors"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/event"
)
type unimplementedSubscription struct{}
func (s *unimplementedSubscription) Unsubscribe() {}
func (s *unimplementedSubscription) Err() <-chan error {
ch := make(chan error, 1)
ch <- errors.New("Subscription type not implemented")
return ch
}
func (b *LesApiBackend) SubscribeDropTxsEvent(ch chan<- core.DropTxsEvent) event.Subscription {
return &unimplementedSubscription{}
}
func (b *LesApiBackend) SubscribeRejectedTxEvent(ch chan<- core.RejectedTxEvent) event.Subscription {
return &unimplementedSubscription{}
}