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
31f82eb3
Commit
31f82eb3
authored
Apr 24, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth, eth/downloader: don't require td on downloader. Fixed tests
parent
b86e7526
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
25 deletions
+22
-25
backend.go
eth/backend.go
+2
-2
downloader.go
eth/downloader/downloader.go
+1
-4
downloader_test.go
eth/downloader/downloader_test.go
+17
-17
handler.go
eth/handler.go
+2
-2
No files found.
eth/backend.go
View file @
31f82eb3
...
...
@@ -217,7 +217,7 @@ func New(config *Config) (*Ethereum, error) {
}
eth
.
chainManager
=
core
.
NewChainManager
(
blockDb
,
stateDb
,
eth
.
EventMux
())
eth
.
downloader
=
downloader
.
New
(
eth
.
chainManager
.
HasBlock
,
eth
.
chainManager
.
InsertChain
,
eth
.
chainManager
.
Td
)
eth
.
downloader
=
downloader
.
New
(
eth
.
chainManager
.
HasBlock
,
eth
.
chainManager
.
InsertChain
)
eth
.
pow
=
ethash
.
New
(
eth
.
chainManager
)
eth
.
txPool
=
core
.
NewTxPool
(
eth
.
EventMux
(),
eth
.
chainManager
.
State
)
eth
.
blockProcessor
=
core
.
NewBlockProcessor
(
stateDb
,
extraDb
,
eth
.
pow
,
eth
.
txPool
,
eth
.
chainManager
,
eth
.
EventMux
())
...
...
@@ -448,7 +448,7 @@ func (self *Ethereum) SuggestPeer(nodeURL string) error {
}
func
(
s
*
Ethereum
)
Stop
()
{
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
txSub
.
Unsubscribe
()
// quits txBroadcastLoop
s
.
protocolManager
.
Stop
()
s
.
txPool
.
Stop
()
...
...
eth/downloader/downloader.go
View file @
31f82eb3
...
...
@@ -39,7 +39,6 @@ var (
type
hashCheckFn
func
(
common
.
Hash
)
bool
type
chainInsertFn
func
(
types
.
Blocks
)
error
type
hashIterFn
func
()
(
common
.
Hash
,
error
)
type
currentTdFn
func
()
*
big
.
Int
type
blockPack
struct
{
peerId
string
...
...
@@ -61,7 +60,6 @@ type Downloader struct {
// Callbacks
hasBlock
hashCheckFn
insertChain
chainInsertFn
currentTd
currentTdFn
// Status
fetchingHashes
int32
...
...
@@ -76,13 +74,12 @@ type Downloader struct {
quit
chan
struct
{}
}
func
New
(
hasBlock
hashCheckFn
,
insertChain
chainInsertFn
,
currentTd
currentTdFn
)
*
Downloader
{
func
New
(
hasBlock
hashCheckFn
,
insertChain
chainInsertFn
)
*
Downloader
{
downloader
:=
&
Downloader
{
queue
:
newqueue
(),
peers
:
make
(
peers
),
hasBlock
:
hasBlock
,
insertChain
:
insertChain
,
currentTd
:
currentTd
,
newPeerCh
:
make
(
chan
*
peer
,
1
),
syncCh
:
make
(
chan
syncPack
,
1
),
hashCh
:
make
(
chan
[]
common
.
Hash
,
1
),
...
...
eth/downloader/downloader_test.go
View file @
31f82eb3
...
...
@@ -49,7 +49,7 @@ type downloadTester struct {
func
newTester
(
t
*
testing
.
T
,
hashes
[]
common
.
Hash
,
blocks
map
[
common
.
Hash
]
*
types
.
Block
)
*
downloadTester
{
tester
:=
&
downloadTester
{
t
:
t
,
hashes
:
hashes
,
blocks
:
blocks
,
done
:
make
(
chan
bool
)}
downloader
:=
New
(
tester
.
hasBlock
,
tester
.
insertChain
,
func
()
*
big
.
Int
{
return
new
(
big
.
Int
)
}
)
downloader
:=
New
(
tester
.
hasBlock
,
tester
.
insertChain
)
tester
.
downloader
=
downloader
return
tester
...
...
@@ -112,7 +112,8 @@ func TestDownload(t *testing.T) {
minDesiredPeerCount
=
4
blockTtl
=
1
*
time
.
Second
hashes
:=
createHashes
(
0
,
1000
)
targetBlocks
:=
1000
hashes
:=
createHashes
(
0
,
targetBlocks
)
blocks
:=
createBlocksFromHashes
(
hashes
)
tester
:=
newTester
(
t
,
hashes
,
blocks
)
...
...
@@ -121,21 +122,21 @@ func TestDownload(t *testing.T) {
tester
.
badBlocksPeer
(
"peer3"
,
big
.
NewInt
(
0
),
common
.
Hash
{})
tester
.
badBlocksPeer
(
"peer4"
,
big
.
NewInt
(
0
),
common
.
Hash
{})
success
:
select
{
case
<-
tester
.
done
:
break
success
case
<-
time
.
After
(
10
*
time
.
Second
)
:
// XXX this could actually fail on a slow computer
t
.
Error
(
"timeout"
)
blox
,
err
:=
tester
.
downloader
.
Synchronise
(
"peer1"
,
hashes
[
0
])
if
err
!=
nil
{
t
.
Error
(
"download error"
,
err
)
}
if
len
(
blox
)
!=
targetBlocks
{
t
.
Error
(
"expected"
,
targetBlocks
,
"have"
,
len
(
blox
))
}
}
func
TestMissing
(
t
*
testing
.
T
)
{
t
.
Skip
()
glog
.
SetV
(
logger
.
Detail
)
glog
.
SetToStderr
(
true
)
targetBlocks
:=
1000
hashes
:=
createHashes
(
0
,
1000
)
extraHashes
:=
createHashes
(
1001
,
1003
)
blocks
:=
createBlocksFromHashes
(
append
(
extraHashes
,
hashes
...
))
...
...
@@ -146,13 +147,12 @@ func TestMissing(t *testing.T) {
hashes
=
append
(
extraHashes
,
hashes
[
:
len
(
hashes
)
-
1
]
...
)
tester
.
newPeer
(
"peer2"
,
big
.
NewInt
(
0
),
common
.
Hash
{})
success1
:
select
{
case
<-
tester
.
done
:
break
success1
case
<-
time
.
After
(
10
*
time
.
Second
)
:
// XXX this could actually fail on a slow computer
t
.
Error
(
"timout"
)
blox
,
err
:=
tester
.
downloader
.
Synchronise
(
"peer1"
,
hashes
[
0
])
if
err
!=
nil
{
t
.
Error
(
"download error"
,
err
)
}
tester
.
downloader
.
AddBlock
(
"peer2"
,
blocks
[
hashes
[
len
(
hashes
)
-
1
]],
big
.
NewInt
(
10001
))
if
len
(
blox
)
!=
targetBlocks
{
t
.
Error
(
"expected"
,
targetBlocks
,
"have"
,
len
(
blox
))
}
}
eth/handler.go
View file @
31f82eb3
...
...
@@ -134,14 +134,14 @@ out:
if
len
(
pm
.
peers
)
<
minDesiredPeerCount
{
break
}
itimer
.
Stop
()
// Find the best peer
peer
:=
getBestPeer
(
pm
.
peers
)
if
peer
==
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
"Sync attempt cancelled. No peers available"
)
return
}
itimer
.
Stop
()
go
pm
.
synchronise
(
peer
)
case
<-
itimer
.
C
:
// The timer will make sure that the downloader keeps an active state
...
...
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