Skip to content

Commit

Permalink
Merge pull request #1153 from lavanet/CNS-631-connect-with-osmosis-ibc
Browse files Browse the repository at this point in the history
CNS-631-add-ibc-modules
  • Loading branch information
Yaroms authored Jan 23, 2024
2 parents 141dd17 + 569358a commit 74eb203
Show file tree
Hide file tree
Showing 10 changed files with 251 additions and 12 deletions.
60 changes: 51 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (

"github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/runtime"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
"github.com/lavanet/lava/x/fixationstore"
fixationkeeper "github.com/lavanet/lava/x/fixationstore/keeper"
fixationtypes "github.com/lavanet/lava/x/fixationstore/types"
"github.com/lavanet/lava/x/timerstore"
timerstorekeeper "github.com/lavanet/lava/x/timerstore/keeper"
timerstoretypes "github.com/lavanet/lava/x/timerstore/types"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
tmjson "github.com/cometbft/cometbft/libs/json"
Expand Down Expand Up @@ -84,6 +84,12 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand All @@ -94,6 +100,7 @@ import (
ibcporttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/lavanet/lava/app/keepers"
appparams "github.com/lavanet/lava/app/params"
"github.com/lavanet/lava/app/upgrades"
Expand Down Expand Up @@ -166,6 +173,7 @@ var Upgrades = []upgrades.Upgrade{
upgrades.Upgrade_0_32_0,
upgrades.Upgrade_0_32_3,
upgrades.Upgrade_0_33_0,
upgrades.Upgrade_0_34_0,
}

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -212,6 +220,8 @@ var (
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
ibctm.AppModuleBasic{},
ica.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
Expand All @@ -237,7 +247,8 @@ var (
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
subscriptionmoduletypes.ModuleName: {authtypes.Burner, authtypes.Staking},
string(rewardsmoduletypes.ValidatorsRewardsAllocationPoolName): {authtypes.Minter, authtypes.Staking},
string(rewardsmoduletypes.ValidatorsRewardsDistributionPoolName): {authtypes.Burner, authtypes.Staking},
Expand Down Expand Up @@ -319,7 +330,10 @@ func New(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, crisistypes.StoreKey, ibctransfertypes.StoreKey, ibcexported.StoreKey, capabilitytypes.StoreKey,
evidencetypes.StoreKey, crisistypes.StoreKey, ibctransfertypes.StoreKey, ibcexported.StoreKey,
icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
capabilitytypes.StoreKey,
specmoduletypes.StoreKey,
epochstoragemoduletypes.StoreKey,
dualstakingmoduletypes.StoreKey,
Expand Down Expand Up @@ -359,6 +373,8 @@ func New(
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
// this line is used by starport scaffolding # stargate/app/scopedKeeper

// add keepers
Expand Down Expand Up @@ -556,6 +572,7 @@ func New(
// TODO: Check alternatives to this
// AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.UpgradeKeeper)).
// AddRoute(ibcexported.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))

// Create Transfer Keepers
Expand All @@ -567,6 +584,26 @@ func New(
transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

app.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, keys[icahosttypes.StoreKey],
app.GetSubspace(icahosttypes.SubModuleName),
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
icaControllerKeeper := icacontrollerkeeper.NewKeeper(
appCodec, keys[icacontrollertypes.StoreKey],
app.GetSubspace(icacontrollertypes.SubModuleName),
app.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
scopedICAControllerKeeper, app.MsgServiceRouter(),
)
icaModule := ica.NewAppModule(&icaControllerKeeper, &app.ICAHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper,
Expand Down Expand Up @@ -612,8 +649,8 @@ func New(

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
// ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferModule)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
// this line is used by starport scaffolding # ibc/app/router
app.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -663,7 +700,7 @@ func New(
protocolModule,
downtimeModule,
rewardsModule,

icaModule,
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
// this line is used by starport scaffolding # stargate/app/appModule
)
Expand All @@ -689,6 +726,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
dualstakingmoduletypes.ModuleName,
Expand Down Expand Up @@ -716,6 +754,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
dualstakingmoduletypes.ModuleName,
Expand Down Expand Up @@ -755,6 +794,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
subscriptionmoduletypes.ModuleName,
downtimemoduletypes.ModuleName,
Expand Down Expand Up @@ -1019,6 +1059,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(ibcexported.ModuleName)
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(specmoduletypes.ModuleName)
paramsKeeper.Subspace(epochstoragemoduletypes.ModuleName)
paramsKeeper.Subspace(dualstakingmoduletypes.ModuleName)
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/lavaKeepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
conflictmodulekeeper "github.com/lavanet/lava/x/conflict/keeper"
Expand Down Expand Up @@ -68,4 +69,5 @@ type LavaKeepers struct {
DowntimeKeeper downtimemodulekeeper.Keeper
RewardsKeeper rewardsmodulekeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
}
10 changes: 10 additions & 0 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
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/lavanet/lava/app/keepers"
v1 "github.com/lavanet/lava/x/downtime/v1"
dualstakingtypes "github.com/lavanet/lava/x/dualstaking/types"
Expand Down Expand Up @@ -193,3 +195,11 @@ var Upgrade_0_33_0 = Upgrade{
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_0_34_0 = Upgrade{
UpgradeName: "v0.34.0",
CreateUpgradeHandler: defaultUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{icahosttypes.StoreKey, icacontrollertypes.StoreKey},
},
}
3 changes: 3 additions & 0 deletions protocol/chainlib/chain_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ func (cf *ChainFetcher) Verify(ctx context.Context, verification VerificationCon
{Key: "parsedResult", Value: parsedResult},
{Key: "verification.Value", Value: verification.Value},
{Key: "Method", Value: parsing.GetApiName()},
{Key: "Extension", Value: verification.Extension},
{Key: "Addon", Value: verification.Addon},
{Key: "Verification", Value: verification.Name},
}...)
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ if ! command_exists jq; then
fi

rm -rf ~/.lava
lavad init validator --chain-id lava
chainID="lava"
lavad init validator --chain-id $chainID
lavad config broadcast-mode sync
lavad config keyring-backend test

Expand Down Expand Up @@ -106,6 +107,6 @@ done
# its total balance is 3% from the total tokens amount: 10^9 * 10^6 ulava
lavad add-genesis-account validators_rewards_allocation_pool 30000000000000ulava --module-account
lavad add-genesis-account providers_rewards_allocation_pool 30000000000000ulava --module-account
lavad gentx alice 10000000000000ulava --chain-id lava
lavad gentx alice 10000000000000ulava --chain-id $chainID
lavad collect-gentxs
lavad start --pruning=nothing
2 changes: 1 addition & 1 deletion scripts/init_chain_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ echo; echo "#### Voting on plans del proposal ####"
lavad tx gov vote $(latest_vote) yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

echo; echo "#### Sending proposal for plans del ####"
lavad tx subscription buy DefaultPlan $(lavad keys show user1 -a) -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
lavad tx subscription buy DefaultPlan $(lavad keys show user1 -a) --enable-auto-renewal -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
# lavad tx project set-policy $(lavad keys show user1 -a)-admin ./cookbook/projects/policy_all_chains_with_addon.yml -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

# MANTLE
Expand Down
124 changes: 124 additions & 0 deletions scripts/relayer/init_chain_2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash
# this scripts boots up another chain in different ports to run in parrallel with the regular /scripts/init_chain.sh script
__dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $__dir/../useful_commands.sh

# Check if jq is not installed
if ! command_exists jq; then
echo "jq not found. Please install jq using the init_install.sh script or manually."
exit 1
fi

home=~/.lava2
chainID="lava-local-2"
rm -rf $home
lavad init validator --chain-id $chainID --home $home
lavad config broadcast-mode sync --home $home
lavad config keyring-backend test --home $home
lavad config node "tcp://localhost:36657" --home $home


# Specify the file path, field to edit, and new value
path="$home/config/"
genesis='genesis.json'
config='config.toml'
app='app.toml'

# Edit genesis file
if [ "$1" == "debug" ]; then
# Edit genesis file with additional line
data=$(cat "$path$genesis" \
| jq '.app_state.gov.params.min_deposit[0].denom = "ulava"' \
| jq '.app_state.gov.params.min_deposit[0].amount = "100"' \
| jq '.app_state.gov.params.voting_period = "4s"' \
| jq '.app_state.gov.params.expedited_voting_period = "3s"' \
| jq '.app_state.gov.params.expedited_min_deposit[0].denom = "ulava"' \
| jq '.app_state.gov.params.expedited_min_deposit[0].amount = "200"' \
| jq '.app_state.gov.params.expedited_threshold = "0.67"' \
| jq '.app_state.mint.params.mint_denom = "ulava"' \
| jq '.app_state.staking.params.bond_denom = "ulava"' \
| jq '.app_state.crisis.constant_fee.denom = "ulava"' \
| jq '.app_state.epochstorage.params.epochsToSave = "5"' \
| jq '.app_state.epochstorage.params.epochBlocks = "4"' \
| jq '.app_state.downtime.params.downtime_duration = "1s"' \
)
else
# Edit genesis file without the additional line
data=$(cat "$path$genesis" \
| jq '.app_state.gov.params.min_deposit[0].denom = "ulava"' \
| jq '.app_state.gov.params.min_deposit[0].amount = "100"' \
| jq '.app_state.gov.params.voting_period = "4s"' \
| jq '.app_state.gov.params.expedited_voting_period = "3s"' \
| jq '.app_state.gov.params.expedited_min_deposit[0].denom = "ulava"' \
| jq '.app_state.gov.params.expedited_min_deposit[0].amount = "200"' \
| jq '.app_state.gov.params.expedited_threshold = "0.67"' \
| jq '.app_state.mint.params.mint_denom = "ulava"' \
| jq '.app_state.mint.params.mint_denom = "ulava"' \
| jq '.app_state.staking.params.bond_denom = "ulava"' \
| jq '.app_state.crisis.constant_fee.denom = "ulava"' \
| jq '.app_state.downtime.params.downtime_duration = "6s"' \
| jq '.app_state.downtime.params.epoch_duration = "8s"' \
)
fi

echo -n "$data" > "$path$genesis"

echo "using genesis file"
echo $(cat "$path$genesis")

# Determine OS
os_name=$(uname)
case "$(uname)" in
Darwin)
SED_INLINE="-i ''" ;;
Linux)
SED_INLINE="-i" ;;
*)
echo "unknown system: $(uname)"
exit 1 ;;
esac


sed $SED_INLINE \
-e 's/timeout_propose = .*/timeout_propose = "1s"/' \
-e 's/timeout_propose_delta = .*/timeout_propose_delta = "500ms"/' \
-e 's/timeout_prevote = .*/timeout_prevote = "1s"/' \
-e 's/timeout_prevote_delta = .*/timeout_prevote_delta = "500ms"/' \
-e 's/timeout_precommit = .*/timeout_precommit = "500ms"/' \
-e 's/timeout_precommit_delta = .*/timeout_precommit_delta = "1s"/' \
-e 's/timeout_commit = .*/timeout_commit = "1s"/' \
-e 's/skip_timeout_commit = .*/skip_timeout_commit = false/' "$path$config"

# Edit app.toml file
sed $SED_INLINE -e "s/enable = .*/enable = true/" "$path$app"
sed $SED_INLINE -e "/Enable defines if the Rosetta API server should be enabled.*/{n;s/enable = .*/enable = false/}" "$path$app"

# change ports
sed $SED_INLINE \
-e 's/tcp:\/\/0\.0\.0\.0:26656/tcp:\/\/0.0.0.0:36656/' \
-e 's/tcp:\/\/127\.0\.0\.1:26658/tcp:\/\/127.0.0.1:36658/' \
-e 's/tcp:\/\/127\.0\.0\.1:26657/tcp:\/\/127.0.0.1:36657/' \
-e 's/tcp:\/\/127\.0\.0\.1:26656/tcp:\/\/127.0.0.1:36656/' "$path$config"

# Edit app.toml file
sed $SED_INLINE \
-e 's/tcp:\/\/localhost:1317/tcp:\/\/localhost:2317/' \
-e 's/localhost:9090/localhost:8090/' \
-e 's/":7070"/":7070"/' \
-e 's/localhost:9091/localhost:8091/' "$path$app"

# Add users
users=("alice" "bob" "user1" "user2" "user3" "user4" "user5" "servicer1" "servicer2" "servicer3" "servicer4" "servicer5" "servicer6" "servicer7" "servicer8" "servicer9" "servicer10")

for user in "${users[@]}"; do
lavad keys add "$user" --home $home
lavad add-genesis-account "$user" 50000000000000ulava --home $home
done

# add validators_allocation_pool for validators block rewards
# its total balance is 3% from the total tokens amount: 10^9 * 10^6 ulava
lavad add-genesis-account validators_rewards_allocation_pool 30000000000000ulava --module-account --home $home
lavad add-genesis-account providers_rewards_allocation_pool 30000000000000ulava --module-account --home $home
lavad gentx alice 10000000000000ulava --chain-id $chainID --home $home
lavad collect-gentxs --home $home
lavad start --pruning=nothing --home $home
Loading

0 comments on commit 74eb203

Please sign in to comment.