Skip to content

Commit

Permalink
Merge pull request #517 from bnb-chain/develop
Browse files Browse the repository at this point in the history
release: prepare release for v1.1.0
  • Loading branch information
unclezoro authored Nov 2, 2023
2 parents 7c07254 + 12abbd9 commit 23e0d01
Show file tree
Hide file tree
Showing 39 changed files with 2,012 additions and 458 deletions.
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ add an example CLI or API response...
Notable changes:
* add each change in a bullet point here
* ...

### Potential Impacts
* add potential impacts for other components here
* ...
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Changelog

## v1.1.0
This release contains 2 new features, 3 bugfixes and 6 chores.

Features:
* [#493](https://github.com/bnb-chain/greenfield/pull/493) feat: support reject bucket migration
* [#504](https://github.com/bnb-chain/greenfield/pull/504) feat: add a hardfork for the link to opBNB

Bugfixes:
* [#506](https://github.com/bnb-chain/greenfield/pull/506) fix: add GlobalVirtualGroupFamilyId to createBucketPackage
* [#509](https://github.com/bnb-chain/greenfield/pull/509) fix: make handleCreateBucketSynPackage forward compatible
* [#511](https://github.com/bnb-chain/greenfield/pull/511) fix: policy key is not GC while a expired policy is GC

Chores:
* [#484](https://github.com/bnb-chain/greenfield/pull/484) chore: improve the validations of messages
* [#497](https://github.com/bnb-chain/greenfield/pull/497) chore: add cmd
* [#503](https://github.com/bnb-chain/greenfield/pull/503) chore: add potential impacts for PR template
* [#508](https://github.com/bnb-chain/greenfield/pull/508) chore: update cosmos-sdk version
* [#512](https://github.com/bnb-chain/greenfield/pull/512) chore: allow anyone to trigger the settlement of GVG/GVG family
* [#514](https://github.com/bnb-chain/greenfield/pull/514) chore: update cosmos-sdk and cometbft

## v1.0.1
This release contains 2 chores.

Expand Down
5 changes: 5 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type CrossChainConfig struct {
SrcChainId uint32 `mapstructure:"src-chain-id"`

DestBscChainId uint32 `mapstructure:"dest-bsc-chain-id"`

DestOpChainId uint32 `mapstructure:"dest-op-chain-id"`
}

var CustomAppTemplate = serverconfig.DefaultConfigTemplate + `
Expand All @@ -25,6 +27,8 @@ var CustomAppTemplate = serverconfig.DefaultConfigTemplate + `
src-chain-id = {{ .CrossChain.SrcChainId }}
# chain-id for bsc destination chain
dest-bsc-chain-id = {{ .CrossChain.DestBscChainId }}
# chain-id for op bnb destination chain
dest-op-chain-id = {{ .CrossChain.DestOpChainId }}
`

func NewDefaultAppConfig() *AppConfig {
Expand All @@ -48,6 +52,7 @@ func NewDefaultAppConfig() *AppConfig {
CrossChain: CrossChainConfig{
SrcChainId: 1,
DestBscChainId: 2,
DestOpChainId: 3,
},
}
}
32 changes: 32 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import (
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/gashub/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

bridgemoduletypes "github.com/bnb-chain/greenfield/x/bridge/types"
paymentmodule "github.com/bnb-chain/greenfield/x/payment"
paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"
storagemoduletypes "github.com/bnb-chain/greenfield/x/storage/types"
)

func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.Config) error {
Expand All @@ -19,6 +22,7 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.

// Register the upgrade handlers here
app.registerNagquUpgradeHandler()
app.registerPampasUpgradeHandler()
// app.register...()
// ...
return nil
Expand Down Expand Up @@ -61,6 +65,34 @@ func (app *App) registerNagquUpgradeHandler() {
}
mm.SetConsensusVersion(2)
return nil
})
}

func (app *App) registerPampasUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Pampas,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)

// open resource channels for opbnb
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), bridgemoduletypes.SyncParamsChannelID, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.BucketChannelId, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.ObjectChannelId, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.GroupChannelId, sdk.ChannelAllow)

// register MsgRejectMigrateBucket Gas param
app.GashubKeeper.SetMsgGasParams(ctx, *types.NewMsgGasParamsWithFixedGas("/greenfield.storage.MsgRejectMigrateBucket", 1.2e3))

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Pampas,
func() error {
app.Logger().Info("Init Pampas upgrade")

// enable chain id for opbnb
app.CrossChainKeeper.SetDestOpChainID(sdk.ChainID(app.appConfig.CrossChain.DestOpChainId))
return nil
})
}
1 change: 1 addition & 0 deletions deployment/localup/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SP_MIN_DEPOSIT_AMOUNT=10000000000000000000000000
## CROSS CHAIN
SRC_CHAIN_ID=18
DEST_CHAIN_ID=714
DEST_OP_CHAIN_ID=2320

## Proposal
PROPOSAL_ID_START=1
Expand Down
2 changes: 2 additions & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function generate_genesis() {
sed -i -e "s/snapshot-interval = 0/snapshot-interval = ${SNAPSHOT_INTERVAL}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/src-chain-id = 1/src-chain-id = ${SRC_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-bsc-chain-id = 2/dest-bsc-chain-id = ${DEST_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-op-chain-id = 3/dest-op-chain-id = ${DEST_OP_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/snapshot-keep-recent = 2/snapshot-keep-recent = ${SNAPSHOT_KEEP_RECENT}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/\"reserve_time\": \"15552000\"/\"reserve_time\": \"60\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"forced_settle_time\": \"86400\"/\"forced_settle_time\": \"30\"/g" ${workspace}/.local/validator${i}/config/genesis.json
Expand All @@ -171,6 +172,7 @@ function generate_genesis() {
#sed -i -e "s/\"community_tax\": \"0.020000000000000000\"/\"community_tax\": \"0\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/log_level = \"info\"/\log_level= \"debug\"/g" ${workspace}/.local/validator${i}/config/config.toml
echo -e '[[upgrade]]\nname = "Nagqu"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Pampas"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
17 changes: 4 additions & 13 deletions e2e/tests/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,27 +1147,18 @@ func (s *PaymentTestSuite) TestVirtualGroup_Settle() {

// settle gvg family
msgSettle := virtualgrouptypes.MsgSettle{
StorageProvider: sp.FundingKey.GetAddr().String(),
StorageProvider: user.GetAddr().String(),
GlobalVirtualGroupFamilyId: family.Id,
}
s.SendTxBlock(sp.FundingKey, &msgSettle)
s.SendTxBlock(user, &msgSettle)

// settle gvg
var secondarySp *core.StorageProvider
for _, sp := range s.StorageProviders {
for _, id := range gvg.SecondarySpIds {
if sp.Info.Id == id {
secondarySp = sp
break
}
}
}
msgSettle = virtualgrouptypes.MsgSettle{
StorageProvider: secondarySp.FundingKey.GetAddr().String(),
StorageProvider: user.GetAddr().String(),
GlobalVirtualGroupFamilyId: 0,
GlobalVirtualGroupIds: []uint32{gvg.Id},
}
s.SendTxBlock(secondarySp.FundingKey, &msgSettle)
s.SendTxBlock(user, &msgSettle)

// assertions - balance has been checked in other tests in virtual group
streamRecordsAfter := s.getStreamRecords(streamAddresses)
Expand Down
133 changes: 130 additions & 3 deletions e2e/tests/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,18 @@ func (s *StorageTestSuite) TestCreateObjectByOthers() {
s.Require().Equal(verifyPermResp.Effect, types.EFFECT_DENY)
s.T().Logf("resp: %s, rep %s", verifyPermReq.String(), verifyPermResp.String())

// Put bucket policy
statement := &types.Statement{
// Put object policy
statement1 := &types.Statement{
Actions: []types.ActionType{types.ACTION_CREATE_OBJECT},
Effect: types.EFFECT_ALLOW,
}
statement2 := &types.Statement{
Actions: []types.ActionType{types.ACTION_UPDATE_OBJECT_INFO},
Effect: types.EFFECT_ALLOW,
}
principal := types.NewPrincipalWithAccount(user[1].GetAddr())
msgPutPolicy := storagetypes.NewMsgPutPolicy(user[0].GetAddr(), types2.NewBucketGRN(bucketName).String(),
principal, []*types.Statement{statement}, nil)
principal, []*types.Statement{statement1, statement2}, nil)
s.SendTxBlock(user[0], msgPutPolicy)

// verify permission
Expand Down Expand Up @@ -1906,3 +1910,126 @@ func (s *StorageTestSuite) TestGrantsPermissionToObjectWithWildcardInName() {
_, err := s.Client.HeadObject(context.Background(), &storagetypes.QueryHeadObjectRequest{BucketName: bucketName, ObjectName: objectName})
s.Require().True(strings.Contains(err.Error(), "No such object"))
}

func (s *StorageTestSuite) TestExpiredAccountPolicyGCAndRePut() {
var err error
ctx := context.Background()
user1 := s.GenAndChargeAccounts(1, 1000000)[0]

_, owner, bucketName, bucketId, _, _ := s.createObjectWithVisibility(storagetypes.VISIBILITY_TYPE_PUBLIC_READ)

principal := types.NewPrincipalWithAccount(user1.GetAddr())

// Put bucket policy
bucketStatement := &types.Statement{
Actions: []types.ActionType{types.ACTION_DELETE_BUCKET},
Effect: types.EFFECT_ALLOW,
}
expirationTime := time.Now().Add(5 * time.Second)

msgPutBucketPolicy := storagetypes.NewMsgPutPolicy(owner.GetAddr(), types2.NewBucketGRN(bucketName).String(),
principal, []*types.Statement{bucketStatement}, &expirationTime)
s.SendTxBlock(owner, msgPutBucketPolicy)

// Query the policy which is enforced on bucket
grn1 := types2.NewBucketGRN(bucketName)
queryPolicyForAccountResp, err := s.Client.QueryPolicyForAccount(ctx, &storagetypes.QueryPolicyForAccountRequest{
Resource: grn1.String(),
PrincipalAddress: user1.GetAddr().String(),
})
s.Require().NoError(err)
s.Require().Equal(bucketId, queryPolicyForAccountResp.Policy.ResourceId)

// wait for policy expired
time.Sleep(5 * time.Second)

// query the policy, which is already GC, should get err.
_, err = s.Client.QueryPolicyForAccount(ctx, &storagetypes.QueryPolicyForAccountRequest{
Resource: grn1.String(),
PrincipalAddress: user1.GetAddr().String(),
})
s.Require().Error(err)

// the user should be able to re-put policy for the bucket.
msgPutBucketPolicy = storagetypes.NewMsgPutPolicy(owner.GetAddr(), types2.NewBucketGRN(bucketName).String(),
principal, []*types.Statement{bucketStatement}, nil)
s.SendTxBlock(owner, msgPutBucketPolicy)

// Query the policy which is enforced on bucket.
queryPolicyForAccountResp, err = s.Client.QueryPolicyForAccount(ctx, &storagetypes.QueryPolicyForAccountRequest{
Resource: grn1.String(),
PrincipalAddress: user1.GetAddr().String(),
})
s.Require().NoError(err)
s.Require().Equal(bucketId, queryPolicyForAccountResp.Policy.ResourceId)
}

func (s *StorageTestSuite) TestExpiredGroupPolicyGCAndRePut() {
ctx := context.Background()
user := s.GenAndChargeAccounts(3, 10000)
_, owner, bucketName, bucketId, _, _ := s.createObjectWithVisibility(storagetypes.VISIBILITY_TYPE_PUBLIC_READ)

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, "")
s.SendTxBlock(owner, msgCreateGroup)
membersToAdd := []*storagetypes.MsgGroupMember{
{Member: user[1].GetAddr().String()},
}
membersToDelete := []sdk.AccAddress{}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), testGroupName, membersToAdd, membersToDelete)
s.SendTxBlock(owner, msgUpdateGroupMember)

// Head Group
headGroupRequest := storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err := s.Client.HeadGroup(ctx, &headGroupRequest)
s.Require().NoError(err)
s.Require().Equal(headGroupResponse.GroupInfo.GroupName, testGroupName)
s.Require().True(owner.GetAddr().Equals(sdk.MustAccAddressFromHex(headGroupResponse.GroupInfo.Owner)))
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())

principal := types.NewPrincipalWithGroupId(headGroupResponse.GroupInfo.Id)
// Put bucket policy for group
expirationTime := time.Now().Add(5 * time.Second)

bucketStatement := &types.Statement{
Actions: []types.ActionType{types.ACTION_DELETE_BUCKET},
Effect: types.EFFECT_ALLOW,
}
msgPutBucketPolicy := storagetypes.NewMsgPutPolicy(owner.GetAddr(), types2.NewBucketGRN(bucketName).String(),
principal, []*types.Statement{bucketStatement}, &expirationTime)
s.SendTxBlock(owner, msgPutBucketPolicy)

// Query bucket policy for group
grn := types2.NewBucketGRN(bucketName)
queryPolicyForGroupReq := storagetypes.QueryPolicyForGroupRequest{
Resource: grn.String(),
PrincipalGroupId: headGroupResponse.GroupInfo.Id.String(),
}

queryPolicyForGroupResp, err := s.Client.QueryPolicyForGroup(ctx, &queryPolicyForGroupReq)
s.Require().NoError(err)
s.Require().Equal(bucketId, queryPolicyForGroupResp.Policy.ResourceId)
s.Require().Equal(queryPolicyForGroupResp.Policy.ResourceType, resource.RESOURCE_TYPE_BUCKET)
s.Require().Equal(types.EFFECT_ALLOW, queryPolicyForGroupResp.Policy.Statements[0].Effect)
bucketPolicyId := queryPolicyForGroupResp.Policy.Id

// wait for policy expired
time.Sleep(5 * time.Second)

// policy is GC
_, err = s.Client.QueryPolicyById(ctx, &storagetypes.QueryPolicyByIdRequest{PolicyId: bucketPolicyId.String()})
s.Require().Error(err)
s.Require().ErrorContains(err, "No such Policy")

// the user should be able to re-put policy for the bucket.
msgPutBucketPolicy = storagetypes.NewMsgPutPolicy(owner.GetAddr(), types2.NewBucketGRN(bucketName).String(),
principal, []*types.Statement{bucketStatement}, nil)
s.SendTxBlock(owner, msgPutBucketPolicy)

queryPolicyForGroupResp, err = s.Client.QueryPolicyForGroup(ctx, &queryPolicyForGroupReq)
s.Require().NoError(err)
s.Require().Equal(bucketId, queryPolicyForGroupResp.Policy.ResourceId)
s.Require().Equal(queryPolicyForGroupResp.Policy.ResourceType, resource.RESOURCE_TYPE_BUCKET)
s.Require().Equal(types.EFFECT_ALLOW, queryPolicyForGroupResp.Policy.Statements[0].Effect)
}
64 changes: 64 additions & 0 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,3 +2010,67 @@ func (s *StorageTestSuite) TestMaintenanceSPCreateBucketAndObject() {
s.Require().NoError(err)
s.Require().Equal(sptypes.STATUS_IN_SERVICE, spResp.StorageProvider.Status)
}

func (s *StorageTestSuite) TestRejectMigrateBucket() {
// construct bucket and object
primarySP := s.BaseSuite.PickStorageProvider()
gvg, found := primarySP.GetFirstGlobalVirtualGroup()
s.Require().True(found)
user := s.GenAndChargeAccounts(1, 1000000)[0]
bucketName := storageutils.GenRandomBucketName()
objectName := storageutils.GenRandomObjectName()
s.BaseSuite.CreateObject(user, primarySP, gvg.Id, bucketName, objectName)

var err error
dstPrimarySP := s.CreateNewStorageProvider()

// migrate bucket
msgMigrationBucket := storagetypes.NewMsgMigrateBucket(user.GetAddr(), bucketName, dstPrimarySP.Info.Id)
msgMigrationBucket.DstPrimarySpApproval.ExpiredHeight = math.MaxInt
msgMigrationBucket.DstPrimarySpApproval.Sig, err = dstPrimarySP.ApprovalKey.Sign(msgMigrationBucket.GetApprovalBytes())
s.SendTxBlock(user, msgMigrationBucket)
s.Require().NoError(err)

ctx := context.Background()
queryHeadBucketRequest := storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err := s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketName, bucketName)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_MIGRATING)

// Dest SP reject the migration
rejectMigration := storagetypes.NewMsgRejectMigrateBucket(dstPrimarySP.OperatorKey.GetAddr(), bucketName)
s.SendTxBlock(dstPrimarySP.OperatorKey, rejectMigration)
s.Require().NoError(err)

queryHeadBucketRequest = storagetypes.QueryHeadBucketRequest{
BucketName: bucketName,
}
queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED)

// migrate bucket again
msgMigrationBucket = storagetypes.NewMsgMigrateBucket(user.GetAddr(), bucketName, dstPrimarySP.Info.Id)
msgMigrationBucket.DstPrimarySpApproval.ExpiredHeight = math.MaxInt
msgMigrationBucket.DstPrimarySpApproval.Sig, err = dstPrimarySP.ApprovalKey.Sign(msgMigrationBucket.GetApprovalBytes())
s.SendTxBlock(user, msgMigrationBucket)
s.Require().NoError(err)

// cancel migration by user
msgCancelMigrationBucket := storagetypes.NewMsgCancelMigrateBucket(user.GetAddr(), bucketName)
s.SendTxBlock(user, msgCancelMigrationBucket)
s.Require().NoError(err)

queryHeadBucketResponse, err = s.Client.HeadBucket(ctx, &queryHeadBucketRequest)
s.Require().NoError(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED)

// dest SP should fail to reject
s.Client.SetKeyManager(dstPrimarySP.OperatorKey)
_, err = s.Client.BroadcastTx(context.Background(), []sdk.Msg{rejectMigration}, nil)
s.Require().Error(err)
s.Require().Equal(queryHeadBucketResponse.BucketInfo.BucketStatus, storagetypes.BUCKET_STATUS_CREATED)
}
Loading

0 comments on commit 23e0d01

Please sign in to comment.