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
9ba9fe81
Commit
9ba9fe81
authored
Dec 12, 2016
by
Nick Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/utils, eth: Add gzip support for chain dump and restore
parent
ee445a2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
cmd.go
cmd/utils/cmd.go
+28
-3
api.go
eth/api.go
+17
-2
No files found.
cmd/utils/cmd.go
View file @
9ba9fe81
...
...
@@ -18,12 +18,14 @@
package
utils
import
(
"compress/gzip"
"fmt"
"io"
"os"
"os/signal"
"regexp"
"runtime"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
...
...
@@ -133,7 +135,15 @@ func ImportChain(chain *core.BlockChain, fn string) error {
return
err
}
defer
fh
.
Close
()
stream
:=
rlp
.
NewStream
(
fh
,
0
)
var
reader
io
.
Reader
=
fh
if
strings
.
HasSuffix
(
fn
,
".gz"
)
{
if
reader
,
err
=
gzip
.
NewReader
(
reader
);
err
!=
nil
{
return
err
}
}
stream
:=
rlp
.
NewStream
(
reader
,
0
)
// Run actual the import.
blocks
:=
make
(
types
.
Blocks
,
importBatchSize
)
...
...
@@ -195,10 +205,18 @@ func ExportChain(blockchain *core.BlockChain, fn string) error {
return
err
}
defer
fh
.
Close
()
if
err
:=
blockchain
.
Export
(
fh
);
err
!=
nil
{
var
writer
io
.
Writer
=
fh
if
strings
.
HasSuffix
(
fn
,
".gz"
)
{
writer
=
gzip
.
NewWriter
(
writer
)
defer
writer
.
(
*
gzip
.
Writer
)
.
Close
()
}
if
err
:=
blockchain
.
Export
(
writer
);
err
!=
nil
{
return
err
}
glog
.
Infoln
(
"Exported blockchain to "
,
fn
)
return
nil
}
...
...
@@ -210,7 +228,14 @@ func ExportAppendChain(blockchain *core.BlockChain, fn string, first uint64, las
return
err
}
defer
fh
.
Close
()
if
err
:=
blockchain
.
ExportN
(
fh
,
first
,
last
);
err
!=
nil
{
var
writer
io
.
Writer
=
fh
if
strings
.
HasSuffix
(
fn
,
".gz"
)
{
writer
=
gzip
.
NewWriter
(
writer
)
defer
writer
.
(
*
gzip
.
Writer
)
.
Close
()
}
if
err
:=
blockchain
.
ExportN
(
writer
,
first
,
last
);
err
!=
nil
{
return
err
}
glog
.
Infoln
(
"Exported blockchain to "
,
fn
)
...
...
eth/api.go
View file @
9ba9fe81
...
...
@@ -18,6 +18,7 @@ package eth
import
(
"bytes"
"compress/gzip"
"errors"
"fmt"
"io"
...
...
@@ -25,6 +26,7 @@ import (
"math/big"
"os"
"runtime"
"strings"
"time"
"github.com/ethereum/ethash"
...
...
@@ -217,8 +219,14 @@ func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
}
defer
out
.
Close
()
var
writer
io
.
Writer
=
out
if
strings
.
HasSuffix
(
file
,
".gz"
)
{
writer
=
gzip
.
NewWriter
(
writer
)
defer
writer
.
(
*
gzip
.
Writer
)
.
Close
()
}
// Export the blockchain
if
err
:=
api
.
eth
.
BlockChain
()
.
Export
(
out
);
err
!=
nil
{
if
err
:=
api
.
eth
.
BlockChain
()
.
Export
(
writer
);
err
!=
nil
{
return
false
,
err
}
return
true
,
nil
...
...
@@ -243,8 +251,15 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) {
}
defer
in
.
Close
()
var
reader
io
.
Reader
=
in
if
strings
.
HasSuffix
(
file
,
".gz"
)
{
if
reader
,
err
=
gzip
.
NewReader
(
reader
);
err
!=
nil
{
return
false
,
err
}
}
// Run actual the import in pre-configured batches
stream
:=
rlp
.
NewStream
(
in
,
0
)
stream
:=
rlp
.
NewStream
(
reader
,
0
)
blocks
,
index
:=
make
([]
*
types
.
Block
,
0
,
2500
),
0
for
batch
:=
0
;
;
batch
++
{
...
...
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