Skip to content

Commit

Permalink
lsnative: incremental diff containing distilled patch for adding LSM …
Browse files Browse the repository at this point in the history
…to 0.46.11

This diff contains:
* slashing module changes
* staking module changes
* genutil module changes
* distribution module changes
* staking proto changes
* distribution proto changes
* added new protocgen.sh
  • Loading branch information
Maksim Kupriianov committed Apr 3, 2023
1 parent 46c48bb commit d754c6f
Show file tree
Hide file tree
Showing 130 changed files with 3,409 additions and 741 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ go 1.19

require (
cosmossdk.io/math v1.0.0-beta.3
github.com/armon/go-metrics v0.4.1
github.com/cosmos/cosmos-proto v1.0.0-alpha8
github.com/cosmos/cosmos-sdk v0.46.11
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v6 v6.1.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.27
Expand All @@ -22,6 +27,7 @@ require (
google.golang.org/grpc v1.52.0
google.golang.org/protobuf v1.28.2-0.20220831092852-f930b1dc76e8
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/yaml v1.3.0
)

require (
Expand All @@ -36,7 +42,6 @@ require (
github.com/99designs/keyring v1.2.1 // indirect
github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect
github.com/Workiva/go-datastructures v1.0.53 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aws/aws-sdk-go v1.40.45 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
Expand All @@ -51,8 +56,6 @@ require (
github.com/cometbft/cometbft-db v0.7.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha8 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.5 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
Expand Down Expand Up @@ -119,7 +122,6 @@ require (
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand All @@ -132,7 +134,6 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect
Expand All @@ -155,7 +156,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace (
Expand Down
4 changes: 2 additions & 2 deletions x/lsnative/distribution/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/keeper"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// BeginBlocker sets the proposer for determining distribution during endblock
Expand Down
51 changes: 49 additions & 2 deletions x/lsnative/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
sdkdistr "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// GetQueryCmd returns the cli query commands for this module
Expand All @@ -31,6 +32,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryValidatorSlashes(),
GetCmdQueryDelegatorRewards(),
GetCmdQueryCommunityPool(),
GetCmdQueryTokenizeShareRecordReward(),
)

return distQueryCmd
Expand Down Expand Up @@ -260,7 +262,7 @@ $ %s query distribution rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p %s1ggh

res, err := queryClient.DelegationRewards(
ctx,
&types.QueryDelegationRewardsRequest{DelegatorAddress: delegatorAddr.String(), ValidatorAddress: validatorAddr.String()},
&sdkdistr.QueryDelegationRewardsRequest{DelegatorAddress: delegatorAddr.String(), ValidatorAddress: validatorAddr.String()},
)
if err != nil {
return err
Expand Down Expand Up @@ -319,3 +321,48 @@ $ %s query distribution community-pool
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdQueryTokenizeShareRecordReward implements the query tokenize share record rewards
func GetCmdQueryTokenizeShareRecordReward() *cobra.Command {
bech32PrefixAccAddr := sdk.GetConfig().GetBech32AccountAddrPrefix()

cmd := &cobra.Command{
Use: "tokenize-share-record-rewards [owner]",
Args: cobra.ExactArgs(1),
Short: "Query distribution tokenize share record rewards",
Long: strings.TrimSpace(
fmt.Sprintf(`Query the query tokenize share record rewards.
Example:
$ %s query distribution tokenize-share-record-rewards %s1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhffj
`,
version.AppName, bech32PrefixAccAddr,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

ownerAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

res, err := queryClient.TokenizeShareRecordReward(
cmd.Context(),
&types.QueryTokenizeShareRecordRewardRequest{OwnerAddress: ownerAddr.String()},
)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
74 changes: 73 additions & 1 deletion x/lsnative/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"
Expand All @@ -12,8 +13,8 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// Transaction flags for the x/distribution module
Expand Down Expand Up @@ -41,6 +42,8 @@ func NewTxCmd() *cobra.Command {
NewWithdrawAllRewardsCmd(),
NewSetWithdrawAddrCmd(),
NewFundCommunityPoolCmd(),
NewWithdrawTokenizeShareRecordRewardCmd(),
NewWithdrawAllTokenizeShareRecordRewardCmd(),
)

return distTxCmd
Expand Down Expand Up @@ -326,3 +329,72 @@ Where proposal.json contains:

return cmd
}

// WithdrawAllTokenizeShareRecordReward defines a method to withdraw reward for all owning TokenizeShareRecord
func NewWithdrawAllTokenizeShareRecordRewardCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-all-tokenize-share-rewards",
Args: cobra.ExactArgs(0),
Short: "Withdraw reward for all owning TokenizeShareRecord",
Long: strings.TrimSpace(
fmt.Sprintf(`Withdraw reward for all owned TokenizeShareRecord
Example:
$ %s tx distribution withdraw-tokenize-share-rewards --from mykey
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgWithdrawAllTokenizeShareRecordReward(clientCtx.GetFromAddress())

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

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// WithdrawTokenizeShareRecordReward defines a method to withdraw reward for an owning TokenizeShareRecord
func NewWithdrawTokenizeShareRecordRewardCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-tokenize-share-rewards",
Args: cobra.ExactArgs(1),
Short: "Withdraw reward for an owning TokenizeShareRecord",
Long: strings.TrimSpace(
fmt.Sprintf(`Withdraw reward for an owned TokenizeShareRecord
Example:
$ %s tx distribution withdraw-tokenize-share-rewards 1 --from mykey
`,
version.AppName,
),
),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

recordId, err := strconv.Atoi(args[0])
if err != nil {
return err
}

msg := types.NewMsgWithdrawTokenizeShareRecordReward(clientCtx.GetFromAddress(), uint64(recordId))

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

flags.AddTxFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion x/lsnative/distribution/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// ParseCommunityPoolSpendProposalWithDeposit reads and parses a CommunityPoolSpendProposalWithDeposit from a file.
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/distribution/client/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// QueryDelegationRewards queries a delegation rewards between a delegator and a
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/distribution/client/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package client

import (
"github.com/cosmos/cosmos-sdk/x/distribution/client/cli"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/client/cli"
)

// ProposalHandler is the community spend proposal handler.
Expand Down
4 changes: 2 additions & 2 deletions x/lsnative/distribution/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package distribution
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/keeper"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

func NewCommunityPoolSpendProposalHandler(k keeper.Keeper) govtypes.Handler {
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/distribution/keeper/alias_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// get outstanding rewards
Expand Down
6 changes: 3 additions & 3 deletions x/lsnative/distribution/keeper/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
sdkstaking "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// AllocateTokens handles distribution of the collected fees
Expand Down Expand Up @@ -108,7 +108,7 @@ func (k Keeper) AllocateTokens(

// AllocateTokensToValidator allocate tokens to a particular validator,
// splitting according to commission.
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) {
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val sdkstaking.ValidatorI, tokens sdk.DecCoins) {
// split tokens between validator and delegators according to commission
commission := tokens.MulDec(val.GetCommission())
shared := tokens.Sub(commission)
Expand Down
13 changes: 7 additions & 6 deletions x/lsnative/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
sdkdistr "github.com/cosmos/cosmos-sdk/x/distribution/types"
sdkstaking "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// initialize starting info for a new delegation
Expand All @@ -27,7 +28,7 @@ func (k Keeper) initializeDelegation(ctx sdk.Context, val sdk.ValAddress, del sd
}

// calculate the rewards accrued by a delegation between two periods
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val stakingtypes.ValidatorI,
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val sdkstaking.ValidatorI,
startingPeriod, endingPeriod uint64, stake sdk.Dec,
) (rewards sdk.DecCoins) {
// sanity check
Expand All @@ -53,7 +54,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val stakingty
}

// calculate the total rewards accrued by a delegation
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val sdkstaking.ValidatorI, del sdkstaking.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
// fetch starting info for delegation
startingInfo := k.GetDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr())

Expand Down Expand Up @@ -136,10 +137,10 @@ func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.Val
return rewards
}

func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI) (sdk.Coins, error) {
func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val sdkstaking.ValidatorI, del sdkstaking.DelegationI) (sdk.Coins, error) {
// check existence of delegator starting info
if !k.HasDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) {
return nil, types.ErrEmptyDelegationDistInfo
return nil, sdkdistr.ErrEmptyDelegationDistInfo
}

// end current period and calculate rewards
Expand Down
5 changes: 3 additions & 2 deletions x/lsnative/distribution/keeper/fee_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
sdkdistr "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// DistributeFromFeePool distributes funds from the distribution module account to
Expand All @@ -15,7 +16,7 @@ func (k Keeper) DistributeFromFeePool(ctx sdk.Context, amount sdk.Coins, receive
// must be reduced separately from the SendCoinsFromModuleToAccount call
newPool, negative := feePool.CommunityPool.SafeSub(sdk.NewDecCoinsFromCoins(amount...))
if negative {
return types.ErrBadDistribution
return sdkdistr.ErrBadDistribution
}

feePool.CommunityPool = newPool
Expand Down
2 changes: 1 addition & 1 deletion x/lsnative/distribution/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/persistenceOne/persistence-sdk/v2/x/lsnative/distribution/types"
)

// InitGenesis sets distribution information for genesis
Expand Down

0 comments on commit d754c6f

Please sign in to comment.