From d0acd1923673b40045a0df098a1a32e5cf6fcb15 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Thu, 3 Aug 2023 18:51:34 +0800 Subject: [PATCH 1/7] add maintenance mode for sp --- sdk/client/tx_test.go | 20 +++++ x/challenge/abci.go | 2 +- x/challenge/keeper/msg_server_submit.go | 2 +- x/sp/keeper/sp.go | 17 +++++ x/sp/keeper/sp_maintenance.go | 99 +++++++++++++++++++++++++ x/storage/keeper/virtualgroup.go | 4 + 6 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 x/sp/keeper/sp_maintenance.go diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index 254ce61b3..8f593a22c 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -195,3 +197,21 @@ func TestSendTXViaWebsocketClient(t *testing.T) { assert.Equal(t, uint32(0), response.TxResponse.Code) } } + +func TestSpTXViaWebsocketClient(t *testing.T) { + km, err := keys.NewPrivateKeyManager("9fd8cc7d9a6cdc12c299825a1ff8f27aebef2ec0e00c3fe4d1201daa7cbba3f2") + assert.NoError(t, err) + gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) + assert.NoError(t, err) + km.GetAddr() + + msg := &sptypes.MsgUpdateStorageProviderStatus{ + SpAddress: km.GetAddr().String(), + Status: sptypes.STATUS_IN_SERVICE, + MaintenanceDuration: 0, + } + response, err := gnfdCli.BroadcastTx(context.Background(), []sdk.Msg{msg}, nil) + assert.NoError(t, err) + assert.Equal(t, uint32(0), response.TxResponse.Code) + t.Log(response.TxResponse) +} diff --git a/x/challenge/abci.go b/x/challenge/abci.go index 0334c4121..1eeb97bb3 100644 --- a/x/challenge/abci.go +++ b/x/challenge/abci.go @@ -89,7 +89,7 @@ func EndBlocker(ctx sdk.Context, keeper k.Keeper) { if !found { continue } - if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING { + if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING && sp.Status != sptypes.STATUS_IN_MAINTENANCE { continue } diff --git a/x/challenge/keeper/msg_server_submit.go b/x/challenge/keeper/msg_server_submit.go index 49f92c669..38fd0a3d3 100644 --- a/x/challenge/keeper/msg_server_submit.go +++ b/x/challenge/keeper/msg_server_submit.go @@ -24,7 +24,7 @@ func (k msgServer) Submit(goCtx context.Context, msg *types.MsgSubmit) (*types.M return nil, types.ErrUnknownBucketObject } sp := k.StorageKeeper.MustGetPrimarySPForBucket(ctx, bucketInfo) - if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING { + if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING && sp.Status != sptypes.STATUS_IN_MAINTENANCE { return nil, types.ErrInvalidSpStatus } diff --git a/x/sp/keeper/sp.go b/x/sp/keeper/sp.go index e79321964..032a17120 100644 --- a/x/sp/keeper/sp.go +++ b/x/sp/keeper/sp.go @@ -82,6 +82,17 @@ func (k Keeper) GetStorageProviderByGcAddr(ctx sdk.Context, gcAddr sdk.AccAddres return k.GetStorageProvider(ctx, k.spSequence.DecodeSequence(id)) } +func (k Keeper) GetStorageProviderByTestAddr(ctx sdk.Context, testAddr sdk.AccAddress) (sp *types.StorageProvider, found bool) { + store := ctx.KVStore(k.storeKey) + + id := store.Get(types.GetStorageProviderByTestAddrKey(testAddr)) + if id == nil { + return sp, false + } + + return k.GetStorageProvider(ctx, k.spSequence.DecodeSequence(id)) +} + func (k Keeper) SetStorageProvider(ctx sdk.Context, sp *types.StorageProvider) { store := ctx.KVStore(k.storeKey) bz := types.MustMarshalStorageProvider(k.cdc, sp) @@ -120,6 +131,12 @@ func (k Keeper) SetStorageProviderByGcAddr(ctx sdk.Context, sp *types.StoragePro store.Set(types.GetStorageProviderByGcAddrKey(gcAddr), k.spSequence.EncodeSequence(sp.Id)) } +func (k Keeper) SetStorageProviderByTestAddr(ctx sdk.Context, sp *types.StorageProvider) { + testAddr := sp.GetTestAccAddress() + store := ctx.KVStore(k.storeKey) + store.Set(types.GetStorageProviderByTestAddrKey(testAddr), k.spSequence.EncodeSequence(sp.Id)) +} + func (k Keeper) GetAllStorageProviders(ctx sdk.Context) (sps []types.StorageProvider) { store := ctx.KVStore(k.storeKey) diff --git a/x/sp/keeper/sp_maintenance.go b/x/sp/keeper/sp_maintenance.go new file mode 100644 index 000000000..50c3fe074 --- /dev/null +++ b/x/sp/keeper/sp_maintenance.go @@ -0,0 +1,99 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/errors" + "github.com/bnb-chain/greenfield/x/sp/types" + "github.com/cosmos/cosmos-sdk/store/prefix" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (k Keeper) UpdateToInMaintenance(ctx sdk.Context, sp *types.StorageProvider, requestDuration int64) error { + params := k.GetParams(ctx) + store := ctx.KVStore(k.storeKey) + recordsPrefixStore := prefix.NewStore(store, types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress))) + iterator := recordsPrefixStore.ReverseIterator(nil, nil) + defer iterator.Close() + newRecord := &types.MaintenanceRecord{ + Height: ctx.BlockHeight(), + RequestDuration: requestDuration, + RequestAt: ctx.BlockTime().Unix(), + } + sp.Status = types.STATUS_IN_MAINTENANCE + if !iterator.Valid() { + if requestDuration > params.GetMaintenanceDurationQuota() { + return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "not enough quota, quota=%d is less than requested=%d", params.GetMaintenanceDurationQuota(), requestDuration) + } + store.Set(types.GetStorageProviderMaintenanceRecordKey(sdk.MustAccAddressFromHex(sp.OperatorAddress), ctx.BlockHeight()), k.cdc.MustMarshal(newRecord)) + return nil + } + + totalUsedTime := int64(0) + for ; iterator.Valid(); iterator.Next() { + record := &types.MaintenanceRecord{} + k.cdc.MustUnmarshal(iterator.Value(), record) + threshHold := record.GetHeight() + params.GetNumOfLockupBlocksForMaintenance() + if ctx.BlockHeight() < threshHold { + return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "wait after block height %d", threshHold) + } + totalUsedTime = totalUsedTime + record.GetActualDuration() + } + if totalUsedTime+requestDuration > params.GetMaintenanceDurationQuota() { + return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "not enough quota, quota=%d is less than requested=%d", params.GetMaintenanceDurationQuota()-totalUsedTime, requestDuration) + } + store.Set(types.GetStorageProviderMaintenanceRecordKey(sdk.MustAccAddressFromHex(sp.OperatorAddress), ctx.BlockHeight()), k.cdc.MustMarshal(newRecord)) + return nil +} + +func (k Keeper) UpdateToInService(ctx sdk.Context, sp *types.StorageProvider) { + store := ctx.KVStore(k.storeKey) + spAddr := types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress)) + recordsPrefixStore := prefix.NewStore(store, spAddr) + iterator := recordsPrefixStore.ReverseIterator(nil, nil) + + // update the latest record usedTime + if iterator.Valid() { + record := &types.MaintenanceRecord{} + k.cdc.MustUnmarshal(iterator.Value(), record) + record.ActualDuration = ctx.BlockTime().Unix() - record.RequestAt + recordsPrefixStore.Set(iterator.Key(), k.cdc.MustMarshal(record)) + } + sp.Status = types.STATUS_IN_SERVICE +} + +func (k Keeper) ForceMaintenanceRecords(ctx sdk.Context) { + params := k.GetParams(ctx) + store := ctx.KVStore(k.storeKey) + curTime := ctx.BlockTime().Unix() + iter := storetypes.KVStorePrefixIterator(store, types.StorageProviderKey) + for ; iter.Valid(); iter.Next() { + sp := types.MustUnmarshalStorageProvider(k.cdc, iter.Value()) + prefixStore := prefix.NewStore(store, types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress))) + + iterator := prefixStore.Iterator(nil, nil) + for ; iterator.Valid(); iterator.Next() { + record := &types.MaintenanceRecord{} + k.cdc.MustUnmarshal(iterator.Value(), record) + + fmt.Printf("records is %v\n", record) + // purge old records + if record.GetHeight()+params.GetNumOfHistoricalBlocksForMaintenanceRecords() < ctx.BlockHeight() { + prefixStore.Delete(iterator.Key()) + } else if record.GetActualDuration() == 0 && record.RequestAt+record.GetRequestDuration() < curTime { + fmt.Printf("force update %v\n", record) + record.ActualDuration = record.RequestDuration + prefixStore.Set(iterator.Key(), k.cdc.MustMarshal(record)) + sp.Status = types.STATUS_IN_SERVICE + k.SetStorageProvider(ctx, sp) + k.SetStorageProviderByFundingAddr(ctx, sp) + k.SetStorageProviderBySealAddr(ctx, sp) + k.SetStorageProviderByApprovalAddr(ctx, sp) + k.SetStorageProviderByGcAddr(ctx, sp) + k.SetStorageProviderByTestAddr(ctx, sp) + k.SetStorageProviderByBlsKey(ctx, sp) + } + } + } +} diff --git a/x/storage/keeper/virtualgroup.go b/x/storage/keeper/virtualgroup.go index 7353322fd..5d4f8a5ee 100644 --- a/x/storage/keeper/virtualgroup.go +++ b/x/storage/keeper/virtualgroup.go @@ -2,6 +2,7 @@ package keeper import ( "cosmossdk.io/math" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -122,6 +123,9 @@ func (k Keeper) VerifyGVGSecondarySPsBlsSignature(ctx sdk.Context, gvg *vgtypes. if !found { panic("should not happen") } + if secondarySp.Status != sptypes.STATUS_IN_SERVICE { + return sptypes.ErrStorageProviderNotInService + } spBlsPubKey, err := bls.PublicKeyFromBytes(secondarySp.BlsKey) if err != nil { return types.ErrInvalidBlsPubKey.Wrapf("BLS public key converts failed: %v", err) From 033f940c62efae129f44c223f662c9aa97318435 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Thu, 3 Aug 2023 19:51:15 +0800 Subject: [PATCH 2/7] fix test --- x/sp/keeper/sp_maintenance.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/x/sp/keeper/sp_maintenance.go b/x/sp/keeper/sp_maintenance.go index 50c3fe074..01e914b04 100644 --- a/x/sp/keeper/sp_maintenance.go +++ b/x/sp/keeper/sp_maintenance.go @@ -76,8 +76,6 @@ func (k Keeper) ForceMaintenanceRecords(ctx sdk.Context) { for ; iterator.Valid(); iterator.Next() { record := &types.MaintenanceRecord{} k.cdc.MustUnmarshal(iterator.Value(), record) - - fmt.Printf("records is %v\n", record) // purge old records if record.GetHeight()+params.GetNumOfHistoricalBlocksForMaintenanceRecords() < ctx.BlockHeight() { prefixStore.Delete(iterator.Key()) From c5c20cbee743b8e6fd67c93dfd11e3d44fdee848 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 4 Aug 2023 16:10:05 +0800 Subject: [PATCH 3/7] add query api and fix test --- sdk/client/tx_test.go | 20 -------- x/sp/keeper/sp_maintenance.go | 97 ----------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 x/sp/keeper/sp_maintenance.go diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index 8f593a22c..254ce61b3 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -5,8 +5,6 @@ import ( "testing" "time" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -197,21 +195,3 @@ func TestSendTXViaWebsocketClient(t *testing.T) { assert.Equal(t, uint32(0), response.TxResponse.Code) } } - -func TestSpTXViaWebsocketClient(t *testing.T) { - km, err := keys.NewPrivateKeyManager("9fd8cc7d9a6cdc12c299825a1ff8f27aebef2ec0e00c3fe4d1201daa7cbba3f2") - assert.NoError(t, err) - gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) - assert.NoError(t, err) - km.GetAddr() - - msg := &sptypes.MsgUpdateStorageProviderStatus{ - SpAddress: km.GetAddr().String(), - Status: sptypes.STATUS_IN_SERVICE, - MaintenanceDuration: 0, - } - response, err := gnfdCli.BroadcastTx(context.Background(), []sdk.Msg{msg}, nil) - assert.NoError(t, err) - assert.Equal(t, uint32(0), response.TxResponse.Code) - t.Log(response.TxResponse) -} diff --git a/x/sp/keeper/sp_maintenance.go b/x/sp/keeper/sp_maintenance.go deleted file mode 100644 index 01e914b04..000000000 --- a/x/sp/keeper/sp_maintenance.go +++ /dev/null @@ -1,97 +0,0 @@ -package keeper - -import ( - "fmt" - - "cosmossdk.io/errors" - "github.com/bnb-chain/greenfield/x/sp/types" - "github.com/cosmos/cosmos-sdk/store/prefix" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -func (k Keeper) UpdateToInMaintenance(ctx sdk.Context, sp *types.StorageProvider, requestDuration int64) error { - params := k.GetParams(ctx) - store := ctx.KVStore(k.storeKey) - recordsPrefixStore := prefix.NewStore(store, types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress))) - iterator := recordsPrefixStore.ReverseIterator(nil, nil) - defer iterator.Close() - newRecord := &types.MaintenanceRecord{ - Height: ctx.BlockHeight(), - RequestDuration: requestDuration, - RequestAt: ctx.BlockTime().Unix(), - } - sp.Status = types.STATUS_IN_MAINTENANCE - if !iterator.Valid() { - if requestDuration > params.GetMaintenanceDurationQuota() { - return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "not enough quota, quota=%d is less than requested=%d", params.GetMaintenanceDurationQuota(), requestDuration) - } - store.Set(types.GetStorageProviderMaintenanceRecordKey(sdk.MustAccAddressFromHex(sp.OperatorAddress), ctx.BlockHeight()), k.cdc.MustMarshal(newRecord)) - return nil - } - - totalUsedTime := int64(0) - for ; iterator.Valid(); iterator.Next() { - record := &types.MaintenanceRecord{} - k.cdc.MustUnmarshal(iterator.Value(), record) - threshHold := record.GetHeight() + params.GetNumOfLockupBlocksForMaintenance() - if ctx.BlockHeight() < threshHold { - return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "wait after block height %d", threshHold) - } - totalUsedTime = totalUsedTime + record.GetActualDuration() - } - if totalUsedTime+requestDuration > params.GetMaintenanceDurationQuota() { - return errors.Wrapf(types.ErrStorageProviderStatusUpdateNotAllow, "not enough quota, quota=%d is less than requested=%d", params.GetMaintenanceDurationQuota()-totalUsedTime, requestDuration) - } - store.Set(types.GetStorageProviderMaintenanceRecordKey(sdk.MustAccAddressFromHex(sp.OperatorAddress), ctx.BlockHeight()), k.cdc.MustMarshal(newRecord)) - return nil -} - -func (k Keeper) UpdateToInService(ctx sdk.Context, sp *types.StorageProvider) { - store := ctx.KVStore(k.storeKey) - spAddr := types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress)) - recordsPrefixStore := prefix.NewStore(store, spAddr) - iterator := recordsPrefixStore.ReverseIterator(nil, nil) - - // update the latest record usedTime - if iterator.Valid() { - record := &types.MaintenanceRecord{} - k.cdc.MustUnmarshal(iterator.Value(), record) - record.ActualDuration = ctx.BlockTime().Unix() - record.RequestAt - recordsPrefixStore.Set(iterator.Key(), k.cdc.MustMarshal(record)) - } - sp.Status = types.STATUS_IN_SERVICE -} - -func (k Keeper) ForceMaintenanceRecords(ctx sdk.Context) { - params := k.GetParams(ctx) - store := ctx.KVStore(k.storeKey) - curTime := ctx.BlockTime().Unix() - iter := storetypes.KVStorePrefixIterator(store, types.StorageProviderKey) - for ; iter.Valid(); iter.Next() { - sp := types.MustUnmarshalStorageProvider(k.cdc, iter.Value()) - prefixStore := prefix.NewStore(store, types.GetStorageProviderMaintenanceRecordsPrefix(sdk.MustAccAddressFromHex(sp.OperatorAddress))) - - iterator := prefixStore.Iterator(nil, nil) - for ; iterator.Valid(); iterator.Next() { - record := &types.MaintenanceRecord{} - k.cdc.MustUnmarshal(iterator.Value(), record) - // purge old records - if record.GetHeight()+params.GetNumOfHistoricalBlocksForMaintenanceRecords() < ctx.BlockHeight() { - prefixStore.Delete(iterator.Key()) - } else if record.GetActualDuration() == 0 && record.RequestAt+record.GetRequestDuration() < curTime { - fmt.Printf("force update %v\n", record) - record.ActualDuration = record.RequestDuration - prefixStore.Set(iterator.Key(), k.cdc.MustMarshal(record)) - sp.Status = types.STATUS_IN_SERVICE - k.SetStorageProvider(ctx, sp) - k.SetStorageProviderByFundingAddr(ctx, sp) - k.SetStorageProviderBySealAddr(ctx, sp) - k.SetStorageProviderByApprovalAddr(ctx, sp) - k.SetStorageProviderByGcAddr(ctx, sp) - k.SetStorageProviderByTestAddr(ctx, sp) - k.SetStorageProviderByBlsKey(ctx, sp) - } - } - } -} From 4b685c25f2f26341aee4a93310b0ae0a58f5a77d Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Fri, 4 Aug 2023 23:56:06 +0800 Subject: [PATCH 4/7] change underlying storage model --- sdk/client/tx_test.go | 34 ++++++++++++++++++++++++++++++++++ x/sp/keeper/grpc_query.go | 1 - 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index 254ce61b3..e5476e49b 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -2,6 +2,8 @@ package client import ( "context" + "fmt" + sptypes "github.com/bnb-chain/greenfield/x/sp/types" "testing" "time" @@ -195,3 +197,35 @@ func TestSendTXViaWebsocketClient(t *testing.T) { assert.Equal(t, uint32(0), response.TxResponse.Code) } } + +func TestSpTXViaWebsocketClient(t *testing.T) { + km, err := keys.NewPrivateKeyManager("c8babf9a81412a04e840fbebc1fdf93d0c751e43af370dbc1e85424fed46bf85") + assert.NoError(t, err) + gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) + assert.NoError(t, err) + fmt.Println(km.GetAddr()) + + msg := &sptypes.MsgUpdateStorageProviderStatus{ + SpAddress: km.GetAddr().String(), + Status: sptypes.STATUS_IN_MAINTENANCE, + MaintenanceDuration: 100, + } + response, err := gnfdCli.BroadcastTx(context.Background(), []sdk.Msg{msg}, nil) + assert.NoError(t, err) + assert.Equal(t, uint32(0), response.TxResponse.Code) + t.Log(response.TxResponse) +} + +func TestQuerySPMain(t *testing.T) { + km, err := keys.NewPrivateKeyManager("d68709c9e205478234b38bfb53787206a2d3fa760ed47fa85d008af0ad92891a") + assert.NoError(t, err) + gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) + assert.NoError(t, err) + km.GetAddr() + + resp, err := gnfdCli.StorageProviderMaintenanceRecordsByOperatorAddress(context.Background(), &sptypes.QueryStorageProviderMaintenanceRecordsRequest{OperatorAddress: "0xD738b122a78D79ABf14fB1C6AcB05f63CE3De58f"}) + if err != nil { + panic(err) + } + t.Log(resp.Records) +} diff --git a/x/sp/keeper/grpc_query.go b/x/sp/keeper/grpc_query.go index 413db357b..c64008514 100644 --- a/x/sp/keeper/grpc_query.go +++ b/x/sp/keeper/grpc_query.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" From ac7dbd1506c8db5b22a0178d1a8b5dd9dc9d327a Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Sat, 5 Aug 2023 20:03:20 +0800 Subject: [PATCH 5/7] add cmd --- sdk/client/tx_test.go | 34 ---------------------------------- x/sp/keeper/grpc_query.go | 1 + 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/sdk/client/tx_test.go b/sdk/client/tx_test.go index e5476e49b..254ce61b3 100644 --- a/sdk/client/tx_test.go +++ b/sdk/client/tx_test.go @@ -2,8 +2,6 @@ package client import ( "context" - "fmt" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" "testing" "time" @@ -197,35 +195,3 @@ func TestSendTXViaWebsocketClient(t *testing.T) { assert.Equal(t, uint32(0), response.TxResponse.Code) } } - -func TestSpTXViaWebsocketClient(t *testing.T) { - km, err := keys.NewPrivateKeyManager("c8babf9a81412a04e840fbebc1fdf93d0c751e43af370dbc1e85424fed46bf85") - assert.NoError(t, err) - gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) - assert.NoError(t, err) - fmt.Println(km.GetAddr()) - - msg := &sptypes.MsgUpdateStorageProviderStatus{ - SpAddress: km.GetAddr().String(), - Status: sptypes.STATUS_IN_MAINTENANCE, - MaintenanceDuration: 100, - } - response, err := gnfdCli.BroadcastTx(context.Background(), []sdk.Msg{msg}, nil) - assert.NoError(t, err) - assert.Equal(t, uint32(0), response.TxResponse.Code) - t.Log(response.TxResponse) -} - -func TestQuerySPMain(t *testing.T) { - km, err := keys.NewPrivateKeyManager("d68709c9e205478234b38bfb53787206a2d3fa760ed47fa85d008af0ad92891a") - assert.NoError(t, err) - gnfdCli, err := NewGreenfieldClient(test.TEST_RPC_ADDR, test.TEST_CHAIN_ID, WithKeyManager(km)) - assert.NoError(t, err) - km.GetAddr() - - resp, err := gnfdCli.StorageProviderMaintenanceRecordsByOperatorAddress(context.Background(), &sptypes.QueryStorageProviderMaintenanceRecordsRequest{OperatorAddress: "0xD738b122a78D79ABf14fB1C6AcB05f63CE3De58f"}) - if err != nil { - panic(err) - } - t.Log(resp.Records) -} diff --git a/x/sp/keeper/grpc_query.go b/x/sp/keeper/grpc_query.go index c64008514..413db357b 100644 --- a/x/sp/keeper/grpc_query.go +++ b/x/sp/keeper/grpc_query.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" From f08924c0f6b07ee709de07f3a1d6151114561f14 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Tue, 8 Aug 2023 12:13:17 +0800 Subject: [PATCH 6/7] fix comments --- x/challenge/abci.go | 2 +- x/challenge/keeper/msg_server_submit.go | 2 +- x/sp/keeper/sp.go | 17 ----------------- x/storage/keeper/virtualgroup.go | 4 ---- 4 files changed, 2 insertions(+), 23 deletions(-) diff --git a/x/challenge/abci.go b/x/challenge/abci.go index 1eeb97bb3..0334c4121 100644 --- a/x/challenge/abci.go +++ b/x/challenge/abci.go @@ -89,7 +89,7 @@ func EndBlocker(ctx sdk.Context, keeper k.Keeper) { if !found { continue } - if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING && sp.Status != sptypes.STATUS_IN_MAINTENANCE { + if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING { continue } diff --git a/x/challenge/keeper/msg_server_submit.go b/x/challenge/keeper/msg_server_submit.go index 38fd0a3d3..49f92c669 100644 --- a/x/challenge/keeper/msg_server_submit.go +++ b/x/challenge/keeper/msg_server_submit.go @@ -24,7 +24,7 @@ func (k msgServer) Submit(goCtx context.Context, msg *types.MsgSubmit) (*types.M return nil, types.ErrUnknownBucketObject } sp := k.StorageKeeper.MustGetPrimarySPForBucket(ctx, bucketInfo) - if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING && sp.Status != sptypes.STATUS_IN_MAINTENANCE { + if sp.Status != sptypes.STATUS_IN_SERVICE && sp.Status != sptypes.STATUS_GRACEFUL_EXITING { return nil, types.ErrInvalidSpStatus } diff --git a/x/sp/keeper/sp.go b/x/sp/keeper/sp.go index 032a17120..e79321964 100644 --- a/x/sp/keeper/sp.go +++ b/x/sp/keeper/sp.go @@ -82,17 +82,6 @@ func (k Keeper) GetStorageProviderByGcAddr(ctx sdk.Context, gcAddr sdk.AccAddres return k.GetStorageProvider(ctx, k.spSequence.DecodeSequence(id)) } -func (k Keeper) GetStorageProviderByTestAddr(ctx sdk.Context, testAddr sdk.AccAddress) (sp *types.StorageProvider, found bool) { - store := ctx.KVStore(k.storeKey) - - id := store.Get(types.GetStorageProviderByTestAddrKey(testAddr)) - if id == nil { - return sp, false - } - - return k.GetStorageProvider(ctx, k.spSequence.DecodeSequence(id)) -} - func (k Keeper) SetStorageProvider(ctx sdk.Context, sp *types.StorageProvider) { store := ctx.KVStore(k.storeKey) bz := types.MustMarshalStorageProvider(k.cdc, sp) @@ -131,12 +120,6 @@ func (k Keeper) SetStorageProviderByGcAddr(ctx sdk.Context, sp *types.StoragePro store.Set(types.GetStorageProviderByGcAddrKey(gcAddr), k.spSequence.EncodeSequence(sp.Id)) } -func (k Keeper) SetStorageProviderByTestAddr(ctx sdk.Context, sp *types.StorageProvider) { - testAddr := sp.GetTestAccAddress() - store := ctx.KVStore(k.storeKey) - store.Set(types.GetStorageProviderByTestAddrKey(testAddr), k.spSequence.EncodeSequence(sp.Id)) -} - func (k Keeper) GetAllStorageProviders(ctx sdk.Context) (sps []types.StorageProvider) { store := ctx.KVStore(k.storeKey) diff --git a/x/storage/keeper/virtualgroup.go b/x/storage/keeper/virtualgroup.go index 5d4f8a5ee..7353322fd 100644 --- a/x/storage/keeper/virtualgroup.go +++ b/x/storage/keeper/virtualgroup.go @@ -2,7 +2,6 @@ package keeper import ( "cosmossdk.io/math" - sptypes "github.com/bnb-chain/greenfield/x/sp/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/prysmaticlabs/prysm/crypto/bls" @@ -123,9 +122,6 @@ func (k Keeper) VerifyGVGSecondarySPsBlsSignature(ctx sdk.Context, gvg *vgtypes. if !found { panic("should not happen") } - if secondarySp.Status != sptypes.STATUS_IN_SERVICE { - return sptypes.ErrStorageProviderNotInService - } spBlsPubKey, err := bls.PublicKeyFromBytes(secondarySp.BlsKey) if err != nil { return types.ErrInvalidBlsPubKey.Wrapf("BLS public key converts failed: %v", err) From 1078b4661997f48b458cc36f19eb33bbed96f741 Mon Sep 17 00:00:00 2001 From: Alexgao001 Date: Tue, 8 Aug 2023 17:41:28 +0800 Subject: [PATCH 7/7] modify the default params --- x/sp/types/params.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/sp/types/params.go b/x/sp/types/params.go index fd041cad3..d25650a30 100644 --- a/x/sp/types/params.go +++ b/x/sp/types/params.go @@ -17,11 +17,11 @@ const ( // Default deposit denom DefaultDepositDenom = "BNB" // DefaultNumOfHistoricalBlocksForMaintenanceRecords The oldest block from current will be kept of for SP maintenance records - DefaultNumOfHistoricalBlocksForMaintenanceRecords = 21600 //todo set a reasonable number after test + DefaultNumOfHistoricalBlocksForMaintenanceRecords = 864000 // DefaultMaintenanceDurationQuota is the total allowed time for a SP to be in Maintenance mode within DefaultNumOfHistoricalBlocksForMaintenanceRecords - DefaultMaintenanceDurationQuota = 21600 // in second + DefaultMaintenanceDurationQuota = 21600 // 6 hour // DefaultNumOfLockUpBlocksForMaintenance defines blocks difference which Sp update itself to Maintenance mode is allowed - DefaultNumOfLockUpBlocksForMaintenance = 10 //todo set a reasonable number after test + DefaultNumOfLockUpBlocksForMaintenance = 21600 ) var (