Skip to content

Commit 12d12c0

Browse files
committed
feat: add max_bytes and max_duration for session in subscription module
1 parent 2e99003 commit 12d12c0

File tree

20 files changed

+1238
-1125
lines changed

20 files changed

+1238
-1125
lines changed

proto/sentinel/node/v3/events.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ message EventCreateSession {
4646
string acc_address = 2;
4747
string node_address = 3;
4848
string price = 4;
49-
int64 max_gigabytes = 5;
50-
int64 max_hours = 6;
49+
string max_bytes = 5;
50+
string max_duration = 6;
5151
}

proto/sentinel/node/v3/session.proto

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,14 @@ syntax = "proto3";
22
package sentinel.node.v3;
33

44
import "gogoproto/gogo.proto";
5-
import "google/protobuf/duration.proto";
6-
import "google/protobuf/timestamp.proto";
5+
import "sentinel/session/v3/session.proto";
76
import "sentinel/types/v1/price.proto";
8-
import "sentinel/types/v1/status.proto";
97

108
option go_package = "github.com/sentinel-official/hub/v12/x/node/types/v3";
119
option (gogoproto.equal_all) = false;
10+
option (gogoproto.goproto_getters_all) = false;
1211

1312
message Session {
14-
uint64 id = 1 [(gogoproto.customname) = "ID"];
15-
string acc_address = 2;
16-
string node_address = 3;
17-
sentinel.types.v1.Price price = 4 [(gogoproto.nullable) = false];
18-
string download_bytes = 5 [
19-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
20-
(gogoproto.nullable) = false
21-
];
22-
string upload_bytes = 6 [
23-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
24-
(gogoproto.nullable) = false
25-
];
26-
int64 max_gigabytes = 7;
27-
google.protobuf.Duration duration = 8 [
28-
(gogoproto.nullable) = false,
29-
(gogoproto.stdduration) = true
30-
];
31-
int64 max_hours = 9;
32-
sentinel.types.v1.Status status = 10;
33-
google.protobuf.Timestamp inactive_at = 11 [
34-
(gogoproto.nullable) = false,
35-
(gogoproto.stdtime) = true
36-
];
37-
google.protobuf.Timestamp status_at = 12 [
38-
(gogoproto.nullable) = false,
39-
(gogoproto.stdtime) = true
40-
];
13+
sentinel.session.v3.BaseSession base_session = 1 [(gogoproto.embed) = true];
14+
sentinel.types.v1.Price price = 2 [(gogoproto.nullable) = false];
4115
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
syntax = "proto3";
2+
package sentinel.session.v3;
3+
4+
import "gogoproto/gogo.proto";
5+
import "google/protobuf/duration.proto";
6+
import "google/protobuf/timestamp.proto";
7+
import "sentinel/types/v1/status.proto";
8+
9+
option go_package = "github.com/sentinel-official/hub/v12/x/session/types/v3";
10+
option (gogoproto.equal_all) = false;
11+
option (gogoproto.goproto_getters_all) = false;
12+
13+
message BaseSession {
14+
uint64 id = 1 [(gogoproto.customname) = "ID"];
15+
string acc_address = 2;
16+
string node_address = 3;
17+
string download_bytes = 4 [
18+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
19+
(gogoproto.nullable) = false
20+
];
21+
string upload_bytes = 5 [
22+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
23+
(gogoproto.nullable) = false
24+
];
25+
string max_bytes = 6 [
26+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
27+
(gogoproto.nullable) = false
28+
];
29+
google.protobuf.Duration duration = 7 [
30+
(gogoproto.nullable) = false,
31+
(gogoproto.stdduration) = true
32+
];
33+
google.protobuf.Duration max_duration = 8 [
34+
(gogoproto.nullable) = false,
35+
(gogoproto.stdduration) = true
36+
];
37+
sentinel.types.v1.Status status = 9;
38+
google.protobuf.Timestamp inactive_at = 10 [
39+
(gogoproto.nullable) = false,
40+
(gogoproto.stdtime) = true
41+
];
42+
google.protobuf.Timestamp start_at = 11 [
43+
(gogoproto.nullable) = false,
44+
(gogoproto.stdtime) = true
45+
];
46+
google.protobuf.Timestamp status_at = 12 [
47+
(gogoproto.nullable) = false,
48+
(gogoproto.stdtime) = true
49+
];
50+
}

proto/sentinel/subscription/v3/session.proto

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,13 @@ syntax = "proto3";
22
package sentinel.subscription.v3;
33

44
import "gogoproto/gogo.proto";
5-
import "google/protobuf/duration.proto";
6-
import "google/protobuf/timestamp.proto";
7-
import "sentinel/types/v1/status.proto";
5+
import "sentinel/session/v3/session.proto";
86

97
option go_package = "github.com/sentinel-official/hub/v12/x/subscription/types/v3";
108
option (gogoproto.equal_all) = false;
9+
option (gogoproto.goproto_getters_all) = false;
1110

1211
message Session {
13-
uint64 id = 1 [(gogoproto.customname) = "ID"];
14-
string acc_address = 2;
15-
string node_address = 3;
16-
uint64 subscription_id = 4 [(gogoproto.customname) = "SubscriptionID"];
17-
string download_bytes = 5 [
18-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
19-
(gogoproto.nullable) = false
20-
];
21-
string upload_bytes = 6 [
22-
(gogoproto.customtype) = "cosmossdk.io/math.Int",
23-
(gogoproto.nullable) = false
24-
];
25-
google.protobuf.Duration duration = 7 [
26-
(gogoproto.nullable) = false,
27-
(gogoproto.stdduration) = true
28-
];
29-
sentinel.types.v1.Status status = 8;
30-
google.protobuf.Timestamp inactive_at = 9 [
31-
(gogoproto.nullable) = false,
32-
(gogoproto.stdtime) = true
33-
];
34-
google.protobuf.Timestamp status_at = 10 [
35-
(gogoproto.nullable) = false,
36-
(gogoproto.stdtime) = true
37-
];
12+
sentinel.session.v3.BaseSession base_session = 1 [(gogoproto.embed) = true];
13+
uint64 subscription_id = 2 [(gogoproto.customname) = "SubscriptionID"];
3814
}

x/node/keeper/msg_handler.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
v1base "github.com/sentinel-official/hub/v12/types/v1"
1111
"github.com/sentinel-official/hub/v12/x/node/types"
1212
"github.com/sentinel-official/hub/v12/x/node/types/v3"
13+
sessiontypes "github.com/sentinel-official/hub/v12/x/session/types/v3"
1314
)
1415

