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: implemente Msgs for SP exit #533

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func (app *App) registerPampasUpgradeHandler() {
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgMigrateBucket")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgCancelMigrateBucket")
app.GashubKeeper.DeleteMsgGasParams(ctx, "/greenfield.storage.MsgCompleteMigrateBucket")

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

Expand All @@ -117,6 +116,15 @@ func (app *App) registerEddystoneUpgradeHandler() {
msgSetTagGasParams := gashubtypes.NewMsgGasParamsWithFixedGas(typeUrl, 1.2e3)
app.GashubKeeper.SetMsgGasParams(ctx, *msgSetTagGasParams)

// TODO use a new harfork
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgReserveSwapIn", 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCancelSwapIn", 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCompleteSwapIn", 1.2e3))

app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgStorageProviderForceExit", 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgStorageProviderExit", 1.2e3))
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas("/greenfield.virtualgroup.MsgCompleteStorageProviderExit", 1.2e3))

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

Expand Down
10 changes: 10 additions & 0 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (s *BaseSuite) SendTxBlockWithExpectErrorString(msg sdk.Msg, from keys.KeyM
_, err := s.Client.BroadcastTx(context.Background(), []sdk.Msg{msg}, txOpt)
s.T().Logf("tx failed, err: %v, expect error string: %s", err, expectErrorString)
s.Require().Error(err)
fmt.Println(err.Error())
s.Require().True(strings.Contains(err.Error(), expectErrorString))
}

Expand Down Expand Up @@ -733,6 +734,15 @@ func (s *BaseSuite) PickStorageProvider() *StorageProvider {
return nil
}

func (s *BaseSuite) PickStorageProviderByID(id uint32) *StorageProvider {
for _, sp := range s.StorageProviders {
if sp.Info.Id == id {
return sp
}
}
return nil
}

func (s *BaseSuite) PickDifferentStorageProvider(spId uint32) *StorageProvider {
for _, sp := range s.StorageProviders {
if sp.Info.Id != spId {
Expand Down
483 changes: 483 additions & 0 deletions e2e/tests/virtualgroup_test.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proto/greenfield/sp/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum Status {
STATUS_IN_JAILED = 1;
STATUS_GRACEFUL_EXITING = 2;
STATUS_IN_MAINTENANCE = 3;
STATUS_FORCE_EXITING = 4;
}

// StorageProvider defines the meta info of storage provider
Expand Down
38 changes: 38 additions & 0 deletions proto/greenfield/virtualgroup/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,41 @@ message EventCompleteStorageProviderExit {
(gogoproto.nullable) = false
];
}

message EventSwapIn {
// The id of the storage provider who wants to swap in
uint32 storage_provider_id = 1;
// The id of the gvg family which the storage provider wants to swap in as primary sp
uint32 global_virtual_group_family_id = 2;
// The id of the gvg which the storage provider wants to swap in as secondary sp
uint32 global_virtual_group_id = 3;
// The id of the target sp who will be swapped
uint32 target_sp_id = 4;
}

message EventCompleteSwapIn {
// The id of the storage provider who complete swap in.
uint32 storage_provider_id = 1;
// The id of the storage provider who swap in the family or gvgs
uint32 target_storage_provider_id = 2;
// The id of the gvg family
uint32 global_virtual_group_family_id = 3;
// The id of the gvg
uint32 global_virtual_group_id = 4;
}

message EventCancelSwapIn {
// The id of the storage provider who cancel swap in.
uint32 storage_provider_id = 1;
// The id of the gvg family
uint32 global_virtual_group_family_id = 2;
// The id of the gvg
uint32 global_virtual_group_id = 3;
// The id of the target sp who was swapped from family or gvgs
uint32 target_sp_id = 4;
}

message EventStorageProviderForceExit {
// The id of the storage provider who wants to exit
uint32 storage_provider_id = 1;
}
6 changes: 5 additions & 1 deletion proto/greenfield/virtualgroup/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ message Params {
uint32 max_global_virtual_group_num_per_family = 4;
// if the store size reach the exceed, the family is not allowed to sever more buckets
uint64 max_store_size_per_family = 5;
}
// the validity period that a successor SP can reserve to complete the swap for Global virtual group/family
uint64 swap_in_validity_period = 6;
// sp_concurrent_exit_num defines the number of sp allowed for exit concurrently.
uint32 sp_concurrent_exit_num = 7;
}
14 changes: 14 additions & 0 deletions proto/greenfield/virtualgroup/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ service Query {
rpc AvailableGlobalVirtualGroupFamilies(AvailableGlobalVirtualGroupFamiliesRequest) returns (AvailableGlobalVirtualGroupFamiliesResponse) {
option (google.api.http).get = "/greenfield/virtualgroup/available_global_virtual_group_families";
}

// AvailableGlobalVirtualGroupFamilies filters a list of GlobalVirtualGroupFamilies ID which are qualified to create bucket on
rpc SwapInInfo(QuerySwapInInfoRequest) returns (QuerySwapInInfoResponse) {
option (google.api.http).get = "/greenfield/virtualgroup/swap_in_info";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -92,3 +97,12 @@ message AvailableGlobalVirtualGroupFamiliesRequest {
message AvailableGlobalVirtualGroupFamiliesResponse {
repeated uint32 global_virtual_group_family_ids = 1;
}

message QuerySwapInInfoRequest {
uint32 global_virtual_group_family_id = 1;
uint32 global_virtual_group_id = 2;
}

message QuerySwapInInfoResponse {
SwapInInfo swap_in_info = 1;
}
73 changes: 71 additions & 2 deletions proto/greenfield/virtualgroup/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ service Msg {
rpc CompleteStorageProviderExit(MsgCompleteStorageProviderExit) returns (MsgCompleteStorageProviderExitResponse);
rpc CompleteSwapOut(MsgCompleteSwapOut) returns (MsgCompleteSwapOutResponse);
rpc CancelSwapOut(MsgCancelSwapOut) returns (MsgCancelSwapOutResponse);
rpc SwapIn(MsgReserveSwapIn) returns (MsgReserveSwapInResponse);
rpc CancelSwapIn(MsgCancelSwapIn) returns (MsgCancelSwapInResponse);
rpc CompleteSwapIn(MsgCompleteSwapIn) returns (MsgCompleteSwapInResponse);

// StorageProviderForceExit defines a governance operation for a SP force exit
// The authority is defined in the keeper.
rpc StorageProviderForceExit(MsgStorageProviderForceExit) returns (MsgStorageProviderForceExitResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand Down Expand Up @@ -119,8 +126,6 @@ message MsgSwapOut {
common.Approval successor_sp_approval = 5;
}

message MsgSwapOutResponse {}

message MsgCompleteSwapOut {
option (cosmos.msg.v1.signer) = "storage_provider";

Expand Down Expand Up @@ -187,3 +192,67 @@ message MsgCompleteStorageProviderExit {
}

message MsgCompleteStorageProviderExitResponse {}

message MsgSwapOutResponse {}

message MsgReserveSwapIn {
option (cosmos.msg.v1.signer) = "storage_provider";

// storage_provider defines the operator account address of the storage provider who want to swap into the virtual group family or global virtual group.
string storage_provider = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// target_sp_id defines the storage provider id to be replaced by the successor sp.
uint32 target_sp_id = 2;
// virtual_group_family_id is the identifier of the virtual group family.
// if it set to non-zero, it represents that the operator swap in as the primary storage provider
// it it set to zero, it represents that the operator swap in as the secondary storage provider.
uint32 global_virtual_group_family_id = 3;
// global_virtual_group_id is a global virtual group ID associated with the swap in.
// It allows to be empty only when the operator is the primary storage provider.
uint32 global_virtual_group_id = 4;
}

message MsgReserveSwapInResponse {}

message MsgCompleteSwapIn {
option (cosmos.msg.v1.signer) = "storage_provider";

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

message MsgCompleteSwapInResponse {}

message MsgCancelSwapIn {
option (cosmos.msg.v1.signer) = "storage_provider";

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

message MsgCancelSwapInResponse {}
// this line is used by starport scaffolding # proto/tx/message
message MsgStorageProviderForceExit {
option (cosmos.msg.v1.signer) = "authority";

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

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

message MsgStorageProviderForceExitResponse {}
18 changes: 17 additions & 1 deletion proto/greenfield/virtualgroup/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ message GlobalVirtualGroupsBindingOnBucket {
message GVGStatisticsWithinSP {
// storage_provider_id defines the id of the sp which the statistics associated to
uint32 storage_provider_id = 1;
// primary_sp_family_count defines the number of the family which this sp serves as primary sp
// primary_count defines the number of global virtual groups (GVGs) which this sp serves as primary sp
uint32 primary_count = 2;
// secondary_count defines the number of global virtual groups (GVGs) in
// which this storage provider serves as a secondary storage provider.
uint32 secondary_count = 3;
// Redundancy defines the number of gvg that sp serves as sp and secondary sp, which breaks the data redundancy requirement.
// In most case, this should not happen,
// during sp exit, a successor sp might need to swapIn GVG(s) that it is already a secondary and become the primary SP
// of whole family.
// a successor sp which need to swapIn a GVG as secondary must be unique to all other SP. So this will not be used for
// swapIn individual GVG as secondary
uint32 break_redundancy_reqmt_gvg_count = 4;
}

message SwapOutInfo {
Expand All @@ -72,3 +79,12 @@ message SwapOutInfo {
// successor_sp_id is the id of the successor storage provider.
uint32 successor_sp_id = 2;
}

message SwapInInfo {
// successor_sp_id defines the id of sp who want to join the family or GVG
uint32 successor_sp_id = 1;
// target_sp_id is the id of SP in the family or GVG to be swapped.
uint32 target_sp_id = 2;
// expiration_time is the expiration of epoch time for the swapInInfo
uint64 expiration_time = 4;
}
1 change: 1 addition & 0 deletions x/sp/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
ErrStorageProviderStatusUpdateNotAllow = errors.Register(ModuleName, 16, "StorageProvider status is not allow to change")
ErrStorageProviderMaintenanceAddrExists = errors.Register(ModuleName, 17, "StorageProvider already exist for this maintenance address; must use new StorageProvider maintenance address.")
ErrStorageProviderPriceUpdateNotAllow = errors.Register(ModuleName, 18, "StorageProvider update price is disallowed")
ErrStorageProviderWrongStatus = errors.Register(ModuleName, 19, "StorageProvider is in wrong status")

ErrSignerNotGovModule = errors.Register(ModuleName, 40, "signer is not gov module account")
ErrSignerEmpty = errors.Register(ModuleName, 41, "signer is empty")
Expand Down
Loading
Loading