@@ -36,7 +36,7 @@ type queue struct {
3636 pendPool map [string ]* fetchRequest // Currently pending block retrieval operations
3737
3838 blockPool map [common.Hash ]int // Hash-set of the downloaded data blocks, mapping to cache indexes
39- blockCache []* types. Block // Downloaded but not yet delivered blocks
39+ blockCache []* Block // Downloaded but not yet delivered blocks
4040 blockOffset int // Offset of the first cached block in the block-chain
4141
4242 lock sync.RWMutex
@@ -148,7 +148,7 @@ func (q *queue) Insert(hashes []common.Hash) []common.Hash {
148148
149149// GetHeadBlock retrieves the first block from the cache, or nil if it hasn't
150150// been downloaded yet (or simply non existent).
151- func (q * queue ) GetHeadBlock () * types. Block {
151+ func (q * queue ) GetHeadBlock () * Block {
152152 q .lock .RLock ()
153153 defer q .lock .RUnlock ()
154154
@@ -159,7 +159,7 @@ func (q *queue) GetHeadBlock() *types.Block {
159159}
160160
161161// GetBlock retrieves a downloaded block, or nil if non-existent.
162- func (q * queue ) GetBlock (hash common.Hash ) * types. Block {
162+ func (q * queue ) GetBlock (hash common.Hash ) * Block {
163163 q .lock .RLock ()
164164 defer q .lock .RUnlock ()
165165
@@ -176,18 +176,18 @@ func (q *queue) GetBlock(hash common.Hash) *types.Block {
176176}
177177
178178// TakeBlocks retrieves and permanently removes a batch of blocks from the cache.
179- func (q * queue ) TakeBlocks () types. Blocks {
179+ func (q * queue ) TakeBlocks () [] * Block {
180180 q .lock .Lock ()
181181 defer q .lock .Unlock ()
182182
183183 // Accumulate all available blocks
184- var blocks types. Blocks
184+ blocks := [] * Block {}
185185 for _ , block := range q .blockCache {
186186 if block == nil {
187187 break
188188 }
189189 blocks = append (blocks , block )
190- delete (q .blockPool , block .Hash ())
190+ delete (q .blockPool , block .RawBlock . Hash ())
191191 }
192192 // Delete the blocks from the slice and let them be garbage collected
193193 // without this slice trick the blocks would stay in memory until nil
@@ -312,8 +312,10 @@ func (q *queue) Deliver(id string, blocks []*types.Block) (err error) {
312312 return ErrInvalidChain
313313 }
314314 // Otherwise merge the block and mark the hash block
315- q .blockCache [index ] = block
316-
315+ q .blockCache [index ] = & Block {
316+ RawBlock : block ,
317+ OriginPeer : id ,
318+ }
317319 delete (request .Hashes , hash )
318320 delete (q .hashPool , hash )
319321 q .blockPool [hash ] = int (block .NumberU64 ())
@@ -342,6 +344,6 @@ func (q *queue) Alloc(offset int) {
342344 size = blockCacheLimit
343345 }
344346 if len (q .blockCache ) < size {
345- q .blockCache = append (q .blockCache , make ([]* types. Block , size - len (q .blockCache ))... )
347+ q .blockCache = append (q .blockCache , make ([]* Block , size - len (q .blockCache ))... )
346348 }
347349}
0 commit comments