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: sp maintenance mode #403

Merged
merged 12 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions deployment/localup/create_sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"seal_address":"0x942a7C3eA3011b831D94BdcA8b950fE26853e74d",
"approval_address":"0x8FEe9d987Ce29Dd7e9A6aF5eb9d8AA5f98a367b1",
"gc_address": "0x9c024772c932b3E6748AbE50C4e895086Be18249",
"test_address": "0x9c024772c932b3E6748AbE50C4e895086Be18249",
fynnss marked this conversation as resolved.
Show resolved Hide resolved
"endpoint": "https://www.greenfield.io",
"deposit":{
"denom":"BNB",
Expand Down
9 changes: 9 additions & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function init() {
${bin} keys add sp${i}_bls --keyring-backend test --home ${workspace}/.local/sp${i} --algo eth_bls > ${workspace}/.local/sp${i}/bls_info 2>&1
${bin} keys add sp${i}_approval --keyring-backend test --home ${workspace}/.local/sp${i} > ${workspace}/.local/sp${i}/approval_info 2>&1
${bin} keys add sp${i}_gc --keyring-backend test --home ${workspace}/.local/sp${i} > ${workspace}/.local/sp${i}/gc_info 2>&1
${bin} keys add sp${i}_test --keyring-backend test --home ${workspace}/.local/sp${i} > ${workspace}/.local/sp${i}/test_info 2>&1
done

}
Expand Down Expand Up @@ -198,11 +199,13 @@ function generate_sp_genesis {
spseal_addr=("$(${bin} keys show sp${i}_seal -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spapproval_addr=("$(${bin} keys show sp${i}_approval -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spgc_addr=("$(${bin} keys show sp${i}_gc -a --keyring-backend test --home ${workspace}/.local/sp${i})")
sptest_addr=("$(${bin} keys show sp${i}_test -a --keyring-backend test --home ${workspace}/.local/sp${i})")
${bin} add-genesis-account $spoperator_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spfund_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spseal_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spapproval_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $spgc_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
${bin} add-genesis-account $sptest_addr ${GENESIS_ACCOUNT_BALANCE}${STAKING_BOND_DENOM} --home ${workspace}/.local/validator0
done

rm -rf ${workspace}/.local/gensptx
Expand All @@ -216,6 +219,7 @@ function generate_sp_genesis {
bls_proof=("$(${bin} keys sign "${bls_pub_key}" --from sp${i}_bls --keyring-backend test --home ${workspace}/.local/sp${i})")
spapproval_addr=("$(${bin} keys show sp${i}_approval -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spgc_addr=("$(${bin} keys show sp${i}_gc -a --keyring-backend test --home ${workspace}/.local/sp${i})")
sptest_addr=("$(${bin} keys show sp${i}_test -a --keyring-backend test --home ${workspace}/.local/sp${i})")
validator0Addr="$(${bin} keys show validator0 -a --keyring-backend test --home ${workspace}/.local/validator0)"
# create bond storage provider tx
${bin} spgentx sp${i} ${SP_MIN_DEPOSIT_AMOUNT}${STAKING_BOND_DENOM} \
Expand All @@ -228,6 +232,7 @@ function generate_sp_genesis {
--bls-proof=${bls_proof} \
--approval-address=${spapproval_addr} \
--gc-address=${spgc_addr} \
--test-address=${sptest_addr} \
--keyring-backend=test \
--chain-id=${CHAIN_ID} \
--moniker="sp${i}" \
Expand Down Expand Up @@ -261,25 +266,29 @@ function export_sps {
spseal_addr=("$(${bin} keys show sp${i}_seal -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spapproval_addr=("$(${bin} keys show sp${i}_approval -a --keyring-backend test --home ${workspace}/.local/sp${i})")
spgc_addr=("$(${bin} keys show sp${i}_gc -a --keyring-backend test --home ${workspace}/.local/sp${i})")
sptest_addr=("$(${bin} keys show sp${i}_test -a --keyring-backend test --home ${workspace}/.local/sp${i})")
bls_pub_key=("$(${bin} keys show sp${i}_bls --keyring-backend test --home ${workspace}/.local/sp${i} --output json | jq -r .pubkey_hex)")
spoperator_priv_key=("$(echo "y" | ${bin} keys export sp${i} --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
spfund_priv_key=("$(echo "y" | ${bin} keys export sp${i}_fund --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
spseal_priv_key=("$(echo "y" | ${bin} keys export sp${i}_seal --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
spapproval_priv_key=("$(echo "y" | ${bin} keys export sp${i}_approval --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
spgc_priv_key=("$(echo "y" | ${bin} keys export sp${i}_gc --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
sptest_priv_key=("$(echo "y" | ${bin} keys export sp${i}_test --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
bls_priv_key=("$(echo "y" | ${bin} keys export sp${i}_bls --unarmored-hex --unsafe --keyring-backend test --home ${workspace}/.local/sp${i})")
output="${output}\"sp${i}\":{"
output="${output}\"OperatorAddress\": \"${spoperator_addr}\","
output="${output}\"FundingAddress\": \"${spfund_addr}\","
output="${output}\"SealAddress\": \"${spseal_addr}\","
output="${output}\"ApprovalAddress\": \"${spapproval_addr}\","
output="${output}\"GcAddress\": \"${spgc_addr}\","
output="${output}\"TestAddress\": \"${sptest_addr}\","
output="${output}\"BlsPubKey\": \"${bls_pub_key}\","
output="${output}\"OperatorPrivateKey\": \"${spoperator_priv_key}\","
output="${output}\"FundingPrivateKey\": \"${spfund_priv_key}\","
output="${output}\"SealPrivateKey\": \"${spseal_priv_key}\","
output="${output}\"ApprovalPrivateKey\": \"${spapproval_priv_key}\","
output="${output}\"GcPrivateKey\": \"${spgc_priv_key}\","
output="${output}\"TestPrivateKey\": \"${sptest_priv_key}\","
output="${output}\"BlsPrivateKey\": \"${bls_priv_key}\""
output="${output}},"
done
Expand Down
23 changes: 20 additions & 3 deletions e2e/core/basesuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type StorageProvider struct {
FundingKey keys.KeyManager
ApprovalKey keys.KeyManager
GcKey keys.KeyManager
TestKey keys.KeyManager
BlsKey keys.KeyManager
Info *sptypes.StorageProvider
GlobalVirtualGroupFamilies map[uint32][]*virtualgroupmoduletypes.GlobalVirtualGroup
Expand Down Expand Up @@ -155,6 +156,8 @@ func (s *BaseSuite) SetupSuite() {
s.Require().NoError(err)
sp.GcKey, err = keys.NewMnemonicKeyManager(spMnemonics.GcMnemonic)
s.Require().NoError(err)
sp.TestKey, err = keys.NewMnemonicKeyManager(spMnemonics.TestMnemonic)
s.Require().NoError(err)
sp.BlsKey, err = keys.NewBlsMnemonicKeyManager(s.Config.SPBLSMnemonic[i])
s.Require().NoError(err)
var resp *sptypes.QueryStorageProviderByOperatorAddressResponse
Expand Down Expand Up @@ -432,16 +435,17 @@ func (sp *StorageProvider) GetFirstGlobalVirtualGroup() (*virtualgroupmoduletype
}

func (s *BaseSuite) NewSpAcc() *StorageProvider {
userAccs := s.GenAndChargeAccounts(5, 1000000)
userAccs := s.GenAndChargeAccounts(6, 1000000)
operatorAcc := userAccs[0]
fundingAcc := userAccs[1]
approvalAcc := userAccs[2]
sealAcc := userAccs[3]
gcAcc := userAccs[4]
testAcc := userAccs[5]

blsKm := s.GenRandomBlsKeyManager()
return &StorageProvider{OperatorKey: operatorAcc, SealKey: fundingAcc,
FundingKey: approvalAcc, ApprovalKey: sealAcc, GcKey: gcAcc, BlsKey: blsKm}
FundingKey: approvalAcc, ApprovalKey: sealAcc, GcKey: gcAcc, TestKey: testAcc, BlsKey: blsKm}
}

func (s *BaseSuite) CreateNewStorageProvider() *StorageProvider {
Expand Down Expand Up @@ -484,7 +488,9 @@ func (s *BaseSuite) CreateNewStorageProvider() *StorageProvider {
newSP.OperatorKey.GetAddr(), newSP.FundingKey.GetAddr(),
newSP.SealKey.GetAddr(),
newSP.ApprovalKey.GetAddr(),
newSP.GcKey.GetAddr(), description,
newSP.GcKey.GetAddr(),
newSP.TestKey.GetAddr(),
description,
endpoint, deposit, newReadPrice, 10000, newStorePrice,
hex.EncodeToString(newSP.BlsKey.PubKey().Bytes()),
hex.EncodeToString(blsProofBz),
Expand Down Expand Up @@ -549,7 +555,18 @@ func (s *BaseSuite) CreateNewStorageProvider() *StorageProvider {
s.Require().Equal(querySPByOperatorAddrResp.StorageProvider.SealAddress, newSP.SealKey.GetAddr().String())
s.Require().Equal(querySPByOperatorAddrResp.StorageProvider.ApprovalAddress, newSP.ApprovalKey.GetAddr().String())
s.Require().Equal(querySPByOperatorAddrResp.StorageProvider.Endpoint, endpoint)
s.Require().Equal(querySPByOperatorAddrResp.StorageProvider.Status, sptypes.STATUS_IN_MAINTENANCE)
newSP.Info = querySPByOperatorAddrResp.StorageProvider

// SP need to activate itself
msg := sptypes.NewMsgUpdateStorageProviderStatus(
newSP.OperatorKey.GetAddr(),
sptypes.STATUS_IN_SERVICE,
0,
)

txRes = s.SendTxBlock(newSP.OperatorKey, msg)
s.Require().Equal(txRes.Code, uint32(0))
return newSP
}

Expand Down
2 changes: 2 additions & 0 deletions e2e/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SPMnemonics struct {
FundingMnemonic string `yaml:"FundingMnemonic"` // funding account mnemonic with enough balance
ApprovalMnemonic string `yaml:"ApprovalMnemonic"` // approval account mnemonic with enough balance
GcMnemonic string `yaml:"GcMnemonic"` // gc account mnemonic with enough balance
TestMnemonic string `yaml:"TestMnemonic"` // test account mnemonic with enough balance
}

type Config struct {
Expand Down Expand Up @@ -83,6 +84,7 @@ func ParseSPMnemonics(i int) SPMnemonics {
FundingMnemonic: ParseMnemonicFromFile(fmt.Sprintf("../../deployment/localup/.local/sp%d/fund_info", i)),
ApprovalMnemonic: ParseMnemonicFromFile(fmt.Sprintf("../../deployment/localup/.local/sp%d/approval_info", i)),
GcMnemonic: ParseMnemonicFromFile(fmt.Sprintf("../../deployment/localup/.local/sp%d/gc_info", i)),
TestMnemonic: ParseMnemonicFromFile(fmt.Sprintf("../../deployment/localup/.local/sp%d/test_info", i)),
}
}

Expand Down
1 change: 1 addition & 0 deletions e2e/tests/gensp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (s *GenStorageProviderTestSuite) TestGenStorageProvider() {
SealAddress: sp.SealKey.GetAddr().String(),
ApprovalAddress: sp.ApprovalKey.GetAddr().String(),
GcAddress: sp.GcKey.GetAddr().String(),
TestAddress: sp.TestKey.GetAddr().String(),
BlsKey: sp.BlsKey.PubKey().Bytes(),
Description: sptypes.Description{
Moniker: sp.Info.Description.Moniker,
Expand Down
43 changes: 41 additions & 2 deletions e2e/tests/sp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (s *StorageProviderTestSuite) TestEditStorageProvider() {
SealAddress: prevSP.SealAddress,
ApprovalAddress: prevSP.ApprovalAddress,
GcAddress: prevSP.GcAddress,
TestAddress: prevSP.TestAddress,
BlsKey: newBlsPubKeyBz,
Description: sptypes.Description{
Moniker: "sp_test_edit",
Expand All @@ -103,7 +104,7 @@ func (s *StorageProviderTestSuite) TestEditStorageProvider() {
}
msgEditSP := sptypes.NewMsgEditStorageProvider(
sp.OperatorKey.GetAddr(), newSP.Endpoint, &newSP.Description,
sp.SealKey.GetAddr(), sp.ApprovalKey.GetAddr(), sp.GcKey.GetAddr(),
sp.SealKey.GetAddr(), sp.ApprovalKey.GetAddr(), sp.GcKey.GetAddr(), sp.TestKey.GetAddr(),
hex.EncodeToString(newBlsPubKeyBz),
hex.EncodeToString(newBlsProofBz),
)
Expand All @@ -124,7 +125,7 @@ func (s *StorageProviderTestSuite) TestEditStorageProvider() {
// 4. revert storage provider info
msgEditSP = sptypes.NewMsgEditStorageProvider(
sp.OperatorKey.GetAddr(), prevSP.Endpoint, &prevSP.Description,
sp.SealKey.GetAddr(), sp.ApprovalKey.GetAddr(), sp.GcKey.GetAddr(),
sp.SealKey.GetAddr(), sp.ApprovalKey.GetAddr(), sp.GcKey.GetAddr(), sp.TestKey.GetAddr(),
hex.EncodeToString(prevSP.BlsKey), hex.EncodeToString(blsProof))

txRes = s.SendTxBlock(sp.OperatorKey, msgEditSP)
Expand Down Expand Up @@ -330,3 +331,41 @@ CheckProposalStatus:
s.T().Errorf("update params failed")
}
}

func (s *StorageProviderTestSuite) TestUpdateStorageProviderStatus() {
ctx := context.Background()
sp := s.BaseSuite.PickStorageProvider()
operatorAddr := sp.OperatorKey.GetAddr()

// 1. query storage provider
req := sptypes.QueryStorageProviderByOperatorAddressRequest{
OperatorAddress: operatorAddr.String(),
}
spResp, err := s.Client.StorageProviderByOperatorAddress(ctx, &req)
s.Require().NoError(err)
s.Require().Equal(sptypes.STATUS_IN_SERVICE, spResp.StorageProvider.Status)

msg := sptypes.NewMsgUpdateStorageProviderStatus(
operatorAddr,
sptypes.STATUS_IN_MAINTENANCE,
120,
)
txRes := s.SendTxBlock(sp.OperatorKey, msg)
s.Require().Equal(txRes.Code, uint32(0))

spResp, err = s.Client.StorageProviderByOperatorAddress(ctx, &req)
s.Require().NoError(err)
s.Require().Equal(sptypes.STATUS_IN_MAINTENANCE, spResp.StorageProvider.Status)

msg = sptypes.NewMsgUpdateStorageProviderStatus(
operatorAddr,
sptypes.STATUS_IN_SERVICE,
0,
)

txRes = s.SendTxBlock(sp.OperatorKey, msg)
s.Require().Equal(txRes.Code, uint32(0))
spResp, err = s.Client.StorageProviderByOperatorAddress(ctx, &req)
s.Require().NoError(err)
s.Require().Equal(sptypes.STATUS_IN_SERVICE, spResp.StorageProvider.Status)
}
Loading
Loading