Skip to content

Commit

Permalink
[ORA-742] Implementation of IBC bridge (#74)
Browse files Browse the repository at this point in the history
- IBC Keeper added to AlloraApp
- Added configurations in yaml
- Added ibc module, ibc middleware
- Added simulation ibc bridge code between allora and axelar chain
- Updated recalculating the inflation

> For testing on mainnet, must enable this code.
[line](https://github.com/allora-network/allora-chain/blob/163fefe97184d90f133487cc4f0ce216aa9d894b/x/ibc/gmp/ibc_middleware.go#L116)

This function is to test receiving data from Axelra to Allora -
[`TestGMPMessageFrom_Success()`](https://github.com/allora-network/allora-chain/blob/163fefe97184d90f133487cc4f0ce216aa9d894b/x/ibc/testing/ibc_middleware_test.go#L9)
And this function is for sending data from Allora to Axelra -
[`TestGMPMessageTo_Success()`](https://github.com/allora-network/allora-chain/blob/163fefe97184d90f133487cc4f0ce216aa9d894b/x/ibc/testing/ibc_middleware_test.go#L31)

---------

Co-authored-by: Kenny P <17100641+kpeluso@users.noreply.github.com>
  • Loading branch information
RedBird96 and kpeluso authored Mar 19, 2024
1 parent 1e1267e commit c6064b3
Show file tree
Hide file tree
Showing 15 changed files with 1,297 additions and 50 deletions.
122 changes: 118 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package app

import (
_ "embed"
"github.com/allora-network/allora-chain/x/emissions"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
"io"
"os"
"path/filepath"
Expand All @@ -13,7 +17,7 @@ import (
"cosmossdk.io/log"

storetypes "cosmossdk.io/store/types"
emissions "github.com/allora-network/allora-chain/x/emissions"
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
emissionsKeeper "github.com/allora-network/allora-chain/x/emissions/keeper"
mintkeeper "github.com/allora-network/allora-chain/x/mint/keeper"
minttypes "github.com/allora-network/allora-chain/x/mint/types"
Expand All @@ -34,17 +38,30 @@ import (
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
icacontrollerkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/keeper"
ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper"
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types"

_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects
_ "cosmossdk.io/x/upgrade"
_ "github.com/allora-network/allora-chain/x/emissions/module"
_ "github.com/allora-network/allora-chain/x/mint/module" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/bank" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/consensus" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/distribution" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/params" // import for side-effects
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
)

Expand Down Expand Up @@ -77,6 +94,22 @@ type AlloraApp struct {
ConsensusParamsKeeper consensuskeeper.Keeper
MintKeeper mintkeeper.Keeper
EmissionsKeeper emissionsKeeper.Keeper
ParamsKeeper paramskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper

// IBC
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
CapabilityKeeper *capabilitykeeper.Keeper
IBCFeeKeeper ibcfeekeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper

// Scoped IBC
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedIBCTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper

// simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -138,29 +171,46 @@ func NewAlloraApp(
&app.ConsensusParamsKeeper,
&app.MintKeeper,
&app.EmissionsKeeper,
&app.UpgradeKeeper,
&app.ParamsKeeper,
); err != nil {
return nil, err
}

app.App = appBuilder.Build(db, traceStore, baseAppOptions...)

// Register legacy modules
app.registerIBCModules()

// register streaming services
if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil {
return nil, err
}

/**** Module Options ****/

// begin_blockers: [emissions, distribution, staking, mint]
// end_blockers: [staking, emissions]
//begin_blockers: [capability, emissions, distribution, staking, mint, ibc, transfer, genutil, interchainaccounts, feeibc]
//end_blockers: [staking, ibc, transfer, capability, genutil, interchainaccounts, feeibc, emissions]
app.ModuleManager.SetOrderBeginBlockers(
capabilitytypes.ModuleName,
emissions.ModuleName,
distrtypes.ModuleName,
stakingtypes.ModuleName,
minttypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
genutiltypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
)
app.ModuleManager.SetOrderEndBlockers(
stakingtypes.ModuleName,
ibcexported.ModuleName,
ibctransfertypes.ModuleName,
capabilitytypes.ModuleName,
genutiltypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
emissions.ModuleName,
)

Expand All @@ -186,6 +236,14 @@ func (app *AlloraApp) LegacyAmino() *codec.LegacyAmino {
return app.legacyAmino
}

// AppCodec returns App's app codec.
//
// NOTE: This is solely to be used for testing purposes as it may be desirable
// for modules to register their own custom testing types.
func (app *AlloraApp) AppCodec() codec.Codec {
return app.appCodec
}

// GetKey returns the KVStoreKey for the provided store key.
func (app *AlloraApp) GetKey(storeKey string) *storetypes.KVStoreKey {
sk := app.UnsafeFindStoreKey(storeKey)
Expand All @@ -196,6 +254,16 @@ func (app *AlloraApp) GetKey(storeKey string) *storetypes.KVStoreKey {
return kvStoreKey
}

// GetMemKey returns the MemoryStoreKey for the provided store key.
func (app *AlloraApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
key, ok := app.UnsafeFindStoreKey(storeKey).(*storetypes.MemoryStoreKey)
if !ok {
return nil
}

return key
}

func (app *AlloraApp) kvStoreKeys() map[string]*storetypes.KVStoreKey {
keys := make(map[string]*storetypes.KVStoreKey)
for _, k := range app.GetStoreKeys() {
Expand All @@ -207,6 +275,22 @@ func (app *AlloraApp) kvStoreKeys() map[string]*storetypes.KVStoreKey {
return keys
}

// GetSubspace returns a param subspace for a given module name.
func (app *AlloraApp) GetSubspace(moduleName string) paramstypes.Subspace {
subspace, _ := app.ParamsKeeper.GetSubspace(moduleName)
return subspace
}

// GetIBCKeeper returns the IBC keeper.
func (app *AlloraApp) GetIBCKeeper() *ibckeeper.Keeper {
return app.IBCKeeper
}

// GetCapabilityScopedKeeper returns the capability scoped keeper.
func (app *AlloraApp) GetCapabilityScopedKeeper(moduleName string) capabilitykeeper.ScopedKeeper {
return app.CapabilityKeeper.ScopeToModule(moduleName)
}

// SimulationManager implements the SimulationApp interface
func (app *AlloraApp) SimulationManager() *module.SimulationManager {
return app.sm
Expand All @@ -221,3 +305,33 @@ func (app *AlloraApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.API
panic(err)
}
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) GetBaseApp() *baseapp.BaseApp {
return app.App.BaseApp
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return app.StakingKeeper
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper {
return app.ScopedIBCKeeper
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) GetTxConfig() client.TxConfig {
return app.txConfig
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) LastCommitID() storetypes.CommitID {
return app.BaseApp.LastCommitID()
}

// ibctesting.TestingApp compatibility
func (app *AlloraApp) LastBlockHeight() int64 {
return app.BaseApp.LastBlockHeight()
}
17 changes: 13 additions & 4 deletions app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ modules:
# there is nothing left over in the validator fee pool, so as to keep the CanWithdrawInvariant invariant.
# NOTE: staking module is required if HistoricalEntries param > 0
# order of emissions must come before distribution for reputers + workers take their rewards cut before validators cut
begin_blockers: [emissions, distribution, staking, mint]
end_blockers: [staking, emissions]
begin_blockers: [capability, emissions, distribution, staking, mint, ibc, transfer, genutil, interchainaccounts, feeibc]
end_blockers: [staking, ibc, transfer, capability, genutil, interchainaccounts, feeibc, emissions]
# NOTE: The genutils module must occur after staking so that pools are properly initialized with tokens from genesis accounts.
# NOTE: The genutils module must also occur after auth so that it can access the params from auth.
init_genesis: [auth, bank, distribution, staking, genutil, mint, emissions, allorastaking, allorarequests, allorarewards]
init_genesis: [capability, auth, bank, distribution, staking, mint, ibc, genutil, transfer, interchainaccounts, feeibc, params, upgrade, consensus, emissions, allorastaking, allorarequests, allorarewards]
override_store_keys:
- module_name: auth
kv_store_key: acc
Expand All @@ -31,6 +31,10 @@ modules:
- account : allorarequests
- account : distribution
- account : allorarewards
- account: transfer
permissions: [minter, burner]
- account: feeibc
- account: interchainaccounts
- name: bank
config:
"@type": cosmos.bank.module.v1.Module
Expand All @@ -57,4 +61,9 @@ modules:
- name: distribution
config:
"@type": cosmos.distribution.module.v1.Module

- name: upgrade
config:
"@type": cosmos.upgrade.module.v1.Module
- name: params
config:
"@type": cosmos.params.module.v1.Module
Loading

0 comments on commit c6064b3

Please sign in to comment.