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

feat: group member expiration #374

Merged
merged 22 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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 .github/workflows/buf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ on:

jobs:
protobuf-check:
strategy:
matrix:
go-version: [1.20.x]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -26,6 +29,7 @@ jobs:
- name: Test protobuf changes generates new go files
run: |
export PATH="$PATH:$(go env GOPATH)/bin"
go mod tidy
make tools proto-gen-check
- name: Test protobuf swagger changes
run: |
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ format:
tools:
go install github.com/cosmos/gogoproto/protoc-gen-gocosmos
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install github.com/golang/mock/mockgen

proto-gen:
cd proto && buf generate && cp -r github.com/bnb-chain/greenfield/x/* ../x && cp -r github.com/bnb-chain/greenfield/types/* ../types && rm -rf github.com && go mod tidy
Expand Down
23 changes: 20 additions & 3 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.

// Register the upgrade handlers here
// app.registerPublicDelegationUpgradeHandler()
// app.register...()
// ...
// app.registerNagquUpgradeHandler()

return nil
}

// registerPublicDelegationUpgradeHandler registers the upgrade handlers for the public delegation upgrade.
// it will be enabled at the future version.
// func (app *App) registerPublicDelegationUpgradeHandler() {
// // Register the upgrade handler
// app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.EnablePublicDelegationUpgrade,
Expand All @@ -36,3 +35,21 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.
// },
// )
// }

// registerNagquUpgradeHandler registers the upgrade handlers for Nagqu.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove these useless code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

// func (app *App) registerNagquUpgradeHandler() {
// // Register the upgrade handler
// app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Nagqu,
// func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// app.Logger().Info("processing upgrade handler", "name", plan.Name, "info", plan.Info)
// return fromVM, nil
// })

// // Register the upgrade initializer
// app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Nagqu,
// func() error {
// app.Logger().Info("processing upgrade initializer", "name", upgradetypes.Nagqu)
// return nil
// },
// )
// }
16 changes: 16 additions & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ function generate_sp_genesis {
${bin} collect-spgentxs --gentx-dir ${workspace}/.local/validator0/config/gensptx --home ${workspace}/.local/validator0
}

function export_validator {
size=$1

for ((i = 0; i < ${size}; i++)); do
bls_priv_key=("$(echo "y" | ${bin} keys export validator_bls${i} --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/validator${i})")
relayer_key=("$(echo "y" | ${bin} keys export relayer${i} --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/relayer${i})")

echo "validator_bls${i} bls_priv_key: ${bls_priv_key}"
echo "relayer${i} relayer_key: ${relayer_key}"
done
}

function export_sps {
size=$1
sp_size=1
Expand Down Expand Up @@ -312,6 +324,10 @@ generate)
export_sps)
export_sps $SIZE $SP_SIZE
;;

export_validator)
export_validator $SIZE
;;
start)
echo "===== start ===="
start $SIZE
Expand Down
11 changes: 11 additions & 0 deletions deployment/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ bash ./deployment/localup/localup.sh stop

3. Send Tx
```bash
VALIDATOR=$(./build/bin/gnfd keys show validator0 -a --home ./deployment/localup/.local/validator0 --keyring-backend test)
GROUP_NAME="admin2"

./build/bin/gnfd tx storage create-group $GROUP_NAME --from validator0 --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b sync

./build/bin/gnfd tx storage update-group-member $GROUP_NAME "0xfABDd8b607201667fE54054CB4AD9068Afa2993e,0xba8dde27ddc0f39041a1d9a4efd24b5b5d81fe17" "1691118864,2691118864" "" --from validator0 --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b sync
./build/bin/gnfd tx storage renew-group-member $GROUP_NAME 0xfABDd8b607201667fE54054CB4AD9068Afa2993e 1791118864 --from validator0 --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b sync

./build/bin/gnfd q storage head-group-member $VALIDATOR $GROUP_NAME 0xfABDd8b607201667fE54054CB4AD9068Afa2993e --node http://localhost:26750
./build/bin/gnfd q storage head-group-member $VALIDATOR $GROUP_NAME 0xba8dde27ddc0f39041a1d9a4efd24b5b5d81fe17 --node http://localhost:26750

./build/bin/gnfd tx bank send validator0 0x32Ff14Fa1547314b95991976DB432F9Aa648A423 500000000000000000000BNB --home ./deployment/localup/.local/validator0 --keyring-backend test --node http://localhost:26750 -b sync
```

Expand Down
22 changes: 11 additions & 11 deletions e2e/tests/permission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,15 @@ func (s *StorageTestSuite) TestGrantsPermissionToGroup() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(user[0].GetAddr(), testGroupName, []sdk.AccAddress{user[1].GetAddr()}, "")
msgCreateGroup := storagetypes.NewMsgCreateGroup(user[0].GetAddr(), testGroupName, "")
s.SendTxBlock(user[0], msgCreateGroup)

membersToAdd := []*storagetypes.MsgGroupMember{
{Member: user[1].GetAddr().String(), ExpirationTime: storagetypes.MaxTimeStamp}}
membersToDelete := []sdk.AccAddress{}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(user[0].GetAddr(), user[0].GetAddr(), testGroupName, membersToAdd, membersToDelete)
s.SendTxBlock(user[0], msgUpdateGroupMember)

// Head Group
headGroupRequest := storagetypes.QueryHeadGroupRequest{GroupOwner: user[0].GetAddr().String(), GroupName: testGroupName}
headGroupResponse, err := s.Client.HeadGroup(ctx, &headGroupRequest)
Expand Down Expand Up @@ -1168,9 +1174,7 @@ func (s *StorageTestSuite) TestDeleteGroupPolicy() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName,
[]sdk.AccAddress{user[1].GetAddr(), user[2].GetAddr(), user[3].GetAddr()},
"")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, "")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1219,7 +1223,7 @@ func (s *StorageTestSuite) TestStalePermissionForGroupGC() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, []sdk.AccAddress{user[0].GetAddr(), user[1].GetAddr(), user[2].GetAddr()}, "")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, "")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1316,9 +1320,7 @@ func (s *StorageTestSuite) TestGroupMembersAndPolicyGC() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName,
[]sdk.AccAddress{user[1].GetAddr(), user[2].GetAddr(), user[3].GetAddr()},
"")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, "")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1489,9 +1491,7 @@ func (s *StorageTestSuite) TestUpdateGroupExtraWithPermission() {

// Create Group
testGroupName := "testGroup"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName,
[]sdk.AccAddress{user[1].GetAddr(), user[2].GetAddr(), user[3].GetAddr()},
"")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, "")
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down
97 changes: 71 additions & 26 deletions e2e/tests/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (s *StorageTestSuite) TestCreateGroup() {
groupName := storageutils.GenRandomGroupName()

// 1. CreateGroup
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, "")
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), groupName)

Expand All @@ -300,7 +300,14 @@ func (s *StorageTestSuite) TestCreateGroup() {
s.Require().NoError(err)
s.Require().GreaterOrEqual(len(queryListGroupResp.GroupInfos), 1)

// 3. HeadGroupMember
// 4. UpdateGroupMember(add)
membersToAdd := []*storagetypes.MsgGroupMember{
{Member: member.GetAddr().String(), ExpirationTime: storagetypes.MaxTimeStamp}}
membersToDelete := []sdk.AccAddress{}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
s.SendTxBlock(owner, msgUpdateGroupMember)

// 4-1. HeadGroupMember(add)
queryHeadGroupMemberReq := storagetypes.QueryHeadGroupMemberRequest{
Member: member.GetAddr().String(),
GroupName: groupName,
Expand All @@ -310,33 +317,25 @@ func (s *StorageTestSuite) TestCreateGroup() {
s.Require().NoError(err)
s.Require().Equal(queryHeadGroupMemberResp.GroupMember.GroupId, queryHeadGroupResp.GroupInfo.Id)

// 4. UpdateGroupMember
// 5. UpdateGroupMember(delete)
member2 := s.GenAndChargeAccounts(1, 1000000)[0]
membersToAdd := []sdk.AccAddress{member2.GetAddr()}
membersToDelete := []sdk.AccAddress{member.GetAddr()}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
membersToAdd = []*storagetypes.MsgGroupMember{
{Member: member2.GetAddr().String(), ExpirationTime: storagetypes.MaxTimeStamp}}
membersToDelete = []sdk.AccAddress{member.GetAddr()}
msgUpdateGroupMember = storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
s.SendTxBlock(owner, msgUpdateGroupMember)

// 5. HeadGroupMember (delete)
// 5-1. HeadGroupMember (delete)
queryHeadGroupMemberReqDelete := storagetypes.QueryHeadGroupMemberRequest{
Member: member.GetAddr().String(),
GroupName: groupName,
GroupOwner: owner.GetAddr().String(),
}
_, err = s.Client.HeadGroupMember(ctx, &queryHeadGroupMemberReqDelete)
s.Require().True(strings.Contains(err.Error(), storagetypes.ErrNoSuchGroupMember.Error()))
// 5. HeadGroupMember (add)
queryHeadGroupMemberReqAdd := storagetypes.QueryHeadGroupMemberRequest{
Member: member2.GetAddr().String(),
GroupName: groupName,
GroupOwner: owner.GetAddr().String(),
}
queryHeadGroupMemberRespAdd, err := s.Client.HeadGroupMember(ctx, &queryHeadGroupMemberReqAdd)
s.Require().NoError(err)
s.Require().Equal(queryHeadGroupMemberRespAdd.GroupMember.GroupId, queryHeadGroupResp.GroupInfo.Id)

// 6. Create a group with the same name
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, "")
s.SendTxBlockWithExpectErrorString(msgCreateGroup, owner, "exists")
}

Expand All @@ -348,9 +347,14 @@ func (s *StorageTestSuite) TestLeaveGroup() {
groupName := storageutils.GenRandomGroupName()

// 1. CreateGroup
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, "")
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), groupName)
membersToAdd := []*storagetypes.MsgGroupMember{
{Member: member.GetAddr().String(), ExpirationTime: storagetypes.MaxTimeStamp}}
membersToDelete := []sdk.AccAddress{}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
s.SendTxBlock(owner, msgUpdateGroupMember)

// 2. HeadGroup
queryHeadGroupReq := storagetypes.QueryHeadGroupRequest{GroupOwner: owner.GetAddr().String(), GroupName: groupName}
Expand Down Expand Up @@ -384,9 +388,10 @@ func (s *StorageTestSuite) TestLeaveGroup() {

// 4. UpdateGroupMember
member2 := s.GenAndChargeAccounts(1, 1000000)[0]
membersToAdd := []sdk.AccAddress{member2.GetAddr()}
membersToDelete := []sdk.AccAddress{member.GetAddr()}
msgUpdateGroupMember := storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
membersToAdd = []*storagetypes.MsgGroupMember{
{Member: member2.GetAddr().String(), ExpirationTime: storagetypes.MaxTimeStamp}}
membersToDelete = []sdk.AccAddress{member.GetAddr()}
msgUpdateGroupMember = storagetypes.NewMsgUpdateGroupMember(owner.GetAddr(), owner.GetAddr(), groupName, membersToAdd, membersToDelete)
s.SendTxBlock(owner, msgUpdateGroupMember)

// 5. leave group
Expand Down Expand Up @@ -692,11 +697,10 @@ func (s *StorageTestSuite) TestMirrorGroup() {
ctx := context.Background()

owner := s.GenAndChargeAccounts(1, 1000000)[0]
member := s.GenAndChargeAccounts(1, 1000000)[0]
groupName := storageutils.GenRandomGroupName()

// 1. CreateGroup
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, "")
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), groupName)

Expand All @@ -713,7 +717,7 @@ func (s *StorageTestSuite) TestMirrorGroup() {

// CreateGroup
groupName = storageutils.GenRandomGroupName()
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, []sdk.AccAddress{member.GetAddr()}, "")
msgCreateGroup = storagetypes.NewMsgCreateGroup(owner.GetAddr(), groupName, "")
s.SendTxBlock(owner, msgCreateGroup)

// MirrorGroup using name
Expand Down Expand Up @@ -1488,10 +1492,10 @@ func (s *StorageTestSuite) TestCreateAndUpdateGroupExtraField() {
ctx := context.Background()
owner := s.GenAndChargeAccounts(1, 1000000)[0]

// Create a group without members
// Create a group
testGroupName := "appName/bucketName"
extra := "{\"description\":\"no description\",\"imageUrl\":\"www.images.com/image1\"}"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, nil, extra)
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, extra)
s.SendTxBlock(owner, msgCreateGroup)

// Head Group
Expand Down Expand Up @@ -1532,6 +1536,47 @@ func (s *StorageTestSuite) TestCreateAndUpdateGroupExtraField() {
s.T().Logf("GroupInfo: %s", headGroupResponse.GetGroupInfo().String())
}

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

// Create a group
testGroupName := "appName/bucketName"
extra := "{\"description\":\"no description\",\"imageUrl\":\"www.images.com/image1\"}"
msgCreateGroup := storagetypes.NewMsgCreateGroup(owner.GetAddr(), testGroupName, extra)
s.SendTxBlock(owner, msgCreateGroup)
s.T().Logf("CerateGroup success, owner: %s, group name: %s", owner.GetAddr().String(), testGroupName)

// 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.Require().Equal(headGroupResponse.GroupInfo.Extra, extra)

// Renew GroupMember
expiration, err := time.Parse(time.RFC3339, "2022-12-31T23:59:59Z")
s.Require().NoError(err)
members := []*storagetypes.MsgGroupMember{
{Member: member.GetAddr().String(), ExpirationTime: expiration}}
msgUpdateGroupMember := storagetypes.NewMsgRenewGroupMember(owner.GetAddr(), owner.GetAddr(), testGroupName, members)
s.SendTxBlock(owner, msgUpdateGroupMember)

// Head GroupMember
queryHeadGroupMemberReq := storagetypes.QueryHeadGroupMemberRequest{
Member: member.GetAddr().String(),
GroupName: testGroupName,
GroupOwner: owner.GetAddr().String(),
}
queryHeadGroupMemberResp, err := s.Client.HeadGroupMember(ctx, &queryHeadGroupMemberReq)
s.Require().NoError(err)
s.Require().Equal(queryHeadGroupMemberResp.GroupMember.GroupId, headGroupResponse.GroupInfo.Id)
s.Require().True(queryHeadGroupMemberResp.GroupMember.ExpirationTime.Equal(expiration))
}

func (s *StorageTestSuite) TestRejectSealObject() {
var err error
// CreateBucket
Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,13 @@ require (
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.10.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
nhooyr.io/websocket v1.8.6 // indirect
Expand All @@ -176,7 +177,7 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v0.0.2-alpha.2
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 v0.2.3-alpha.3.0.20230803020148-9216a6aea390
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20230807083232-9a0d3b09e97f
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1-alpha.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Loading