downloader: return an error for peer.fetch and return chunk to queue
If a peer was somehow already fetching and somehow managed to end up in the `available` pool it should return it's work.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package downloader
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math/big"
|
||||
"sync"
|
||||
|
||||
@@ -31,10 +32,14 @@ func newPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn,
|
||||
}
|
||||
|
||||
// fetch a chunk using the peer
|
||||
func (p *peer) fetch(chunk *chunk) {
|
||||
func (p *peer) fetch(chunk *chunk) error {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
|
||||
if p.state == workingState {
|
||||
return errors.New("peer already fetching chunk")
|
||||
}
|
||||
|
||||
// set working state
|
||||
p.state = workingState
|
||||
// convert the set to a fetchable slice
|
||||
@@ -45,4 +50,6 @@ func (p *peer) fetch(chunk *chunk) {
|
||||
return true
|
||||
})
|
||||
p.getBlocks(hashes)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user