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{
|
dl := &Downloader{
|
||||||
stateDB: stateDb,
|
stateDB: stateDb,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
queue: newQueue(blockCacheMaxItems, blockCacheInitialItems),
|
queue: newQueue(),
|
||||||
peers: newPeerSet(),
|
peers: newPeerSet(),
|
||||||
blockchain: chain,
|
blockchain: chain,
|
||||||
dropPeer: dropPeer,
|
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
|
// 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()
|
d.peers.Reset()
|
||||||
|
|
||||||
for _, ch := range []chan bool{d.queue.blockWakeCh, d.queue.receiptWakeCh} {
|
for _, ch := range []chan bool{d.queue.blockWakeCh, d.queue.receiptWakeCh} {
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blockCacheMaxItems = 8192 // Maximum number of blocks to cache before throttling the download
|
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
|
||||||
blockCacheMemory = 1024 * 1024 * 1024 // Maximum amount of memory to use for block caching
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -159,7 +158,7 @@ type queue struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newQueue creates a new download queue for scheduling block retrieval.
|
// newQueue creates a new download queue for scheduling block retrieval.
|
||||||
func newQueue(blockCacheLimit int, thresholdInitialSize int) *queue {
|
func newQueue() *queue {
|
||||||
lock := new(sync.RWMutex)
|
lock := new(sync.RWMutex)
|
||||||
q := &queue{
|
q := &queue{
|
||||||
headerContCh: make(chan bool, 1),
|
headerContCh: make(chan bool, 1),
|
||||||
|
|
@ -170,12 +169,12 @@ func newQueue(blockCacheLimit int, thresholdInitialSize int) *queue {
|
||||||
active: sync.NewCond(lock),
|
active: sync.NewCond(lock),
|
||||||
lock: lock,
|
lock: lock,
|
||||||
}
|
}
|
||||||
q.Reset(blockCacheLimit, thresholdInitialSize)
|
q.Reset()
|
||||||
return q
|
return q
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset clears out the queue contents.
|
// Reset clears out the queue contents.
|
||||||
func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
|
func (q *queue) Reset() {
|
||||||
q.lock.Lock()
|
q.lock.Lock()
|
||||||
defer q.lock.Unlock()
|
defer q.lock.Unlock()
|
||||||
|
|
||||||
|
|
@ -193,7 +192,7 @@ func (q *queue) Reset(blockCacheLimit int, thresholdInitialSize int) {
|
||||||
q.receiptTaskQueue.Reset()
|
q.receiptTaskQueue.Reset()
|
||||||
q.receiptPendPool = make(map[string]*fetchRequest)
|
q.receiptPendPool = make(map[string]*fetchRequest)
|
||||||
|
|
||||||
q.resultCache = newResultStore(blockCacheLimit)
|
q.resultCache = newResultStore()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close marks the end of the sync, unblocking Results.
|
// Close marks the end of the sync, unblocking Results.
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ type resultStore struct {
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newResultStore(size int) *resultStore {
|
func newResultStore() *resultStore {
|
||||||
return &resultStore{
|
return &resultStore{
|
||||||
resultOffset: 0,
|
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.
|
// blocks each contain a transaction filled with calldata that is all zeroes.
|
||||||
// The size of a worst-case block is ~= gasUsed / 10
|
// The size of a worst-case block is ~= gasUsed / 10
|
||||||
func (r *resultStore) throttleThreshold(index int) bool {
|
func (r *resultStore) throttleThreshold(index int) bool {
|
||||||
// estimate the average block size of all scheduled blocks
|
// estimate the average size of a worst-case block, given what we have already queued:
|
||||||
estBlockSize := max((r.itemsGasUsed/(uint64(index)+1))/10, 524)
|
// 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)
|
throttleThreshold := min(uint64(len(r.items)), uint64(blockCacheMemory)/estBlockSize+1)
|
||||||
return index >= int(throttleThreshold)
|
return index >= int(throttleThreshold)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue