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
a8bc2181
Commit
a8bc2181
authored
May 27, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/utils: skip batches with known blocks during import
This makes block importing restartable.
parent
67effb94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
3 deletions
+16
-3
cmd.go
cmd/utils/cmd.go
+16
-3
No files found.
cmd/utils/cmd.go
View file @
a8bc2181
...
...
@@ -204,12 +204,11 @@ func ImportChain(chain *core.ChainManager, fn string) error {
defer
fh
.
Close
()
stream
:=
rlp
.
NewStream
(
fh
,
0
)
// Remove all existing blocks and start the import.
chain
.
Reset
()
// Run actual the import.
batchSize
:=
2500
blocks
:=
make
(
types
.
Blocks
,
batchSize
)
n
:=
0
for
{
for
batch
:=
0
;
;
batch
++
{
// Load a batch of RLP blocks.
if
checkInterrupt
()
{
return
fmt
.
Errorf
(
"interrupted"
)
...
...
@@ -232,6 +231,11 @@ func ImportChain(chain *core.ChainManager, fn string) error {
if
checkInterrupt
()
{
return
fmt
.
Errorf
(
"interrupted"
)
}
if
hasAllBlocks
(
chain
,
blocks
[
:
i
])
{
glog
.
Infof
(
"skipping batch %d, all blocks present [%x / %x]"
,
batch
,
blocks
[
0
]
.
Hash
()
.
Bytes
()[
:
4
],
blocks
[
i
-
1
]
.
Hash
()
.
Bytes
()[
:
4
])
continue
}
if
_
,
err
:=
chain
.
InsertChain
(
blocks
[
:
i
]);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid block %d: %v"
,
n
,
err
)
}
...
...
@@ -239,6 +243,15 @@ func ImportChain(chain *core.ChainManager, fn string) error {
return
nil
}
func
hasAllBlocks
(
chain
*
core
.
ChainManager
,
bs
[]
*
types
.
Block
)
bool
{
for
_
,
b
:=
range
bs
{
if
!
chain
.
HasBlock
(
b
.
Hash
())
{
return
false
}
}
return
true
}
func
ExportChain
(
chainmgr
*
core
.
ChainManager
,
fn
string
)
error
{
glog
.
Infoln
(
"Exporting blockchain to"
,
fn
)
fh
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_CREATE
|
os
.
O_WRONLY
|
os
.
O_TRUNC
,
os
.
ModePerm
)
...
...
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