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
735b029d
Commit
735b029d
authored
10 years ago
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: return the index of the block that failed when inserting a chain
parent
764e81bf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
15 additions
and
14 deletions
+15
-14
cmd.go
cmd/utils/cmd.go
+2
-2
chain_makers.go
core/chain_makers.go
+1
-1
chain_manager.go
core/chain_manager.go
+5
-3
downloader.go
eth/downloader/downloader.go
+4
-5
handler.go
eth/handler.go
+1
-1
worker.go
miner/worker.go
+1
-1
block_test_util.go
tests/block_test_util.go
+1
-1
No files found.
cmd/utils/cmd.go
View file @
735b029d
...
...
@@ -172,7 +172,7 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
n
++
if
n
==
batchSize
{
if
err
:=
chainmgr
.
InsertChain
(
blocks
);
err
!=
nil
{
if
_
,
err
:=
chainmgr
.
InsertChain
(
blocks
);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid block %v"
,
err
)
}
n
=
0
...
...
@@ -181,7 +181,7 @@ func ImportChain(chainmgr *core.ChainManager, fn string) error {
}
if
n
>
0
{
if
err
:=
chainmgr
.
InsertChain
(
blocks
[
:
n
]);
err
!=
nil
{
if
_
,
err
:=
chainmgr
.
InsertChain
(
blocks
[
:
n
]);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid block %v"
,
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
core/chain_makers.go
View file @
735b029d
...
...
@@ -141,6 +141,6 @@ func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
return
bman
,
nil
}
lchain
:=
makeChain
(
bman
,
parent
,
n
,
db
,
CanonicalSeed
)
err
:=
bman
.
bc
.
InsertChain
(
lchain
)
_
,
err
:=
bman
.
bc
.
InsertChain
(
lchain
)
return
bman
,
err
}
This diff is collapsed.
Click to expand it.
core/chain_manager.go
View file @
735b029d
...
...
@@ -497,7 +497,9 @@ func (self *ChainManager) procFutureBlocks() {
self
.
InsertChain
(
blocks
)
}
func
(
self
*
ChainManager
)
InsertChain
(
chain
types
.
Blocks
)
error
{
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
func
(
self
*
ChainManager
)
InsertChain
(
chain
types
.
Blocks
)
(
int
,
error
)
{
// A queued approach to delivering events. This is generally faster than direct delivery and requires much less mutex acquiring.
var
(
queue
=
make
([]
interface
{},
len
(
chain
))
...
...
@@ -540,7 +542,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
glog
.
V
(
logger
.
Error
)
.
Infoln
(
err
)
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
block
)
return
err
return
i
,
err
}
block
.
Td
=
new
(
big
.
Int
)
.
Set
(
CalculateTD
(
block
,
self
.
GetBlock
(
block
.
ParentHash
())))
...
...
@@ -613,7 +615,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
go
self
.
eventMux
.
Post
(
queueEvent
)
return
nil
return
0
,
nil
}
// diff takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
...
...
This diff is collapsed.
Click to expand it.
eth/downloader/downloader.go
View file @
735b029d
...
...
@@ -37,7 +37,7 @@ var (
)
type
hashCheckFn
func
(
common
.
Hash
)
bool
type
chainInsertFn
func
(
types
.
Blocks
)
error
type
chainInsertFn
func
(
types
.
Blocks
)
(
int
,
error
)
type
hashIterFn
func
()
(
common
.
Hash
,
error
)
type
blockPack
struct
{
...
...
@@ -432,12 +432,11 @@ func (d *Downloader) process(peer *peer) error {
// TODO check for parent error. When there's a parent error we should stop
// processing and start requesting the `block.hash` so that it's parent and
// grandparents can be requested and queued.
err
=
d
.
insertChain
(
blocks
[
:
max
])
var
i
int
i
,
err
=
d
.
insertChain
(
blocks
[
:
max
])
if
err
!=
nil
&&
core
.
IsParentErr
(
err
)
{
glog
.
V
(
logger
.
Debug
)
.
Info
ln
(
"Aborting process due to missing parent."
)
glog
.
V
(
logger
.
Debug
)
.
Info
f
(
"Aborting process due to missing parent (%d)
\n
"
,
i
)
// XXX this needs a lot of attention
blocks
=
nil
break
}
else
if
err
!=
nil
{
// immediatly unregister the false peer but do not disconnect
...
...
This diff is collapsed.
Click to expand it.
eth/handler.go
View file @
735b029d
...
...
@@ -376,7 +376,7 @@ func (self *ProtocolManager) handleMsg(p *peer) error {
// if the parent exists we process the block and propagate to our peers
// if the parent does not exists we delegate to the downloader.
if
self
.
chainman
.
HasBlock
(
request
.
Block
.
ParentHash
())
{
if
err
:=
self
.
chainman
.
InsertChain
(
types
.
Blocks
{
request
.
Block
});
err
!=
nil
{
if
_
,
err
:=
self
.
chainman
.
InsertChain
(
types
.
Blocks
{
request
.
Block
});
err
!=
nil
{
// handle error
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
miner/worker.go
View file @
735b029d
...
...
@@ -184,7 +184,7 @@ func (self *worker) wait() {
continue
}
if
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
block
});
err
==
nil
{
if
_
,
err
:=
self
.
chain
.
InsertChain
(
types
.
Blocks
{
block
});
err
==
nil
{
for
_
,
uncle
:=
range
block
.
Uncles
()
{
delete
(
self
.
possibleUncles
,
uncle
.
Hash
())
}
...
...
This diff is collapsed.
Click to expand it.
tests/block_test_util.go
View file @
735b029d
...
...
@@ -162,7 +162,7 @@ func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) error {
}
}
// RLP decoding worked, try to insert into chain:
err
=
chainManager
.
InsertChain
(
types
.
Blocks
{
cb
})
_
,
err
=
chainManager
.
InsertChain
(
types
.
Blocks
{
cb
})
if
err
!=
nil
{
if
b
.
BlockHeader
==
nil
{
continue
// OK - block is supposed to be invalid, continue with next block
...
...
This diff is collapsed.
Click to expand it.
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