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
166853ae
Commit
166853ae
authored
May 14, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test
parent
98a631b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
26 deletions
+17
-26
peer.go
peer.go
+17
-26
No files found.
peer.go
View file @
166853ae
...
...
@@ -299,28 +299,6 @@ func (p *Peer) HandleInbound() {
var
block
,
lastBlock
*
ethchain
.
Block
var
err
error
// 1. Compare the first block over the wire's prev-hash with the hash of your last block
// 2. If these two values are the same you can just link the chains together.
// [1:0,2:1,3:2] <- Current blocks (format block:previous_block)
// [1:0,2:1,3:2,4:3,5:4] <- incoming blocks
// == [1,2,3,4,5]
// 3. If the values are not the same we will have to go back and calculate the chain with the highest total difficulty
// [1:0,2:1,3:2,11:3,12:11,13:12]
// [1:0,2:1,3:2,4:3,5:4,6:5]
// [3:2,11:3,12:11,13:12]
// [3:2,4:3,5:4,6:5]
// Heb ik dit blok?
// Nee: heb ik een blok met PrevHash 3?
// Ja: DIVERSION
// Nee; Adding to chain
// See if we can find a common ancestor
// 1. Get the earliest block in the package.
// 2. Do we have this block?
// 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
&&
p
.
catchingUp
{
// We requested blocks and now we need to make sure we have a common ancestor somewhere in these blocks so we can find
...
...
@@ -342,8 +320,9 @@ func (p *Peer) HandleInbound() {
if
!
p
.
ethereum
.
StateManager
()
.
BlockChain
()
.
HasBlock
(
block
.
Hash
())
{
// 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
)
{
//ethutil.Config.Log.Infof("[PEER] Local and foreign chain have diverted after %x, finding best chain!\n", block.PrevHash)
if
p
.
ethereum
.
StateManager
()
.
BlockChain
()
.
FindCanonicalChainFromMsg
(
msg
,
block
.
PrevHash
)
{
p
.
catchingUp
=
false
return
}
}
...
...
@@ -375,7 +354,8 @@ func (p *Peer) HandleInbound() {
p
.
catchingUp
=
false
p
.
CatchupWithPeer
(
p
.
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
())
}
else
if
ethchain
.
IsValidationErr
(
err
)
{
// TODO
fmt
.
Println
(
err
)
p
.
catchingUp
=
false
}
}
else
{
// XXX Do we want to catch up if there were errors?
...
...
@@ -385,12 +365,20 @@ func (p *Peer) HandleInbound() {
blockInfo
:=
lastBlock
.
BlockInfo
()
ethutil
.
Config
.
Log
.
Infof
(
"Synced to block height #%d %x %x
\n
"
,
blockInfo
.
Number
,
lastBlock
.
Hash
(),
blockInfo
.
Hash
)
}
p
.
catchingUp
=
false
p
.
CatchupWithPeer
(
p
.
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
())
hash
:=
p
.
ethereum
.
BlockChain
()
.
CurrentBlock
.
Hash
()
p
.
CatchupWithPeer
(
hash
)
}
}
p
.
catchingUp
=
false
if
lastBlock
!=
nil
&&
err
==
nil
{
fmt
.
Println
(
"Did proc. no err"
)
}
else
{
fmt
.
Println
(
"other"
)
}
fmt
.
Println
(
"length of chain"
,
msg
.
Data
.
Len
())
case
ethwire
.
MsgTxTy
:
// If the message was a transaction queue the transaction
// in the TxPool where it will undergo validation and
...
...
@@ -453,7 +441,10 @@ func (p *Peer) HandleInbound() {
if
len
(
chain
)
>
0
{
ethutil
.
Config
.
Log
.
Debugf
(
"[PEER] Returning %d blocks: %x "
,
len
(
chain
),
parent
.
Hash
())
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
chain
))
}
else
{
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgBlockTy
,
[]
interface
{}))
}
}
else
{
ethutil
.
Config
.
Log
.
Debugf
(
"[PEER] Could not find a similar block"
)
// If no blocks are found we send back a reply with msg not in chain
...
...
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