Skip to content

Commit

Permalink
Merge pull request #651 from KiraCore/release/v0.3.44
Browse files Browse the repository at this point in the history
release/v0.3.44 -> master
  • Loading branch information
kmlbgn authored Apr 12, 2024
2 parents 6c1d3fc + f6733ba commit 9a5445b
Show file tree
Hide file tree
Showing 90 changed files with 2,227 additions and 1,875 deletions.
480 changes: 240 additions & 240 deletions .github/workflows/main.yml

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Features:

- Docs update
- Set execution fees proposal
- Proper error handling for non existing identity records key from an address
- Fix usage of native cosmos staking module msg to custom staking module msg
- Unique identity keys
- Genesis init fix
- CLI to use flags for execution fees proposal
- Slashing module params to gov module properties
- Identity record verification bug fix
- Network properties handling fix
79 changes: 40 additions & 39 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"time"

errorsmod "cosmossdk.io/errors"
kiratypes "github.com/KiraCore/sekai/types"
custodykeeper "github.com/KiraCore/sekai/x/custody/keeper"
custodytypes "github.com/KiraCore/sekai/x/custody/types"
Expand Down Expand Up @@ -80,7 +81,7 @@ func NewCustodyDecorator(ck custodykeeper.Keeper, gk customgovkeeper.Keeper) Cus
func (cd CustodyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

for _, msg := range feeTx.GetMsgs() {
Expand All @@ -92,126 +93,126 @@ func (cd CustodyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
{
msg, ok := msg.(*custodytypes.MsgCreateCustodyRecord)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeAddToCustodyWhiteList:
{
msg, ok := msg.(*custodytypes.MsgAddToCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeAddToCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgAddToCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeRemoveFromCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgRemoveFromCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeDropCustodyCustodians:
{
msg, ok := msg.(*custodytypes.MsgDropCustodyCustodians)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeRemoveFromCustodyWhiteList:
{
msg, ok := msg.(*custodytypes.MsgRemoveFromCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeDropCustodyWhiteList:
{
msg, ok := msg.(*custodytypes.MsgDropCustodyWhiteList)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidType, "Not a MsgCreateCustodyRecord")
}

hash := sha256.Sum256([]byte(msg.OldKey))
hashString := hex.EncodeToString(hash[:])

if msg.TargetAddress != "" && msg.TargetAddress != settings.NextController {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongTargetAddr, "Custody module")
}

if hashString != settings.Key {
return ctx, sdkerrors.Wrap(custodytypes.ErrWrongKey, "Custody module")
return ctx, errorsmod.Wrap(custodytypes.ErrWrongKey, "Custody module")
}
}
case kiratypes.MsgTypeSend:
Expand All @@ -222,15 +223,15 @@ func (cd CustodyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
count := uint64(len(custodians.Addresses))

if len(msg.Reward) < 1 {
return ctx, sdkerrors.Wrap(custodytypes.ErrNotEnoughReward, "no reward")
return ctx, errorsmod.Wrap(custodytypes.ErrNotEnoughReward, "no reward")
}

if msg.Reward[0].Amount.Uint64() < properties.MinCustodyReward*count {
return ctx, sdkerrors.Wrap(custodytypes.ErrNotEnoughReward, "to small reward")
return ctx, errorsmod.Wrap(custodytypes.ErrNotEnoughReward, "to small reward")
}

if msg.Reward[0].Denom != cd.ck.DefaultDenom(ctx) {
return ctx, sdkerrors.Wrap(custodytypes.ErrNotEnoughReward, "wrong reward denom")
return ctx, errorsmod.Wrap(custodytypes.ErrNotEnoughReward, "wrong reward denom")
}
}
}
Expand All @@ -244,7 +245,7 @@ func (cd CustodyDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
custodians := cd.ck.GetCustodyCustodiansByAddress(ctx, msg.GetSigners()[0])

if len(custodians.Addresses) > 0 {
return ctx, sdkerrors.Wrap(sdkerrors.ErrConflict, "Custody module is enabled. Please use custody send instead.")
return ctx, errorsmod.Wrap(sdkerrors.ErrConflict, "Custody module is enabled. Please use custody send instead.")
}
}

Expand Down Expand Up @@ -316,7 +317,7 @@ func NewValidateFeeRangeDecorator(
func (svd ValidateFeeRangeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}

properties := svd.cgk.GetNetworkProperties(ctx)
Expand All @@ -328,13 +329,13 @@ func (svd ValidateFeeRangeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
for _, feeCoin := range feeCoins {
rate := svd.tk.GetTokenRate(ctx, feeCoin.Denom)
if !properties.EnableForeignFeePayments && feeCoin.Denom != defaultDenom {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("foreign fee payments is disabled by governance"))
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("foreign fee payments is disabled by governance"))
}
if rate == nil || !rate.FeePayments {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("currency you are trying to use was not whitelisted as fee payment"))
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("currency you are trying to use was not whitelisted as fee payment"))
}
if tokensBlackWhite.IsFrozen(feeCoin.Denom, defaultDenom, properties.EnableTokenBlacklist, properties.EnableTokenWhitelist) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("currency you are trying to use as fee is frozen"))
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("currency you are trying to use as fee is frozen"))
}
feeAmount = feeAmount.Add(sdk.NewDecFromInt(feeCoin.Amount).Mul(rate.FeeRate))
}
Expand All @@ -353,11 +354,11 @@ func (svd ValidateFeeRangeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
}

