Skip to content

Commit

Permalink
introduce erdos upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Apr 2, 2024
1 parent 113e610 commit 8c5e2f5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 25 deletions.
19 changes: 19 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.
app.registerUralUpgradeHandler()
app.registerPawneeUpgradeHandler()
app.registerSerengetiUpgradeHandler()
app.registerErdosUpgradeHandler()
// app.register...()
// ...
return nil
Expand Down Expand Up @@ -237,3 +238,21 @@ func (app *App) registerSerengetiUpgradeHandler() {
return nil
})
}

func (app *App) registerErdosUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Erdos,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)
app.VirtualgroupKeeper.MigrateGlobalVirtualGroupFamiliesForSP(ctx)
app.GashubKeeper.SetMsgGasParams(ctx, *gashubtypes.NewMsgGasParamsWithFixedGas(sdk.MsgTypeURL(&storagemoduletypes.MsgSetBucketFlowRateLimit{}), 1.2e2))
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Erdos,
func() error {
app.Logger().Info("Init Erdos upgrade")
return nil
})
}
1 change: 1 addition & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function generate_genesis() {
echo -e '[[upgrade]]\nname = "Ural"\nheight = 22\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Pawnee"\nheight = 23\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Serengeti"\nheight = 24\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Erdos"\nheight = 25\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
14 changes: 1 addition & 13 deletions e2e/tests/storage_rate_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import (

"github.com/bnb-chain/greenfield/e2e/core"
"github.com/bnb-chain/greenfield/sdk/keys"
virtualgrouptypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"

types2 "github.com/bnb-chain/greenfield/sdk/types"

storageutils "github.com/bnb-chain/greenfield/testutil/storage"
storagetypes "github.com/bnb-chain/greenfield/x/storage/types"
virtualgrouptypes "github.com/bnb-chain/greenfield/x/virtualgroup/types"
)

func (s *StorageTestSuite) enableMessage() {
Expand Down Expand Up @@ -87,8 +85,6 @@ func (s *StorageTestSuite) enableMessage() {
}

func (s *StorageTestSuite) TestSetBucketRateLimitToZero() {
s.enableMessage()

var err error
sp := s.BaseSuite.PickStorageProvider()
gvg, found := sp.GetFirstGlobalVirtualGroup()
Expand Down Expand Up @@ -262,8 +258,6 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Object() {
// 6. the payment account set the rate limit to a positive number
// 7. user update the read quota to a positive number and it should pass
func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Bucket() {
s.enableMessage()

var err error
sp := s.BaseSuite.PickStorageProvider()
gvg, found := sp.GetFirstGlobalVirtualGroup()
Expand Down Expand Up @@ -358,8 +352,6 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_Bucket() {
// 6. the payment account set the rate limit to a positive number
// 7. user update the payment account to another payment account, it should pass
func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_BucketPaymentAccount() {
s.enableMessage()

var err error
sp := s.BaseSuite.PickStorageProvider()
gvg, found := sp.GetFirstGlobalVirtualGroup()
Expand Down Expand Up @@ -443,8 +435,6 @@ func (s *StorageTestSuite) TestNotOwnerSetBucketRateLimit_BucketPaymentAccount()
}

func (s *StorageTestSuite) TestQueryBucketRateLimit() {
s.enableMessage()

var err error
sp := s.BaseSuite.PickStorageProvider()
gvg, found := sp.GetFirstGlobalVirtualGroup()
Expand Down Expand Up @@ -489,8 +479,6 @@ func (s *StorageTestSuite) TestQueryBucketRateLimit() {
}

func (s *StorageTestSuite) TestSetBucketFlowRateLimit_Discontinue() {
s.enableMessage()

sp, user, bucketName, _, _, _ := s.createObjectWithNewGvg(storagetypes.VISIBILITY_TYPE_PRIVATE)

// SetBucketRateLimit
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.2.0
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 v1.5.1-0.20240314024318-a972393c0430
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.5.1-0.20240402031746-d46857cfafc0
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
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
Expand Down
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 v1.2.0 h1:LTStppZS9WkVj0TfEYKkk5OAQDGfY
github.com/bnb-chain/greenfield-cometbft v1.2.0/go.mod h1:WVOEZ59UYM2XePQH47/IQfcInspDn8wbRXhFSJrbU1c=
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 v1.5.1-0.20240314024318-a972393c0430 h1:Lerm4iJITbmJBOqRj/IPQhS8cvjTKOfuq3XOoDgjAtM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.5.1-0.20240314024318-a972393c0430/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
github.com/bnb-chain/greenfield-cosmos-sdk v1.5.1-0.20240402031746-d46857cfafc0 h1:Cm9EWuktgeyYotoL6ef0XpqB2ECjIzDwQxqFmgfPjTM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.5.1-0.20240402031746-d46857cfafc0/go.mod h1:XF8U3VN1euzLkIR5xiSNyQSnBabvnD86oz6fgdrpteQ=
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
2 changes: 1 addition & 1 deletion x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (k Keeper) doDeleteBucket(ctx sdk.Context, operator sdk.AccAddress, bucketI
}
}

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
// delete bucket flow rate limit status
k.deleteBucketFlowRateLimitStatus(ctx, bucketInfo.BucketName, bucketInfo.Id)
}
Expand Down
14 changes: 7 additions & 7 deletions x/storage/keeper/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (k Keeper) ChargeBucketReadFee(ctx sdk.Context, bucketInfo *storagetypes.Bu
return fmt.Errorf("charge bucket read fee failed, get bucket bill failed: %s %s", bucketInfo.BucketName, err.Error())
}

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
err := k.isBucketFlowRateUnderLimit(ctx, sdk.MustAccAddressFromHex(bucketInfo.PaymentAddress), sdk.MustAccAddressFromHex(bucketInfo.Owner), bucketInfo.BucketName, bill)
if err != nil {
return err
Expand All @@ -46,7 +46,7 @@ func (k Keeper) UnChargeBucketReadFee(ctx sdk.Context, bucketInfo *storagetypes.
return fmt.Errorf("unexpected total store charge size: %s, %d", bucketInfo.BucketName, internalBucketInfo.TotalChargeSize)
}

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
// if the bucket's flow rate limit is set to zero, no need to uncharge, since the bucket is already uncharged
if k.IsBucketRateLimited(ctx, bucketInfo.BucketName) {
return nil
Expand Down Expand Up @@ -145,7 +145,7 @@ func (k Keeper) lockObjectStoreFee(ctx sdk.Context, bucketInfo *storagetypes.Buc
})
}

if ctx.IsUpgraded(upgradetypes.Serengeti) && k.shouldCheckRateLimit(ctx, paymentAddr, sdk.MustAccAddressFromHex(bucketInfo.Owner), bucketInfo.BucketName) {
if ctx.IsUpgraded(upgradetypes.Erdos) && k.shouldCheckRateLimit(ctx, paymentAddr, sdk.MustAccAddressFromHex(bucketInfo.Owner), bucketInfo.BucketName) {
internalBucketInfo := k.MustGetInternalBucketInfo(ctx, bucketInfo.Id)
internalBucketInfo.PriceTime = timestamp
nextBill, err := k.GetBucketReadStoreBill(ctx, bucketInfo, internalBucketInfo)
Expand Down Expand Up @@ -346,7 +346,7 @@ func (k Keeper) ChargeViaBucketChange(ctx sdk.Context, bucketInfo *storagetypes.
return fmt.Errorf("get new bucket bill failed: %s %w", bucketInfo.BucketName, err)
}

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
isPreviousBucketLimited := k.IsBucketRateLimited(ctx, bucketInfo.BucketName)

if prevPaymentAccount == bucketInfo.PaymentAddress && isPreviousBucketLimited {
Expand Down Expand Up @@ -434,7 +434,7 @@ func (k Keeper) ChargeViaObjectChange(ctx sdk.Context, bucketInfo *storagetypes.
userFlows.Flows = append(userFlows.Flows, getNegFlows(preOutFlows)...)
userFlows.Flows = append(userFlows.Flows, newOutFlows...)

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
var shouldApplyFlowRate = true
forced, _ := ctx.Value(types.ForceUpdateStreamRecordKey).(bool)
if forced {
Expand Down Expand Up @@ -570,7 +570,7 @@ func (k Keeper) GetBucketReadStoreBill(ctx sdk.Context, bucketInfo *storagetypes
func (k Keeper) UnChargeBucketReadStoreFee(ctx sdk.Context, bucketInfo *storagetypes.BucketInfo,
internalBucketInfo *storagetypes.InternalBucketInfo) error {

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
// if the bucket's flow rate limit is set to zero, no need to uncharge, since the bucket is already uncharged
if k.IsBucketRateLimited(ctx, bucketInfo.BucketName) {
return nil
Expand All @@ -597,7 +597,7 @@ func (k Keeper) ChargeBucketReadStoreFee(ctx sdk.Context, bucketInfo *storagetyp
return fmt.Errorf("get bucket bill failed: %s %s", bucketInfo.BucketName, err.Error())
}

if ctx.IsUpgraded(upgradetypes.Serengeti) {
if ctx.IsUpgraded(upgradetypes.Erdos) {
err := k.isBucketFlowRateUnderLimit(ctx, sdk.MustAccAddressFromHex(bucketInfo.PaymentAddress), sdk.MustAccAddressFromHex(bucketInfo.Owner), bucketInfo.BucketName, bill)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/storage/keeper/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (k Keeper) VerifyPaymentAccount(ctx sdk.Context, paymentAddress string, own
}

// don't check if the payment account is owned by the owner account
if !ctx.IsUpgraded(upgradetypes.Serengeti) {
if !ctx.IsUpgraded(upgradetypes.Erdos) {
if !k.paymentKeeper.IsPaymentAccountOwner(ctx, paymentAcc, ownerAcc) {
return nil, paymenttypes.ErrNotPaymentAccountOwner
}
Expand Down

0 comments on commit 8c5e2f5

Please sign in to comment.