1516
func (k *Keeper) HandleMsgRegisterNode(ctx sdk.Context, msg *v3.MsgRegisterNodeRequest) (*v3.MsgRegisterNodeResponse, error) {
@@ -200,18 +201,21 @@ func (k *Keeper) HandleMsgStartSession(ctx sdk.Context, msg *v3.MsgStartSessionR
200201
count := k.GetSessionCount(ctx)
201202
inactiveAt := k.GetSessionInactiveAt(ctx)
202203
session := &v3.Session{
203-
ID: count + 1,
204-
AccAddress: accAddr.String(),
205-
NodeAddress: nodeAddr.String(),
206-
Price: price,
207-
DownloadBytes: sdkmath.ZeroInt(),
208-
UploadBytes: sdkmath.ZeroInt(),
209-
MaxGigabytes: msg.Gigabytes,
210-
Duration: 0,
211-
MaxHours: msg.Hours,
212-
Status: v1base.StatusActive,
213-
InactiveAt: inactiveAt,
214-
StatusAt: ctx.BlockTime(),
204+
BaseSession: &sessiontypes.BaseSession{
205+
ID: count + 1,
206+
AccAddress: accAddr.String(),
207+
NodeAddress: nodeAddr.String(),
208+
DownloadBytes: sdkmath.ZeroInt(),
209+
UploadBytes: sdkmath.ZeroInt(),
210+
MaxBytes: msg.GetGigabytes(),
211+
Duration: 0,
212+
MaxDuration: msg.GetHours(),
213+
Status: v1base.StatusActive,
214+
InactiveAt: inactiveAt,
215+
StartAt: ctx.BlockTime(),
216+
StatusAt: ctx.BlockTime(),
217+
},
218+
Price: price,
215219
}
216220

217221
deposit := session.DepositAmount()
@@ -227,12 +231,12 @@ func (k *Keeper) HandleMsgStartSession(ctx sdk.Context, msg *v3.MsgStartSessionR
227231

228232
ctx.EventManager().EmitTypedEvent(
229233
&v3.EventCreateSession{
230-
ID: session.ID,
231-
AccAddress: session.AccAddress,
232-
NodeAddress: session.NodeAddress,
233-
Price: session.Price.String(),
234-
MaxGigabytes: session.MaxGigabytes,
235-
MaxHours: session.MaxHours,
234+
ID: session.ID,
235+
AccAddress: session.AccAddress,
236+
NodeAddress: session.NodeAddress,
237+
Price: session.Price.String(),
238+
MaxBytes: session.MaxBytes.String(),
239+
MaxDuration: session.MaxDuration.String(),
236240
},
237241
)
238242

x/node/keeper/session.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package keeper
2+
3+
import (
4+
sdk "github.com/cosmos/cosmos-sdk/types"
5+
6+
"github.com/sentinel-official/hub/v12/x/node/types/v3"
7+
sessiontypes "github.com/sentinel-official/hub/v12/x/session/types/v3"
8+
)
9+
10+
// UpdateSessionMaxValues checks the session type and updates its values if needed.
11+
func (k *Keeper) UpdateSessionMaxValues(_ sdk.Context, session sessiontypes.Session) error {
12+
// Check if the session is of type v3.Session.
13+
_, ok := session.(*v3.Session)
14+
if !ok {
15+
return nil
16+
}
17+
18+
// Return nil as no update needed.
19+
return nil
20+
}

0 commit comments

Comments
 (0)