Skip to content

Commit

Permalink
refine the code
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Jun 19, 2023
1 parent 80d3d74 commit 8bded06
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
2 changes: 0 additions & 2 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,7 @@ message MsgUpdateParams {

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

// params defines the x/storage parameters to update.

// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}
Expand Down
16 changes: 12 additions & 4 deletions proto/greenfield/virtualgroup/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,48 @@ message GlobalVirtualGroup {
// Each local virtual group is associated with a unique virtual payment account,
// where all object fees are streamed to.
message LocalVirtualGroup {
// id is the identifier of the local virtual group.
uint32 id = 1;

// id is the unique identification for bucket.
// bucket_id is the unique identification for the bucket.
string bucket_id = 2 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// global_virtual_group_id is the identifier of the global virtual group.
uint32 global_virtual_group_id = 3;
// stored_size is the size of the stored data in the local virtual group.
uint64 stored_size = 4;
}

// Global virtual group family serve as a means of grouping global virtual groups.
// Each bucket must be associated with a unique global virtual group family and cannot cross families.
message GlobalVirtualGroupFamily {
// id is the identifier of the global virtual group family.
uint32 id = 1;

// global_virtual_group_ids is a list of identifiers of the global virtual groups associated with the family.
repeated uint32 global_virtual_group_ids = 2;
// virtual_payment_address is the payment address associated with the global virtual group family.
string virtual_payment_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message GlobalVirtualGroupsBindingOnBucket {
// id is the unique identification for bucket.
// bucket_id is the unique identification for the bucket.
string bucket_id = 1 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
// global_virtual_group_ids is a list of identifiers of the global virtual groups associated with the bucket.
repeated uint32 global_virtual_group_ids = 2;
// local_virtual_group_ids is a list of identifiers of the local virtual groups associated with the bucket.
repeated uint32 local_virtual_group_ids = 3;
}

message GVGStatisticsWithinSP {
uint32 storage_provider_id = 1;
// 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;
}

Expand Down
1 change: 1 addition & 0 deletions x/storage/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions x/virtualgroup/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,18 @@ func (k Keeper) RebindingGVGsToBucket(ctx sdk.Context, bucketID math.Uint, dstSP
lvg2gvg[lvgID] = gvgsBindingOnBucket.GlobalVirtualGroupIds[i]
}

newGVGBindingOnBucket.BucketId = bucketID
// verify secondary signature
for _, newLvg2gvg := range newLVGToGVGMappings {
dstGVG, found := k.GetGVG(ctx, newLvg2gvg.GlobalVirtualGroupId)
if !found {
return types.ErrGVGNotExist.Wrapf("dst gvg not found")
}

lvg, found := k.GetLVG(ctx, bucketID, newLvg2gvg.LocalVirtualGroupId)
if !found {
return types.ErrGVGNotExist.Wrapf("lvg not found")
}

srcGVGID, exists := lvg2gvg[newLvg2gvg.LocalVirtualGroupId]
if exists {
return types.ErrMigrationBucketFailed.Wrapf("local virtual group not found, id: %d", newLvg2gvg.LocalVirtualGroupId)
Expand All @@ -579,17 +583,21 @@ func (k Keeper) RebindingGVGsToBucket(ctx sdk.Context, bucketID math.Uint, dstSP
}
}

dstGVG.StoredSize += srcGVG.StoredSize
dstGVG.StoredSize += lvg.StoredSize
srcGVG.StoredSize -= lvg.StoredSize
// TODO(fynn): add deposit check
newGVGBindingOnBucket.LocalVirtualGroupIds = append(newGVGBindingOnBucket.LocalVirtualGroupIds, newLvg2gvg.LocalVirtualGroupId)
newGVGBindingOnBucket.GlobalVirtualGroupIds = append(newGVGBindingOnBucket.GlobalVirtualGroupIds, newLvg2gvg.GlobalVirtualGroupId)
delete(lvg2gvg, newLvg2gvg.LocalVirtualGroupId)
k.SetGVG(ctx, dstGVG)
k.SetGVG(ctx, srcGVG)
}

if len(lvg2gvg) != 0 || len(gvgsBindingOnBucket.LocalVirtualGroupIds) != len(newGVGBindingOnBucket.LocalVirtualGroupIds) {
return types.ErrMigrationBucketFailed.Wrapf("LVG is not fully rebinding.")
}

newGVGBindingOnBucket.BucketId = bucketID
k.SetGVGsBindingOnBucket(ctx, &newGVGBindingOnBucket)
return nil
}
28 changes: 19 additions & 9 deletions x/virtualgroup/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8bded06

Please sign in to comment.