mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/fetcher: convert to method
This commit is contained in:
parent
3f43370ed4
commit
bc06583957
1 changed files with 14 additions and 17 deletions
|
|
@ -227,24 +227,15 @@ func (f *TxFetcher) Notify(peer string, hashes []common.Hash) error {
|
|||
// loop, so anything caught here is time saved internally.
|
||||
var (
|
||||
unknowns = make([]common.Hash, 0, len(hashes))
|
||||
duplicate, underpriced int64
|
||||
duplicate int64
|
||||
underpriced int64
|
||||
)
|
||||
isUnderpriced := func(hash common.Hash) bool {
|
||||
prevTime, ok := f.underpriced.Peek(hash)
|
||||
if ok && prevTime+maxTxUnderpricedTimeout < time.Now().Unix() {
|
||||
f.underpriced.Remove(hash)
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
||||
for _, hash := range hashes {
|
||||
switch {
|
||||
case f.hasTx(hash):
|
||||
duplicate++
|
||||
|
||||
case isUnderpriced(hash):
|
||||
case f.isKnownUnderpriced(hash):
|
||||
underpriced++
|
||||
|
||||
default:
|
||||
unknowns = append(unknowns, hash)
|
||||
}
|
||||
|
|
@ -256,10 +247,7 @@ func (f *TxFetcher) Notify(peer string, hashes []common.Hash) error {
|
|||
if len(unknowns) == 0 {
|
||||
return nil
|
||||
}
|
||||
announce := &txAnnounce{
|
||||
origin: peer,
|
||||
hashes: unknowns,
|
||||
}
|
||||
announce := &txAnnounce{origin: peer, hashes: unknowns}
|
||||
select {
|
||||
case f.notify <- announce:
|
||||
return nil
|
||||
|
|
@ -268,6 +256,15 @@ func (f *TxFetcher) Notify(peer string, hashes []common.Hash) error {
|
|||
}
|
||||
}
|
||||
|
||||
func (f *TxFetcher) isKnownUnderpriced(hash common.Hash) bool {
|
||||
prevTime, ok := f.underpriced.Peek(hash)
|
||||
if ok && prevTime+maxTxUnderpricedTimeout < time.Now().Unix() {
|
||||
f.underpriced.Remove(hash)
|
||||
return false
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// Enqueue imports a batch of received transaction into the transaction pool
|
||||
// and the fetcher. This method may be called by both transaction broadcasts and
|
||||
// direct request replies. The differentiation is important so the fetcher can
|
||||
|
|
|
|||
Loading…
Reference in a new issue