aboutsummaryrefslogtreecommitdiffstats
path: root/block_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-22 20:52:20 +0800
committerobscuren <geffobscura@gmail.com>2014-08-22 20:52:20 +0800
commitbe9bfb5536c7410bdd9cb3fbd13fb622bfc00a57 (patch)
tree23ec7bd9267f20a099fbc7a7e5c2759b89fb4fb8 /block_pool.go
parent836ed9d6b70e3ae928624f9ed81ed206a66b85b8 (diff)
downloadgo-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar.gz
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar.bz2
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar.lz
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar.xz
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.tar.zst
go-tangerine-be9bfb5536c7410bdd9cb3fbd13fb622bfc00a57.zip
Minor improvement catching up
* When catching up check linked up the chain of hashes
Diffstat (limited to 'block_pool.go')
-rw-r--r--block_pool.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/block_pool.go b/block_pool.go
index 2be2bc787..e3f0f6ff0 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -1,6 +1,7 @@
package eth
import (
+ "fmt"
"math"
"math/big"
"sync"
@@ -51,6 +52,7 @@ func (self *BlockPool) AddHash(hash []byte) {
func (self *BlockPool) SetBlock(b *ethchain.Block, peer *Peer) {
hash := string(b.Hash())
+ fmt.Printf("::SetBlock %x\n", hash)
if self.pool[hash] == nil {
self.pool[hash] = &block{peer, nil}
@@ -88,13 +90,19 @@ func (self *BlockPool) CheckLinkAndProcess(f func(block *ethchain.Block)) bool {
}
func (self *BlockPool) IsLinked() bool {
- if len(self.hashPool) == 0 || self.pool[string(self.hashPool[0])] == nil {
+ if len(self.hashPool) == 0 {
return false
}
- block := self.pool[string(self.hashPool[0])].block
- if block != nil {
- return self.eth.BlockChain().HasBlock(block.PrevHash)
+ for i := 0; i < len(self.hashPool); i++ {
+ item := self.pool[string(self.hashPool[i])]
+ if item != nil && item.block != nil {
+ if self.eth.BlockChain().HasBlock(item.block.PrevHash) {
+ self.hashPool = self.hashPool[i:]
+
+ return true
+ }
+ }
}
return false