cli: adjust resulting state object structure in upload-state command

`upload-state` suppose to create objects with key-value pairs instead of
full MPT nodes. Partially revert 5f80a14.

Ref. #3782

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
Ekaterina Pavlova 2025-03-26 13:16:27 +09:00
parent fd41598b8a
commit f60feefe45
5 changed files with 22 additions and 28 deletions

View file

@ -30,7 +30,7 @@ func dumpBin(ctx *cli.Context) error {
count := uint32(ctx.Uint("count")) count := uint32(ctx.Uint("count"))
start := uint32(ctx.Uint("start")) start := uint32(ctx.Uint("start"))
chain, _, prometheus, pprof, err := InitBCWithMetrics(cfg, log) chain, prometheus, pprof, err := InitBCWithMetrics(cfg, log)
if err != nil { if err != nil {
return err return err
} }

View file

@ -141,10 +141,10 @@ func newGraceContext() context.Context {
} }
// InitBCWithMetrics initializes the blockchain with metrics with the given configuration. // InitBCWithMetrics initializes the blockchain with metrics with the given configuration.
func InitBCWithMetrics(cfg config.Config, log *zap.Logger) (*core.Blockchain, storage.Store, *metrics.Service, *metrics.Service, error) { func InitBCWithMetrics(cfg config.Config, log *zap.Logger) (*core.Blockchain, *metrics.Service, *metrics.Service, error) {
chain, store, err := initBlockChain(cfg, log) chain, _, err := initBlockChain(cfg, log)
if err != nil { if err != nil {
return nil, nil, nil, nil, cli.Exit(err, 1) return nil, nil, nil, cli.Exit(err, 1)
} }
prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus, log) prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus, log)
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log) pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof, log)
@ -152,14 +152,14 @@ func InitBCWithMetrics(cfg config.Config, log *zap.Logger) (*core.Blockchain, st
go chain.Run() go chain.Run()
err = prometheus.Start() err = prometheus.Start()
if err != nil { if err != nil {
return nil, nil, nil, nil, cli.Exit(fmt.Errorf("failed to start Prometheus service: %w", err), 1) return nil, nil, nil, cli.Exit(fmt.Errorf("failed to start Prometheus service: %w", err), 1)
} }
err = pprof.Start() err = pprof.Start()
if err != nil { if err != nil {
return nil, nil, nil, nil, cli.Exit(fmt.Errorf("failed to start Pprof service: %w", err), 1) return nil, nil, nil, cli.Exit(fmt.Errorf("failed to start Pprof service: %w", err), 1)
} }
return chain, store, prometheus, pprof, nil return chain, prometheus, pprof, nil
} }
func dumpDB(ctx *cli.Context) error { func dumpDB(ctx *cli.Context) error {
@ -190,7 +190,7 @@ func dumpDB(ctx *cli.Context) error {
defer outStream.Close() defer outStream.Close()
writer := io.NewBinWriterFromIO(outStream) writer := io.NewBinWriterFromIO(outStream)
chain, _, prometheus, pprof, err := InitBCWithMetrics(cfg, log) chain, prometheus, pprof, err := InitBCWithMetrics(cfg, log)
if err != nil { if err != nil {
return err return err
} }
@ -250,7 +250,7 @@ func restoreDB(ctx *cli.Context) error {
cfg.ApplicationConfiguration.SaveStorageBatch = true cfg.ApplicationConfiguration.SaveStorageBatch = true
} }
chain, _, prometheus, pprof, err := InitBCWithMetrics(cfg, log) chain, prometheus, pprof, err := InitBCWithMetrics(cfg, log)
if err != nil { if err != nil {
return err return err
} }
@ -471,7 +471,7 @@ func startServer(ctx *cli.Context) error {
return cli.Exit(err, 1) return cli.Exit(err, 1)
} }
chain, _, prometheus, pprof, err := InitBCWithMetrics(cfg, log) chain, prometheus, pprof, err := InitBCWithMetrics(cfg, log)
if err != nil { if err != nil {
return cli.Exit(err, 1) return cli.Exit(err, 1)
} }

View file

@ -200,11 +200,11 @@ func TestInitBCWithMetrics(t *testing.T) {
}) })
t.Run("bad store", func(t *testing.T) { t.Run("bad store", func(t *testing.T) {
_, _, _, _, err = InitBCWithMetrics(config.Config{}, logger) _, _, _, err = InitBCWithMetrics(config.Config{}, logger)
require.Error(t, err) require.Error(t, err)
}) })
chain, _, prometheus, pprof, err := InitBCWithMetrics(cfg, logger) chain, prometheus, pprof, err := InitBCWithMetrics(cfg, logger)
require.NoError(t, err) require.NoError(t, err)
t.Cleanup(func() { t.Cleanup(func() {
chain.Close() chain.Close()

View file

@ -189,7 +189,7 @@ func NewCommands() []*cli.Command {
}, },
{ {
Name: "upload-state", Name: "upload-state",
Usage: "Start the node, traverse MPT and upload MPT nodes to the NeoFS container at every StateSyncInterval number of blocks", Usage: "Start the node, traverse contract storage key-value pairs and upload them to the NeoFS container at every StateSyncInterval number of blocks",
UsageText: "neo-go util upload-state --fs-rpc-endpoint <address1>[,<address2>[...]] --container <cid> --state-attribute state --wallet <wallet> [--wallet-config <config>] [--address <address>] [--searchers <num>] [--retries <num>] [--debug] [--config-path path] [-p/-m/-t] [--config-file file] [--force-timestamp-logs]", UsageText: "neo-go util upload-state --fs-rpc-endpoint <address1>[,<address2>[...]] --container <cid> --state-attribute state --wallet <wallet> [--wallet-config <config>] [--address <address>] [--searchers <num>] [--retries <num>] [--debug] [--config-path path] [-p/-m/-t] [--config-file file] [--force-timestamp-logs]",
Action: uploadState, Action: uploadState,
Flags: uploadStateFlags, Flags: uploadStateFlags,

View file

@ -9,8 +9,6 @@ import (
"github.com/nspcc-dev/neo-go/cli/options" "github.com/nspcc-dev/neo-go/cli/options"
"github.com/nspcc-dev/neo-go/cli/server" "github.com/nspcc-dev/neo-go/cli/server"
"github.com/nspcc-dev/neo-go/pkg/core" "github.com/nspcc-dev/neo-go/pkg/core"
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
"github.com/nspcc-dev/neo-go/pkg/core/storage"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
gio "github.com/nspcc-dev/neo-go/pkg/io" gio "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/services/helpers/neofs" "github.com/nspcc-dev/neo-go/pkg/services/helpers/neofs"
@ -53,7 +51,7 @@ func uploadState(ctx *cli.Context) error {
defer func() { _ = logCloser() }() defer func() { _ = logCloser() }()
} }
chain, store, prometheus, pprof, err := server.InitBCWithMetrics(cfg, log) chain, prometheus, pprof, err := server.InitBCWithMetrics(cfg, log)
if err != nil { if err != nil {
return err return err
} }
@ -133,7 +131,7 @@ func uploadState(ctx *cli.Context) error {
wrt.WriteU32LE(uint32(chain.GetConfig().Magic)) wrt.WriteU32LE(uint32(chain.GetConfig().Magic))
wrt.WriteU32LE(height) wrt.WriteU32LE(height)
wrt.WriteBytes(stateRoot.Root[:]) wrt.WriteBytes(stateRoot.Root[:])
err = traverseMPT(stateRoot.Root, store, wrt) err = traverseMPT(stateRoot.Root, stateModule, wrt)
if err != nil { if err != nil {
_ = writer.Close() _ = writer.Close()
return err return err
@ -192,15 +190,11 @@ func searchStateIndex(ctx *cli.Context, p neofs.PoolWrapper, containerID cid.ID,
} }
} }
func traverseMPT(root util.Uint256, store storage.Store, writer *gio.BinWriter) error { func traverseMPT(root util.Uint256, stateModule core.StateRoot, writer *gio.BinWriter) error {
cache := storage.NewMemCachedStore(store) stateModule.SeekStates(root, []byte{}, func(k, v []byte) bool {
billet := mpt.NewBillet(root, mpt.ModeAll, mpt.DummySTTempStoragePrefix, cache) writer.WriteVarBytes(k)
err := billet.Traverse(func(pathToNode []byte, node mpt.Node, nodeBytes []byte) bool { writer.WriteVarBytes(v)
writer.WriteVarBytes(nodeBytes) return writer.Err == nil
return writer.Err != nil })
}, false) return writer.Err
if err != nil {
return fmt.Errorf("billet traversal error: %w", err)
}
return nil
} }