Skip to content

Commit

Permalink
add circuit breaker module
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Aug 22, 2024
1 parent b64c773 commit c25e831
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
circuitante "cosmossdk.io/x/circuit/ante"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
globalfeeante "github.com/OmniFlix/omniflixhub/v5/x/globalfee/ante"
Expand Down Expand Up @@ -36,6 +37,7 @@ type HandlerOptions struct {

GlobalFeeKeeper globalfeekeeper.Keeper
StakingKeeper stakingkeeper.Keeper
CircuitKeeper circuitante.CircuitBreaker
}

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
Expand Down Expand Up @@ -75,6 +77,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
options.FeegrantKeeper,
options.TxFeeChecker,
),
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ func NewOmniFlixApp(
BypassMinFeeMsgTypes: GetDefaultBypassFeeMessages(),
GlobalFeeKeeper: app.GlobalFeeKeeper,
StakingKeeper: *app.StakingKeeper,
CircuitKeeper: &app.CircuitKeeper,
},
)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import (
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"

circuitkeeper "cosmossdk.io/x/circuit/keeper"
circuittypes "cosmossdk.io/x/circuit/types"

distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

Expand Down Expand Up @@ -155,6 +158,7 @@ type AppKeepers struct {
IBCHooksKeeper ibchookskeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
CircuitKeeper circuitkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
GlobalFeeKeeper globalfeekeeper.Keeper
GroupKeeper groupkeeper.Keeper
Expand Down Expand Up @@ -272,6 +276,13 @@ func NewAppKeeper(
appKeepers.AccountKeeper,
)

appKeepers.CircuitKeeper = circuitkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[circuittypes.StoreKey]),
govModAddress,
addresscodec.NewBech32Codec(bech32AccountAddressPrefix),
)

appKeepers.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keepers

import (
storetypes "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
evidencetypes "cosmossdk.io/x/evidence/types"
"cosmossdk.io/x/feegrant"
upgradetypes "cosmossdk.io/x/upgrade/types"
Expand Down Expand Up @@ -58,6 +59,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
capabilitytypes.StoreKey,
crisistypes.StoreKey,
feegrant.StoreKey,
circuittypes.StoreKey,
wasmtypes.StoreKey,
globalfeetypes.StoreKey,
group.StoreKey,
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
// sdk v.50.x migration TODO:Eventually should get rid of this in favor of NewBasicManagerFromManager

import (
circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/nft"
"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -43,6 +44,8 @@ import (
"cosmossdk.io/x/feegrant"
feegrantmodule "cosmossdk.io/x/feegrant/module"

"cosmossdk.io/x/circuit"

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

Expand Down Expand Up @@ -130,6 +133,7 @@ var (
ibchooks.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
circuit.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
Expand Down Expand Up @@ -232,6 +236,7 @@ func appModules(
),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
circuit.NewAppModule(appCodec, app.CircuitKeeper),
upgrade.NewAppModule(app.UpgradeKeeper, addresscodec.NewBech32Codec(appparams.Bech32AccountAddrPrefix)),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
Expand Down Expand Up @@ -339,6 +344,7 @@ func orderBeginBlockers() []string {
authtypes.ModuleName,
crisistypes.ModuleName,
feegrant.ModuleName,
circuittypes.ModuleName,
globalfee.ModuleName,
tokenfactorytypes.ModuleName,
group.ModuleName,
Expand Down Expand Up @@ -375,6 +381,7 @@ func orderEndBlockers() []string {
distrtypes.ModuleName,
ibcexported.ModuleName,
feegrant.ModuleName,
circuittypes.ModuleName,
globalfee.ModuleName,
group.ModuleName,
tokenfactorytypes.ModuleName,
Expand Down Expand Up @@ -415,6 +422,7 @@ func orderInitGenesis() []string {
upgradetypes.ModuleName,
vestingtypes.ModuleName,
feegrant.ModuleName,
circuittypes.ModuleName,
ibchookstypes.ModuleName,
wasmtypes.ModuleName,
globalfee.ModuleName,
Expand Down
5 changes: 4 additions & 1 deletion app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v5

import (
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
"github.com/OmniFlix/omniflixhub/v5/app/upgrades"
)

Expand All @@ -11,6 +12,8 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV5UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Added: []string{
circuittypes.StoreKey,
},
},
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.1.0
cosmossdk.io/x/circuit v0.1.1
cosmossdk.io/x/evidence v0.1.1
cosmossdk.io/x/feegrant v0.1.1
cosmossdk.io/x/nft v0.1.1
Expand Down

0 comments on commit c25e831

Please sign in to comment.