Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: IPRPC over IBC #1446

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5008a8f
CNS-960: make rewards module ibc middleware
oren-lava May 21, 2024
d3c5144
CNS-960: implement memo ibc-transfer memo parsing
oren-lava May 22, 2024
10e1650
CNS-960: unit test for memo parsing
oren-lava May 22, 2024
14559ca
CNS-960: fix lint
oren-lava May 22, 2024
5f038ba
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava May 27, 2024
e796926
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava May 29, 2024
54f7b0d
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jun 6, 2024
c5b5020
CNS-960: nil ack comment
oren-lava Jun 6, 2024
1723bb7
CNS-960: make iprpc memo a protobuf
oren-lava Jun 6, 2024
6a3ccb7
CNS-960: improve memo decoding code
oren-lava Jun 6, 2024
0ad3878
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jun 10, 2024
a331cd9
CNS-960: create types/ibc_iprpc.go and PendingIprpcPool
oren-lava Jun 13, 2024
154a420
CNS-960: update middleware to work with pending pool and temp addrees…
oren-lava Jun 13, 2024
f1a7a37
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jun 13, 2024
1676677
CNS-960: handling async packets
oren-lava Jun 18, 2024
fc25eb2
CNS-960: lint
oren-lava Jun 18, 2024
b9904e9
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jun 18, 2024
98110fe
CNS-960: fix coderabbitai comments
oren-lava Jun 18, 2024
bbd5416
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jun 19, 2024
0b5f338
feat: IPRPC over IBC: Part 2 - CNS-964: CLI for submitting an IPRPC o…
oren-lava Jul 8, 2024
4cedfe7
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Jul 8, 2024
04865f1
CNS-960: small fix send to pending iprpc pool without leftovers
oren-lava Jul 8, 2024
d853bff
CNS-960: code rabbit suggestions
oren-lava Aug 29, 2024
ee68fb7
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Aug 29, 2024
894dfee
CNS-960: lint fix
oren-lava Aug 29, 2024
b352fcd
Merge branch 'main' into CNS-960-ibc-middleware
oren-lava Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ var (
string(rewardsmoduletypes.ProvidersRewardsAllocationPool): {authtypes.Minter, authtypes.Staking},
dualstakingmoduletypes.ModuleName: {authtypes.Burner, authtypes.Staking},
string(rewardsmoduletypes.IprpcPoolName): nil,
string(rewardsmoduletypes.PendingIprpcPoolName): nil,
// this line is used by starport scaffolding # stargate/app/maccPerms
}
)
Expand Down Expand Up @@ -560,6 +561,7 @@ func New(
authtypes.FeeCollectorName,
app.TimerStoreKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.IBCKeeper.ChannelKeeper,
)
rewardsModule := rewardsmodule.NewAppModule(appCodec, app.RewardsKeeper, app.AccountKeeper, app.BankKeeper)

Expand Down Expand Up @@ -715,6 +717,7 @@ func New(
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
transferStack = rewardsmodule.NewIBCMiddleware(transferStack, app.RewardsKeeper)
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)

// this line is used by starport scaffolding # ibc/app/router
Expand Down
1 change: 1 addition & 0 deletions proto/lavanet/lava/rewards/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ message GenesisState {
cosmos.base.v1beta1.Coin min_iprpc_cost = 5 [(gogoproto.nullable) = false];
repeated IprpcReward iprpc_rewards = 6 [(gogoproto.nullable) = false];
uint64 iprpc_rewards_current = 7;
repeated PendingIbcIprpcFund pending_ibc_iprpc_funds = 8 [(gogoproto.nullable) = false];
// this line is used by starport scaffolding # genesis/proto/state
}
15 changes: 15 additions & 0 deletions proto/lavanet/lava/rewards/iprpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,19 @@ message Specfund {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
}

message IprpcMemo {
string creator = 1;
string spec = 2;
uint64 duration = 3; // Iprpc fund period in months
}

message PendingIbcIprpcFund {
uint64 index = 1; // unique index
string creator = 2;
string spec = 3;
uint64 duration = 4;
cosmos.base.v1beta1.Coin fund = 5 [(gogoproto.nullable) = false];
uint64 expiry = 6; // expiry timestamp
}
8 changes: 7 additions & 1 deletion proto/lavanet/lava/rewards/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";
package lavanet.lava.rewards;

import "gogoproto/gogo.proto";

import "google/protobuf/duration.proto";
option go_package = "github.com/lavanet/lava/x/rewards/types";

// Params defines the parameters for the module.
Expand Down Expand Up @@ -40,4 +40,10 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration ibc_iprpc_expiration = 7 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.moretags) = "yaml:\"ibc_iprpc_expiration\""
];
}
20 changes: 20 additions & 0 deletions proto/lavanet/lava/rewards/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ service Query {
rpc IprpcSpecReward(QueryIprpcSpecRewardRequest) returns (QueryIprpcSpecRewardResponse) {
option (google.api.http).get = "/lavanet/lava/rewards/iprpc_spec_reward/{spec}";
}

// PendingIbcIprpcFunds queries for a spec's IPRPC reward
rpc PendingIbcIprpcFunds(QueryPendingIbcIprpcFundsRequest) returns (QueryPendingIbcIprpcFundsResponse) {
option (google.api.http).get = "/lavanet/lava/rewards/pending_ibc_iprpc_funds/{filter}";
}
oren-lava marked this conversation as resolved.
Show resolved Hide resolved
// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -134,4 +139,19 @@ message QueryIprpcSpecRewardResponse {
uint64 current_month_id = 2;
}

// QueryPendingIbcIprpcFundsRequest is request type for the Query/PendingIbcIprpcFund RPC method.
message QueryPendingIbcIprpcFundsRequest {
string filter = 1; // can be an uint64 index, creator name and spec name
}

