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
677836cb
Commit
677836cb
authored
Oct 02, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kick off bad peers on bad chains and improved catch up on diverted chain
parent
a75c9200
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
block_pool.go
block_pool.go
+12
-2
peer.go
peer.go
+7
-8
No files found.
block_pool.go
View file @
677836cb
...
@@ -56,6 +56,11 @@ func (self *BlockPool) Len() int {
...
@@ -56,6 +56,11 @@ func (self *BlockPool) Len() int {
return
len
(
self
.
hashPool
)
return
len
(
self
.
hashPool
)
}
}
func
(
self
*
BlockPool
)
Reset
()
{
self
.
pool
=
make
(
map
[
string
]
*
block
)
self
.
hashPool
=
nil
}
func
(
self
*
BlockPool
)
HasLatestHash
()
bool
{
func
(
self
*
BlockPool
)
HasLatestHash
()
bool
{
self
.
mut
.
Lock
()
self
.
mut
.
Lock
()
defer
self
.
mut
.
Unlock
()
defer
self
.
mut
.
Unlock
()
...
@@ -77,7 +82,7 @@ func (self *BlockPool) Blocks() (blocks ethchain.Blocks) {
...
@@ -77,7 +82,7 @@ func (self *BlockPool) Blocks() (blocks ethchain.Blocks) {
return
return
}
}
func
(
self
*
BlockPool
)
FetchHashes
(
peer
*
Peer
)
{
func
(
self
*
BlockPool
)
FetchHashes
(
peer
*
Peer
)
bool
{
highestTd
:=
self
.
eth
.
HighestTDPeer
()
highestTd
:=
self
.
eth
.
HighestTDPeer
()
if
(
self
.
peer
==
nil
&&
peer
.
td
.
Cmp
(
highestTd
)
>=
0
)
||
(
self
.
peer
!=
nil
&&
peer
.
td
.
Cmp
(
self
.
peer
.
td
)
>=
0
)
||
self
.
peer
==
peer
{
if
(
self
.
peer
==
nil
&&
peer
.
td
.
Cmp
(
highestTd
)
>=
0
)
||
(
self
.
peer
!=
nil
&&
peer
.
td
.
Cmp
(
self
.
peer
.
td
)
>=
0
)
||
self
.
peer
==
peer
{
...
@@ -95,7 +100,11 @@ func (self *BlockPool) FetchHashes(peer *Peer) {
...
@@ -95,7 +100,11 @@ func (self *BlockPool) FetchHashes(peer *Peer) {
peerlogger
.
Debugf
(
"Fetching hashes (%d)
\n
"
,
amount
)
peerlogger
.
Debugf
(
"Fetching hashes (%d)
\n
"
,
amount
)
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
peer
.
lastReceivedHash
,
uint32
(
amount
)}))
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
peer
.
lastReceivedHash
,
uint32
(
amount
)}))
}
}
return
true
}
}
return
false
}
}
func
(
self
*
BlockPool
)
AddHash
(
hash
[]
byte
,
peer
*
Peer
)
{
func
(
self
*
BlockPool
)
AddHash
(
hash
[]
byte
,
peer
*
Peer
)
{
...
@@ -122,7 +131,7 @@ func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) {
...
@@ -122,7 +131,7 @@ func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) {
self
.
pool
[
hash
]
=
&
block
{
peer
,
peer
,
b
,
time
.
Now
(),
0
}
self
.
pool
[
hash
]
=
&
block
{
peer
,
peer
,
b
,
time
.
Now
(),
0
}
if
!
self
.
eth
.
BlockChain
()
.
HasBlock
(
b
.
PrevHash
)
&&
self
.
pool
[
string
(
b
.
PrevHash
)]
==
nil
&&
!
self
.
fetchingHashes
{
if
!
self
.
eth
.
BlockChain
()
.
HasBlock
(
b
.
PrevHash
)
&&
self
.
pool
[
string
(
b
.
PrevHash
)]
==
nil
&&
!
self
.
fetchingHashes
{
poollogger
.
Infof
(
"Unknown
block, requesting parent
(%x...)
\n
"
,
b
.
PrevHash
[
0
:
4
])
poollogger
.
Infof
(
"Unknown
chain, requesting
(%x...)
\n
"
,
b
.
PrevHash
[
0
:
4
])
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
b
.
Hash
(),
uint32
(
256
)}))
peer
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetBlockHashesTy
,
[]
interface
{}{
b
.
Hash
(),
uint32
(
256
)}))
}
}
}
else
if
self
.
pool
[
hash
]
!=
nil
{
}
else
if
self
.
pool
[
hash
]
!=
nil
{
...
@@ -308,6 +317,7 @@ out:
...
@@ -308,6 +317,7 @@ out:
}
}
if
err
!=
nil
{
if
err
!=
nil
{
self
.
Reset
()
// Remove this bad chain
// Remove this bad chain
for
_
,
block
:=
range
blocks
{
for
_
,
block
:=
range
blocks
{
self
.
Remove
(
block
.
Hash
())
self
.
Remove
(
block
.
Hash
())
...
...
peer.go
View file @
677836cb
...
@@ -202,7 +202,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -202,7 +202,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
go
func
()
{
go
func
()
{
conn
,
err
:=
p
.
Connect
(
addr
)
conn
,
err
:=
p
.
Connect
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
peerlogger
.
Debugln
(
"Connection to peer failed. Giving up."
,
err
)
//
peerlogger.Debugln("Connection to peer failed. Giving up.", err)
p
.
Stop
()
p
.
Stop
()
return
return
}
}
...
@@ -517,7 +517,9 @@ func (p *Peer) HandleInbound() {
...
@@ -517,7 +517,9 @@ func (p *Peer) HandleInbound() {
}
}
if
!
foundCommonHash
&&
msg
.
Data
.
Len
()
!=
0
{
if
!
foundCommonHash
&&
msg
.
Data
.
Len
()
!=
0
{
p
.
FetchHashes
()
if
!
p
.
FetchHashes
()
{
p
.
doneFetchingHashes
=
true
}
}
else
{
}
else
{
peerlogger
.
Infof
(
"Found common hash (%x...)
\n
"
,
p
.
lastReceivedHash
[
0
:
4
])
peerlogger
.
Infof
(
"Found common hash (%x...)
\n
"
,
p
.
lastReceivedHash
[
0
:
4
])
p
.
doneFetchingHashes
=
true
p
.
doneFetchingHashes
=
true
...
@@ -553,9 +555,9 @@ func (self *Peer) FetchBlocks(hashes [][]byte) {
...
@@ -553,9 +555,9 @@ func (self *Peer) FetchBlocks(hashes [][]byte) {
}
}
}
}
func
(
self
*
Peer
)
FetchHashes
()
{
func
(
self
*
Peer
)
FetchHashes
()
bool
{
blockPool
:=
self
.
ethereum
.
blockPool
blockPool
:=
self
.
ethereum
.
blockPool
blockPool
.
FetchHashes
(
self
)
return
blockPool
.
FetchHashes
(
self
)
/*
/*
if self.td.Cmp(self.ethereum.HighestTDPeer()) >= 0 {
if self.td.Cmp(self.ethereum.HighestTDPeer()) >= 0 {
...
@@ -718,10 +720,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
...
@@ -718,10 +720,7 @@ func (self *Peer) handleStatus(msg *ethwire.Msg) {
// Compare the total TD with the blockchain TD. If remote is higher
// Compare the total TD with the blockchain TD. If remote is higher
// fetch hashes from highest TD node.
// fetch hashes from highest TD node.
if
self
.
td
.
Cmp
(
self
.
ethereum
.
BlockChain
()
.
TD
)
>
0
{
self
.
FetchHashes
()
self
.
ethereum
.
blockPool
.
AddHash
(
self
.
lastReceivedHash
,
self
)
self
.
FetchHashes
()
}
ethlogger
.
Infof
(
"Peer is [eth] capable. (TD = %v ~ %x) %d / %d"
,
self
.
td
,
self
.
bestHash
,
protoVersion
,
netVersion
)
ethlogger
.
Infof
(
"Peer is [eth] capable. (TD = %v ~ %x) %d / %d"
,
self
.
td
,
self
.
bestHash
,
protoVersion
,
netVersion
)
...
...
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