cli/server: redo dumper to dump blocks from 0
NGD dumps are all zero-based and even though I don't like it (genesys block should not be imported, it's the root of chain trust), we have to conform to this convention for interoperability with C# nodes (otherwise they're not able to import our dumps). This also renames `skip` dumper parameter to `start` which is more logical now, the default is to start the dump from block number zero.
This commit is contained in:
parent
7aa7490fb2
commit
b706130175
1 changed files with 29 additions and 25 deletions
|
@ -35,23 +35,31 @@ func NewCommands() []cli.Command {
|
||||||
Name: "count, c",
|
Name: "count, c",
|
||||||
Usage: "number of blocks to be processed (default or 0: all chain)",
|
Usage: "number of blocks to be processed (default or 0: all chain)",
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
var cfgCountOutFlags = make([]cli.Flag, len(cfgWithCountFlags))
|
||||||
|
copy(cfgCountOutFlags, cfgWithCountFlags)
|
||||||
|
cfgCountOutFlags = append(cfgCountOutFlags,
|
||||||
|
cli.UintFlag{
|
||||||
|
Name: "start, s",
|
||||||
|
Usage: "block number to start from (default: 0)",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "out, o",
|
||||||
|
Usage: "Output file (stdout if not given)",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
var cfgCountInFlags = make([]cli.Flag, len(cfgWithCountFlags))
|
||||||
|
copy(cfgCountInFlags, cfgWithCountFlags)
|
||||||
|
cfgCountInFlags = append(cfgCountInFlags,
|
||||||
cli.UintFlag{
|
cli.UintFlag{
|
||||||
Name: "skip, s",
|
Name: "skip, s",
|
||||||
Usage: "number of blocks to skip (default: 0)",
|
Usage: "number of blocks to skip (default: 0)",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "in, i",
|
||||||
|
Usage: "Input file (stdin if not given)",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
var cfgCountOutFlags = make([]cli.Flag, len(cfgWithCountFlags))
|
|
||||||
copy(cfgCountOutFlags, cfgWithCountFlags)
|
|
||||||
cfgCountOutFlags = append(cfgCountOutFlags, cli.StringFlag{
|
|
||||||
Name: "out, o",
|
|
||||||
Usage: "Output file (stdout if not given)",
|
|
||||||
})
|
|
||||||
var cfgCountInFlags = make([]cli.Flag, len(cfgWithCountFlags))
|
|
||||||
copy(cfgCountInFlags, cfgWithCountFlags)
|
|
||||||
cfgCountInFlags = append(cfgCountInFlags, cli.StringFlag{
|
|
||||||
Name: "in, i",
|
|
||||||
Usage: "Input file (stdin if not given)",
|
|
||||||
})
|
|
||||||
return []cli.Command{
|
return []cli.Command{
|
||||||
{
|
{
|
||||||
Name: "node",
|
Name: "node",
|
||||||
|
@ -129,12 +137,6 @@ func handleLoggingParams(ctx *cli.Context, cfg config.ApplicationConfiguration)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCountAndSkipFromContext(ctx *cli.Context) (uint32, uint32) {
|
|
||||||
count := uint32(ctx.Uint("count"))
|
|
||||||
skip := uint32(ctx.Uint("skip"))
|
|
||||||
return count, skip
|
|
||||||
}
|
|
||||||
|
|
||||||
func initBCWithMetrics(cfg config.Config) (*core.Blockchain, *metrics.Service, *metrics.Service, error) {
|
func initBCWithMetrics(cfg config.Config) (*core.Blockchain, *metrics.Service, *metrics.Service, error) {
|
||||||
chain, err := initBlockChain(cfg)
|
chain, err := initBlockChain(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -159,7 +161,8 @@ func dumpDB(ctx *cli.Context) error {
|
||||||
if err := handleLoggingParams(ctx, cfg.ApplicationConfiguration); err != nil {
|
if err := handleLoggingParams(ctx, cfg.ApplicationConfiguration); err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
count, skip := getCountAndSkipFromContext(ctx)
|
count := uint32(ctx.Uint("count"))
|
||||||
|
start := uint32(ctx.Uint("start"))
|
||||||
|
|
||||||
var outStream = os.Stdout
|
var outStream = os.Stdout
|
||||||
if out := ctx.String("out"); out != "" {
|
if out := ctx.String("out"); out != "" {
|
||||||
|
@ -176,15 +179,15 @@ func dumpDB(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
chainHeight := chain.BlockHeight()
|
chainCount := chain.BlockHeight() + 1
|
||||||
if skip+count > chainHeight {
|
if start+count > chainCount {
|
||||||
return cli.NewExitError(fmt.Errorf("chain is not that high (%d) to dump %d blocks starting from %d", chainHeight, count, skip), 1)
|
return cli.NewExitError(fmt.Errorf("chain is not that high (%d) to dump %d blocks starting from %d", chainCount-1, count, start), 1)
|
||||||
}
|
}
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
count = chainHeight - skip
|
count = chainCount - start
|
||||||
}
|
}
|
||||||
writer.WriteU32LE(count)
|
writer.WriteU32LE(count)
|
||||||
for i := skip + 1; i <= skip+count; i++ {
|
for i := start; i < start+count; i++ {
|
||||||
bh := chain.GetHeaderHash(int(i))
|
bh := chain.GetHeaderHash(int(i))
|
||||||
b, err := chain.GetBlock(bh)
|
b, err := chain.GetBlock(bh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -213,7 +216,8 @@ func restoreDB(ctx *cli.Context) error {
|
||||||
if err := handleLoggingParams(ctx, cfg.ApplicationConfiguration); err != nil {
|
if err := handleLoggingParams(ctx, cfg.ApplicationConfiguration); err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
count, skip := getCountAndSkipFromContext(ctx)
|
count := uint32(ctx.Uint("count"))
|
||||||
|
skip := uint32(ctx.Uint("skip"))
|
||||||
|
|
||||||
var inStream = os.Stdin
|
var inStream = os.Stdin
|
||||||
if in := ctx.String("in"); in != "" {
|
if in := ctx.String("in"); in != "" {
|
||||||
|
|
Loading…
Reference in a new issue