aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-03-24 17:24:06 +0800
committerMaran <maran.hidskes@gmail.com>2014-03-24 17:24:06 +0800
commit274d5cc91c45349ec8d7a1f5a20ef29896b38b2e (patch)
tree6524987835bcfebd788fd3e89e3a42603cd9f056 /peer.go
parentb52b1fca89fd56549ecc0f086d96a39d6009e568 (diff)
downloaddexon-274d5cc91c45349ec8d7a1f5a20ef29896b38b2e.tar.gz
dexon-274d5cc91c45349ec8d7a1f5a20ef29896b38b2e.tar.zst
dexon-274d5cc91c45349ec8d7a1f5a20ef29896b38b2e.zip
FindCanonicalChain returns true or false when we are on the Canonical chain or not
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/peer.go b/peer.go
index 2cc940400..22bbe7a4c 100644
--- a/peer.go
+++ b/peer.go
@@ -316,11 +316,18 @@ func (p *Peer) HandleInbound() {
// 3. Yes: Let's continue what we are doing
// 4. No: Let's request more blocks back.
+ // Make sure we are actually receiving anything
if msg.Data.Len()-1 > 1 {
+ // We requested blocks and now we need to make sure we have a common ancestor somewhere in these blocks so we can find
+ // common ground to start syncing from
lastBlock = ethchain.NewBlockFromRlpValue(msg.Data.Get(msg.Data.Len() - 1))
if p.ethereum.StateManager().BlockChain().HasBlock(lastBlock.Hash()) {
fmt.Println("[PEER] We found a common ancestor, let's continue.")
} else {
+
+ // If we can't find a common ancenstor we need to request more blocks.
+ // FIXME: At one point this won't scale anymore since we are not asking for an offset
+ // we just keep increasing the amount of blocks.
fmt.Println("[PEER] No common ancestor found, requesting more blocks.")
p.blocksRequested = p.blocksRequested * 2
p.catchingUp = false
@@ -329,14 +336,16 @@ func (p *Peer) HandleInbound() {
for i := msg.Data.Len() - 1; i >= 0; i-- {
block = ethchain.NewBlockFromRlpValue(msg.Data.Get(i))
- // Do we have this block on our chain?
+ // Do we have this block on our chain? If so we can continue
if p.ethereum.StateManager().BlockChain().HasBlock(block.Hash()) {
fmt.Println("[PEER] Block found, checking next one.")
} else {
// We don't have this block, but we do have a block with the same prevHash, diversion time!
if p.ethereum.StateManager().BlockChain().HasBlockWithPrevHash(block.PrevHash) {
fmt.Printf("[PEER] Local and foreign chain have diverted after %x, we are going to get freaky with it!\n", block.PrevHash)
- p.ethereum.StateManager().BlockChain().FindCanonicalChain(msg, block.PrevHash)
+ if p.ethereum.StateManager().BlockChain().FindCanonicalChain(msg, block.PrevHash) {
+ return
+ }
} else {
fmt.Println("[PEER] Both local and foreign chain have same parent. Continue normally")
}
@@ -358,7 +367,6 @@ func (p *Peer) HandleInbound() {
}
break
} else {
- ethutil.Config.Log.Infof("[PEER] Block %x added\n", block.Hash())
lastBlock = block
}
}