aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/utils/cmd.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 2e2b627df..2a5e2ec6a 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -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)