## Description When locally working with golangci-lint, we can see that there were many deprecation warnings about sdk.Int. This PR resolves that and makes 1-2 other linting related changes. Issue on linting coming next. This also moves BitCurve to bitCurve. I expect that this set of changes will require several pull requests, one of them to the settings for the linter. It also does a gofumpt, because we had various formatting-related linters fail, too. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
192 lines
4.7 KiB
Go
192 lines
4.7 KiB
Go
package server
|
|
|
|
// DONTCOVER
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
cfg "github.com/tendermint/tendermint/config"
|
|
pvm "github.com/tendermint/tendermint/privval"
|
|
"github.com/tendermint/tendermint/scripts/keymigrate"
|
|
"github.com/tendermint/tendermint/scripts/scmigrate"
|
|
tversion "github.com/tendermint/tendermint/version"
|
|
"sigs.k8s.io/yaml"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// ShowNodeIDCmd - ported from Tendermint, dump node ID to stdout
|
|
func ShowNodeIDCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "show-node-id",
|
|
Short: "Show this node's ID",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
cfg := serverCtx.Config
|
|
|
|
nodeKey, err := cfg.LoadNodeKeyID()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(nodeKey)
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
// ShowValidatorCmd - ported from Tendermint, show this node's validator info
|
|
func ShowValidatorCmd() *cobra.Command {
|
|
cmd := cobra.Command{
|
|
Use: "show-validator",
|
|
Short: "Show this node's tendermint validator info",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
cfg := serverCtx.Config
|
|
|
|
privValidator, err := pvm.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
pk, err := privValidator.GetPubKey(cmd.Context())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
sdkPK, err := cryptocodec.FromTmPubKeyInterface(pk)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
|
bz, err := clientCtx.Codec.MarshalInterfaceJSON(sdkPK)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(string(bz))
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return &cmd
|
|
}
|
|
|
|
// ShowAddressCmd - show this node's validator address
|
|
func ShowAddressCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "show-address",
|
|
Short: "Shows this node's tendermint validator consensus address",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
cfg := serverCtx.Config
|
|
|
|
privValidator, err := pvm.LoadFilePV(cfg.PrivValidator.KeyFile(), cfg.PrivValidator.StateFile())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
valConsAddr := (sdk.ConsAddress)(privValidator.GetAddress())
|
|
fmt.Println(valConsAddr.String())
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
// VersionCmd prints tendermint and ABCI version numbers.
|
|
func VersionCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print tendermint libraries' version",
|
|
Long: "Print protocols' and libraries' version numbers against which this app has been compiled.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
bs, err := yaml.Marshal(&struct {
|
|
Tendermint string
|
|
ABCI string
|
|
BlockProtocol uint64
|
|
P2PProtocol uint64
|
|
}{
|
|
Tendermint: tversion.TMVersion,
|
|
ABCI: tversion.ABCIVersion,
|
|
BlockProtocol: tversion.BlockProtocol,
|
|
P2PProtocol: tversion.P2PProtocol,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(string(bs))
|
|
return nil
|
|
},
|
|
}
|
|
}
|
|
|
|
// makeKeyMigrateCmd is ported from tendermint's key-migrate command, but
|
|
// uses the SDK's own server.Context.
|
|
// ref: https://github.com/tendermint/tendermint/blob/master/UPGRADING.md#database-key-format-changes
|
|
func makeKeyMigrateCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "key-migrate",
|
|
Short: "Run Tendermint database key migration",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
ctx, cancel := context.WithCancel(cmd.Context())
|
|
defer cancel()
|
|
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
config := serverCtx.Config
|
|
|
|
contexts := []string{
|
|
// this is ordered to put the
|
|
// (presumably) biggest/most important
|
|
// subsets first.
|
|
"blockstore",
|
|
"state",
|
|
"peerstore",
|
|
"tx_index",
|
|
"evidence",
|
|
"light",
|
|
}
|
|
|
|
for idx, dbctx := range contexts {
|
|
serverCtx.Logger.Info("beginning a key migration",
|
|
"dbctx", dbctx,
|
|
"num", idx+1,
|
|
"total", len(contexts),
|
|
)
|
|
|
|
db, err := cfg.DefaultDBProvider(&cfg.DBContext{
|
|
ID: dbctx,
|
|
Config: config,
|
|
})
|
|
if err != nil {
|
|
return fmt.Errorf("constructing database handle: %w", err)
|
|
}
|
|
|
|
if err = keymigrate.Migrate(ctx, db); err != nil {
|
|
return fmt.Errorf("running migration for context %q: %w",
|
|
dbctx, err)
|
|
}
|
|
|
|
if dbctx == "blockstore" {
|
|
if err := scmigrate.Migrate(ctx, db); err != nil {
|
|
return fmt.Errorf("running seen commit migration: %w", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
serverCtx.Logger.Info("completed database migration successfully")
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
return cmd
|
|
}
|