good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
69d86442
Commit
69d86442
authored
Sep 23, 2015
by
Jeffrey Wilcke
Browse files
Options
Downloads
Plain Diff
Merge pull request #1803 from Gustav-Simonsson/badhashes
core: Add BadHashErr and test for BadHashes handling
parents
36f46a61
bfde1a43
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
core/chain_manager.go
+1
-1
1 addition, 1 deletion
core/chain_manager.go
core/chain_manager_test.go
+54
-1
54 additions, 1 deletion
core/chain_manager_test.go
core/error.go
+11
-0
11 additions, 0 deletions
core/error.go
with
66 additions
and
2 deletions
core/chain_manager.go
+
1
−
1
View file @
69d86442
...
...
@@ -642,7 +642,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
}
if
BadHashes
[
block
.
Hash
()]
{
err
:=
fmt
.
Errorf
(
"Found known bad hash in chain %x"
,
block
.
Hash
())
err
:=
BadHashError
(
block
.
Hash
())
blockErr
(
block
,
err
)
return
i
,
err
}
...
...
This diff is collapsed.
Click to expand it.
core/chain_manager_test.go
+
54
−
1
View file @
69d86442
...
...
@@ -75,7 +75,7 @@ func testFork(t *testing.T, bman *BlockProcessor, i, N int, f func(td1, td2 *big
if
err
!=
nil
{
t
.
Fatal
(
"could not make new canonical in testFork"
,
err
)
}
// asert the bmans have the same block at i
// as
s
ert the bmans have the same block at i
bi1
:=
bman
.
bc
.
GetBlockByNumber
(
uint64
(
i
))
.
Hash
()
bi2
:=
bman2
.
bc
.
GetBlockByNumber
(
uint64
(
i
))
.
Hash
()
if
bi1
!=
bi2
{
...
...
@@ -421,6 +421,59 @@ func TestReorgLongest(t *testing.T) {
}
}
func
TestBadHashes
(
t
*
testing
.
T
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
genesis
,
err
:=
WriteTestNetGenesisBlock
(
db
,
0
)
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
bc
:=
chm
(
genesis
,
db
)
chain
:=
makeChainWithDiff
(
genesis
,
[]
int
{
1
,
2
,
4
},
10
)
BadHashes
[
chain
[
2
]
.
Header
()
.
Hash
()]
=
true
_
,
err
=
bc
.
InsertChain
(
chain
)
if
!
IsBadHashError
(
err
)
{
t
.
Errorf
(
"error mismatch: want: BadHashError, have: %v"
,
err
)
}
}
func
TestReorgBadHashes
(
t
*
testing
.
T
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
genesis
,
err
:=
WriteTestNetGenesisBlock
(
db
,
0
)
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
FailNow
()
}
bc
:=
chm
(
genesis
,
db
)
chain
:=
makeChainWithDiff
(
genesis
,
[]
int
{
1
,
2
,
3
,
4
},
11
)
bc
.
InsertChain
(
chain
)
if
chain
[
3
]
.
Header
()
.
Hash
()
!=
bc
.
LastBlockHash
()
{
t
.
Errorf
(
"last block hash mismatch: want: %x, have: %x"
,
chain
[
3
]
.
Header
()
.
Hash
(),
bc
.
LastBlockHash
())
}
// NewChainManager should check BadHashes when loading it db
BadHashes
[
chain
[
3
]
.
Header
()
.
Hash
()]
=
true
var
eventMux
event
.
TypeMux
ncm
,
err
:=
NewChainManager
(
db
,
FakePow
{},
&
eventMux
)
if
err
!=
nil
{
t
.
Errorf
(
"NewChainManager err: %s"
,
err
)
}
// check it set head to (valid) parent of bad hash block
if
chain
[
2
]
.
Header
()
.
Hash
()
!=
ncm
.
LastBlockHash
()
{
t
.
Errorf
(
"last block hash mismatch: want: %x, have: %x"
,
chain
[
2
]
.
Header
()
.
Hash
(),
ncm
.
LastBlockHash
())
}
if
chain
[
2
]
.
Header
()
.
GasLimit
.
Cmp
(
ncm
.
GasLimit
())
!=
0
{
t
.
Errorf
(
"current block gasLimit mismatch: want: %x, have: %x"
,
chain
[
2
]
.
Header
()
.
GasLimit
,
ncm
.
GasLimit
())
}
}
func
TestReorgShortest
(
t
*
testing
.
T
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
genesis
,
err
:=
WriteTestNetGenesisBlock
(
db
,
0
)
...
...
This diff is collapsed.
Click to expand it.
core/error.go
+
11
−
0
View file @
69d86442
...
...
@@ -177,3 +177,14 @@ func IsValueTransferErr(e error) bool {
_
,
ok
:=
e
.
(
*
ValueTransferError
)
return
ok
}
type
BadHashError
common
.
Hash
func
(
h
BadHashError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"Found known bad hash in chain %x"
,
h
)
}
func
IsBadHashError
(
err
error
)
bool
{
_
,
ok
:=
err
.
(
BadHashError
)
return
ok
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment