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

fix: migrate bucket #1398

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
12 changes: 11 additions & 1 deletion modular/metadata/metadata_bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,15 +520,25 @@ func (r *MetadataModular) GfSpGetLatestBucketReadQuota(
", bucket_id: " + util.Uint64ToString(req.GetBucketId()) + ", error: " + err.Error())}, nil
}
}

// if the traffic table has been created, return the db info from meta service
var chargedQuotaSize uint64
bucketInfo, err := r.baseApp.Consensus().QueryBucketInfoById(ctx, req.BucketId)
if err != nil {
log.Errorw("failed to get bucketInfo on chain",
"bucket_id", req.GetBucketId(), "error", err)
chargedQuotaSize = bucketTraffic.ChargedQuotaSize
} else {
chargedQuotaSize = bucketInfo.ChargedReadQuota
}
quota := &gfsptask.GfSpBucketQuotaInfo{
BucketName: bucketTraffic.BucketName,
BucketId: bucketTraffic.BucketID,
Month: bucketTraffic.YearMonth,
ReadConsumedSize: bucketTraffic.ReadConsumedSize,
FreeQuotaConsumedSize: bucketTraffic.FreeQuotaConsumedSize,
FreeQuotaSize: bucketTraffic.FreeQuotaSize,
ChargedQuotaSize: bucketTraffic.ChargedQuotaSize,
ChargedQuotaSize: chargedQuotaSize,
MonthlyFreeQuotaSize: bucketTraffic.MonthlyFreeQuotaSize,
MonthlyFreeQuotaConsumedSize: bucketTraffic.MonthlyFreeQuotaConsumedSize,
}
Expand Down
18 changes: 17 additions & 1 deletion modular/metadata/metadata_bucket_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"testing"

"cosmossdk.io/math"
"github.com/forbole/juno/v4/common"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -656,6 +657,7 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {
a.baseApp.SetGfBsDB(m)
spDBMocker := spdb.NewMockSPDB(ctrl)

consensusChargedQuotaSize := uint64(100)
bucketTraffic := &spdb.BucketTraffic{
BucketID: 1,
YearMonth: "2024-01",
Expand All @@ -670,6 +672,20 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {

consensusMock := consensus.NewMockConsensus(ctrl)
consensusMock.EXPECT().QuerySPFreeQuota(gomock.Any(), gomock.Any()).Return(uint64(10000), nil).Times(0)
consensusMock.EXPECT().QueryBucketInfoById(gomock.Any(), gomock.Any()).Return(&storagetypes.BucketInfo{
Owner: "0x11E0A11A7A01E2E757447B52FBD7152004AC699D",
BucketName: "",
Visibility: 0,
Id: math.NewUint(1),
SourceType: 0,
CreateAt: 0,
PaymentAddress: "",
GlobalVirtualGroupFamilyId: 0,
ChargedReadQuota: consensusChargedQuotaSize,
BucketStatus: 0,
Tags: nil,
SpAsDelegatedAgentDisabled: false,
}, nil).AnyTimes()
a.baseApp.SetConsensus(consensusMock)

resp, err := a.GfSpGetLatestBucketReadQuota(context.Background(), &types.GfSpGetLatestBucketReadQuotaRequest{
Expand All @@ -684,7 +700,7 @@ func TestMetadataModular_GfSpGetLatestBucketReadQuota_Success(t *testing.T) {
ReadConsumedSize: bucketTraffic.ReadConsumedSize,
FreeQuotaConsumedSize: bucketTraffic.FreeQuotaConsumedSize,
FreeQuotaSize: bucketTraffic.FreeQuotaSize,
ChargedQuotaSize: bucketTraffic.ChargedQuotaSize,
ChargedQuotaSize: consensusChargedQuotaSize,
},
}, resp)
}
Expand Down
4 changes: 2 additions & 2 deletions modular/metadata/metadata_sp_exit_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ func (r *MetadataModular) GfSpListMigrateBucketEvents(ctx context.Context, req *
GlobalVirtualGroupFamilyId: complete.GlobalVirtualGroupFamilyId,
}
}
if cancel != nil && cancel.CreateAt >= event.CreateAt && complete == nil {
if cancel != nil && cancel.CreateAt >= event.CreateAt && (complete == nil || cancel.CreateAt > complete.CreateAt) {
spCancelEvent = &storage_types.EventCancelMigrationBucket{
Operator: cancel.Operator.String(),
BucketName: cancel.BucketName,
BucketId: math.NewUintFromBigInt(cancel.BucketID.Big()),
}
}
if reject != nil && reject.CreateAt >= event.CreateAt && complete == nil {
if reject != nil && reject.CreateAt >= event.CreateAt && (complete == nil || reject.CreateAt > complete.CreateAt) {
spRejectEvent = &storage_types.EventRejectMigrateBucket{
Operator: reject.Operator.String(),
BucketName: reject.BucketName,
Expand Down
Loading