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

Cleanup/readpool refactor zboxcore #1106

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.1

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c
github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89
github.com/go-resty/resty/v2 v2.7.0
github.com/herumi/bls-go-binary v1.31.0
github.com/shopspring/decimal v1.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565 h1:z+DtCR8mBsjPnEs
github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565/go.mod h1:UyDC8Qyl5z9lGkCnf9RHJPMektnFX8XtCJZHXCCVj8E=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c h1:o8SPHAi3/bUMFqMPVNhMs77Ce5qxLzs5Q9YYyuT/llQ=
github.com/0chain/gosdk v1.17.7-0.20240913214358-e71c555b3b9c/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI=
github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89 h1:icV32Kaq/gZbh7bnVVpacOb4eTqWZaIMGOU8LWbzhwc=
github.com/0chain/gosdk v1.17.7-0.20240919221730-fa5e1cec2d89/go.mod h1:+9quBj37eUmdFrWbvDv1Fs4+gG/Vz8Ls/4Ywu/sd8GI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Luzifer/go-openssl/v3 v3.1.0 h1:QqKqo6kYXGGUsvtUoCpRZm8lHw+jDfhbzr36gVj+/gw=
Expand Down
21 changes: 0 additions & 21 deletions internal/api/model/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@ func NewCreateWritePoolTransactionData(createWritePoolRequest CreateWritePoolReq
}
}

func NewCreateReadPoolTransactionData() TransactionData {
return TransactionData{
Name: "read_pool_lock",
}
}

func NewUnlockReadPoolTransactionData() TransactionData {
return TransactionData{
Name: "read_pool_unlock",
}
}

