Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
274d5cc9
Commit
274d5cc9
authored
Mar 24, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FindCanonicalChain returns true or false when we are on the Canonical chain or not
parent
b52b1fca
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
block_chain.go
ethchain/block_chain.go
+4
-1
peer.go
peer.go
+11
-3
No files found.
ethchain/block_chain.go
View file @
274d5cc9
...
...
@@ -103,7 +103,8 @@ func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int {
}
// Is tasked by finding the CanonicalChain and resetting the chain if we are not the Conical one
func
(
bc
*
BlockChain
)
FindCanonicalChain
(
msg
*
ethwire
.
Msg
,
commonBlockHash
[]
byte
)
{
// Return true if we are the using the canonical chain false if not
func
(
bc
*
BlockChain
)
FindCanonicalChain
(
msg
*
ethwire
.
Msg
,
commonBlockHash
[]
byte
)
bool
{
// 1. Calculate TD of the current chain
// 2. Calculate TD of the new chain
// Reset state to the correct one
...
...
@@ -138,8 +139,10 @@ func (bc *BlockChain) FindCanonicalChain(msg *ethwire.Msg, commonBlockHash []byt
if
chainDifficulty
.
Cmp
(
curChainDifficulty
)
==
1
{
log
.
Println
(
"[BCHAIN] The incoming Chain beat our asses, resetting"
)
bc
.
ResetTillBlockHash
(
commonBlockHash
)
return
false
}
else
{
log
.
Println
(
"[BCHAIN] Our chain showed the incoming chain who is boss. Ignoring."
)
return
true
}
}
func
(
bc
*
BlockChain
)
ResetTillBlockHash
(
hash
[]
byte
)
error
{
...
...
peer.go
View file @
274d5cc9
...
...
@@ -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
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment