Skip to content

Commit

Permalink
chore: use subscription staking share instead provider staking share …
Browse files Browse the repository at this point in the history
…value
  • Loading branch information
ironman0x7b2 committed Feb 13, 2025
1 parent 0629420 commit aeb186a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 23 deletions.
13 changes: 13 additions & 0 deletions x/node/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

base "github.com/sentinel-official/hub/v12/types"
Expand Down Expand Up @@ -65,6 +66,14 @@ func (k *Keeper) DeleteSessionForNode(ctx sdk.Context, addr base.NodeAddress, id
k.session.DeleteSessionForNode(ctx, addr, id)
}

func (k *Keeper) IsValidSessionGigabytes(ctx sdk.Context, gigabytes int64) bool {
return k.session.IsValidGigabytes(ctx, gigabytes)
}

func (k *Keeper) IsValidSessionHours(ctx sdk.Context, hours int64) bool {
return k.session.IsValidHours(ctx, hours)
}

func (k *Keeper) GetSessionCount(ctx sdk.Context) uint64 {
return k.session.GetSessionCount(ctx)
}
Expand All @@ -77,6 +86,10 @@ func (k *Keeper) GetSession(ctx sdk.Context, id uint64) (sessiontypes.Session, b
return k.session.GetSession(ctx, id)
}

func (k *Keeper) SessionStakingShare(ctx sdk.Context) math.LegacyDec {
return k.session.StakingShare(ctx)
}

func (k *Keeper) SetSessionCount(ctx sdk.Context, count uint64) {
k.session.SetSessionCount(ctx, count)
}
Expand Down
4 changes: 4 additions & 0 deletions x/node/keeper/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"time"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

Expand Down Expand Up @@ -44,10 +45,13 @@ type SessionKeeper interface {
GetInactiveAt(ctx sdk.Context) time.Time
GetSessionCount(ctx sdk.Context) uint64
GetSession(ctx sdk.Context, id uint64) (sessiontypes.Session, bool)
IsValidGigabytes(ctx sdk.Context, id int64) bool
IsValidHours(ctx sdk.Context, id int64) bool
NodeInactivePreHook(ctx sdk.Context, addr base.NodeAddress) error
SetSessionCount(ctx sdk.Context, count uint64)
SetSession(ctx sdk.Context, session sessiontypes.Session)
SetSessionForAccount(ctx sdk.Context, addr sdk.AccAddress, id uint64)
SetSessionForInactiveAt(ctx sdk.Context, at time.Time, id uint64)
SetSessionForNode(ctx sdk.Context, addr base.NodeAddress, id uint64)
StakingShare(ctx sdk.Context) math.LegacyDec
}
2 changes: 1 addition & 1 deletion x/node/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k *Keeper) SessionInactivePreHook(ctx sdk.Context, id uint64) error {
}

// Retrieve the staking share and compute the total payment amount for the session.
share := k.StakingShare(ctx)
share := k.SessionStakingShare(ctx)
totalPayment := session.PaymentAmount()

// Calculate the staking reward and transfer it to the fee collector module.
Expand Down
5 changes: 0 additions & 5 deletions x/subscription/keeper/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"time"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

base "github.com/sentinel-official/hub/v12/types"
Expand All @@ -28,10 +27,6 @@ func (k *Keeper) SendCoinFromAccountToModule(ctx sdk.Context, from sdk.AccAddres
return k.bank.SendCoinsFromAccountToModule(ctx, from, to, sdk.NewCoins(coin))
}

func (k *Keeper) ProviderStakingShare(ctx sdk.Context) sdkmath.LegacyDec {
return k.provider.StakingShare(ctx)
}

func (k *Keeper) GetNode(ctx sdk.Context, addr base.NodeAddress) (nodetypes.Node, bool) {
return k.node.GetNode(ctx, addr)
}
Expand Down
5 changes: 0 additions & 5 deletions x/subscription/keeper/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
"time"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

Expand All @@ -30,10 +29,6 @@ type DepositKeeper interface {
SendCoinsFromDepositToModule(ctx sdk.Context, fromAddr sdk.AccAddress, toModule string, coins sdk.Coins) error
}

type ProviderKeeper interface {
StakingShare(ctx sdk.Context) sdkmath.LegacyDec
}

type NodeKeeper interface {
HasNodeForPlan(ctx sdk.Context, id uint64, addr base.NodeAddress) bool
GetNode(ctx sdk.Context, addr base.NodeAddress) (nodetypes.Node, bool)
Expand Down
15 changes: 5 additions & 10 deletions x/subscription/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ type Keeper struct {
key storetypes.StoreKey
router *baseapp.MsgServiceRouter

bank BankKeeper
node NodeKeeper
oracle OracleKeeper
plan PlanKeeper
provider ProviderKeeper
session SessionKeeper
bank BankKeeper
node NodeKeeper
oracle OracleKeeper
plan PlanKeeper
session SessionKeeper
}

func NewKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, router *baseapp.MsgServiceRouter, authority, feeCollectorName string) Keeper {
Expand All @@ -42,10 +41,6 @@ func (k *Keeper) WithBankKeeper(keeper BankKeeper) {
k.bank = keeper
}

func (k *Keeper) WithProviderKeeper(keeper ProviderKeeper) {
k.provider = keeper
}

func (k *Keeper) WithNodeKeeper(keeper NodeKeeper) {
k.node = keeper
}
Expand Down
4 changes: 2 additions & 2 deletions x/subscription/keeper/msg_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (k *Keeper) HandleMsgRenewSubscription(ctx sdk.Context, msg *v3.MsgRenewSub
k.DeleteSubscriptionForInactiveAt(ctx, subscription.InactiveAt, subscription.ID)
k.DeleteSubscriptionForRenewalAt(ctx, subscription.RenewalAt(), subscription.ID)

share := k.ProviderStakingShare(ctx)
share := k.StakingShare(ctx)
totalPayment := price.QuotePrice()

accAddr, err := sdk.AccAddressFromBech32(msg.From)
Expand Down Expand Up @@ -292,7 +292,7 @@ func (k *Keeper) HandleMsgStartSubscription(ctx sdk.Context, msg *v3.MsgStartSub
StatusAt: ctx.BlockTime(),
}

share := k.ProviderStakingShare(ctx)
share := k.StakingShare(ctx)
totalPayment := price.QuotePrice()

reward := baseutils.GetProportionOfCoin(totalPayment, share)
Expand Down

0 comments on commit aeb186a

Please sign in to comment.