mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth/downloader: minor fixes after review call
This commit is contained in:
parent
78c5d8d324
commit
1d5b5864d7
3 changed files with 19 additions and 23 deletions
|
|
@ -261,7 +261,7 @@ func (dl *downloadTester) InsertHeaderChain(headers []*types.Header, checkFreq i
|
|||
defer dl.lock.Unlock()
|
||||
// Do a quick check, as the blockchain.InsertHeaderChain doesn't insert anything in case of errors
|
||||
if _, ok := dl.getHeader(headers[0].ParentHash); !ok {
|
||||
return 0, errors.New("unknown parentx")
|
||||
return 0, errors.New("unknown parent")
|
||||
}
|
||||
for i := 1; i < len(headers); i++ {
|
||||
if headers[i].ParentHash != headers[i-1].Hash() {
|
||||
|
|
|
|||
|
|
@ -860,7 +860,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header,
|
|||
q.lock.Lock()
|
||||
var acceptCount = 0
|
||||
for _, header := range request.Headers[:i] {
|
||||
if res, stale, err := q.resultCache.GetFetchResult(header); err == nil {
|
||||
if res, stale, err := q.resultCache.GetDeliverySlot(header); err == nil {
|
||||
reconstruct(acceptCount, res)
|
||||
} else {
|
||||
// else: betweeen here and above, some other peer filled this result,
|
||||
|
|
|
|||
|
|
@ -73,29 +73,25 @@ func (r *resultStore) SetThrottleThreshold(threshold uint64) {
|
|||
// prio right now
|
||||
// fetchResult -- the result to store data into
|
||||
// err -- any error that occurred
|
||||
func (r *resultStore) AddFetch(header *types.Header, fastSync bool) (stale, throttled bool, item *fetchResult, err error) {
|
||||
func (r *resultStore) AddFetch(header *types.Header, fastSync bool) (bool, bool, *fetchResult, error) {
|
||||
header.Hash()
|
||||
r.lock.RLock()
|
||||
var index int
|
||||
if item, index, stale, throttled, err = r.getFetchResult(header); err != nil {
|
||||
item, index, stale, throttled, err := r.getFetchResult(header)
|
||||
if err != nil || stale || throttled {
|
||||
r.lock.RUnlock()
|
||||
return
|
||||
}
|
||||
if stale {
|
||||
r.lock.RUnlock()
|
||||
return
|
||||
}
|
||||
if throttled {
|
||||
// Index is above the current threshold of 'prioritized' blocks,
|
||||
log.Debug("resultcache throttle", "index", index, "threshold", r.throttleThreshold)
|
||||
r.lock.RUnlock()
|
||||
return
|
||||
if throttled {
|
||||
log.Debug("resultcache throttle", "index", index, "threshold", r.throttleThreshold)
|
||||
|
||||
}
|
||||
return stale, throttled, item, err
|
||||
}
|
||||
if item != nil {
|
||||
// All good, item already exists (perhaps a receipt fetch following
|
||||
// a body fetch)
|
||||
r.lock.RUnlock()
|
||||
return
|
||||
return stale, throttled, item, err
|
||||
}
|
||||
r.lock.RUnlock()
|
||||
// Need to create a fetchresult, and as we've just release the Rlock,
|
||||
|
|
@ -103,22 +99,22 @@ func (r *resultStore) AddFetch(header *types.Header, fastSync bool) (stale, thro
|
|||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
// Same checks as above, now with wlock
|
||||
if item, index, stale, throttled, err = r.getFetchResult(header); err != nil {
|
||||
return
|
||||
}
|
||||
if stale || throttled {
|
||||
return
|
||||
item, index, stale, throttled, err = r.getFetchResult(header)
|
||||
if err != nil || stale || throttled {
|
||||
return stale, throttled, item, err
|
||||
}
|
||||
if item == nil {
|
||||
item = newFetchResult(header, fastSync)
|
||||
r.items[index] = item
|
||||
}
|
||||
return
|
||||
return stale, throttled, item, err
|
||||
}
|
||||
|
||||
// GetFetchResult returns the fetchResult for the given header. If the 'stale' flag
|
||||
// GetDeliverySlot returns the fetchResult for the given header. If the 'stale' flag
|
||||
// is true, that means the header has already been delivered 'upstream'.
|
||||
func (r *resultStore) GetFetchResult(header *types.Header) (*fetchResult, bool, error) {
|
||||
// This method does not bubble up the 'throttle' flag, since it's moot at the
|
||||
// point in time when the item is downloaded and ready for delivery
|
||||
func (r *resultStore) GetDeliverySlot(header *types.Header) (*fetchResult, bool, error) {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
res, _, stale, _, err := r.getFetchResult(header)
|
||||
|
|
|
|||
Loading…
Reference in a new issue