Skip to content

Commit

Permalink
feat: add hardfork logic
Browse files Browse the repository at this point in the history
  • Loading branch information
constwz committed Jul 11, 2024
1 parent f715552 commit d35a9ce
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 16 deletions.
17 changes: 17 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.
app.registerSerengetiUpgradeHandler()
app.registerErdosUpgradeHandler()
app.registerVeldUpgradeHandler()
app.registerMongolianUpgradeHandler()
// app.register...()
// ...
return nil
Expand Down Expand Up @@ -279,3 +280,19 @@ func (app *App) registerVeldUpgradeHandler() {
return nil
})
}

func (app *App) registerMongolianUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Mongolian,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Mongolian,
func() error {
app.Logger().Info("Init Veld 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 @@ -181,6 +181,7 @@ function generate_genesis() {
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
echo -e '[[upgrade]]\nname = "Veld"\nheight = 26\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Mongolian"\nheight = 27\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.3.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.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.8.1-0.20240711041516-7fd2f478ff35
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.3.0 h1:v3nZ16ledTZGF5Csys7fTQGZcEV78
github.com/bnb-chain/greenfield-cometbft v1.3.0/go.mod h1:0D+VPivZTeBldjtGGi9LKbBnKEO/RtMRJikie92LkYI=
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.8.0 h1:XaHBYnlAJNIEVTr9dXp3jzw12gCoIEL5jHiAMp+PX0s=
github.com/bnb-chain/greenfield-cosmos-sdk v1.8.0/go.mod h1:2bwmwdXYBISnQoMwgAcZTVGt21lMsHZSeeeMByTvDlQ=
github.com/bnb-chain/greenfield-cosmos-sdk v1.8.1-0.20240711041516-7fd2f478ff35 h1:9VZdnAqCBFCGzNxzV7jnxqSpUwIDwH7UcUMl1nfCEY4=
github.com/bnb-chain/greenfield-cosmos-sdk v1.8.1-0.20240711041516-7fd2f478ff35/go.mod h1:2bwmwdXYBISnQoMwgAcZTVGt21lMsHZSeeeMByTvDlQ=
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
3 changes: 2 additions & 1 deletion x/storage/keeper/cross_app_permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package keeper

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

types2 "github.com/bnb-chain/greenfield/types"
gnfderrors "github.com/bnb-chain/greenfield/types/errors"
gnfdresource "github.com/bnb-chain/greenfield/types/resource"
permtypes "github.com/bnb-chain/greenfield/x/permission/types"
"github.com/bnb-chain/greenfield/x/storage/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

var _ sdk.CrossChainApplication = &PermissionApp{}
Expand Down
62 changes: 50 additions & 12 deletions x/storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,13 @@ func (k Keeper) DeleteBucket(ctx sdk.Context, operator sdk.AccAddress, bucketNam
if !found {
return types.ErrNoSuchBucket
}
if bucketInfo.SourceType != types.SOURCE_TYPE_ORIGIN && bucketInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch

if bucketInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if bucketInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}

// check permission
Expand Down Expand Up @@ -417,6 +422,10 @@ func (k Keeper) UpdateBucketInfo(ctx sdk.Context, operator sdk.AccAddress, bucke
if !found {
return types.ErrNoSuchBucket
}
// check bucket source
if bucketInfo.SourceType != opts.SourceType && !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
}

if ctx.IsUpgraded(upgradetypes.Hulunbeier) {
sp := k.MustGetPrimarySPForBucket(ctx, bucketInfo)
Expand Down Expand Up @@ -983,6 +992,10 @@ func (k Keeper) CancelCreateObject(
return types.ErrObjectNotCreated.Wrapf("Object status: %s", objectInfo.ObjectStatus.String())
}

if objectInfo.SourceType != opts.SourceType && !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
}

var creator sdk.AccAddress
owner := sdk.MustAccAddressFromHex(objectInfo.Owner)
if objectInfo.Creator != "" {
Expand Down Expand Up @@ -1048,8 +1061,12 @@ func (k Keeper) DeleteObject(
objectInfo.ObjectName)
}

if objectInfo.SourceType != types.SOURCE_TYPE_ORIGIN && objectInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
if objectInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if objectInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}

if objectInfo.ObjectStatus == types.OBJECT_STATUS_CREATED {
Expand Down Expand Up @@ -1203,6 +1220,10 @@ func (k Keeper) CopyObject(
return sdkmath.ZeroUint(), errors.Wrapf(types.ErrNoSuchObject, "src object name (%s)", srcObjectName)
}

if srcObjectInfo.SourceType != opts.SourceType && !ctx.IsUpgraded(upgradetypes.Mongolian) {
return sdkmath.ZeroUint(), types.ErrSourceTypeMismatch
}

if srcObjectInfo.IsUpdating {
return sdkmath.ZeroUint(), types.ErrAccessDenied.Wrapf("the object is being updated, can not be copied")
}
Expand Down Expand Up @@ -1540,8 +1561,12 @@ func (k Keeper) DeleteGroup(ctx sdk.Context, operator sdk.AccAddress, groupName
if !found {
return types.ErrNoSuchGroup
}
if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN && groupInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
if groupInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}
// check permission
effect := k.VerifyGroupPermission(ctx, groupInfo, operator, permtypes.ACTION_DELETE_GROUP)
Expand Down Expand Up @@ -1576,8 +1601,13 @@ func (k Keeper) LeaveGroup(
if !found {
return types.ErrNoSuchGroup
}
if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN && groupInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch

if groupInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}

// Note: Delete group does not require the group is empty. The group member will be deleted by on-chain GC.
Expand All @@ -1598,8 +1628,12 @@ func (k Keeper) LeaveGroup(
}

func (k Keeper) UpdateGroupMember(ctx sdk.Context, operator sdk.AccAddress, groupInfo *types.GroupInfo, opts types.UpdateGroupMemberOptions) error {
if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN && groupInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
if groupInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}

// check permission
Expand Down Expand Up @@ -1653,8 +1687,12 @@ func (k Keeper) UpdateGroupMember(ctx sdk.Context, operator sdk.AccAddress, grou
}

func (k Keeper) RenewGroupMember(ctx sdk.Context, operator sdk.AccAddress, groupInfo *types.GroupInfo, opts types.RenewGroupMemberOptions) error {
if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN && groupInfo.SourceType != opts.SourceType {
return types.ErrSourceTypeMismatch
if groupInfo.SourceType != opts.SourceType {
if !ctx.IsUpgraded(upgradetypes.Mongolian) {
return types.ErrSourceTypeMismatch
} else if groupInfo.SourceType != types.SOURCE_TYPE_ORIGIN {
return types.ErrSourceTypeMismatch
}
}

// check permission
Expand Down

0 comments on commit d35a9ce

Please sign in to comment.