aboutsummaryrefslogtreecommitdiffstats
path: root/block_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-04 19:46:33 +0800
committerobscuren <geffobscura@gmail.com>2014-11-04 19:46:33 +0800
commit699dcaf65ced99517724984f5930845417cfdfca (patch)
tree36bdb1d1c992924750088b431cac94566df443cd /block_pool.go
parentf4b717cb9da6113304f243caea6a3799a1aeecf3 (diff)
downloaddexon-699dcaf65ced99517724984f5930845417cfdfca.tar.gz
dexon-699dcaf65ced99517724984f5930845417cfdfca.tar.zst
dexon-699dcaf65ced99517724984f5930845417cfdfca.zip
Reworked chain handling process
* Forks * Rename * Moved inserting of blocks & processing * Added chain testing method for validating pieces of a **a** chain.
Diffstat (limited to 'block_pool.go')
-rw-r--r--block_pool.go40
1 files changed, 17 insertions, 23 deletions
diff --git a/block_pool.go b/block_pool.go
index 9003256fd..ff0675c50 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -313,31 +313,25 @@ out:
// If caught up and just a new block has been propagated:
// sm.eth.EventMux().Post(NewBlockEvent{block})
// otherwise process and don't emit anything
- var err error
- for i, block := range blocks {
- err = self.eth.BlockManager().Process(block)
+ if len(blocks) > 0 {
+ chainManager := self.eth.ChainManager()
+ chain := chain.NewChain(blocks)
+ _, err := chainManager.TestChain(chain)
if err != nil {
- poollogger.Infoln(err)
- poollogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
- poollogger.Debugln(block)
-
- blocks = blocks[i:]
-
- break
+ self.Reset()
+
+ poollogger.Debugf("Punishing peer for supplying bad chain (%v)\n", self.peer.conn.RemoteAddr())
+ // This peer gave us bad hashes and made us fetch a bad chain, therefor he shall be punished.
+ self.eth.BlacklistPeer(self.peer)
+ self.peer.StopWithReason(DiscBadPeer)
+ self.td = ethutil.Big0
+ self.peer = nil
+ } else {
+ chainManager.InsertChain(chain)
+ for _, block := range blocks {
+ self.Remove(block.Hash())
+ }
}
-
- self.Remove(block.Hash())
- }
-
- if err != nil {
- self.Reset()
-
- poollogger.Debugf("Punishing peer for supplying bad chain (%v)\n", self.peer.conn.RemoteAddr())
- // This peer gave us bad hashes and made us fetch a bad chain, therefor he shall be punished.
- self.eth.BlacklistPeer(self.peer)
- self.peer.StopWithReason(DiscBadPeer)
- self.td = ethutil.Big0
- self.peer = nil
}
}
}