Skip to content

Commit

Permalink
feat: support reject bucket migration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Sep 25, 2023
1 parent 014b759 commit 8496bab
Show file tree
Hide file tree
Showing 11 changed files with 1,032 additions and 251 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.3
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20230925033348-16e523d40995
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/bnb-chain/greenfield-cometbft v0.0.3 h1:tv8NMy3bzX/1urqXGQIIAZSLy83lo
github.com/bnb-chain/greenfield-cometbft v0.0.3/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6 h1:aPrd2nG2nYZr8nSmGgN8efus6sni4OIZ1Bdx6s+mS3A=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.6/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20230925033348-16e523d40995 h1:PliHG+z1dVVgTjfn7CKuJh1Umh6S4vu+dV3MqWDa9cM=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20230925033348-16e523d40995/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down
13 changes: 13 additions & 0 deletions proto/greenfield/storage/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ message EventCancelMigrationBucket {
];
}

message EventRejectMigrateBucket {
// The address of the operator that reject the bucket migration, must be the dest SP
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// The name of the bucket to be migrated
string bucket_name = 2;
// bucket_id define an u256 id for object
string bucket_id = 3 [
(cosmos_proto.scalar) = "cosmos.Uint",
(gogoproto.customtype) = "Uint",
(gogoproto.nullable) = false
];
}

message EventCompleteMigrationBucket {
// The address of the operator that initiated the bucket migration,
// usually the owner of the bucket or another account which has permission to operate
Expand Down
13 changes: 13 additions & 0 deletions proto/greenfield/storage/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ service Msg {
rpc MigrateBucket(MsgMigrateBucket) returns (MsgMigrateBucketResponse);
rpc CompleteMigrateBucket(MsgCompleteMigrateBucket) returns (MsgCompleteMigrateBucketResponse);
rpc CancelMigrateBucket(MsgCancelMigrateBucket) returns (MsgCancelMigrateBucketResponse);
rpc RejectMigrateBucket(MsgRejectMigrateBucket) returns (MsgRejectMigrateBucketResponse);
}
message MsgCreateBucket {
option (cosmos.msg.v1.signer) = "creator";
Expand Down Expand Up @@ -615,3 +616,15 @@ message MsgCancelMigrateBucket {
}

message MsgCancelMigrateBucketResponse {}

message MsgRejectMigrateBucket {
option (cosmos.msg.v1.signer) = "operator";

// operator defines the account address of the msg operator.
// only the Dest SP can send this transaction to reject the bucket migration.
string operator = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// bucket_name defines the name of the bucket that need to be migrated
string bucket_name = 2;
}

message MsgRejectMigrateBucketResponse {}
1 change: 0 additions & 1 deletion sdk/client/gnfd_tm.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (c *GreenfieldClient) GetStatus(ctx context.Context) (*ctypes.ResultStatus,

func (c *GreenfieldClient) BroadcastVote(ctx context.Context, vote votepool.Vote) error {
_, err := c.tendermintClient.BroadcastVote(ctx, vote)

return err
}

Expand Down
34 changes: 34 additions & 0 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,40 @@ func (k Keeper) CancelBucketMigration(ctx sdk.Context, operator sdk.AccAddress,
return nil
}

func (k Keeper) RejectBucketMigration(ctx sdk.Context, operator sdk.AccAddress, bucketName string) error {
store := ctx.KVStore(k.storeKey)
bucketInfo, found := k.GetBucketInfo(ctx, bucketName)
if !found {
return types.ErrNoSuchBucket
}
if bucketInfo.BucketStatus != types.BUCKET_STATUS_MIGRATING {
return types.ErrInvalidBucketStatus.Wrapf("The bucket is not in migrating status")
}

migrationBucketInfo, found := k.GetMigrationBucketInfo(ctx, bucketInfo.Id)
if !found {
panic("migration bucket key not found for a migrating bucket. Should not happen")
}

sp := k.spKeeper.MustGetStorageProvider(ctx, migrationBucketInfo.DstSpId)
if !sdk.MustAccAddressFromHex(sp.OperatorAddress).Equals(operator) {
return types.ErrAccessDenied.Wrap("Only the dest SP can reject the bucket migration.")
}

bucketInfo.BucketStatus = types.BUCKET_STATUS_CREATED
k.SetBucketInfo(ctx, bucketInfo)
store.Delete(types.GetMigrationBucketKey(bucketInfo.Id))

if err := ctx.EventManager().EmitTypedEvents(&types.EventRejectMigrateBucket{
Operator: operator.String(),
BucketName: bucketName,
BucketId: bucketInfo.Id,
}); err != nil {
return err
}
return nil
}

func (k Keeper) GetMigrationBucketInfo(ctx sdk.Context, bucketID sdkmath.Uint) (*types.MigrationBucketInfo, bool) {
store := ctx.KVStore(k.storeKey)

Expand Down
13 changes: 13 additions & 0 deletions x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,19 @@ func (k msgServer) CancelMigrateBucket(goCtx context.Context, msg *types.MsgCanc
return &types.MsgCancelMigrateBucketResponse{}, nil
}

func (k msgServer) RejectMigrateBucket(goCtx context.Context, msg *storagetypes.MsgRejectMigrateBucket) (*storagetypes.MsgRejectMigrateBucketResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

operator := sdk.MustAccAddressFromHex(msg.Operator)

err := k.RejectBucketMigration(ctx, operator, msg.BucketName)
if err != nil {
return nil, err
}

return &types.MsgRejectMigrateBucketResponse{}, nil
}

func (k Keeper) verifyGVGSignatures(ctx sdk.Context, bucketID math.Uint, dstSP *sptypes.StorageProvider, gvgMappings []*storagetypes.GVGMapping) error {
// verify secondary sp signature
for _, newLvg2gvg := range gvgMappings {
Expand Down
4 changes: 4 additions & 0 deletions x/storage/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgMigrateBucket{}, "storage/MigrateBucket", nil)
cdc.RegisterConcrete(&MsgCompleteMigrateBucket{}, "storage/CompleteMigrateBucket", nil)
cdc.RegisterConcrete(&MsgCancelMigrateBucket{}, "storage/CancelMigrateBucket", nil)
cdc.RegisterConcrete(&MsgRejectMigrateBucket{}, "storage/RejectMigrateBucket", nil)
// this line is used by starport scaffolding # 2
}

Expand Down Expand Up @@ -112,6 +113,9 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgCancelMigrateBucket{},
)
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgRejectMigrateBucket{},
)
// this line is used by starport scaffolding # 3

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
Loading

0 comments on commit 8496bab

Please sign in to comment.