Skip to content

Commit 131fcd7

Browse files
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. Ref. #3782 Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
1 parent fd41598 commit 131fcd7

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

‎cli/util/convert.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func NewCommands() []*cli.Command {
189189
},
190190
{
191191
Name: "upload-state",
192-
Usage: "Start the node, traverse MPT and upload MPT nodes to the NeoFS container at every StateSyncInterval number of blocks",
192+
Usage: "Start the node, traverse only contract storage key-value pairs and upload them to the NeoFS container at every StateSyncInterval number of blocks",
193193
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]",
194194
Action: uploadState,
195195
Flags: uploadStateFlags,

‎cli/util/upload_state.go‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/nspcc-dev/neo-go/cli/options"
1010
"github.com/nspcc-dev/neo-go/cli/server"
1111
"github.com/nspcc-dev/neo-go/pkg/core"
12-
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
13-
"github.com/nspcc-dev/neo-go/pkg/core/storage"
1412
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
1513
gio "github.com/nspcc-dev/neo-go/pkg/io"
1614
"github.com/nspcc-dev/neo-go/pkg/services/helpers/neofs"
@@ -53,7 +51,7 @@ func uploadState(ctx *cli.Context) error {
5351
defer func() { _ = logCloser() }()
5452
}
5553

56-
chain, store, prometheus, pprof, err := server.InitBCWithMetrics(cfg, log)
54+
chain, _, prometheus, pprof, err := server.InitBCWithMetrics(cfg, log)
5755
if err != nil {
5856
return err
5957
}
@@ -133,7 +131,7 @@ func uploadState(ctx *cli.Context) error {
133131
wrt.WriteU32LE(uint32(chain.GetConfig().Magic))
134132
wrt.WriteU32LE(height)
135133
wrt.WriteBytes(stateRoot.Root[:])
136-
err = traverseMPT(stateRoot.Root, store, wrt)
134+
err = traverseMPT(stateRoot.Root, stateModule, wrt)
137135
if err != nil {
138136
_ = writer.Close()
139137
return err
@@ -192,15 +190,11 @@ func searchStateIndex(ctx *cli.Context, p neofs.PoolWrapper, containerID cid.ID,
192190
}
193191
}
194192

195-
func traverseMPT(root util.Uint256, store storage.Store, writer *gio.BinWriter) error {
196-
cache := storage.NewMemCachedStore(store)
197-
billet := mpt.NewBillet(root, mpt.ModeAll, mpt.DummySTTempStoragePrefix, cache)
198-
err := billet.Traverse(func(pathToNode []byte, node mpt.Node, nodeBytes []byte) bool {
199-
writer.WriteVarBytes(nodeBytes)
200-
return writer.Err != nil
201-
}, false)
202-
if err != nil {
203-
return fmt.Errorf("billet traversal error: %w", err)
204-
}
205-
return nil
193+
func traverseMPT(root util.Uint256, stateModule core.StateRoot, writer *gio.BinWriter) error {
194+
stateModule.SeekStates(root, []byte{}, func(k, v []byte) bool {
195+
writer.WriteVarBytes(k)
196+
writer.WriteVarBytes(v)
197+
return writer.Err == nil
198+
})
199+
return writer.Err
206200
}

0 commit comments

Comments
 (0)