mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-02-02 09:40:35 +00:00
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
|
// 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.
|
// Example: file `BlockStorage_100000/dump-block-6000.json` contains blocks from 5001 to 6000.
|
||||||
func getPath(prefix string, index uint32) (string, error) {
|
func getPath(prefix string, index uint32) (string, error) {
|
||||||
dirN := (index-1)/100000 + 1
|
dirN := ((index + 99999) / 100000) * 100000
|
||||||
dir := fmt.Sprintf("BlockStorage_%d00000", dirN)
|
dir := fmt.Sprintf("BlockStorage_%d", dirN)
|
||||||
|
|
||||||
path := filepath.Join(prefix, dir)
|
path := filepath.Join(prefix, dir)
|
||||||
info, err := os.Stat(path)
|
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)
|
return "", fmt.Errorf("file `%s` is not a directory", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileN := (index-1)/1000 + 1
|
fileN := ((index + 999) / 1000) * 1000
|
||||||
file := fmt.Sprintf("dump-block-%d000.json", fileN)
|
file := fmt.Sprintf("dump-block-%d.json", fileN)
|
||||||
return filepath.Join(path, file), nil
|
return filepath.Join(path, file), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,16 +292,19 @@ func restoreDB(ctx *cli.Context) error {
|
||||||
genesis, err := chain.GetBlock(block.Hash())
|
genesis, err := chain.GetBlock(block.Hash())
|
||||||
if err == nil && genesis.Index == 0 {
|
if err == nil && genesis.Index == 0 {
|
||||||
log.Info("skipped genesis block", zap.String("hash", block.Hash().StringLE()))
|
log.Info("skipped genesis block", zap.String("hash", block.Hash().StringLE()))
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
err = chain.AddBlock(block)
|
err = chain.AddBlock(block)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if dumpDir != "" {
|
if dumpDir != "" {
|
||||||
batch := chain.LastBatch()
|
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)
|
dump.add(block.Index, batch)
|
||||||
lastIndex = block.Index
|
lastIndex = block.Index
|
||||||
if block.Index%1000 == 0 {
|
if block.Index%1000 == 0 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue