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
96dad6b6
Unverified
Commit
96dad6b6
authored
Feb 11, 2018
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: don't require state for ancestor lookups
parent
5cf75a30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
downloader.go
eth/downloader/downloader.go
+6
-5
downloader_test.go
eth/downloader/downloader_test.go
+3
-8
No files found.
eth/downloader/downloader.go
View file @
96dad6b6
...
...
@@ -173,8 +173,8 @@ type LightChain interface {
type
BlockChain
interface
{
LightChain
// HasBlock
AndState verifies block and associated states'
presence in the local chain.
HasBlock
AndState
(
common
.
Hash
,
uint64
)
bool
// HasBlock
verifies a block's
presence in the local chain.
HasBlock
(
common
.
Hash
,
uint64
)
bool
// GetBlockByHash retrieves a block from the local chain.
GetBlockByHash
(
common
.
Hash
)
*
types
.
Block
...
...
@@ -582,7 +582,6 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
// Figure out the valid ancestor range to prevent rewrite attacks
floor
,
ceil
:=
int64
(
-
1
),
d
.
lightchain
.
CurrentHeader
()
.
Number
.
Uint64
()
p
.
log
.
Debug
(
"Looking for common ancestor"
,
"local"
,
ceil
,
"remote"
,
height
)
if
d
.
mode
==
FullSync
{
ceil
=
d
.
blockchain
.
CurrentBlock
()
.
NumberU64
()
}
else
if
d
.
mode
==
FastSync
{
...
...
@@ -591,6 +590,8 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
if
ceil
>=
MaxForkAncestry
{
floor
=
int64
(
ceil
-
MaxForkAncestry
)
}
p
.
log
.
Debug
(
"Looking for common ancestor"
,
"local"
,
ceil
,
"remote"
,
height
)
// Request the topmost blocks to short circuit binary ancestor lookup
head
:=
ceil
if
head
>
height
{
...
...
@@ -646,7 +647,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
continue
}
// Otherwise check if we already know the header or not
if
(
d
.
mode
==
FullSync
&&
d
.
blockchain
.
HasBlock
AndState
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
d
.
lightchain
.
HasHeader
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
{
if
(
d
.
mode
==
FullSync
&&
d
.
blockchain
.
HasBlock
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
d
.
lightchain
.
HasHeader
(
headers
[
i
]
.
Hash
(),
headers
[
i
]
.
Number
.
Uint64
()))
{
number
,
hash
=
headers
[
i
]
.
Number
.
Uint64
(),
headers
[
i
]
.
Hash
()
// If every header is known, even future ones, the peer straight out lied about its head
...
...
@@ -711,7 +712,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
arrived
=
true
// Modify the search interval based on the response
if
(
d
.
mode
==
FullSync
&&
!
d
.
blockchain
.
HasBlock
AndState
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
!
d
.
lightchain
.
HasHeader
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
{
if
(
d
.
mode
==
FullSync
&&
!
d
.
blockchain
.
HasBlock
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
||
(
d
.
mode
!=
FullSync
&&
!
d
.
lightchain
.
HasHeader
(
headers
[
0
]
.
Hash
(),
headers
[
0
]
.
Number
.
Uint64
()))
{
end
=
check
break
}
...
...
eth/downloader/downloader_test.go
View file @
96dad6b6
...
...
@@ -221,14 +221,9 @@ func (dl *downloadTester) HasHeader(hash common.Hash, number uint64) bool {
return
dl
.
GetHeaderByHash
(
hash
)
!=
nil
}
// HasBlockAndState checks if a block and associated state is present in the testers canonical chain.
func
(
dl
*
downloadTester
)
HasBlockAndState
(
hash
common
.
Hash
,
number
uint64
)
bool
{
block
:=
dl
.
GetBlockByHash
(
hash
)
if
block
==
nil
{
return
false
}
_
,
err
:=
dl
.
stateDb
.
Get
(
block
.
Root
()
.
Bytes
())
return
err
==
nil
// HasBlock checks if a block is present in the testers canonical chain.
func
(
dl
*
downloadTester
)
HasBlock
(
hash
common
.
Hash
,
number
uint64
)
bool
{
return
dl
.
GetBlockByHash
(
hash
)
!=
nil
}
// GetHeader retrieves a header from the testers canonical 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