core, eth: minor txpool event cleanups
This commit is contained in:
		| @@ -188,8 +188,8 @@ func (b *EthAPIBackend) TxPoolContent() (map[common.Address]types.Transactions, | ||||
| 	return b.eth.TxPool().Content() | ||||
| } | ||||
|  | ||||
| func (b *EthAPIBackend) SubscribeTxPreEvent(ch chan<- core.TxsPreEvent) event.Subscription { | ||||
| 	return b.eth.TxPool().SubscribeTxPreEvent(ch) | ||||
| func (b *EthAPIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { | ||||
| 	return b.eth.TxPool().SubscribeNewTxsEvent(ch) | ||||
| } | ||||
|  | ||||
| func (b *EthAPIBackend) Downloader() *downloader.Downloader { | ||||
|   | ||||
| @@ -105,7 +105,7 @@ func (api *PublicFilterAPI) timeoutLoop() { | ||||
| func (api *PublicFilterAPI) NewPendingTransactionFilter() rpc.ID { | ||||
| 	var ( | ||||
| 		pendingTxs   = make(chan []common.Hash) | ||||
| 		pendingTxSub = api.events.SubscribePendingTxEvents(pendingTxs) | ||||
| 		pendingTxSub = api.events.SubscribePendingTxs(pendingTxs) | ||||
| 	) | ||||
|  | ||||
| 	api.filtersMu.Lock() | ||||
| @@ -145,7 +145,7 @@ func (api *PublicFilterAPI) NewPendingTransactions(ctx context.Context) (*rpc.Su | ||||
|  | ||||
| 	go func() { | ||||
| 		txHashes := make(chan []common.Hash, 128) | ||||
| 		pendingTxSub := api.events.SubscribePendingTxEvents(txHashes) | ||||
| 		pendingTxSub := api.events.SubscribePendingTxs(txHashes) | ||||
|  | ||||
| 		for { | ||||
| 			select { | ||||
|   | ||||
| @@ -36,7 +36,7 @@ type Backend interface { | ||||
| 	GetReceipts(ctx context.Context, blockHash common.Hash) (types.Receipts, error) | ||||
| 	GetLogs(ctx context.Context, blockHash common.Hash) ([][]*types.Log, error) | ||||
|  | ||||
| 	SubscribeTxPreEvent(chan<- core.TxsPreEvent) event.Subscription | ||||
| 	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription | ||||
| 	SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription | ||||
| 	SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription | ||||
| 	SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription | ||||
|   | ||||
| @@ -59,7 +59,7 @@ const ( | ||||
|  | ||||
| const ( | ||||
|  | ||||
| 	// txChanSize is the size of channel listening to TxsPreEvent. | ||||
| 	// txChanSize is the size of channel listening to NewTxsEvent. | ||||
| 	// The number is referenced from the size of tx pool. | ||||
| 	txChanSize = 4096 | ||||
| 	// rmLogsChanSize is the size of channel listening to RemovedLogsEvent. | ||||
| @@ -104,7 +104,7 @@ type EventSystem struct { | ||||
| 	// Channels | ||||
| 	install   chan *subscription         // install filter for event notification | ||||
| 	uninstall chan *subscription         // remove filter for event notification | ||||
| 	txsCh     chan core.TxsPreEvent      // 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 | ||||
| 	rmLogsCh  chan core.RemovedLogsEvent // Channel to receive removed log event | ||||
| 	chainCh   chan core.ChainEvent       // Channel to receive new chain event | ||||
| @@ -123,14 +123,14 @@ func NewEventSystem(mux *event.TypeMux, backend Backend, lightMode bool) *EventS | ||||
| 		lightMode: lightMode, | ||||
| 		install:   make(chan *subscription), | ||||
| 		uninstall: make(chan *subscription), | ||||
| 		txsCh:     make(chan core.TxsPreEvent, txChanSize), | ||||
| 		txsCh:     make(chan core.NewTxsEvent, txChanSize), | ||||
| 		logsCh:    make(chan []*types.Log, logsChanSize), | ||||
| 		rmLogsCh:  make(chan core.RemovedLogsEvent, rmLogsChanSize), | ||||
| 		chainCh:   make(chan core.ChainEvent, chainEvChanSize), | ||||
| 	} | ||||
|  | ||||
| 	// Subscribe events | ||||
| 	m.txsSub = m.backend.SubscribeTxPreEvent(m.txsCh) | ||||
| 	m.txsSub = m.backend.SubscribeNewTxsEvent(m.txsCh) | ||||
| 	m.logsSub = m.backend.SubscribeLogsEvent(m.logsCh) | ||||
| 	m.rmLogsSub = m.backend.SubscribeRemovedLogsEvent(m.rmLogsCh) | ||||
| 	m.chainSub = m.backend.SubscribeChainEvent(m.chainCh) | ||||
| @@ -298,9 +298,9 @@ func (es *EventSystem) SubscribeNewHeads(headers chan *types.Header) *Subscripti | ||||
| 	return es.subscribe(sub) | ||||
| } | ||||
|  | ||||
| // SubscribePendingTxEvents creates a subscription that writes transaction hashes for | ||||
| // SubscribePendingTxs creates a subscription that writes transaction hashes for | ||||
| // transactions that enter the transaction pool. | ||||
| func (es *EventSystem) SubscribePendingTxEvents(hashes chan []common.Hash) *Subscription { | ||||
| func (es *EventSystem) SubscribePendingTxs(hashes chan []common.Hash) *Subscription { | ||||
| 	sub := &subscription{ | ||||
| 		id:        rpc.NewID(), | ||||
| 		typ:       PendingTransactionsSubscription, | ||||
| @@ -348,8 +348,8 @@ func (es *EventSystem) broadcast(filters filterIndex, ev interface{}) { | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	case core.TxsPreEvent: | ||||
| 		hashes := make([]common.Hash, 0, e.Txs.Len()) | ||||
| 	case core.NewTxsEvent: | ||||
| 		hashes := make([]common.Hash, 0, len(e.Txs)) | ||||
| 		for _, tx := range e.Txs { | ||||
| 			hashes = append(hashes, tx.Hash()) | ||||
| 		} | ||||
|   | ||||
| @@ -96,7 +96,7 @@ func (b *testBackend) GetLogs(ctx context.Context, hash common.Hash) ([][]*types | ||||
| 	return logs, nil | ||||
| } | ||||
|  | ||||
| func (b *testBackend) SubscribeTxPreEvent(ch chan<- core.TxsPreEvent) event.Subscription { | ||||
| func (b *testBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { | ||||
| 	return b.txFeed.Subscribe(ch) | ||||
| } | ||||
|  | ||||
| @@ -232,7 +232,7 @@ func TestPendingTxFilter(t *testing.T) { | ||||
| 	fid0 := api.NewPendingTransactionFilter() | ||||
|  | ||||
| 	time.Sleep(1 * time.Second) | ||||
| 	txFeed.Send(core.TxsPreEvent{transactions}) | ||||
| 	txFeed.Send(core.NewTxsEvent{Txs: transactions}) | ||||
|  | ||||
| 	timeout := time.Now().Add(1 * time.Second) | ||||
| 	for { | ||||
|   | ||||
| @@ -46,7 +46,7 @@ const ( | ||||
| 	softResponseLimit = 2 * 1024 * 1024 // Target maximum size of returned blocks, headers or node data. | ||||
| 	estHeaderRlpSize  = 500             // Approximate size of an RLP encoded block header | ||||
|  | ||||
| 	// txChanSize is the size of channel listening to TxsPreEvent. | ||||
| 	// txChanSize is the size of channel listening to NewTxsEvent. | ||||
| 	// The number is referenced from the size of tx pool. | ||||
| 	txChanSize = 4096 | ||||
| ) | ||||
| @@ -81,7 +81,7 @@ type ProtocolManager struct { | ||||
| 	SubProtocols []p2p.Protocol | ||||
|  | ||||
| 	eventMux      *event.TypeMux | ||||
| 	txsCh         chan core.TxsPreEvent | ||||
| 	txsCh         chan core.NewTxsEvent | ||||
| 	txsSub        event.Subscription | ||||
| 	minedBlockSub *event.TypeMuxSubscription | ||||
|  | ||||
| @@ -204,8 +204,8 @@ func (pm *ProtocolManager) Start(maxPeers int) { | ||||
| 	pm.maxPeers = maxPeers | ||||
|  | ||||
| 	// broadcast transactions | ||||
| 	pm.txsCh = make(chan core.TxsPreEvent, txChanSize) | ||||
| 	pm.txsSub = pm.txpool.SubscribeTxPreEvent(pm.txsCh) | ||||
| 	pm.txsCh = make(chan core.NewTxsEvent, txChanSize) | ||||
| 	pm.txsSub = pm.txpool.SubscribeNewTxsEvent(pm.txsCh) | ||||
| 	go pm.txBroadcastLoop() | ||||
|  | ||||
| 	// broadcast mined blocks | ||||
|   | ||||
| @@ -124,7 +124,7 @@ func (p *testTxPool) Pending() (map[common.Address]types.Transactions, error) { | ||||
| 	return batches, nil | ||||
| } | ||||
|  | ||||
| func (p *testTxPool) SubscribeTxPreEvent(ch chan<- core.TxsPreEvent) event.Subscription { | ||||
| func (p *testTxPool) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription { | ||||
| 	return p.txFeed.Subscribe(ch) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -103,9 +103,9 @@ type txPool interface { | ||||
| 	// The slice should be modifiable by the caller. | ||||
| 	Pending() (map[common.Address]types.Transactions, error) | ||||
|  | ||||
| 	// SubscribeTxPreEvent should return an event subscription of | ||||
| 	// TxsPreEvent and send events to the given channel. | ||||
| 	SubscribeTxPreEvent(chan<- core.TxsPreEvent) event.Subscription | ||||
| 	// SubscribeNewTxsEvent should return an event subscription of | ||||
| 	// NewTxsEvent and send events to the given channel. | ||||
| 	SubscribeNewTxsEvent(chan<- core.NewTxsEvent) event.Subscription | ||||
| } | ||||
|  | ||||
| // statusData is the network packet for the status message. | ||||
|   | ||||
| @@ -116,7 +116,7 @@ func testRecvTransactions(t *testing.T, protocol int) { | ||||
| 			t.Errorf("added wrong tx hash: got %v, want %v", added[0].Hash(), tx.Hash()) | ||||
| 		} | ||||
| 	case <-time.After(2 * time.Second): | ||||
| 		t.Errorf("no TxsPreEvent received within 2 seconds") | ||||
| 		t.Errorf("no NewTxsEvent received within 2 seconds") | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user