Skip to content

Commit

Permalink
Merge branch 'osmo-v22/v0.47.5' into adam/osmo/v0.47.5-iavl-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic committed Jan 30, 2024
2 parents d6eb2d8 + 55b53a1 commit 743e42a
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 124 deletions.
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
require.Equal(t, []byte("ok"), okValue)
}
// check block gas is always consumed
baseGas := uint64(51682) // baseGas is the gas consumed before tx msg
baseGas := uint64(47842) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) {
// capped by gasLimit
Expand Down
7 changes: 6 additions & 1 deletion baseapp/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package baseapp

import (
"context"
"fmt"
"strconv"

gogogrpc "github.com/cosmos/gogoproto/grpc"
Expand All @@ -21,7 +22,7 @@ import (
func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter }

// RegisterGRPCServer registers gRPC services directly with the gRPC server.
func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server, logQueries bool) {
// Define an interceptor for all gRPC queries: this interceptor will create
// a new sdk.Context, and pass it into the query handler.
interceptor := func(grpcCtx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
Expand Down Expand Up @@ -65,6 +66,10 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
app.logger.Error("failed to set gRPC header", "err", err)
}

if logQueries {
app.logger.Info("gRPC query received of type: " + fmt.Sprintf("%#v", req))
}

return handler(grpcCtx, req)
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ require (
replace (
// use cosmos fork of keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/cometbft/cometbft => github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,6 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/coinbase/rosetta-sdk-go/types v1.0.0 h1:jpVIwLcPoOeCR6o1tU+Xv7r5bMONNbHU7MuEHboiFuA=
github.com/coinbase/rosetta-sdk-go/types v1.0.0/go.mod h1:eq7W2TMRH22GTW0N0beDnN931DW0/WOI1R2sdHNHG4c=
github.com/cometbft/cometbft v0.37.2 h1:XB0yyHGT0lwmJlFmM4+rsRnczPlHoAKFX6K8Zgc2/Jc=
github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo=
github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0=
github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4=
Expand Down Expand Up @@ -885,6 +883,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA=
github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146 h1:Qkshh58fZCRoHSzbyW8NJf1wBhf9bg1MPFZEuyuI9lE=
github.com/osmosis-labs/cometbft v0.0.0-20240103055822-28da358e3146/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs=
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
Expand Down
4 changes: 0 additions & 4 deletions math/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ func (i Int) Mul(i2 Int) (res Int) {
panic("Int overflow")
}
res = Int{mul(i.i, i2.i)}
// Check overflow if sign of both are same
if res.i.BitLen() > MaxBitLen {
panic("Int overflow")
}
return
}

Expand Down
8 changes: 8 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
// bytes the server can send.
DefaultGRPCMaxSendMsgSize = math.MaxInt32

// DefaultLogQueries defines the default value for the log_queries parameter.
// Should be set to false unless debugging.
DefaultLogQueries = false

// FileStreamer defines the store streaming type for file streaming.
FileStreamer = "file"
)
Expand Down Expand Up @@ -177,6 +181,9 @@ type GRPCConfig struct {
// MaxSendMsgSize defines the max message size in bytes the server can send.
// The default value is math.MaxInt32.
MaxSendMsgSize int `mapstructure:"max-send-msg-size"`

// LogQueries logs every gRPC query to the console as an info log.
LogQueries bool `mapstructure:"log-queries"`
}

// GRPCWebConfig defines configuration for the gRPC-web server.
Expand Down Expand Up @@ -319,6 +326,7 @@ func DefaultConfig() *Config {
Address: DefaultGRPCAddress,
MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize,
MaxSendMsgSize: DefaultGRPCMaxSendMsgSize,
LogQueries: DefaultLogQueries,
},
Rosetta: RosettaConfig{
Enable: false,
Expand Down
5 changes: 5 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}"
# The default value is math.MaxInt32.
max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}"
# LogQueries if enabled will print an info log containing the query request
# that was submitted to this node on every submission.
# This is useful strictly for debugging purposes and should be disabled otherwise.
log-queries = {{ .GRPC.LogQueries }}
###############################################################################
### gRPC Web Configuration ###
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func StartGRPCServer(clientCtx client.Context, app types.Application, cfg config
grpc.MaxRecvMsgSize(maxRecvMsgSize),
)

app.RegisterGRPCServer(grpcSrv)
app.RegisterGRPCServer(grpcSrv, cfg.LogQueries)

// Reflection allows consumers to build dynamic clients that can write to any
// Cosmos SDK application without relying on application packages at compile
Expand Down
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func (ms multiStore) LatestVersion() int64 {
panic("not implemented")
}

func (ms multiStore) GetCommitInfo(key int64) (*storetypes.CommitInfo, error) {
panic("not implemented")
}

var _ sdk.KVStore = kvStore{}

type kvStore struct {
Expand Down
56 changes: 56 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
"os"
"runtime/pprof"
"sort"
"strings"
"time"

"github.com/cometbft/cometbft/abci/server"
Expand All @@ -22,6 +24,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

Check failure on line 26 in server/start.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
"encoding/hex"

"cosmossdk.io/tools/rosetta"
crgserver "cosmossdk.io/tools/rosetta/lib/server"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -32,6 +36,7 @@ import (
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
"github.com/cosmos/cosmos-sdk/server/types"
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
Expand Down Expand Up @@ -334,6 +339,18 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
if err := tmNode.Start(); err != nil {
return err
}

// Start a goroutine to listen for appHash errors from consensus layer.
go func() {
for appHashError := range tmNode.BCReactor().AppHashErrorsCh() {
// If an error is received, call returnCommitInfo
if appHashError.Err != nil {
if commitInfoErr := returnCommitInfo(ctx, app, int64(appHashError.Height)); commitInfoErr != nil {
ctx.Logger.Error("failed to return commit info", "err", commitInfoErr)
}
}
}
}()
}

// Add the tx service to the gRPC router. We only need to register this
Expand Down Expand Up @@ -566,3 +583,42 @@ func wrapCPUProfile(ctx *Context, callback func() error) error {

return WaitForQuitSignals()
}

// returnCommitInfo returns the individual app hashes for every module given a version (height).
func returnCommitInfo(ctx *Context, app types.Application, version int64) error {
commitInfoForHeight, err := app.CommitMultiStore().GetCommitInfo(version)
if err != nil {
return err
}

// Create a new slice of StoreInfos for storing the modified hashes.
storeInfos := make([]storetypes.StoreInfo, len(commitInfoForHeight.StoreInfos))

for i, storeInfo := range commitInfoForHeight.StoreInfos {
// Convert the hash to a hexadecimal string.
hash := strings.ToUpper(hex.EncodeToString(storeInfo.CommitId.Hash))

// Create a new StoreInfo with the modified hash.
storeInfos[i] = storetypes.StoreInfo{
Name: storeInfo.Name,
CommitId: storetypes.CommitID{
Version: storeInfo.CommitId.Version,
Hash: []byte(hash),
},
}
}

// Sort the storeInfos slice based on the module name.
sort.Slice(storeInfos, func(i, j int) bool {
return storeInfos[i].Name < storeInfos[j].Name
})

// Create a new CommitInfo with the modified StoreInfos.
commitInfoForHeight = &storetypes.CommitInfo{
Version: commitInfoForHeight.Version,
StoreInfos: storeInfos,
}

ctx.Logger.Error("your node has app hashed. Compare each module's hashes with a node that did not app hash to determine the problematic module", "commitInfo", commitInfoForHeight.String())
return nil
}
2 changes: 1 addition & 1 deletion server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type (

// RegisterGRPCServer registers gRPC services directly with the gRPC
// server.
RegisterGRPCServer(grpc.Server)
RegisterGRPCServer(grpc.Server, bool)

// RegisterTxService registers the gRPC Query service for tx (such as tx
// simulation, fetching txs by hash...).
Expand Down
3 changes: 3 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ type CommitMultiStore interface {
// Panics on a nil key.
GetCommitKVStore(key StoreKey) CommitKVStore

// Panics on a nil version.
GetCommitInfo(ver int64) (*CommitInfo, error)

// Load the latest persisted version. Called once after all calls to
// Mount*Store() are complete.
LoadLatestVersion() error
Expand Down
8 changes: 6 additions & 2 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ func (coins Coins) Add(coinsB ...Coin) Coins {
return coins.safeAdd(coinsB)
}

var zeroInt = NewInt(0)

// safeAdd will perform addition of two coins sets. If both coin sets are
// empty, then an empty set is returned. If only a single set is empty, the
// other set is returned. Otherwise, the coins are compared in order of their
Expand All @@ -335,7 +337,7 @@ func (coins Coins) safeAdd(coinsB Coins) (coalesced Coins) {
}

for denom, cL := range uniqCoins { //#nosec
comboCoin := Coin{Denom: denom, Amount: NewInt(0)}
comboCoin := Coin{Denom: denom, Amount: zeroInt}
for _, c := range cL {
comboCoin = comboCoin.Add(c)
}
Expand Down Expand Up @@ -827,7 +829,9 @@ var _ sort.Interface = Coins{}

// Sort is a helper function to sort the set of coins in-place
func (coins Coins) Sort() Coins {
sort.Sort(coins)
if len(coins) > 1 {
sort.Sort(coins)
}
return coins
}

Expand Down
2 changes: 1 addition & 1 deletion types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewABCIMessageLog(i uint32, log string, events Events) ABCIMessageLog {
// String implements the fmt.Stringer interface for the ABCIMessageLogs type.
func (logs ABCIMessageLogs) String() (str string) {
if logs != nil {
raw, err := cdc.MarshalJSON(logs)
raw, err := json.Marshal(logs)
if err == nil {
str = string(raw)
}
Expand Down
5 changes: 2 additions & 3 deletions types/result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types_test

import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
"testing"
Expand All @@ -13,7 +14,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -41,14 +41,13 @@ func (s *resultTestSuite) TestParseABCILog() {
}

func (s *resultTestSuite) TestABCIMessageLog() {
cdc := codec.NewLegacyAmino()
events := sdk.Events{
sdk.NewEvent("transfer", sdk.NewAttribute("sender", "foo")),
sdk.NewEvent("transfer", sdk.NewAttribute("sender", "bar")),
}
msgLog := sdk.NewABCIMessageLog(0, "", events)
msgLogs := sdk.ABCIMessageLogs{msgLog}
bz, err := cdc.MarshalJSON(msgLogs)
bz, err := json.Marshal(msgLogs)

s.Require().NoError(err)
s.Require().Equal(string(bz), msgLogs.String())
Expand Down
50 changes: 50 additions & 0 deletions x/auth/vesting/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"io/ioutil"
"os"
"strconv"
"time"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)

Expand Down Expand Up @@ -40,6 +42,7 @@ func GetTxCmd() *cobra.Command {
NewMsgCreatePermanentLockedAccountCmd(),
NewMsgCreatePeriodicVestingAccountCmd(),
NewMsgCreateClawbackVestingAccountCmd(),
NewMsgCreateCliffVestingAccountCmd(),
NewMsgClawbackCmd(),
)

Expand Down Expand Up @@ -377,3 +380,50 @@ func NewMsgClawbackCmd() *cobra.Command {
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// NewMsgCreateDelayedVestingAccountCmd returns a CLI command handler for creating a
// NewMsgCreateDelayedVestingAccountCmd transaction.
// This is hacky, but meant to mitigate the pain of a very specific use case.
// Namely, make it easy to make cliff locks to an address.
func NewMsgCreateCliffVestingAccountCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "create-cliff-vesting-account [to_address] [amount] [cliff_duration]",
Short: "Create a new cliff vesting account funded with an allocation of tokens.",
Long: `Create a new delayed vesting account funded with an allocation of tokens. All vesting accouts created will have their start time
set by the committed block's time. The cliff duration should be specified in hours.`,
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
toAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

amount, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}

cliffDuration, err := time.ParseDuration(args[2])
if err != nil {
err = errors.Wrap(err, "duration incorrectly formatted, see https://pkg.go.dev/time#ParseDuration")
return err
}
cliffVesting := true

endTime := time.Now().Add(cliffDuration)
endEpochTime := endTime.Unix()

msg := types.NewMsgCreateVestingAccount(clientCtx.GetFromAddress(), toAddr, amount, endEpochTime, cliffVesting)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
Loading

0 comments on commit 743e42a

Please sign in to comment.