Skip to content

Commit

Permalink
cmd/utils: add magic for exportdata
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Oct 19, 2021
1 parent 7a97faa commit c925a9b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package utils
import (
"bufio"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -354,11 +355,14 @@ func ExportPreimages(db ethdb.Database, fn string) error {
// should be bumped.
// If the importer sees a higher version, it should reject the import.
type exportHeader struct {
Magic string // Always set to 'gethdbdump' for disambiguation
Version uint64
Kind string
UnixTime uint64
}

const exportMagic = "gethdbdump"

// ImportLDBData imports a batch of snapshot data into the database
func ImportLDBData(db ethdb.Database, f string, startIndex int64, interrupt chan struct{}) error {
log.Info("Importing leveldb data", "file", f)
Expand All @@ -383,6 +387,9 @@ func ImportLDBData(db ethdb.Database, f string, startIndex int64, interrupt chan
if err := stream.Decode(&header); err != nil {
return fmt.Errorf("could not decode header: %v", err)
}
if header.Magic != exportMagic {
return errors.New("incompatible data, wrong magic")
}
if header.Version != 0 {
return fmt.Errorf("incompatible version %d, (support only 0)", header.Version)
}
Expand Down Expand Up @@ -471,6 +478,7 @@ func ExportChaindata(db ethdb.Database, fn string, kind string, checker func(key
}
// Write the header
if err := rlp.Encode(writer, &exportHeader{
Magic: exportMagic,
Version: 0,
Kind: kind,
UnixTime: uint64(time.Now().Unix()),
Expand Down
1 change: 1 addition & 0 deletions cmd/utils/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestImportFutureFormat(t *testing.T) {
}
defer fh.Close()
if err := rlp.Encode(fh, &exportHeader{
Magic: exportMagic,
Version: 500,
Kind: "testdata",
UnixTime: uint64(time.Now().Unix()),
Expand Down

0 comments on commit c925a9b

Please sign in to comment.