les, light: implement ODR transaction lookup by hash (#19069)

* les, light: implement ODR transaction lookup by hash

* les: delete useless file

* internal/ethapi: always use backend to find transaction

* les, eth, internal/ethapi: renamed GetCanonicalTransaction to GetTransaction

* light: add canonical header verification to GetTransaction
This commit is contained in:
Felföldi Zsolt
2019-05-13 13:41:10 +02:00
committed by Péter Szilágyi
parent f4fb1a1801
commit 40cdcf8c47
16 changed files with 182 additions and 51 deletions

View File

@ -17,6 +17,7 @@
package les
import (
"context"
"sync"
"github.com/ethereum/go-ethereum/common"
@ -36,21 +37,27 @@ type LesTxRelay struct {
peerList []*peer
peerStartPos int
lock sync.RWMutex
stop chan struct{}
reqDist *requestDistributor
retriever *retrieveManager
}
func NewLesTxRelay(ps *peerSet, reqDist *requestDistributor) *LesTxRelay {
func NewLesTxRelay(ps *peerSet, retriever *retrieveManager) *LesTxRelay {
r := &LesTxRelay{
txSent: make(map[common.Hash]*ltrInfo),
txPending: make(map[common.Hash]struct{}),
ps: ps,
reqDist: reqDist,
retriever: retriever,
stop: make(chan struct{}),
}
ps.notify(r)
return r
}
func (self *LesTxRelay) Stop() {
close(self.stop)
}
func (self *LesTxRelay) registerPeer(p *peer) {
self.lock.Lock()
defer self.lock.Unlock()
@ -132,7 +139,7 @@ func (self *LesTxRelay) send(txs types.Transactions, count int) {
return func() { peer.SendTxs(reqID, cost, enc) }
},
}
self.reqDist.queue(rq)
go self.retriever.retrieve(context.Background(), reqID, rq, func(p distPeer, msg *Msg) error { return nil }, self.stop)
}
}