From 174cffdff3662f16386be503f3be29f6c710600c Mon Sep 17 00:00:00 2001 From: Piers Shepperson Date: Tue, 27 Jun 2023 19:44:50 +0100 Subject: [PATCH 1/3] Move min lock demand to allocation (#1046) * min_lock_demand * mobile --- core/transaction/entity.go | 19 ++++++++++--------- mobilesdk/zbox/allocation.go | 16 ++++++++-------- zboxcore/sdk/allocation.go | 5 ++--- zcncore/transaction.go | 3 +-- zcncore/transaction_mobile.go | 8 +++----- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 6b2b89fac..891976a31 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -54,15 +54,16 @@ type SmartContractTxnData struct { } type StorageAllocation struct { - ID string `json:"id"` - DataShards int `json:"data_shards"` - ParityShards int `json:"parity_shards"` - Size int64 `json:"size"` - Expiration int64 `json:"expiration_date"` - Owner string `json:"owner_id"` - OwnerPublicKey string `json:"owner_public_key"` - ReadRatio *Ratio `json:"read_ratio"` - WriteRatio *Ratio `json:"write_ratio"` + ID string `json:"id"` + DataShards int `json:"data_shards"` + ParityShards int `json:"parity_shards"` + Size int64 `json:"size"` + Expiration int64 `json:"expiration_date"` + Owner string `json:"owner_id"` + OwnerPublicKey string `json:"owner_public_key"` + ReadRatio *Ratio `json:"read_ratio"` + WriteRatio *Ratio `json:"write_ratio"` + MinLockDemand float64 `json:"min_lock_demand"` } type Ratio struct { ZCN int64 `json:"zcn"` diff --git a/mobilesdk/zbox/allocation.go b/mobilesdk/zbox/allocation.go index 779f146d5..51e1c6153 100644 --- a/mobilesdk/zbox/allocation.go +++ b/mobilesdk/zbox/allocation.go @@ -15,14 +15,14 @@ var ErrInvalidAllocation = errors.New("zbox: invalid allocation") // Allocation - structure for allocation object type Allocation struct { - ID string `json:"id"` - DataShards int `json:"data_shards"` - ParityShards int `json:"parity_shards"` - Size int64 `json:"size"` - Expiration int64 `json:"expiration_date"` - Name string `json:"name"` - Stats string `json:"stats"` - + ID string `json:"id"` + DataShards int `json:"data_shards"` + ParityShards int `json:"parity_shards"` + Size int64 `json:"size"` + Expiration int64 `json:"expiration_date"` + Name string `json:"name"` + Stats string `json:"stats"` + MinLockDemand float64 `json:"min_lock_demand"` blobbers []*blockchain.StorageNode `json:"-"` sdkAllocation *sdk.Allocation `json:"-"` } diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 185ce67b4..bf7445640 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -132,7 +132,6 @@ func (pr *PriceRange) IsValid() bool { type Terms struct { ReadPrice common.Balance `json:"read_price"` // tokens / GB WritePrice common.Balance `json:"write_price"` // tokens / GB - MinLockDemand float64 `json:"min_lock_demand"` MaxOfferDuration time.Duration `json:"max_offer_duration"` } @@ -171,8 +170,8 @@ type Allocation struct { // ReadPriceRange is requested reading prices range. ReadPriceRange PriceRange `json:"read_price_range"` // WritePriceRange is requested writing prices range. - WritePriceRange PriceRange `json:"write_price_range"` - + WritePriceRange PriceRange `json:"write_price_range"` + MinLockDemand float64 `json:"min_lock_demand"` ChallengeCompletionTime time.Duration `json:"challenge_completion_time"` StartTime common.Timestamp `json:"start_time"` Finalized bool `json:"finalized,omitempty"` diff --git a/zcncore/transaction.go b/zcncore/transaction.go index 67923d7df..53a8dc0fa 100644 --- a/zcncore/transaction.go +++ b/zcncore/transaction.go @@ -197,8 +197,7 @@ type StakePoolSettings struct { type Terms struct { ReadPrice common.Balance `json:"read_price"` // tokens / GB - WritePrice common.Balance `json:"write_price"` // tokens / GB - MinLockDemand float64 `json:"min_lock_demand"` + WritePrice common.Balance `json:"write_price"` // tokens / GB ` MaxOfferDuration time.Duration `json:"max_offer_duration"` } diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 3f8711df6..5309cb26b 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -149,10 +149,9 @@ type StakePoolSettings struct { } type Terms struct { - ReadPrice int64 `json:"read_price"` // tokens / GB - WritePrice int64 `json:"write_price"` // tokens / GB - MinLockDemand float64 `json:"min_lock_demand"` - MaxOfferDuration int64 `json:"max_offer_duration"` + ReadPrice int64 `json:"read_price"` // tokens / GB + WritePrice int64 `json:"write_price"` // tokens / GB + MaxOfferDuration int64 `json:"max_offer_duration"` } type Blobber interface { @@ -196,7 +195,6 @@ func (b *blobber) SetTerms(readPrice int64, writePrice int64, minLockDemand floa b.Terms = Terms{ ReadPrice: readPrice, WritePrice: writePrice, - MinLockDemand: minLockDemand, MaxOfferDuration: maxOfferDuration, } } From 84f2b61b051cee6512b6367e340bf8c6eb51a8f7 Mon Sep 17 00:00:00 2001 From: Yury Date: Thu, 29 Jun 2023 21:58:06 +0300 Subject: [PATCH 2/3] Feat/caching get fees estimate (#1069) * added caching instead of the network call * clean up * clean up * fixes for update image (#1058) * update wasm demo for download * preserver order in blobber of newallocationrequestg * fixes for update image * use multiUpload * demo for multi operation * clean up logs * init Consensus * feat wasm: UpdateForbidAllocation * expose lockReadPool * fix for unique blobbers * init Consensus in Lock function (#1063) * init Consensus * fix panic in dirworker --------- Co-authored-by: Hitenjain14 * fixed comments --------- Co-authored-by: sarvesh raut Co-authored-by: boddumanohar Co-authored-by: Hitenjain14 --- core/transaction/entity.go | 43 +++++++++ core/version/version.go | 2 +- wasmsdk/allocation.go | 31 +++++++ wasmsdk/blobber.go | 14 ++- wasmsdk/demo/index.html | 142 ++++++++++++++++++------------ wasmsdk/proxy.go | 64 ++++++++------ wasmsdk/updateImage.go | 6 +- zboxcore/sdk/dirworker.go | 7 +- zboxcore/sdk/sdk.go | 23 +++-- zboxcore/sdk/writemarker_mutex.go | 2 +- 10 files changed, 227 insertions(+), 107 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 891976a31..922ec9203 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -6,11 +6,14 @@ import ( "net/http" "strings" "sync" + "time" + "github.com/0chain/common/core/logging" "github.com/0chain/errors" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/core/util" + lru "github.com/hashicorp/golang-lru" ) const TXN_SUBMIT_URL = "v1/transaction/put" @@ -174,6 +177,16 @@ type SignFunc = func(msg string) (string, error) type VerifyFunc = func(signature, msgHash, publicKey string) (bool, error) type SignWithWallet = func(msg string, wallet interface{}) (string, error) +var cache *lru.Cache + +func init() { + var err error + cache, err = lru.New(100) + if err != nil { + fmt.Println("caching Initilization failed, err:", err) + } +} + func NewTransactionEntity(clientID string, chainID string, publicKey string, nonce int64) *Transaction { txn := &Transaction{} txn.Version = "1.0" @@ -270,8 +283,14 @@ func sendTransactionToURL(url string, txn *Transaction, wg *sync.WaitGroup) ([]b return nil, errors.Wrap(err, errors.New("transaction_send_error", postResponse.Body)) } +type cachedObject struct { + Expiration time.Duration + Value interface{} +} + // EstimateFee estimates transaction fee func EstimateFee(txn *Transaction, miners []string, reqPercent ...float32) (uint64, error) { + const minReqNum = 3 var reqN int @@ -295,6 +314,20 @@ func EstimateFee(txn *Transaction, miners []string, reqPercent ...float32) (uint go func(minerUrl string) { defer wg.Done() + // Retrieve the object from the cache + cached, ok := cache.Get(STORAGESC_CREATE_ALLOCATION) + + if ok { + cachedObj, ok := cached.(*cachedObject) + if !ok { + logging.Logger.Error("Object of bad type") + return + } + val := cachedObj.Value.(map[string]interface{})["fee"].(int) + feeC <- uint64(val) + return + } + url := minerUrl + ESTIMATE_TRANSACTION_COST req, err := util.NewHTTPPostRequest(url, txn) if err != nil { @@ -344,6 +377,16 @@ func EstimateFee(txn *Transaction, miners []string, reqPercent ...float32) (uint } } + // adding response to cache + obj := map[string]interface{}{ + "fee": fee, + } + + cache.Add(STORAGESC_CREATE_ALLOCATION, &cachedObject{ + Expiration: 30 * time.Hour, + Value: obj, + }) + return fee, nil } diff --git a/core/version/version.go b/core/version/version.go index 926e95f8c..a618c325b 100644 --- a/core/version/version.go +++ b/core/version/version.go @@ -2,5 +2,5 @@ //====== THIS IS AUTOGENERATED FILE. DO NOT MODIFY ======== package version -const VERSIONSTR = "v1.8.16-58-g520bdba8" +const VERSIONSTR = "v1.8.16-87-gc6a0e22b" diff --git a/wasmsdk/allocation.go b/wasmsdk/allocation.go index 4f11957a7..0c8896edc 100644 --- a/wasmsdk/allocation.go +++ b/wasmsdk/allocation.go @@ -104,6 +104,32 @@ func transferAllocation(allocationID, newOwnerId, newOwnerPublicKey string) erro return err } +// updateForbidAllocation updates the settings for forbid alocation +func UpdateForbidAllocation(allocationID string, forbidupload, forbiddelete, forbidupdate, forbidmove, forbidcopy, forbidrename bool) (string, error) { + + hash, _, err := sdk.UpdateAllocation( + 0, //size, + 0, //int64(expiry/time.Second), + allocationID, // allocID, + 0, //lock, + false, //updateTerms, + "", //addBlobberId, + "", //removeBlobberId, + false, //thirdPartyExtendable, + &sdk.FileOptionsParameters{ + ForbidUpload: sdk.FileOptionParam{Changed: forbidupload, Value: forbidupload}, + ForbidDelete: sdk.FileOptionParam{Changed: forbiddelete, Value: forbiddelete}, + ForbidUpdate: sdk.FileOptionParam{Changed: forbidupdate, Value: forbidupdate}, + ForbidMove: sdk.FileOptionParam{Changed: forbidmove, Value: forbidmove}, + ForbidCopy: sdk.FileOptionParam{Changed: forbidcopy, Value: forbidcopy}, + ForbidRename: sdk.FileOptionParam{Changed: forbidrename, Value: forbidrename}, + }, + ) + + return hash, err + +} + func freezeAllocation(allocationID string) (string, error) { hash, _, err := sdk.UpdateAllocation( @@ -241,6 +267,11 @@ func lockStakePool(providerType, tokens, fee uint64, providerID string) (string, return hash, err } +func lockReadPool(tokens, fee uint64) (string, error) { + hash, _, err := sdk.ReadPoolLock(tokens, fee) + return hash, err +} + func unlockStakePool(providerType, fee uint64, providerID string) (int64, error) { unstake, _, err := sdk.StakePoolUnlock(sdk.ProviderType(providerType), providerID, fee) return unstake, err diff --git a/wasmsdk/blobber.go b/wasmsdk/blobber.go index 2d6c91ebe..1ad4b0218 100644 --- a/wasmsdk/blobber.go +++ b/wasmsdk/blobber.go @@ -401,7 +401,7 @@ type BulkUploadOption struct { ThumbnailBytes jsbridge.Bytes `json:"thumbnailBytes,omitempty"` Encrypt bool `json:"encrypt,omitempty"` - webstreaming bool `json:"webstreaming,omitempty"` + Webstreaming bool `json:"webstreaming,omitempty"` IsUpdate bool `json:"isUpdate,omitempty"` IsRepair bool `json:"isRepair,omitempty"` @@ -420,6 +420,7 @@ type MultiUploadResult struct { Success bool `json:"success,omitempty"` Error string `json:"error,omitempty"` } + type MultiOperationOption struct { OperationType string `json:"operationType,omitempty"` RemotePath string `json:"remotePath,omitempty"` @@ -430,7 +431,7 @@ type MultiOperationOption struct { // MultiOperation - do copy, move, delete and createdir operation together // ## Inputs // - allocationID -// - jsonMultiUploadOpetions: Json Array of MultiOperationOption. eg: "[{"operationType":"move","remotePath":"/README.md","destPath":"/folder1/"},{"operationType":"delete","remotePath":"/t3.txt"}]" +// - jsonMultiUploadOptions: Json Array of MultiOperationOption. eg: "[{"operationType":"move","remotePath":"/README.md","destPath":"/folder1/"},{"operationType":"delete","remotePath":"/t3.txt"}]" // // ## Outputs // - error @@ -438,9 +439,15 @@ func MultiOperation(allocationID string, jsonMultiUploadOptions string) error { if allocationID == "" { return errors.New("AllocationID is required") } + + if jsonMultiUploadOptions == "" { + return errors.New("operations are empty") + } + var options []MultiOperationOption err := json.Unmarshal([]byte(jsonMultiUploadOptions), &options) if err != nil { + sdkLogger.Info("error unmarshalling") return err } totalOp := len(options) @@ -481,7 +488,7 @@ func bulkUpload(jsonBulkUploadOptions string) ([]BulkUploadResult, error) { o.ReadChunkFuncName, o.FileSize, o.ThumbnailBytes.Buffer, - o.webstreaming, + o.Webstreaming, o.Encrypt, o.IsUpdate, o.IsRepair, @@ -505,6 +512,7 @@ func bulkUpload(jsonBulkUploadOptions string) ([]BulkUploadResult, error) { return results, nil } + func multiUpload(jsonBulkUploadOptions string) (MultiUploadResult, error) { var options []BulkUploadOption result := MultiUploadResult{} diff --git a/wasmsdk/demo/index.html b/wasmsdk/demo/index.html index c4142e56d..d82f81dd8 100644 --- a/wasmsdk/demo/index.html +++ b/wasmsdk/demo/index.html @@ -41,7 +41,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates value="41729ed8d82f782646d2d30b9719acfd236842b9b6e47fee12b7bdbd05b35122" />

- Mnemonic
@@ -57,9 +57,8 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates
Sharing
- + value="eyJjbGllbnRfaWQiOiJhNGM1M2JmMjQ4YzYzNGVhNDgzYTk4Y2JhYTZiNzY3MjI2ZjUwNDUwNmIyOTkzODRiMzBmMmMwMGE1MmYwODUxIiwib3duZXJfaWQiOiIzMDc2NGJjYmE3MzIxNmI2N2MzNmIwNWExN2I0ZGQwNzZiZmRjNWJiMGVkODQ4NTZmMjc2MjIxODhjMzc3MjY5IiwiYWxsb2NhdGlvbl9pZCI6IjJmMjc3NDJlODYxN2YyY2U1MTk2OWFhNWQ1ZDAyY2MyZDg1NzQ1MzQ5MGVkZjBlODYzNmE0OTdjYjRmNTY3MWUiLCJmaWxlX3BhdGhfaGFzaCI6IjVhYTE2NzkyZDQ1YWMwMzI0ZTExZjc0Y2E5N2M0NDk3Zjc2ZmIxM2ZkN2ExMjIzMjc4NzQ4ZjY4OGIyNzU2OGUiLCJhY3R1YWxfZmlsZV9oYXNoIjoiYjQxZTFmZGI2YThlNzM0MmNkMzk5ZjY3MWFiYWRkM2MyN2QzZDQ0YjdmZGM0OGU3Mzc1ZTI4ZTM3MTI2NWY3YiIsImZpbGVfbmFtZSI6InJ0eDA5MDIwMDIxMnAucGRmIiwicmVmZXJlbmNlX3R5cGUiOiJmIiwiZXhwaXJhdGlvbiI6MTY4ODY4OTcyMTcxNCwidGltZXN0YW1wIjoxNjg3MDAyNzE2LCJlbmNyeXB0ZWQiOnRydWUsInNpZ25hdHVyZSI6IjIyOWUyY2FkNTU5YzEwMGU4MTVhNjk2ZTQ5YTU3ZTUyNGU5ZmQ1YmZmZTRjYjAyY2I0MDM1NGY0OTQ1YzY5MWYifQ==" />
+
@@ -112,6 +111,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates +
@@ -159,7 +159,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates const privateKey = get('privateKey').value const mnemonic = get('mnemonic').value return { - clientID, publicKey, privateKey,mnemonic + clientID, publicKey, privateKey, mnemonic } } @@ -197,7 +197,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates network = "dev.zus.network" } - const blockWorker = 'https://'+network+'/dns'; + const blockWorker = 'https://' + network + '/dns'; const config = [ networkConfig.chainId, blockWorker, @@ -205,7 +205,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates networkConfig.minConfirmation, networkConfig.minSubmit, networkConfig.confirmationChainLength, - 'https://0box.'+network, //zboxHost + 'https://0box.' + network, //zboxHost 'vult', //zboxAppType ] @@ -253,7 +253,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates onClick('btnCreateAllocation', async () => { const expiry = new Date() - expiry.setDate(expiry.getDate() + 30) + expiry.setDate(expiry.getDate() + 300) //name string, datashards, parityshards int, size, expiry int64,minReadPrice, maxReadPrice, minWritePrice, maxWritePrice int64, lock int64,preferredBlobberIds []string const config = { @@ -265,7 +265,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates maxReadPrice: 184467440737095516, minWritePrice: 0, maxWritePrice: 184467440737095516, - lock: 5000000000 + lock: 18800000000 } try { const allocation = await goWasm.sdk.createAllocation(config.datashards, config.parityshards, config.size, config.expiry, @@ -296,7 +296,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates let resp = await goWasm.sdk.getRemoteFileMap(allocationID) console.log(resp) txtOutput.innerHTML = JSON.stringify(resp, null, 2) - }catch(e){ + } catch (e) { alert(e) } }) @@ -325,10 +325,10 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates let expiry = 1680408725 let maxReadPrice = 10000000000 let maxWritePrice = 1000000000 - try{ + try { const price = await goWasm.sdk.getAllocationMinLock(dataShards, parityShards, size, expiry, maxReadPrice, maxWritePrice) txtOutput.innerHTML = price - }catch(e) { + } catch (e) { alert(e) } }) @@ -351,12 +351,12 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates return } let details = await getBlobberDetails(blobberID) - details.terms.read_price+=1 + details.terms.read_price += 1 try { - const txn = await goWasm.sdk.updateBlobberSettings(JSON.stringify(details)) - } catch (e) { - alert(e) - } + const txn = await goWasm.sdk.updateBlobberSettings(JSON.stringify(details)) + } catch (e) { + alert(e) + } // txtOutput.innerHTML = JSON.stringify(alloc, null, 2) }) @@ -394,7 +394,8 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates }) } - const results = await goWasm.bulkUpload(objects) + // const results = await goWasm.bulkUpload(objects) + const results = await goWasm.multiUpload(objects) console.log(JSON.stringify(results)) } @@ -402,8 +403,8 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates onClick('btnShare', async () => { // change these values according to your wallet (obtained from zbox `zbox getwallet`) - let clientID = "7838eedbf2add6dc590a5ee95643e9a872ec7a9ae6c5efc452f2fa9c6971eb3a" - let encryptionPublicKey = "b0h8PCKsg3exMzR3SOHsXk0Uwx0BiY50deZVYuWq8VY=" + let clientID = "a4c53bf248c634ea483a98cbaa6b767226f504506b299384b30f2c00a52f0851" + let encryptionPublicKey = "SCxZlinUp+Z29jt8hXT623osEjALXVel6HdHgq1lXEY=" const file = files.find(it => it.path == getSelectedFile()) if (file) { @@ -418,7 +419,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates let expiration = time += 3600 // after 1 hour let availableAfter = 0 try { - const result = await goWasm.sdk.share(allocationId, file?.path, clientID, encryptionPublicKey, expiration, false, availableAfter) + const result = await goWasm.sdk.share(allocationId, file?.path, "", "", expiration, false, availableAfter) console.log("output of share", result) txtOutput.innerHTML = JSON.stringify(result, null, 2) } catch (e) { @@ -467,8 +468,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates const allocationId = getSelectedAllocation() //allocationID, remotePath, authTicket, lookupHash string, downloadThumbnailOnly bool, numBlocks int - const file = await goWasm.sdk.download(allocationId, path, '', '', false, 10, "downloadCallback") - + const file = await goWasm.sdk.download(allocationId, path, '', '', false, 10, "downloadCallback", true) const a = document.createElement('a') document.body.appendChild(a) @@ -494,15 +494,15 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates console.log("removeBlobberID", removeBlobberID) // addBlobberId = addBlobberId.trim() // removeBlobberID = removeBlobberID.trim() - const allocationId = getSelectedAllocation() - if (!allocationId) { - alert("please provide allocationId") - } + const allocationId = getSelectedAllocation() + if (!allocationId) { + alert("please provide allocationId") + } - try { - const file = await goWasm.sdk.updateAllocationWithRepair(allocationId, 0, 0, 5000000000, false, addBlobberId, removeBlobberID) + try { + const file = await goWasm.sdk.updateAllocationWithRepair(allocationId, 0, 0, 5000000000, false, addBlobberId, removeBlobberID) - } catch (e) { + } catch (e) { alert(e) } }) @@ -511,29 +511,31 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates const authTicket = get('authTicket').value if (authTicket) { - - //allocationID, remotePath, authTicket, lookupHash string, downloadThumbnailOnly bool, numBlocks int, callbackFuncName string - const file = await goWasm.sdk.download('', '', authTicket, '', false, 10, "downloadCallback") - - const a = document.createElement('a') - document.body.appendChild(a) - a.style = 'display: none' - a.href = file.url - a.download = file.fileName - a.click() - window.URL.revokeObjectURL(file.url) - document.body.removeChild(a) - + try { + const file = await goWasm.sdk.download('', '', authTicket, '', false, 10, "downloadCallback", true) + + console.log("downloaded file", file) + const a = document.createElement('a') + document.body.appendChild(a) + a.style = 'display: none' + a.href = file.url + a.download = file.fileName + a.click() + window.URL.revokeObjectURL(file.url) + document.body.removeChild(a) + } catch (e) { + alert(e) + } } }) onClick('decodeAuthticket', async () => { const authTicket = get('authTicket').value if (authTicket) { - try{ + try { const output = await goWasm.sdk.decodeAuthTicket(authTicket); - console.log(output) - txtOutput.innerHTML = JSON.stringify(output, null, 2) + console.log(output) + txtOutput.innerHTML = JSON.stringify(output, null, 2) } catch (e) { alert(e) } @@ -675,7 +677,7 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates try { const stats = await goWasm.sdk.getcontainers(username, password, domain) - txtOutput.innerHTML = JSON.stringify(stats, null, 2) + txtOutput.innerHTML = JSON.stringify(stats, null, 2) } catch (e) { alert(e) } @@ -690,22 +692,22 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates try { const stats = await goWasm.sdk.updatecontainer(username, password, domain, containerid, image) txtOutput.innerHTML = JSON.stringify(stats, null, 2) - } catch (e) { + } catch (e) { alert(e) } }) onClick('btnSearchContainer', async () => { - const domain = "https://chimneyhwayr.zus.network" - const username = "username1" - const password = "password1" - const containername = "validator" - try { - const stats = await goWasm.sdk.searchcontainer(username, password, domain, containername) - txtOutput.innerHTML = JSON.stringify(stats, null, 2) - } catch (e) { - alert(e) - } + const domain = "https://chimneyhwayr.zus.network" + const username = "username1" + const password = "password1" + const containername = "validator" + try { + const stats = await goWasm.sdk.searchcontainer(username, password, domain, containername) + txtOutput.innerHTML = JSON.stringify(stats, null, 2) + } catch (e) { + alert(e) + } }) onClick('btnAllocationRepair', async () => { @@ -713,5 +715,29 @@

please download zcn.wasm from https://github.com/0chain/gosdk/releases/lates const output = await goWasm.sdk.allocationRepair(allocationId, "/") txtOutput.innerHTML = output }) + + onClick('btnMultiOps', async () => { + const allocationId = getSelectedAllocation() + if (!allocationId) { + alert("please provide allocationId") + } + const objects = [] + + objects.push({ + operationType: `move`, + remotePath: `/zcn.wasm`, + destPath: `/folder1`, + }) + + let stringifiedArray = JSON.stringify(objects); + + try { + console.log("execting", objects[0]) + const output = await goWasm.sdk.multiOperation(allocationId, stringifiedArray) + } catch (e) { + alert(e) + } + }) + diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index b65e93444..a9b923e61 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -161,25 +161,27 @@ func main() { "createThumbnail": createThumbnail, //blobber - "delete": Delete, - "rename": Rename, - "copy": Copy, - "move": Move, - "share": Share, - "download": download, - "upload": upload, - "bulkUpload": bulkUpload, - "multiUpload": multiUpload, - "listObjects": listObjects, - "createDir": createDir, - "downloadBlocks": downloadBlocks, - "getFileStats": getFileStats, - "updateBlobberSettings": updateBlobberSettings, - "getRemoteFileMap": getRemoteFileMap, - "getBlobbers": getBlobbers, - "getcontainers": GetContainers, - "updatecontainer": UpdateContainer, - "searchcontainer": SearchContainer, + "delete": Delete, + "rename": Rename, + "copy": Copy, + "move": Move, + "share": Share, + "download": download, + "upload": upload, + "bulkUpload": bulkUpload, + "multiUpload": multiUpload, + "multiOperation": MultiOperation, + "listObjects": listObjects, + "createDir": createDir, + "downloadBlocks": downloadBlocks, + "getFileStats": getFileStats, + "updateBlobberSettings": updateBlobberSettings, + "getRemoteFileMap": getRemoteFileMap, + "getBlobbers": getBlobbers, + "getcontainers": GetContainers, + "updatecontainer": UpdateContainer, + "searchcontainer": SearchContainer, + "updateForbidAllocation": UpdateForbidAllocation, // player "play": play, @@ -200,13 +202,22 @@ func main() { "updateAllocationWithRepair": updateAllocationWithRepair, "getAllocationMinLock": getAllocationMinLock, "getAllocationWith": getAllocationWith, - "getReadPoolInfo": getReadPoolInfo, - "lockStakePool": lockStakePool, - "lockWritePool": lockWritePool, - "getSkatePoolInfo": getSkatePoolInfo, - "unlockStakePool": unlockStakePool, - "decodeAuthTicket": decodeAuthTicket, - "allocationRepair": allocationRepair, + + // readpool + "getReadPoolInfo": getReadPoolInfo, + "lockReadPool": lockReadPool, + "createReadPool": createReadPool, + + // stakepool + "getSkatePoolInfo": getSkatePoolInfo, + "lockStakePool": lockStakePool, + "unlockStakePool": unlockStakePool, + + // writepool + "lockWritePool": lockWritePool, + + "decodeAuthTicket": decodeAuthTicket, + "allocationRepair": allocationRepair, //smartcontract "executeSmartContract": executeSmartContract, @@ -224,7 +235,6 @@ func main() { //zcn "getWalletBalance": getWalletBalance, - "createReadPool": createReadPool, //0box api "getCsrfToken": getCsrfToken, diff --git a/wasmsdk/updateImage.go b/wasmsdk/updateImage.go index 221104acf..d793a2c11 100644 --- a/wasmsdk/updateImage.go +++ b/wasmsdk/updateImage.go @@ -27,8 +27,8 @@ type Endpoint struct { } const ( - AUTH = "/portainer/api/auth" - ENDPOINTS = "/portainer/api/endpoints" + AUTH = "/api/auth" + ENDPOINTS = "/api/endpoints" CONTAINERS = "/docker/containers/" PULLIMAGE = "/docker/images/create?fromImage=" ) @@ -158,7 +158,7 @@ func SearchContainer(username, password, domain, name string) ([]*map[string]int // the search regex start with ^/blobber_ because the blobber config files reside in blobber folder // https://github.com/0chain/zcnwebappscripts/blob/main/chimney.sh#L18 - url := domain + ENDPOINTS + endpointID + CONTAINERS + fmt.Sprintf("json?all=1&filters={\"name\":[\"^/blobber_%s*\"]}", name) + url := domain + ENDPOINTS + endpointID + CONTAINERS + fmt.Sprintf("json?all=1&filters={\"name\":[\"^/%s*\"]}", name) return searchContainerInternal(authToken, url) } diff --git a/zboxcore/sdk/dirworker.go b/zboxcore/sdk/dirworker.go index a8808d0ad..c833f7bdf 100644 --- a/zboxcore/sdk/dirworker.go +++ b/zboxcore/sdk/dirworker.go @@ -310,8 +310,11 @@ func (dirOp *DirOperation) Process(allocObj *Allocation, connectionID string) ([ mu: dirOp.maskMU, wg: &sync.WaitGroup{}, } - dR.consensusThresh = dirOp.consensusThresh - dR.fullconsensus = dirOp.fullconsensus + dR.Consensus = Consensus{ + RWMutex: &sync.RWMutex{}, + consensusThresh: dR.consensusThresh, + fullconsensus: dR.fullconsensus, + } _ = dR.ProcessWithBlobbers(allocObj) diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index aae9d8e92..4ece59f0a 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -1037,17 +1037,16 @@ func getNewAllocationBlobbers( return nil, err } - //filter duplicates - ids := make(map[string]struct{}) - for _, id := range preferredBlobberIds { - ids[id] = struct{}{} - } - for _, id := range allocBlobberIDs { - ids[id] = struct{}{} - } - blobbers := make([]string, 0, len(ids)) - for id := range ids { - blobbers = append(blobbers, id) + blobbers := append(preferredBlobberIds, allocBlobberIDs...) + + // filter duplicates + ids := make(map[string]bool) + uniqueBlobbers := []string{} + for _, b := range blobbers { + if !ids[b] { + uniqueBlobbers = append(uniqueBlobbers, b) + ids[b] = true + } } return map[string]interface{}{ @@ -1055,7 +1054,7 @@ func getNewAllocationBlobbers( "parity_shards": parityshards, "size": size, "expiration_date": expiry, - "blobbers": blobbers, + "blobbers": uniqueBlobbers, "read_price_range": readPrice, "write_price_range": writePrice, }, nil diff --git a/zboxcore/sdk/writemarker_mutex.go b/zboxcore/sdk/writemarker_mutex.go index e531dd8e9..6d293ea70 100644 --- a/zboxcore/sdk/writemarker_mutex.go +++ b/zboxcore/sdk/writemarker_mutex.go @@ -218,7 +218,7 @@ func (wmMu *WriteMarkerMutex) Lock( } wg := &sync.WaitGroup{} - cons := &Consensus{} + cons := &Consensus{RWMutex: &sync.RWMutex{}} for i := *mask; !i.Equals64(0); i = i.And(zboxutil.NewUint128(1).Lsh(pos).Not()) { pos = uint64(i.TrailingZeros()) From 9f45f6c9dbfb45b87a99d8d821c4175d39def9d6 Mon Sep 17 00:00:00 2001 From: Piers Shepperson Date: Thu, 29 Jun 2023 22:42:13 +0100 Subject: [PATCH 3/3] Rename blobber field to not_available (#1043) * remove unstake total * not_available * added GRAPHNODE_SC * fixes for update image (#1058) * update wasm demo for download * preserver order in blobber of newallocationrequestg * fixes for update image * use multiUpload * demo for multi operation * clean up logs * init Consensus * feat wasm: UpdateForbidAllocation * expose lockReadPool * fix for unique blobbers * init Consensus in Lock function (#1063) * init Consensus * fix panic in dirworker --------- Co-authored-by: Hitenjain14 * run build on all PRs * run on every PR --------- Co-authored-by: Manali-Jain-Squareops Co-authored-by: boddumanohar Co-authored-by: Hitenjain14 Co-authored-by: Kishan Dhakan <42718091+Kishan-Dhakan@users.noreply.github.com> --- .github/workflows/build-sdks.yml | 1 - .github/workflows/tests.yml | 1 - zboxcore/sdk/sdk.go | 2 +- zcncore/transaction.go | 2 +- zcncore/transaction_mobile.go | 4 ++-- 5 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-sdks.yml b/.github/workflows/build-sdks.yml index af614cf7d..c17e192cd 100644 --- a/.github/workflows/build-sdks.yml +++ b/.github/workflows/build-sdks.yml @@ -10,7 +10,6 @@ on: tags: - 'v*.*.*' pull_request: - branches: [ master, staging, qa ] workflow_dispatch: env: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 05169e4e1..5d7fd4e34 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,6 @@ on: push: branches: [ master, staging ] pull_request: - branches: [ master, staging ] workflow_dispatch: env: diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 4ece59f0a..a7ebc890e 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -580,7 +580,7 @@ type Blobber struct { UncollectedServiceCharge int64 `json:"uncollected_service_charge"` IsKilled bool `json:"is_killed"` IsShutdown bool `json:"is_shutdown"` - IsAvailable bool `json:"is_available"` + NotAvailable bool `json:"not_available"` } type Validator struct { diff --git a/zcncore/transaction.go b/zcncore/transaction.go index 53a8dc0fa..19dfed39c 100644 --- a/zcncore/transaction.go +++ b/zcncore/transaction.go @@ -209,7 +209,7 @@ type Blobber struct { Allocated common.Size `json:"allocated"` LastHealthCheck common.Timestamp `json:"last_health_check"` StakePoolSettings StakePoolSettings `json:"stake_pool_settings"` - IsAvailable bool `json:"is_available"` + NotAvailable bool `json:"not_available"` } type Validator struct { diff --git a/zcncore/transaction_mobile.go b/zcncore/transaction_mobile.go index 5309cb26b..2d1bf7380 100644 --- a/zcncore/transaction_mobile.go +++ b/zcncore/transaction_mobile.go @@ -178,7 +178,7 @@ type blobber struct { LastHealthCheck int64 `json:"last_health_check"` Terms Terms `json:"terms"` StakePoolSettings StakePoolSettings `json:"stake_pool_settings"` - IsAvailable bool `json:"is_available"` + NotAvailable bool `json:"not_available"` } func (b *blobber) SetStakePoolSettings(delegateWallet string, minStake int64, maxStake int64, numDelegates int, serviceCharge float64) { @@ -200,7 +200,7 @@ func (b *blobber) SetTerms(readPrice int64, writePrice int64, minLockDemand floa } func (b *blobber) SetAvailable(availability bool) { - b.IsAvailable = availability + b.NotAvailable = availability } type Validator interface {