cli/server: dump genesis block state when restoring
Neo 3 node does it too and it's very useful because now the genesis block also does some state changes that are important.
This commit is contained in:
parent
21cb7d5701
commit
176c0e98d6
2 changed files with 13 additions and 10 deletions
|
@ -165,8 +165,8 @@ func readFile(path string) (*dump, error) {
|
|||
// File dump-block-$FILENO.json contains blocks from $FILENO-999, $FILENO
|
||||
// Example: file `BlockStorage_100000/dump-block-6000.json` contains blocks from 5001 to 6000.
|
||||
func getPath(prefix string, index uint32) (string, error) {
|
||||
dirN := (index-1)/100000 + 1
|
||||
dir := fmt.Sprintf("BlockStorage_%d00000", dirN)
|
||||
dirN := ((index + 99999) / 100000) * 100000
|
||||
dir := fmt.Sprintf("BlockStorage_%d", dirN)
|
||||
|
||||
path := filepath.Join(prefix, dir)
|
||||
info, err := os.Stat(path)
|
||||
|
@ -179,7 +179,7 @@ func getPath(prefix string, index uint32) (string, error) {
|
|||
return "", fmt.Errorf("file `%s` is not a directory", path)
|
||||
}
|
||||
|
||||
fileN := (index-1)/1000 + 1
|
||||
file := fmt.Sprintf("dump-block-%d000.json", fileN)
|
||||
fileN := ((index + 999) / 1000) * 1000
|
||||
file := fmt.Sprintf("dump-block-%d.json", fileN)
|
||||
return filepath.Join(path, file), nil
|
||||
}
|
||||
|
|
|
@ -292,16 +292,19 @@ func restoreDB(ctx *cli.Context) error {
|
|||
genesis, err := chain.GetBlock(block.Hash())
|
||||
if err == nil && genesis.Index == 0 {
|
||||
log.Info("skipped genesis block", zap.String("hash", block.Hash().StringLE()))
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
err = chain.AddBlock(block)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
||||
}
|
||||
}
|
||||
err = chain.AddBlock(block)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
||||
}
|
||||
|
||||
if dumpDir != "" {
|
||||
batch := chain.LastBatch()
|
||||
// The genesis block may already be persisted, so LastBatch() will return nil.
|
||||
if batch == nil && block.Index == 0 {
|
||||
continue
|
||||
}
|
||||
dump.add(block.Index, batch)
|
||||
lastIndex = block.Index
|
||||
if block.Index%1000 == 0 {
|
||||
|
|
Loading…
Reference in a new issue