message PendingIbcIprpcFundInfo {
PendingIbcIprpcFund pending_ibc_iprpc_fund = 1 [(gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin cost = 2 [(gogoproto.nullable) = false]; // equals to min_iprpc_cost * duration
}

// QueryPendingIbcIprpcFundsResponse is response type for the Query/PendingIbcIprpcFund RPC method.
message QueryPendingIbcIprpcFundsResponse {
repeated PendingIbcIprpcFundInfo pending_ibc_iprpc_funds_info = 1 [(gogoproto.nullable) = false];
}

// this line is used by starport scaffolding # 3
9 changes: 9 additions & 0 deletions proto/lavanet/lava/rewards/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option go_package = "github.com/lavanet/lava/x/rewards/types";
service Msg {
rpc SetIprpcData(MsgSetIprpcData) returns (MsgSetIprpcDataResponse);
rpc FundIprpc(MsgFundIprpc) returns (MsgFundIprpcResponse);
rpc CoverIbcIprpcFundCost(MsgCoverIbcIprpcFundCost) returns (MsgCoverIbcIprpcFundCostResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

Expand All @@ -37,4 +38,12 @@ message MsgFundIprpc {
message MsgFundIprpcResponse {
}

message MsgCoverIbcIprpcFundCost {
string creator = 1;
uint64 index = 2; // PendingIbcIprpcFund index
}

message MsgCoverIbcIprpcFundCostResponse {
}

// this line is used by starport scaffolding # proto/tx/message
7 changes: 7 additions & 0 deletions scripts/test/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ trace lavad q rewards show-iprpc-data > /dev/null
trace lavad q rewards iprpc-provider-reward > /dev/null
trace lavad q rewards iprpc-spec-reward > /dev/null
trace lavad q rewards provider-reward >/dev/null
trace lavad q rewards pending-ibc-iprpc-funds > /dev/null

echo "Testing rewards tx commands"
trace lavad tx rewards fund-iprpc ETH1 4 100000ulava --from alice >/dev/null
wait_count_blocks 1 >/dev/null
trace lavad tx rewards submit-ibc-iprpc-tx ETH1 3 100ulava transfer channel-0 --from bob --home ~/.lava --node tcp://localhost:26657 >/dev/null


echo "Testing events command"
trace lavad test events 30 10 --event lava_relay_payment --from alice --timeout 1s >/dev/null
Expand Down
37 changes: 28 additions & 9 deletions testutil/common/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
testkeeper "github.com/lavanet/lava/testutil/keeper"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/utils/lavaslices"
Expand All @@ -25,6 +26,7 @@ import (
pairingtypes "github.com/lavanet/lava/x/pairing/types"
planstypes "github.com/lavanet/lava/x/plans/types"
projectstypes "github.com/lavanet/lava/x/projects/types"
"github.com/lavanet/lava/x/rewards"
rewardstypes "github.com/lavanet/lava/x/rewards/types"
spectypes "github.com/lavanet/lava/x/spec/types"
subscriptiontypes "github.com/lavanet/lava/x/subscription/types"
Expand All @@ -34,10 +36,11 @@ import (
type Tester struct {
T *testing.T

GoCtx context.Context
Ctx sdk.Context
Servers *testkeeper.Servers
Keepers *testkeeper.Keepers
GoCtx context.Context
Ctx sdk.Context
Servers *testkeeper.Servers
Keepers *testkeeper.Keepers
IbcTransfer porttypes.Middleware

accounts map[string]sigs.Account
plans map[string]planstypes.Plan
Expand Down Expand Up @@ -75,11 +78,12 @@ func NewTesterRaw(t *testing.T) *Tester {
servers, keepers, GoCtx := testkeeper.InitAllKeepers(t)

ts := &Tester{
T: t,
GoCtx: GoCtx,
Ctx: sdk.UnwrapSDKContext(GoCtx),
Servers: servers,
Keepers: keepers,
T: t,
GoCtx: GoCtx,
Ctx: sdk.UnwrapSDKContext(GoCtx),
Servers: servers,
Keepers: keepers,
IbcTransfer: rewards.NewIBCMiddleware(keepers.IbcTransfer, keepers.Rewards),

accounts: make(map[string]sigs.Account),
plans: make(map[string]planstypes.Plan),
Expand Down Expand Up @@ -699,6 +703,11 @@ func (ts *Tester) TxRewardsFundIprpc(creator string, spec string, duration uint6
return ts.Servers.RewardsServer.FundIprpc(ts.GoCtx, msg)
}

func (ts *Tester) TxRewardsCoverIbcIprpcFundCost(creator string, index uint64) (*rewardstypes.MsgCoverIbcIprpcFundCostResponse, error) {
msg := rewardstypes.NewMsgCoverIbcIprpcFundCost(creator, index)
return ts.Servers.RewardsServer.CoverIbcIprpcFundCost(ts.GoCtx, msg)
}

// TxCreateValidator: implement 'tx staking createvalidator' and bond its tokens
func (ts *Tester) TxCreateValidator(validator sigs.Account, amount math.Int) {
consensusPowerTokens := ts.Keepers.StakingKeeper.TokensFromConsensusPower(ts.Ctx, 1)
Expand Down Expand Up @@ -969,20 +978,30 @@ func (ts *Tester) QueryRewardsShowIprpcData() (*rewardstypes.QueryShowIprpcDataR
return ts.Keepers.Rewards.ShowIprpcData(ts.GoCtx, msg)
}

// QueryRewardsShowIprpcData implements 'q rewards iprpc-provider-reward-estimation'
func (ts *Tester) QueryRewardsIprpcProviderRewardEstimation(provider string) (*rewardstypes.QueryIprpcProviderRewardEstimationResponse, error) {
msg := &rewardstypes.QueryIprpcProviderRewardEstimationRequest{
Provider: provider,
}
return ts.Keepers.Rewards.IprpcProviderRewardEstimation(ts.GoCtx, msg)
}

// QueryRewardsShowIprpcData implements 'q rewards iprpc-spec-reward'
func (ts *Tester) QueryRewardsIprpcSpecReward(spec string) (*rewardstypes.QueryIprpcSpecRewardResponse, error) {
msg := &rewardstypes.QueryIprpcSpecRewardRequest{
Spec: spec,
}
return ts.Keepers.Rewards.IprpcSpecReward(ts.GoCtx, msg)
}

// QueryRewardsShowIprpcData implements 'q rewards pending-ibc-iprpc-funds'
func (ts *Tester) QueryRewardsPendingIbcIprpcFunds(filter string) (*rewardstypes.QueryPendingIbcIprpcFundsResponse, error) {
msg := &rewardstypes.QueryPendingIbcIprpcFundsRequest{
Filter: filter,
}
return ts.Keepers.Rewards.PendingIbcIprpcFunds(ts.GoCtx, msg)
}

// block/epoch helpers
// QueryRewardsProviderReward implements 'q rewards provider-reward'
func (ts *Tester) QueryRewardsProviderReward(chainID string, provider string) (*rewardstypes.QueryProviderRewardResponse, error) {
Expand Down
11 changes: 10 additions & 1 deletion testutil/keeper/keepers_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
commonconsts "github.com/lavanet/lava/testutil/common/consts"
"github.com/lavanet/lava/utils/sigs"
conflictkeeper "github.com/lavanet/lava/x/conflict/keeper"
Expand Down Expand Up @@ -95,6 +96,7 @@ type Keepers struct {
SlashingKeeper slashingkeeper.Keeper
Rewards rewardskeeper.Keeper
Distribution distributionkeeper.Keeper
IbcTransfer mockIbcTransferKeeper
}

type Servers struct {
Expand All @@ -111,6 +113,7 @@ type Servers struct {
SlashingServer slashingtypes.MsgServer
RewardsServer rewardstypes.MsgServer
DistributionServer distributiontypes.MsgServer
IbcTransferServer ibctransfertypes.MsgServer
}

type KeeperBeginBlockerWithRequest interface {
Expand Down Expand Up @@ -142,6 +145,9 @@ func InitAllKeepers(t testing.TB) (*Servers, *Keepers, context.Context) {
distributionStoreKey := sdk.NewKVStoreKey(distributiontypes.StoreKey)
stateStore.MountStoreWithDB(distributionStoreKey, storetypes.StoreTypeIAVL, db)

ibctransferStoreKey := sdk.NewKVStoreKey(ibctransfertypes.StoreKey)
stateStore.MountStoreWithDB(ibctransferStoreKey, storetypes.StoreTypeIAVL, db)

stakingStoreKey := sdk.NewKVStoreKey(stakingtypes.StoreKey)
stateStore.MountStoreWithDB(stakingStoreKey, storetypes.StoreTypeIAVL, db)

Expand Down Expand Up @@ -217,6 +223,7 @@ func InitAllKeepers(t testing.TB) (*Servers, *Keepers, context.Context) {
paramsKeeper.Subspace(rewardstypes.ModuleName)
paramsKeeper.Subspace(distributiontypes.ModuleName)
paramsKeeper.Subspace(dualstakingtypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
// paramsKeeper.Subspace(conflicttypes.ModuleName) //TODO...

epochparamsSubspace, _ := paramsKeeper.GetSubspace(epochstoragetypes.ModuleName)
Expand Down Expand Up @@ -245,11 +252,13 @@ func InitAllKeepers(t testing.TB) (*Servers, *Keepers, context.Context) {
)

downtimeParamsSubspace, _ := paramsKeeper.GetSubspace(downtimemoduletypes.ModuleName)
ibctransferparamsSubspace, _ := paramsKeeper.GetSubspace(ibctransfertypes.ModuleName)

ks := Keepers{}
ks.TimerStoreKeeper = timerstorekeeper.NewKeeper(cdc)
ks.AccountKeeper = mockAccountKeeper{}
ks.BankKeeper = mockBankKeeper{}
ks.IbcTransfer = NewMockIbcTransferKeeper(ibctransferStoreKey, cdc, ibctransferparamsSubspace, ks.AccountKeeper, ks.BankKeeper)
init_balance()
ks.StakingKeeper = *stakingkeeper.NewKeeper(cdc, stakingStoreKey, ks.AccountKeeper, ks.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Distribution = distributionkeeper.NewKeeper(cdc, distributionStoreKey, ks.AccountKeeper, ks.BankKeeper, ks.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String())
Expand All @@ -264,7 +273,7 @@ func InitAllKeepers(t testing.TB) (*Servers, *Keepers, context.Context) {
ks.Projects = *projectskeeper.NewKeeper(cdc, projectsStoreKey, projectsMemStoreKey, projectsparamsSubspace, ks.Epochstorage, ks.FixationStoreKeeper)
ks.Protocol = *protocolkeeper.NewKeeper(cdc, protocolStoreKey, protocolMemStoreKey, protocolparamsSubspace, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Downtime = downtimekeeper.NewKeeper(cdc, downtimeKey, downtimeParamsSubspace, ks.Epochstorage)
ks.Rewards = *rewardskeeper.NewKeeper(cdc, rewardsStoreKey, rewardsMemStoreKey, rewardsparamsSubspace, ks.BankKeeper, ks.AccountKeeper, ks.Spec, ks.Epochstorage, ks.Downtime, ks.StakingKeeper, ks.Dualstaking, ks.Distribution, authtypes.FeeCollectorName, ks.TimerStoreKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
ks.Rewards = *rewardskeeper.NewKeeper(cdc, rewardsStoreKey, rewardsMemStoreKey, rewardsparamsSubspace, ks.BankKeeper, ks.AccountKeeper, ks.Spec, ks.Epochstorage, ks.Downtime, ks.StakingKeeper, ks.Dualstaking, ks.Distribution, authtypes.FeeCollectorName, ks.TimerStoreKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), nil)
ks.Subscription = *subscriptionkeeper.NewKeeper(cdc, subscriptionStoreKey, subscriptionMemStoreKey, subscriptionparamsSubspace, &ks.BankKeeper, &ks.AccountKeeper, &ks.Epochstorage, ks.Projects, ks.Plans, ks.Dualstaking, ks.Rewards, ks.FixationStoreKeeper, ks.TimerStoreKeeper, ks.StakingKeeper)
ks.Pairing = *pairingkeeper.NewKeeper(cdc, pairingStoreKey, pairingMemStoreKey, pairingparamsSubspace, &ks.BankKeeper, &ks.AccountKeeper, ks.Spec, &ks.Epochstorage, ks.Projects, ks.Subscription, ks.Plans, ks.Downtime, ks.Dualstaking, &ks.StakingKeeper, ks.FixationStoreKeeper, ks.TimerStoreKeeper)
ks.ParamsKeeper = paramsKeeper
Expand Down
Loading
Loading