Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgao001 committed Feb 5, 2024
1 parent c244c8b commit de62f2c
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 177 deletions.
10 changes: 10 additions & 0 deletions e2e/tests/storage_bill_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2567,4 +2567,14 @@ func (s *PaymentTestSuite) TestStorageBill_UpdateObject() {
userStreamAccountAfterSealObjectTx := streamRecordsAfterSealObjectTx.User
s.Require().Equal(sdkmath.ZeroInt(), userStreamAccountAfterSealObjectTx.LockBalance)
s.Require().Equal(userStreamAccountAfterUpdateObjTx.NetflowRate.Sub(orginChargeRate.Neg()).Add(newChargeRate.Neg()), userStreamAccountAfterSealObjectTx.NetflowRate)

// User deletes the object
msgDeleteObject := storagetypes.NewMsgDeleteObject(user.GetAddr(), bucketName, objectName)
s.SendTxBlock(user, msgDeleteObject)

// get stream records after UpdateObjectContent Tx
streamRecordsAfterDeleteObjectTx := s.getStreamRecords(streamAddresses)
s.T().Logf("streamRecordsAfterDeleteObjectTx %s", core.YamlString(streamRecordsAfterDeleteObjectTx))
userstreamRecordsAfterDeleteObjectTx := streamRecordsAfterDeleteObjectTx.User
s.Require().Equal(sdk.ZeroInt(), userstreamRecordsAfterDeleteObjectTx.LockBalance)
}
2 changes: 0 additions & 2 deletions proto/greenfield/storage/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ message EventSealObject {
uint32 global_virtual_group_id = 7;
// local_virtual_group_id defines the unique id of lvg which the object stored
uint32 local_virtual_group_id = 8;
// for_update indicates whether sealing on a updating object
bool for_update = 9;
}

// EventCopyObject is emitted on MsgCopyObject
Expand Down
18 changes: 7 additions & 11 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,6 @@ func (k Keeper) SealObject(
Status: objectInfo.ObjectStatus,
GlobalVirtualGroupId: opts.GlobalVirtualGroupId,
LocalVirtualGroupId: objectInfo.LocalVirtualGroupId,
ForUpdate: isUpdate,
}); err != nil {
return err
}
Expand Down Expand Up @@ -967,18 +966,20 @@ func (k Keeper) DeleteObject(
}
return types.ErrObjectNotSealed
}
// user should cancel the update first to delete an object.
if objectInfo.IsUpdating {
return types.ErrObjectIsUpdating
}
// check permission
effect := k.VerifyObjectPermission(ctx, bucketInfo, objectInfo, operator, permtypes.ACTION_DELETE_OBJECT)
if effect != permtypes.EFFECT_ALLOW {
return types.ErrAccessDenied.Wrapf(
"The operator(%s) has no DeleteObject permission of the bucket(%s), object(%s)",
operator.String(), bucketName, objectName)
}

if objectInfo.IsUpdating {
shadowObjectInfo := k.MustGetShadowObjectInfo(ctx, bucketInfo.BucketName, objectInfo.ObjectName)
err := k.UnlockShadowObjectFeeAndDeleteShadowObjectInfo(ctx, bucketInfo, shadowObjectInfo, objectInfo.ObjectName)
if err != nil {
return err
}
}
_ = k.MustGetPrimarySPForBucket(ctx, bucketInfo)
internalBucketInfo := k.MustGetInternalBucketInfo(ctx, bucketInfo.Id)

Expand Down Expand Up @@ -1220,7 +1221,6 @@ func (k Keeper) RejectSealObject(ctx sdk.Context, operator sdk.AccAddress, bucke
// only this field need to revert
objectInfo.IsUpdating = false
obz := k.cdc.MustMarshal(objectInfo)
store.Set(types.GetObjectKey(bucketName, objectName), k.objectSeq.EncodeSequence(objectInfo.Id))
store.Set(types.GetObjectByIDKey(objectInfo.Id), obz)
} else {
err := k.UnlockObjectStoreFee(ctx, bucketInfo, objectInfo)
Expand Down Expand Up @@ -2442,9 +2442,6 @@ func (k Keeper) UpdateObjectContent(
if objectInfo.IsUpdating {
return types.ErrObjectIsUpdating.Wrapf("The object is already being updated")
}
if objectInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
}
// check permission
effect := k.VerifyObjectPermission(ctx, bucketInfo, objectInfo, operator, permtypes.ACTION_UPDATE_OBJECT_CONTENT)
if effect != permtypes.EFFECT_ALLOW {
Expand Down Expand Up @@ -2569,7 +2566,6 @@ func (k Keeper) CancelUpdateObjectContent(

objectInfo.IsUpdating = false
obz := k.cdc.MustMarshal(objectInfo)
store.Set(types.GetObjectKey(bucketName, objectName), k.objectSeq.EncodeSequence(objectInfo.Id))
store.Set(types.GetObjectByIDKey(objectInfo.Id), obz)

return ctx.EventManager().EmitTypedEvents(&types.EventCancelUpdateObjectContent{
Expand Down
1 change: 0 additions & 1 deletion x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ func (k msgServer) UpdateObjectContent(goCtx context.Context, msg *storagetypes.
err := k.Keeper.UpdateObjectContent(ctx, operatorAcc, msg.BucketName, msg.ObjectName, msg.PayloadSize, storagetypes.UpdateObjectOptions{
Checksums: msg.ExpectChecksums,
ContentType: msg.ContentType,
SourceType: types.SOURCE_TYPE_ORIGIN,
})
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit de62f2c

Please sign in to comment.