Skip to content

Commit 5306e98

Browse files
committed
feat: add active_duration and inactive_pending_duration for session instead status_change_delay
1 parent 9438052 commit 5306e98

File tree

12 files changed

+226
-146
lines changed

12 files changed

+226
-146
lines changed

proto/sentinel/session/v3/params.proto

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ option (gogoproto.equal_all) = false;
99
option (gogoproto.goproto_getters_all) = false;
1010

1111
message Params {
12-
int64 max_gigabytes = 1;
13-
int64 min_gigabytes = 2;
14-
int64 max_hours = 3;
15-
int64 min_hours = 4;
16-
bool proof_verification_enabled = 5;
17-
string staking_share = 6 [
18-
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
19-
(gogoproto.nullable) = false
12+
google.protobuf.Duration active_duration = 1 [
13+
(gogoproto.nullable) = false,
14+
(gogoproto.stdduration) = true
2015
];
21-
google.protobuf.Duration status_change_delay = 7 [
16+
google.protobuf.Duration inactive_pending_duration = 2 [
2217
(gogoproto.nullable) = false,
2318
(gogoproto.stdduration) = true
2419
];
20+
int64 max_gigabytes = 3;
21+
int64 min_gigabytes = 4;
22+
int64 max_hours = 5;
23+
int64 min_hours = 6;
24+
bool proof_verification_enabled = 7;
25+
string staking_share = 8 [
26+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
27+
(gogoproto.nullable) = false
28+
];
2529
}

x/node/keeper/alias.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func (k *Keeper) GetSessionCount(ctx sdk.Context) uint64 {
7878
return k.session.GetSessionCount(ctx)
7979
}
8080

81-
func (k *Keeper) GetSessionInactiveAt(ctx sdk.Context) time.Time {
82-
return k.session.GetInactiveAt(ctx)
81+
func (k *Keeper) GetSessionInactivePendingAt(ctx sdk.Context) time.Time {
82+
return k.session.GetInactivePendingAt(ctx)
8383
}
8484

8585
func (k *Keeper) GetSession(ctx sdk.Context, id uint64) (sessiontypes.Session, bool) {

x/node/keeper/expected.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type SessionKeeper interface {
4242
DeleteSession(ctx sdk.Context, id uint64)
4343
DeleteSessionForAccount(ctx sdk.Context, addr sdk.AccAddress, id uint64)
4444
DeleteSessionForNode(ctx sdk.Context, addr base.NodeAddress, id uint64)
45-
GetInactiveAt(ctx sdk.Context) time.Time
45+
GetInactivePendingAt(ctx sdk.Context) time.Time
4646
GetSessionCount(ctx sdk.Context) uint64
4747
GetSession(ctx sdk.Context, id uint64) (sessiontypes.Session, bool)
4848
IsValidGigabytes(ctx sdk.Context, id int64) bool

x/node/keeper/msg_handler.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ func (k *Keeper) HandleMsgStartSession(ctx sdk.Context, msg *v3.MsgStartSessionR
252252
return nil, err
253253
}
254254

255-
// Generate new session ID and expiration time
255+
// Build a new session with default usage and time fields
256256
count := k.GetSessionCount(ctx)
257-
inactiveAt := k.GetSessionInactiveAt(ctx)
258-
259-
// Construct the session object with bandwidth/time limits and metadata
257+
inactiveAt := k.GetSessionInactivePendingAt(ctx)
260258
session := &v3.Session{
261259
BaseSession: &sessiontypes.BaseSession{
262260
ID: count + 1,

x/session/keeper/msg_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func (k *Keeper) HandleMsgUpdateSession(ctx sdk.Context, msg *v3.MsgUpdateSessio
126126

127127
// If active, refresh inactivity timeout
128128
if session.GetStatus().Equal(v1base.StatusActive) {
129-
inactiveAt := k.GetInactiveAt(ctx)
130-
session.SetInactiveAt(inactiveAt)
129+
inactivePendingAt := k.GetInactivePendingAt(ctx)
130+
session.SetInactiveAt(inactivePendingAt)
131131
}
132132

133133
// Persist updated session and reindex if still active

x/session/keeper/params.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ func (k *Keeper) GetParams(ctx sdk.Context) (v v3.Params) {
3030
return v
3131
}
3232

33+
// ActiveDuration returns the active duration from the module's parameters.
34+
func (k *Keeper) ActiveDuration(ctx sdk.Context) time.Duration {
35+
return k.GetParams(ctx).ActiveDuration
36+
}
37+
38+
// InactivePendingDuration returns the inactive pending duration from the module's parameters.
39+
func (k *Keeper) InactivePendingDuration(ctx sdk.Context) time.Duration {
40+
return k.GetParams(ctx).InactivePendingDuration
41+
}
42+
3343
// MaxGigabytes retrieves the maximum gigabytes parameter from the module's parameters.
3444
func (k *Keeper) MaxGigabytes(ctx sdk.Context) int64 {
3545
return k.GetParams(ctx).MaxGigabytes
@@ -60,11 +70,6 @@ func (k *Keeper) StakingShare(ctx sdk.Context) sdkmath.LegacyDec {
6070
return k.GetParams(ctx).StakingShare
6171
}
6272

63-
// StatusChangeDelay returns the delay for status changes from the module's parameters.
64-
func (k *Keeper) StatusChangeDelay(ctx sdk.Context) time.Duration {
65-
return k.GetParams(ctx).StatusChangeDelay
66-
}
67-
6873
// IsValidGigabytes checks if the provided gigabytes are within the valid range defined by the module's parameters.
6974
func (k *Keeper) IsValidGigabytes(ctx sdk.Context, gigabytes int64) bool {
7075
if gigabytes > k.MaxGigabytes(ctx) {
@@ -91,9 +96,16 @@ func (k *Keeper) IsValidHours(ctx sdk.Context, hours int64) bool {
9196
return true
9297
}
9398

94-
// GetInactiveAt returns the inactive time by adding StatusChangeDelay to the current block time.
99+
// GetInactivePendingAt returns the inactive pending time by adding ActiveDuration to the current block time.
100+
func (k *Keeper) GetInactivePendingAt(ctx sdk.Context) time.Time {
101+
d := k.ActiveDuration(ctx)
102+
103+
return ctx.BlockTime().Add(d)
104+
}
105+
106+
// GetInactiveAt returns the inactive time by adding InactivePendingDuration to the current block time.
95107
func (k *Keeper) GetInactiveAt(ctx sdk.Context) time.Time {
96-
d := k.StatusChangeDelay(ctx)
108+
d := k.InactivePendingDuration(ctx)
97109

98110
return ctx.BlockTime().Add(d)
99111
}

x/session/migrations/migrator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ func (k *Migrator) deleteKeys(ctx sdk.Context, keyPrefix []byte) (keys [][]byte)
5353

5454
func (k *Migrator) setParams(ctx sdk.Context) {
5555
params := v3.Params{
56+
ActiveDuration: 2 * time.Hour,
57+
InactivePendingDuration: 2 * time.Hour,
5658
MaxGigabytes: 1_000_000,
5759
MinGigabytes: 1,
5860
MaxHours: 720,
5961
MinHours: 1,
6062
ProofVerificationEnabled: false,
6163
StakingShare: sdkmath.LegacyMustNewDecFromStr("0.2"),
62-
StatusChangeDelay: 2 * time.Hour,
6364
}
6465

6566
k.session.SetParams(ctx, params)

x/session/types/v3/params.go

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@ import (
1010

1111
// Default parameter values for the Params struct.
1212
var (
13+
DefaultActiveDuration = 1 * time.Minute // Default active duration
14+
DefaultInactivePendingDuration = 1 * time.Minute // Default inactive pending duration
1315
DefaultMaxGigabytes int64 = 10 // Default maximum allowed gigabytes
1416
DefaultMinGigabytes int64 = 1 // Default minimum allowed gigabytes
1517
DefaultMaxHours int64 = 10 // Default maximum allowed hours
1618
DefaultMinHours int64 = 1 // Default minimum allowed hours
1719
DefaultProofVerificationEnabled = false // Default proof verification flag
1820
DefaultStakingShare = math.LegacyMustNewDecFromStr("0.1") // Default staking share: 0.1
19-
DefaultStatusChangeDelay = 1 * time.Minute // Default delay before validator status change
2021
)
2122

2223
// Validate checks whether the Params fields are valid according to defined rules.
2324
func (m *Params) Validate() error {
25+
if err := validateActiveDuration(m.ActiveDuration); err != nil {
26+
return fmt.Errorf("invalid active_duration: %w", err)
27+
}
28+
29+
if err := validateInactivePendingDuration(m.InactivePendingDuration); err != nil {
30+
return fmt.Errorf("invalid inactive_pending_duration: %w", err)
31+
}
32+
2433
if err := validateMaxGigabytes(m.MaxGigabytes); err != nil {
2534
return fmt.Errorf("invalid max_gigabytes: %w", err)
2635
}
@@ -45,42 +54,66 @@ func (m *Params) Validate() error {
4554
return fmt.Errorf("invalid staking_share: %w", err)
4655
}
4756

48-
if err := validateStatusChangeDelay(m.StatusChangeDelay); err != nil {
49-
return fmt.Errorf("invalid status_change_delay: %w", err)
50-
}
51-
5257
return nil
5358
}
5459

5560
// NewParams creates a new Params instance with custom values.
5661
func NewParams(
57-
maxGigabytes, minGigabytes, maxHours, minHours int64, proofVerificationEnabled bool, stakingShare math.LegacyDec,
58-
statusChangeDelay time.Duration,
62+
activeDuration, inactivePendingDuration time.Duration, maxGigabytes, minGigabytes, maxHours, minHours int64,
63+
proofVerificationEnabled bool, stakingShare math.LegacyDec,
5964
) Params {
6065
return Params{
66+
ActiveDuration: activeDuration,
67+
InactivePendingDuration: inactivePendingDuration,
6168
MaxGigabytes: maxGigabytes,
6269
MinGigabytes: minGigabytes,
6370
MaxHours: maxHours,
6471
MinHours: minHours,
6572
ProofVerificationEnabled: proofVerificationEnabled,
6673
StakingShare: stakingShare,
67-
StatusChangeDelay: statusChangeDelay,
6874
}
6975
}
7076

7177
// DefaultParams returns a Params struct initialized with default values.
7278
func DefaultParams() Params {
7379
return NewParams(
80+
DefaultActiveDuration,
81+
DefaultInactivePendingDuration,
7482
DefaultMaxGigabytes,
7583
DefaultMinGigabytes,
7684
DefaultMaxHours,
7785
DefaultMinHours,
7886
DefaultProofVerificationEnabled,
7987
DefaultStakingShare,
80-
DefaultStatusChangeDelay,
8188
)
8289
}
8390

91+
// validateActiveDuration ensures the activeDuration is positive and non-zero.
92+
func validateActiveDuration(v time.Duration) error {
93+
if v == 0 {
94+
return errors.New("value cannot be zero")
95+
}
96+
97+
if v < 0 {
98+
return errors.New("value cannot be negative")
99+
}
100+
101+
return nil
102+
}
103+
104+
// validateInactivePendingDuration ensures the inactivePendingDuration is positive and non-zero.
105+
func validateInactivePendingDuration(v time.Duration) error {
106+
if v == 0 {
107+
return errors.New("value cannot be zero")
108+
}
109+
110+
if v < 0 {
111+
return errors.New("value cannot be negative")
112+
}
113+
114+
return nil
115+
}
116+
84117
// validateMaxGigabytes ensures maxGigabytes is a positive non-zero integer.
85118
func validateMaxGigabytes(v int64) error {
86119
if v == 0 {
@@ -155,16 +188,3 @@ func validateStakingShare(v math.LegacyDec) error {
155188

156189
return nil
157190
}
158-
159-
// validateStatusChangeDelay ensures the delay is positive and non-zero.
160-
func validateStatusChangeDelay(v time.Duration) error {
161-
if v == 0 {
162-
return errors.New("value cannot be zero")
163-
}
164-
165-
if v < 0 {
166-
return errors.New("value cannot be negative")
167-
}
168-
169-
return nil
170-
}

0 commit comments

Comments
 (0)