-
Notifications
You must be signed in to change notification settings - Fork 370
feat: add dump iavl root cmd #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
songgaoye
wants to merge
23
commits into
master
Choose a base branch
from
dump_root
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fb17ccd
feat: add dump iavl root and memiavl root
songgaoye 5d9fb7e
add changelog
songgaoye 229651c
update app.go
songgaoye 640c18d
update lint
songgaoye ccfd78b
add special storeInfo for the same hash with iavl node
songgaoye c0a18f4
rm unused code
songgaoye 1442586
update calculate again logic
songgaoye 6358f82
Merge branch 'master' into dump_root
songgaoye 3a72154
Merge branch 'master' into dump_root
songgaoye 673c99c
1.fix changelog 2.update comment 3. close db
songgaoye 75aae6c
update StoreKeys
songgaoye 473dcbf
fmt
songgaoye 35787fb
update changelog
songgaoye 33af983
update fmt
songgaoye de045d6
Merge branch 'master' into dump_root
songgaoye e3df051
fix comment
songgaoye a9dd7ae
Merge branch 'master' into dump_root
songgaoye 9cafd02
rm dump memiavl root
songgaoye 42e2664
update StoreKey
songgaoye 64b8ffc
fix golangci-lint
songgaoye 19c36df
use dbm read_only
songgaoye 6aedb0b
update DumpIavlRoot support rocksdb backend comment
songgaoye f7fe206
sort storeNames
songgaoye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package app | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"sort" | ||
|
||
dbm "github.com/cosmos/cosmos-db" | ||
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" | ||
icacontrollertypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/controller/types" | ||
icahosttypes "github.com/cosmos/ibc-go/v10/modules/apps/27-interchain-accounts/host/types" | ||
ibctransfertypes "github.com/cosmos/ibc-go/v10/modules/apps/transfer/types" | ||
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported" | ||
"github.com/crypto-org-chain/chain-main/v4/app" | ||
chainmaintypes "github.com/crypto-org-chain/chain-main/v4/x/chainmain/types" | ||
nfttransfertypes "github.com/crypto-org-chain/chain-main/v4/x/nft-transfer/types" | ||
nfttypes "github.com/crypto-org-chain/chain-main/v4/x/nft/types" | ||
supplytypes "github.com/crypto-org-chain/chain-main/v4/x/supply/types" | ||
"github.com/spf13/cobra" | ||
|
||
"cosmossdk.io/log" | ||
"cosmossdk.io/store/rootmulti" | ||
"cosmossdk.io/store/types" | ||
evidencetypes "cosmossdk.io/x/evidence/types" | ||
"cosmossdk.io/x/feegrant" | ||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
|
||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/cosmos/cosmos-sdk/x/group" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" | ||
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
func DumpRootCmd() *cobra.Command { | ||
keys, _, _ := app.StoreKeys() | ||
storeNames := make([]string, 0, len(keys)) | ||
for name := range keys { | ||
storeNames = append(storeNames, name) | ||
} | ||
sort.Strings(storeNames) | ||
return DumpRootGroupCmd(storeNames) | ||
} | ||
|
||
func DumpRootGroupCmd(storeNames []string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "dump-root", | ||
Short: "dump module root", | ||
} | ||
cmd.AddCommand( | ||
DumpIavlRoot(storeNames), | ||
) | ||
return cmd | ||
} | ||
|
||
func DumpIavlRoot(storeNames []string) *cobra.Command { | ||
// this needs to change in different height | ||
// because some StoreKey version are zero | ||
// such as consensusparamtypes, circuittypes | ||
storeNames = []string{ | ||
authtypes.StoreKey, | ||
banktypes.StoreKey, | ||
stakingtypes.StoreKey, | ||
minttypes.StoreKey, | ||
distrtypes.StoreKey, | ||
slashingtypes.StoreKey, | ||
govtypes.StoreKey, | ||
paramstypes.StoreKey, | ||
ibcexported.StoreKey, | ||
upgradetypes.StoreKey, | ||
feegrant.StoreKey, | ||
evidencetypes.StoreKey, | ||
ibctransfertypes.StoreKey, | ||
icacontrollertypes.StoreKey, | ||
icahosttypes.StoreKey, | ||
capabilitytypes.StoreKey, | ||
authzkeeper.StoreKey, | ||
nfttransfertypes.StoreKey, | ||
group.StoreKey, | ||
chainmaintypes.StoreKey, | ||
supplytypes.StoreKey, | ||
// maxsupplytypes.StoreKey, | ||
nfttypes.StoreKey, | ||
// consensusparamtypes.StoreKey, | ||
// circuittypes.StoreKey, | ||
"icaauth", | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "dump-iavl-root", | ||
Short: "dump iavl root at version [dir]", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
dir := args[0] | ||
version, err := cmd.Flags().GetInt64("version") | ||
songgaoye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
db, err := dbm.NewGoLevelDB("application", dir, dbm.OptionsMap{"read_only": true}) | ||
songgaoye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
defer db.Close() | ||
rs := rootmulti.NewStore(db, log.NewNopLogger(), nil) | ||
for _, storeKey := range storeNames { | ||
rs.MountStoreWithDB(types.NewKVStoreKey(storeKey), types.StoreTypeIAVL, nil) | ||
} | ||
|
||
err = rs.LoadVersion(version) | ||
if err != nil { | ||
fmt.Printf("failed to load version %d %s\n", version, err.Error()) | ||
return err | ||
} | ||
|
||
var cInfo *types.CommitInfo | ||
cInfo, err = rs.GetCommitInfo(version) | ||
if err != nil { | ||
fmt.Printf("failed to load version %d commit info: %s\n", version, err.Error()) | ||
return err | ||
} | ||
infoMaps := make(map[string]types.StoreInfo) | ||
for _, storeInfo := range cInfo.StoreInfos { | ||
infoMaps[storeInfo.Name] = storeInfo | ||
} | ||
|
||
var infos []types.StoreInfo | ||
for _, storeName := range storeNames { | ||
info, ok := infoMaps[storeName] | ||
if !ok { | ||
fmt.Printf("module %s not loaded\n", storeName) | ||
continue | ||
} | ||
commitID := info.CommitId | ||
fmt.Printf("module %s version %d RootHash %X\n", storeName, commitID.Version, commitID.Hash) | ||
infos = append(infos, info) | ||
} | ||
|
||
if len(infos) != len(cInfo.StoreInfos) { | ||
fmt.Printf("Warning: Partial commit info (loaded %d stores, found %d)\n", len(cInfo.StoreInfos), len(infos)) | ||
storeMaps := make(map[string]struct{}) | ||
for _, storeName := range storeNames { | ||
storeMaps[storeName] = struct{}{} | ||
} | ||
for _, info := range cInfo.StoreInfos { | ||
if _, ok := storeMaps[info.Name]; !ok { | ||
fmt.Printf("module %s missed\n", info.Name) | ||
} | ||
} | ||
} | ||
|
||
commitInfo := &types.CommitInfo{ | ||
Version: version, | ||
StoreInfos: infos, | ||
} | ||
|
||
if rs.LastCommitID().Version != commitInfo.Version || !bytes.Equal(rs.LastCommitID().Hash, commitInfo.Hash()) { | ||
return fmt.Errorf("failed to calculate %d commit info, rs Hash %X, commit Hash %X", rs.LastCommitID().Version, rs.LastCommitID().Hash, commitInfo.Hash()) | ||
} | ||
fmt.Printf("Version %d RootHash %X\n", commitInfo.Version, commitInfo.Hash()) | ||
return nil | ||
}, | ||
} | ||
cmd.Flags().Int64("version", 0, "the version to dump") | ||
return cmd | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.