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

release: prepare release for v0.2.5-alpha.2 #469

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.2.5-alpha.2
This release contains 1 bugfix.
* [#465](https://github.com/bnb-chain/greenfield/pull/465) fix: remaining policies need re-persistence

## v0.2.5-alpha.1
This release contains 4 features and 4 bugfixes.

Expand Down
43 changes: 34 additions & 9 deletions x/permission/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,14 @@ func (k Keeper) ForceDeleteAccountPolicyForResource(ctx sdk.Context, maxDelete,
resourceAccountsPolicyStore := prefix.NewStore(store, types.PolicyForAccountPrefix(resourceID, resourceType))
iterator := resourceAccountsPolicyStore.Iterator(nil, nil)
defer iterator.Close()

isNagquUpgraded := ctx.IsUpgraded(upgradetypes.Nagqu)
for ; iterator.Valid(); iterator.Next() {
// if exceeding the limit, pause the GC and mark the current resource's deletion is not complete yet
if isNagquUpgraded {
if deletedTotal >= maxDelete {
return deletedTotal, false
}
}
policyId := k.policySeq.DecodeSequence(iterator.Value())
policy, _ := k.GetPolicyByID(ctx, policyId)
if policy != nil && policy.ExpirationTime != nil {
Expand All @@ -400,11 +406,11 @@ func (k Keeper) ForceDeleteAccountPolicyForResource(ctx sdk.Context, maxDelete,
PolicyId: policyId,
})
deletedTotal++
// if exceeding the limit, pause the GC and mark the current resource's deletion is not complete yet
if deletedTotal > maxDelete {
return deletedTotal, false
if !isNagquUpgraded {
if deletedTotal > maxDelete {
return deletedTotal, false
}
}

}
return deletedTotal, true
}
Expand All @@ -420,7 +426,16 @@ func (k Keeper) ForceDeleteGroupPolicyForResource(ctx sdk.Context, maxDelete, de
if bz != nil {
policyGroup := types.PolicyGroup{}
k.cdc.MustUnmarshal(bz, &policyGroup)

isNagquUpgraded := ctx.IsUpgraded(upgradetypes.Nagqu)
for i := 0; i < len(policyGroup.Items); i++ {
if isNagquUpgraded {
if deletedTotal >= maxDelete {
remainingPolicies := policyGroup.Items[i:]
store.Set(policyForGroupKey, k.cdc.MustMarshal(&types.PolicyGroup{Items: remainingPolicies}))
return deletedTotal, false
}
}
policyId := policyGroup.Items[i].PolicyId
policy, _ := k.GetPolicyByID(ctx, policyId)
if policy != nil && policy.ExpirationTime != nil {
Expand All @@ -434,8 +449,10 @@ func (k Keeper) ForceDeleteGroupPolicyForResource(ctx sdk.Context, maxDelete, de
PolicyId: policyId,
})
deletedTotal++
if deletedTotal > maxDelete {
return deletedTotal, false
if !isNagquUpgraded {
if deletedTotal > maxDelete {
return deletedTotal, false
}
}
}
store.Delete(policyForGroupKey)
Expand All @@ -449,15 +466,23 @@ func (k Keeper) ForceDeleteGroupMembers(ctx sdk.Context, maxDelete, deletedTotal
groupMembersPrefixStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.GroupMembersPrefix(groupId))
iter := groupMembersPrefixStore.Iterator(nil, nil)
defer iter.Close()
isNagquUpgraded := ctx.IsUpgraded(upgradetypes.Nagqu)
for ; iter.Valid(); iter.Next() {
if isNagquUpgraded {
if deletedTotal >= maxDelete {
return deletedTotal, false
}
}
memberID := k.groupMemberSeq.DecodeSequence(iter.Value())
// delete GroupMemberByIDPrefix_id -> groupMember
store.Delete(types.GetGroupMemberByIDKey(memberID))
// delete GroupMemberPrefix_groupId_memberAddr -> memberSequence(id)
groupMembersPrefixStore.Delete(iter.Key())
deletedTotal++
if deletedTotal > maxDelete {
return deletedTotal, false
if !isNagquUpgraded {
if deletedTotal > maxDelete {
return deletedTotal, false
}
}
}
return deletedTotal, true
Expand Down
4 changes: 2 additions & 2 deletions x/storage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ func (k Keeper) QueryLockFee(c context.Context, req *types.QueryLockFeeRequest)
return nil, status.Error(codes.InvalidArgument, "invalid primary storage provider address")
}

sp, found := k.spKeeper.GetStorageProviderByOperatorAddr(ctx, primaryAcc)
_, found := k.spKeeper.GetStorageProviderByOperatorAddr(ctx, primaryAcc)
if !found {
return nil, sptypes.ErrStorageProviderNotFound
}

amount, err := k.GetObjectLockFee(ctx, sp.GetId(), createAt, req.PayloadSize)
amount, err := k.GetObjectLockFee(ctx, createAt, req.PayloadSize)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down
13 changes: 6 additions & 7 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (k Keeper) ForceDeleteBucket(ctx sdk.Context, bucketId sdkmath.Uint, cap ui
}

if objectStatus == types.OBJECT_STATUS_CREATED {
if err = k.UnlockObjectStoreFee(ctx, sp.Id, bucketInfo, &objectInfo); err != nil {
if err = k.UnlockObjectStoreFee(ctx, bucketInfo, &objectInfo); err != nil {
ctx.Logger().Error("unlock store fee error", "err", err)
return false, deleted, err
}
Expand Down Expand Up @@ -623,7 +623,7 @@ func (k Keeper) CreateObject(
}
} else {
// Lock Fee
err = k.LockObjectStoreFee(ctx, sp.Id, bucketInfo, &objectInfo)
err = k.LockObjectStoreFee(ctx, bucketInfo, &objectInfo)
if err != nil {
return sdkmath.ZeroUint(), err
}
Expand Down Expand Up @@ -835,7 +835,7 @@ func (k Keeper) CancelCreateObject(
return errors.Wrapf(types.ErrAccessDenied, "Only allowed owner/creator to do cancel create object")
}

err := k.UnlockObjectStoreFee(ctx, spInState.Id, bucketInfo, objectInfo)
err := k.UnlockObjectStoreFee(ctx, bucketInfo, objectInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -955,7 +955,7 @@ func (k Keeper) ForceDeleteObject(ctx sdk.Context, objectId sdkmath.Uint) error

spInState := k.MustGetPrimarySPForBucket(ctx, bucketInfo)
if objectStatus == types.OBJECT_STATUS_CREATED {
err := k.UnlockObjectStoreFee(ctx, spInState.Id, bucketInfo, objectInfo)
err := k.UnlockObjectStoreFee(ctx, bucketInfo, objectInfo)
if err != nil {
ctx.Logger().Error("unlock store fee error", "err", err)
return err
Expand Down Expand Up @@ -1057,7 +1057,7 @@ func (k Keeper) CopyObject(
return sdkmath.ZeroUint(), err
}
} else {
err = k.LockObjectStoreFee(ctx, dstPrimarySP.Id, dstBucketInfo, &objectInfo)
err = k.LockObjectStoreFee(ctx, dstBucketInfo, &objectInfo)
if err != nil {
return sdkmath.ZeroUint(), err
}
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func (k Keeper) RejectSealObject(ctx sdk.Context, operator sdk.AccAddress, bucke
return errors.Wrapf(types.ErrAccessDenied, "Only allowed primary SP to do cancel create object")
}

err := k.UnlockObjectStoreFee(ctx, spInState.Id, bucketInfo, objectInfo)
err := k.UnlockObjectStoreFee(ctx, bucketInfo, objectInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -1843,7 +1843,6 @@ func (k Keeper) garbageCollectionForResource(ctx sdk.Context, deleteStalePolicie
deletedTotal, done = k.permKeeper.ForceDeleteAccountPolicyForResource(ctx, maxCleanup, deletedTotal, resourceType, id)
if !done {
resourceIds.Id = temp

deleteStalePoliciesPrefixStore.Set(iterator.Key(), k.cdc.MustMarshal(deleteInfo))
return deletedTotal, false
}
Expand Down
13 changes: 6 additions & 7 deletions x/storage/keeper/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func (k Keeper) UpdateBucketInfoAndCharge(ctx sdk.Context, bucketInfo *storagety
return err
}

func (k Keeper) LockObjectStoreFee(ctx sdk.Context, primarySpId uint32, bucketInfo *storagetypes.BucketInfo, objectInfo *storagetypes.ObjectInfo) error {
func (k Keeper) LockObjectStoreFee(ctx sdk.Context, bucketInfo *storagetypes.BucketInfo, objectInfo *storagetypes.ObjectInfo) error {
paymentAddr := sdk.MustAccAddressFromHex(bucketInfo.PaymentAddress)
amount, err := k.GetObjectLockFee(ctx, primarySpId, objectInfo.CreateAt, objectInfo.PayloadSize)
amount, err := k.GetObjectLockFee(ctx, objectInfo.CreateAt, objectInfo.PayloadSize)
if err != nil {
return fmt.Errorf("get object store fee rate failed: %s %s %w", bucketInfo.BucketName, objectInfo.ObjectName, err)
}
Expand All @@ -133,9 +133,8 @@ func (k Keeper) LockObjectStoreFee(ctx sdk.Context, primarySpId uint32, bucketIn
}

// UnlockObjectStoreFee unlock store fee if the object is deleted in INIT state
func (k Keeper) UnlockObjectStoreFee(ctx sdk.Context, primarySpId uint32, bucketInfo *storagetypes.BucketInfo, objectInfo *storagetypes.ObjectInfo) error {

lockedBalance, err := k.GetObjectLockFee(ctx, primarySpId, objectInfo.CreateAt, objectInfo.PayloadSize)
func (k Keeper) UnlockObjectStoreFee(ctx sdk.Context, bucketInfo *storagetypes.BucketInfo, objectInfo *storagetypes.ObjectInfo) error {
lockedBalance, err := k.GetObjectLockFee(ctx, objectInfo.CreateAt, objectInfo.PayloadSize)
if err != nil {
return fmt.Errorf("get object store fee rate failed: %s %s %w", bucketInfo.BucketName, objectInfo.ObjectName, err)
}
Expand All @@ -151,7 +150,7 @@ func (k Keeper) UnlockObjectStoreFee(ctx sdk.Context, primarySpId uint32, bucket
func (k Keeper) UnlockAndChargeObjectStoreFee(ctx sdk.Context, primarySpId uint32, bucketInfo *storagetypes.BucketInfo,
internalBucketInfo *storagetypes.InternalBucketInfo, objectInfo *storagetypes.ObjectInfo) error {
// unlock store fee
err := k.UnlockObjectStoreFee(ctx, primarySpId, bucketInfo, objectInfo)
err := k.UnlockObjectStoreFee(ctx, bucketInfo, objectInfo)
if err != nil {
return fmt.Errorf("unlock store fee failed: %s %s %w", bucketInfo.BucketName, objectInfo.ObjectName, err)
}
Expand Down Expand Up @@ -488,7 +487,7 @@ func getNegFlows(flows []types.OutFlow) (negFlows []types.OutFlow) {
return negFlows
}

func (k Keeper) GetObjectLockFee(ctx sdk.Context, primarySpId uint32, priceTime int64, payloadSize uint64) (amount sdkmath.Int, err error) {
func (k Keeper) GetObjectLockFee(ctx sdk.Context, priceTime int64, payloadSize uint64) (amount sdkmath.Int, err error) {
price, err := k.spKeeper.GetGlobalSpStorePriceByTime(ctx, priceTime)
if err != nil {
return amount, fmt.Errorf("get store price failed: %d %w", priceTime, err)
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *TestSuite) TestGetObjectLockFee() {

// verify lock fee calculation
payloadSize := int64(10 * 1024 * 1024)
amount, err := s.storageKeeper.GetObjectLockFee(s.ctx, 100, time.Now().Unix(), uint64(payloadSize))
amount, err := s.storageKeeper.GetObjectLockFee(s.ctx, time.Now().Unix(), uint64(payloadSize))
s.Require().NoError(err)
secondarySPNum := int64(s.storageKeeper.GetExpectSecondarySPNumForECObject(s.ctx, time.Now().Unix()))
spRate := price.PrimaryStorePrice.Add(price.SecondaryStorePrice.MulInt64(secondarySPNum)).MulInt64(payloadSize)
Expand Down
Loading