-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor x/{gov, crisis} according to ADR 031 (#7533)
* Refactor x/gov according to ADR 31 * fix tests * Refactor x/crisis according to ADR 031 * fix lint * lint * lint * review changes * lint * review change * fic doc Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
Showing
10 changed files
with
1,099 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/crisis/types" | ||
) | ||
|
||
var _ types.MsgServer = Keeper{} | ||
|
||
func (k Keeper) VerifyInvariant(goCtx context.Context, msg *types.MsgVerifyInvariant) (*types.MsgVerifyInvariantResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
constantFee := sdk.NewCoins(k.GetConstantFee(ctx)) | ||
|
||
sender, err := sdk.AccAddressFromBech32(msg.Sender) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := k.SendCoinsFromAccountToFeeCollector(ctx, sender, constantFee); err != nil { | ||
return nil, err | ||
} | ||
|
||
// use a cached context to avoid gas costs during invariants | ||
cacheCtx, _ := ctx.CacheContext() | ||
|
||
found := false | ||
msgFullRoute := msg.FullInvariantRoute() | ||
|
||
var res string | ||
var stop bool | ||
for _, invarRoute := range k.Routes() { | ||
if invarRoute.FullRoute() == msgFullRoute { | ||
res, stop = invarRoute.Invar(cacheCtx) | ||
found = true | ||
|
||
break | ||
} | ||
} | ||
|
||
if !found { | ||
return nil, types.ErrUnknownInvariant | ||
} | ||
|
||
if stop { | ||
// NOTE currently, because the chain halts here, this transaction will never be included | ||
// in the blockchain thus the constant fee will have never been deducted. Thus no | ||
// refund is required. | ||
|
||
// TODO uncomment the following code block with implementation of the circuit breaker | ||
//// refund constant fee | ||
//err := k.distrKeeper.DistributeFromFeePool(ctx, constantFee, msg.Sender) | ||
//if err != nil { | ||
//// if there are insufficient coins to refund, log the error, | ||
//// but still halt the chain. | ||
//logger := ctx.Logger().With("module", "x/crisis") | ||
//logger.Error(fmt.Sprintf( | ||
//"WARNING: insufficient funds to allocate to sender from fee pool, err: %s", err)) | ||
//} | ||
|
||
// TODO replace with circuit breaker | ||
panic(res) | ||
} | ||
|
||
ctx.EventManager().EmitEvents(sdk.Events{ | ||
sdk.NewEvent( | ||
types.EventTypeInvariant, | ||
sdk.NewAttribute(types.AttributeKeyRoute, msg.InvariantRoute), | ||
), | ||
sdk.NewEvent( | ||
sdk.EventTypeMessage, | ||
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCrisis), | ||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender), | ||
), | ||
}) | ||
|
||
return &types.MsgVerifyInvariantResponse{}, nil | ||
} |
Oops, something went wrong.