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