From afade4fb0920db92ef52028dc4891a7d7b3991ff Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Sat, 5 Jul 2025 16:36:55 +0530 Subject: [PATCH 01/18] miner transaction request reduce timeout --- core/transaction/entity.go | 4 ++-- core/util/httpnet.go | 27 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 995a45954..5eed4ef60 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -270,7 +270,7 @@ func (t *Transaction) VerifySigWith(pubkey string, verifyHandler VerifyFunc) (bo } func SendTransactionSync(txn *Transaction, miners []string) error { - const requestTimeout = 3 * time.Second // Timeout for each request + const requestTimeout = 12 * time.Second // Timeout for each request fails := make(chan error, len(miners)) var wg sync.WaitGroup @@ -282,7 +282,7 @@ func SendTransactionSync(txn *Transaction, miners []string) error { go func(url string) { defer wg.Done() - // Create a context with a 30-second timeout for each request + // Create a context with a 12-second timeout for each request ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) defer cancel() diff --git a/core/util/httpnet.go b/core/util/httpnet.go index bcc5f2b77..7a9e9703f 100644 --- a/core/util/httpnet.go +++ b/core/util/httpnet.go @@ -85,18 +85,27 @@ func init() { func httpDo(req *http.Request, ctx context.Context, cncl context.CancelFunc, f func(*http.Response, error) error) error { c := make(chan error, 1) + done := make(chan struct{}) - go func() { c <- f(Client.Do(req.WithContext(ctx))) }() + go func() { + select { + case c <- f(Client.Do(req.WithContext(ctx))): + // normal completion + case <-done: + // context cancelled, do not call f + } + }() select { - case <-ctx.Done(): - // Use the cancel function only after trying to get the result. - <-c // Wait for f to return. - return ctx.Err() - case err := <-c: - // Ensure that we call cncl after we are done with the response - defer cncl() // Move this here to ensure we cancel after processing - return err + case <-ctx.Done(): + // Use the cancel function only after trying to get the result. + close(done) + cncl() + return ctx.Err() + case err := <-c: + // Ensure that we call cncl after we are done with the response + defer cncl() // Move this here to ensure we cancel after processing + return err } } From 03482a5fd20b5a9dc400bf84af1182705658bd35 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Mon, 21 Jul 2025 09:42:14 +0530 Subject: [PATCH 02/18] upload test --- core/client/set.go | 45 +++++++- core/sys/sign.go | 3 + core/sys/vars.go | 2 +- core/version/version.go | 3 +- zboxcore/sdk/allocation.go | 3 + zboxcore/sdk/chunked_upload.go | 14 ++- zboxcore/sdk/chunked_upload_blobber.go | 16 ++- zboxcore/sdk/chunked_upload_form_builder.go | 7 +- zboxcore/sdk/chunked_upload_model.go | 2 + zboxcore/sdk/chunked_upload_option.go | 7 ++ zboxcore/sdk/chunked_upload_process.go | 25 +++- zboxcore/sdk/commitworker.go | 68 +++++++++-- zboxcore/sdk/multi_operation_worker.go | 80 +++++++++++-- zboxcore/sdk/rollback.go | 22 +++- zboxcore/sdk/sdk.go | 119 ++++++++++++++++++++ zboxcore/sdk/upload_worker.go | 5 + zboxcore/zboxutil/http.go | 61 +++++++++- 17 files changed, 439 insertions(+), 43 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index 113909e90..5a6772da1 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "strings" + "sync" "github.com/0chain/gosdk/core/conf" @@ -34,6 +35,8 @@ type Client struct { nonce int64 txnFee uint64 sign SignFunc + wg map[string]*sync.WaitGroup + walletCount map[string]int // maintains count of wallets in the WaitGroup by Client ID } type InitSdkOptions struct { @@ -74,7 +77,7 @@ func init() { // get sign lock <-sigC fmt.Println("Sign: with sys.SignWithAuth:", sys.SignWithAuth, "sysKeys:", GetClientSysKeys(clients...)) - sig, err := sys.SignWithAuth(hash, client.signatureScheme, GetClientSysKeys(clients...)) + sig, err := sys.SignWithAuth(hash, client.signatureScheme, GetClientSysKeys(clients...), wallet.ClientID) sigC <- struct{}{} return sig, err } @@ -82,6 +85,9 @@ func init() { sys.Verify = verifySignature sys.VerifyWith = verifySignatureWith sys.VerifyEd25519With = verifyEd25519With + + client.wg = make(map[string]*sync.WaitGroup) + client.walletCount = make(map[string]int) } var SignFn = func(hash string) (string, error) { @@ -95,16 +101,18 @@ var SignFn = func(hash string) (string, error) { return ss.Sign(hash) } -func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair) (string, error) { +func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair, clientID string) (string, error) { sig, err := sys.Sign(hash, signatureScheme, keys) if err != nil { return "", fmt.Errorf("failed to sign with split key: %v", err) } + fmt.Printf("Signature: %s\n", sig) + fmt.Printf("ClientID signHashWithAuth: %s\n", clientID) data, err := json.Marshal(AuthMessage{ Hash: hash, Signature: sig, - ClientID: client.wallet.ClientID, + ClientID: clientID, }) if err != nil { return "", err @@ -209,6 +217,37 @@ func SetWallet(w zcncrypto.Wallet) { client.wallets[w.ClientID] = &w } +func GetWalletByClientID(clientID string) *zcncrypto.Wallet { + if client.wallets == nil { + return nil + } + if _, exists := client.wallets[clientID]; !exists { + return nil + } + return client.wallets[clientID] +} + +func AddWallet(wallet zcncrypto.Wallet) { + if client.wallets == nil { + client.wallets = make(map[string]*zcncrypto.Wallet) + } + if _, exists := client.wg[wallet.ClientID]; !exists { + client.wg[wallet.ClientID] = &sync.WaitGroup{} + } + client.wg[wallet.ClientID].Add(1) + client.walletCount[wallet.ClientID]++ + client.wallets[wallet.ClientID] = &wallet +} + +// RemoveWallet should be set before any transaction or client specific APIs +func RemoveWallet(clientID string) { + client.wg[clientID].Done() + client.walletCount[clientID]-- + if client.walletCount[clientID] == 0 { + delete(client.wallets, clientID) + } +} + // SetWalletMode sets current wallet split key mode. func SetWalletMode(mode bool) { if client.wallet != nil { diff --git a/core/sys/sign.go b/core/sys/sign.go index 37ac18479..6f398b8a1 100644 --- a/core/sys/sign.go +++ b/core/sys/sign.go @@ -9,6 +9,9 @@ type KeyPair struct { // SignFunc sign method for request verification type SignFunc func(hash string, signatureScheme string, keys []KeyPair) (string, error) +// SignFunc sign method for request verification +type SignWithAuthFunc func(hash string, signatureScheme string, keys []KeyPair, clientId string) (string, error) + type VerifyFunc func(signature string, msg string) (bool, error) type VerifyWithFunc func(pk, signature string, msg string) (bool, error) diff --git a/core/sys/vars.go b/core/sys/vars.go index f1f0fde5c..866c3980d 100644 --- a/core/sys/vars.go +++ b/core/sys/vars.go @@ -15,7 +15,7 @@ var ( // Sign sign method. it should be initialized on different platform. Sign SignFunc - SignWithAuth SignFunc + SignWithAuth SignWithAuthFunc // Verify verify method. it should be initialized on different platform. Verify VerifyFunc diff --git a/core/version/version.go b/core/version/version.go index fa0af25cc..4f54f23ab 100644 --- a/core/version/version.go +++ b/core/version/version.go @@ -1,5 +1,6 @@ + //====== THIS IS AUTOGENERATED FILE. DO NOT MODIFY ======== package version +const VERSIONSTR = "v1.20.6-1-gafade4fb" -const VERSIONSTR = "v1.17.11-269-g7fd90660" diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 1c4991bdb..4c8dc0aa5 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -1082,6 +1082,7 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul go func(pos int) { defer wg.Done() err := mo.createConnectionObj(pos) + fmt.Printf("Multioperation: create connection for blobber %d , err : %v", pos, err) if err != nil { l.Logger.Error(err.Error()) connectionErrors[pos] = err @@ -1189,8 +1190,10 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul mo.operations = append(mo.operations, operation) } + fmt.Printf("Multioperation: operations to process %d ; operations: %v \n", len(mo.operations), mo.operations) if len(mo.operations) > 0 { err := mo.Process() + fmt.Printf("Multioperation: Process operations, err : %v", err) if err != nil { return err } diff --git a/zboxcore/sdk/chunked_upload.go b/zboxcore/sdk/chunked_upload.go index 1408fa539..d4d416de8 100644 --- a/zboxcore/sdk/chunked_upload.go +++ b/zboxcore/sdk/chunked_upload.go @@ -430,10 +430,14 @@ func (su *ChunkedUpload) process() error { defer su.chunkReader.Release() defer su.chunkReader.Close() defer su.ctxCncl(nil) + + fmt.Printf("ChunkedUpload process started for %s\n", su.fileMeta.RemoteName) for { - chunks, err := su.readChunks(su.chunkNumber) + fmt.Printf("Reading chunks from chunk reader: %v\n", su.chunkNumber) + chunks, err := su.readChunks(su.chunkNumber) + fmt.Printf("readChunks returned: %v\n", err) // chunk, err := su.chunkReader.Next() if err != nil { if su.statusCallback != nil { @@ -449,6 +453,7 @@ func (su *ChunkedUpload) process() error { if chunks.isFinal { if su.fileMeta.ActualHash == "" { su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash() + fmt.Printf("GetFileHash returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -463,6 +468,7 @@ func (su *ChunkedUpload) process() error { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, thrown.New("upload_failed", "Upload failed. Uploaded size does not match with actual size: "+fmt.Sprintf("%d != %d", su.fileMeta.ActualSize, su.progress.ReadLength))) } + fmt.Printf("Upload failed. Uploaded size does not match with actual size: %d != %d\n", su.fileMeta.ActualSize, su.progress.ReadLength) return thrown.New("upload_failed", "Upload failed. Uploaded size does not match with actual size: "+fmt.Sprintf("%d != %d", su.fileMeta.ActualSize, su.progress.ReadLength)) } } @@ -472,6 +478,7 @@ func (su *ChunkedUpload) process() error { chunks.fileShards, chunks.thumbnailShards, chunks.isFinal, chunks.totalReadSize, ) + fmt.Printf("su processUpload returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -683,6 +690,7 @@ func (su *ChunkedUpload) uploadProcessor() { } func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { + fmt.Printf("uploadToBlobbers started!") select { case <-su.ctx.Done(): return context.Cause(su.ctx) @@ -706,7 +714,7 @@ func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { go func(pos uint64) { defer wg.Done() err := su.blobbers[pos].sendUploadRequest(ctx, su, uploadData.isFinal, su.encryptedKey, uploadData.uploadBody[pos].dataBuffers, uploadData.uploadBody[pos].formData, uploadData.uploadBody[pos].contentSlice, pos, &consensus) - + fmt.Printf("sendUploadRequest returned: %v\n", err) if err != nil { if strings.Contains(err.Error(), "duplicate") { su.consensus.Done() @@ -728,12 +736,14 @@ func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { close(wgErrors) for err := range wgErrors { su.ctxCncl(thrown.New("upload_failed", fmt.Sprintf("Upload failed. %s", err))) + fmt.Printf("Upload failed with error: %v\n", err) return err } if !consensus.isConsensusOk() { err := thrown.New("consensus_not_met", fmt.Sprintf("Upload failed File not found for path %s. Required consensus atleast %d, got %d", su.fileMeta.RemotePath, consensus.consensusThresh, consensus.getConsensus())) su.ctxCncl(err) + fmt.Printf("Upload failed with consensus error: %v\n", err) return err } if uploadData.uploadLength > 0 { diff --git a/zboxcore/sdk/chunked_upload_blobber.go b/zboxcore/sdk/chunked_upload_blobber.go index 2bbe2fe7a..847441b07 100644 --- a/zboxcore/sdk/chunked_upload_blobber.go +++ b/zboxcore/sdk/chunked_upload_blobber.go @@ -71,6 +71,12 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest( eg, _ := errgroup.WithContext(ctx) + clientID := su.allocationObj.Owner + if su.wallet != nil { + clientID = su.wallet.ClientID + } + fmt.Printf("clientID: %s\n", clientID) + fmt.Printf("allocation owner: %s\n", su.allocationObj.Owner) for dataInd := 0; dataInd < len(dataBuffers); dataInd++ { ind := dataInd eg.Go(func() error { @@ -80,11 +86,19 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest( var req *fasthttp.Request for i := 0; i < 6; i++ { req, err = zboxutil.NewFastUploadRequest( - sb.blobber.Baseurl, su.allocationObj.ID, su.allocationObj.Tx, dataBuffers[ind].Bytes(), su.httpMethod, su.allocationObj.Owner) + sb.blobber.Baseurl, su.allocationObj.ID, su.allocationObj.Tx, dataBuffers[ind].Bytes(), su.httpMethod, clientID) if err != nil { return err } + // Print all headers + fmt.Printf("Blobber Upload Request Headers for %s:\n", sb.blobber.Baseurl) + req.Header.VisitAll(func(k, v []byte) { + fmt.Printf(" %s: %s\n", string(k), string(v)) + }) + // Print body + // fmt.Printf("Blobber Upload Request Body for %s:\n%s\n", sb.blobber.Baseurl, string(req.Body())) + req.Header.Add("Content-Type", contentSlice[ind]) err, shouldContinue = func() (err error, shouldContinue bool) { resp := fasthttp.AcquireResponse() diff --git a/zboxcore/sdk/chunked_upload_form_builder.go b/zboxcore/sdk/chunked_upload_form_builder.go index 6781d311b..76c1406b9 100644 --- a/zboxcore/sdk/chunked_upload_form_builder.go +++ b/zboxcore/sdk/chunked_upload_form_builder.go @@ -24,7 +24,7 @@ type ChunkedUploadFormBuilder interface { fileMeta *FileMeta, hasher Hasher, connectionID, blobberID string, chunkSize int64, chunkStartIndex, chunkEndIndex int, isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte, - thumbnailChunkData []byte, shardSize int64, + thumbnailChunkData []byte, shardSize int64, clients... string, ) (blobberData, error) } @@ -59,7 +59,7 @@ func (b *chunkedUploadFormBuilder) Build( fileMeta *FileMeta, hasher Hasher, connectionID, blobberID string, chunkSize int64, chunkStartIndex, chunkEndIndex int, isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte, - thumbnailChunkData []byte, shardSize int64, + thumbnailChunkData []byte, shardSize int64, clients... string, ) (blobberData, error) { metadata := ChunkedUploadFormMetadata{ @@ -149,6 +149,7 @@ func (b *chunkedUploadFormBuilder) Build( metadata.FileBytesLen += len(chunkBytes) } + fmt.Printf("b.privateSigningKey: %v\n", b.privateSigningKey) if isFinal && i == numBodies-1 { err = hasher.Finalize() if err != nil { @@ -206,7 +207,7 @@ func (b *chunkedUploadFormBuilder) Build( } formData.ValidationRootSignature = hex.EncodeToString(sig) } else { - rootSig, err := client.Sign(hash) + rootSig, err := client.Sign(hash, clients...) if err != nil { return res, err } diff --git a/zboxcore/sdk/chunked_upload_model.go b/zboxcore/sdk/chunked_upload_model.go index d5fb3d42f..db26f0407 100644 --- a/zboxcore/sdk/chunked_upload_model.go +++ b/zboxcore/sdk/chunked_upload_model.go @@ -11,6 +11,7 @@ import ( "time" "github.com/0chain/gosdk/core/common" + "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/allocationchange" "github.com/0chain/gosdk/zboxcore/encryption" "github.com/0chain/gosdk/zboxcore/fileref" @@ -97,6 +98,7 @@ type ChunkedUpload struct { processMap map[int]zboxutil.Uint128 //nolint:unused //used in wasm check chunked_upload_process_js.go processMapLock sync.Mutex //nolint:unused + wallet *zcncrypto.Wallet } // FileMeta metadata of stream input/local diff --git a/zboxcore/sdk/chunked_upload_option.go b/zboxcore/sdk/chunked_upload_option.go index 09bc26e56..89b7d5835 100644 --- a/zboxcore/sdk/chunked_upload_option.go +++ b/zboxcore/sdk/chunked_upload_option.go @@ -7,6 +7,7 @@ import ( "os" "time" + "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/zboxutil" "github.com/klauspost/reedsolomon" ) @@ -37,6 +38,12 @@ func WithThumbnail(buf []byte) ChunkedUploadOption { } } +func WithWallet(w *zcncrypto.Wallet) ChunkedUploadOption { + return func(su *ChunkedUpload) { + su.wallet = w + } +} + // WithThumbnailFile add thumbnail from file. stream mode is unnecessary for thumbnail. // - fileName: file name of the thumbnail, which will be read and uploaded func WithThumbnailFile(fileName string) ChunkedUploadOption { diff --git a/zboxcore/sdk/chunked_upload_process.go b/zboxcore/sdk/chunked_upload_process.go index 72a7560b7..6fc8e0ece 100644 --- a/zboxcore/sdk/chunked_upload_process.go +++ b/zboxcore/sdk/chunked_upload_process.go @@ -43,6 +43,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, fileShards []blobberShards, thumbnailShards blobberShards, isFinal bool, uploadLength int64) error { + fmt.Printf("inside su processUpload for chunk %d-%d\n", chunkStartIndex, chunkEndIndex) //chunk has not be uploaded yet if chunkEndIndex <= su.progress.ChunkIndex { // Write data to hashers @@ -50,6 +51,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, hasher := su.blobbers[i].progress.Hasher for _, chunkBytes := range blobberShard { err := hasher.WriteToFixedMT(chunkBytes) + fmt.Printf("WriteToFixedMT returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -57,6 +59,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, return err } err = hasher.WriteToValidationMT(chunkBytes) + fmt.Printf("WriteToValidationMT returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -88,6 +91,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, wgErrors := make(chan error, len(su.blobbers)) if len(fileShards) == 0 { + fmt.Printf("No data to upload, skipping upload process\n") return thrown.New("upload_failed", "Upload failed. No data to upload") } @@ -105,10 +109,21 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, wg.Add(1) go func(b *ChunkedUploadBlobber, thumbnailChunkData []byte, pos uint64) { defer wg.Done() - uploadData, err := su.formBuilder.Build( - &su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID, blobber.blobber.ID, - su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint, - fileShards[pos], thumbnailChunkData, su.shardSize) + var uploadData blobberData + var err error + if su.wallet != nil { + uploadData, err = su.formBuilder.Build( + &su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID, blobber.blobber.ID, + su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint, + fileShards[pos], thumbnailChunkData, su.shardSize, su.wallet.ClientID) + fmt.Printf("Build returned: %v\n", err) + } else { + uploadData, err = su.formBuilder.Build( + &su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID, blobber.blobber.ID, + su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint, + fileShards[pos], thumbnailChunkData, su.shardSize) + fmt.Printf("Build returned: %v\n", err) + } if err != nil { errC := atomic.AddInt32(&errCount, 1) if errC > int32(su.allocationObj.ParityShards-1) { // If atleast data shards + 1 number of blobbers can process the upload, it can be repaired later @@ -136,6 +151,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, close(wgErrors) fileShards = nil for err := range wgErrors { + fmt.Printf("Error in upload: %v\n", err) su.removeProgress() return thrown.New("upload_failed", fmt.Sprintf("Upload failed. %s", err)) } @@ -159,6 +175,7 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, blobberUpload.uploadBody = finalBuffer return su.uploadToBlobbers(blobberUpload) } + fmt.Printf("ChunkedUpload processUpload completed for chunk %d-%d\n", chunkStartIndex, chunkEndIndex) return nil } diff --git a/zboxcore/sdk/commitworker.go b/zboxcore/sdk/commitworker.go index 84449614c..f0ded1745 100644 --- a/zboxcore/sdk/commitworker.go +++ b/zboxcore/sdk/commitworker.go @@ -20,6 +20,7 @@ import ( thrown "github.com/0chain/errors" "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/encryption" + "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/allocationchange" "github.com/0chain/gosdk/zboxcore/blockchain" "github.com/0chain/gosdk/zboxcore/fileref" @@ -90,6 +91,7 @@ type CommitRequestV2 struct { commitMask zboxutil.Uint128 changeIndex uint64 isRepair bool + wallet *zcncrypto.Wallet } var ( @@ -404,6 +406,7 @@ type refPathResp struct { } func (commitReq *CommitRequestV2) processCommit() { + fmt.Printf("commitReqV2 processCommit called\n") defer commitReq.wg.Done() l.Logger.Debug("received a commit request") paths := make([]string, 0) @@ -433,7 +436,19 @@ func (commitReq *CommitRequestV2) processCommit() { pos = uint64(i.TrailingZeros()) go func(ind uint64) { blobber := commitReq.allocationObj.Blobbers[ind] - trie, err := getReferencePathV2(blobber, commitReq.allocationObj.ID, commitReq.allocationObj.Tx, commitReq.sig, paths, &success, mu) + // trie, err := getReferencePathV2(blobber, commitReq.allocationObj.ID, commitReq.allocationObj.Tx, commitReq.sig, paths, &success, mu) + + var ( + trie *wmpt.WeightedMerkleTrie + err error + ) + if commitReq.wallet != nil { + trie, err = getReferencePathV2(blobber, commitReq.allocationObj.ID, commitReq.allocationObj.Tx, commitReq.sig, paths, &success, mu, commitReq.wallet.ClientID) + } else { + trie, err = getReferencePathV2(blobber, commitReq.allocationObj.ID, commitReq.allocationObj.Tx, commitReq.sig, paths, &success, mu) + } + fmt.Printf("getReferencePathV2 err: %v\n", err) + resp := refPathResp{ trie: trie, err: err, @@ -468,11 +483,13 @@ func (commitReq *CommitRequestV2) processCommit() { } if trie == nil { + fmt.Printf("Failed to get reference path\n") commitReq.commitMask = zboxutil.NewUint128(0) commitReq.result = ErrorCommitResult("Failed to get reference path") return } if commitReq.commitMask.CountOnes() < commitReq.consensusThresh { + fmt.Printf("Consensus threshold not met: %d < %d\n", commitReq.commitMask.CountOnes(), commitReq.consensusThresh) commitReq.commitMask = zboxutil.NewUint128(0) commitReq.result = ErrorCommitResult("Failed to get reference path") return @@ -480,11 +497,13 @@ func (commitReq *CommitRequestV2) processCommit() { elapsedGetRefPath := time.Since(now) prevWeight := trie.Weight() for _, change := range commitReq.changes { + fmt.Printf("Processing change: %T\n", change) if change == nil { continue } err = change.ProcessChangeV2(trie, changeIndex) if err != nil && err != wmpt.ErrNotFound { + fmt.Printf("Error processing change: %v\n", err) l.Logger.Error("Error processing change ", err) commitReq.result = ErrorCommitResult("Failed to process change " + err.Error()) return @@ -505,6 +524,7 @@ func (commitReq *CommitRequestV2) processCommit() { defer wg.Done() commitErr := commitReq.commitBlobber(rootHash, rootWeight, prevWeight, blobber) if commitErr != nil { + fmt.Printf("Error committing to blobber: %s - %v\n", blobber.Baseurl, commitErr) l.Logger.Error("Error committing to blobber: ", blobber.Baseurl, " ", commitErr) errSlice[ind] = commitErr mu.Lock() @@ -538,12 +558,14 @@ func (commitReq *CommitRequestV2) processCommit() { err = errors.New("consensus_not_met", fmt.Sprintf("Successfully committed to %d blobbers, but required %d", commitReq.commitMask.CountOnes(), commitReq.consensusThresh)) } commitReq.result = ErrorCommitResult(err.Error()) + fmt.Printf("Consensus threshold not met: %d < %d\n", commitReq.commitMask.CountOnes(), commitReq.consensusThresh) return } if !commitReq.isRepair { commitReq.allocationObj.allocationRoot = encryption.Hash(hex.EncodeToString(rootHash) + commitReq.allocationObj.ID) } l.Logger.Info("[commit] ", "elapsedGetRefPath ", elapsedGetRefPath.Milliseconds(), " elapsedProcessChanges ", elapsedProcessChanges.Milliseconds(), " elapsedCommit ", elapsedCommit.Milliseconds(), " total ", time.Since(now).Milliseconds()) + fmt.Printf("processCommit completed!\n") commitReq.result = SuccessCommitResult() } @@ -574,6 +596,9 @@ func (req *CommitRequestV2) commitBlobber(rootHash []byte, rootWeight, prevWeigh wm.AllocationID = req.allocationObj.ID wm.FileMetaRoot = fileMetaRoot wm.ClientID = client.Id() + if req.wallet != nil { + wm.ClientID = req.wallet.ClientID + } err = wm.Sign() if err != nil { l.Logger.Error("Error signing writemarker", err) @@ -585,8 +610,12 @@ func (req *CommitRequestV2) commitBlobber(rootHash []byte, rootWeight, prevWeigh return err } - err = submitWriteMarker(wmData, nil, blobber, req.connectionID, req.allocationObj.ID, req.allocationObj.Tx, req.allocationObj.StorageVersion) - if err != nil { + if req.wallet != nil { + err = submitWriteMarker(wmData, nil, blobber, req.connectionID, req.allocationObj.ID, req.allocationObj.Tx, req.allocationObj.StorageVersion, req.wallet.ClientID) + } else { + err = submitWriteMarker(wmData, nil, blobber, req.connectionID, req.allocationObj.ID, req.allocationObj.Tx, req.allocationObj.StorageVersion) + } + if err != nil { l.Logger.Error("Error submitting writemarker ", err) return err } @@ -616,7 +645,8 @@ func getFormWritter(connectionID string, wmData, fileIDMetaData []byte, body *by return formWriter, nil } -func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocationTx, sig string, paths []string, success *bool, mu *sync.Mutex) (*wmpt.WeightedMerkleTrie, error) { +func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocationTx, sig string, paths []string, success *bool, mu *sync.Mutex, clientIds... string) (*wmpt.WeightedMerkleTrie, error) { + fmt.Printf("initial success: %v\n", *success) if len(paths) == 0 || blobber.LatestWM == nil || blobber.LatestWM.ChainSize == 0 { var node wmpt.Node if blobber.LatestWM != nil && len(blobber.LatestWM.FileMetaRoot) > 0 && blobber.LatestWM.ChainSize > 0 { @@ -635,7 +665,8 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio for retries := 0; retries < 3; retries++ { err, shouldContinue = func() (err error, shouldContinue bool) { var req *http.Request - req, err = zboxutil.NewReferencePathRequestV2(blobber.Baseurl, allocationID, allocationTx, sig, paths, false) + req, err = zboxutil.NewReferencePathRequestV2(blobber.Baseurl, allocationID, allocationTx, sig, paths, false, clientIds...) + fmt.Printf("getReferencePathV2 req err: %v\n", err) if err != nil { l.Logger.Error("Creating ref path req", err) return @@ -643,6 +674,7 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio ctx, cncl := context.WithTimeout(context.Background(), (time.Second * 30)) err = zboxutil.HttpDo(ctx, cncl, req, func(resp *http.Response, err error) error { + fmt.Printf("HttpDo req err: %v\n", err) if err != nil { l.Logger.Error("Ref path error:", err) if errors.Is(err, http.ErrServerClosed) || strings.Contains(err.Error(), "GOAWAY") { @@ -675,6 +707,8 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio shouldContinue = true return err } + fmt.Printf("Reference path error response: Status: %d - %s ", + resp.StatusCode, string(respBody)) return errors.New( strconv.Itoa(resp.StatusCode), fmt.Sprintf("Reference path error response: Status: %d - %s ", @@ -695,6 +729,7 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio break } } + fmt.Printf("HttpDo after req err: %v\n", err) if err != nil { return nil, err } @@ -702,34 +737,49 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio elapsedRefPath := time.Since(now) mu.Lock() defer mu.Unlock() + fmt.Printf("after success: %v\n", *success) if *success { + fmt.Printf("errAlreadySuccessful err\n") return nil, errAlreadySuccessful } trie := wmpt.New(nil, nil) - if lR.LatestWM != nil { - err = lR.LatestWM.VerifySignature(client.PublicKey()) + if lR.LatestWM != nil { + var useClientID string + if len(clientIds) > 0 && clientIds[0] != "" { + useClientID = clientIds[0] + } else { + useClientID = client.Id() + } + wallet := client.GetWalletByClientID(useClientID) + + err = lR.LatestWM.VerifySignature(wallet.ClientKey) + fmt.Printf("verify signature err : %v\n", err) if err != nil { return nil, errors.New("signature_verification_failed", err.Error()) } err = trie.Deserialize(lR.Path) + fmt.Printf("Deserialize err : %v\n", err) if err != nil { l.Logger.Error("Error deserializing trie", err) return nil, err } l.Logger.Info("[getReferencePathV2] elapsedRefPath ", elapsedRefPath.Milliseconds(), " elapsedDeserialize ", (time.Since(now) - elapsedRefPath).Milliseconds()) chainBlocks := numBlocks(lR.LatestWM.ChainSize) + fmt.Printf("chain_length_mismatch: %v\n", err) if trie.Weight() != uint64(chainBlocks) { return nil, errors.New("chain_length_mismatch", fmt.Sprintf("Expected chain length %d, got %d", chainBlocks, trie.Weight())) } + fmt.Printf("allocation_root_mismatch: %v\n", err) if hex.EncodeToString(trie.Root()) != lR.LatestWM.FileMetaRoot { return nil, errors.New("allocation_root_mismatch", fmt.Sprintf("Expected allocation root %s, got %s", lR.LatestWM.AllocationRoot, hex.EncodeToString(trie.Root()))) } } *success = true + fmt.Printf("getReferencePathV2 success") return trie, nil } -func submitWriteMarker(wmData, metaData []byte, blobber *blockchain.StorageNode, connectionID, allocationID, allocationTx string, apiVersion int) (err error) { +func submitWriteMarker(wmData, metaData []byte, blobber *blockchain.StorageNode, connectionID, allocationID, allocationTx string, apiVersion int, clientIds... string) (err error) { var ( resp *http.Response shouldContinue bool @@ -742,7 +792,7 @@ func submitWriteMarker(wmData, metaData []byte, blobber *blockchain.StorageNode, l.Logger.Error("Creating form writer failed: ", err) return } - httpreq, err := zboxutil.NewCommitRequest(blobber.Baseurl, allocationID, allocationTx, body, apiVersion) + httpreq, err := zboxutil.NewCommitRequest(blobber.Baseurl, allocationID, allocationTx, body, apiVersion, clientIds...) if err != nil { l.Logger.Error("Error creating commit req: ", err) return diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index 38a6a6f07..dfa97818b 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -16,6 +16,7 @@ import ( "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/core/util" + "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/allocationchange" "github.com/0chain/gosdk/zboxcore/fileref" "github.com/0chain/gosdk/zboxcore/logger" @@ -63,10 +64,12 @@ type MultiOperation struct { changes [][]allocationchange.AllocationChange changesV2 []allocationchange.AllocationChangeV2 isRepair bool + wallet *zcncrypto.Wallet } func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { - + // fmt.Printf("Creating connection object for blobber index %d with connection ID %s", blobberIdx, mo.connectionID) + fmt.Printf("Creating connection object for blobber index %d with connection ID %s\n", blobberIdx, mo.connectionID) defer func() { if err == nil { mo.maskMU.Lock() @@ -85,6 +88,7 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { blobber := mo.allocationObj.Blobbers[blobberIdx] for i := 0; i < 3; i++ { + fmt.Printf("Iter %d", i+1) err, shouldContinue = func() (err error, shouldContinue bool) { body := new(bytes.Buffer) formWriter := multipart.NewWriter(body) @@ -95,11 +99,56 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { } formWriter.Close() + fmt.Printf("Creating connection object for blobber %s with connection ID %s", blobber.Baseurl, mo.connectionID) var httpreq *http.Request - httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.allocationObj.Owner) - if err != nil { - l.Logger.Error(blobber.Baseurl, "Error creating new connection request", err) - return + if mo.wallet != nil { + fmt.Printf("mo wallet : %v", *mo.wallet) + httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.wallet.ClientID) + if err != nil { + l.Logger.Error(blobber.Baseurl, "Error creating new connection request by wallet", err) + return err, false + } + + + // log + + fmt.Printf("Request created with wallet") + fmt.Printf("Request URL: %s\n", httpreq.URL.String()) + fmt.Printf("Request Method: %s\n", httpreq.Method) + fmt.Printf("Request Headers:\n") + for k, v := range httpreq.Header { + fmt.Printf(" %s: %v\n", k, v) + } + if httpreq.Body != nil { + bodyBytes, _ := io.ReadAll(httpreq.Body) + fmt.Printf("Request Body: %s\n", string(bodyBytes)) + // Restore body for later use + httpreq.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + } + + } else { + fmt.Printf("No wallet") + httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.allocationObj.Owner) + if err != nil { + l.Logger.Error(blobber.Baseurl, "Error creating new connection request", err) + return + } + + // log + + fmt.Printf("Request created without wallet") + fmt.Printf("Request URL: %s\n", httpreq.URL.String()) + fmt.Printf("Request Method: %s\n", httpreq.Method) + fmt.Printf("Request Headers:\n") + for k, v := range httpreq.Header { + fmt.Printf(" %s: %v\n", k, v) + } + if httpreq.Body != nil { + bodyBytes, _ := io.ReadAll(httpreq.Body) + fmt.Printf("Request Body: %s\n", string(bodyBytes)) + // Restore body for later use + httpreq.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) + } } httpreq.Header.Add("Content-Type", formWriter.FormDataContentType()) @@ -109,6 +158,7 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { resp = r return err }) + fmt.Printf("Create Connection Err: %v", err) if err != nil { logger.Logger.Error("Create Connection: ", err) return @@ -126,6 +176,8 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { latestRespMsg = string(respBody) latestStatusCode = resp.StatusCode + fmt.Printf("resp status code : %v", latestStatusCode) + fmt.Printf("resp status body : %v", latestRespMsg) if resp.StatusCode == http.StatusOK { l.Logger.Debug(blobber.Baseurl, " connection obj created.") return @@ -147,7 +199,8 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { err = errors.New("response_error", string(respBody)) return }() - + + fmt.Printf("Iter %d; err : %v, shouldContinue: %v", i+1, err, shouldContinue) if err != nil { return } @@ -163,6 +216,7 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { } func (mo *MultiOperation) Process() error { + fmt.Printf("MultiOperation Process start") l.Logger.Debug("MultiOperation Process start") wg := &sync.WaitGroup{} if mo.allocationObj.StorageVersion == 0 { @@ -270,7 +324,11 @@ func (mo *MultiOperation) Process() error { start = time.Now() status := Commit if !mo.isRepair && !mo.allocationObj.checkStatus { - status, _, err = mo.allocationObj.CheckAllocStatus() + if mo.wallet != nil { + status, _, err = mo.allocationObj.CheckAllocStatus(mo.wallet.ClientID) + } else { + status, _, err = mo.allocationObj.CheckAllocStatus() + } if err != nil { logger.Logger.Error("Error checking allocation status", err) if singleClientMode { @@ -323,7 +381,10 @@ func (mo *MultiOperation) Process() error { } if mo.allocationObj.StorageVersion == StorageV2 { - return mo.commitV2() + fmt.Printf("Commit V2 called!") + err = mo.commitV2() + fmt.Printf("Commit V2 returned: %v\n", err) + return err } commitReqs := make([]*CommitRequest, activeBlobbers) @@ -393,7 +454,7 @@ func (mo *MultiOperation) Process() error { } func (mo *MultiOperation) commitV2() error { - + fmt.Printf("commitV2 called \n") rootMap := make(map[string]zboxutil.Uint128) var pos uint64 for i := mo.operationMask; !i.Equals64(0); i = i.And(zboxutil.NewUint128(1).Lsh(pos).Not()) { @@ -427,6 +488,7 @@ func (mo *MultiOperation) commitV2() error { consensusThresh: threshold, changes: changes, isRepair: mo.isRepair, + wallet: mo.wallet, } commitReqs[counter] = commitReq counter++ diff --git a/zboxcore/sdk/rollback.go b/zboxcore/sdk/rollback.go index 6d1607c44..2e8480355 100644 --- a/zboxcore/sdk/rollback.go +++ b/zboxcore/sdk/rollback.go @@ -65,6 +65,13 @@ type BlobberStatus struct { func GetWritemarker(allocID, allocTx, sig, id, baseUrl string, clientId ...string) (*LatestPrevWriteMarker, error) { var lpm LatestPrevWriteMarker + var useClientID string + if len(clientId) > 0 && clientId[0] != "" { + useClientID = clientId[0] + } else { + useClientID = client.Id() + } + wallet := client.GetWalletByClientID(useClientID) req, err := zboxutil.NewWritemarkerRequest(baseUrl, allocID, allocTx, sig, clientId...) if err != nil { @@ -103,12 +110,12 @@ func GetWritemarker(allocID, allocTx, sig, id, baseUrl string, clientId ...strin return nil, err } if lpm.LatestWM != nil { - err = lpm.LatestWM.VerifySignature(client.PublicKey()) + err = lpm.LatestWM.VerifySignature(wallet.ClientKey) if err != nil { return nil, fmt.Errorf("signature verification failed for latest writemarker: %s", err.Error()) } if lpm.PrevWM != nil { - err = lpm.PrevWM.VerifySignature(client.PublicKey()) + err = lpm.PrevWM.VerifySignature(wallet.ClientKey) if err != nil { return nil, fmt.Errorf("signature verification failed for latest writemarker: %s", err.Error()) } @@ -269,7 +276,14 @@ func (rb *RollbackBlobber) processRollback(ctx context.Context, tx string) error // CheckAllocStatus checks the status of the allocation // and returns the status of the allocation and its blobbers. -func (a *Allocation) CheckAllocStatus() (AllocStatus, []BlobberStatus, error) { +func (a *Allocation) CheckAllocStatus(clientId... string) (AllocStatus, []BlobberStatus, error) { + + var useClientID string + if len(clientId) > 0 && clientId[0] != "" { + useClientID = clientId[0] + } else { + useClientID = a.Owner + } wg := &sync.WaitGroup{} markerChan := make(chan *RollbackBlobber, len(a.Blobbers)) @@ -286,7 +300,7 @@ func (a *Allocation) CheckAllocStatus() (AllocStatus, []BlobberStatus, error) { ID: blobber.ID, Status: "available", } - wr, err := GetWritemarker(a.ID, a.Tx, a.sig, blobber.ID, blobber.Baseurl, a.Owner) + wr, err := GetWritemarker(a.ID, a.Tx, a.sig, blobber.ID, blobber.Baseurl, useClientID) if err != nil { atomic.AddInt32(&errCnt, 1) markerError = err diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 91b8ee639..3254ec70f 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -7,12 +7,22 @@ import ( "io" "math" "net/http" + "os" + "path" "strconv" + "strings" "github.com/0chain/common/core/currency" "github.com/0chain/errors" + thrown "github.com/0chain/errors" + "github.com/0chain/gosdk/constants" "github.com/0chain/gosdk/core/logger" + "github.com/0chain/gosdk/core/pathutil" "github.com/0chain/gosdk/core/screstapi" + "github.com/0chain/gosdk/core/sys" + "github.com/0chain/gosdk/core/zcncrypto" + + // "github.com/0chain/gosdk/zcncore" "gopkg.in/natefinch/lumberjack.v2" "github.com/0chain/gosdk/core/client" @@ -1473,3 +1483,112 @@ func updateMaskBit(mask uint16, index uint8, value bool) uint16 { return mask & ^uint16(1< 0 && clientIds[0] != "" { + wallet := client.GetWalletByClientID(clientIds[0]) + req.Header.Set("X-App-Client-ID", wallet.ClientID) + req.Header.Set("X-App-Client-Key", wallet.ClientKey) + return + } req.Header.Set("X-App-Client-ID", client.Id()) req.Header.Set("X-App-Client-Key", client.PublicKey()) } @@ -208,7 +218,11 @@ func setClientInfoWithSign(req *http.Request, sig, allocation, baseURL string, c } else { clientID = client.Id() } - setClientInfo(req) + wallet := client.GetWalletByClientID(clientID) + fmt.Printf("setClientInfoWithSign: clientID: %s, allocation: %s, baseURL: %s\n", clientID, allocation, baseURL) + fmt.Printf("setClientInfoWithSign: wallet: %v\n", wallet) + req.Header.Set("X-App-Client-ID", wallet.ClientID) + req.Header.Set("X-App-Client-Key", wallet.ClientKey) req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) hashData := allocation + baseURL @@ -243,7 +257,7 @@ func NewCommitRequest(baseUrl, allocationID string, allocationTx string, body io if err != nil { return nil, err } - setClientInfo(req) + setClientInfo(req, clients...) req.Header.Set(ALLOCATION_ID_HEADER, allocationID) @@ -651,11 +665,21 @@ func NewFastUploadRequest(baseURL, allocationID string, allocationTx string, bod } func setFastClientInfoWithSign(req *fasthttp.Request, allocation, baseURL string, clients ...string) error { - req.Header.Set("X-App-Client-ID", client.Id()) - req.Header.Set("X-App-Client-Key", client.PublicKey()) + var clientID string + if len(clients) > 0 && clients[0] != "" { + clientID = clients[0] + } else { + clientID = client.Id() + } + wallet := client.GetWalletByClientID(clientID) + fmt.Printf("setFastClientInfoWithSign: clientID: %s, allocation: %s, baseURL: %s\n", clientID, allocation, baseURL) + fmt.Printf("setFastClientInfoWithSign: wallet: %v\n", wallet) + req.Header.Set("X-App-Client-ID", wallet.ClientID) + req.Header.Set("X-App-Client-Key", wallet.ClientKey) + hashData := allocation + baseURL - clientID := client.Id() + // clientID := client.Id() sig2, ok := SignCache.Get(hashData + ":" + clientID) if !ok { var err error @@ -694,7 +718,32 @@ func NewUploadRequest(baseUrl, allocationID, allocationTx, sig string, body io.R return req, nil } +func NewConnectionRequestByWallet(baseUrl, allocationID, allocationTx, sig string, body io.Reader, wallet *zcncrypto.Wallet) (*http.Request, error) { + l.Logger.Info(fmt.Sprintf("NewConnectionRequestByWallet: baseUrl: %s, allocationID: %s, allocationTx: %s, sig: %s", baseUrl, allocationID, allocationTx, sig)) + u, err := joinUrl(baseUrl, CREATE_CONNECTION_ENDPOINT, allocationTx) + if err != nil { + return nil, err + } + req, err := http.NewRequest(http.MethodPost, u.String(), body) + if err != nil { + return nil, err + } + req.Header.Set("X-App-Client-ID", wallet.ClientID) + req.Header.Set("X-App-Client-Key", wallet.ClientKey) + req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) + hashData := allocationTx + baseUrl + sig2, err := wallet.Sign(encryption.Hash(hashData), constants.BLS0CHAIN.String()) + if err != nil { + return nil, err + } + req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) + req.Header.Set(CLIENT_SIGNATURE_HEADER_V2, sig2) + req.Header.Set(ALLOCATION_ID_HEADER, allocationID) + return req, nil +} + func NewConnectionRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader, clients ...string) (*http.Request, error) { + l.Logger.Info(fmt.Sprintf("NewConnectionRequest: baseUrl: %s, allocationID: %s, allocationTx: %s, sig: %s", baseUrl, allocationID, allocationTx, sig)) u, err := joinUrl(baseUrl, CREATE_CONNECTION_ENDPOINT, allocationTx) if err != nil { return nil, err From 56990735ecd34770358a7b3517bf7c2db6249987 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Mon, 28 Jul 2025 12:03:22 +0530 Subject: [PATCH 03/18] upload test --- core/client/set.go | 3 ++ zboxcore/sdk/allocation.go | 19 +++++++++-- zboxcore/sdk/chunked_upload_form_builder.go | 22 ++++++++++++- zboxcore/sdk/deleteworker.go | 35 ++++++++++++++++++--- zboxcore/sdk/dirworker.go | 19 +++++++++-- zboxcore/sdk/downloadworker.go | 27 ++++++++++++++++ zboxcore/sdk/multi_operation_worker.go | 20 +++++++----- zboxcore/sdk/sdk.go | 2 +- zboxcore/zboxutil/http.go | 2 +- 9 files changed, 130 insertions(+), 19 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index 5a6772da1..c49df5e20 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -237,15 +237,18 @@ func AddWallet(wallet zcncrypto.Wallet) { client.wg[wallet.ClientID].Add(1) client.walletCount[wallet.ClientID]++ client.wallets[wallet.ClientID] = &wallet + fmt.Println("AddWallet: ", wallet.ClientID, "wallets: ", client.wallets, "wgCount: ", client.walletCount[wallet.ClientID]) } // RemoveWallet should be set before any transaction or client specific APIs func RemoveWallet(clientID string) { + fmt.Println("RemoveWallet: ", clientID, "wg: ", client.wg[clientID]) client.wg[clientID].Done() client.walletCount[clientID]-- if client.walletCount[clientID] == 0 { delete(client.wallets, clientID) } + fmt.Println("RemoveWallet: ", clientID, "wallets: ", client.wallets, "wgCount: ", client.walletCount[clientID]) } // SetWalletMode sets current wallet split key mode. diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 4c8dc0aa5..c9278a00f 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -1049,6 +1049,7 @@ func (a *Allocation) RepairRequired(remotepath string) (zboxutil.Uint128, zboxut // - operations: the operations to perform. // - opts: the options of the multi operation as operation functions that customize the multi operation. func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...MultiOperationOption) error { + fmt.Printf("DoMultiOperation called with operations %v with Opts : %v", operations, opts) if len(operations) == 0 { return nil } @@ -1070,9 +1071,11 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul consensusThresh: a.consensusThreshold, fullconsensus: a.fullconsensus, } + fmt.Printf("opts : %v", opts) for _, opt := range opts { opt(&mo) } + fmt.Printf("mo.Wallet : %v", mo.Wallet) previousPaths := make(map[string]bool) connectionErrors := make([]error, len(mo.allocationObj.Blobbers)) @@ -1152,10 +1155,20 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul operation, newConnectionID, err = NewUploadOperation(mo.ctx, op.Workdir, mo.allocationObj, mo.connectionID, op.FileMeta, op.FileReader, false, op.IsWebstreaming, op.IsRepair, op.DownloadFile, op.StreamUpload, op.Opts...) case constants.FileOperationDelete: + fmt.Printf("FileOperationDelete : %v", op.RemotePath) + var clientId string + if mo.Wallet != nil { + fmt.Printf("mo.Wallet is not nil : %v", mo.Wallet.ClientID) + clientId = mo.Wallet.ClientID + } else { + fmt.Printf("mo.Wallet is nil : %v", mo.allocationObj.Owner) + clientId = mo.allocationObj.Owner + } + if op.Mask != nil { - operation = NewDeleteOperation(mo.ctx, op.RemotePath, *op.Mask, mo.maskMU, mo.consensusThresh, mo.fullconsensus) + operation = NewDeleteOperation(mo.ctx, op.RemotePath, *op.Mask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, clientId) } else { - operation = NewDeleteOperation(mo.ctx, op.RemotePath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus) + operation = NewDeleteOperation(mo.ctx, op.RemotePath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, clientId) } case constants.FileOperationUpdate: @@ -1165,7 +1178,7 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul operation, newConnectionID, err = NewUploadOperation(mo.ctx, op.Workdir, mo.allocationObj, mo.connectionID, op.FileMeta, op.FileReader, true, op.IsWebstreaming, op.IsRepair, op.DownloadFile, op.StreamUpload, op.Opts...) case constants.FileOperationCreateDir: - operation = NewDirOperation(op.RemotePath, op.FileMeta.CustomMeta, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) + operation = NewDirOperation(op.RemotePath, op.FileMeta.CustomMeta, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx, mo.Wallet) default: return errors.New("invalid_operation", "Operation is not valid") diff --git a/zboxcore/sdk/chunked_upload_form_builder.go b/zboxcore/sdk/chunked_upload_form_builder.go index 76c1406b9..5a6f7afc1 100644 --- a/zboxcore/sdk/chunked_upload_form_builder.go +++ b/zboxcore/sdk/chunked_upload_form_builder.go @@ -105,6 +105,9 @@ func (b *chunkedUploadFormBuilder) Build( if b.privateSigningKey != nil { formData.SignatureVersion = SignatureV2 + fmt.Printf("[UPLOAD] Setting SignatureVersion to %d (SignatureV2) - using allocation private signing key\n", SignatureV2) + } else { + fmt.Printf("[UPLOAD] SignatureVersion not set (legacy mode) - using client private key\n") } for i := 0; i < numBodies; i++ { @@ -182,17 +185,28 @@ func (b *chunkedUploadFormBuilder) Build( } if b.privateSigningKey != nil { decodedHash, _ := hex.DecodeString(fileMeta.ActualHash) + fmt.Printf("[UPLOAD] Creating signature with allocation private signing key\n") + fmt.Printf("[UPLOAD] SignatureVersion: %d (SignatureV2)\n", SignatureV2) + fmt.Printf("[UPLOAD] ActualFileHash: %s\n", fileMeta.ActualHash) + fmt.Printf("[UPLOAD] Signing key type: allocation private signing key\n") + fmt.Printf("[UPLOAD] Signing key length: %d bytes\n", len(b.privateSigningKey)) sig, err := b.privateSigningKey.Sign(nil, decodedHash, crypto.Hash(0)) if err != nil { return res, err } formData.ActualFileHashSignature = hex.EncodeToString(sig) + fmt.Printf("[UPLOAD] ActualFileHashSignature created: %s\n", formData.ActualFileHashSignature) } else { - sig, err := client.Sign(fileMeta.ActualHash) + fmt.Printf("[UPLOAD] Creating signature with client private key\n") + fmt.Printf("[UPLOAD] SignatureVersion: %d (legacy)\n", 0) + fmt.Printf("[UPLOAD] ActualFileHash: %s\n", fileMeta.ActualHash) + fmt.Printf("[UPLOAD] Signing key type: client private key\n") + sig, err := client.Sign(fileMeta.ActualHash, clients...) if err != nil { return res, err } formData.ActualFileHashSignature = sig + fmt.Printf("[UPLOAD] ActualFileHashSignature created: %s\n", formData.ActualFileHashSignature) } hash := formData.ActualFileHashSignature + formData.ValidationRoot if b.storageVersion == StorageV2 { @@ -201,17 +215,23 @@ func (b *chunkedUploadFormBuilder) Build( } if b.privateSigningKey != nil { decodedHash, _ := hex.DecodeString(hash) + fmt.Printf("[UPLOAD] Creating validation root signature with allocation private signing key\n") + fmt.Printf("[UPLOAD] Validation root hash: %s\n", hash) sig, err := b.privateSigningKey.Sign(nil, decodedHash, crypto.Hash(0)) if err != nil { return res, err } formData.ValidationRootSignature = hex.EncodeToString(sig) + fmt.Printf("[UPLOAD] ValidationRootSignature created: %s\n", formData.ValidationRootSignature) } else { + fmt.Printf("[UPLOAD] Creating validation root signature with client private key\n") + fmt.Printf("[UPLOAD] Validation root hash: %s\n", hash) rootSig, err := client.Sign(hash, clients...) if err != nil { return res, err } formData.ValidationRootSignature = rootSig + fmt.Printf("[UPLOAD] ValidationRootSignature created: %s\n", formData.ValidationRootSignature) } formData.ActualHash = fileMeta.ActualHash diff --git a/zboxcore/sdk/deleteworker.go b/zboxcore/sdk/deleteworker.go index 243e88c5b..c7cbf075b 100644 --- a/zboxcore/sdk/deleteworker.go +++ b/zboxcore/sdk/deleteworker.go @@ -19,6 +19,7 @@ import ( "github.com/google/uuid" "github.com/0chain/gosdk/constants" + "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/zboxcore/allocationchange" "github.com/0chain/gosdk/zboxcore/blockchain" @@ -43,6 +44,7 @@ type DeleteRequest struct { connectionID string consensus Consensus timestamp int64 + clientId string } var errFileDeleted = errors.New("file_deleted", "file is already deleted") @@ -66,7 +68,7 @@ func (req *DeleteRequest) deleteBlobberFile( query.Add("connection_id", req.connectionID) query.Add("path", req.remotefilepath) - httpreq, err := zboxutil.NewDeleteRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, query, req.allocationObj.Owner) + httpreq, err := zboxutil.NewDeleteRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, query, req.clientId) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating delete request", err) return err @@ -356,6 +358,7 @@ type DeleteOperation struct { consensus Consensus lookupHash string refs []fileref.RefEntity + clientId string } func (dop *DeleteOperation) Process(allocObj *Allocation, connectionID string) ([]fileref.RefEntity, zboxutil.Uint128, error) { @@ -374,6 +377,7 @@ func (dop *DeleteOperation) Process(allocObj *Allocation, connectionID string) ( maskMu: dop.maskMu, wg: &sync.WaitGroup{}, consensus: Consensus{RWMutex: &sync.RWMutex{}}, + clientId: dop.clientId, } deleteReq.consensus.fullconsensus = dop.consensus.fullconsensus deleteReq.consensus.consensusThresh = dop.consensus.consensusThresh @@ -582,7 +586,7 @@ func (dop *DeleteOperation) Error(allocObj *Allocation, consensus int, err error } -func NewDeleteOperation(ctx context.Context, remotePath string, deleteMask zboxutil.Uint128, maskMu *sync.Mutex, consensusTh, fullConsensus int) *DeleteOperation { +func NewDeleteOperation(ctx context.Context, remotePath string, deleteMask zboxutil.Uint128, maskMu *sync.Mutex, consensusTh, fullConsensus int, clientIds... string) *DeleteOperation { dop := &DeleteOperation{} dop.remotefilepath = zboxutil.RemoteClean(remotePath) dop.deleteMask = deleteMask @@ -590,6 +594,7 @@ func NewDeleteOperation(ctx context.Context, remotePath string, deleteMask zboxu dop.consensus.consensusThresh = consensusTh dop.consensus.fullconsensus = fullConsensus dop.ctx, dop.ctxCncl = context.WithCancel(ctx) + dop.clientId = clientIds[0] return dop } @@ -623,7 +628,18 @@ func (req *DeleteRequest) deleteSubDirectories() error { } ops = append(ops, op) } - err = req.allocationObj.DoMultiOperation(ops) + if req.clientId != "" { + clientId := req.clientId + wallet := client.GetWalletByClientID(clientId) + if wallet == nil { + return errors.New("client_not_found", "wallet is not set for the client") + } + err = req.allocationObj.DoMultiOperation(ops, func(mo *MultiOperation) { + mo.Wallet = wallet + }) + } else { + err = req.allocationObj.DoMultiOperation(ops) + } if err != nil { return err } @@ -657,7 +673,18 @@ func (req *DeleteRequest) deleteSubDirectories() error { } ops = append(ops, op) } - err = req.allocationObj.DoMultiOperation(ops) + if req.clientId != "" { + clientId := req.clientId + wallet := client.GetWalletByClientID(clientId) + if wallet == nil { + return errors.New("client_not_found", "wallet is not set for the client") + } + err = req.allocationObj.DoMultiOperation(ops, func(mo *MultiOperation) { + mo.Wallet = wallet + }) + } else { + err = req.allocationObj.DoMultiOperation(ops) + } if err != nil { return err } diff --git a/zboxcore/sdk/dirworker.go b/zboxcore/sdk/dirworker.go index a1b4ef26f..dc64f450d 100644 --- a/zboxcore/sdk/dirworker.go +++ b/zboxcore/sdk/dirworker.go @@ -16,6 +16,7 @@ import ( "github.com/0chain/errors" "github.com/0chain/gosdk/core/common" "github.com/0chain/gosdk/core/util" + "github.com/0chain/gosdk/core/zcncrypto" "github.com/0chain/gosdk/zboxcore/allocationchange" "github.com/0chain/gosdk/zboxcore/blockchain" "github.com/0chain/gosdk/zboxcore/fileref" @@ -45,6 +46,7 @@ type DirRequest struct { timestamp int64 alreadyExists map[uint64]bool customMeta string + wallet *zcncrypto.Wallet Consensus } @@ -187,7 +189,17 @@ func (req *DirRequest) createDirInBlobber(blobber *blockchain.StorageNode, pos u } formWriter.Close() - httpreq, err := zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) + var ( + httpreq *http.Request + ) + if req.wallet != nil { + fmt.Printf("req.wallet is not nil : %v", req.wallet.ClientID) + httpreq, err = zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.wallet.ClientID) + } else { + fmt.Printf("req.wallet is nil : %v", req.allocationObj.Owner) + httpreq, err = zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) + } + fmt.Printf("error creating dir request : %v", err) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating dir request", err) return err, false @@ -282,6 +294,7 @@ type DirOperation struct { maskMU *sync.Mutex customMeta string alreadyExists map[uint64]bool + wallet *zcncrypto.Wallet Consensus } @@ -303,6 +316,7 @@ func (dirOp *DirOperation) Process(allocObj *Allocation, connectionID string) ([ wg: &sync.WaitGroup{}, alreadyExists: make(map[uint64]bool), customMeta: dirOp.customMeta, + wallet: dirOp.wallet, } dR.Consensus = Consensus{ RWMutex: &sync.RWMutex{}, @@ -364,7 +378,7 @@ func (dirOp *DirOperation) Error(allocObj *Allocation, consensus int, err error) } -func NewDirOperation(remotePath, customMeta string, dirMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context) *DirOperation { +func NewDirOperation(remotePath, customMeta string, dirMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context, wallet *zcncrypto.Wallet) *DirOperation { dirOp := &DirOperation{} dirOp.remotePath = zboxutil.RemoteClean(remotePath) dirOp.dirMask = dirMask @@ -372,6 +386,7 @@ func NewDirOperation(remotePath, customMeta string, dirMask zboxutil.Uint128, ma dirOp.consensusThresh = consensusTh dirOp.fullconsensus = fullConsensus dirOp.customMeta = customMeta + dirOp.wallet = wallet dirOp.ctx, dirOp.ctxCncl = context.WithCancel(ctx) dirOp.alreadyExists = make(map[uint64]bool) return dirOp diff --git a/zboxcore/sdk/downloadworker.go b/zboxcore/sdk/downloadworker.go index a28479f9e..a3c7dadad 100644 --- a/zboxcore/sdk/downloadworker.go +++ b/zboxcore/sdk/downloadworker.go @@ -1235,17 +1235,30 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) } actualHash := fmr.fileref.ActualFileHash actualFileHashSignature := fmr.fileref.ActualFileHashSignature + fmt.Printf("[DOWNLOAD] Processing fileRef from blobber %d\n", fmr.blobberIdx) + fmt.Printf("[DOWNLOAD] FileRef SignatureVersion: %d\n", fmr.fileref.SignatureVersion) + fmt.Printf("[DOWNLOAD] FileRef ActualFileHash: %s\n", actualHash) + fmt.Printf("[DOWNLOAD] FileRef ActualFileHashSignature: %s\n", actualFileHashSignature) + fmt.Printf("[DOWNLOAD] FileRef ValidationRoot: %s\n", fmr.fileref.ValidationRoot) + fmt.Printf("[DOWNLOAD] FileRef ValidationRootSignature: %s\n", fmr.fileref.ValidationRootSignature) + var ( isValid bool err error ) if fmr.fileref.SignatureVersion == SignatureV2 { + fmt.Printf("[DOWNLOAD] Using SignatureV2 verification with allocation owner signing public key\n") + fmt.Printf("[DOWNLOAD] Verification key type: allocation owner signing public key\n") + fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerSigningPubKey) isValid, err = sys.VerifyEd25519With( req.allocOwnerSigningPubKey, actualFileHashSignature, actualHash, ) } else { + fmt.Printf("[DOWNLOAD] Using legacy verification with allocation owner public key\n") + fmt.Printf("[DOWNLOAD] Verification key type: allocation owner public key\n") + fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerPubKey) isValid, err = sys.VerifyWith( req.allocOwnerPubKey, actualFileHashSignature, @@ -1253,13 +1266,16 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) ) } if err != nil { + fmt.Printf("[DOWNLOAD] Signature verification error: %v\n", err) l.Logger.Error(err) continue } if !isValid { + fmt.Printf("[DOWNLOAD] Invalid signature for blobber %d\n", fmr.blobberIdx) l.Logger.Error("invalid signature") continue } + fmt.Printf("[DOWNLOAD] Signature verification successful for blobber %d\n", fmr.blobberIdx) retMap[actualFileHashSignature]++ if retMap[actualFileHashSignature] > req.consensus { @@ -1301,17 +1317,25 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) hashData := fmt.Sprintf("%s:%s:%s:%s", fRef.ActualFileHash, fRef.ValidationRoot, fRef.FixedMerkleRoot, req.blobbers[i].ID) hash = encrypt.Hash(hashData) } + fmt.Printf("[DOWNLOAD] Verifying validation root signature for blobber %d\n", i) + fmt.Printf("[DOWNLOAD] Validation root hash: %s\n", hash) + fmt.Printf("[DOWNLOAD] Validation root signature: %s\n", fRef.ValidationRootSignature) + var ( isValid bool err error ) if fRef.SignatureVersion == SignatureV2 { + fmt.Printf("[DOWNLOAD] Using SignatureV2 verification for validation root\n") + fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerSigningPubKey) isValid, err = sys.VerifyEd25519With( req.allocOwnerSigningPubKey, fRef.ValidationRootSignature, hash, ) } else { + fmt.Printf("[DOWNLOAD] Using legacy verification for validation root\n") + fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerPubKey) isValid, err = sys.VerifyWith( req.allocOwnerPubKey, fRef.ValidationRootSignature, @@ -1319,13 +1343,16 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) ) } if err != nil { + fmt.Printf("[DOWNLOAD] Validation root signature verification error: %v\n", err) l.Logger.Error(err, "allocOwnerPubKey: ", req.allocOwnerPubKey, " validationRootSignature: ", fRef.ValidationRootSignature, " actualFileHashSignature: ", fRef.ActualFileHashSignature, " validationRoot: ", fRef.ValidationRoot) continue } if !isValid { + fmt.Printf("[DOWNLOAD] Invalid validation root signature for blobber %d\n", i) l.Logger.Error("invalid validation root signature") continue } + fmt.Printf("[DOWNLOAD] Validation root signature verification successful for blobber %d\n", i) blobber := req.blobbers[fmr.blobberIdx] vr, _ := hex.DecodeString(fmr.fileref.ValidationRoot) diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index dfa97818b..2c4d3d52e 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -64,7 +64,7 @@ type MultiOperation struct { changes [][]allocationchange.AllocationChange changesV2 []allocationchange.AllocationChangeV2 isRepair bool - wallet *zcncrypto.Wallet + Wallet *zcncrypto.Wallet } func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { @@ -101,9 +101,9 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { fmt.Printf("Creating connection object for blobber %s with connection ID %s", blobber.Baseurl, mo.connectionID) var httpreq *http.Request - if mo.wallet != nil { - fmt.Printf("mo wallet : %v", *mo.wallet) - httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.wallet.ClientID) + if mo.Wallet != nil { + fmt.Printf("mo wallet : %v", *mo.Wallet) + httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.Wallet.ClientID) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating new connection request by wallet", err) return err, false @@ -217,6 +217,7 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { func (mo *MultiOperation) Process() error { fmt.Printf("MultiOperation Process start") + fmt.Printf("MultiOperation mo.Wallet : %v", mo.Wallet) l.Logger.Debug("MultiOperation Process start") wg := &sync.WaitGroup{} if mo.allocationObj.StorageVersion == 0 { @@ -324,8 +325,8 @@ func (mo *MultiOperation) Process() error { start = time.Now() status := Commit if !mo.isRepair && !mo.allocationObj.checkStatus { - if mo.wallet != nil { - status, _, err = mo.allocationObj.CheckAllocStatus(mo.wallet.ClientID) + if mo.Wallet != nil { + status, _, err = mo.allocationObj.CheckAllocStatus(mo.Wallet.ClientID) } else { status, _, err = mo.allocationObj.CheckAllocStatus() } @@ -488,10 +489,15 @@ func (mo *MultiOperation) commitV2() error { consensusThresh: threshold, changes: changes, isRepair: mo.isRepair, - wallet: mo.wallet, + wallet: mo.Wallet, } commitReqs[counter] = commitReq counter++ + if commitReq.wallet != nil { + fmt.Printf("commitReq wallet ID : %v", commitReq.wallet.ClientID) + } else { + fmt.Printf("commitReq wallet is nil \n") + } go AddCommitRequest(commitReq) } wg.Wait() diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 3254ec70f..78eff6825 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -1586,7 +1586,7 @@ func DoMultiUploadByWallet(wallet zcncrypto.Wallet, a *Allocation, workdir strin } setWalletOpt := func (mo *MultiOperation) { - mo.wallet = &wallet + mo.Wallet = &wallet } return a.DoMultiOperation(operationRequests, setWalletOpt) diff --git a/zboxcore/zboxutil/http.go b/zboxcore/zboxutil/http.go index b8536164a..b403ca032 100644 --- a/zboxcore/zboxutil/http.go +++ b/zboxcore/zboxutil/http.go @@ -880,7 +880,7 @@ func NewRedeemRequest(baseUrl, allocationID, allocationTx string, clients ...str return req, nil } -func NewDeleteRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values, clients ...string) (*http.Request, error) { +func NewDeleteRequest(baseUrl, allocationID, allocationTx, sig string, query *url.Values, clients... string) (*http.Request, error) { u, err := joinUrl(baseUrl, UPLOAD_ENDPOINT, allocationTx) if err != nil { return nil, err From 44dec8235aef9bf4b79a04bdb2e852fc45972656 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Mon, 28 Jul 2025 16:13:33 +0530 Subject: [PATCH 04/18] change func arg --- core/client/set.go | 14 +++++++++++--- core/sys/sign.go | 2 +- wasmsdk/proxy.go | 24 ++++++++++++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index c49df5e20..3fd470eb0 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -101,12 +101,20 @@ var SignFn = func(hash string) (string, error) { return ss.Sign(hash) } -func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair, clientID string) (string, error) { +func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair, clientIds ...string) (string, error) { sig, err := sys.Sign(hash, signatureScheme, keys) if err != nil { return "", fmt.Errorf("failed to sign with split key: %v", err) } + // Get the first clientID from variadic arguments, or use default wallet clientID + var clientID string + if len(clientIds) > 0 && clientIds[0] != "" { + clientID = clientIds[0] + } else { + clientID = client.wallet.ClientID + } + fmt.Printf("Signature: %s\n", sig) fmt.Printf("ClientID signHashWithAuth: %s\n", clientID) data, err := json.Marshal(AuthMessage{ @@ -219,8 +227,8 @@ func SetWallet(w zcncrypto.Wallet) { func GetWalletByClientID(clientID string) *zcncrypto.Wallet { if client.wallets == nil { - return nil - } + return nil + } if _, exists := client.wallets[clientID]; !exists { return nil } diff --git a/core/sys/sign.go b/core/sys/sign.go index 6f398b8a1..0b58a6e58 100644 --- a/core/sys/sign.go +++ b/core/sys/sign.go @@ -10,7 +10,7 @@ type KeyPair struct { type SignFunc func(hash string, signatureScheme string, keys []KeyPair) (string, error) // SignFunc sign method for request verification -type SignWithAuthFunc func(hash string, signatureScheme string, keys []KeyPair, clientId string) (string, error) +type SignWithAuthFunc func(hash string, signatureScheme string, keys []KeyPair, clientIds ...string) (string, error) type VerifyFunc func(signature string, msg string) (bool, error) diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index 7d4ec007e..9ae4a77bd 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -78,16 +78,24 @@ func main() { return signFunc(hash) } - sys.SignWithAuth = func(hash, signatureScheme string, keys []sys.KeyPair) (string, error) { + sys.SignWithAuth = func(hash, signatureScheme string, keys []sys.KeyPair, clientIds ...string) (string, error) { sig, err := sys.Sign(hash, signatureScheme, keys) if err != nil { return "", fmt.Errorf("failed to sign with split key: %v", err) } + // Get the first clientID from variadic arguments, or use default wallet clientID + var clientID string + if len(clientIds) > 0 && clientIds[0] != "" { + clientID = clientIds[0] + } else { + clientID = client.Wallet().ClientID + } + data, err := json.Marshal(client.AuthMessage{ Hash: hash, Signature: sig, - ClientID: client.Wallet().ClientID, + ClientID: clientID, }) if err != nil { return "", err @@ -377,17 +385,25 @@ func main() { return signFunc(hash) } - sys.SignWithAuth = func(hash, signatureScheme string, keys []sys.KeyPair) (string, error) { + sys.SignWithAuth = func(hash, signatureScheme string, keys []sys.KeyPair, clientIds ...string) (string, error) { fmt.Println("[worker] SignWithAuth pubkey:", keys[0]) sig, err := sys.Sign(hash, signatureScheme, keys) if err != nil { return "", fmt.Errorf("failed to sign with split key: %v", err) } + // Get the first clientID from variadic arguments, or use default wallet clientID + var clientID string + if len(clientIds) > 0 && clientIds[0] != "" { + clientID = clientIds[0] + } else { + clientID = client.Wallet().ClientID + } + data, err := json.Marshal(client.AuthMessage{ Hash: hash, Signature: sig, - ClientID: client.GetClient().ClientID, + ClientID: clientID, }) if err != nil { return "", err From 107c28174614247c892ec69bd2c44835e7b42579 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Sat, 2 Aug 2025 15:36:00 +0530 Subject: [PATCH 05/18] remove logs and reset miners --- core/client/set.go | 5 -- core/transaction/entity.go | 7 +++ zboxcore/sdk/allocation.go | 9 ---- zboxcore/sdk/chunked_upload.go | 11 ---- zboxcore/sdk/chunked_upload_blobber.go | 10 ---- zboxcore/sdk/chunked_upload_form_builder.go | 23 +------- zboxcore/sdk/chunked_upload_process.go | 8 --- zboxcore/sdk/commitworker.go | 26 ++------- zboxcore/sdk/deleteworker.go | 4 +- zboxcore/sdk/dirworker.go | 3 -- zboxcore/sdk/downloadworker.go | 25 --------- zboxcore/sdk/multi_operation_worker.go | 58 +-------------------- zboxcore/sdk/rollback.go | 3 ++ zboxcore/sdk/sdk.go | 4 -- zboxcore/sdk/upload_worker.go | 5 -- zboxcore/zboxutil/http.go | 13 +++-- znft/keystore.go | 2 +- 17 files changed, 27 insertions(+), 189 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index 3fd470eb0..dbd097c55 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -115,8 +115,6 @@ func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair, clientId clientID = client.wallet.ClientID } - fmt.Printf("Signature: %s\n", sig) - fmt.Printf("ClientID signHashWithAuth: %s\n", clientID) data, err := json.Marshal(AuthMessage{ Hash: hash, Signature: sig, @@ -245,18 +243,15 @@ func AddWallet(wallet zcncrypto.Wallet) { client.wg[wallet.ClientID].Add(1) client.walletCount[wallet.ClientID]++ client.wallets[wallet.ClientID] = &wallet - fmt.Println("AddWallet: ", wallet.ClientID, "wallets: ", client.wallets, "wgCount: ", client.walletCount[wallet.ClientID]) } // RemoveWallet should be set before any transaction or client specific APIs func RemoveWallet(clientID string) { - fmt.Println("RemoveWallet: ", clientID, "wg: ", client.wg[clientID]) client.wg[clientID].Done() client.walletCount[clientID]-- if client.walletCount[clientID] == 0 { delete(client.wallets, clientID) } - fmt.Println("RemoveWallet: ", clientID, "wallets: ", client.wallets, "wgCount: ", client.walletCount[clientID]) } // SetWalletMode sets current wallet split key mode. diff --git a/core/transaction/entity.go b/core/transaction/entity.go index 5eed4ef60..b79b5b965 100644 --- a/core/transaction/entity.go +++ b/core/transaction/entity.go @@ -320,6 +320,13 @@ func SendTransactionSync(txn *Transaction, miners []string) error { } } + // Reset stable miners list if any miner failed + if failureCount > 0 { + if nodeClient, err := client.GetNode(); err == nil { + nodeClient.ResetStableMiners() + } + } + if failureCount == len(miners) { return fmt.Errorf(dominantErr) } diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index d9688f134..8e5ee85fb 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -1049,7 +1049,6 @@ func (a *Allocation) RepairRequired(remotepath string) (zboxutil.Uint128, zboxut // - operations: the operations to perform. // - opts: the options of the multi operation as operation functions that customize the multi operation. func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...MultiOperationOption) error { - fmt.Printf("DoMultiOperation called with operations %v with Opts : %v", operations, opts) if len(operations) == 0 { return nil } @@ -1071,11 +1070,9 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul consensusThresh: a.consensusThreshold, fullconsensus: a.fullconsensus, } - fmt.Printf("opts : %v", opts) for _, opt := range opts { opt(&mo) } - fmt.Printf("mo.Wallet : %v", mo.Wallet) previousPaths := make(map[string]bool) connectionErrors := make([]error, len(mo.allocationObj.Blobbers)) @@ -1085,7 +1082,6 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul go func(pos int) { defer wg.Done() err := mo.createConnectionObj(pos) - fmt.Printf("Multioperation: create connection for blobber %d , err : %v", pos, err) if err != nil { l.Logger.Error(err.Error()) connectionErrors[pos] = err @@ -1155,13 +1151,10 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul operation, newConnectionID, err = NewUploadOperation(mo.ctx, op.Workdir, mo.allocationObj, mo.connectionID, op.FileMeta, op.FileReader, false, op.IsWebstreaming, op.IsRepair, op.DownloadFile, op.StreamUpload, op.Opts...) case constants.FileOperationDelete: - fmt.Printf("FileOperationDelete : %v", op.RemotePath) var clientId string if mo.Wallet != nil { - fmt.Printf("mo.Wallet is not nil : %v", mo.Wallet.ClientID) clientId = mo.Wallet.ClientID } else { - fmt.Printf("mo.Wallet is nil : %v", mo.allocationObj.Owner) clientId = mo.allocationObj.Owner } @@ -1203,10 +1196,8 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul mo.operations = append(mo.operations, operation) } - fmt.Printf("Multioperation: operations to process %d ; operations: %v \n", len(mo.operations), mo.operations) if len(mo.operations) > 0 { err := mo.Process() - fmt.Printf("Multioperation: Process operations, err : %v", err) if err != nil { return err } diff --git a/zboxcore/sdk/chunked_upload.go b/zboxcore/sdk/chunked_upload.go index d4d416de8..7eab1b015 100644 --- a/zboxcore/sdk/chunked_upload.go +++ b/zboxcore/sdk/chunked_upload.go @@ -431,13 +431,9 @@ func (su *ChunkedUpload) process() error { defer su.chunkReader.Close() defer su.ctxCncl(nil) - fmt.Printf("ChunkedUpload process started for %s\n", su.fileMeta.RemoteName) for { - fmt.Printf("Reading chunks from chunk reader: %v\n", su.chunkNumber) - chunks, err := su.readChunks(su.chunkNumber) - fmt.Printf("readChunks returned: %v\n", err) // chunk, err := su.chunkReader.Next() if err != nil { if su.statusCallback != nil { @@ -453,7 +449,6 @@ func (su *ChunkedUpload) process() error { if chunks.isFinal { if su.fileMeta.ActualHash == "" { su.fileMeta.ActualHash, err = su.chunkReader.GetFileHash() - fmt.Printf("GetFileHash returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -468,7 +463,6 @@ func (su *ChunkedUpload) process() error { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, thrown.New("upload_failed", "Upload failed. Uploaded size does not match with actual size: "+fmt.Sprintf("%d != %d", su.fileMeta.ActualSize, su.progress.ReadLength))) } - fmt.Printf("Upload failed. Uploaded size does not match with actual size: %d != %d\n", su.fileMeta.ActualSize, su.progress.ReadLength) return thrown.New("upload_failed", "Upload failed. Uploaded size does not match with actual size: "+fmt.Sprintf("%d != %d", su.fileMeta.ActualSize, su.progress.ReadLength)) } } @@ -478,7 +472,6 @@ func (su *ChunkedUpload) process() error { chunks.fileShards, chunks.thumbnailShards, chunks.isFinal, chunks.totalReadSize, ) - fmt.Printf("su processUpload returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -690,7 +683,6 @@ func (su *ChunkedUpload) uploadProcessor() { } func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { - fmt.Printf("uploadToBlobbers started!") select { case <-su.ctx.Done(): return context.Cause(su.ctx) @@ -714,7 +706,6 @@ func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { go func(pos uint64) { defer wg.Done() err := su.blobbers[pos].sendUploadRequest(ctx, su, uploadData.isFinal, su.encryptedKey, uploadData.uploadBody[pos].dataBuffers, uploadData.uploadBody[pos].formData, uploadData.uploadBody[pos].contentSlice, pos, &consensus) - fmt.Printf("sendUploadRequest returned: %v\n", err) if err != nil { if strings.Contains(err.Error(), "duplicate") { su.consensus.Done() @@ -736,14 +727,12 @@ func (su *ChunkedUpload) uploadToBlobbers(uploadData UploadData) error { close(wgErrors) for err := range wgErrors { su.ctxCncl(thrown.New("upload_failed", fmt.Sprintf("Upload failed. %s", err))) - fmt.Printf("Upload failed with error: %v\n", err) return err } if !consensus.isConsensusOk() { err := thrown.New("consensus_not_met", fmt.Sprintf("Upload failed File not found for path %s. Required consensus atleast %d, got %d", su.fileMeta.RemotePath, consensus.consensusThresh, consensus.getConsensus())) su.ctxCncl(err) - fmt.Printf("Upload failed with consensus error: %v\n", err) return err } if uploadData.uploadLength > 0 { diff --git a/zboxcore/sdk/chunked_upload_blobber.go b/zboxcore/sdk/chunked_upload_blobber.go index 847441b07..005898a41 100644 --- a/zboxcore/sdk/chunked_upload_blobber.go +++ b/zboxcore/sdk/chunked_upload_blobber.go @@ -75,8 +75,6 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest( if su.wallet != nil { clientID = su.wallet.ClientID } - fmt.Printf("clientID: %s\n", clientID) - fmt.Printf("allocation owner: %s\n", su.allocationObj.Owner) for dataInd := 0; dataInd < len(dataBuffers); dataInd++ { ind := dataInd eg.Go(func() error { @@ -91,14 +89,6 @@ func (sb *ChunkedUploadBlobber) sendUploadRequest( return err } - // Print all headers - fmt.Printf("Blobber Upload Request Headers for %s:\n", sb.blobber.Baseurl) - req.Header.VisitAll(func(k, v []byte) { - fmt.Printf(" %s: %s\n", string(k), string(v)) - }) - // Print body - // fmt.Printf("Blobber Upload Request Body for %s:\n%s\n", sb.blobber.Baseurl, string(req.Body())) - req.Header.Add("Content-Type", contentSlice[ind]) err, shouldContinue = func() (err error, shouldContinue bool) { resp := fasthttp.AcquireResponse() diff --git a/zboxcore/sdk/chunked_upload_form_builder.go b/zboxcore/sdk/chunked_upload_form_builder.go index 5a6f7afc1..be3e1d813 100644 --- a/zboxcore/sdk/chunked_upload_form_builder.go +++ b/zboxcore/sdk/chunked_upload_form_builder.go @@ -105,10 +105,7 @@ func (b *chunkedUploadFormBuilder) Build( if b.privateSigningKey != nil { formData.SignatureVersion = SignatureV2 - fmt.Printf("[UPLOAD] Setting SignatureVersion to %d (SignatureV2) - using allocation private signing key\n", SignatureV2) - } else { - fmt.Printf("[UPLOAD] SignatureVersion not set (legacy mode) - using client private key\n") - } + } for i := 0; i < numBodies; i++ { @@ -152,7 +149,6 @@ func (b *chunkedUploadFormBuilder) Build( metadata.FileBytesLen += len(chunkBytes) } - fmt.Printf("b.privateSigningKey: %v\n", b.privateSigningKey) if isFinal && i == numBodies-1 { err = hasher.Finalize() if err != nil { @@ -185,28 +181,17 @@ func (b *chunkedUploadFormBuilder) Build( } if b.privateSigningKey != nil { decodedHash, _ := hex.DecodeString(fileMeta.ActualHash) - fmt.Printf("[UPLOAD] Creating signature with allocation private signing key\n") - fmt.Printf("[UPLOAD] SignatureVersion: %d (SignatureV2)\n", SignatureV2) - fmt.Printf("[UPLOAD] ActualFileHash: %s\n", fileMeta.ActualHash) - fmt.Printf("[UPLOAD] Signing key type: allocation private signing key\n") - fmt.Printf("[UPLOAD] Signing key length: %d bytes\n", len(b.privateSigningKey)) sig, err := b.privateSigningKey.Sign(nil, decodedHash, crypto.Hash(0)) if err != nil { return res, err } formData.ActualFileHashSignature = hex.EncodeToString(sig) - fmt.Printf("[UPLOAD] ActualFileHashSignature created: %s\n", formData.ActualFileHashSignature) } else { - fmt.Printf("[UPLOAD] Creating signature with client private key\n") - fmt.Printf("[UPLOAD] SignatureVersion: %d (legacy)\n", 0) - fmt.Printf("[UPLOAD] ActualFileHash: %s\n", fileMeta.ActualHash) - fmt.Printf("[UPLOAD] Signing key type: client private key\n") sig, err := client.Sign(fileMeta.ActualHash, clients...) if err != nil { return res, err } formData.ActualFileHashSignature = sig - fmt.Printf("[UPLOAD] ActualFileHashSignature created: %s\n", formData.ActualFileHashSignature) } hash := formData.ActualFileHashSignature + formData.ValidationRoot if b.storageVersion == StorageV2 { @@ -215,23 +200,17 @@ func (b *chunkedUploadFormBuilder) Build( } if b.privateSigningKey != nil { decodedHash, _ := hex.DecodeString(hash) - fmt.Printf("[UPLOAD] Creating validation root signature with allocation private signing key\n") - fmt.Printf("[UPLOAD] Validation root hash: %s\n", hash) sig, err := b.privateSigningKey.Sign(nil, decodedHash, crypto.Hash(0)) if err != nil { return res, err } formData.ValidationRootSignature = hex.EncodeToString(sig) - fmt.Printf("[UPLOAD] ValidationRootSignature created: %s\n", formData.ValidationRootSignature) } else { - fmt.Printf("[UPLOAD] Creating validation root signature with client private key\n") - fmt.Printf("[UPLOAD] Validation root hash: %s\n", hash) rootSig, err := client.Sign(hash, clients...) if err != nil { return res, err } formData.ValidationRootSignature = rootSig - fmt.Printf("[UPLOAD] ValidationRootSignature created: %s\n", formData.ValidationRootSignature) } formData.ActualHash = fileMeta.ActualHash diff --git a/zboxcore/sdk/chunked_upload_process.go b/zboxcore/sdk/chunked_upload_process.go index 6fc8e0ece..5f2680e8b 100644 --- a/zboxcore/sdk/chunked_upload_process.go +++ b/zboxcore/sdk/chunked_upload_process.go @@ -43,7 +43,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, fileShards []blobberShards, thumbnailShards blobberShards, isFinal bool, uploadLength int64) error { - fmt.Printf("inside su processUpload for chunk %d-%d\n", chunkStartIndex, chunkEndIndex) //chunk has not be uploaded yet if chunkEndIndex <= su.progress.ChunkIndex { // Write data to hashers @@ -51,7 +50,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, hasher := su.blobbers[i].progress.Hasher for _, chunkBytes := range blobberShard { err := hasher.WriteToFixedMT(chunkBytes) - fmt.Printf("WriteToFixedMT returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -59,7 +57,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, return err } err = hasher.WriteToValidationMT(chunkBytes) - fmt.Printf("WriteToValidationMT returned: %v\n", err) if err != nil { if su.statusCallback != nil { su.statusCallback.Error(su.allocationObj.ID, su.fileMeta.RemotePath, su.opCode, err) @@ -91,7 +88,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, wgErrors := make(chan error, len(su.blobbers)) if len(fileShards) == 0 { - fmt.Printf("No data to upload, skipping upload process\n") return thrown.New("upload_failed", "Upload failed. No data to upload") } @@ -116,13 +112,11 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, &su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID, blobber.blobber.ID, su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint, fileShards[pos], thumbnailChunkData, su.shardSize, su.wallet.ClientID) - fmt.Printf("Build returned: %v\n", err) } else { uploadData, err = su.formBuilder.Build( &su.fileMeta, blobber.progress.Hasher, su.progress.ConnectionID, blobber.blobber.ID, su.chunkSize, chunkStartIndex, chunkEndIndex, isFinal, su.encryptedKey, su.progress.EncryptedKeyPoint, fileShards[pos], thumbnailChunkData, su.shardSize) - fmt.Printf("Build returned: %v\n", err) } if err != nil { errC := atomic.AddInt32(&errCount, 1) @@ -151,7 +145,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, close(wgErrors) fileShards = nil for err := range wgErrors { - fmt.Printf("Error in upload: %v\n", err) su.removeProgress() return thrown.New("upload_failed", fmt.Sprintf("Upload failed. %s", err)) } @@ -175,7 +168,6 @@ func (su *ChunkedUpload) processUpload(chunkStartIndex, chunkEndIndex int, blobberUpload.uploadBody = finalBuffer return su.uploadToBlobbers(blobberUpload) } - fmt.Printf("ChunkedUpload processUpload completed for chunk %d-%d\n", chunkStartIndex, chunkEndIndex) return nil } diff --git a/zboxcore/sdk/commitworker.go b/zboxcore/sdk/commitworker.go index a9302655b..df958116c 100644 --- a/zboxcore/sdk/commitworker.go +++ b/zboxcore/sdk/commitworker.go @@ -406,7 +406,6 @@ type refPathResp struct { } func (commitReq *CommitRequestV2) processCommit() { - fmt.Printf("commitReqV2 processCommit called\n") defer commitReq.wg.Done() l.Logger.Debug("received a commit request") paths := make([]string, 0) @@ -447,7 +446,6 @@ func (commitReq *CommitRequestV2) processCommit() { } else { trie, err = getReferencePathV2(blobber, commitReq.allocationObj.ID, commitReq.allocationObj.Tx, commitReq.sig, paths, &success, mu) } - fmt.Printf("getReferencePathV2 err: %v\n", err) resp := refPathResp{ trie: trie, @@ -483,13 +481,11 @@ func (commitReq *CommitRequestV2) processCommit() { } if trie == nil { - fmt.Printf("Failed to get reference path\n") commitReq.commitMask = zboxutil.NewUint128(0) commitReq.result = ErrorCommitResult("Failed to get reference path") return } if commitReq.commitMask.CountOnes() < commitReq.consensusThresh { - fmt.Printf("Consensus threshold not met: %d < %d\n", commitReq.commitMask.CountOnes(), commitReq.consensusThresh) commitReq.commitMask = zboxutil.NewUint128(0) commitReq.result = ErrorCommitResult("Failed to get reference path") return @@ -497,13 +493,11 @@ func (commitReq *CommitRequestV2) processCommit() { elapsedGetRefPath := time.Since(now) prevWeight := trie.Weight() for _, change := range commitReq.changes { - fmt.Printf("Processing change: %T\n", change) if change == nil { continue } err = change.ProcessChangeV2(trie, changeIndex) if err != nil && err != wmpt.ErrNotFound { - fmt.Printf("Error processing change: %v\n", err) l.Logger.Error("Error processing change ", err) commitReq.result = ErrorCommitResult("Failed to process change " + err.Error()) return @@ -524,7 +518,6 @@ func (commitReq *CommitRequestV2) processCommit() { defer wg.Done() commitErr := commitReq.commitBlobber(rootHash, rootWeight, prevWeight, blobber) if commitErr != nil { - fmt.Printf("Error committing to blobber: %s - %v\n", blobber.Baseurl, commitErr) l.Logger.Error("Error committing to blobber: ", blobber.Baseurl, " ", commitErr) errSlice[ind] = commitErr mu.Lock() @@ -558,14 +551,12 @@ func (commitReq *CommitRequestV2) processCommit() { err = errors.New("consensus_not_met", fmt.Sprintf("Successfully committed to %d blobbers, but required %d", commitReq.commitMask.CountOnes(), commitReq.consensusThresh)) } commitReq.result = ErrorCommitResult(err.Error()) - fmt.Printf("Consensus threshold not met: %d < %d\n", commitReq.commitMask.CountOnes(), commitReq.consensusThresh) return } if !commitReq.isRepair { commitReq.allocationObj.allocationRoot = encryption.Hash(hex.EncodeToString(rootHash) + commitReq.allocationObj.ID) } l.Logger.Info("[commit] ", "elapsedGetRefPath ", elapsedGetRefPath.Milliseconds(), " elapsedProcessChanges ", elapsedProcessChanges.Milliseconds(), " elapsedCommit ", elapsedCommit.Milliseconds(), " total ", time.Since(now).Milliseconds()) - fmt.Printf("processCommit completed!\n") commitReq.result = SuccessCommitResult() } @@ -649,7 +640,6 @@ func getFormWritter(connectionID string, wmData, fileIDMetaData []byte, body *by } func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocationTx, sig string, paths []string, success *bool, mu *sync.Mutex, clientIds... string) (*wmpt.WeightedMerkleTrie, error) { - fmt.Printf("initial success: %v\n", *success) if len(paths) == 0 || blobber.LatestWM == nil || blobber.LatestWM.ChainSize == 0 { var node wmpt.Node if blobber.LatestWM != nil && len(blobber.LatestWM.FileMetaRoot) > 0 && blobber.LatestWM.ChainSize > 0 { @@ -669,7 +659,6 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio err, shouldContinue = func() (err error, shouldContinue bool) { var req *http.Request req, err = zboxutil.NewReferencePathRequestV2(blobber.Baseurl, allocationID, allocationTx, sig, paths, false, clientIds...) - fmt.Printf("getReferencePathV2 req err: %v\n", err) if err != nil { l.Logger.Error("Creating ref path req", err) return @@ -677,7 +666,6 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio ctx, cncl := context.WithTimeout(context.Background(), (time.Second * 30)) err = zboxutil.HttpDo(ctx, cncl, req, func(resp *http.Response, err error) error { - fmt.Printf("HttpDo req err: %v\n", err) if err != nil { l.Logger.Error("Ref path error:", err) if errors.Is(err, http.ErrServerClosed) || strings.Contains(err.Error(), "GOAWAY") { @@ -710,8 +698,6 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio shouldContinue = true return err } - fmt.Printf("Reference path error response: Status: %d - %s ", - resp.StatusCode, string(respBody)) return errors.New( strconv.Itoa(resp.StatusCode), fmt.Sprintf("Reference path error response: Status: %d - %s ", @@ -732,7 +718,6 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio break } } - fmt.Printf("HttpDo after req err: %v\n", err) if err != nil { return nil, err } @@ -740,9 +725,7 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio elapsedRefPath := time.Since(now) mu.Lock() defer mu.Unlock() - fmt.Printf("after success: %v\n", *success) if *success { - fmt.Printf("errAlreadySuccessful err\n") return nil, errAlreadySuccessful } trie := wmpt.New(nil, nil) @@ -754,31 +737,28 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio useClientID = client.Id() } wallet := client.GetWalletByClientID(useClientID) - + if wallet == nil { + return nil, errors.New("wallet not found", useClientID) + } err = lR.LatestWM.VerifySignature(wallet.ClientKey) - fmt.Printf("verify signature err : %v\n", err) if err != nil { return nil, errors.New("signature_verification_failed", err.Error()) } err = trie.Deserialize(lR.Path) - fmt.Printf("Deserialize err : %v\n", err) if err != nil { l.Logger.Error("Error deserializing trie", err) return nil, err } l.Logger.Info("[getReferencePathV2] elapsedRefPath ", elapsedRefPath.Milliseconds(), " elapsedDeserialize ", (time.Since(now) - elapsedRefPath).Milliseconds()) chainBlocks := numBlocks(lR.LatestWM.ChainSize) - fmt.Printf("chain_length_mismatch: %v\n", err) if trie.Weight() != uint64(chainBlocks) { return nil, errors.New("chain_length_mismatch", fmt.Sprintf("Expected chain length %d, got %d", chainBlocks, trie.Weight())) } - fmt.Printf("allocation_root_mismatch: %v\n", err) if hex.EncodeToString(trie.Root()) != lR.LatestWM.FileMetaRoot { return nil, errors.New("allocation_root_mismatch", fmt.Sprintf("Expected allocation root %s, got %s", lR.LatestWM.AllocationRoot, hex.EncodeToString(trie.Root()))) } } *success = true - fmt.Printf("getReferencePathV2 success") return trie, nil } diff --git a/zboxcore/sdk/deleteworker.go b/zboxcore/sdk/deleteworker.go index c7cbf075b..c3f3e3eef 100644 --- a/zboxcore/sdk/deleteworker.go +++ b/zboxcore/sdk/deleteworker.go @@ -632,7 +632,7 @@ func (req *DeleteRequest) deleteSubDirectories() error { clientId := req.clientId wallet := client.GetWalletByClientID(clientId) if wallet == nil { - return errors.New("client_not_found", "wallet is not set for the client") + return errors.New("client_not_found", clientId) } err = req.allocationObj.DoMultiOperation(ops, func(mo *MultiOperation) { mo.Wallet = wallet @@ -677,7 +677,7 @@ func (req *DeleteRequest) deleteSubDirectories() error { clientId := req.clientId wallet := client.GetWalletByClientID(clientId) if wallet == nil { - return errors.New("client_not_found", "wallet is not set for the client") + return errors.New("client_not_found", clientId) } err = req.allocationObj.DoMultiOperation(ops, func(mo *MultiOperation) { mo.Wallet = wallet diff --git a/zboxcore/sdk/dirworker.go b/zboxcore/sdk/dirworker.go index dc64f450d..bdca91bdb 100644 --- a/zboxcore/sdk/dirworker.go +++ b/zboxcore/sdk/dirworker.go @@ -193,13 +193,10 @@ func (req *DirRequest) createDirInBlobber(blobber *blockchain.StorageNode, pos u httpreq *http.Request ) if req.wallet != nil { - fmt.Printf("req.wallet is not nil : %v", req.wallet.ClientID) httpreq, err = zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.wallet.ClientID) } else { - fmt.Printf("req.wallet is nil : %v", req.allocationObj.Owner) httpreq, err = zboxutil.NewCreateDirRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) } - fmt.Printf("error creating dir request : %v", err) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating dir request", err) return err, false diff --git a/zboxcore/sdk/downloadworker.go b/zboxcore/sdk/downloadworker.go index a3c7dadad..fa8af5008 100644 --- a/zboxcore/sdk/downloadworker.go +++ b/zboxcore/sdk/downloadworker.go @@ -1235,30 +1235,18 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) } actualHash := fmr.fileref.ActualFileHash actualFileHashSignature := fmr.fileref.ActualFileHashSignature - fmt.Printf("[DOWNLOAD] Processing fileRef from blobber %d\n", fmr.blobberIdx) - fmt.Printf("[DOWNLOAD] FileRef SignatureVersion: %d\n", fmr.fileref.SignatureVersion) - fmt.Printf("[DOWNLOAD] FileRef ActualFileHash: %s\n", actualHash) - fmt.Printf("[DOWNLOAD] FileRef ActualFileHashSignature: %s\n", actualFileHashSignature) - fmt.Printf("[DOWNLOAD] FileRef ValidationRoot: %s\n", fmr.fileref.ValidationRoot) - fmt.Printf("[DOWNLOAD] FileRef ValidationRootSignature: %s\n", fmr.fileref.ValidationRootSignature) var ( isValid bool err error ) if fmr.fileref.SignatureVersion == SignatureV2 { - fmt.Printf("[DOWNLOAD] Using SignatureV2 verification with allocation owner signing public key\n") - fmt.Printf("[DOWNLOAD] Verification key type: allocation owner signing public key\n") - fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerSigningPubKey) isValid, err = sys.VerifyEd25519With( req.allocOwnerSigningPubKey, actualFileHashSignature, actualHash, ) } else { - fmt.Printf("[DOWNLOAD] Using legacy verification with allocation owner public key\n") - fmt.Printf("[DOWNLOAD] Verification key type: allocation owner public key\n") - fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerPubKey) isValid, err = sys.VerifyWith( req.allocOwnerPubKey, actualFileHashSignature, @@ -1266,16 +1254,13 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) ) } if err != nil { - fmt.Printf("[DOWNLOAD] Signature verification error: %v\n", err) l.Logger.Error(err) continue } if !isValid { - fmt.Printf("[DOWNLOAD] Invalid signature for blobber %d\n", fmr.blobberIdx) l.Logger.Error("invalid signature") continue } - fmt.Printf("[DOWNLOAD] Signature verification successful for blobber %d\n", fmr.blobberIdx) retMap[actualFileHashSignature]++ if retMap[actualFileHashSignature] > req.consensus { @@ -1317,25 +1302,18 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) hashData := fmt.Sprintf("%s:%s:%s:%s", fRef.ActualFileHash, fRef.ValidationRoot, fRef.FixedMerkleRoot, req.blobbers[i].ID) hash = encrypt.Hash(hashData) } - fmt.Printf("[DOWNLOAD] Verifying validation root signature for blobber %d\n", i) - fmt.Printf("[DOWNLOAD] Validation root hash: %s\n", hash) - fmt.Printf("[DOWNLOAD] Validation root signature: %s\n", fRef.ValidationRootSignature) var ( isValid bool err error ) if fRef.SignatureVersion == SignatureV2 { - fmt.Printf("[DOWNLOAD] Using SignatureV2 verification for validation root\n") - fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerSigningPubKey) isValid, err = sys.VerifyEd25519With( req.allocOwnerSigningPubKey, fRef.ValidationRootSignature, hash, ) } else { - fmt.Printf("[DOWNLOAD] Using legacy verification for validation root\n") - fmt.Printf("[DOWNLOAD] Verification key: %s\n", req.allocOwnerPubKey) isValid, err = sys.VerifyWith( req.allocOwnerPubKey, fRef.ValidationRootSignature, @@ -1343,16 +1321,13 @@ func (req *DownloadRequest) getFileMetaConsensus(fMetaResp []*fileMetaResponse) ) } if err != nil { - fmt.Printf("[DOWNLOAD] Validation root signature verification error: %v\n", err) l.Logger.Error(err, "allocOwnerPubKey: ", req.allocOwnerPubKey, " validationRootSignature: ", fRef.ValidationRootSignature, " actualFileHashSignature: ", fRef.ActualFileHashSignature, " validationRoot: ", fRef.ValidationRoot) continue } if !isValid { - fmt.Printf("[DOWNLOAD] Invalid validation root signature for blobber %d\n", i) l.Logger.Error("invalid validation root signature") continue } - fmt.Printf("[DOWNLOAD] Validation root signature verification successful for blobber %d\n", i) blobber := req.blobbers[fmr.blobberIdx] vr, _ := hex.DecodeString(fmr.fileref.ValidationRoot) diff --git a/zboxcore/sdk/multi_operation_worker.go b/zboxcore/sdk/multi_operation_worker.go index 2c4d3d52e..b70883049 100644 --- a/zboxcore/sdk/multi_operation_worker.go +++ b/zboxcore/sdk/multi_operation_worker.go @@ -68,8 +68,6 @@ type MultiOperation struct { } func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { - // fmt.Printf("Creating connection object for blobber index %d with connection ID %s", blobberIdx, mo.connectionID) - fmt.Printf("Creating connection object for blobber index %d with connection ID %s\n", blobberIdx, mo.connectionID) defer func() { if err == nil { mo.maskMU.Lock() @@ -88,7 +86,6 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { blobber := mo.allocationObj.Blobbers[blobberIdx] for i := 0; i < 3; i++ { - fmt.Printf("Iter %d", i+1) err, shouldContinue = func() (err error, shouldContinue bool) { body := new(bytes.Buffer) formWriter := multipart.NewWriter(body) @@ -99,56 +96,19 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { } formWriter.Close() - fmt.Printf("Creating connection object for blobber %s with connection ID %s", blobber.Baseurl, mo.connectionID) var httpreq *http.Request if mo.Wallet != nil { - fmt.Printf("mo wallet : %v", *mo.Wallet) httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.Wallet.ClientID) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating new connection request by wallet", err) return err, false } - - - // log - - fmt.Printf("Request created with wallet") - fmt.Printf("Request URL: %s\n", httpreq.URL.String()) - fmt.Printf("Request Method: %s\n", httpreq.Method) - fmt.Printf("Request Headers:\n") - for k, v := range httpreq.Header { - fmt.Printf(" %s: %v\n", k, v) - } - if httpreq.Body != nil { - bodyBytes, _ := io.ReadAll(httpreq.Body) - fmt.Printf("Request Body: %s\n", string(bodyBytes)) - // Restore body for later use - httpreq.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) - } - } else { - fmt.Printf("No wallet") httpreq, err = zboxutil.NewConnectionRequest(blobber.Baseurl, mo.allocationObj.ID, mo.allocationObj.Tx, mo.allocationObj.sig, body, mo.allocationObj.Owner) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating new connection request", err) return } - - // log - - fmt.Printf("Request created without wallet") - fmt.Printf("Request URL: %s\n", httpreq.URL.String()) - fmt.Printf("Request Method: %s\n", httpreq.Method) - fmt.Printf("Request Headers:\n") - for k, v := range httpreq.Header { - fmt.Printf(" %s: %v\n", k, v) - } - if httpreq.Body != nil { - bodyBytes, _ := io.ReadAll(httpreq.Body) - fmt.Printf("Request Body: %s\n", string(bodyBytes)) - // Restore body for later use - httpreq.Body = io.NopCloser(bytes.NewBuffer(bodyBytes)) - } } httpreq.Header.Add("Content-Type", formWriter.FormDataContentType()) @@ -158,7 +118,6 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { resp = r return err }) - fmt.Printf("Create Connection Err: %v", err) if err != nil { logger.Logger.Error("Create Connection: ", err) return @@ -176,8 +135,6 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { latestRespMsg = string(respBody) latestStatusCode = resp.StatusCode - fmt.Printf("resp status code : %v", latestStatusCode) - fmt.Printf("resp status body : %v", latestRespMsg) if resp.StatusCode == http.StatusOK { l.Logger.Debug(blobber.Baseurl, " connection obj created.") return @@ -199,8 +156,6 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { err = errors.New("response_error", string(respBody)) return }() - - fmt.Printf("Iter %d; err : %v, shouldContinue: %v", i+1, err, shouldContinue) if err != nil { return } @@ -216,8 +171,6 @@ func (mo *MultiOperation) createConnectionObj(blobberIdx int) (err error) { } func (mo *MultiOperation) Process() error { - fmt.Printf("MultiOperation Process start") - fmt.Printf("MultiOperation mo.Wallet : %v", mo.Wallet) l.Logger.Debug("MultiOperation Process start") wg := &sync.WaitGroup{} if mo.allocationObj.StorageVersion == 0 { @@ -382,10 +335,7 @@ func (mo *MultiOperation) Process() error { } if mo.allocationObj.StorageVersion == StorageV2 { - fmt.Printf("Commit V2 called!") - err = mo.commitV2() - fmt.Printf("Commit V2 returned: %v\n", err) - return err + return mo.commitV2() } commitReqs := make([]*CommitRequest, activeBlobbers) @@ -455,7 +405,6 @@ func (mo *MultiOperation) Process() error { } func (mo *MultiOperation) commitV2() error { - fmt.Printf("commitV2 called \n") rootMap := make(map[string]zboxutil.Uint128) var pos uint64 for i := mo.operationMask; !i.Equals64(0); i = i.And(zboxutil.NewUint128(1).Lsh(pos).Not()) { @@ -493,11 +442,6 @@ func (mo *MultiOperation) commitV2() error { } commitReqs[counter] = commitReq counter++ - if commitReq.wallet != nil { - fmt.Printf("commitReq wallet ID : %v", commitReq.wallet.ClientID) - } else { - fmt.Printf("commitReq wallet is nil \n") - } go AddCommitRequest(commitReq) } wg.Wait() diff --git a/zboxcore/sdk/rollback.go b/zboxcore/sdk/rollback.go index 2e8480355..2044c033b 100644 --- a/zboxcore/sdk/rollback.go +++ b/zboxcore/sdk/rollback.go @@ -72,6 +72,9 @@ func GetWritemarker(allocID, allocTx, sig, id, baseUrl string, clientId ...strin useClientID = client.Id() } wallet := client.GetWalletByClientID(useClientID) + if wallet == nil { + return nil, errors.New("wallet not found : " + useClientID) + } req, err := zboxutil.NewWritemarkerRequest(baseUrl, allocID, allocTx, sig, clientId...) if err != nil { diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 78eff6825..872f29738 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -1485,8 +1485,6 @@ func updateMaskBit(mask uint16, index uint8, value bool) uint16 { } func DoMultiUploadByWallet(wallet zcncrypto.Wallet, a *Allocation, workdir string, localPaths []string, fileNames []string, thumbnailPaths []string, encrypts []bool, chunkNumbers []int, remotePaths []string, isUpdate []bool, isWebstreaming []bool, status StatusCallback) error { - - fmt.Printf("Starting multi upload with walletID: %v, walletKey: %v", wallet.ClientID, wallet.ClientKey) if len(localPaths) != len(thumbnailPaths) { return errors.New("invalid_value", "length of localpaths and thumbnailpaths must be equal") @@ -1589,6 +1587,4 @@ func DoMultiUploadByWallet(wallet zcncrypto.Wallet, a *Allocation, workdir strin mo.Wallet = &wallet } return a.DoMultiOperation(operationRequests, setWalletOpt) - - // return allocationObj.StartMultiUpload(workdir, localPaths, fileNames, thumbnailPaths, encrypts, chunkNumbers, remotePaths, isUpdate, isWebstreaming, status) } diff --git a/zboxcore/sdk/upload_worker.go b/zboxcore/sdk/upload_worker.go index 73b6ad7eb..285443c1e 100644 --- a/zboxcore/sdk/upload_worker.go +++ b/zboxcore/sdk/upload_worker.go @@ -5,7 +5,6 @@ import ( "context" "encoding/hex" "errors" - "fmt" "io" "strings" @@ -32,7 +31,6 @@ type UploadOperation struct { var ErrPauseUpload = errors.New("upload paused by user") func (uo *UploadOperation) Process(allocObj *Allocation, connectionID string) ([]fileref.RefEntity, zboxutil.Uint128, error) { - fmt.Printf("upload operation started\n") if uo.isDownload { if f, ok := uo.chunkedUpload.fileReader.(sys.File); ok { err := allocObj.DownloadFileToFileHandler(f, uo.chunkedUpload.fileMeta.RemotePath, false, nil, true, WithFileCallback(func() { @@ -45,7 +43,6 @@ func (uo *UploadOperation) Process(allocObj *Allocation, connectionID string) ([ } } err := uo.chunkedUpload.process() - fmt.Printf("process returned: %v\n", err) if err != nil { l.Logger.Error("UploadOperation Failed", zap.String("name", uo.chunkedUpload.fileMeta.RemoteName), zap.Error(err)) return nil, uo.chunkedUpload.uploadMask, err @@ -67,7 +64,6 @@ func (uo *UploadOperation) Process(allocObj *Allocation, connectionID string) ([ } uo.lookupHash = fileref.GetReferenceLookup(uo.chunkedUpload.allocationObj.ID, uo.chunkedUpload.fileMeta.RemotePath) l.Logger.Debug("UploadOperation Success", zap.String("name", uo.chunkedUpload.fileMeta.RemoteName)) - fmt.Printf("UploadOperation Success: %s\n", uo.chunkedUpload.fileMeta.RemoteName) return nil, uo.chunkedUpload.uploadMask, nil } @@ -139,7 +135,6 @@ func NewUploadOperation(ctx context.Context, workdir string, allocObj *Allocatio } cu, err := CreateChunkedUpload(ctx, workdir, allocObj, fileMeta, fileReader, isUpdate, isRepair, isWebstreaming, connectionID, opts...) - fmt.Printf("CreateChunkedUpload returned: %v", err) if err != nil { return nil, "", err } diff --git a/zboxcore/zboxutil/http.go b/zboxcore/zboxutil/http.go index b403ca032..b7d587261 100644 --- a/zboxcore/zboxutil/http.go +++ b/zboxcore/zboxutil/http.go @@ -203,6 +203,9 @@ func NewHTTPRequest(method string, url string, data []byte) (*http.Request, cont func setClientInfo(req *http.Request, clientIds... string) { if len(clientIds) > 0 && clientIds[0] != "" { wallet := client.GetWalletByClientID(clientIds[0]) + if wallet == nil { + panic("wallet not found : " + clientIds[0]) + } req.Header.Set("X-App-Client-ID", wallet.ClientID) req.Header.Set("X-App-Client-Key", wallet.ClientKey) return @@ -219,8 +222,9 @@ func setClientInfoWithSign(req *http.Request, sig, allocation, baseURL string, c clientID = client.Id() } wallet := client.GetWalletByClientID(clientID) - fmt.Printf("setClientInfoWithSign: clientID: %s, allocation: %s, baseURL: %s\n", clientID, allocation, baseURL) - fmt.Printf("setClientInfoWithSign: wallet: %v\n", wallet) + if wallet == nil { + return errors.New("wallet not found", clientID) + } req.Header.Set("X-App-Client-ID", wallet.ClientID) req.Header.Set("X-App-Client-Key", wallet.ClientKey) req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) @@ -672,8 +676,9 @@ func setFastClientInfoWithSign(req *fasthttp.Request, allocation, baseURL string clientID = client.Id() } wallet := client.GetWalletByClientID(clientID) - fmt.Printf("setFastClientInfoWithSign: clientID: %s, allocation: %s, baseURL: %s\n", clientID, allocation, baseURL) - fmt.Printf("setFastClientInfoWithSign: wallet: %v\n", wallet) + if wallet == nil { + return errors.New("wallet not found", clientID) + } req.Header.Set("X-App-Client-ID", wallet.ClientID) req.Header.Set("X-App-Client-Key", wallet.ClientKey) diff --git a/znft/keystore.go b/znft/keystore.go index 14ea36680..4762acda9 100644 --- a/znft/keystore.go +++ b/znft/keystore.go @@ -30,7 +30,7 @@ func DeleteAccount(homedir, address string) bool { }) if err != nil && wallet == nil { - Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err))`` + Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err)) return false } From 2d4071fba85dcd5ea6cae26de0b38a61e579f40f Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Sun, 3 Aug 2025 12:01:02 +0530 Subject: [PATCH 06/18] fix compilation --- znft/znft.go | 1 - 1 file changed, 1 deletion(-) diff --git a/znft/znft.go b/znft/znft.go index 5a5b27224..54f18dd5c 100644 --- a/znft/znft.go +++ b/znft/znft.go @@ -2,7 +2,6 @@ package znft import ( "context" - "fmt" "os" "github.com/0chain/gosdk/core/logger" From df4dbdf40bf88835b8010ea8d021b9c7c147ac15 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Tue, 19 Aug 2025 21:08:18 +0530 Subject: [PATCH 07/18] client id support in zauth sign --- core/client/set.go | 4 ++-- core/client/zauth.go | 20 ++++++++++++++++++-- core/sys/sign.go | 2 +- zboxcore/zboxutil/http.go | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index dbd097c55..da2d9821a 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -73,7 +73,7 @@ func init() { if !wallet.IsSplit { return sys.Sign(hash, client.signatureScheme, GetClientSysKeys(clients...)) } - + fmt.Printf("Sign: wallet details: %+v\n", *wallet) // get sign lock <-sigC fmt.Println("Sign: with sys.SignWithAuth:", sys.SignWithAuth, "sysKeys:", GetClientSysKeys(clients...)) @@ -128,7 +128,7 @@ func signHashWithAuth(hash, signatureScheme string, keys []sys.KeyPair, clientId return "", errors.New("authCommon is not set") } - rsp, err := sys.AuthCommon(string(data)) + rsp, err := sys.AuthCommon(string(data), clientID) if err != nil { return "", err } diff --git a/core/client/zauth.go b/core/client/zauth.go index 9e31f3457..a38179653 100644 --- a/core/client/zauth.go +++ b/core/client/zauth.go @@ -535,7 +535,7 @@ func CallZvaultRetrieveSharedWallets(serverAddr, token string) (string, error) { // ZauthSignTxn returns a function that sends a txn signing request to the zauth server func ZauthSignTxn(serverAddr string) sys.AuthorizeFunc { - return func(msg string) (string, error) { + return func(msg string, clientIds ...string) (string, error) { req, err := http.NewRequest("POST", serverAddr+"/sign/txn", bytes.NewBuffer([]byte(msg))) if err != nil { return "", errors.Wrap(err, "failed to create HTTP request") @@ -543,6 +543,14 @@ func ZauthSignTxn(serverAddr string) sys.AuthorizeFunc { req.Header.Set("Content-Type", "application/json") c := GetClient() pubkey := c.Keys[0].PublicKey + if len(clientIds) > 0 { + c = GetWalletByClientID(clientIds[0]) + if c == nil { + return "", errors.Errorf("wallet not found for client ID: %s", clientIds[0]) + } + pubkey = c.Keys[0].PublicKey + } + req.Header.Set("X-Peer-Public-Key", pubkey) client := &http.Client{} @@ -572,7 +580,7 @@ func ZauthSignTxn(serverAddr string) sys.AuthorizeFunc { } func ZauthAuthCommon(serverAddr string) sys.AuthorizeFunc { - return func(msg string) (string, error) { + return func(msg string, clientIds ...string) (string, error) { req, err := http.NewRequest("POST", serverAddr+"/sign/msg", bytes.NewBuffer([]byte(msg))) if err != nil { return "", errors.Wrap(err, "failed to create HTTP request") @@ -580,6 +588,14 @@ func ZauthAuthCommon(serverAddr string) sys.AuthorizeFunc { c := GetClient() pubkey := c.Keys[0].PublicKey + if len(clientIds) > 0 { + c = GetWalletByClientID(clientIds[0]) + if c == nil { + return "", errors.Errorf("wallet not found for client ID: %s", clientIds[0]) + } + pubkey = c.Keys[0].PublicKey + } + req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Peer-Public-Key", pubkey) diff --git a/core/sys/sign.go b/core/sys/sign.go index 0b58a6e58..186729726 100644 --- a/core/sys/sign.go +++ b/core/sys/sign.go @@ -16,4 +16,4 @@ type VerifyFunc func(signature string, msg string) (bool, error) type VerifyWithFunc func(pk, signature string, msg string) (bool, error) -type AuthorizeFunc func(msg string) (string, error) +type AuthorizeFunc func(msg string, clientIds... string) (string, error) diff --git a/zboxcore/zboxutil/http.go b/zboxcore/zboxutil/http.go index b7d587261..927290502 100644 --- a/zboxcore/zboxutil/http.go +++ b/zboxcore/zboxutil/http.go @@ -225,6 +225,7 @@ func setClientInfoWithSign(req *http.Request, sig, allocation, baseURL string, c if wallet == nil { return errors.New("wallet not found", clientID) } + fmt.Printf("setClientInfoWithSign: wallet details: %+v\n", *wallet) req.Header.Set("X-App-Client-ID", wallet.ClientID) req.Header.Set("X-App-Client-Key", wallet.ClientKey) req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) From a8fbe2e0f5689091da650cafaaee6a1a35daecfd Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Tue, 2 Sep 2025 11:57:26 +0530 Subject: [PATCH 08/18] add godocs --- core/client/set.go | 4 +++- zboxcore/sdk/sdk.go | 1 + zboxcore/zboxutil/http.go | 47 ++++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index da2d9821a..e5df9e3c3 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -223,6 +223,7 @@ func SetWallet(w zcncrypto.Wallet) { client.wallets[w.ClientID] = &w } +// GetWalletByClientID gets a wallet by client id. func GetWalletByClientID(clientID string) *zcncrypto.Wallet { if client.wallets == nil { return nil @@ -233,6 +234,7 @@ func GetWalletByClientID(clientID string) *zcncrypto.Wallet { return client.wallets[clientID] } +// AddWallet adds a new wallet to the sdk. func AddWallet(wallet zcncrypto.Wallet) { if client.wallets == nil { client.wallets = make(map[string]*zcncrypto.Wallet) @@ -245,7 +247,7 @@ func AddWallet(wallet zcncrypto.Wallet) { client.wallets[wallet.ClientID] = &wallet } -// RemoveWallet should be set before any transaction or client specific APIs +// RemoveWallet removes a wallet from the sdk. func RemoveWallet(clientID string) { client.wg[clientID].Done() client.walletCount[clientID]-- diff --git a/zboxcore/sdk/sdk.go b/zboxcore/sdk/sdk.go index 872f29738..0b018bca4 100644 --- a/zboxcore/sdk/sdk.go +++ b/zboxcore/sdk/sdk.go @@ -1484,6 +1484,7 @@ func updateMaskBit(mask uint16, index uint8, value bool) uint16 { } } +// DoMultiUploadByWallet uploads multiple files to the allocation using the given wallet. func DoMultiUploadByWallet(wallet zcncrypto.Wallet, a *Allocation, workdir string, localPaths []string, fileNames []string, thumbnailPaths []string, encrypts []bool, chunkNumbers []int, remotePaths []string, isUpdate []bool, isWebstreaming []bool, status StatusCallback) error { if len(localPaths) != len(thumbnailPaths) { diff --git a/zboxcore/zboxutil/http.go b/zboxcore/zboxutil/http.go index 927290502..cb2225127 100644 --- a/zboxcore/zboxutil/http.go +++ b/zboxcore/zboxutil/http.go @@ -724,29 +724,30 @@ func NewUploadRequest(baseUrl, allocationID, allocationTx, sig string, body io.R return req, nil } -func NewConnectionRequestByWallet(baseUrl, allocationID, allocationTx, sig string, body io.Reader, wallet *zcncrypto.Wallet) (*http.Request, error) { - l.Logger.Info(fmt.Sprintf("NewConnectionRequestByWallet: baseUrl: %s, allocationID: %s, allocationTx: %s, sig: %s", baseUrl, allocationID, allocationTx, sig)) - u, err := joinUrl(baseUrl, CREATE_CONNECTION_ENDPOINT, allocationTx) - if err != nil { - return nil, err - } - req, err := http.NewRequest(http.MethodPost, u.String(), body) - if err != nil { - return nil, err - } - req.Header.Set("X-App-Client-ID", wallet.ClientID) - req.Header.Set("X-App-Client-Key", wallet.ClientKey) - req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) - hashData := allocationTx + baseUrl - sig2, err := wallet.Sign(encryption.Hash(hashData), constants.BLS0CHAIN.String()) - if err != nil { - return nil, err - } - req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) - req.Header.Set(CLIENT_SIGNATURE_HEADER_V2, sig2) - req.Header.Set(ALLOCATION_ID_HEADER, allocationID) - return req, nil -} +// NewConnectionRequestByWallet creates a new connection request using the given wallet. +// func NewConnectionRequestByWallet(baseUrl, allocationID, allocationTx, sig string, body io.Reader, wallet *zcncrypto.Wallet) (*http.Request, error) { +// l.Logger.Info(fmt.Sprintf("NewConnectionRequestByWallet: baseUrl: %s, allocationID: %s, allocationTx: %s, sig: %s", baseUrl, allocationID, allocationTx, sig)) +// u, err := joinUrl(baseUrl, CREATE_CONNECTION_ENDPOINT, allocationTx) +// if err != nil { +// return nil, err +// } +// req, err := http.NewRequest(http.MethodPost, u.String(), body) +// if err != nil { +// return nil, err +// } +// req.Header.Set("X-App-Client-ID", wallet.ClientID) +// req.Header.Set("X-App-Client-Key", wallet.ClientKey) +// req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) +// hashData := allocationTx + baseUrl +// sig2, err := wallet.Sign(encryption.Hash(hashData), constants.BLS0CHAIN.String()) +// if err != nil { +// return nil, err +// } +// req.Header.Set(CLIENT_SIGNATURE_HEADER, sig) +// req.Header.Set(CLIENT_SIGNATURE_HEADER_V2, sig2) +// req.Header.Set(ALLOCATION_ID_HEADER, allocationID) +// return req, nil +// } func NewConnectionRequest(baseUrl, allocationID, allocationTx, sig string, body io.Reader, clients ...string) (*http.Request, error) { l.Logger.Info(fmt.Sprintf("NewConnectionRequest: baseUrl: %s, allocationID: %s, allocationTx: %s, sig: %s", baseUrl, allocationID, allocationTx, sig)) From f1a2b7a756c58e20a567f1e18630d9008021d129 Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Tue, 2 Sep 2025 12:04:53 +0530 Subject: [PATCH 09/18] revert keystore.go same as staging --- znft/keystore.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/znft/keystore.go b/znft/keystore.go index 4762acda9..757f329d5 100644 --- a/znft/keystore.go +++ b/znft/keystore.go @@ -5,6 +5,7 @@ import ( "os" "path" + log "github.com/0chain/gosdk/zcnbridge/log" hdw "github.com/0chain/gosdk/zcncore/ethhdwallet" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -30,7 +31,7 @@ func DeleteAccount(homedir, address string) bool { }) if err != nil && wallet == nil { - Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err)) + log.Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err)) return false } @@ -54,17 +55,17 @@ func AccountExists(homedir, address string) bool { }) if err != nil && wallet == nil { - Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err)) + log.Logger.Error(fmt.Sprintf("failed to find account %s, error: %s", address, err)) return false } status, _ := wallet.Status() url := wallet.URL() - Logger.Info( + log.Logger.Info( fmt.Sprintf("Account exists. Status: %s, Path: %s", status, url), ) - + return true } @@ -76,10 +77,10 @@ func CreateKeyStorage(homedir, password string) error { if err != nil { return errors.Wrap(err, "failed to create keystore") } - Logger.Info( + log.Logger.Info( fmt.Sprintf("Created account: %s", account.Address.Hex()), ) - + return nil } @@ -144,7 +145,7 @@ func ImportAccount(homedir, mnemonic, password string) (string, error) { // 3. Find key acc, err := ks.Find(account) if err == nil { - Logger.Info( + log.Logger.Info( fmt.Sprintf("Account already exists: %s\nPath: %s\n\n", acc.Address.Hex(), acc.URL.Path), ) return acc.Address.Hex(), nil @@ -156,9 +157,9 @@ func ImportAccount(homedir, mnemonic, password string) (string, error) { return "", errors.Wrap(err, "failed to get import private key") } - Logger.Info( + log.Logger.Info( fmt.Sprintf("Imported account %s to path: %s\n", acc.Address.Hex(), acc.URL.Path), ) - + return acc.Address.Hex(), nil } From 6b1ddf594266b9d66264b5d53205d11cb4174c4b Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Tue, 2 Sep 2025 12:08:12 +0530 Subject: [PATCH 10/18] fix compilation --- zboxcore/zboxutil/http.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/zboxcore/zboxutil/http.go b/zboxcore/zboxutil/http.go index cb2225127..05e01891b 100644 --- a/zboxcore/zboxutil/http.go +++ b/zboxcore/zboxutil/http.go @@ -17,11 +17,9 @@ import ( "github.com/hashicorp/golang-lru/v2/simplelru" "github.com/0chain/errors" - "github.com/0chain/gosdk/constants" "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/encryption" "github.com/0chain/gosdk/core/logger" - "github.com/0chain/gosdk/core/zcncrypto" l "github.com/0chain/gosdk/zboxcore/logger" lru "github.com/hashicorp/golang-lru/v2" "github.com/hitenjain14/fasthttp" From 34f7c5f20babf816871d983cf0b0ad7cc2f6b8aa Mon Sep 17 00:00:00 2001 From: Arun Ramanathan Date: Tue, 2 Sep 2025 12:16:52 +0530 Subject: [PATCH 11/18] fix compilation --- mobilesdk/sdk/sdk.go | 2 +- wasmsdk/auth_txn.go | 4 ++-- wasmsdk/proxy.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mobilesdk/sdk/sdk.go b/mobilesdk/sdk/sdk.go index 8ce6558c9..d9b78bcfd 100644 --- a/mobilesdk/sdk/sdk.go +++ b/mobilesdk/sdk/sdk.go @@ -33,7 +33,7 @@ var nonce = int64(0) var allocationIDRequired = errors.Errorf("Allocation ID is required") type Autorizer interface { - Auth(msg string) (string, error) + Auth(msg string, clientIDs ...string) (string, error) } // ChainConfig - blockchain config diff --git a/wasmsdk/auth_txn.go b/wasmsdk/auth_txn.go index e917512e5..aa8354446 100644 --- a/wasmsdk/auth_txn.go +++ b/wasmsdk/auth_txn.go @@ -29,7 +29,7 @@ func registerAuthorizer(this js.Value, args []js.Value) interface{} { authCallback = parseAuthorizerCallback(args[0]) authResponseC = make(chan string, 1) - sys.Authorize = func(msg string) (string, error) { + sys.Authorize = func(msg string, clientIDs ...string) (string, error) { authCallback(msg) return <-authResponseC, nil } @@ -93,7 +93,7 @@ func registerAuthCommon(this js.Value, args []js.Value) interface{} { authMsgCallback = parseAuthorizerCallback(args[0]) authMsgResponseC = make(chan string, 1) - sys.AuthCommon = func(msg string) (string, error) { + sys.AuthCommon = func(msg string, clientIDs ...string) (string, error) { authMsgLock <- struct{}{} defer func() { <-authMsgLock diff --git a/wasmsdk/proxy.go b/wasmsdk/proxy.go index 16b1d0045..ec56f3ec0 100644 --- a/wasmsdk/proxy.go +++ b/wasmsdk/proxy.go @@ -478,7 +478,7 @@ func main() { gInitProxyKeys(publicKey, privateKey) if isSplit { - sys.AuthCommon = func(msg string) (string, error) { + sys.AuthCommon = func(msg string, clientIDs ...string) (string, error) { // send message to main thread sendMessageToMainThread(msg) // wait for response from main thread From d497ed3776998e9f0e64329af2ce5ec1b34fe8ec Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Sat, 27 Sep 2025 22:59:20 +0530 Subject: [PATCH 12/18] move method changes for multi wallet --- zboxcore/sdk/renameworker.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/zboxcore/sdk/renameworker.go b/zboxcore/sdk/renameworker.go index 644bfcc75..6881dcd1e 100644 --- a/zboxcore/sdk/renameworker.go +++ b/zboxcore/sdk/renameworker.go @@ -45,10 +45,15 @@ type RenameRequest struct { connectionID string consensus Consensus timestamp int64 + clientId string } func (req *RenameRequest) getObjectTreeFromBlobber(blobber *blockchain.StorageNode) (fileref.RefEntity, error) { - return getObjectTreeFromBlobber(req.ctx, req.allocationID, req.allocationTx, req.sig, req.remotefilepath, blobber, req.allocationObj.Owner) + clientId := req.clientId + if clientId == "" { + clientId = req.allocationObj.Owner + } + return getObjectTreeFromBlobber(req.ctx, req.allocationID, req.allocationTx, req.sig, req.remotefilepath, blobber, req.allocationObj.Owner, clientId) } func (req *RenameRequest) getFileMetaFromBlobber(pos int) (fileRef *fileref.FileRef, err error) { @@ -117,7 +122,11 @@ func (req *RenameRequest) renameBlobberObject( formWriter.Close() var httpreq *http.Request - httpreq, err = zboxutil.NewRenameRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) + clientId := req.clientId + if clientId == "" { + clientId = req.allocationObj.Owner + } + httpreq, err = zboxutil.NewRenameRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner, clientId) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating rename request", err) return @@ -418,6 +427,7 @@ type RenameOperation struct { newName string maskMU *sync.Mutex objectTreeRefs []fileref.RefEntity + clientId string consensus Consensus } @@ -439,6 +449,7 @@ func (ro *RenameOperation) Process(allocObj *Allocation, connectionID string) ([ maskMU: ro.maskMU, wg: &sync.WaitGroup{}, consensus: Consensus{RWMutex: &sync.RWMutex{}}, + clientId: ro.clientId } if filepath.Base(ro.remotefilepath) == ro.newName { return nil, ro.renameMask, errors.New("invalid_operation", "Cannot rename to same name") @@ -526,7 +537,7 @@ func (ro *RenameOperation) Error(allocObj *Allocation, consensus int, err error) } -func NewRenameOperation(remotePath string, destName string, renameMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context) *RenameOperation { +func NewRenameOperation(remotePath string, destName string, renameMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context, clientId string) *RenameOperation { ro := &RenameOperation{} ro.remotefilepath = zboxutil.RemoteClean(remotePath) ro.newName = path.Base(destName) @@ -535,6 +546,7 @@ func NewRenameOperation(remotePath string, destName string, renameMask zboxutil. ro.consensus.consensusThresh = consensusTh ro.consensus.fullconsensus = fullConsensus ro.ctx, ro.ctxCncl = context.WithCancel(ctx) + ro.clientId = clientId return ro } From d27ab0c90e5b7efcd5bf7e19f1aca2ec93561d43 Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Sat, 27 Sep 2025 23:04:00 +0530 Subject: [PATCH 13/18] move method changes for multi wallet --- zboxcore/sdk/moveworker.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/zboxcore/sdk/moveworker.go b/zboxcore/sdk/moveworker.go index 2bceac689..2294e09c0 100644 --- a/zboxcore/sdk/moveworker.go +++ b/zboxcore/sdk/moveworker.go @@ -45,11 +45,16 @@ type MoveRequest struct { connectionID string timestamp int64 destLookupHash string + clientId string Consensus } func (req *MoveRequest) getObjectTreeFromBlobber(blobber *blockchain.StorageNode) (fileref.RefEntity, error) { - return getObjectTreeFromBlobber(req.ctx, req.allocationID, req.allocationTx, req.sig, req.remotefilepath, blobber, req.allocationObj.Owner) + clientId := req.clientId + if clientId == "" { + clientId = req.allocationObj.Owner + } + return getObjectTreeFromBlobber(req.ctx, req.allocationID, req.allocationTx, req.sig, req.remotefilepath, blobber, req.allocationObj.Owner, clientId) } func (req *MoveRequest) getFileMetaFromBlobber(pos int) (fileRef *fileref.FileRef, err error) { @@ -122,7 +127,11 @@ func (req *MoveRequest) moveBlobberObject( cncl context.CancelFunc ) - httpreq, err = zboxutil.NewMoveRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) + clientId := req.clientId + if clientId == "" { + clientId = req.allocationObj.Owner + } + httpreq, err = zboxutil.NewMoveRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner, clientId) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating rename request", err) return @@ -422,6 +431,7 @@ type MoveOperation struct { maskMU *sync.Mutex consensus Consensus objectTreeRefs []fileref.RefEntity + clientId string } func (mo *MoveOperation) Process(allocObj *Allocation, connectionID string) ([]fileref.RefEntity, zboxutil.Uint128, error) { @@ -439,6 +449,7 @@ func (mo *MoveOperation) Process(allocObj *Allocation, connectionID string) ([]f maskMU: mo.maskMU, destPath: mo.destPath, Consensus: Consensus{RWMutex: &sync.RWMutex{}}, + clientId: mo.clientId, } mR.Consensus.fullconsensus = mo.consensus.fullconsensus mR.Consensus.consensusThresh = mo.consensus.consensusThresh @@ -518,7 +529,7 @@ func (mo *MoveOperation) Error(allocObj *Allocation, consensus int, err error) { } -func NewMoveOperation(remotePath string, destPath string, moveMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context) *MoveOperation { +func NewMoveOperation(remotePath string, destPath string, moveMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh int, fullConsensus int, ctx context.Context, clientId string) *MoveOperation { mo := &MoveOperation{} mo.remotefilepath = zboxutil.RemoteClean(remotePath) if destPath != "/" { @@ -530,6 +541,7 @@ func NewMoveOperation(remotePath string, destPath string, moveMask zboxutil.Uint mo.consensus.consensusThresh = consensusTh mo.consensus.fullconsensus = fullConsensus mo.ctx, mo.ctxCncl = context.WithCancel(ctx) + mo.clientId = clientId return mo } From 7fb10ba109833203894567be86e2cf64738a3bfb Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Sat, 27 Sep 2025 23:23:13 +0530 Subject: [PATCH 14/18] copy changes for multi wallet --- zboxcore/sdk/copyworker.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/zboxcore/sdk/copyworker.go b/zboxcore/sdk/copyworker.go index 9d77f2425..5e7d1bbd9 100644 --- a/zboxcore/sdk/copyworker.go +++ b/zboxcore/sdk/copyworker.go @@ -46,6 +46,7 @@ type CopyRequest struct { timestamp int64 dirOnly bool destLookupHash string + clientId string Consensus } @@ -130,7 +131,11 @@ func (req *CopyRequest) copyBlobberObject( cncl context.CancelFunc ) - httpreq, err = zboxutil.NewCopyRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner) + clientId := req.clientId + if clientId == "" { + clientId = req.allocationObj.Owner + } + httpreq, err = zboxutil.NewCopyRequest(blobber.Baseurl, req.allocationID, req.allocationTx, req.sig, body, req.allocationObj.Owner, clientId) if err != nil { l.Logger.Error(blobber.Baseurl, "Error creating rename request", err) return @@ -417,6 +422,7 @@ type CopyOperation struct { copyMask zboxutil.Uint128 maskMU *sync.Mutex objectTreeRefs []fileref.RefEntity + clientId string Consensus } @@ -438,6 +444,7 @@ func (co *CopyOperation) Process(allocObj *Allocation, connectionID string) ([]f maskMU: co.maskMU, dirOnly: co.dirOnly, Consensus: Consensus{RWMutex: &sync.RWMutex{}}, + clientId: co.clientId, } cR.consensusThresh = co.consensusThresh @@ -517,7 +524,7 @@ func (co *CopyOperation) Error(allocObj *Allocation, consensus int, err error) { } -func NewCopyOperation(ctx context.Context, remotePath string, destPath string, copyMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh, fullConsensus int, copyDirOnly bool) *CopyOperation { +func NewCopyOperation(ctx context.Context, remotePath string, destPath string, copyMask zboxutil.Uint128, maskMU *sync.Mutex, consensusTh, fullConsensus int, copyDirOnly bool, clientId string) *CopyOperation { co := &CopyOperation{} co.remotefilepath = zboxutil.RemoteClean(remotePath) co.copyMask = copyMask @@ -530,6 +537,7 @@ func NewCopyOperation(ctx context.Context, remotePath string, destPath string, c co.destPath = destPath co.ctx, co.ctxCncl = context.WithCancel(ctx) co.dirOnly = copyDirOnly + co.clientId = clientId return co } From a574e9fa3dea81c7e1d20f8fb36ee01621b3c3a2 Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Sat, 27 Sep 2025 23:28:12 +0530 Subject: [PATCH 15/18] add clientId for all operations --- zboxcore/sdk/allocation.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/zboxcore/sdk/allocation.go b/zboxcore/sdk/allocation.go index 8b605f5f5..83c75cab8 100644 --- a/zboxcore/sdk/allocation.go +++ b/zboxcore/sdk/allocation.go @@ -1139,13 +1139,31 @@ func (a *Allocation) DoMultiOperation(operations []OperationRequest, opts ...Mul switch op.OperationType { case constants.FileOperationRename: - operation = NewRenameOperation(op.RemotePath, op.DestName, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) + var clientId string + if mo.Wallet != nil { + clientId = mo.Wallet.ClientID + } else { + clientId = mo.allocationObj.Owner + } + operation = NewRenameOperation(op.RemotePath, op.DestName, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx, clientId) case constants.FileOperationCopy: - operation = NewCopyOperation(mo.ctx, op.RemotePath, op.DestPath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, op.CopyDirOnly) + var clientId string + if mo.Wallet != nil { + clientId = mo.Wallet.ClientID + } else { + clientId = mo.allocationObj.Owner + } + operation = NewCopyOperation(mo.ctx, op.RemotePath, op.DestPath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, op.CopyDirOnly, clientId) case constants.FileOperationMove: - operation = NewMoveOperation(op.RemotePath, op.DestPath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx) + var clientId string + if mo.Wallet != nil { + clientId = mo.Wallet.ClientID + } else { + clientId = mo.allocationObj.Owner + } + operation = NewMoveOperation(op.RemotePath, op.DestPath, mo.operationMask, mo.maskMU, mo.consensusThresh, mo.fullconsensus, mo.ctx, clientId) case constants.FileOperationInsert: cancelLock.Lock() From 346ab9774fb72e0210ff4b16bfed3c2c05a6a0c3 Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Sun, 28 Sep 2025 00:50:58 +0530 Subject: [PATCH 16/18] make public key as key for wallet map --- core/client/set.go | 102 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 25 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index e5df9e3c3..bb999f486 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -66,8 +66,17 @@ func init() { Sign = func(hash string, clients ...string) (string, error) { wallet := client.wallet - if len(clients) > 0 && clients[0] != "" && client.wallets[clients[0]] != nil { - wallet = client.wallets[clients[0]] + if len(clients) > 0 && clients[0] != "" { + if client.wallets[clients[0]] != nil { + wallet = client.wallets[clients[0]] + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + wallet = w + break + } + } + } } if !wallet.IsSplit { @@ -197,9 +206,20 @@ func verifyEd25519With(pubKey, signature, hash string) (bool, error) { func GetClientSysKeys(clients ...string) []sys.KeyPair { var wallet *zcncrypto.Wallet - if len(clients) > 0 && clients[0] != "" && client.wallets[clients[0]] != nil { - wallet = client.wallets[clients[0]] - } else { + if len(clients) > 0 && clients[0] != "" { + if client.wallets[clients[0]] != nil { + wallet = client.wallets[clients[0]] + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + wallet = w + break + } + } + } + } + + if wallet == nil{ wallet = client.wallet } @@ -220,7 +240,14 @@ func SetWallet(w zcncrypto.Wallet) { if client.wallets == nil { client.wallets = make(map[string]*zcncrypto.Wallet) } - client.wallets[w.ClientID] = &w + client.wallets[w.ClientKey] = &w +} + +func GetWalletByClientKey(clientKey string) *zcncrypto.Wallet { + if client.wallets == nil { + return nil + } + return client.wallets[clientKey] } // GetWalletByClientID gets a wallet by client id. @@ -231,28 +258,45 @@ func GetWalletByClientID(clientID string) *zcncrypto.Wallet { if _, exists := client.wallets[clientID]; !exists { return nil } - return client.wallets[clientID] + + for _, wallet := range client.wallets { + if wallet.ClientID == clientID { + return wallet + } + } + + return nil } // AddWallet adds a new wallet to the sdk. func AddWallet(wallet zcncrypto.Wallet) { + clientKey := wallet.ClientKey if client.wallets == nil { client.wallets = make(map[string]*zcncrypto.Wallet) } if _, exists := client.wg[wallet.ClientID]; !exists { client.wg[wallet.ClientID] = &sync.WaitGroup{} } - client.wg[wallet.ClientID].Add(1) - client.walletCount[wallet.ClientID]++ - client.wallets[wallet.ClientID] = &wallet + client.wg[clientKey].Add(1) + client.walletCount[clientKey]++ + client.wallets[clientKey] = &wallet } // RemoveWallet removes a wallet from the sdk. -func RemoveWallet(clientID string) { - client.wg[clientID].Done() - client.walletCount[clientID]-- - if client.walletCount[clientID] == 0 { - delete(client.wallets, clientID) +func RemoveWallet(clientKey string) { + client.wg[clientKey].Done() + client.walletCount[clientKey]-- + if client.walletCount[clientKey] == 0 { + delete(client.wallets, clientKey) + } +} + +func RemoveWalletByClientID(clientID string) { + for clientKey, wallet := range client.wallets { + if wallet.ClientID == clientID { + RemoveWallet(clientKey) + return + } } } @@ -327,12 +371,16 @@ func IsWalletSet() bool { } func PublicKey(clients ...string) string { - if len(clients) > 0 && clients[0] != "" && client.wallets[clients[0]] != nil { - if client.wallets[clients[0]] == nil { - fmt.Println("Public key is empty") - return "" + if len(clients) > 0 && clients[0] != "" { + if client.wallets[clients[0]] != nil { + return client.wallets[clients[0]].ClientKey + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + return w.ClientKey + } + } } - return client.wallets[clients[0]].ClientKey } return client.wallet.ClientKey @@ -350,12 +398,16 @@ func PrivateKey() string { } func Id(clients ...string) string { - if len(clients) > 0 && clients[0] != "" && client.wallets[clients[0]] != nil { - if client.wallets[clients[0]] == nil { - fmt.Println("Id is empty : ", clients[0]) - return "" + if len(clients) > 0 && clients[0] != "" { + if client.wallets[clients[0]] != nil { + return client.wallets[clients[0]].ClientID + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + return w.ClientID + } + } } - return client.wallets[clients[0]].ClientID } return client.wallet.ClientID } From ea5f6a85d5210cd6d289b7216675960aefca3f9d Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Thu, 2 Oct 2025 03:57:54 +0530 Subject: [PATCH 17/18] created SignByMultiWallet function --- core/client/set.go | 94 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 83 insertions(+), 11 deletions(-) diff --git a/core/client/set.go b/core/client/set.go index bb999f486..954fe4b7f 100644 --- a/core/client/set.go +++ b/core/client/set.go @@ -19,12 +19,15 @@ var ( client Client sdkInitialized bool - Sign SignFunc - sigC = make(chan struct{}, 1) + Sign SignFunc + SignByMultiWallet SignByMultiWalletFunc + sigC = make(chan struct{}, 1) ) type SignFunc func(hash string, clients ...string) (string, error) +type SignByMultiWalletFunc func(hash string, pubkey string, clients ...string) (string, error) + // maintains client's information type Client struct { wallet *zcncrypto.Wallet @@ -91,6 +94,59 @@ func init() { return sig, err } + SignByMultiWallet = func(hash string, pubkey string, clients ...string) (string, error) { + var wallet *zcncrypto.Wallet + + // First try to find wallet by public key + if pubkey != "" { + if client.wallets[pubkey] != nil { + wallet = client.wallets[pubkey] + } else { + // Fallback to searching by client ID if pubkey not found + if len(clients) > 0 && clients[0] != "" { + if client.wallets[clients[0]] != nil { + wallet = client.wallets[clients[0]] + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + wallet = w + break + } + } + } + } + } + } else if len(clients) > 0 && clients[0] != "" { + // If no pubkey provided, fallback to client ID lookup + if client.wallets[clients[0]] != nil { + wallet = client.wallets[clients[0]] + } else { + for _, w := range client.wallets { + if w.ClientID == clients[0] { + wallet = w + break + } + } + } + } + + // If no wallet found, use default wallet + if wallet == nil { + wallet = client.wallet + } + + if !wallet.IsSplit { + return sys.Sign(hash, client.signatureScheme, GetClientSysKeysByWallet(wallet)) + } + fmt.Printf("SignByMultiWallet: wallet details: %+v\n", *wallet) + // get sign lock + <-sigC + fmt.Println("SignByMultiWallet: with sys.SignWithAuth:", sys.SignWithAuth, "sysKeys:", GetClientSysKeysByWallet(wallet)) + sig, err := sys.SignWithAuth(hash, client.signatureScheme, GetClientSysKeysByWallet(wallet), wallet.ClientID) + sigC <- struct{}{} + return sig, err + } + sys.Verify = verifySignature sys.VerifyWith = verifySignatureWith sys.VerifyEd25519With = verifyEd25519With @@ -217,9 +273,9 @@ func GetClientSysKeys(clients ...string) []sys.KeyPair { } } } - } - - if wallet == nil{ + } + + if wallet == nil { wallet = client.wallet } @@ -234,6 +290,22 @@ func GetClientSysKeys(clients ...string) []sys.KeyPair { return keys } +func GetClientSysKeysByWallet(wallet *zcncrypto.Wallet) []sys.KeyPair { + if wallet == nil { + return GetClientSysKeys() + } + + var keys []sys.KeyPair + for _, kv := range wallet.Keys { + keys = append(keys, sys.KeyPair{ + PrivateKey: kv.PrivateKey, + PublicKey: kv.PublicKey, + }) + } + + return keys +} + // SetWallet should be set before any transaction or client specific APIs func SetWallet(w zcncrypto.Wallet) { client.wallet = &w @@ -253,11 +325,11 @@ func GetWalletByClientKey(clientKey string) *zcncrypto.Wallet { // GetWalletByClientID gets a wallet by client id. func GetWalletByClientID(clientID string) *zcncrypto.Wallet { if client.wallets == nil { - return nil - } + return nil + } if _, exists := client.wallets[clientID]; !exists { - return nil - } + return nil + } for _, wallet := range client.wallets { if wallet.ClientID == clientID { @@ -275,8 +347,8 @@ func AddWallet(wallet zcncrypto.Wallet) { client.wallets = make(map[string]*zcncrypto.Wallet) } if _, exists := client.wg[wallet.ClientID]; !exists { - client.wg[wallet.ClientID] = &sync.WaitGroup{} - } + client.wg[wallet.ClientID] = &sync.WaitGroup{} + } client.wg[clientKey].Add(1) client.walletCount[clientKey]++ client.wallets[clientKey] = &wallet From 370243f75a7f016c2ec3656b7219b9da25483082 Mon Sep 17 00:00:00 2001 From: Kunal Goyal <151kgoyal@gmail.com> Date: Thu, 2 Oct 2025 04:14:27 +0530 Subject: [PATCH 18/18] updated file operations and test files --- zboxcore/sdk/blobber_operations.go | 6 ++++-- zboxcore/sdk/chunked_upload_form_builder.go | 19 ++++++++++++++----- zboxcore/sdk/copyworker_test.go | 6 ++++-- zboxcore/sdk/filestatsworker_test.go | 4 +++- zboxcore/sdk/renameworker.go | 2 +- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/zboxcore/sdk/blobber_operations.go b/zboxcore/sdk/blobber_operations.go index cdcd3b9c2..b24d645a5 100644 --- a/zboxcore/sdk/blobber_operations.go +++ b/zboxcore/sdk/blobber_operations.go @@ -196,7 +196,8 @@ func UpdateAllocation( func GetUpdateAllocTicket(allocationID, userID, operationType string, roundExpiry int64) (string, error) { payload := fmt.Sprintf("%s:%d:%s:%s", allocationID, roundExpiry, userID, operationType) - signature, err := client.Sign(hex.EncodeToString([]byte(payload))) + pubkey := client.PublicKey() + signature, err := client.SignByMultiWallet(hex.EncodeToString([]byte(payload)), pubkey) if err != nil { return "", err } @@ -366,7 +367,8 @@ func GenerateOwnerSigningKey(ownerPublicKey, ownerID string) (ed25519.PrivateKey return nil, errors.New("owner_public_key_required", "owner public key is required") } hashData := fmt.Sprintf("%s:%s", ownerPublicKey, "owner_signing_public_key") - sig, err := client.Sign(encryption.Hash(hashData), ownerID) + pubkey := client.PublicKey() + sig, err := client.SignByMultiWallet(encryption.Hash(hashData), pubkey, ownerID) if err != nil { logger.Logger.Error("error during sign", zap.Error(err)) return nil, err diff --git a/zboxcore/sdk/chunked_upload_form_builder.go b/zboxcore/sdk/chunked_upload_form_builder.go index be3e1d813..cc103cd6e 100644 --- a/zboxcore/sdk/chunked_upload_form_builder.go +++ b/zboxcore/sdk/chunked_upload_form_builder.go @@ -24,7 +24,7 @@ type ChunkedUploadFormBuilder interface { fileMeta *FileMeta, hasher Hasher, connectionID, blobberID string, chunkSize int64, chunkStartIndex, chunkEndIndex int, isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte, - thumbnailChunkData []byte, shardSize int64, clients... string, + thumbnailChunkData []byte, shardSize int64, clients ...string, ) (blobberData, error) } @@ -59,7 +59,7 @@ func (b *chunkedUploadFormBuilder) Build( fileMeta *FileMeta, hasher Hasher, connectionID, blobberID string, chunkSize int64, chunkStartIndex, chunkEndIndex int, isFinal bool, encryptedKey, encryptedKeyPoint string, fileChunksData [][]byte, - thumbnailChunkData []byte, shardSize int64, clients... string, + thumbnailChunkData []byte, shardSize int64, clients ...string, ) (blobberData, error) { metadata := ChunkedUploadFormMetadata{ @@ -105,7 +105,7 @@ func (b *chunkedUploadFormBuilder) Build( if b.privateSigningKey != nil { formData.SignatureVersion = SignatureV2 - } + } for i := 0; i < numBodies; i++ { @@ -187,7 +187,12 @@ func (b *chunkedUploadFormBuilder) Build( } formData.ActualFileHashSignature = hex.EncodeToString(sig) } else { - sig, err := client.Sign(fileMeta.ActualHash, clients...) + var pubkey string + if len(clients) > 0 && clients[0] != "" { + pubkey = client.PublicKey(clients...) + } + + sig, err := client.SignByMultiWallet(fileMeta.ActualHash, pubkey, clients...) if err != nil { return res, err } @@ -206,7 +211,11 @@ func (b *chunkedUploadFormBuilder) Build( } formData.ValidationRootSignature = hex.EncodeToString(sig) } else { - rootSig, err := client.Sign(hash, clients...) + var pubkey string + if len(clients) > 0 && clients[0] != "" { + pubkey = client.PublicKey(clients...) + } + rootSig, err := client.SignByMultiWallet(hash, pubkey, clients...) if err != nil { return res, err } diff --git a/zboxcore/sdk/copyworker_test.go b/zboxcore/sdk/copyworker_test.go index f795ce51b..fdc7a3496 100644 --- a/zboxcore/sdk/copyworker_test.go +++ b/zboxcore/sdk/copyworker_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "encoding/json" - "github.com/0chain/gosdk/zboxcore/mocks" "io" "mime" "mime/multipart" @@ -14,6 +13,8 @@ import ( "sync" "testing" + "github.com/0chain/gosdk/zboxcore/mocks" + "github.com/0chain/errors" "github.com/0chain/gosdk/core/client" "github.com/0chain/gosdk/core/zcncrypto" @@ -495,7 +496,8 @@ func TestCopyRequest_ProcessCopy(t *testing.T) { maskMU: &sync.Mutex{}, connectionID: mockConnectionId, } - sig, err := client.Sign(mockAllocationTxId) + pubkey := client.PublicKey() + sig, err := client.SignByMultiWallet(mockAllocationTxId, pubkey) require.NoError(err) req.sig = sig req.ctx, req.ctxCncl = context.WithCancel(context.TODO()) diff --git a/zboxcore/sdk/filestatsworker_test.go b/zboxcore/sdk/filestatsworker_test.go index d9c7e6ba4..a1a50f97a 100644 --- a/zboxcore/sdk/filestatsworker_test.go +++ b/zboxcore/sdk/filestatsworker_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "github.com/0chain/gosdk/zboxcore/mocks" "io" @@ -126,7 +127,8 @@ func TestListRequest_getFileStatsInfoFromBlobber(t *testing.T) { require.NoError(t, err) require.EqualValues(t, expected, string(actual)) - sign, _ := client.Sign(encryption.Hash(mockAllocationTxId)) + pubkey := client.PublicKey() + sign, _ := client.SignByMultiWallet(encryption.Hash(mockAllocationTxId), pubkey) return req.URL.Path == "Test_Success"+zboxutil.FILE_STATS_ENDPOINT+mockAllocationTxId && req.Method == "POST" && req.Header.Get("X-App-Client-ID") == mockClientId && diff --git a/zboxcore/sdk/renameworker.go b/zboxcore/sdk/renameworker.go index 6881dcd1e..f83dc75ac 100644 --- a/zboxcore/sdk/renameworker.go +++ b/zboxcore/sdk/renameworker.go @@ -449,7 +449,7 @@ func (ro *RenameOperation) Process(allocObj *Allocation, connectionID string) ([ maskMU: ro.maskMU, wg: &sync.WaitGroup{}, consensus: Consensus{RWMutex: &sync.RWMutex{}}, - clientId: ro.clientId + clientId: ro.clientId, } if filepath.Base(ro.remotefilepath) == ro.newName { return nil, ro.renameMask, errors.New("invalid_operation", "Cannot rename to same name")