if feeAmount.LT(sdk.NewDec(int64(properties.MinTxFee))) || feeAmount.GT(sdk.NewDec(int64(properties.MaxTxFee))) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("fee %+v(%d) is out of range [%d, %d]%s", feeTx.GetFee(), feeAmount.RoundInt().Int64(), properties.MinTxFee, properties.MaxTxFee, defaultDenom))
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("fee %+v(%d) is out of range [%d, %d]%s", feeTx.GetFee(), feeAmount.RoundInt().Int64(), properties.MinTxFee, properties.MaxTxFee, defaultDenom))
}

if feeAmount.LT(sdk.NewDec(int64(executionMaxFee))) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("fee %+v(%d) is less than max execution fee %d%s", feeTx.GetFee(), feeAmount.RoundInt().Int64(), executionMaxFee, defaultDenom))
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, fmt.Sprintf("fee %+v(%d) is less than max execution fee %d%s", feeTx.GetFee(), feeAmount.RoundInt().Int64(), executionMaxFee, defaultDenom))
}

return next(ctx, tx, simulate)
Expand All @@ -383,7 +384,7 @@ func NewExecutionFeeRegistrationDecorator(ak keeper.AccountKeeper, cgk customgov
func (sgcd ExecutionFeeRegistrationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
sigTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

// execution fee consume gas
Expand Down Expand Up @@ -426,7 +427,7 @@ func findString(a []string, x string) int {
func (pnmd PoorNetworkManagementDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
sigTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

// if not poor network, skip this process
Expand All @@ -440,18 +441,18 @@ func (pnmd PoorNetworkManagementDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx
// on poor network, we introduce POOR_NETWORK_MAX_BANK_TX_SEND network property to limit transaction send amount
msg := msg.(*bank.MsgSend)
if len(msg.Amount) > 1 || msg.Amount[0].Denom != pnmd.csk.DefaultDenom(ctx) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only bond denom is allowed on poor network")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "only bond denom is allowed on poor network")
}
if msg.Amount[0].Amount.Uint64() > pnmd.cgk.GetNetworkProperties(ctx).PoorNetworkMaxBankSend {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "only restricted amount send is allowed on poor network")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "only restricted amount send is allowed on poor network")
}
// TODO: we could do restriction to send only when target account does not exist on chain yet for more restriction
return next(ctx, tx, simulate)
}
if findString(pnmsgs.Messages, kiratypes.MsgType(msg)) >= 0 {
return next(ctx, tx, simulate)
}
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid transaction type on poor network")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "invalid transaction type on poor network")
}

return next(ctx, tx, simulate)
Expand All @@ -477,7 +478,7 @@ func NewBlackWhiteTokensCheckDecorator(cgk customgovkeeper.Keeper, csk customsta
func (pnmd BlackWhiteTokensCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
sigTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "invalid transaction type")
}

defaultDenom := pnmd.csk.DefaultDenom(ctx)
Expand All @@ -488,7 +489,7 @@ func (pnmd BlackWhiteTokensCheckDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx
msg := msg.(*bank.MsgSend)
for _, amt := range msg.Amount {
if tokensBlackWhite.IsFrozen(amt.Denom, defaultDenom, properties.EnableTokenBlacklist, properties.EnableTokenWhitelist) {
return ctx, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "token is frozen")
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "token is frozen")
}
}
}
Expand Down
Loading

0 comments on commit 9a5445b

Please sign in to comment.