Skip to content
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

Add warnings when provider unbonding is shorter than consumer unbonding #858

Merged
Merged
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions x/ccv/provider/client/proposal_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package client

import (
"context"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -15,6 +16,7 @@ import (
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govrest "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
clienttypes "github.com/cosmos/ibc-go/v4/modules/core/02-client/types"
"github.com/cosmos/interchain-security/x/ccv/provider/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -74,6 +76,15 @@ Where proposal.json contains:
return err
}

// do not fail for errors regarding the unbonding period, but just log a warning
err = CheckPropUnbondingPeriod(clientCtx, proposal.UnbondingPeriod)
if err != nil {
fmt.Fprint(
os.Stderr,
err.Error(),
)
}

content := types.NewConsumerAdditionProposal(
proposal.Title, proposal.Description, proposal.ChainId, proposal.InitialHeight,
proposal.GenesisHash, proposal.BinaryHash, proposal.SpawnTime,
Expand Down Expand Up @@ -441,3 +452,26 @@ func postEquivocationProposalHandlerFn(clientCtx client.Context) http.HandlerFun
tx.WriteGeneratedTxResponse(clientCtx, w, req.BaseReq, msg)
}
}

func CheckPropUnbondingPeriod(clientCtx client.Context, propUnbondingPeriod time.Duration) error {
queryClient := stakingtypes.NewQueryClient(clientCtx)

res, err := queryClient.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
if err != nil {
return err
}

providerUnbondingTime := res.Params.UnbondingTime

if providerUnbondingTime < propUnbondingPeriod {
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf(
`consumer unbonding period is advised to be smaller than provider unbonding period, but is longer.
This is not a security risk, but will effectively lengthen the unbonding period on the provider.
consumer unbonding: %s
provider unbonding: %s`,
propUnbondingPeriod,
providerUnbondingTime)
}

return nil
}