Skip to content

Commit

Permalink
Merge branch 'main' into adam/reset-signing-info
Browse files Browse the repository at this point in the history
  • Loading branch information
czarcas7ic authored Apr 18, 2024
2 parents fbcd43c + fe5f836 commit 74a95bc
Show file tree
Hide file tree
Showing 133 changed files with 17,241 additions and 228 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
},
"rust-analyzer.checkOnSave": false
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### State Breaking

* [#8053](https://github.com/osmosis-labs/osmosis/pull/8053) Reset validator signing info missed blocks counter
* [#8030](https://github.com/osmosis-labs/osmosis/pull/8030) Delete legacy behavior where lockups could not unbond at very small block heights on a testnet.
* [#7005](https://github.com/osmosis-labs/osmosis/pull/7005) Adding deactivated smart account module.

### State Compatible

Expand Down
52 changes: 41 additions & 11 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (

storetypes "github.com/cosmos/cosmos-sdk/store/types"

smartaccountante "github.com/osmosis-labs/osmosis/v24/x/smart-account/ante"
smartaccountkeeper "github.com/osmosis-labs/osmosis/v24/x/smart-account/keeper"

txfeeskeeper "github.com/osmosis-labs/osmosis/v24/x/txfees/keeper"
txfeestypes "github.com/osmosis-labs/osmosis/v24/x/txfees/types"
)
Expand All @@ -32,7 +35,8 @@ func NewAnteHandler(
appOpts servertypes.AppOptions,
wasmConfig wasmtypes.WasmConfig,
txCounterStoreKey storetypes.StoreKey,
ak ante.AccountKeeper,
accountKeeper ante.AccountKeeper,
smartAccountKeeper *smartaccountkeeper.Keeper,
bankKeeper txfeestypes.BankKeeper,
txFeesKeeper *txfeeskeeper.Keeper,
spotPriceCalculator txfeestypes.SpotPriceCalculator,
Expand All @@ -44,7 +48,35 @@ func NewAnteHandler(
mempoolFeeDecorator := txfeeskeeper.NewMempoolFeeDecorator(*txFeesKeeper, mempoolFeeOptions)
sendblockOptions := osmoante.NewSendBlockOptions(appOpts)
sendblockDecorator := osmoante.NewSendBlockDecorator(sendblockOptions)
deductFeeDecorator := txfeeskeeper.NewDeductFeeDecorator(*txFeesKeeper, ak, bankKeeper, nil)
deductFeeDecorator := txfeeskeeper.NewDeductFeeDecorator(*txFeesKeeper, accountKeeper, bankKeeper, nil)

// classicSignatureVerificationDecorator is the old flow to enable a circuit breaker
classicSignatureVerificationDecorator := sdk.ChainAnteDecorators(
deductFeeDecorator,
// We use the old pubkey decorator here to ensure that accounts work as expected,
// in SetPubkeyDecorator we set a pubkey in the account store, for authenticators
// we avoid this code path completely.
ante.NewSetPubKeyDecorator(accountKeeper),
ante.NewValidateSigCountDecorator(accountKeeper),
ante.NewSigGasConsumeDecorator(accountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(accountKeeper, signModeHandler),
ante.NewIncrementSequenceDecorator(accountKeeper),
ibcante.NewRedundantRelayDecorator(channelKeeper),
)

// authenticatorVerificationDecorator is the new authenticator flow that's embedded into the circuit breaker ante
authenticatorVerificationDecorator := sdk.ChainAnteDecorators(
smartaccountante.LimitFeePayerDecorator{},
smartaccountante.NewSetPubKeyDecorator(accountKeeper),
ante.NewValidateSigCountDecorator(accountKeeper),
// Both the signature verification and gas consumption functionality
// is embedded in the authenticator decorator
smartaccountante.NewAuthenticatorDecorator(smartAccountKeeper, accountKeeper, signModeHandler),
ante.NewIncrementSequenceDecorator(accountKeeper),
ibcante.NewRedundantRelayDecorator(channelKeeper),
deductFeeDecorator,
)

return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(wasmConfig.SimulationGasLimit),
Expand All @@ -57,14 +89,12 @@ func NewAnteHandler(
sendblockDecorator,
ante.NewValidateBasicDecorator(),
ante.TxTimeoutHeightDecorator{},
ante.NewValidateMemoDecorator(ak),
ante.NewConsumeGasForTxSizeDecorator(ak),
deductFeeDecorator,
ante.NewSetPubKeyDecorator(ak), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(ak),
ante.NewSigGasConsumeDecorator(ak, sigGasConsumer),
ante.NewSigVerificationDecorator(ak, signModeHandler),
ante.NewIncrementSequenceDecorator(ak),
ibcante.NewRedundantRelayDecorator(channelKeeper),
ante.NewValidateMemoDecorator(accountKeeper),
ante.NewConsumeGasForTxSizeDecorator(accountKeeper),
smartaccountante.NewCircuitBreakerDecorator(
smartAccountKeeper,
authenticatorVerificationDecorator,
classicSignatureVerificationDecorator,
),
)
}
6 changes: 5 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ func NewOsmosisApp(
wasmConfig,
app.GetKey(wasmtypes.StoreKey),
app.AccountKeeper,
app.SmartAccountKeeper,
app.BankKeeper,
app.TxFeesKeeper,
app.GAMMKeeper,
Expand All @@ -415,7 +416,7 @@ func NewOsmosisApp(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
app.SetAnteHandler(anteHandler)
app.SetPostHandler(NewPostHandler(app.ProtoRevKeeper))
app.SetPostHandler(NewPostHandler(app.ProtoRevKeeper, app.SmartAccountKeeper, app.AccountKeeper, encodingConfig.TxConfig.SignModeHandler()))
app.SetEndBlocker(app.EndBlocker)

// Register snapshot extensions to enable state-sync for wasm.
Expand Down Expand Up @@ -468,6 +469,9 @@ func getSQSServiceWriteListeners(app *OsmosisApp, appCodec codec.Codec, blockPoo
writeListeners[app.GetKey(cosmwasmpooltypes.StoreKey)] = []storetypes.WriteListener{
writelistener.NewCosmwasmPool(blockPoolUpdateTracker),
}
writeListeners[app.GetKey(banktypes.StoreKey)] = []storetypes.WriteListener{
writelistener.NewCosmwasmPoolBalance(blockPoolUpdateTracker),
}
return writeListeners
}

Expand Down
34 changes: 34 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ import (
// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"

"github.com/osmosis-labs/osmosis/v24/x/smart-account/authenticator"
smartaccountkeeper "github.com/osmosis-labs/osmosis/v24/x/smart-account/keeper"
smartaccounttypes "github.com/osmosis-labs/osmosis/v24/x/smart-account/types"

_ "github.com/osmosis-labs/osmosis/v24/client/docs/statik"
owasm "github.com/osmosis-labs/osmosis/v24/wasmbinding"
concentratedliquidity "github.com/osmosis-labs/osmosis/v24/x/concentrated-liquidity"
Expand Down Expand Up @@ -168,6 +172,8 @@ type AppKeepers struct {
ValidatorSetPreferenceKeeper *valsetpref.Keeper
ConcentratedLiquidityKeeper *concentratedliquidity.Keeper
CosmwasmPoolKeeper *cosmwasmpool.Keeper
SmartAccountKeeper *smartaccountkeeper.Keeper
AuthenticatorManager *authenticator.AuthenticatorManager

// IBC modules
// transfer module
Expand Down Expand Up @@ -217,6 +223,27 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)
appKeepers.BankKeeper = &bankKeeper

// Initialize authenticators
appKeepers.AuthenticatorManager = authenticator.NewAuthenticatorManager()
appKeepers.AuthenticatorManager.InitializeAuthenticators([]authenticator.Authenticator{
authenticator.NewSignatureVerificationAuthenticator(appKeepers.AccountKeeper),
authenticator.NewMessageFilterAuthenticator(encodingConfig),
authenticator.NewAllOfAuthenticator(appKeepers.AuthenticatorManager),
authenticator.NewAnyOfAuthenticator(appKeepers.AuthenticatorManager),
authenticator.NewPartitionedAnyOfAuthenticator(appKeepers.AuthenticatorManager),
authenticator.NewPartitionedAllOfAuthenticator(appKeepers.AuthenticatorManager),
})
govModuleAddr := appKeepers.AccountKeeper.GetModuleAddress(govtypes.ModuleName)

smartAccountKeeper := smartaccountkeeper.NewKeeper(
appCodec,
appKeepers.keys[smartaccounttypes.ManagerStoreKey],
govModuleAddr,
appKeepers.GetSubspace(smartaccounttypes.ModuleName),
appKeepers.AuthenticatorManager,
)
appKeepers.SmartAccountKeeper = &smartAccountKeeper

authzKeeper := authzkeeper.NewKeeper(
appKeepers.keys[authzkeeper.StoreKey],
appCodec,
Expand Down Expand Up @@ -550,6 +577,10 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.IBCHooksKeeper.ContractKeeper = appKeepers.ContractKeeper
appKeepers.ConcentratedLiquidityKeeper.SetContractKeeper(appKeepers.ContractKeeper)

// register CosmWasm authenticator
appKeepers.AuthenticatorManager.RegisterAuthenticator(
authenticator.NewCosmwasmAuthenticator(appKeepers.ContractKeeper, appKeepers.AccountKeeper, encodingConfig.TxConfig.SignModeHandler(), appCodec))

// set token factory contract keeper
appKeepers.TokenFactoryKeeper.SetContractKeeper(appKeepers.ContractKeeper)

Expand Down Expand Up @@ -750,6 +781,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(cosmwasmpooltypes.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)
paramsKeeper.Subspace(smartaccounttypes.ModuleName).WithKeyTable(smartaccounttypes.ParamKeyTable())
paramsKeeper.Subspace(txfeestypes.ModuleName)

return paramsKeeper
Expand Down Expand Up @@ -873,5 +905,7 @@ func KVStoreKeys() []string {
icqtypes.StoreKey,
packetforwardtypes.StoreKey,
cosmwasmpooltypes.StoreKey,
smartaccounttypes.ManagerStoreKey,
smartaccounttypes.AuthenticatorStoreKey,
}
}
3 changes: 3 additions & 0 deletions app/keepers/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (

genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"

smartaccount "github.com/osmosis-labs/osmosis/v24/x/smart-account"

_ "github.com/osmosis-labs/osmosis/v24/client/docs/statik"
clclient "github.com/osmosis-labs/osmosis/v24/x/concentrated-liquidity/client"
concentratedliquidity "github.com/osmosis-labs/osmosis/v24/x/concentrated-liquidity/clmodule"
Expand Down Expand Up @@ -130,4 +132,5 @@ var AppModuleBasics = []module.AppModuleBasic{
packetforward.AppModuleBasic{},
cosmwasmpoolmodule.AppModuleBasic{},
tendermint.AppModuleBasic{},
smartaccount.AppModuleBasic{},
}
8 changes: 7 additions & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/client"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
"github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
Expand Down Expand Up @@ -40,7 +41,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
Expand All @@ -65,6 +65,9 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/osmosis/osmoutils/partialord"
smartaccount "github.com/osmosis-labs/osmosis/v24/x/smart-account"
smartaccounttypes "github.com/osmosis-labs/osmosis/v24/x/smart-account/types"

appparams "github.com/osmosis-labs/osmosis/v24/app/params"
_ "github.com/osmosis-labs/osmosis/v24/client/docs/statik"
"github.com/osmosis-labs/osmosis/v24/simulation/simtypes"
Expand Down Expand Up @@ -132,6 +135,7 @@ var moduleAccountPermissions = map[string][]string{
valsetpreftypes.ModuleName: {authtypes.Staking},
poolmanagertypes.ModuleName: nil,
cosmwasmpooltypes.ModuleName: nil,
smartaccounttypes.ModuleName: nil,
}

// appModules return modules to initialize module manager.
Expand Down Expand Up @@ -197,6 +201,7 @@ func appModules(
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
cwpoolmodule.NewAppModule(appCodec, *app.CosmwasmPoolKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
smartaccount.NewAppModule(appCodec, *app.SmartAccountKeeper),
}
}

Expand Down Expand Up @@ -264,6 +269,7 @@ func OrderInitGenesis(allModuleNames []string) []string {
protorevtypes.ModuleName,
twaptypes.ModuleName,
txfeestypes.ModuleName,
smartaccounttypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
paramstypes.ModuleName,
Expand Down
24 changes: 21 additions & 3 deletions app/posthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"

smartaccountkeeper "github.com/osmosis-labs/osmosis/v24/x/smart-account/keeper"
smartaccountpost "github.com/osmosis-labs/osmosis/v24/x/smart-account/post"

protorevkeeper "github.com/osmosis-labs/osmosis/v24/x/protorev/keeper"
)

func NewPostHandler(protoRevKeeper *protorevkeeper.Keeper) sdk.PostHandler {
protoRevDecorator := protorevkeeper.NewProtoRevDecorator(*protoRevKeeper)
return sdk.ChainPostDecorators(protoRevDecorator)
func NewPostHandler(
protoRevKeeper *protorevkeeper.Keeper,
smartAccountKeeper *smartaccountkeeper.Keeper,
accountKeeper *authkeeper.AccountKeeper,
sigModeHandler authsigning.SignModeHandler,
) sdk.PostHandler {
return sdk.ChainPostDecorators(
protorevkeeper.NewProtoRevDecorator(*protoRevKeeper),
smartaccountpost.NewAuthenticatorPostDecorator(
smartAccountKeeper,
accountKeeper,
sigModeHandler,
// Add an empty handler here to enable a circuit breaker pattern
sdk.ChainPostDecorators(sdk.Terminator{}),
),
)
}
7 changes: 6 additions & 1 deletion app/upgrades/v25/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/osmosis-labs/osmosis/v24/app/upgrades"

store "github.com/cosmos/cosmos-sdk/store/types"

smartaccounttypes "github.com/osmosis-labs/osmosis/v24/x/smart-account/types"
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v25 upgrade.
Expand All @@ -13,7 +15,10 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Added: []string{
smartaccounttypes.ManagerStoreKey,
smartaccounttypes.AuthenticatorStoreKey,
},
Deleted: []string{},
},
}
6 changes: 6 additions & 0 deletions app/upgrades/v25/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func CreateUpgradeHandler(
// Reset missed blocks counter for all validators
resetMissedBlocksCounter(ctx, keepers.SlashingKeeper)

// Set the authenticator params in the store
authenticatorParams := keepers.SmartAccountKeeper.GetParams(ctx)
authenticatorParams.MaximumUnauthenticatedGas = 120_000
authenticatorParams.IsSmartAccountActive = false
keepers.SmartAccountKeeper.SetParams(ctx, authenticatorParams)

return migrations, nil
}
}
Expand Down
Loading

0 comments on commit 74a95bc

Please sign in to comment.