-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: switch from L2 to L1 (#161)
## Description This PR updates the codebase to switch our chain from being an L2 based on the Initia `opinit` stack to be a sovereign Cosmos-SDK based chain. The main changes that have been made are the following: * replaced the `opchild` module with `gov`, `distribution`, `slashing` and `staking` * updated the Bech32 prefix to be `milk` instead of `initi` * set the default denomination to be `umilk` Closes: MILK-127, MILK-120 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [x] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [x] included the necessary unit and integration [tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --------- Co-authored-by: Manuel <[email protected]>
- Loading branch information
Showing
154 changed files
with
8,506 additions
and
9,296 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package ante | ||
|
||
import ( | ||
feemarketante "github.com/skip-mev/feemarket/x/feemarket/ante" | ||
feemarketkeeper "github.com/skip-mev/feemarket/x/feemarket/keeper" | ||
|
||
milkywayerrors "github.com/milkyway-labs/milkyway/types/errors" | ||
|
||
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante" | ||
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" | ||
|
||
corestoretypes "cosmossdk.io/core/store" | ||
errorsmod "cosmossdk.io/errors" | ||
storetypes "cosmossdk.io/store/types" | ||
txsigning "cosmossdk.io/x/tx/signing" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/tx/signing" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
|
||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
) | ||
|
||
// UseFeeMarketDecorator to make the integration testing easier: we can switch off its ante and post decorators with this flag | ||
var UseFeeMarketDecorator = true | ||
|
||
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC | ||
// channel keeper. | ||
type HandlerOptions struct { | ||
ExtensionOptionChecker ante.ExtensionOptionChecker | ||
FeegrantKeeper ante.FeegrantKeeper | ||
SignModeHandler *txsigning.HandlerMap | ||
SigGasConsumer func(meter storetypes.GasMeter, sig signing.SignatureV2, params authtypes.Params) error | ||
|
||
AccountKeeper feemarketante.AccountKeeper | ||
BankKeeper feemarketante.BankKeeper | ||
Codec codec.BinaryCodec | ||
IBCkeeper *ibckeeper.Keeper | ||
StakingKeeper *stakingkeeper.Keeper | ||
FeeMarketKeeper *feemarketkeeper.Keeper | ||
TxFeeChecker ante.TxFeeChecker | ||
TXCounterStoreService corestoretypes.KVStoreService | ||
WasmConfig *wasmtypes.WasmConfig | ||
} | ||
|
||
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { | ||
if opts.AccountKeeper == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "account keeper is required for AnteHandler") | ||
} | ||
if opts.BankKeeper == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "bank keeper is required for AnteHandler") | ||
} | ||
if opts.SignModeHandler == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "sign mode handler is required for AnteHandler") | ||
} | ||
if opts.IBCkeeper == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "IBC keeper is required for AnteHandler") | ||
} | ||
if opts.FeeMarketKeeper == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrLogic, "FeeMarket keeper is required for AnteHandler") | ||
} | ||
|
||
if opts.StakingKeeper == nil { | ||
return nil, errorsmod.Wrap(milkywayerrors.ErrNotFound, "staking param store is required for AnteHandler") | ||
} | ||
|
||
sigGasConsumer := opts.SigGasConsumer | ||
if sigGasConsumer == nil { | ||
sigGasConsumer = ante.DefaultSigVerificationGasConsumer | ||
} | ||
|
||
anteDecorators := []sdk.AnteDecorator{ | ||
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
wasmkeeper.NewLimitSimulationGasDecorator(opts.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early | ||
wasmkeeper.NewCountTXDecorator(opts.TXCounterStoreService), | ||
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker), | ||
ante.NewValidateBasicDecorator(), | ||
ante.NewTxTimeoutHeightDecorator(), | ||
ante.NewValidateMemoDecorator(opts.AccountKeeper), | ||
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), | ||
NewGovVoteDecorator(opts.Codec, opts.StakingKeeper), | ||
NewGovExpeditedProposalsDecorator(opts.Codec), | ||
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators | ||
ante.NewValidateSigCountDecorator(opts.AccountKeeper), | ||
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer), | ||
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler), | ||
ante.NewIncrementSequenceDecorator(opts.AccountKeeper), | ||
ibcante.NewRedundantRelayDecorator(opts.IBCkeeper), | ||
} | ||
|
||
if UseFeeMarketDecorator { | ||
anteDecorators = append(anteDecorators, | ||
feemarketante.NewFeeMarketCheckDecorator( | ||
opts.AccountKeeper, | ||
opts.BankKeeper, | ||
opts.FeegrantKeeper, | ||
opts.FeeMarketKeeper, | ||
ante.NewDeductFeeDecorator( | ||
opts.AccountKeeper, | ||
opts.BankKeeper, | ||
opts.FeegrantKeeper, | ||
opts.TxFeeChecker))) | ||
} | ||
|
||
return sdk.ChainAnteDecorators(anteDecorators...), nil | ||
} |
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,80 @@ | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
|
||
milkywayerrors "github.com/milkyway-labs/milkyway/types/errors" | ||
) | ||
|
||
var expeditedPropDecoratorEnabled = true | ||
|
||
// SetExpeditedProposalsEnabled toggles the expedited proposals decorator on/off. | ||
// Should only be used in testing - this is to allow simtests to pass. | ||
func SetExpeditedProposalsEnabled(val bool) { | ||
expeditedPropDecoratorEnabled = val | ||
} | ||
|
||
var expeditedPropsWhitelist = map[string]struct{}{ | ||
"/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade": {}, | ||
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {}, | ||
} | ||
|
||
// Check if the proposal is whitelisted for expedited voting. | ||
type GovExpeditedProposalsDecorator struct { | ||
cdc codec.BinaryCodec | ||
} | ||
|
||
func NewGovExpeditedProposalsDecorator(cdc codec.BinaryCodec) GovExpeditedProposalsDecorator { | ||
return GovExpeditedProposalsDecorator{ | ||
cdc: cdc, | ||
} | ||
} | ||
|
||
// AnteHandle checks if the proposal is whitelisted for expedited voting. | ||
// Only proposals submitted using "milkywayd tx gov submit-proposal" can be expedited. | ||
// Legacy proposals submitted using "milkywayd tx gov submit-legacy-proposal" cannot be marked as expedited. | ||
func (g GovExpeditedProposalsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
if expeditedPropDecoratorEnabled { | ||
for _, msg := range tx.GetMsgs() { | ||
prop, ok := msg.(*govv1.MsgSubmitProposal) | ||
if !ok { | ||
continue | ||
} | ||
if prop.Expedited { | ||
if err := g.validateExpeditedGovProp(prop); err != nil { | ||
return ctx, err | ||
} | ||
} | ||
} | ||
} | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
func (g GovExpeditedProposalsDecorator) isWhitelisted(msgType string) bool { | ||
_, ok := expeditedPropsWhitelist[msgType] | ||
return ok | ||
} | ||
|
||
func (g GovExpeditedProposalsDecorator) validateExpeditedGovProp(prop *govv1.MsgSubmitProposal) error { | ||
msgs := prop.GetMessages() | ||
if len(msgs) == 0 { | ||
return milkywayerrors.ErrInvalidExpeditedProposal | ||
} | ||
for _, message := range msgs { | ||
// in case of legacy content submitted using govv1.MsgSubmitProposal | ||
if sdkMsg, isLegacy := message.GetCachedValue().(*govv1.MsgExecLegacyContent); isLegacy { | ||
if !g.isWhitelisted(sdkMsg.Content.TypeUrl) { | ||
return errorsmod.Wrapf(milkywayerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", sdkMsg.Content.TypeUrl) | ||
} | ||
continue | ||
} | ||
if !g.isWhitelisted(message.TypeUrl) { | ||
return errorsmod.Wrapf(milkywayerrors.ErrInvalidExpeditedProposal, "invalid Msg type: %s", message.TypeUrl) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.