Skip to content

Commit

Permalink
Merge pull request #775 from cybercongress/v4-final
Browse files Browse the repository at this point in the history
V4 final updates
  • Loading branch information
cyborgshead authored Sep 30, 2024
2 parents 5a115a0 + ce8a710 commit 23359d6
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ contracts
# Scripts
*.mjs

*.wasm
*.wasm

cmd/iavltool/*.txt
16 changes: 14 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
"fmt"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cybercongress/go-cyber/v4/client/docs"
bandwidthkeeper "github.com/cybercongress/go-cyber/v4/x/bandwidth/keeper"
cyberbankkeeper "github.com/cybercongress/go-cyber/v4/x/cyberbank/keeper"
graphkeeper "github.com/cybercongress/go-cyber/v4/x/graph/keeper"
rankkeeper "github.com/cybercongress/go-cyber/v4/x/rank/keeper"
"io"
"os"
"time"
Expand Down Expand Up @@ -257,7 +261,7 @@ func NewApp(
IBCKeeper: app.IBCKeeper,
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
WasmConfig: &wasmConfig,
WasmKeeper: &app.WasmKeeper,
WasmKeeper: app.WasmKeeper,
},
)
if err != nil {
Expand All @@ -271,8 +275,15 @@ func NewApp(
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)

// Register snapshot extensions to enable state-sync for wasm and cyber modules
if manager := app.SnapshotManager(); manager != nil {
err = manager.RegisterExtensions(wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.AppKeepers.WasmKeeper))
err = manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), app.WasmKeeper),
cyberbankkeeper.NewCyberbankSnapshotter(app.CommitMultiStore(), app.CyberbankKeeper),
graphkeeper.NewGraphSnapshotter(app.CommitMultiStore(), app.AppKeepers.GraphKeeper, app.IndexKeeper),
bandwidthkeeper.NewBandwidthSnapshotter(app.CommitMultiStore(), app.BandwidthMeter),
rankkeeper.NewRankSnapshotter(app.CommitMultiStore(), app.RankKeeper),
)
if err != nil {
panic("failed to register snapshot extension: " + err.Error())
}
Expand Down Expand Up @@ -522,6 +533,7 @@ func (app *App) loadContexts(db dbm.DB, ctx sdk.Context) {
app.RankKeeper.StartRankCalculation(freshCtx)
} else {
// genesis case
// NOTE this flow when starting from snapshot
app.CyberbankKeeper.LoadState(freshCtx, freshCtx)
// TODO update index state load to one context as we store cyberlink' block now
app.IndexKeeper.LoadState(freshCtx, freshCtx)
Expand Down
85 changes: 47 additions & 38 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,33 @@ type AppKeepers struct {
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICQKeeper icqkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
NFTKeeper nftkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

TokenFactoryKeeper tokenfactorykeeper.Keeper
WasmKeeper wasmkeeper.Keeper
LiquidityKeeper liquiditykeeper.Keeper
BandwidthMeter *bandwidthkeeper.BandwidthMeter
CyberbankKeeper *cyberbankkeeper.IndexedKeeper
GraphKeeper *graphkeeper.GraphKeeper
IndexKeeper *graphkeeper.IndexKeeper
RankKeeper *rankkeeper.StateKeeper
GridKeeper gridkeeper.Keeper
DmnKeeper *dmnkeeper.Keeper
ResourcesKeeper resourceskeeper.Keeper
ContractKeeper wasmtypes.ContractOpsKeeper
ClockKeeper clockkeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
ICQKeeper *icqkeeper.Keeper
ICAHostKeeper *icahostkeeper.Keeper
ICAControllerKeeper *icacontrollerkeeper.Keeper
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
TransferKeeper *ibctransferkeeper.Keeper

TokenFactoryKeeper tokenfactorykeeper.Keeper
WasmKeeper *wasmkeeper.Keeper
LiquidityKeeper liquiditykeeper.Keeper
BandwidthMeter *bandwidthkeeper.BandwidthMeter
CyberbankKeeper *cyberbankkeeper.IndexedKeeper
GraphKeeper *graphkeeper.GraphKeeper
IndexKeeper *graphkeeper.IndexKeeper
RankKeeper *rankkeeper.StateKeeper
GridKeeper gridkeeper.Keeper
DmnKeeper *dmnkeeper.Keeper
ResourcesKeeper resourceskeeper.Keeper
ContractKeeper wasmtypes.ContractOpsKeeper
ClockKeeper clockkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICQKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -197,9 +197,12 @@ type AppKeepers struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedWasmKeeper capabilitykeeper.ScopedKeeper

// IBC modules
// transfer module
// Middleware wrapper
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware
PacketForwardKeeper *packetforwardkeeper.Keeper
}

func NewAppKeepers(
Expand Down Expand Up @@ -492,7 +495,7 @@ func NewAppKeepers(
appKeepers.IBCHooksKeeper = &hooksKeeper

cyberPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(appKeepers.IBCHooksKeeper, &appKeepers.WasmKeeper, cyberPrefix) // The contract keeper needs to be set later
wasmHooks := ibchooks.NewWasmHooks(appKeepers.IBCHooksKeeper, appKeepers.WasmKeeper, cyberPrefix) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -525,7 +528,7 @@ func NewAppKeepers(
)

// Create Transfer Keepers
appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
transferKeeper := ibctransferkeeper.NewKeeper(
appCodec,
keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
Expand All @@ -537,12 +540,13 @@ func NewAppKeepers(
appKeepers.CyberbankKeeper.Proxy,
scopedTransferKeeper,
)
appKeepers.TransferKeeper = &transferKeeper

// Must be called on PFMRouter AFTER TransferKeeper initialized
appKeepers.PacketForwardKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

// ICQ Keeper
appKeepers.ICQKeeper = icqkeeper.NewKeeper(
icqKeeper := icqkeeper.NewKeeper(
appCodec,
appKeepers.keys[icqtypes.StoreKey],
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware
Expand All @@ -552,8 +556,9 @@ func NewAppKeepers(
bApp.GRPCQueryRouter(),
govModAddress,
)
appKeepers.ICQKeeper = &icqKeeper

appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
icaHostKeeper := icahostkeeper.NewKeeper(
appCodec,
keys[icahosttypes.StoreKey],
appKeepers.GetSubspace(icahosttypes.SubModuleName),
Expand All @@ -564,11 +569,12 @@ func NewAppKeepers(
scopedICAHostKeeper,
bApp.MsgServiceRouter(),
)
appKeepers.ICAHostKeeper = &icaHostKeeper

// required since ibc-go v7.5.0
appKeepers.ICAHostKeeper.WithQueryRouter(bApp.GRPCQueryRouter())

appKeepers.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
icaControllerKeeper := icacontrollerkeeper.NewKeeper(
appCodec,
keys[icacontrollertypes.StoreKey],
appKeepers.GetSubspace(icacontrollertypes.SubModuleName),
Expand All @@ -578,6 +584,7 @@ func NewAppKeepers(
scopedICAControllerKeeper,
bApp.MsgServiceRouter(),
)
appKeepers.ICAControllerKeeper = &icaControllerKeeper

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
Expand Down Expand Up @@ -624,7 +631,7 @@ func NewAppKeepers(
wasmOpts = append(wasmOpts, cyberOpts...)
wasmOpts = append(wasmplugins.RegisterStargateQueries(*bApp.GRPCQueryRouter(), appCodec), wasmOpts...)

appKeepers.WasmKeeper = wasmkeeper.NewKeeper(
wasmKeeper := wasmkeeper.NewKeeper(
appCodec,
keys[wasmtypes.StoreKey],
appKeepers.AccountKeeper,
Expand All @@ -644,20 +651,22 @@ func NewAppKeepers(
govModAddress,
wasmOpts...,
)
appKeepers.WasmKeeper = &wasmKeeper

// set the contract keeper for the Ics20WasmHooks
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper
appKeepers.ContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(appKeepers.WasmKeeper)
appKeepers.Ics20WasmHooks.ContractKeeper = appKeepers.WasmKeeper
//appKeepers.IBCHooksKeeper.ContractKeeper = appKeepers.ContractKeeper

appKeepers.ClockKeeper = clockkeeper.NewKeeper(
appKeepers.keys[clocktypes.StoreKey],
appCodec,
appKeepers.WasmKeeper,
*appKeepers.WasmKeeper,
appKeepers.ContractKeeper,
govModAddress,
)

appKeepers.DmnKeeper.SetWasmKeeper(appKeepers.WasmKeeper)
appKeepers.DmnKeeper.SetWasmKeeper(*appKeepers.WasmKeeper)

// register wasm gov proposal types
// The gov proposal types can be individually enabled
Expand All @@ -667,7 +676,7 @@ func NewAppKeepers(

// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
transferStack = transfer.NewIBCModule(*appKeepers.TransferKeeper)
transferStack = ibchooks.NewIBCMiddleware(transferStack, &appKeepers.HooksICS4Wrapper)
transferStack = packetforward.NewIBCMiddleware(
transferStack,
Expand All @@ -686,22 +695,22 @@ func NewAppKeepers(
// integration point for custom authentication modules
// see https://medium.com/the-interchain-foundation/ibc-go-v6-changes-to-interchain-accounts-and-how-it-impacts-your-chain-806c185300d7
var noAuthzModule porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, appKeepers.ICAControllerKeeper)
icaControllerStack = icacontroller.NewIBCMiddleware(noAuthzModule, *appKeepers.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, appKeepers.IBCFeeKeeper)

// RecvPacket, message that originates from core IBC and goes down to app, the flow is:
// channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket
var icaHostStack porttypes.IBCModule
icaHostStack = icahost.NewIBCModule(appKeepers.ICAHostKeeper)
icaHostStack = icahost.NewIBCModule(*appKeepers.ICAHostKeeper)
icaHostStack = ibcfee.NewIBCMiddleware(icaHostStack, appKeepers.IBCFeeKeeper)

// Create fee enabled wasm ibc Stack
var wasmStack porttypes.IBCModule
wasmStack = wasm.NewIBCHandler(appKeepers.WasmKeeper, appKeepers.IBCKeeper.ChannelKeeper, appKeepers.IBCFeeKeeper)
wasmStack = ibcfee.NewIBCMiddleware(wasmStack, appKeepers.IBCFeeKeeper)

// create ICQ module
icqModule := icq.NewIBCModule(appKeepers.ICQKeeper)
// Create Async ICQ module
icqModule := icq.NewIBCModule(*appKeepers.ICQKeeper)

ibcRouter := porttypes.NewRouter().
AddRoute(ibctransfertypes.ModuleName, transferStack).
Expand Down
14 changes: 7 additions & 7 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func appModules(
crisis.NewAppModule(app.AppKeepers.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
consensus.NewAppModule(appCodec, app.AppKeepers.ConsensusParamsKeeper),

wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.CyberbankKeeper.Proxy, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.CyberbankKeeper.Proxy, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
liquidity.NewAppModule(appCodec, app.LiquidityKeeper, app.AccountKeeper, app.CyberbankKeeper.Proxy, app.DistrKeeper, app.GetSubspace(liquiditytypes.ModuleName)),
cyberbank.NewAppModule(appCodec, app.CyberbankKeeper),
bandwidth.NewAppModule(appCodec, app.AccountKeeper, app.BandwidthMeter, app.GetSubspace(bandwidthtypes.ModuleName)),
Expand All @@ -182,12 +182,12 @@ func appModules(
clock.NewAppModule(appCodec, app.AppKeepers.ClockKeeper),

ibc.NewAppModule(app.IBCKeeper),
transfer.NewAppModule(app.TransferKeeper),
transfer.NewAppModule(*app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper),
ibchooks.NewAppModule(app.AppKeepers.AccountKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
icq.NewAppModule(app.AppKeepers.ICQKeeper, app.GetSubspace(icqtypes.ModuleName)),
icq.NewAppModule(*app.AppKeepers.ICQKeeper, app.GetSubspace(icqtypes.ModuleName)),
}
}

Expand All @@ -213,11 +213,11 @@ func simulationModules(
slashing.NewAppModule(appCodec, app.AppKeepers.SlashingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.AppKeepers.StakingKeeper, app.GetSubspace(stakingtypes.ModuleName)),
sdkparams.NewAppModule(app.AppKeepers.ParamsKeeper),
evidence.NewAppModule(app.AppKeepers.EvidenceKeeper),
wasm.NewAppModule(appCodec, &app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
wasm.NewAppModule(appCodec, app.AppKeepers.WasmKeeper, app.AppKeepers.StakingKeeper, app.AppKeepers.AccountKeeper, app.AppKeepers.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibc.NewAppModule(app.AppKeepers.IBCKeeper),
transfer.NewAppModule(app.AppKeepers.TransferKeeper),
transfer.NewAppModule(*app.AppKeepers.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
ica.NewAppModule(app.ICAControllerKeeper, app.ICAHostKeeper),
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cybercongress/go-cyber/v4/plugins/types"
generaltypes "github.com/cybercongress/go-cyber/v4/types"
clocktypes "github.com/cybercongress/go-cyber/v4/x/clock/types"
tokenfactorytypes "github.com/cybercongress/go-cyber/v4/x/tokenfactory/types"
Expand Down Expand Up @@ -149,7 +148,7 @@ func CreateV4UpgradeHandler(

// x/clock
if err := keepers.ClockKeeper.SetParams(ctx, clocktypes.Params{
ContractGasLimit: 10_000_000,
ContractGasLimit: 20_000_000,
}); err != nil {
return nil, err
}
Expand All @@ -169,7 +168,8 @@ func CreateV4UpgradeHandler(
logger.Info("set ibc packets forward params")

icqParams := icqtypes.DefaultParams()
icqParams.AllowQueries = types.GetStargateWhitelistedPaths()
// TODO Fix this, because if enable than all nodes will go to consensus failure on next block
//icqParams.AllowQueries = types.GetStargateWhitelistedPaths()
if err := keepers.ICQKeeper.SetParams(ctx, icqParams); err != nil {
return nil, err
}
Expand Down
4 changes: 0 additions & 4 deletions plugins/types/stargate_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package types

import (
"fmt"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down Expand Up @@ -71,9 +70,6 @@ func init() {
setWhitelistedQuery("/osmosis.tokenfactory.v1beta1.Query/Params", &tokenfactorytypes.QueryParamsResponse{})
setWhitelistedQuery("/osmosis.tokenfactory.v1beta1.Query/DenomAuthorityMetadata", &tokenfactorytypes.QueryDenomAuthorityMetadataResponse{})
// Does not include denoms_from_creator, TBD if this is the index we want contracts to use instead of admin

// cosmwasm
setWhitelistedQuery("/cosmwasm.wasm.v1.Query/SmartContractState", &wasmtypes.QuerySmartContractStateResponse{})
}

// IsWhitelistedQuery returns if the query is not whitelisted.
Expand Down
Loading

0 comments on commit 23359d6

Please sign in to comment.