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
a34a971b
Commit
a34a971b
authored
Oct 01, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved blockchain downloading
parent
5fa0173c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
37 deletions
+42
-37
block_pool.go
block_pool.go
+1
-3
peer.go
peer.go
+41
-34
No files found.
block_pool.go
View file @
a34a971b
...
...
@@ -217,9 +217,7 @@ out:
}
})
if
!
self
.
fetchingHashes
&&
len
(
self
.
hashPool
)
>
0
{
self
.
DistributeHashes
()
}
if
self
.
ChainLength
<
len
(
self
.
hashPool
)
{
self
.
ChainLength
=
len
(
self
.
hashPool
)
...
...
peer.go
View file @
a34a971b
...
...
@@ -131,7 +131,7 @@ type Peer struct {
// Last received pong message
lastPong
int64
lastBlockReceived
time
.
Time
LastHashReceived
time
.
Time
doneFetchingHashes
bool
host
[]
byte
port
uint16
...
...
@@ -178,6 +178,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
version
:
ethereum
.
ClientIdentity
()
.
String
(),
protocolCaps
:
ethutil
.
NewValue
(
nil
),
td
:
big
.
NewInt
(
0
),
doneFetchingHashes
:
true
,
}
}
...
...
@@ -194,6 +195,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
version
:
ethereum
.
ClientIdentity
()
.
String
(),
protocolCaps
:
ethutil
.
NewValue
(
nil
),
td
:
big
.
NewInt
(
0
),
doneFetchingHashes
:
true
,
}
// Set up the connection in another goroutine so we don't block the main thread
...
...
@@ -503,20 +505,22 @@ func (p *Peer) HandleInbound() {
it
:=
msg
.
Data
.
NewIterator
()
for
it
.
Next
()
{
hash
:=
it
.
Value
()
.
Bytes
()
p
.
lastReceivedHash
=
hash
if
blockPool
.
HasCommonHash
(
hash
)
{
foundCommonHash
=
true
break
}
p
.
lastReceivedHash
=
hash
p
.
LastHashReceived
=
time
.
Now
()
blockPool
.
AddHash
(
hash
,
p
)
}
if
!
foundCommonHash
&&
msg
.
Data
.
Len
()
!=
0
{
p
.
FetchHashes
()
}
else
{
peerlogger
.
Infof
(
"Found common hash (%x...)
\n
"
,
p
.
lastReceivedHash
[
0
:
4
])
p
.
doneFetchingHashes
=
true
}
case
ethwire
.
MsgBlockTy
:
...
...
@@ -543,11 +547,15 @@ func (p *Peer) HandleInbound() {
func
(
self
*
Peer
)
FetchBlocks
(
hashes
[][]
byte
)
{
if
len
(
hashes
)
>
0
{
peerlogger
.
Debugf
(
"Fetching blocks (%d)
\n
"
,
len
(
hashes
))
self
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetBlocksTy
,
ethutil
.
ByteSliceToInterface
(
hashes
)))
}
}
func
(
self
*
Peer
)
FetchHashes
()
{
self
.
doneFetchingHashes
=
false
blockPool
:=
self
.
ethereum
.
blockPool
if
self
.
td
.
Cmp
(
self
.
ethereum
.
HighestTDPeer
())
>=
0
{
...
...
@@ -562,7 +570,7 @@ func (self *Peer) FetchHashes() {
}
func
(
self
*
Peer
)
FetchingHashes
()
bool
{
return
time
.
Since
(
self
.
LastHashReceived
)
<
200
*
time
.
Millisecond
return
!
self
.
doneFetchingHashes
}
// General update method
...
...
@@ -576,10 +584,9 @@ out:
if
self
.
IsCap
(
"eth"
)
{
var
(
sinceBlock
=
time
.
Since
(
self
.
lastBlockReceived
)
sinceHash
=
time
.
Since
(
self
.
LastHashReceived
)
)
if
sinceBlock
>
5
*
time
.
Second
&&
sinceHash
>
5
*
time
.
Second
{
if
sinceBlock
>
5
*
time
.
Second
{
self
.
catchingUp
=
false
}
}
...
...
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