From 7cf075220722c1bfcfcbaf1532c329e168398549 Mon Sep 17 00:00:00 2001 From: Maulik Singhal <69348454+smaulik13@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:18:02 +0530 Subject: [PATCH 01/24] Revert "Revert "gosdk methods directing to 0box"" --- core/client/http.go | 13 +++--- core/client/init_node.go | 5 +++ core/client/set.go | 27 +++++++++++ core/conf/vars.go | 5 +++ core/screstapi/http.go | 86 ++++++++++++++++++++++++++++++++++++ core/transaction/get_data.go | 3 +- mobilesdk/sdk/sdk.go | 17 ++++--- wasmsdk/sdk.go | 20 ++++++++- wasmsdk/zcn.go | 4 +- winsdk/wallet.go | 5 ++- zboxapi/sdk.go | 33 +++++++++++++- zboxcore/fileref/fileref.go | 1 + zboxcore/logger/logger.go | 4 +- zboxcore/sdk/listworker.go | 4 ++ zboxcore/sdk/rollback.go | 84 +++++++++++++++++++++++++++++++++++ zboxcore/sdk/sdk.go | 44 +++++++++--------- zcnbridge/rest.go | 7 +-- zcncore/get_data.go | 21 ++++----- zcncore/wallet_mobile.go | 3 +- 19 files changed, 330 insertions(+), 56 deletions(-) create mode 100644 core/screstapi/http.go diff --git a/core/client/http.go b/core/client/http.go index 744ce0d4b..4572b366e 100644 --- a/core/client/http.go +++ b/core/client/http.go @@ -3,14 +3,15 @@ package client import ( "encoding/json" "fmt" - "github.com/0chain/errors" - "github.com/0chain/gosdk/core/conf" - "github.com/0chain/gosdk/core/util" - "github.com/shopspring/decimal" "log" "net/http" "net/url" "sync" + + "github.com/0chain/errors" + "github.com/0chain/gosdk/core/conf" + "github.com/0chain/gosdk/core/util" + "github.com/shopspring/decimal" ) // SCRestAPIHandler is a function type to handle the response from the SC Rest API @@ -20,7 +21,7 @@ import ( // `err` - the error if any type SCRestAPIHandler func(response map[string][]byte, numSharders int, err error) -func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) { +func MakeSCRestAPICallToSharder(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) ([]byte, error) { const ( consensusThresh = float32(25.0) ScRestApiUrl = "v1/screst/" @@ -159,7 +160,7 @@ func GetBalance(clientIDs ...string) (*GetBalanceResponse, error) { clientID = Id() } - if res, err = MakeSCRestAPICall("", GetBalance, map[string]string{ + if res, err = MakeSCRestAPICallToSharder("", GetBalance, map[string]string{ "client_id": clientID, }, "v1/"); err != nil { return nil, err diff --git a/core/client/init_node.go b/core/client/init_node.go index 444b33834..d356f2071 100644 --- a/core/client/init_node.go +++ b/core/client/init_node.go @@ -20,6 +20,7 @@ import ( var ( logging = logger.GetLogger() nodeClient *Node + IsAppFlow = false ) // Node Maintains central states of SDK (client's context, network). @@ -34,6 +35,10 @@ type Node struct { networkGuard sync.RWMutex } +func SetIsAppFlow(val bool) { + IsAppFlow = true +} + // GetStableMiners Returns stable miner urls. // Length of stable miners is depedent on config's MinSubmit and number of miners in network. func (n *Node) GetStableMiners() []string { diff --git a/core/client/set.go b/core/client/set.go index 1c72c0625..7aff4e528 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -36,6 +36,23 @@ type Client struct { sign SignFunc } +type InitSdkOptions struct { + WalletJSON string + BlockWorker string + ChainID string + SignatureScheme string + Nonce int64 + IsSplitWallet bool + AddWallet bool + TxnFee *int + MinConfirmation *int + MinSubmit *int + ConfirmationChainLength *int + SharderConsensous *int + ZboxHost string + ZboxAppType string +} + func init() { sys.Sign = signHash sys.SignWithAuth = signHashWithAuth @@ -362,6 +379,16 @@ func InitSDK(walletJSON string, return nil } +func InitSDKWithWebApp(params InitSdkOptions) error { + err := InitSDK(params.WalletJSON, params.BlockWorker, params.ChainID, params.SignatureScheme, params.Nonce, params.AddWallet, *params.MinConfirmation, *params.MinSubmit, *params.ConfirmationChainLength, *params.SharderConsensous) + if err != nil { + return err + } + conf.SetZboxAppConfigs(params.ZboxHost, params.ZboxAppType) + SetIsAppFlow(true) + return nil +} + func IsSDKInitialized() bool { return sdkInitialized } diff --git a/core/conf/vars.go b/core/conf/vars.go index 8551c1cd9..e31cbcd8f 100644 --- a/core/conf/vars.go +++ b/core/conf/vars.go @@ -39,6 +39,11 @@ func GetClientConfig() (*Config, error) { return cfg, nil } +func SetZboxAppConfigs(zboxHost, zboxAppType string) { + cfg.ZboxHost = zboxHost + cfg.ZboxAppType = zboxAppType +} + // InitClientConfig set global client config func InitClientConfig(c *Config) { onceCfg.Do(func() { diff --git a/core/screstapi/http.go b/core/screstapi/http.go new file mode 100644 index 000000000..53f5823b5 --- /dev/null +++ b/core/screstapi/http.go @@ -0,0 +1,86 @@ +package screstapi + +import ( + "context" + "encoding/json" + + "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/conf" + "github.com/0chain/gosdk/zboxapi" +) + +var urlPathSharderToZboxMap = map[string]string{ + "/getStakePoolStat": "/getStakePoolStat", + "/getUserStakePoolStat": "/getUserStakePoolStat", + "/getChallengePoolStat": "/getChallengePoolStat", + "/getBlobber": "/blobber", + "/getblobbers": "/blobbers", + "/blobber_ids": "/blobber_ids", + "/alloc_blobbers": "/blobbers/allocation", + "/get_validator": "/validator", + "/validators": "/validators", + "/allocation": "/getAllocation", + "/allocations": "/getAllocations", + "/v1/mint_nonce": "/mintNonce", + "client/get/balance": "/balance", + "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", +} + +func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { + _, ok := urlPathSharderToZboxMap[relativePath] + if client.IsAppFlow && ok { + resp, err = MakeSCRestAPICallToZbox(urlPathSharderToZboxMap[relativePath], params) + if err != nil { + resp, err = client.MakeSCRestAPICallToSharder(scAddress, relativePath, params, restApiUrls...) + } + } else { + resp, err = client.MakeSCRestAPICallToSharder(scAddress, relativePath, params, restApiUrls...) + } + + return resp, err +} + +func MakeSCRestAPICallToZbox(relativePath string, params map[string]string) ([]byte, error) { + // req, err := http.NewRequest(method, relativePath) + zboxApiClient := zboxapi.NewClient() + configObj, err := conf.GetClientConfig() + if err != nil { + return nil, err + } + zboxApiClient.SetRequest(configObj.ZboxHost, configObj.ZboxAppType) + + resp, err := zboxApiClient.MakeRestApiCallToZbox(context.TODO(), relativePath, params) + if err != nil { + return nil, err + } + + return resp, nil +} + +func GetBalance(clientIDs ...string) (*client.GetBalanceResponse, error) { + var clientID string + if len(clientIDs) > 0 { + clientID = clientIDs[0] + } else { + clientID = client.Id() + } + + const GetBalanceUrl = "client/get/balance" + var ( + balance client.GetBalanceResponse + err error + resp []byte + ) + + if resp, err = MakeSCRestAPICall("", GetBalanceUrl, map[string]string{ + "client_id": clientID, + }, "v1/"); err != nil { + return nil, err + } + + if err = json.Unmarshal(resp, &balance); err != nil { + return nil, err + } + + return &balance, err +} diff --git a/core/transaction/get_data.go b/core/transaction/get_data.go index cf7a60065..7ac58359a 100644 --- a/core/transaction/get_data.go +++ b/core/transaction/get_data.go @@ -2,6 +2,7 @@ package transaction import ( "encoding/json" + "github.com/0chain/errors" coreHttp "github.com/0chain/gosdk/core/client" ) @@ -45,7 +46,7 @@ func GetConfig(configType string) (conf *InputMap, err error) { relativePath = GET_MINERSC_CONFIGS } - b, err = coreHttp.MakeSCRestAPICall(scAddress, relativePath, nil) + b, err = coreHttp.MakeSCRestAPICallToSharder(scAddress, relativePath, nil) if err != nil { return nil, errors.Wrap(err, "error requesting storage SC configs:") } diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index f319cf968..f5dd299c8 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -125,11 +125,18 @@ func InitStorageSDK(clientJson string, configJson string) (*StorageSDK, error) { l.Logger.Info(configObj.ChainID) l.Logger.Info(configObj.SignatureScheme) l.Logger.Info(configObj.PreferredBlobbers) - if err = client.InitSDK(clientJson, - configObj.BlockWorker, - configObj.ChainID, - configObj.SignatureScheme, - 0, true); err != nil { + params := client.InitSdkOptions{ + WalletJSON: clientJson, + BlockWorker: configObj.BlockWorker, + ChainID: configObj.ChainID, + SignatureScheme: configObj.SignatureScheme, + Nonce: int64(0), + AddWallet: true, + ZboxHost: configObj.ZboxHost, + ZboxAppType: configObj.ZboxAppType, + } + + if err = client.InitSDKWithWebApp(params); err != nil { l.Logger.Error(err) return nil, err } diff --git a/wasmsdk/sdk.go b/wasmsdk/sdk.go index c0b78a2b6..07f9974ad 100644 --- a/wasmsdk/sdk.go +++ b/wasmsdk/sdk.go @@ -12,6 +12,7 @@ import ( "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/core/imageutil" "github.com/0chain/gosdk/core/logger" + "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/zboxcore/sdk" "github.com/0chain/gosdk/zcncore" @@ -40,7 +41,22 @@ func initSDKs(chainID, blockWorker, signatureScheme string, zboxApiClient.SetRequest(zboxHost, zboxAppType) - err := client.InitSDK("{}", blockWorker, chainID, signatureScheme, 0, false, minConfirmation, minSubmit, confirmationChainLength, sharderConsensous) + params := client.InitSdkOptions{ + WalletJSON: "{}", + BlockWorker: blockWorker, + ChainID: chainID, + SignatureScheme: signatureScheme, + Nonce: int64(0), + AddWallet: false, + MinConfirmation: &minConfirmation, + MinSubmit: &minSubmit, + SharderConsensous: &sharderConsensous, + ConfirmationChainLength: &confirmationChainLength, + ZboxHost: zboxHost, + ZboxAppType: zboxAppType, + } + + err := client.InitSDKWithWebApp(params) if err != nil { fmt.Println("wasm: InitStorageSDK ", err) return err @@ -146,7 +162,7 @@ func makeSCRestAPICall(scAddress, relativePath, paramsJson string) (string, erro if err != nil { sdkLogger.Error(fmt.Sprintf("Error parsing JSON: %v", err)) } - b, err := client.MakeSCRestAPICall(scAddress, relativePath, params) + b, err := screstapi.MakeSCRestAPICall(scAddress, relativePath, params) return string(b), err } diff --git a/wasmsdk/zcn.go b/wasmsdk/zcn.go index bb3a53a3d..f0272e4b5 100644 --- a/wasmsdk/zcn.go +++ b/wasmsdk/zcn.go @@ -4,7 +4,7 @@ package main import ( - "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/zcncore" ) @@ -17,7 +17,7 @@ type Balance struct { // getWalletBalance retrieves the wallet balance of the client from the network. // - clientId is the client id func getWalletBalance(clientId string) (*Balance, error) { - bal, err := client.GetBalance(clientId) + bal, err := screstapi.GetBalance(clientId) if err != nil { return nil, err } diff --git a/winsdk/wallet.go b/winsdk/wallet.go index 0e72008f8..51762ea61 100644 --- a/winsdk/wallet.go +++ b/winsdk/wallet.go @@ -8,10 +8,11 @@ import ( ) import ( - "github.com/0chain/gosdk/core/client" "os" "path/filepath" + "github.com/0chain/gosdk/core/screstapi" + "github.com/0chain/gosdk/zcncore" ) @@ -87,7 +88,7 @@ func RecoverWallet(mnemonic *C.char) *C.char { // //export GetWalletBalance func GetWalletBalance(clientID *C.char) *C.char { - b, err := client.GetBalance(C.GoString(clientID)) + b, err := screstapi.GetBalance(C.GoString(clientID)) if err != nil { log.Error("win: ", err) return WithJSON(0, err) diff --git a/zboxapi/sdk.go b/zboxapi/sdk.go index 0ac6e7064..270e18c63 100644 --- a/zboxapi/sdk.go +++ b/zboxapi/sdk.go @@ -6,11 +6,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/0chain/gosdk/core/client" + "io" "net/http" + "net/url" "strconv" "time" + "github.com/0chain/gosdk/core/client" + thrown "github.com/0chain/errors" "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/core/logger" @@ -371,3 +374,31 @@ func (c *Client) GetSharedToMe(ctx context.Context, phoneNumber, token string) ( return result.Data, nil } + +func (c *Client) MakeRestApiCallToZbox(ctx context.Context, relativePath string, params map[string]string) ([]byte, error) { + urlPath := c.baseUrl + "/v2" + relativePath + u, err := url.Parse(urlPath) + if err != nil { + return nil, fmt.Errorf("error parsing URL: %w", err) + } + + // Add query parameters + q := u.Query() + for key, value := range params { + q.Add(key, value) + } + u.RawQuery = q.Encode() + + resp, err := http.Get(u.String()) + if err != nil { + return nil, fmt.Errorf("error making GET request: %w", err) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("error reading response body: %w", err) + } + resp.Body.Close() + + return body, nil +} diff --git a/zboxcore/fileref/fileref.go b/zboxcore/fileref/fileref.go index a1c082d5e..3f226777a 100644 --- a/zboxcore/fileref/fileref.go +++ b/zboxcore/fileref/fileref.go @@ -106,6 +106,7 @@ type Ref struct { AllocationRoot string `json:"allocation_root" mapstructure:"allocation_root"` CreatedAt common.Timestamp `json:"created_at" mapstructure:"created_at"` UpdatedAt common.Timestamp `json:"updated_at" mapstructure:"updated_at"` + NumFiles int `json:"num_files" mapstructure:"num_files"` } // GetReferenceLookup returns the lookup hash for a given allocationID and path diff --git a/zboxcore/logger/logger.go b/zboxcore/logger/logger.go index 64134eb35..0a78ddab7 100644 --- a/zboxcore/logger/logger.go +++ b/zboxcore/logger/logger.go @@ -1,7 +1,9 @@ // Proxy for the core logger package. package logger -import "github.com/0chain/gosdk/core/logger" +import ( + "github.com/0chain/gosdk/core/logger" +) // Logger global logger instance var Logger = logger.GetLogger() diff --git a/zboxcore/sdk/listworker.go b/zboxcore/sdk/listworker.go index d8944557d..a46e30f9b 100644 --- a/zboxcore/sdk/listworker.go +++ b/zboxcore/sdk/listworker.go @@ -69,6 +69,7 @@ type ListResult struct { ThumbnailSize int64 `json:"thumbnail_size"` ActualThumbnailHash string `json:"actual_thumbnail_hash"` ActualThumbnailSize int64 `json:"actual_thumbnail_size"` + NumFiles int `json:"num_files"` CreatedAt common.Timestamp `json:"created_at"` UpdatedAt common.Timestamp `json:"updated_at"` @@ -266,6 +267,9 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) { result.ThumbnailSize = ti.ref.ThumbnailSize result.ActualThumbnailHash = ti.ref.ActualThumbnailHash result.ActualThumbnailSize = ti.ref.ActualThumbnailSize + if result.Path == "/" && req.storageVersion == StorageV2 { + result.NumFiles = ti.ref.NumFiles + } if ti.ref.ActualSize > 0 { result.ActualNumBlocks = (ti.ref.ActualSize + CHUNK_SIZE - 1) / CHUNK_SIZE diff --git a/zboxcore/sdk/rollback.go b/zboxcore/sdk/rollback.go index f623dbc63..6d1607c44 100644 --- a/zboxcore/sdk/rollback.go +++ b/zboxcore/sdk/rollback.go @@ -316,6 +316,10 @@ func (a *Allocation) CheckAllocStatus() (AllocStatus, []BlobberStatus, error) { return Broken, blobberRes, common.NewError("check_alloc_status_failed", markerError.Error()) } + if a.StorageVersion == StorageV2 { + return a.checkStatusV2(markerChan, blobberRes) + } + versionMap := make(map[string][]*RollbackBlobber) var ( @@ -472,3 +476,83 @@ func (a *Allocation) RollbackWithMask(mask zboxutil.Uint128) { wg.Wait() } + +func (a *Allocation) checkStatusV2(markerChan chan *RollbackBlobber, blobStatus []BlobberStatus) (AllocStatus, []BlobberStatus, error) { + var ( + latestVersionMap = make(map[string][]*RollbackBlobber) + allVersionMap = make(map[string][]*RollbackBlobber) + consensusVersion string + allVersionConensus string + ) + + for rb := range markerChan { + if rb == nil || rb.lpm.LatestWM == nil { + continue + } + version := rb.lpm.LatestWM.AllocationRoot + latestVersionMap[version] = append(latestVersionMap[version], rb) + if len(latestVersionMap[version]) > a.DataShards { + consensusVersion = version + } + allVersionMap[version] = append(allVersionMap[version], rb) + if rb.lpm.PrevWM != nil && rb.lpm.PrevWM.AllocationRoot != version { + allVersionMap[rb.lpm.PrevWM.AllocationRoot] = append(allVersionMap[rb.lpm.PrevWM.AllocationRoot], rb) + if len(allVersionMap[rb.lpm.PrevWM.AllocationRoot]) >= a.DataShards { + allVersionConensus = rb.lpm.PrevWM.AllocationRoot + } + } + if len(allVersionMap[version]) >= a.DataShards { + allVersionConensus = version + } + } + + if consensusVersion != "" { + a.allocationRoot = consensusVersion + return Commit, blobStatus, nil + } + + if allVersionConensus == "" { + if len(latestVersionMap) == 0 { + return Commit, blobStatus, nil + } + return Broken, blobStatus, nil + } + + if len(latestVersionMap[allVersionConensus]) >= a.DataShards { + a.allocationRoot = allVersionConensus + return Repair, blobStatus, nil + } + l.Logger.Info("Rolling back to previous version") + fullConsensus := len(allVersionMap[allVersionConensus]) - len(latestVersionMap[allVersionConensus]) + consensusThresh := a.DataShards - len(latestVersionMap[allVersionConensus]) + var successCnt int32 + wg := &sync.WaitGroup{} + + for _, rb := range allVersionMap[allVersionConensus] { + if rb.lpm.LatestWM.AllocationRoot == allVersionConensus { + continue + } + wg.Add(1) + go func(rb *RollbackBlobber) { + defer wg.Done() + err := rb.processRollback(context.TODO(), a.Tx) + if err != nil { + rb.commitResult = ErrorCommitResult(err.Error()) + l.Logger.Error("error during rollback", zap.Error(err)) + } else { + atomic.AddInt32(&successCnt, 1) + rb.commitResult = SuccessCommitResult() + } + }(rb) + } + wg.Wait() + if successCnt < int32(consensusThresh) { + return Broken, blobStatus, common.NewError("rollback_failed", "Rollback failed") + } + a.allocationRoot = allVersionConensus + if successCnt == int32(fullConsensus) { + return Repair, blobStatus, nil + } + + return Commit, blobStatus, nil +} diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 40fdb954b..a8e3934fb 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -12,6 +12,7 @@ import ( "github.com/0chain/common/core/currency" "github.com/0chain/errors" "github.com/0chain/gosdk/core/logger" + "github.com/0chain/gosdk/core/screstapi" "gopkg.in/natefinch/lumberjack.v2" "github.com/0chain/gosdk/core/client" @@ -163,7 +164,7 @@ func GetStakePoolInfo(providerType ProviderType, providerID string) (info *Stake } var b []byte - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getStakePoolStat", + b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getStakePoolStat", map[string]string{"provider_type": strconv.Itoa(int(providerType)), "provider_id": providerID}) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool info:") @@ -204,7 +205,7 @@ func GetStakePoolUserInfo(clientID string, offset, limit int) (info *StakePoolUs "offset": strconv.FormatInt(int64(offset), 10), "limit": strconv.FormatInt(int64(limit), 10), } - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getUserStakePoolStat", params) if err != nil { return nil, errors.Wrap(err, "error requesting stake pool user info:") @@ -257,7 +258,7 @@ func GetChallengePoolInfo(allocID string) (info *ChallengePoolInfo, err error) { } var b []byte - b, err = client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err = screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getChallengePoolStat", map[string]string{"allocation_id": allocID}) if err != nil { return nil, errors.Wrap(err, "error requesting challenge pool info:") @@ -281,7 +282,7 @@ func GetMptData(key string) ([]byte, error) { } var b []byte - b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, + b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/get_mpt_key", map[string]string{"key": key}, ) if err != nil { @@ -447,13 +448,9 @@ func getBlobbersInternal(active, stakable bool, limit, offset int) (bs []*Blobbe Nodes []*Blobber } - url := fmt.Sprintf("/getblobbers?active=%s&limit=%d&offset=%d&stakable=%s", - strconv.FormatBool(active), - limit, - offset, - strconv.FormatBool(stakable), - ) - b, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, url, nil) + b, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/getblobbers", map[string]string{"active": strconv.FormatBool(active), "limit": strconv.FormatInt(int64(limit), 10), + "offset": strconv.FormatInt(int64(offset), 10), + "stakable": strconv.FormatBool(stakable)}) var wrap nodes if err != nil { return nil, errors.Wrap(err, "error requesting blobbers:") @@ -511,7 +508,7 @@ func GetBlobber(blobberID string) (blob *Blobber, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/getBlobber", map[string]string{"blobber_id": blobberID}, @@ -536,7 +533,7 @@ func GetValidator(validatorID string) (validator *Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/get_validator", map[string]string{"validator_id": validatorID}, @@ -561,7 +558,7 @@ func GetValidators(stakable bool) (validators []*Validator, err error) { return nil, sdkNotInitialized } var b []byte - b, err = client.MakeSCRestAPICall( + b, err = screstapi.MakeSCRestAPICall( STORAGE_SCADDRESS, "/validators", map[string]string{ @@ -625,10 +622,11 @@ func GetAllocation(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } + allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -646,10 +644,11 @@ func GetAllocationForUpdate(allocationID string) (*Allocation, error) { } params := make(map[string]string) params["allocation"] = allocationID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } + allocationObj := &Allocation{} err = json.Unmarshal(allocationBytes, allocationObj) if err != nil { @@ -665,7 +664,7 @@ func GetAllocationUpdates(allocation *Allocation) error { params := make(map[string]string) params["allocation"] = allocation.ID - allocationBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } @@ -718,10 +717,11 @@ func getAllocationsInternal(clientID string, limit, offset int) ([]*Allocation, params["client"] = clientID params["limit"] = fmt.Sprint(limit) params["offset"] = fmt.Sprint(offset) - allocationsBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) + allocationsBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocations", params) if err != nil { return nil, errors.New("allocations_fetch_error", "Error fetching the allocations."+err.Error()) } + allocations := make([]*Allocation, 0) err = json.Unmarshal(allocationsBytes, &allocations) if err != nil { @@ -848,7 +848,7 @@ func GetAllocationBlobbers( params["force"] = strconv.FormatBool(force[0]) } - allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) + allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/alloc_blobbers", params) if err != nil { return nil, err } @@ -935,7 +935,7 @@ func GetBlobberIds(blobberUrls []string) ([]string, error) { params := make(map[string]string) params["blobber_urls"] = string(urlsStr) - idsStr, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) + idsStr, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/blobber_ids", params) if err != nil { return nil, err } @@ -960,7 +960,7 @@ func GetFreeAllocationBlobbers(request map[string]interface{}) ([]string, error) params := make(map[string]string) params["free_allocation_data"] = string(data) - allocBlobber, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) + allocBlobber, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/free_alloc_blobbers", params) if err != nil { return nil, err } @@ -1406,7 +1406,7 @@ func GetUpdateAllocationMinLock( params := make(map[string]string) params["data"] = string(data) - responseBytes, err := client.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) + responseBytes, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation-update-min-lock", params) if err != nil { return 0, errors.Wrap(err, "failed to request allocation update min lock") } diff --git a/zcnbridge/rest.go b/zcnbridge/rest.go index ab860b16d..f5c12241f 100644 --- a/zcnbridge/rest.go +++ b/zcnbridge/rest.go @@ -3,6 +3,7 @@ package zcnbridge import ( "encoding/json" "fmt" + coreHttp "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" @@ -88,7 +89,7 @@ func GetAuthorizer(id string) (res []byte, err error) { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetAuthorizer, zcncore.Params{ "id": id, }) } @@ -101,7 +102,7 @@ func GetAuthorizers(active bool) (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, fmt.Sprintf(PathGetAuthorizerNodes, active), nil) } // GetGlobalConfig Returns global config @@ -111,5 +112,5 @@ func GetGlobalConfig() (res []byte, err error) { if err != nil { return nil, err } - return coreHttp.MakeSCRestAPICall(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) + return coreHttp.MakeSCRestAPICallToSharder(zcncore.ZCNSCSmartContractAddress, PathGetGlobalConfig, nil) } diff --git a/zcncore/get_data.go b/zcncore/get_data.go index d5a7eeaba..96ad74878 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -10,6 +10,7 @@ import ( "github.com/0chain/gosdk/core/block" "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/sys" "github.com/0chain/gosdk/core/tokenrate" "github.com/0chain/gosdk/core/util" @@ -213,7 +214,7 @@ func withParams(uri string, params Params) string { //nolint:unused // return // } // -// return coreHttp.MakeSCRestAPICall(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ +// return coreHttp.MakeSCRestAPICallToSharder(StorageSmartContractAddress, STORAGE_GET_BLOBBER_SNAPSHOT, Params{ // "round": strconv.FormatInt(round, 10), // "limit": strconv.FormatInt(limit, 10), // "offset": strconv.FormatInt(offset, 10), @@ -228,7 +229,7 @@ func GetMinerSCNodeInfo(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_NODE, Params{ "id": id, }) } @@ -241,7 +242,7 @@ func GetMintNonce() ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ + return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_MINT_NONCE, Params{ "client_id": client.Id(), }) } @@ -251,7 +252,7 @@ func GetMiners(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_MINERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -264,7 +265,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_SHARDERS, Params{ "active": strconv.FormatBool(active), "stakable": strconv.FormatBool(stakable), "offset": strconv.FormatInt(int64(offset), 10), @@ -276,7 +277,7 @@ func GetSharders(active, stakable bool, limit, offset int) ([]byte, error) { // - numSharders: number of sharders // - timeout: request timeout func GetLatestFinalizedMagicBlock() (m *block.MagicBlock, err error) { - res, err := client.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") + res, err := screstapi.MakeSCRestAPICall("", GET_LATEST_FINALIZED_MAGIC_BLOCK, nil, "") if err != nil { return nil, err } @@ -305,7 +306,7 @@ func GetMinerSCUserInfo(clientID string) ([]byte, error) { clientID = client.Id() } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_USER, Params{ "client_id": clientID, }) } @@ -317,7 +318,7 @@ func GetMinerSCNodePool(id string) ([]byte, error) { return nil, err } - return client.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ + return screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_MINERSC_POOL, Params{ "id": id, "pool_id": client.Id(), }) @@ -335,7 +336,7 @@ func GetNotProcessedZCNBurnTickets(ethereumAddress, startNonce string) ([]byte, const GET_NOT_PROCESSED_BURN_TICKETS = `/v1/not_processed_burn_tickets` - return client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ + return screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_NOT_PROCESSED_BURN_TICKETS, Params{ "ethereum_address": ethereumAddress, "nonce": startNonce, }) @@ -354,7 +355,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { const GET_USER_LOCKED_TOTAL = `/v1/getUserLockedTotal` - info, err := client.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ + info, err := screstapi.MakeSCRestAPICall(ZCNSCSmartContractAddress, GET_USER_LOCKED_TOTAL, Params{ "client_id": clientID, }) diff --git a/zcncore/wallet_mobile.go b/zcncore/wallet_mobile.go index 7fd9b0564..b84955efd 100644 --- a/zcncore/wallet_mobile.go +++ b/zcncore/wallet_mobile.go @@ -5,6 +5,7 @@ package zcncore import ( "github.com/0chain/gosdk/core/client" + "github.com/0chain/gosdk/core/screstapi" "github.com/0chain/gosdk/core/zcncrypto" ) @@ -31,7 +32,7 @@ func (w *wallet) Sign(hash string) (string, error) { // GetWalletBalance retrieve wallet balance from sharders // - id: client id func GetWalletBalance(id string) (int64, error) { - response, err := client.GetBalance(id) + response, err := screstapi.GetBalance(id) if err != nil { return 0, err } From 2ddc5445575ecc3e99feec808324b8772f9a1f85 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Thu, 6 Feb 2025 12:58:19 +0530 Subject: [PATCH 02/24] fix --- zcncore/get_data.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zcncore/get_data.go b/zcncore/get_data.go index 96ad74878..d346a550b 100644 --- a/zcncore/get_data.go +++ b/zcncore/get_data.go @@ -377,7 +377,7 @@ func GetUserLockedTotal(clientID string) (int64, error) { } func IsHardforkActivated(name string) (bool, error) { - res, err := client.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ + res, err := screstapi.MakeSCRestAPICall(MinerSmartContractAddress, GET_HARDFORK, Params{ "name": name, }) if err != nil { @@ -409,7 +409,7 @@ func IsHardforkActivated(name string) (bool, error) { } func GetCurrentRound() (int64, error) { - res, err := client.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") + res, err := screstapi.MakeSCRestAPICall("", GET_CURRENT_ROUND, nil, "") if err != nil { return 0, err } From a2457de40a9a877c77135af4aed8763b6fac3342 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 02:00:57 +0530 Subject: [PATCH 03/24] removed extra changes --- core/screstapi/http.go | 22 +++++----- zboxcore/sdk/listworker.go | 5 +-- zboxcore/sdk/rollback.go | 86 +------------------------------------- 3 files changed, 13 insertions(+), 100 deletions(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 53f5823b5..912e73703 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -10,20 +10,20 @@ import ( ) var urlPathSharderToZboxMap = map[string]string{ - "/getStakePoolStat": "/getStakePoolStat", - "/getUserStakePoolStat": "/getUserStakePoolStat", - "/getChallengePoolStat": "/getChallengePoolStat", - "/getBlobber": "/blobber", - "/getblobbers": "/blobbers", - "/blobber_ids": "/blobber_ids", - "/alloc_blobbers": "/blobbers/allocation", - "/get_validator": "/validator", - "/validators": "/validators", - "/allocation": "/getAllocation", - "/allocations": "/getAllocations", + "/getStakePoolStat": "/getStakePoolStat", + "/getUserStakePoolStat": "/getUserStakePoolStat", + "/getChallengePoolStat": "/getChallengePoolStat", + "/getBlobber": "/blobber", + "/getblobbers": "/blobbers", + "/blobber_ids": "/blobber_ids", + "/alloc_blobbers": "/blobbers/allocation", + "/get_validator": "/validator", + "/validators": "/validators", "/v1/mint_nonce": "/mintNonce", "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", + // "/allocation": "/getAllocation", + // "/allocations": "/getAllocations", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { diff --git a/zboxcore/sdk/listworker.go b/zboxcore/sdk/listworker.go index a46e30f9b..35f3ec0ca 100644 --- a/zboxcore/sdk/listworker.go +++ b/zboxcore/sdk/listworker.go @@ -267,14 +267,11 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) { result.ThumbnailSize = ti.ref.ThumbnailSize result.ActualThumbnailHash = ti.ref.ActualThumbnailHash result.ActualThumbnailSize = ti.ref.ActualThumbnailSize - if result.Path == "/" && req.storageVersion == StorageV2 { - result.NumFiles = ti.ref.NumFiles - } if ti.ref.ActualSize > 0 { result.ActualNumBlocks = (ti.ref.ActualSize + CHUNK_SIZE - 1) / CHUNK_SIZE } - result.Size += ti.ref.Size + result.Size += ti.ref.Size result.NumBlocks += ti.ref.NumBlocks if ti.ref.Path == "/" && result.ActualSize == 0 { result.ActualSize = ti.ref.Size * int64(req.dataShards) diff --git a/zboxcore/sdk/rollback.go b/zboxcore/sdk/rollback.go index 6d1607c44..61fbefdb4 100644 --- a/zboxcore/sdk/rollback.go +++ b/zboxcore/sdk/rollback.go @@ -316,10 +316,6 @@ func (a *Allocation) CheckAllocStatus() (AllocStatus, []BlobberStatus, error) { return Broken, blobberRes, common.NewError("check_alloc_status_failed", markerError.Error()) } - if a.StorageVersion == StorageV2 { - return a.checkStatusV2(markerChan, blobberRes) - } - versionMap := make(map[string][]*RollbackBlobber) var ( @@ -475,84 +471,4 @@ func (a *Allocation) RollbackWithMask(mask zboxutil.Uint128) { } wg.Wait() -} - -func (a *Allocation) checkStatusV2(markerChan chan *RollbackBlobber, blobStatus []BlobberStatus) (AllocStatus, []BlobberStatus, error) { - var ( - latestVersionMap = make(map[string][]*RollbackBlobber) - allVersionMap = make(map[string][]*RollbackBlobber) - consensusVersion string - allVersionConensus string - ) - - for rb := range markerChan { - if rb == nil || rb.lpm.LatestWM == nil { - continue - } - version := rb.lpm.LatestWM.AllocationRoot - latestVersionMap[version] = append(latestVersionMap[version], rb) - if len(latestVersionMap[version]) > a.DataShards { - consensusVersion = version - } - allVersionMap[version] = append(allVersionMap[version], rb) - if rb.lpm.PrevWM != nil && rb.lpm.PrevWM.AllocationRoot != version { - allVersionMap[rb.lpm.PrevWM.AllocationRoot] = append(allVersionMap[rb.lpm.PrevWM.AllocationRoot], rb) - if len(allVersionMap[rb.lpm.PrevWM.AllocationRoot]) >= a.DataShards { - allVersionConensus = rb.lpm.PrevWM.AllocationRoot - } - } - if len(allVersionMap[version]) >= a.DataShards { - allVersionConensus = version - } - } - - if consensusVersion != "" { - a.allocationRoot = consensusVersion - return Commit, blobStatus, nil - } - - if allVersionConensus == "" { - if len(latestVersionMap) == 0 { - return Commit, blobStatus, nil - } - return Broken, blobStatus, nil - } - - if len(latestVersionMap[allVersionConensus]) >= a.DataShards { - a.allocationRoot = allVersionConensus - return Repair, blobStatus, nil - } - l.Logger.Info("Rolling back to previous version") - fullConsensus := len(allVersionMap[allVersionConensus]) - len(latestVersionMap[allVersionConensus]) - consensusThresh := a.DataShards - len(latestVersionMap[allVersionConensus]) - var successCnt int32 - wg := &sync.WaitGroup{} - - for _, rb := range allVersionMap[allVersionConensus] { - if rb.lpm.LatestWM.AllocationRoot == allVersionConensus { - continue - } - wg.Add(1) - go func(rb *RollbackBlobber) { - defer wg.Done() - err := rb.processRollback(context.TODO(), a.Tx) - if err != nil { - rb.commitResult = ErrorCommitResult(err.Error()) - l.Logger.Error("error during rollback", zap.Error(err)) - } else { - atomic.AddInt32(&successCnt, 1) - rb.commitResult = SuccessCommitResult() - } - }(rb) - } - wg.Wait() - if successCnt < int32(consensusThresh) { - return Broken, blobStatus, common.NewError("rollback_failed", "Rollback failed") - } - a.allocationRoot = allVersionConensus - if successCnt == int32(fullConsensus) { - return Repair, blobStatus, nil - } - - return Commit, blobStatus, nil -} +} \ No newline at end of file From 7a2308ccd3c915bd1a8fe57428386d784efdfa4c Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 02:23:15 +0530 Subject: [PATCH 04/24] test --- core/screstapi/http.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 912e73703..d3a2e4eb1 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -10,19 +10,19 @@ import ( ) var urlPathSharderToZboxMap = map[string]string{ - "/getStakePoolStat": "/getStakePoolStat", - "/getUserStakePoolStat": "/getUserStakePoolStat", - "/getChallengePoolStat": "/getChallengePoolStat", - "/getBlobber": "/blobber", - "/getblobbers": "/blobbers", - "/blobber_ids": "/blobber_ids", - "/alloc_blobbers": "/blobbers/allocation", - "/get_validator": "/validator", - "/validators": "/validators", + "/getStakePoolStat": "/getStakePoolStat", + "/getUserStakePoolStat": "/getUserStakePoolStat", + "/getChallengePoolStat": "/getChallengePoolStat", + "/getBlobber": "/blobber", + "/getblobbers": "/blobbers", + "/blobber_ids": "/blobber_ids", + "/alloc_blobbers": "/blobbers/allocation", + "/get_validator": "/validator", + "/validators": "/validators", "/v1/mint_nonce": "/mintNonce", "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", - // "/allocation": "/getAllocation", + "/allocation": "/getAllocation", // "/allocations": "/getAllocations", } From c51823a3fe272ef9844ec4b7e669ceba00b5051d Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 02:36:02 +0530 Subject: [PATCH 05/24] test 2 --- core/screstapi/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index d3a2e4eb1..9aa842eb5 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -22,8 +22,8 @@ var urlPathSharderToZboxMap = map[string]string{ "/v1/mint_nonce": "/mintNonce", "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", - "/allocation": "/getAllocation", - // "/allocations": "/getAllocations", + "/allocations": "/getAllocations", + // "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { From ea9d52911c2024464006599645a0ac695aefe0e2 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 02:47:16 +0530 Subject: [PATCH 06/24] test 3 --- core/screstapi/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 9aa842eb5..bd8483110 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -23,7 +23,7 @@ var urlPathSharderToZboxMap = map[string]string{ "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", "/allocations": "/getAllocations", - // "/allocation": "/getAllocation", + "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { From a015a5b1ddba02291a8422226771e0a4430c4f9f Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 12:53:27 +0530 Subject: [PATCH 07/24] test --- wasmsdk/blobber.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 487e05457..0e33dda9e 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -22,6 +22,7 @@ import ( "github.com/0chain/gosdk/core/pathutil" "github.com/0chain/gosdk/core/sys" "github.com/hack-pad/safejs" + "go.uber.org/zap" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/wasmsdk/jsbridge" @@ -457,6 +458,7 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF var alloc *sdk.Allocation if authTicket == "" { alloc, err = getAllocation(allocationID) + sdkLogger.Debug("getAllocation", zap.Any("allocation")) } else { alloc, err = sdk.GetAllocationFromAuthTicket(authTicket) } @@ -629,6 +631,7 @@ func MultiOperation(allocationID string, jsonMultiUploadOptions string) error { } } allocationObj, err := getAllocation(allocationID) + sdkLogger.Debug("Allocation data", zap.Any("allocation", allocationObj)) if err != nil { return err } From ec8ae023222a8f989199e83fd0081382dc7751c0 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 12:54:38 +0530 Subject: [PATCH 08/24] test 3 --- wasmsdk/blobber.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 0e33dda9e..07f7b683d 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -458,7 +458,7 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF var alloc *sdk.Allocation if authTicket == "" { alloc, err = getAllocation(allocationID) - sdkLogger.Debug("getAllocation", zap.Any("allocation")) + sdkLogger.Debug("getAllocation", zap.Any("allocation", alloc)) } else { alloc, err = sdk.GetAllocationFromAuthTicket(authTicket) } From 1e081fe0bc537e9560acd68bb4e27cddece55756 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 14:04:12 +0530 Subject: [PATCH 09/24] test 4 --- wasmsdk/blobber.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 07f7b683d..86012ea94 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -458,7 +458,9 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF var alloc *sdk.Allocation if authTicket == "" { alloc, err = getAllocation(allocationID) - sdkLogger.Debug("getAllocation", zap.Any("allocation", alloc)) + allocationJSON, _ := json.MarshalIndent(alloc, "", " ") + sdkLogger.Debug("Allocation Struct in JSON Format:", string(allocationJSON)) + } else { alloc, err = sdk.GetAllocationFromAuthTicket(authTicket) } From 062c608fbe568423d6b0886657d94b533f40d33c Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 14:20:41 +0530 Subject: [PATCH 10/24] test 5 --- core/screstapi/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index bd8483110..9aa842eb5 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -23,7 +23,7 @@ var urlPathSharderToZboxMap = map[string]string{ "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", "/allocations": "/getAllocations", - "/allocation": "/getAllocation", + // "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { From db60308929cad1c08fd26fbe0fd9f28d6168aeb5 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 16:47:08 +0530 Subject: [PATCH 11/24] test 6 --- core/screstapi/http.go | 2 +- zboxcore/sdk/commitworker.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 9aa842eb5..bd8483110 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -23,7 +23,7 @@ var urlPathSharderToZboxMap = map[string]string{ "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", "/allocations": "/getAllocations", - // "/allocation": "/getAllocation", + "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { diff --git a/zboxcore/sdk/commitworker.go b/zboxcore/sdk/commitworker.go index 262d98b0d..6f00f0070 100644 --- a/zboxcore/sdk/commitworker.go +++ b/zboxcore/sdk/commitworker.go @@ -244,6 +244,8 @@ func (commitreq *CommitRequest) processCommit() { hasher.Write(decodedHash) //nolint:errcheck chainHash = hex.EncodeToString(hasher.Sum(nil)) } + wmJson, _ := json.MarshalIndent(lR.LatestWM, "", " ") + l.Logger.Info("wm json val", string(wmJson)) err = commitreq.commitBlobber(rootRef, chainHash, lR.LatestWM, size, fileIDMeta) if err != nil { commitreq.result = ErrorCommitResult(err.Error()) @@ -500,6 +502,8 @@ func (commitReq *CommitRequestV2) processCommit() { go func(ind int) { defer wg.Done() commitErr := commitReq.commitBlobber(rootHash, rootWeight, prevWeight, blobber) + blobberJson, _ := json.MarshalIndent(blobber, "", " ") + l.Logger.Info("blobber val", string(blobberJson)) if commitErr != nil { l.Logger.Error("Error committing to blobber: ", blobber.Baseurl, " ", commitErr) errSlice[ind] = commitErr From 57e37849ef0b3d4cadf561529cbddedf9fe2ade3 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 17:28:55 +0530 Subject: [PATCH 12/24] logging --- zboxcore/sdk/multi_operation_worker.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index de797d145..37b040821 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -3,6 +3,7 @@ package sdk import ( "bytes" "context" + "encoding/json" "fmt" "io" "mime/multipart" @@ -322,6 +323,8 @@ func (mo *MultiOperation) Process() error { return errors.New("consensus_not_met", fmt.Sprintf("Active blobbers %d is less than consensus threshold %d", activeBlobbers, mo.consensusThresh)) } if mo.allocationObj.StorageVersion == StorageV2 { + allocJson, _ := json.MarshalIndent(mo, "", "") + l.Logger.Info("mo allocation json", string(allocJson)) return mo.commitV2() } commitReqs := make([]*CommitRequest, activeBlobbers) From 0bda1976e5fcc91e385f459bf35437f08d96b48e Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 17:49:57 +0530 Subject: [PATCH 13/24] logging 2 --- zboxcore/sdk/multi_operation_worker.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index 37b040821..44b256f2c 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -322,11 +322,15 @@ func (mo *MultiOperation) Process() error { l.Logger.Error("consensus not met", activeBlobbers, mo.consensusThresh) return errors.New("consensus_not_met", fmt.Sprintf("Active blobbers %d is less than consensus threshold %d", activeBlobbers, mo.consensusThresh)) } + + allocJson, _ := json.MarshalIndent(mo, "", "") + logger.Logger.Debug("mo allocation json", string(allocJson)) + l.Logger.Debug("mo allocation json 1", string(allocJson)) + if mo.allocationObj.StorageVersion == StorageV2 { - allocJson, _ := json.MarshalIndent(mo, "", "") - l.Logger.Info("mo allocation json", string(allocJson)) return mo.commitV2() } + commitReqs := make([]*CommitRequest, activeBlobbers) start = time.Now() wg.Add(activeBlobbers) From fdff424005b1264edc3b3bd5139e23405c91cddb Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 18:12:38 +0530 Subject: [PATCH 14/24] logging --- core/screstapi/http.go | 1 - zboxcore/sdk/multi_operation_worker.go | 1 - 2 files changed, 2 deletions(-) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index bd8483110..69fe7b437 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -23,7 +23,6 @@ var urlPathSharderToZboxMap = map[string]string{ "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", "/allocations": "/getAllocations", - "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index 44b256f2c..3a25fb1f4 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -325,7 +325,6 @@ func (mo *MultiOperation) Process() error { allocJson, _ := json.MarshalIndent(mo, "", "") logger.Logger.Debug("mo allocation json", string(allocJson)) - l.Logger.Debug("mo allocation json 1", string(allocJson)) if mo.allocationObj.StorageVersion == StorageV2 { return mo.commitV2() From b32731e7a31ef9ce85f10f7a8e43b5b29cf35292 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 19:21:37 +0530 Subject: [PATCH 15/24] removed log --- wasmsdk/blobber.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 86012ea94..80f7d6055 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -22,7 +22,6 @@ import ( "github.com/0chain/gosdk/core/pathutil" "github.com/0chain/gosdk/core/sys" "github.com/hack-pad/safejs" - "go.uber.org/zap" "github.com/0chain/gosdk/core/transaction" "github.com/0chain/gosdk/wasmsdk/jsbridge" @@ -633,7 +632,6 @@ func MultiOperation(allocationID string, jsonMultiUploadOptions string) error { } } allocationObj, err := getAllocation(allocationID) - sdkLogger.Debug("Allocation data", zap.Any("allocation", allocationObj)) if err != nil { return err } From 688c570982975e544a4de4aff75d9f58a34a2ba0 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 19:24:20 +0530 Subject: [PATCH 16/24] removed log --- wasmsdk/blobber.go | 3 --- zboxcore/sdk/commitworker.go | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 80f7d6055..487e05457 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -457,9 +457,6 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF var alloc *sdk.Allocation if authTicket == "" { alloc, err = getAllocation(allocationID) - allocationJSON, _ := json.MarshalIndent(alloc, "", " ") - sdkLogger.Debug("Allocation Struct in JSON Format:", string(allocationJSON)) - } else { alloc, err = sdk.GetAllocationFromAuthTicket(authTicket) } diff --git a/zboxcore/sdk/commitworker.go b/zboxcore/sdk/commitworker.go index 6f00f0070..668640ab9 100644 --- a/zboxcore/sdk/commitworker.go +++ b/zboxcore/sdk/commitworker.go @@ -244,8 +244,7 @@ func (commitreq *CommitRequest) processCommit() { hasher.Write(decodedHash) //nolint:errcheck chainHash = hex.EncodeToString(hasher.Sum(nil)) } - wmJson, _ := json.MarshalIndent(lR.LatestWM, "", " ") - l.Logger.Info("wm json val", string(wmJson)) + err = commitreq.commitBlobber(rootRef, chainHash, lR.LatestWM, size, fileIDMeta) if err != nil { commitreq.result = ErrorCommitResult(err.Error()) @@ -502,8 +501,6 @@ func (commitReq *CommitRequestV2) processCommit() { go func(ind int) { defer wg.Done() commitErr := commitReq.commitBlobber(rootHash, rootWeight, prevWeight, blobber) - blobberJson, _ := json.MarshalIndent(blobber, "", " ") - l.Logger.Info("blobber val", string(blobberJson)) if commitErr != nil { l.Logger.Error("Error committing to blobber: ", blobber.Baseurl, " ", commitErr) errSlice[ind] = commitErr From e1ee800504483865a702c54df224d7ce988a2c58 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 19:28:00 +0530 Subject: [PATCH 17/24] removed extra changes --- zboxcore/fileref/fileref.go | 1 - zboxcore/sdk/listworker.go | 3 +-- zboxcore/sdk/multi_operation_worker.go | 4 ---- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/zboxcore/fileref/fileref.go b/zboxcore/fileref/fileref.go index 3f226777a..a1c082d5e 100644 --- a/zboxcore/fileref/fileref.go +++ b/zboxcore/fileref/fileref.go @@ -106,7 +106,6 @@ type Ref struct { AllocationRoot string `json:"allocation_root" mapstructure:"allocation_root"` CreatedAt common.Timestamp `json:"created_at" mapstructure:"created_at"` UpdatedAt common.Timestamp `json:"updated_at" mapstructure:"updated_at"` - NumFiles int `json:"num_files" mapstructure:"num_files"` } // GetReferenceLookup returns the lookup hash for a given allocationID and path diff --git a/zboxcore/sdk/listworker.go b/zboxcore/sdk/listworker.go index 35f3ec0ca..d8944557d 100644 --- a/zboxcore/sdk/listworker.go +++ b/zboxcore/sdk/listworker.go @@ -69,7 +69,6 @@ type ListResult struct { ThumbnailSize int64 `json:"thumbnail_size"` ActualThumbnailHash string `json:"actual_thumbnail_hash"` ActualThumbnailSize int64 `json:"actual_thumbnail_size"` - NumFiles int `json:"num_files"` CreatedAt common.Timestamp `json:"created_at"` UpdatedAt common.Timestamp `json:"updated_at"` @@ -271,7 +270,7 @@ func (req *ListRequest) GetListFromBlobbers() (*ListResult, error) { if ti.ref.ActualSize > 0 { result.ActualNumBlocks = (ti.ref.ActualSize + CHUNK_SIZE - 1) / CHUNK_SIZE } - result.Size += ti.ref.Size + result.Size += ti.ref.Size result.NumBlocks += ti.ref.NumBlocks if ti.ref.Path == "/" && result.ActualSize == 0 { result.ActualSize = ti.ref.Size * int64(req.dataShards) diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index 3a25fb1f4..3b5032a96 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -3,7 +3,6 @@ package sdk import ( "bytes" "context" - "encoding/json" "fmt" "io" "mime/multipart" @@ -323,9 +322,6 @@ func (mo *MultiOperation) Process() error { return errors.New("consensus_not_met", fmt.Sprintf("Active blobbers %d is less than consensus threshold %d", activeBlobbers, mo.consensusThresh)) } - allocJson, _ := json.MarshalIndent(mo, "", "") - logger.Logger.Debug("mo allocation json", string(allocJson)) - if mo.allocationObj.StorageVersion == StorageV2 { return mo.commitV2() } From dc009c436cb5657d341c9bdcf04528f51ad489ed Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 21:43:09 +0530 Subject: [PATCH 18/24] added endpoint --- core/screstapi/http.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/screstapi/http.go b/core/screstapi/http.go index 69fe7b437..bd8483110 100644 --- a/core/screstapi/http.go +++ b/core/screstapi/http.go @@ -23,6 +23,7 @@ var urlPathSharderToZboxMap = map[string]string{ "client/get/balance": "/balance", "/v1/not_processed_burn_tickets": "/not_processed_burn_tickets", "/allocations": "/getAllocations", + "/allocation": "/getAllocation", } func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]string, restApiUrls ...string) (resp []byte, err error) { From cf243796265b5d3916ea8110f435dd57af0ded80 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 22:22:40 +0530 Subject: [PATCH 19/24] logging --- wasmsdk/blobber.go | 6 ++++++ zboxcore/sdk/sdk.go | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 487e05457..32bc962af 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -444,6 +444,11 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF } }() sdkLogger.Info("starting multidownload") + sdkLogger.Debug("allocation id", allocationID) + sdkLogger.Debug("jsonMultiDownloadOptions", jsonMultiDownloadOptions) + sdkLogger.Debug("authTicket", authTicket) + sdkLogger.Debug("callbackFuncName", callbackFuncName) + wg := &sync.WaitGroup{} useCallback := false if callbackFuncName != "" { @@ -535,6 +540,7 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF } respBytes, err := json.Marshal(resp) + sdkLogger.Debug("download response", string(respBytes)) if err != nil { return "", err } diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index a8e3934fb..3ae451648 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -632,6 +632,30 @@ func GetAllocation(allocationID string) (*Allocation, error) { if err != nil { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } + + allocationBytesSh, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + if err != nil { + return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) + } + + allocationObjSharder := &Allocation{} + err = json.Unmarshal(allocationBytesSh, allocationObjSharder) + if err != nil { + return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) + } + + alloczbox, err := json.MarshalIndent(allocationBytes, "", "") + if err != nil { + return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) + } + fmt.Println("allocation_decode for 0box", string(alloczbox)) + + allocSharder, err := json.MarshalIndent(allocationBytesSh, "", "") + if err != nil { + return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) + } + fmt.Println("allocation_decode for sharder", string(allocSharder)) + allocationObj.numBlockDownloads = numBlockDownloads allocationObj.InitAllocation() return allocationObj, nil From 8158e5a8657411da05bd17d17abbd84733d019af Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 22:49:46 +0530 Subject: [PATCH 20/24] fix --- zboxcore/sdk/sdk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 3ae451648..eb340db9c 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -644,13 +644,13 @@ func GetAllocation(allocationID string) (*Allocation, error) { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } - alloczbox, err := json.MarshalIndent(allocationBytes, "", "") + alloczbox, err := json.MarshalIndent(allocationObj, "", "") if err != nil { return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) } fmt.Println("allocation_decode for 0box", string(alloczbox)) - allocSharder, err := json.MarshalIndent(allocationBytesSh, "", "") + allocSharder, err := json.MarshalIndent(allocationObjSharder, "", "") if err != nil { return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) } From 113ffc2cc93a8872a46350eb895e0ea9501bd87d Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Sun, 9 Feb 2025 23:10:08 +0530 Subject: [PATCH 21/24] fix 2 --- zboxcore/sdk/sdk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index eb340db9c..d668c918f 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -633,7 +633,7 @@ func GetAllocation(allocationID string) (*Allocation, error) { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } - allocationBytesSh, err := screstapi.MakeSCRestAPICall(STORAGE_SCADDRESS, "/allocation", params) + allocationBytesSh, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) if err != nil { return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) } From 07ad13e6e58bef69137a602520c40187fdad65c9 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 10 Feb 2025 14:46:34 +0530 Subject: [PATCH 22/24] revert changes --- zboxcore/sdk/sdk.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index d668c918f..0b05e324a 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -633,29 +633,6 @@ func GetAllocation(allocationID string) (*Allocation, error) { return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) } - allocationBytesSh, err := client.MakeSCRestAPICallToSharder(STORAGE_SCADDRESS, "/allocation", params) - if err != nil { - return nil, errors.New("allocation_fetch_error", "Error fetching the allocation."+err.Error()) - } - - allocationObjSharder := &Allocation{} - err = json.Unmarshal(allocationBytesSh, allocationObjSharder) - if err != nil { - return nil, errors.New("allocation_decode_error", "Error decoding the allocation: "+err.Error()+" "+string(allocationBytes)) - } - - alloczbox, err := json.MarshalIndent(allocationObj, "", "") - if err != nil { - return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) - } - fmt.Println("allocation_decode for 0box", string(alloczbox)) - - allocSharder, err := json.MarshalIndent(allocationObjSharder, "", "") - if err != nil { - return nil, errors.New("allocation_decode_error", "Error marshaling the allocation: "+err.Error()) - } - fmt.Println("allocation_decode for sharder", string(allocSharder)) - allocationObj.numBlockDownloads = numBlockDownloads allocationObj.InitAllocation() return allocationObj, nil From 8801258d6b23200c19e3401cefc44e9d7ce8e08c Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 10 Feb 2025 16:08:23 +0530 Subject: [PATCH 23/24] removed logs --- wasmsdk/blobber.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 32bc962af..04219062f 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -443,11 +443,6 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF PrintError("Recovered in multiDownload Error", r) } }() - sdkLogger.Info("starting multidownload") - sdkLogger.Debug("allocation id", allocationID) - sdkLogger.Debug("jsonMultiDownloadOptions", jsonMultiDownloadOptions) - sdkLogger.Debug("authTicket", authTicket) - sdkLogger.Debug("callbackFuncName", callbackFuncName) wg := &sync.WaitGroup{} useCallback := false @@ -540,7 +535,6 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF } respBytes, err := json.Marshal(resp) - sdkLogger.Debug("download response", string(respBytes)) if err != nil { return "", err } From 81661ca11e8e2e6ae4753cfabac60ab029d811e0 Mon Sep 17 00:00:00 2001 From: smaulik13 Date: Mon, 10 Feb 2025 18:12:17 +0530 Subject: [PATCH 24/24] added back log --- wasmsdk/blobber.go | 1 + 1 file changed, 1 insertion(+) diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 04219062f..76da7c764 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -443,6 +443,7 @@ func multiDownload(allocationID, jsonMultiDownloadOptions, authTicket, callbackF PrintError("Recovered in multiDownload Error", r) } }() + sdkLogger.Info("starting multidownload") wg := &sync.WaitGroup{} useCallback := false