func NewCreateStackPoolTransactionData(createStakePoolRequest CreateStakePoolRequest) TransactionData {
return TransactionData{
Name: "stake_pool_lock",
Expand Down Expand Up @@ -372,10 +360,6 @@ type ClientGetBalanceResponse struct {
Nonce int64 `json:"nonce"`
}

type ClientGetReadPoolBalanceRequest struct {
ClientID string
}

type QueryRequest struct {
Query string
}
Expand All @@ -389,11 +373,6 @@ type GetAllChallengesForAllocationRequest struct {
AllocationID string
}

type ClientGetReadPoolBalanceResponse struct {
UserID string `json:"user_id" gorm:"uniqueIndex"`
Balance int64 `json:"balance"`
}

type QueryRewardsResponse struct {
TotalProviderReward float64 `json:"total_provider_reward"`
TotalDelegateReward float64 `json:"total_delegate_reward"`
Expand Down
133 changes: 0 additions & 133 deletions internal/api/util/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const (
TransactionFeeGet = "/v1/estimate_txn_fee"
TransactionGetConfirmation = "/v1/transaction/get/confirmation"
ClientGetBalance = "/v1/client/get/balance"
ClientReadPool = "/v1/screst/:sc_address/getReadPoolStat"
GetNetworkDetails = "/network"
GetFileRef = "/v1/file/refs/:allocation_id"
GetFileRefPath = "/v1/file/referencepath/:allocation_id"
Expand Down Expand Up @@ -497,24 +496,6 @@ func (c *APIClient) V1ClientGetBalance(t *test.SystemTest, clientGetBalanceReque
return clientGetBalanceResponse, resp, err
}

func (c *APIClient) V1ClientGetReadPoolBalance(t *test.SystemTest, clientGetReadBalanceRequest model.ClientGetReadPoolBalanceRequest, requiredStatusCode int) (*model.ClientGetReadPoolBalanceResponse, *resty.Response, error) { //nolint
var clientGetReadPoolBalanceResponse *model.ClientGetReadPoolBalanceResponse

urlBuilder := NewURLBuilder().SetPath(ClientReadPool).AddParams("client_id", clientGetReadBalanceRequest.ClientID).SetPathVariable("sc_address", StorageSmartContractAddress)

resp, err := c.executeForAllServiceProviders(
t,
urlBuilder,
&model.ExecutionRequest{
Dst: &clientGetReadPoolBalanceResponse,
RequiredStatusCode: requiredStatusCode,
},
HttpGETMethod,
SharderServiceProvider)

return clientGetReadPoolBalanceResponse, resp, err
}

func (c *APIClient) V1SCRestGetAllMiners(t *test.SystemTest, requiredStatusCode int) ([]*model.SCRestGetMinerSharderResponse, *resty.Response, error) {
var scRestGetMinersResponse *model.SCRestGetMinersShardersResponse

Expand Down Expand Up @@ -1310,27 +1291,6 @@ func (c *APIClient) GetWalletBalance(t *test.SystemTest, wallet *model.Wallet, r
return clientGetBalanceResponse
}

func (c *APIClient) GetReadPoolBalance(t *test.SystemTest, wallet *model.Wallet, requiredStatusCode int) *model.ClientGetReadPoolBalanceResponse {
t.Log("Get read pool balance...")

clientGetReadPoolBalanceResponse, resp, err := c.V1ClientGetReadPoolBalance(
t,
model.ClientGetReadPoolBalanceRequest{
ClientID: wallet.Id,
},
requiredStatusCode)

if err != nil {
t.Logf("Error getting readpool balance: %v", err)
return clientGetReadPoolBalanceResponse
}
require.Nil(t, err)
require.NotNil(t, resp)
require.NotNil(t, clientGetReadPoolBalanceResponse)

return clientGetReadPoolBalanceResponse
}

func (c *APIClient) GetRewardsByQuery(t *test.SystemTest, query string, requiredStatusCode int) *model.QueryRewardsResponse {
t.Log("Get rewards by query...")

Expand Down Expand Up @@ -1732,99 +1692,6 @@ func (c *APIClient) CreateWritePool(t *test.SystemTest, wallet *model.Wallet, al
return createWritePoolTransactionGetConfirmationResponse.Hash
}

// CreateReadPoolWrapper does not provide deep test of used components
func (c *APIClient) CreateReadPool(t *test.SystemTest, wallet *model.Wallet, tokens float64, requiredTransactionStatus int) string {
t.Log("Create Read pool...")

createReadPoolTransactionPutResponse, resp, err := c.V1TransactionPut(
t,
model.InternalTransactionPutRequest{
Wallet: wallet,
ToClientID: StorageSmartContractAddress,
TransactionData: model.NewCreateReadPoolTransactionData(),
Value: tokenomics.IntToZCN(tokens),
TxnType: SCTxType,
},
HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, resp)
require.NotNil(t, createReadPoolTransactionPutResponse)

var createReadPoolTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse

wait.PoolImmediately(t, time.Minute*2, func() bool {
createReadPoolTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation(
t,
model.TransactionGetConfirmationRequest{
Hash: createReadPoolTransactionPutResponse.Entity.Hash,
},
HttpOkStatus)
if err != nil {
return false
}

if resp == nil {
return false
}

if createReadPoolTransactionGetConfirmationResponse == nil {
return false
}

return createReadPoolTransactionGetConfirmationResponse.Status == requiredTransactionStatus
})

wallet.IncNonce()

return createReadPoolTransactionGetConfirmationResponse.Hash
}

func (c *APIClient) UnlockReadPool(t *test.SystemTest, wallet *model.Wallet, requiredTransactionStatus int) string {
t.Log("Unlock Read pool...")

unlockReadPoolTransactionPutResponse, resp, err := c.V1TransactionPut(
t,
model.InternalTransactionPutRequest{
Wallet: wallet,
ToClientID: StorageSmartContractAddress,
TransactionData: model.NewUnlockReadPoolTransactionData(),
Value: tokenomics.IntToZCN(0.1),
TxnType: SCTxType,
},
HttpOkStatus)
require.Nil(t, err)
require.NotNil(t, resp)
require.NotNil(t, unlockReadPoolTransactionPutResponse)

var unlockReadPoolTransactionGetConfirmationResponse *model.TransactionGetConfirmationResponse

wait.PoolImmediately(t, time.Minute*2, func() bool {
unlockReadPoolTransactionGetConfirmationResponse, resp, err = c.V1TransactionGetConfirmation(
t,
model.TransactionGetConfirmationRequest{
Hash: unlockReadPoolTransactionPutResponse.Entity.Hash,
},
HttpOkStatus)
if err != nil {
return false
}

if resp == nil {
return false
}

if unlockReadPoolTransactionGetConfirmationResponse == nil {
return false
}

return unlockReadPoolTransactionGetConfirmationResponse.Status == requiredTransactionStatus
})

wallet.IncNonce()

return unlockReadPoolTransactionGetConfirmationResponse.Hash
}

func (c *APIClient) V1SCRestGetStakePoolStat(t *test.SystemTest, scRestGetStakePoolStatRequest model.SCRestGetStakePoolStatRequest, requiredStatusCode int) (*model.SCRestGetStakePoolStatResponse, *resty.Response, error) { //nolint
var scRestGetStakePoolStatResponse *model.SCRestGetStakePoolStatResponse

Expand Down
6 changes: 0 additions & 6 deletions internal/cli/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ type Blobber struct {
StakePoolSettings StakePoolSettings `json:"stake_pool_settings"`
}

type ReadPoolInfo struct {
Balance int64 `json:"fmt"`
Zcn float64 `json:"zcn"`
Usd float64 `json:"usd"`
}

type RecentlyAddedRefResult struct {
Offset int `json:"offset"`
Refs []ORef `json:"refs"`
Expand Down
2 changes: 0 additions & 2 deletions tests/api_tests/0box_aggregate_endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1453,8 +1453,6 @@ func Test0boxGraphBlobberEndpoints(testSetup *testing.T) {
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocationWithLockValue(t, wallet, allocationBlobbers, 0.1, client.TxSuccessfulStatus)

apiClient.CreateReadPool(t, wallet, 100, client.TxSuccessfulStatus)

alloc, _ := sdk.GetAllocation(allocationID)

targetBlobber := alloc.BlobberDetails[0].BlobberID
Expand Down
2 changes: 0 additions & 2 deletions tests/api_tests/multi_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func TestMultiDownload(testSetup *testing.T) {
allocationBlobbers := apiClient.GetAllocationBlobbers(t, wallet, &blobberRequirements, client.HttpOkStatus)
allocationID := apiClient.CreateAllocation(t, wallet, allocationBlobbers, client.TxSuccessfulStatus)

apiClient.CreateReadPool(t, wallet, float64(1.5), client.TxSuccessfulStatus)

ops := make([]sdk.OperationRequest, 0, 10)

for i := 0; i < 10; i++ {
Expand Down
3 changes: 0 additions & 3 deletions tests/api_tests/repair_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ func TestRepairAllocation(testSetup *testing.T) {

sdkClient.SetWallet(t, wallet)

apiClient.CreateReadPool(t, wallet, 0.5, client.TxSuccessfulStatus)

t.RunSequentially("Repair allocation after single upload should work", func(t *test.SystemTest) {
blobberRequirements := model.DefaultBlobberRequirements(wallet.Id, wallet.PublicKey)
blobberRequirements.DataShards = 2
Expand Down Expand Up @@ -352,7 +350,6 @@ func TestRepairSize(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
wallet := createWallet(t)
sdkClient.SetWallet(t, wallet)
apiClient.CreateReadPool(t, wallet, 0.5, client.TxSuccessfulStatus)

t.RunSequentiallyWithTimeout("repair size in case of no blobber failure should be zero", 5*time.Minute, func(t *test.SystemTest) {
// create allocation with default blobber requirements
Expand Down
1 change: 0 additions & 1 deletion tests/api_tests/replace_blobber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func TestReplaceBlobber(testSetup *testing.T) {
sdkClient.MultiOperation(t, allocationID, []sdk.OperationRequest{uploadOp})

allocation := apiClient.GetAllocation(t, allocationID, client.HttpOkStatus)
apiClient.CreateReadPool(t, wallet, 1.0, client.TxSuccessfulStatus)

oldBlobberID := getFirstUsedStorageNodeID(allocationBlobbers.Blobbers, allocation.Blobbers)
require.NotZero(t, oldBlobberID, "Old blobber ID contains zero value")
Expand Down
2 changes: 1 addition & 1 deletion tests/cli_tests/0_challenge_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestProtocolChallenge(testSetup *testing.T) {
})

t.RunWithTimeout("Number of challenges between 2 blocks should be equal to the number of blocks after challenge_generation_gap (given that we have active allocations)", 10*time.Minute, func(t *test.SystemTest) {
allocationId := setupAllocationAndReadLock(t, configPath, map[string]interface{}{
allocationId := setupAllocation(t, configPath, map[string]interface{}{
"size": 10 * MB,
"tokens": 9,
})
Expand Down
2 changes: 1 addition & 1 deletion tests/cli_tests/0_expired_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestExpiredAllocation(testSetup *testing.T) {
filesize := int64(256)
remotepath := "/"

allocationID := setupAllocationAndReadLock(t, configPath, map[string]interface{}{
allocationID := setupAllocation(t, configPath, map[string]interface{}{
"size": allocSize,
"tokens": 9,
})
Expand Down
4 changes: 2 additions & 2 deletions tests/cli_tests/config/zbox_config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
block_worker: https://dev.zus.network/dns
block_worker: https://dev-st.devnet-0chain.net/dns
confirmation_chain_length: 3
ethereum_node_url: "https://rpc.tenderly.co/fork/5b7ffac9-50cc-4169-b0ca-6fd203d26ef6"
ethereum_node_url: "https://virtual.mainnet.rpc.tenderly.co/1b2b3323-9a80-49c3-a2ff-50efb7afb359"
min_confirmation: 50
min_submit: 50
signature_scheme: bls0chain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ func TestCreateAllocationFreeStorage(testSetup *testing.T) {
allocation := getAllocation(t, allocationID)
require.Equal(t, ConvertToValue(wantWritePoolToken), allocation.WritePool, "Expected write pool amount not met", strings.Join(output, "\n"))
require.Equal(t, uint16(63), allocation.FileOptions, "Expected file_options to be 63 (all allowed) by default", strings.Join(output, "\n"))

readPool := getReadPoolInfo(t)
require.Equal(t, ConvertToValue(wantReadPoolFraction), readPool.Balance, "Read Pool balance must be equal to locked amount")
})

t.Run("Create free storage with malformed marker should fail", func(t *test.SystemTest) {
Expand Down
15 changes: 0 additions & 15 deletions tests/cli_tests/zboxcli_download_livestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex

require.Nil(t, err, "error creating allocation", strings.Join(output, "\n"))

_, err = readPoolLock(t, configPath, createParams(map[string]interface{}{
"tokens": 1,
}), true)
require.Nil(t, err, "error")

require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]

Expand Down Expand Up @@ -198,11 +193,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex
t.Log(output)
require.Nil(t, err, "error creating allocation", strings.Join(output, "\n"))

_, err = readPoolLock(t, configPath, createParams(map[string]interface{}{
"tokens": 1,
}), true)
require.Nil(t, err, "error")

require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]

Expand Down Expand Up @@ -352,11 +342,6 @@ func TestLivestreamDownload(testSetup *testing.T) { // nolint cyclomatic complex
t.Log(output)
require.Nil(t, err, "error creating allocation", strings.Join(output, "\n"))

_, err = readPoolLock(t, configPath, createParams(map[string]interface{}{
"tokens": 1,
}), true)
require.Nil(t, err, "error")

require.Regexp(t, regexp.MustCompile("Allocation created: ([a-f0-9]{64})"), output[0], "Allocation creation output did not match expected")
allocationID := strings.Fields(output[0])[2]

Expand Down
Loading
Loading