Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [#1](https://github.com/crypto-org-chain/cronos-store/pull/1) feature: add store, memiavl, versiondb.
- [#3](https://github.com/crypto-org-chain/cronos-store/pull/3) feat(memiavl): MultiTree add chainId.
- [#4](https://github.com/crypto-org-chain/cronos-store/pull/4) feat(versiondb/client): add dump versiondb changeset cmd.
- [#4](https://github.com/crypto-org-chain/cronos-store/pull/4) feat(versiondb/client): add dump versiondb changeset cmd.
- [#6](https://github.com/crypto-org-chain/cronos-store/pull/6) feat(memiavl/client): memiavl dump root.
98 changes: 98 additions & 0 deletions memiavl/client/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package client

import (
"fmt"
"sort"

"github.com/crypto-org-chain/cronos-store/memiavl"
"github.com/spf13/cobra"

"cosmossdk.io/store/types"
)

const (
flagVersion = "version"
flagChainId = "chain-id"
)

// DumpRootCmd returns the root command for MemIAVL CLI utilities.
func DumpRootCmd(storeNames []string) *cobra.Command {
cmd := &cobra.Command{
Use: "memiavl",
Short: "memiavl cmds",
}

cmd.AddCommand(
dumpRootCmd(storeNames),
)

return cmd
}

// dumpRootCmd returns the command to dump MemIAVL root hashes.
func dumpRootCmd(storeNames []string) *cobra.Command {
cmd := &cobra.Command{
Use: "dump-memiavl-root",
Short: "dump memiavl root at version [dir]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
dir := args[0]
version, err := cmd.Flags().GetUint32(flagVersion)
if err != nil {
return err
}

opts := memiavl.Options{
InitialStores: storeNames,
CreateIfMissing: false,
TargetVersion: version,
ReadOnly: true,
}

db, err := memiavl.Load(dir, opts, flagChainId)
if err != nil {
return fmt.Errorf("failed to load MemIAVL DB: %w", err)
}
defer db.Close()

sort.Strings(storeNames)
// Dump per-module tree roots
for _, storeName := range storeNames {
tree := db.TreeByName(storeName)
if tree != nil {
fmt.Printf("module %s version %d RootHash %X\n", storeName, tree.Version(), tree.RootHash())
} else {
fmt.Printf("module %s not loaded\n", storeName)
}
}

db.MultiTree.UpdateCommitInfo()
lastCommitInfo := convertCommitInfo(db.MultiTree.LastCommitInfo())
fmt.Printf("MultiTree Version %d RootHash %X\n", lastCommitInfo.Version, lastCommitInfo.Hash())

return nil
},
}

cmd.Flags().Uint32(flagVersion, 0, "Target version to load")
cmd.Flags().String(flagChainId, "", "specify the chain id")

return cmd
}

func convertCommitInfo(commitInfo *memiavl.CommitInfo) *types.CommitInfo {
storeInfos := make([]types.StoreInfo, len(commitInfo.StoreInfos))
for i, storeInfo := range commitInfo.StoreInfos {
storeInfos[i] = types.StoreInfo{
Name: storeInfo.Name,
CommitId: types.CommitID{
Version: storeInfo.CommitId.Version,
Hash: storeInfo.CommitId.Hash,
},
}
}
return &types.CommitInfo{
Version: commitInfo.Version,
StoreInfos: storeInfos,
}
}
17 changes: 17 additions & 0 deletions memiavl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/cosmos/iavl v1.2.0
github.com/cosmos/ics23/go v0.10.0
github.com/ledgerwatch/erigon-lib v0.0.0-20230210071639-db0e7ed11263
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/tidwall/btree v1.7.0
github.com/tidwall/gjson v1.10.2
Expand All @@ -22,27 +23,39 @@ require (
)

require (
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/math v1.3.0 // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.0 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.6 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
github.com/hashicorp/go-metrics v0.5.1 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/linxGnu/grocksdb v1.8.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect
github.com/petermattis/goid v0.0.0-20221215004737-a150e88a970d // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
Expand All @@ -51,7 +64,9 @@ require (
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
Expand All @@ -60,6 +75,8 @@ require (
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/text v0.23.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/grpc v1.60.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading