mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
eth/downloader: clean up PR change. Add some docs where appropriate and remove dead code/parameters/constants
This commit is contained in:
parent
ed3ef9ee64
commit
6ac93500f0
3 changed files with 14 additions and 13 deletions
|
|
@ -206,7 +206,7 @@ func New(stateDb ethdb.Database, mux *event.TypeMux, chain BlockChain, dropPeer
|
|||
dl := &Downloader{
|
||||
stateDB: stateDb,
|
||||
mux: mux,
|
||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
||||
queue: newQueue(),
|
||||
peers: newPeerSet(),
|
||||
blockchain: chain,
|
||||
dropPeer: dropPeer,
|
||||
|
|
@ -352,7 +352,7 @@ func (d *Downloader) synchronise(mode SyncMode, beaconPing chan struct{}) error
|
|||
}
|
||||
}
|
||||
// Reset the queue, peer set and wake channels to clean any internal leftover state
|
||||
d.queue.Reset(blockCacheMaxItems, blockCacheInitialItems)
|
||||
d.queue.Reset()
|
||||
d.peers.Reset()
|
||||
|
||||
for _, ch := range []chan bool{d.queue.blockWakeCh, d.queue.receiptWakeCh} {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ const (
|
|||
|
||||
var (
|
||||
blockCacheMaxItems = 8192 // Maximum number of blocks to cache before throttling the download
|
||||
blockCacheInitialItems = 32 // Initial number of blocks to start fetching, before we know the sizes of the blocks
|
||||
blockCacheMemory = 1024 * 1024 * 1024 // Maximum amount of memory to use for block caching
|
||||
)
|
||||
|
||||
|
|
@ -159,7 +158,7 @@ type queue struct {
|
|||
}
|
||||
|
||||
// newQueue creates a new download queue for scheduling block retrieval.
|
||||
func newQueue(blockCacheLimit int, thresholdInitialSize int) *queue {
|
||||
func newQueue() *queue {
|
||||
lock := new(sync.RWMutex)
|
||||
q := &queue{
|
||||
headerContCh: make(chan bool, 1),
|
||||
|
|
@ -170,12 +169,12 @@ func newQueue(blockCacheLimit int, thresholdInitialSize int) *queue {
|
|||
active: sync.NewCond(lock),
|
||||
lock: lock,
|
||||
}
|
||||
q.Reset(blockCacheLimit, thresholdInitialSize)
|
||||
q.Reset()
|
||||
return q
|
||||
}
|
||||
|
||||
// Reset clears out the queue contents.
|
||||
func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
|
||||
func (q *queue) Reset() {
|
||||
q.lock.Lock()
|
||||
defer q.lock.Unlock()
|
||||
|
||||
|
|
@ -193,7 +192,7 @@ func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
|
|||
q.receiptTaskQueue.Reset()
|
||||
q.receiptPendPool = make(map[string]*fetchRequest)
|
||||
|
||||
q.resultCache = newResultStore(blockCacheLimit)
|
||||
q.resultCache = newResultStore()
|
||||
}
|
||||
|
||||
// Close marks the end of the sync, unblocking Results.
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ type resultStore struct {
|
|||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
func newResultStore(size int) *resultStore {
|
||||
func newResultStore() *resultStore {
|
||||
return &resultStore{
|
||||
resultOffset: 0,
|
||||
items: make([]*fetchResult, size),
|
||||
items: make([]*fetchResult, blockCacheMaxItems),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +99,10 @@ func (r *resultStore) GetDeliverySlot(headerNumber uint64) (*fetchResult, bool,
|
|||
// blocks each contain a transaction filled with calldata that is all zeroes.
|
||||
// The size of a worst-case block is ~= gasUsed / 10
|
||||
func (r *resultStore) throttleThreshold(index int) bool {
|
||||
// estimate the average block size of all scheduled blocks
|
||||
estBlockSize := max((r.itemsGasUsed/(uint64(index)+1))/10, 524)
|
||||
// estimate the average size of a worst-case block, given what we have already queued:
|
||||
// total gas used by in flight blocks / number of in-flight blocks / 10
|
||||
var headerSize uint64 = 524
|
||||
estBlockSize := max((r.itemsGasUsed/(uint64(index)+1))/10, headerSize)
|
||||
|
||||
throttleThreshold := min(uint64(len(r.items)), uint64(blockCacheMemory)/estBlockSize+1)
|
||||
return index >= int(throttleThreshold)
|
||||
|
|
|
|||
Loading…
Reference in a new issue