Skip to content

Commit 260c500

Browse files
committed
refine the code
1 parent 2828906 commit 260c500

File tree

15 files changed

+386
-387
lines changed

15 files changed

+386
-387
lines changed

app/upgrade.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package app
22

33
import (
4+
virtualgroupmodule "github.com/bnb-chain/greenfield/x/virtualgroup"
5+
virtualgrouptypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
46
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
57
sdk "github.com/cosmos/cosmos-sdk/types"
68
"github.com/cosmos/cosmos-sdk/types/module"
@@ -87,8 +89,8 @@ func (app *App) registerPampasUpgradeHandler() {
8789
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgSwapOut")
8890
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCompleteSwapOut")
8991
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCancelSwapOut")
90-
//app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgStorageProviderExit")
91-
//app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCompleteStorageProviderExit")
92+
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgStorageProviderExit")
93+
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.virtualgroup.MsgCompleteStorageProviderExit")
9294

9395
// disable bucket migration.
9496
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgMigrateBucket")
@@ -126,7 +128,6 @@ func (app *App) registerManchurianUpgradeHandler() {
126128
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Manchurian,
127129
func() error {
128130
app.Logger().Info("Init Manchurian upgrade")
129-
130131
return nil
131132
})
132133
}
@@ -141,7 +142,7 @@ func (app *App) registerHulunbeierUpgradeHandler() {
141142
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCancelSwapIn", 1.2e3))
142143
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCompleteSwapIn", 1.2e3))
143144

144-
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgStorageProviderForceExit", 1.2e3))
145+
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgStorageProviderForcedExit", 1.2e3))
145146
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgStorageProviderExit", 1.2e3))
146147
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCompleteStorageProviderExit", 1.2e3))
147148

@@ -152,7 +153,11 @@ func (app *App) registerHulunbeierUpgradeHandler() {
152153
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Hulunbeier,
153154
func() error {
154155
app.Logger().Info("Init Hulunbeier upgrade")
155-
156+
mm, ok := app.mm.Modules[virtualgrouptypes.ModuleName].(*virtualgroupmodule.AppModule)
157+
if !ok {
158+
panic("*virtualgroupmodule.AppModule not found")
159+
}
160+
mm.SetConsensusVersion(2)
156161
return nil
157162
})
158163
}

e2e/tests/virtualgroup_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ func (s *VirtualGroupTestSuite) TestSPExit2() {
10121012
s.Require().Error(err)
10131013
}
10141014

1015-
func (s *VirtualGroupTestSuite) TestSPForceExit() {
1015+
func (s *VirtualGroupTestSuite) TestSPForcedExit() {
10161016

10171017
ctx := context.Background()
10181018
user := s.GenAndChargeAccounts(1, 1000000)[0]
@@ -1041,9 +1041,9 @@ func (s *VirtualGroupTestSuite) TestSPForceExit() {
10411041

10421042
// 3. create a proposal that puts SP-x to FORCE_EXIT
10431043
govAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
1044-
msgForceExit := virtualgroupmoduletypes.NewMsgStorageProviderForceExit(govAddr, spx.OperatorKey.GetAddr())
1044+
msgForcedExit := virtualgroupmoduletypes.NewMsgStorageProviderForcedExit(govAddr, spx.OperatorKey.GetAddr())
10451045

1046-
proposal, err := v1.NewMsgSubmitProposal([]sdk.Msg{msgForceExit}, sdk.NewCoins(sdk.NewCoin("BNB", sdk.NewInt(1000000000000000000))),
1046+
proposal, err := v1.NewMsgSubmitProposal([]sdk.Msg{msgForcedExit}, sdk.NewCoins(sdk.NewCoin("BNB", sdk.NewInt(1000000000000000000))),
10471047
s.Validator.GetAddr().String(), "", "put SP to force exit status", "put SP to force exit status")
10481048
s.Require().NoError(err)
10491049
txBroadCastResp, err := s.SendTxBlockWithoutCheck(proposal, s.Validator)

proto/greenfield/virtualgroup/events.proto

+6-4
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ message EventStorageProviderExit {
165165
message EventCompleteStorageProviderExit {
166166
// The id of the storage provider who complete exit
167167
uint32 storage_provider_id = 1;
168-
// The operator address which initials the complete exit transaction, for itself or another SP
168+
// The operator address which initials the complete exit transaction.
169169
string operator_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
170-
// The storage address which completes the exit
170+
// The storage provider address which completes the exit
171171
string storage_provider_address = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
172172
// total_deposit defines the number of tokens deposited by this storage provider for staking.
173173
string total_deposit = 4 [
@@ -179,7 +179,7 @@ message EventCompleteStorageProviderExit {
179179
bool forced_exit = 5;
180180
}
181181

182-
message EventSwapIn {
182+
message EventReserveSwapIn {
183183
// The id of the storage provider who wants to swap in
184184
uint32 storage_provider_id = 1;
185185
// The id of the gvg family which the storage provider wants to swap in as primary sp
@@ -188,6 +188,8 @@ message EventSwapIn {
188188
uint32 global_virtual_group_id = 3;
189189
// The id of the target sp who will be swapped
190190
uint32 target_sp_id = 4;
191+
// the expiration time of this reserved swapIn
192+
uint64 expiration_time = 5;
191193
}
192194

193195
message EventCompleteSwapIn {
@@ -212,7 +214,7 @@ message EventCancelSwapIn {
212214
uint32 target_sp_id = 4;
213215
}
214216

215-
message EventStorageProviderForceExit {
217+
message EventStorageProviderForcedExit {
216218
// The id of the storage provider who wants to exit
217219
uint32 storage_provider_id = 1;
218220
}

proto/greenfield/virtualgroup/tx.proto

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ service Msg {
3333
rpc CancelSwapIn(MsgCancelSwapIn) returns (MsgCancelSwapInResponse);
3434
rpc CompleteSwapIn(MsgCompleteSwapIn) returns (MsgCompleteSwapInResponse);
3535

36-
// StorageProviderForceExit defines a governance operation for a SP force exit
36+
// StorageProviderForcedExit defines a governance operation for a SP to be forced to exit
3737
// The authority is defined in the keeper.
38-
rpc StorageProviderForceExit(MsgStorageProviderForceExit) returns (MsgStorageProviderForceExitResponse);
38+
rpc StorageProviderForcedExit(MsgStorageProviderForcedExit) returns (MsgStorageProviderForcedExitResponse);
3939
}
4040

4141
// MsgUpdateParams is the Msg/UpdateParams request type.
@@ -192,7 +192,7 @@ message MsgCompleteStorageProviderExit {
192192
// storage_provider defines the operator account address of the storage provider who will exit
193193
string storage_provider = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
194194

195-
// operator defines the operator account address of the storage provider who initials this transaction.
195+
// operator defines the operator account address who initials this transaction.
196196
string operator = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
197197
}
198198

@@ -210,7 +210,7 @@ message MsgReserveSwapIn {
210210
// it it set to zero, it represents that the operator swap in as the secondary storage provider.
211211
uint32 global_virtual_group_family_id = 3;
212212
// global_virtual_group_id is a global virtual group ID associated with the swap in.
213-
// It allows to be empty only when the operator is the primary storage provider.
213+
// It allows to be empty only when the operator wants to be the successor primary storage provider in a family.
214214
uint32 global_virtual_group_id = 4;
215215
}
216216

@@ -219,14 +219,14 @@ message MsgReserveSwapInResponse {}
219219
message MsgCompleteSwapIn {
220220
option (cosmos.msg.v1.signer) = "storage_provider";
221221

222-
// storage_provider defines the operator account address of the storage provider who want to swap into the virtual group family or global virtual group.
222+
// storage_provider defines the operator account address of the storage provider who wants to swap into the virtual group family or global virtual group.
223223
string storage_provider = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
224224
// virtual_group_family_id is the identifier of the virtual group family.
225225
// if it set to non-zero, it represents that the operator swap in as the primary storage provider
226226
// it it set to zero, it represents that the operator swap in as the secondary storage provider.
227227
uint32 global_virtual_group_family_id = 2;
228228
// global_virtual_group_id is a global virtual group ID associated with the swap in.
229-
// It allows to be empty only when the operator is the primary storage provider.
229+
// It allows to be empty only when the operator wants to be the successor primary storage provider in a family.
230230
uint32 global_virtual_group_id = 3;
231231
}
232232

@@ -242,21 +242,21 @@ message MsgCancelSwapIn {
242242
// it it set to zero, it represents that the operator swap in as the secondary storage provider.
243243
uint32 global_virtual_group_family_id = 2;
244244
// global_virtual_group_id is a global virtual group IDs associated with the swap in.
245-
// It allows to be empty only when the operator is the primary storage provider.
245+
// It allows to be empty only when the operator wants to be the successor primary storage provider in a family.
246246
uint32 global_virtual_group_id = 3;
247247
}
248248

249249
message MsgCancelSwapInResponse {}
250250

251251
// this line is used by starport scaffolding # proto/tx/message
252-
message MsgStorageProviderForceExit {
252+
message MsgStorageProviderForcedExit {
253253
option (cosmos.msg.v1.signer) = "authority";
254254

255255
// authority is the address that controls the module (defaults to x/gov unless overwritten).
256256
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
257257

258-
// storage_provider defines the account address of the storage provider which need to force exit
258+
// storage_provider defines the account address of the storage provider forced to exit
259259
string storage_provider = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
260260
}
261261

262-
message MsgStorageProviderForceExitResponse {}
262+
message MsgStorageProviderForcedExitResponse {}

proto/greenfield/virtualgroup/types.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ message SwapOutInfo {
8181
}
8282

8383
message SwapInInfo {
84-
// successor_sp_id defines the id of sp who want to join the family or GVG
84+
// successor_sp_id defines the id of SP who wants to join the family or GVG
8585
uint32 successor_sp_id = 1;
8686
// target_sp_id is the id of SP in the family or GVG to be swapped.
8787
uint32 target_sp_id = 2;

swagger/static/swagger.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6253,7 +6253,7 @@ paths:
62536253
type: integer
62546254
format: int64
62556255
title: >-
6256-
successor_sp_id defines the id of sp who want to join the
6256+
successor_sp_id defines the id of SP who wants to join the
62576257
family or GVG
62586258
target_sp_id:
62596259
type: integer
@@ -37142,7 +37142,7 @@ definitions:
3714237142
type: integer
3714337143
format: int64
3714437144
title: >-
37145-
successor_sp_id defines the id of sp who want to join the family
37145+
successor_sp_id defines the id of SP who wants to join the family
3714637146
or GVG
3714737147
target_sp_id:
3714837148
type: integer
@@ -37159,7 +37159,7 @@ definitions:
3715937159
type: integer
3716037160
format: int64
3716137161
title: >-
37162-
successor_sp_id defines the id of sp who want to join the family or
37162+
successor_sp_id defines the id of SP who wants to join the family or
3716337163
GVG
3716437164
target_sp_id:
3716537165
type: integer

x/storage/keeper/keeper.go

-7
Original file line numberDiff line numberDiff line change
@@ -904,13 +904,6 @@ func (k Keeper) DeleteObject(
904904
}
905905

906906
spInState := k.MustGetPrimarySPForBucket(ctx, bucketInfo)
907-
908-
if ctx.IsUpgraded(upgradetypes.Hulunbeier) {
909-
if spInState.Status == sptypes.STATUS_GRACEFUL_EXITING || spInState.Status == sptypes.STATUS_FORCED_EXITING {
910-
return types.ErrUpdateQuotaFailed.Wrapf("The SP is in %s, object can not be deleted", spInState.Status)
911-
}
912-
}
913-
914907
internalBucketInfo := k.MustGetInternalBucketInfo(ctx, bucketInfo.Id)
915908

916909
err := k.UnChargeObjectStoreFee(ctx, spInState.Id, bucketInfo, internalBucketInfo, objectInfo)

0 commit comments

Comments
 (0)