From fbf4c904b98cb787fbc6ab4f3aa0ab483b20ba56 Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 14:56:15 +0545 Subject: [PATCH 1/7] Fix issue raised by gocritic linter --- .../allocation/allocationchange.go | 2 +- .../blobbercore/allocation/copyfilechange.go | 2 +- .../blobbercore/allocation/protocol.go | 15 ++-- .../blobbercore/allocation/workers.go | 4 +- .../blobbercore/blobberhttp/response.go | 4 +- .../blobbercore/challenge/challenge.go | 4 +- .../blobbercore/challenge/entity.go | 4 +- .../blobbercore/challenge/protocol.go | 2 +- .../0chain.net/blobbercore/config/config.go | 2 +- .../0chain.net/blobbercore/convert/convert.go | 2 +- .../blobbercore/datastore/mock_store.go | 1 - .../blobbercore/filestore/chunk_writer.go | 4 +- .../filestore/chunk_writer_test.go | 2 +- .../blobbercore/filestore/fs_store.go | 14 ++-- .../blobbercore/filestore/mock_store.go | 4 +- .../blobbercore/handler/file_command_add.go | 46 +++++------ .../handler/file_command_delete.go | 2 +- .../handler/file_command_update.go | 47 ++++++------ .../blobbercore/handler/grpc_handler.go | 23 +++--- .../0chain.net/blobbercore/handler/handler.go | 2 +- .../blobbercore/handler/handler_test.go | 34 ++++----- .../handler/helper_integration_test.go | 4 +- .../handler/object_operation_grpc_handler.go | 9 ++- .../handler/object_operation_handler.go | 76 +++++++++---------- .../blobbercore/handler/protocol.go | 2 +- .../blobbercore/handler/storage_handler.go | 75 +++++++++--------- .../0chain.net/blobbercore/handler/worker.go | 4 +- .../0chain.net/blobbercore/handler/zcncore.go | 2 +- .../blobbercore/readmarker/entity.go | 2 +- .../blobbercore/readmarker/protocol.go | 4 +- .../blobbercore/reference/object.go | 2 +- .../blobbercore/reference/objectpath.go | 4 +- .../0chain.net/blobbercore/reference/ref.go | 38 +++++----- .../blobbercore/reference/referencepath.go | 6 +- .../blobbercore/reference/shareinfo.go | 4 +- .../blobbercore/stats/challengestats.go | 10 +-- .../0chain.net/blobbercore/stats/filestats.go | 3 +- .../0chain.net/blobbercore/stats/handler.go | 19 ++--- .../blobbercore/stats/pagination.go | 2 +- code/go/0chain.net/blobbercore/util/json.go | 7 +- .../blobbercore/writemarker/entity.go | 2 +- .../blobbercore/writemarker/protocol.go | 4 +- .../blobbercore/writemarker/worker.go | 3 +- code/go/0chain.net/core/build/info.go | 2 +- code/go/0chain.net/core/cache/lfu.go | 6 +- code/go/0chain.net/core/cache/lru.go | 8 +- code/go/0chain.net/core/common/context.go | 6 +- code/go/0chain.net/core/common/errors.go | 4 +- code/go/0chain.net/core/common/handler.go | 24 +++--- code/go/0chain.net/core/common/time.go | 2 +- code/go/0chain.net/core/common/utils.go | 8 +- code/go/0chain.net/core/encryption/keys.go | 6 +- code/go/0chain.net/core/lock/lock.go | 2 +- code/go/0chain.net/core/logging/logger.go | 2 +- code/go/0chain.net/core/node/self_node.go | 2 +- code/go/0chain.net/core/transaction/http.go | 3 +- code/go/0chain.net/core/util/http.go | 8 +- .../0chain.net/validatorcore/config/config.go | 2 +- .../validatorcore/storage/models.go | 28 +++---- .../validatorcore/storage/protocol.go | 4 +- .../storage/writemarker/entity.go | 2 +- 61 files changed, 310 insertions(+), 311 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 7ff70c93b..734064938 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -69,7 +69,7 @@ func (change *AllocationChange) Save(ctx context.Context) error { // GetAllocationChanges reload connection's changes in allocation from postgres. // 1. update connection's status with NewConnection if connection_id is not found in postgres // 2. mark as NewConnection if connection_id is marked as DeleteConnection -func GetAllocationChanges(ctx context.Context, connectionID string, allocationID string, clientID string) (*AllocationChangeCollector, error) { +func GetAllocationChanges(ctx context.Context, connectionID, allocationID, clientID string) (*AllocationChangeCollector, error) { cc := &AllocationChangeCollector{} db := datastore.GetStore().GetTransaction(ctx) err := db.Where("connection_id = ? and allocation_id = ? and client_id = ? and status <> ?", diff --git a/code/go/0chain.net/blobbercore/allocation/copyfilechange.go b/code/go/0chain.net/blobbercore/allocation/copyfilechange.go index 9558dd834..41e4904e6 100644 --- a/code/go/0chain.net/blobbercore/allocation/copyfilechange.go +++ b/code/go/0chain.net/blobbercore/allocation/copyfilechange.go @@ -99,7 +99,7 @@ func (rf *CopyFileChange) ProcessChange(ctx context.Context, change *AllocationC return rootRef, err } -func (rf *CopyFileChange) processCopyRefs(ctx context.Context, affectedRef *reference.Ref, destRef *reference.Ref, allocationRoot string) { +func (rf *CopyFileChange) processCopyRefs(ctx context.Context, affectedRef, destRef *reference.Ref, allocationRoot string) { if affectedRef.Type == reference.DIRECTORY { newRef := reference.NewDirectoryRef() newRef.AllocationID = rf.AllocationID diff --git a/code/go/0chain.net/blobbercore/allocation/protocol.go b/code/go/0chain.net/blobbercore/allocation/protocol.go index e4c358df9..27905f669 100644 --- a/code/go/0chain.net/blobbercore/allocation/protocol.go +++ b/code/go/0chain.net/blobbercore/allocation/protocol.go @@ -101,14 +101,15 @@ func VerifyAllocationTransaction(ctx context.Context, allocationTx string, if !isExist { foundBlobber := false for _, blobberConnection := range sa.Blobbers { - if blobberConnection.ID == node.Self.ID { - foundBlobber = true - a.AllocationRoot = "" - a.BlobberSize = (sa.Size + int64(len(sa.Blobbers)-1)) / - int64(len(sa.Blobbers)) - a.BlobberSizeUsed = 0 - break + if blobberConnection.ID != node.Self.ID { + continue } + foundBlobber = true + a.AllocationRoot = "" + a.BlobberSize = (sa.Size + int64(len(sa.Blobbers)-1)) / + int64(len(sa.Blobbers)) + a.BlobberSizeUsed = 0 + break } if !foundBlobber { return nil, common.NewError("invalid_blobber", diff --git a/code/go/0chain.net/blobbercore/allocation/workers.go b/code/go/0chain.net/blobbercore/allocation/workers.go index b57ef59fc..2e588a07c 100644 --- a/code/go/0chain.net/blobbercore/allocation/workers.go +++ b/code/go/0chain.net/blobbercore/allocation/workers.go @@ -234,7 +234,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, } // save allocations - if err = tx.Save(a).Error; err != nil { + if err := tx.Save(a).Error; err != nil { return nil, err } @@ -244,7 +244,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, // save allocation terms for _, t := range a.Terms { - if err = tx.Save(t).Error; err != nil { + if err := tx.Save(t).Error; err != nil { return nil, err } } diff --git a/code/go/0chain.net/blobbercore/blobberhttp/response.go b/code/go/0chain.net/blobbercore/blobberhttp/response.go index 68362fe99..1998f6b67 100644 --- a/code/go/0chain.net/blobbercore/blobberhttp/response.go +++ b/code/go/0chain.net/blobbercore/blobberhttp/response.go @@ -14,9 +14,9 @@ type UploadResult struct { Hash string `json:"content_hash"` MerkleRoot string `json:"merkle_root"` - //UploadLength indicates the size of the entire upload in bytes. The value MUST be a non-negative integer. + // UploadLength indicates the size of the entire upload in bytes. The value MUST be a non-negative integer. UploadLength int64 `json:"upload_length"` - //Upload-Offset indicates a byte offset within a resource. The value MUST be a non-negative integer. + // Upload-Offset indicates a byte offset within a resource. The value MUST be a non-negative integer. UploadOffset int64 `json:"upload_offset"` } diff --git a/code/go/0chain.net/blobbercore/challenge/challenge.go b/code/go/0chain.net/blobbercore/challenge/challenge.go index dbe081921..ea8c0bc45 100644 --- a/code/go/0chain.net/blobbercore/challenge/challenge.go +++ b/code/go/0chain.net/blobbercore/challenge/challenge.go @@ -54,7 +54,7 @@ func syncOpenChallenges(ctx context.Context) { logging.Logger.Error("[challenge]json: ", zap.Error(errd)) } else { for _, challengeObj := range blobberChallenges.Challenges { - if challengeObj == nil || len(challengeObj.ChallengeID) == 0 { + if challengeObj == nil || challengeObj.ChallengeID == "" { logging.Logger.Info("[challenge]open: No challenge entity from the challenge map") continue } @@ -75,7 +75,7 @@ func syncOpenChallenges(ctx context.Context) { } } - isFirstChallengeInDatabase := len(challengeObj.PrevChallengeID) == 0 || latestChallenge == nil + isFirstChallengeInDatabase := challengeObj.PrevChallengeID == "" || latestChallenge == nil isNextChallengeOnChain := latestChallenge == nil || latestChallenge.ChallengeID == challengeObj.PrevChallengeID if isFirstChallengeInDatabase || isNextChallengeOnChain { diff --git a/code/go/0chain.net/blobbercore/challenge/entity.go b/code/go/0chain.net/blobbercore/challenge/entity.go index bea780f62..94c5b0435 100644 --- a/code/go/0chain.net/blobbercore/challenge/entity.go +++ b/code/go/0chain.net/blobbercore/challenge/entity.go @@ -123,9 +123,7 @@ func (cr *ChallengeEntity) Save(ctx context.Context) error { if err != nil { return err } - //j, _ := json.Marshal(&cr.ObjectPathString) - // Logger.Info("Object path", zap.Any("objectpath", string(j))) - // Logger.Info("Object path object", zap.Any("object_path", cr.ObjectPath)) + db := datastore.GetStore().GetTransaction(ctx) err = db.Save(cr).Error return err diff --git a/code/go/0chain.net/blobbercore/challenge/protocol.go b/code/go/0chain.net/blobbercore/challenge/protocol.go index e3f9a5b0f..2af8a143a 100644 --- a/code/go/0chain.net/blobbercore/challenge/protocol.go +++ b/code/go/0chain.net/blobbercore/challenge/protocol.go @@ -100,7 +100,7 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error { if rootRef.NumBlocks > 0 { r := rand.New(rand.NewSource(cr.RandomNumber)) blockNum = r.Int63n(rootRef.NumBlocks) - blockNum = blockNum + 1 + blockNum++ cr.BlockNum = blockNum } else { err = common.NewError("allocation_is_blank", "Got a challenge for a blank allocation") diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index 13b2401be..db190dc15 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/viper" ) -//SetupDefaultConfig - setup the default config options that can be overridden via the config file +// SetupDefaultConfig - setup the default config options that can be overridden via the config file func SetupDefaultConfig() { viper.SetDefault("logging.level", "info") viper.SetDefault("contentref_cleaner.frequency", 30) diff --git a/code/go/0chain.net/blobbercore/convert/convert.go b/code/go/0chain.net/blobbercore/convert/convert.go index e1855d415..c287ed756 100644 --- a/code/go/0chain.net/blobbercore/convert/convert.go +++ b/code/go/0chain.net/blobbercore/convert/convert.go @@ -441,7 +441,7 @@ func WriteFileGRPCToHTTP(req *blobbergrpc.UploadFileRequest) (*http.Request, err "Invalid parameters. Error parsing the meta data for upload."+err.Error()) } - r, err := http.NewRequest(req.Method, "", nil) + r, err := http.NewRequest(req.Method, "", http.NoBody) if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/datastore/mock_store.go b/code/go/0chain.net/blobbercore/datastore/mock_store.go index 1b0de35eb..330fe986e 100644 --- a/code/go/0chain.net/blobbercore/datastore/mock_store.go +++ b/code/go/0chain.net/blobbercore/datastore/mock_store.go @@ -26,7 +26,6 @@ func MocketTheStore(t *testing.T, logging bool) { gdb, err := gorm.Open(dialect, new(gorm.Config)) require.NoError(t, err) - //setDB(gdb) instance = &postgresStore{ db: gdb, diff --git a/code/go/0chain.net/blobbercore/filestore/chunk_writer.go b/code/go/0chain.net/blobbercore/filestore/chunk_writer.go index e1e027f03..091466114 100644 --- a/code/go/0chain.net/blobbercore/filestore/chunk_writer.go +++ b/code/go/0chain.net/blobbercore/filestore/chunk_writer.go @@ -7,7 +7,7 @@ import ( "os" ) -//ChunkWriter implements a chunk write that will append content to the file +// ChunkWriter implements a chunk write that will append content to the file type ChunkWriter struct { file string writer *os.File @@ -16,7 +16,7 @@ type ChunkWriter struct { size int64 } -//NewChunkWriter create a ChunkWriter +// NewChunkWriter create a ChunkWriter func NewChunkWriter(file string) (*ChunkWriter, error) { w := &ChunkWriter{ file: file, diff --git a/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go b/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go index 716dc3189..1a22c36e8 100644 --- a/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go +++ b/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go @@ -55,7 +55,7 @@ func TestWriteChunk(t *testing.T) { require.Error(t, err, "failed to create tempfile") return } - offset, err := tempFile.Write([]byte(chunk1)) + offset, err := tempFile.WriteString(chunk1) if err != nil { require.Error(t, err, "failed to write first chunk to tempfile") return diff --git a/code/go/0chain.net/blobbercore/filestore/fs_store.go b/code/go/0chain.net/blobbercore/filestore/fs_store.go index 33d0b9f3c..80c632494 100644 --- a/code/go/0chain.net/blobbercore/filestore/fs_store.go +++ b/code/go/0chain.net/blobbercore/filestore/fs_store.go @@ -55,7 +55,7 @@ type IFileBlockGetter interface { type FileBlockGetter struct { } -func (FileBlockGetter) GetFileBlock(fs *FileFSStore, allocationID string, fileData *FileInputData, blockNum int64, numBlocks int64) ([]byte, error) { +func (FileBlockGetter) GetFileBlock(fs *FileFSStore, allocationID string, fileData *FileInputData, blockNum, numBlocks int64) ([]byte, error) { allocation, err := fs.SetupAllocation(allocationID, true) if err != nil { return nil, common.NewError("invalid_allocation", "Invalid allocation. "+err.Error()) @@ -237,13 +237,13 @@ func (fs *FileFSStore) GetlDiskSizeUsed(allocationID string) (int64, error) { return size, err } -func GetFilePathFromHash(hash string) (string, string) { +func GetFilePathFromHash(h string) (string, string) { var dir bytes.Buffer - fmt.Fprintf(&dir, "%s", hash[0:3]) + fmt.Fprintf(&dir, "%s", h[0:3]) for i := 1; i < 3; i++ { - fmt.Fprintf(&dir, "%s%s", string(os.PathSeparator), hash[3*i:3*i+3]) + fmt.Fprintf(&dir, "%s%s", string(os.PathSeparator), h[3*i:3*i+3]) } - return dir.String(), hash[9:] + return dir.String(), h[9:] } func (fs *FileFSStore) generateTransactionPath(transID string) string { @@ -357,7 +357,7 @@ func (fs *FileFSStore) GetFileBlockForChallenge(allocationID string, fileData *F return returnBytes, fmt.GetMerkleTree(), nil } -func (fs *FileFSStore) GetFileBlock(allocationID string, fileData *FileInputData, blockNum int64, numBlocks int64) ([]byte, error) { +func (fs *FileFSStore) GetFileBlock(allocationID string, fileData *FileInputData, blockNum, numBlocks int64) ([]byte, error) { return fs.fileBlockGetter.GetFileBlock(fs, allocationID, fileData, blockNum, numBlocks) @@ -430,7 +430,7 @@ func (fs *FileFSStore) CommitWrite(allocationID string, fileData *FileInputData, //return false, err } -func (fs *FileFSStore) DeleteFile(allocationID string, contentHash string) error { +func (fs *FileFSStore) DeleteFile(allocationID, contentHash string) error { allocation, err := fs.SetupAllocation(allocationID, true) if err != nil { return common.NewError("filestore_setup_error", "Error setting the fs store. "+err.Error()) diff --git a/code/go/0chain.net/blobbercore/filestore/mock_store.go b/code/go/0chain.net/blobbercore/filestore/mock_store.go index 1b87ff6af..2e5541eae 100644 --- a/code/go/0chain.net/blobbercore/filestore/mock_store.go +++ b/code/go/0chain.net/blobbercore/filestore/mock_store.go @@ -64,7 +64,7 @@ func (ms *MockStore) DeleteDir(allocationID, dirPath, connectionID string) error return nil } -func (ms *MockStore) GetFileBlock(allocationID string, fileData *FileInputData, blockNum int64, numBlocks int64) ([]byte, error) { +func (ms *MockStore) GetFileBlock(allocationID string, fileData *FileInputData, blockNum, numBlocks int64) ([]byte, error) { return nil, constants.ErrNotImplemented } @@ -75,7 +75,7 @@ func (ms *MockStore) CommitWrite(allocationID string, fileData *FileInputData, c func (ms *MockStore) GetFileBlockForChallenge(allocationID string, fileData *FileInputData, blockoffset int) (json.RawMessage, util.MerkleTreeI, error) { return nil, nil, constants.ErrNotImplemented } -func (ms *MockStore) DeleteFile(allocationID string, contentHash string) error { +func (ms *MockStore) DeleteFile(allocationID, contentHash string) error { return nil } func (ms *MockStore) GetTotalDiskSizeUsed() (int64, error) { diff --git a/code/go/0chain.net/blobbercore/handler/file_command_add.go b/code/go/0chain.net/blobbercore/handler/file_command_add.go index 3907b6309..59db9ed6e 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_add.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_add.go @@ -147,40 +147,42 @@ func (cmd *AddFileCommand) ProcessThumbnail(ctx context.Context, req *http.Reque func (cmd *AddFileCommand) reloadChange(connectionObj *allocation.AllocationChangeCollector) { for _, c := range connectionObj.Changes { - if c.Operation == constants.FileOperationInsert { + if c.Operation != constants.FileOperationInsert { + continue + } - dbChangeProcessor := &allocation.AddFileChanger{} + dbChangeProcessor := &allocation.AddFileChanger{} - err := dbChangeProcessor.Unmarshal(c.Input) - if err != nil { - logging.Logger.Error("reloadChange", zap.Error(err)) - } + err := dbChangeProcessor.Unmarshal(c.Input) + if err != nil { + logging.Logger.Error("reloadChange", zap.Error(err)) + } - cmd.fileChanger.Size = dbChangeProcessor.Size - cmd.fileChanger.ThumbnailFilename = dbChangeProcessor.ThumbnailFilename - cmd.fileChanger.ThumbnailSize = dbChangeProcessor.ThumbnailSize - cmd.fileChanger.ThumbnailHash = dbChangeProcessor.Hash + cmd.fileChanger.Size = dbChangeProcessor.Size + cmd.fileChanger.ThumbnailFilename = dbChangeProcessor.ThumbnailFilename + cmd.fileChanger.ThumbnailSize = dbChangeProcessor.ThumbnailSize + cmd.fileChanger.ThumbnailHash = dbChangeProcessor.Hash - return - } + return } } // UpdateChange replace AddFileChange in db func (cmd *AddFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error { for _, c := range connectionObj.Changes { - if c.Operation == constants.FileOperationInsert { - c.Size = connectionObj.Size - c.Input, _ = cmd.fileChanger.Marshal() - - //c.ModelWithTS.UpdatedAt = time.Now() - err := connectionObj.Save(ctx) - if err != nil { - return err - } + if c.Operation != constants.FileOperationInsert { + continue + } + c.Size = connectionObj.Size + c.Input, _ = cmd.fileChanger.Marshal() - return c.Save(ctx) + //c.ModelWithTS.UpdatedAt = time.Now() + err := connectionObj.Save(ctx) + if err != nil { + return err } + + return c.Save(ctx) } //NOT FOUND diff --git a/code/go/0chain.net/blobbercore/handler/file_command_delete.go b/code/go/0chain.net/blobbercore/handler/file_command_delete.go index f33ae7014..d5bbab4e4 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_delete.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_delete.go @@ -25,7 +25,7 @@ func (cmd *FileCommandDelete) IsAuthorized(ctx context.Context, req *http.Reques } path := req.FormValue("path") - if len(path) == 0 { + if path == "" { return common.NewError("invalid_parameters", "Invalid path") } cmd.exisitingFileRef, _ = reference.GetReference(ctx, allocationObj.ID, path) diff --git a/code/go/0chain.net/blobbercore/handler/file_command_update.go b/code/go/0chain.net/blobbercore/handler/file_command_update.go index 5149a5919..af07a536f 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_update.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_update.go @@ -156,40 +156,43 @@ func (cmd *UpdateFileCommand) ProcessThumbnail(ctx context.Context, req *http.Re func (cmd *UpdateFileCommand) reloadChange(connectionObj *allocation.AllocationChangeCollector) { for _, c := range connectionObj.Changes { - if c.Operation == constants.FileOperationUpdate { - - dbFileChanger := &allocation.UpdateFileChanger{} + if c.Operation != constants.FileOperationUpdate { + continue + } - err := dbFileChanger.Unmarshal(c.Input) - if err != nil { - logging.Logger.Error("reloadChange", zap.Error(err)) - } + dbFileChanger := &allocation.UpdateFileChanger{} - // reload uploaded size from db, it was chunk size from client - cmd.fileChanger.Size = dbFileChanger.Size - cmd.fileChanger.ThumbnailFilename = dbFileChanger.ThumbnailFilename - cmd.fileChanger.ThumbnailSize = dbFileChanger.ThumbnailSize - cmd.fileChanger.ThumbnailHash = dbFileChanger.Hash - return + err := dbFileChanger.Unmarshal(c.Input) + if err != nil { + logging.Logger.Error("reloadChange", zap.Error(err)) } + + // reload uploaded size from db, it was chunk size from client + cmd.fileChanger.Size = dbFileChanger.Size + cmd.fileChanger.ThumbnailFilename = dbFileChanger.ThumbnailFilename + cmd.fileChanger.ThumbnailSize = dbFileChanger.ThumbnailSize + cmd.fileChanger.ThumbnailHash = dbFileChanger.Hash + return } } // UpdateChange add UpdateFileChanger in db func (cmd *UpdateFileCommand) UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error { for _, c := range connectionObj.Changes { - if c.Operation == constants.FileOperationUpdate { - c.Size = connectionObj.Size - c.Input, _ = cmd.fileChanger.Marshal() + if c.Operation != constants.FileOperationUpdate { + continue + } - //c.ModelWithTS.UpdatedAt = time.Now() - err := connectionObj.Save(ctx) - if err != nil { - return err - } + c.Size = connectionObj.Size + c.Input, _ = cmd.fileChanger.Marshal() - return c.Save(ctx) + //c.ModelWithTS.UpdatedAt = time.Now() + err := connectionObj.Save(ctx) + if err != nil { + return err } + + return c.Save(ctx) } //NOT FOUND diff --git a/code/go/0chain.net/blobbercore/handler/grpc_handler.go b/code/go/0chain.net/blobbercore/handler/grpc_handler.go index 67989eeb6..9fdff0d54 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_handler.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_handler.go @@ -2,10 +2,11 @@ package handler import ( "context" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "net/http" "strings" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/convert" ) @@ -18,7 +19,7 @@ func newGRPCBlobberService() *blobberGRPCService { } func (b *blobberGRPCService) GetAllocation(ctx context.Context, request *blobbergrpc.GetAllocationRequest) (*blobbergrpc.GetAllocationResponse, error) { - r, err := http.NewRequest("GET", "", nil) + r, err := http.NewRequest("GET", "", http.NoBody) if err != nil { return nil, err } @@ -34,7 +35,7 @@ func (b *blobberGRPCService) GetAllocation(ctx context.Context, request *blobber } func (b *blobberGRPCService) GetFileMetaData(ctx context.Context, req *blobbergrpc.GetFileMetaDataRequest) (*blobbergrpc.GetFileMetaDataResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -54,7 +55,7 @@ func (b *blobberGRPCService) GetFileMetaData(ctx context.Context, req *blobbergr } func (b *blobberGRPCService) GetFileStats(ctx context.Context, req *blobbergrpc.GetFileStatsRequest) (*blobbergrpc.GetFileStatsResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -73,7 +74,7 @@ func (b *blobberGRPCService) GetFileStats(ctx context.Context, req *blobbergrpc. } func (b *blobberGRPCService) ListEntities(ctx context.Context, req *blobbergrpc.ListEntitiesRequest) (*blobbergrpc.ListEntitiesResponse, error) { - r, err := http.NewRequest("", "", nil) + r, err := http.NewRequest("", "", http.NoBody) if err != nil { return nil, err } @@ -93,7 +94,7 @@ func (b *blobberGRPCService) ListEntities(ctx context.Context, req *blobbergrpc. } func (b *blobberGRPCService) GetObjectPath(ctx context.Context, req *blobbergrpc.GetObjectPathRequest) (*blobbergrpc.GetObjectPathResponse, error) { - r, err := http.NewRequest("", "", nil) + r, err := http.NewRequest("", "", http.NoBody) if err != nil { return nil, err } @@ -112,7 +113,7 @@ func (b *blobberGRPCService) GetObjectPath(ctx context.Context, req *blobbergrpc } func (b *blobberGRPCService) GetReferencePath(ctx context.Context, req *blobbergrpc.GetReferencePathRequest) (*blobbergrpc.GetReferencePathResponse, error) { - r, err := http.NewRequest("", "", nil) + r, err := http.NewRequest("", "", http.NoBody) if err != nil { return nil, err } @@ -131,7 +132,7 @@ func (b *blobberGRPCService) GetReferencePath(ctx context.Context, req *blobberg } func (b *blobberGRPCService) GetObjectTree(ctx context.Context, req *blobbergrpc.GetObjectTreeRequest) (*blobbergrpc.GetObjectTreeResponse, error) { - r, err := http.NewRequest("", "", nil) + r, err := http.NewRequest("", "", http.NoBody) if err != nil { return nil, err } @@ -149,7 +150,7 @@ func (b *blobberGRPCService) GetObjectTree(ctx context.Context, req *blobbergrpc } func (b *blobberGRPCService) CalculateHash(ctx context.Context, req *blobbergrpc.CalculateHashRequest) (*blobbergrpc.CalculateHashResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -168,7 +169,7 @@ func (b *blobberGRPCService) CalculateHash(ctx context.Context, req *blobbergrpc } func (b *blobberGRPCService) CommitMetaTxn(ctx context.Context, req *blobbergrpc.CommitMetaTxnRequest) (*blobbergrpc.CommitMetaTxnResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -189,7 +190,7 @@ func (b *blobberGRPCService) CommitMetaTxn(ctx context.Context, req *blobbergrpc } func (b *blobberGRPCService) Collaborator(ctx context.Context, req *blobbergrpc.CollaboratorRequest) (*blobbergrpc.CollaboratorResponse, error) { - r, err := http.NewRequest(strings.ToUpper(req.Method), "", nil) + r, err := http.NewRequest(strings.ToUpper(req.Method), "", http.NoBody) if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index 17ab203f7..bf4df07a3 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -428,7 +428,7 @@ func RevokeShare(ctx context.Context, r *http.Request) (interface{}, error) { if clientID != allocationObj.OwnerID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } - err = reference.DeleteShareInfo(ctx, reference.ShareInfo{ + err = reference.DeleteShareInfo(ctx, &reference.ShareInfo{ ClientID: refereeClientID, FilePathHash: filePathHash, }) diff --git a/code/go/0chain.net/blobbercore/handler/handler_test.go b/code/go/0chain.net/blobbercore/handler/handler_test.go index bc7b8f1e5..d10bf853f 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/handler_test.go @@ -128,8 +128,8 @@ func setup(t *testing.T) { } } -func setupHandlers() (*mux.Router, map[string]string) { - router := mux.NewRouter() +func setupHandlers() (router *mux.Router, opMap map[string]string) { + router = mux.NewRouter() opPath := "/v1/file/objectpath/{allocation}" opName := "Object_Path" @@ -264,7 +264,7 @@ func isEndpointAllowGetReq(name string) bool { } } -func GetAuthTicketForEncryptedFile(allocationID string, remotePath string, fileHash string, clientID string, encPublicKey string) (string, error) { +func GetAuthTicketForEncryptedFile(allocationID, remotePath, fileHash, clientID, encPublicKey string) (string, error) { at := &marker.AuthTicket{} at.AllocationID = allocationID at.OwnerID = client.GetClientID() @@ -371,7 +371,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { if !isEndpointAllowGetReq(name) { method = http.MethodPost } - r, err := http.NewRequest(method, url.String(), nil) + r, err := http.NewRequest(method, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -400,7 +400,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { if !isEndpointAllowGetReq(name) { method = http.MethodPost } - r, err := http.NewRequest(method, url.String(), nil) + r, err := http.NewRequest(method, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -441,7 +441,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("path", path) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodGet, url.String(), nil) + r, err := http.NewRequest(http.MethodGet, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -501,7 +501,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("path", path) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodGet, url.String(), nil) + r, err := http.NewRequest(http.MethodGet, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -561,7 +561,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("path", path) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodPost, url.String(), nil) + r, err := http.NewRequest(http.MethodPost, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -632,7 +632,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("path", path) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodGet, url.String(), nil) + r, err := http.NewRequest(http.MethodGet, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -693,7 +693,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("collab_id", "collab id") url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodGet, url.String(), nil) + r, err := http.NewRequest(http.MethodGet, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -762,7 +762,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("connection_id", connectionID) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodPost, url.String(), nil) + r, err := http.NewRequest(http.MethodPost, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -842,7 +842,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("dest", "dest") url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodPost, url.String(), nil) + r, err := http.NewRequest(http.MethodPost, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -933,7 +933,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { q.Set("attributes", string(attrBytes)) url.RawQuery = q.Encode() - r, err := http.NewRequest(http.MethodPost, url.String(), nil) + r, err := http.NewRequest(http.MethodPost, url.String(), http.NoBody) if err != nil { t.Fatal(err) } @@ -1827,7 +1827,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { t.Fatal(err) } header := make([]byte, 2*1024) - copy(header[:], encMsg.MessageChecksum+","+encMsg.OverallChecksum) + copy(header, encMsg.MessageChecksum+","+encMsg.OverallChecksum) data := append(header, encMsg.EncryptedData...) setMockFileBlock(data) }, @@ -1966,7 +1966,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { t.Fatal(err) } header := make([]byte, 2*1024) - copy(header[:], encMsg.MessageChecksum+","+encMsg.OverallChecksum) + copy(header, encMsg.MessageChecksum+","+encMsg.OverallChecksum) data := append(header, encMsg.EncryptedData...) setMockFileBlock(data) }, @@ -2113,7 +2113,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { t.Fatal(err) } header := make([]byte, 2*1024) - copy(header[:], encMsg.MessageChecksum+","+encMsg.OverallChecksum) + copy(header, encMsg.MessageChecksum+","+encMsg.OverallChecksum) data := append(header, encMsg.EncryptedData...) setMockFileBlock(data) }, @@ -2260,7 +2260,7 @@ func TestHandlers_Requiring_Signature(t *testing.T) { t.Fatal(err) } header := make([]byte, 2*1024) - copy(header[:], encMsg.MessageChecksum+","+encMsg.OverallChecksum) + copy(header, encMsg.MessageChecksum+","+encMsg.OverallChecksum) data := append(header, encMsg.EncryptedData...) setMockFileBlock(data) }, diff --git a/code/go/0chain.net/blobbercore/handler/helper_integration_test.go b/code/go/0chain.net/blobbercore/handler/helper_integration_test.go index 0b92ca7cb..b06cc28b8 100644 --- a/code/go/0chain.net/blobbercore/handler/helper_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/helper_integration_test.go @@ -502,9 +502,9 @@ VALUES (1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','ro return nil } -func GeneratePubPrivateKey(t *testing.T) (string, string, zcncrypto.SignatureScheme) { +func GeneratePubPrivateKey(t *testing.T) (pubKey, privateKey string, signScheme zcncrypto.SignatureScheme) { - signScheme := zcncrypto.NewSignatureScheme("bls0chain") + signScheme = zcncrypto.NewSignatureScheme("bls0chain") wallet, err := signScheme.GenerateKeys() if err != nil { t.Fatal(err) diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go index dcb069c77..8103ad612 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go @@ -2,13 +2,14 @@ package handler import ( "context" + "net/http" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/convert" - "net/http" ) func (b *blobberGRPCService) UpdateObjectAttributes(ctx context.Context, req *blobbergrpc.UpdateObjectAttributesRequest) (*blobbergrpc.UpdateObjectAttributesResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -29,7 +30,7 @@ func (b *blobberGRPCService) UpdateObjectAttributes(ctx context.Context, req *bl } func (b *blobberGRPCService) CopyObject(ctx context.Context, req *blobbergrpc.CopyObjectRequest) (*blobbergrpc.CopyObjectResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } @@ -50,7 +51,7 @@ func (b *blobberGRPCService) CopyObject(ctx context.Context, req *blobbergrpc.Co } func (b *blobberGRPCService) RenameObject(ctx context.Context, req *blobbergrpc.RenameObjectRequest) (*blobbergrpc.RenameObjectResponse, error) { - r, err := http.NewRequest("POST", "", nil) + r, err := http.NewRequest("POST", "", http.NoBody) if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index d64b5c72b..5eb218d6d 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -192,7 +192,7 @@ func (fsh *StorageHandler) DownloadFile( ) // check client - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("download_file", "invalid client") } @@ -204,7 +204,7 @@ func (fsh *StorageHandler) DownloadFile( } // get and parse file params - if err = r.ParseMultipartForm(FormFileParseMaxMemory); nil != err { + if err = r.ParseMultipartForm(FormFileParseMaxMemory); err != nil { Logger.Info("download_file - request_parse_error", zap.Error(err)) return nil, common.NewErrorf("download_file", "request_parse_error: %v", err) @@ -216,7 +216,7 @@ func (fsh *StorageHandler) DownloadFile( } var blockNumStr = r.FormValue("block_num") - if len(blockNumStr) == 0 { + if blockNumStr == "" { return nil, common.NewError("download_file", "no block number") } @@ -227,7 +227,7 @@ func (fsh *StorageHandler) DownloadFile( } var numBlocksStr = r.FormValue("num_blocks") - if len(numBlocksStr) == 0 { + if numBlocksStr == "" { numBlocksStr = "1" } @@ -333,10 +333,8 @@ func (fsh *StorageHandler) DownloadFile( if fileAttrs, err := fileref.GetAttributes(); err != nil { return nil, common.NewErrorf("download_file", "error getting file attributes: %v", err) - } else { - if fileAttrs.WhoPaysForReads == common.WhoPays3rdParty { - payerID = clientID - } + } else if fileAttrs.WhoPaysForReads == common.WhoPays3rdParty { + payerID = clientID } } @@ -514,7 +512,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b allocationID := allocationObj.ID connectionID := r.FormValue("connection_id") - if len(connectionID) == 0 { + if connectionID == "" { return nil, common.NewError("invalid_parameters", "Invalid connection id passed") } @@ -534,21 +532,23 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b var isCollaborator bool for _, change := range connectionObj.Changes { - if change.Operation == constants.FileOperationUpdate { - updateFileChange := new(allocation.UpdateFileChanger) - if err := updateFileChange.Unmarshal(change.Input); err != nil { - return nil, err - } - fileRef, err := reference.GetReference(ctx, allocationID, updateFileChange.Path) - if err != nil { - return nil, err - } - isCollaborator = reference.IsACollaborator(ctx, fileRef.ID, clientID) - break + if change.Operation != constants.FileOperationUpdate { + continue + } + + updateFileChange := new(allocation.UpdateFileChanger) + if err := updateFileChange.Unmarshal(change.Input); err != nil { + return nil, err + } + fileRef, err := reference.GetReference(ctx, allocationID, updateFileChange.Path) + if err != nil { + return nil, err } + isCollaborator = reference.IsACollaborator(ctx, fileRef.ID, clientID) + break } - if len(clientID) == 0 || len(clientKey) == 0 { + if clientID == "" || clientKey == "" { return nil, common.NewError("invalid_params", "Please provide clientID and clientKey") } @@ -556,7 +556,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } - if err = r.ParseMultipartForm(FormFileParseMaxMemory); nil != err { + if err = r.ParseMultipartForm(FormFileParseMaxMemory); err != nil { Logger.Info("Error Parsing the request", zap.Any("error", err)) return nil, common.NewError("request_parse_error", err.Error()) } @@ -577,7 +577,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b var result blobberhttp.CommitResult var latestWM *writemarker.WriteMarkerEntity - if len(allocationObj.AllocationRoot) == 0 { + if allocationObj.AllocationRoot == "" { latestWM = nil } else { latestWM, err = writemarker.GetWriteMarkerEntity(ctx, @@ -607,7 +607,7 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*b clientIDForWriteRedeem = allocationObj.OwnerID } - if err = writePreRedeem(ctx, allocationObj, &writeMarker, clientIDForWriteRedeem); err != nil { + if err := writePreRedeem(ctx, allocationObj, &writeMarker, clientIDForWriteRedeem); err != nil { return nil, err } @@ -689,12 +689,12 @@ func (fsh *StorageHandler) RenameObject(ctx context.Context, r *http.Request) (i return nil, common.NewError("invalid_signature", "Invalid signature") } - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Invalid client") } new_name := r.FormValue("new_name") - if len(new_name) == 0 { + if new_name == "" { return nil, common.NewError("invalid_parameters", "Invalid name") } @@ -703,12 +703,12 @@ func (fsh *StorageHandler) RenameObject(ctx context.Context, r *http.Request) (i return nil, err } - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } connectionID := r.FormValue("connection_id") - if len(connectionID) == 0 { + if connectionID == "" { return nil, common.NewError("invalid_parameters", "Invalid connection id passed") } @@ -886,12 +886,12 @@ func (fsh *StorageHandler) CopyObject(ctx context.Context, r *http.Request) (int allocationID := allocationObj.ID - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Invalid client") } destPath := r.FormValue("dest") - if len(destPath) == 0 { + if destPath == "" { return nil, common.NewError("invalid_parameters", "Invalid destination for operation") } @@ -900,12 +900,12 @@ func (fsh *StorageHandler) CopyObject(ctx context.Context, r *http.Request) (int return nil, err } - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } connectionID := r.FormValue("connection_id") - if len(connectionID) == 0 { + if connectionID == "" { return nil, common.NewError("invalid_parameters", "Invalid connection id passed") } @@ -956,7 +956,7 @@ func (fsh *StorageHandler) CopyObject(ctx context.Context, r *http.Request) (int func (fsh *StorageHandler) DeleteFile(ctx context.Context, r *http.Request, connectionObj *allocation.AllocationChangeCollector) (*blobberhttp.UploadResult, error) { path := r.FormValue("path") - if len(path) == 0 { + if path == "" { return nil, common.NewError("invalid_parameters", "Invalid path") } @@ -1004,12 +1004,12 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*blo allocationID := allocationObj.ID - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation") } dirPath := r.FormValue("dir_path") - if len(dirPath) == 0 { + if dirPath == "" { return nil, common.NewError("invalid_parameters", "Invalid dir path passed") } @@ -1023,7 +1023,7 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*blo } connectionID := r.FormValue("connection_id") - if len(connectionID) == 0 { + if connectionID == "" { return nil, common.NewError("invalid_parameters", "Invalid connection id passed") } @@ -1100,7 +1100,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*blo return nil, common.NewError("immutable_allocation", "Cannot write to an immutable allocation") } - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner or the payer of the allocation") } @@ -1110,7 +1110,7 @@ func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*blo } connectionID := r.FormValue("connection_id") - if len(connectionID) == 0 { + if connectionID == "" { return nil, common.NewError("invalid_parameters", "Invalid connection id passed") } diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 73e4cbe6c..302f3d4c3 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -29,7 +29,7 @@ type WalletCallback struct { err string } -func (wb *WalletCallback) OnWalletCreateComplete(status int, wallet string, err string) { +func (wb *WalletCallback) OnWalletCreateComplete(status int, wallet, err string) { wb.err = err wb.wg.Done() } diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 5bae8d1a0..1e8980d5c 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -39,7 +39,7 @@ type StorageHandler struct{} func (fsh *StorageHandler) verifyAllocation(ctx context.Context, tx string, readonly bool) (alloc *allocation.Allocation, err error) { - if len(tx) == 0 { + if tx == "" { return nil, common.NewError("verify_allocation", "invalid allocation id") } @@ -69,7 +69,7 @@ func (fsh *StorageHandler) convertGormError(err error) error { } func (fsh *StorageHandler) verifyAuthTicket(ctx context.Context, authTokenString string, allocationObj *allocation.Allocation, refRequested *reference.Ref, clientID string) (bool, error) { - if len(authTokenString) == 0 { + if authTokenString == "" { return false, common.NewError("invalid_parameters", "Auth ticket required if data read by anyone other than owner.") } authToken := &readmarker.AuthTicket{} @@ -135,7 +135,7 @@ func (fsh *StorageHandler) GetAllocationUpdateTicket(ctx context.Context, r *htt return allocationObj, nil } -func (fsh *StorageHandler) checkIfFileAlreadyExists(ctx context.Context, allocationID string, path string) *reference.Ref { +func (fsh *StorageHandler) checkIfFileAlreadyExists(ctx context.Context, allocationID, path string) *reference.Ref { fileReference, err := reference.GetReference(ctx, allocationID, path) if err != nil { return nil @@ -156,7 +156,7 @@ func (fsh *StorageHandler) GetFileMeta(ctx context.Context, r *http.Request) (in allocationID := alloc.ID clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -234,7 +234,7 @@ func (fsh *StorageHandler) AddCommitMetaTxn(ctx context.Context, r *http.Request allocationID := allocationObj.ID clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -267,7 +267,7 @@ func (fsh *StorageHandler) AddCommitMetaTxn(ctx context.Context, r *http.Request } txnID := r.FormValue("txn_id") - if len(txnID) == 0 { + if txnID == "" { return nil, common.NewError("invalid_parameter", "TxnID not present in the params") } @@ -317,7 +317,7 @@ func (fsh *StorageHandler) AddCollaborator(ctx context.Context, r *http.Request) } collabClientID := r.FormValue("collab_id") - if len(collabClientID) == 0 { + if collabClientID == "" { return nil, common.NewError("invalid_parameter", "collab_id not present in the params") } @@ -327,7 +327,7 @@ func (fsh *StorageHandler) AddCollaborator(ctx context.Context, r *http.Request) switch r.Method { case http.MethodPost: - if len(clientID) == 0 || clientID != allocationObj.OwnerID { + if clientID == "" || clientID != allocationObj.OwnerID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -351,7 +351,7 @@ func (fsh *StorageHandler) AddCollaborator(ctx context.Context, r *http.Request) return collaborators, nil case http.MethodDelete: - if len(clientID) == 0 || clientID != allocationObj.OwnerID { + if clientID == "" || clientID != allocationObj.OwnerID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -386,7 +386,7 @@ func (fsh *StorageHandler) GetFileStats(ctx context.Context, r *http.Request) (i } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -414,7 +414,7 @@ func (fsh *StorageHandler) GetFileStats(ctx context.Context, r *http.Request) (i } var statsMap map[string]interface{} statsBytes, _ := json.Marshal(fileStats) - if err = json.Unmarshal(statsBytes, &statsMap); err != nil { + if err := json.Unmarshal(statsBytes, &statsMap); err != nil { return nil, err } for k, v := range statsMap { @@ -433,7 +433,7 @@ func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (* } allocationID := allocationObj.ID - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -551,7 +551,7 @@ func (fsh *StorageHandler) getReferencePath(ctx context.Context, r *http.Request } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 { + if clientID == "" { errCh <- common.NewError("invalid_operation", "Please pass clientID in the header") return } @@ -588,7 +588,7 @@ func (fsh *StorageHandler) getReferencePath(ctx context.Context, r *http.Request } var latestWM *writemarker.WriteMarkerEntity - if len(allocationObj.AllocationRoot) == 0 { + if allocationObj.AllocationRoot == "" { latestWM = nil } else { latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot) @@ -624,16 +624,16 @@ func (fsh *StorageHandler) GetObjectPath(ctx context.Context, r *http.Request) ( } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } path := r.FormValue("path") - if len(path) == 0 { + if path == "" { return nil, common.NewError("invalid_parameters", "Invalid path") } blockNumStr := r.FormValue("block_num") - if len(blockNumStr) == 0 { + if blockNumStr == "" { return nil, common.NewError("invalid_parameters", "Invalid path") } @@ -648,7 +648,7 @@ func (fsh *StorageHandler) GetObjectPath(ctx context.Context, r *http.Request) ( } var latestWM *writemarker.WriteMarkerEntity - if len(allocationObj.AllocationRoot) == 0 { + if allocationObj.AllocationRoot == "" { latestWM = nil } else { latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot) @@ -683,11 +683,11 @@ func (fsh *StorageHandler) GetObjectTree(ctx context.Context, r *http.Request) ( } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } path := r.FormValue("path") - if len(path) == 0 { + if path == "" { return nil, common.NewError("invalid_parameters", "Invalid path") } @@ -715,7 +715,7 @@ func (fsh *StorageHandler) GetObjectTree(ctx context.Context, r *http.Request) ( } var latestWM *writemarker.WriteMarkerEntity - if len(allocationObj.AllocationRoot) == 0 { + if allocationObj.AllocationRoot == "" { latestWM = nil } else { latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot) @@ -743,7 +743,7 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 { + if clientID == "" { return nil, common.NewError("invalid_operation", "Client id is required") } @@ -865,7 +865,7 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb fileType := r.FormValue("fileType") levelStr := r.FormValue("level") var level int - if len(levelStr) != 0 { + if levelStr != "" { level, err = strconv.Atoi(levelStr) if err != nil { return nil, common.NewError("invalid_parameters", err.Error()) @@ -899,7 +899,7 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb return nil, err } var latestWM *writemarker.WriteMarkerEntity - if len(allocationObj.AllocationRoot) == 0 { + if allocationObj.AllocationRoot == "" { latestWM = nil } else { latestWM, err = writemarker.GetWriteMarkerEntity(ctx, allocationObj.AllocationRoot) @@ -933,7 +933,7 @@ func (fsh *StorageHandler) CalculateHash(ctx context.Context, r *http.Request) ( allocationID := allocationObj.ID clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || allocationObj.OwnerID != clientID { + if clientID == "" || allocationObj.OwnerID != clientID { return nil, common.NewError("invalid_operation", "Operation needs to be performed by the owner of the allocation") } @@ -957,14 +957,14 @@ func (fsh *StorageHandler) CalculateHash(ctx context.Context, r *http.Request) ( } // verifySignatureFromRequest verifies signature passed as common.ClientSignatureHeader header. -func verifySignatureFromRequest(allocation, sign, pbK string) (bool, error) { +func verifySignatureFromRequest(alloc, sign, pbK string) (bool, error) { sign = encryption.MiraclToHerumiSig(sign) if len(sign) < 64 { return false, nil } - hash := encryption.Hash(allocation) + hash := encryption.Hash(alloc) return encryption.Verify(pbK, sign, hash) } @@ -977,8 +977,8 @@ func pathsFromReq(r *http.Request) ([]string, error) { paths = make([]string, 0) ) - if len(pathsStr) == 0 { - if len(path) == 0 { + if pathsStr == "" { + if path == "" { return nil, common.NewError("invalid_parameters", "Invalid path") } @@ -997,8 +997,8 @@ func pathHashFromReq(r *http.Request, allocationID string) (string, error) { pathHash = r.FormValue("path_hash") path = r.FormValue("path") ) - if len(pathHash) == 0 { - if len(path) == 0 { + if pathHash == "" { + if path == "" { return "", common.NewError("invalid_parameters", "Invalid path") } pathHash = reference.GetReferenceLookup(allocationID, path) @@ -1007,13 +1007,12 @@ func pathHashFromReq(r *http.Request, allocationID string) (string, error) { return pathHash, nil } -func getPathHash(r *http.Request, allocationID string) (string, string, error) { - var ( - pathHash = r.FormValue("path_hash") - path = r.FormValue("path") - ) - if len(pathHash) == 0 { - if len(path) == 0 { +func getPathHash(r *http.Request, allocationID string) (pathHash, path string, err error) { + pathHash = r.FormValue("path_hash") + path = r.FormValue("path") + + if pathHash == "" { + if path == "" { return "", "", common.NewError("invalid_parameters", "Invalid path") } pathHash = reference.GetReferenceLookup(allocationID, path) diff --git a/code/go/0chain.net/blobbercore/handler/worker.go b/code/go/0chain.net/blobbercore/handler/worker.go index 3aa705f1d..4b27f760d 100644 --- a/code/go/0chain.net/blobbercore/handler/worker.go +++ b/code/go/0chain.net/blobbercore/handler/worker.go @@ -103,7 +103,7 @@ func startCleanupTempFiles(ctx context.Context) { } } -func moveColdDataToCloud(ctx context.Context, coldStorageMinFileSize int64, limit int64) { +func moveColdDataToCloud(ctx context.Context, coldStorageMinFileSize, limit int64) { defer func() { if r := recover(); r != nil { Logger.Error("[recover] moveColdDataToCloud", zap.Any("err", r)) @@ -153,7 +153,7 @@ func moveColdDataToCloud(ctx context.Context, coldStorageMinFileSize int64, limi moveFileToCloud(ctx, fileRef) } } - offset = offset + limit + offset += limit } db.Commit() rctx.Done() diff --git a/code/go/0chain.net/blobbercore/handler/zcncore.go b/code/go/0chain.net/blobbercore/handler/zcncore.go index dbdbbf09a..e1bb3a7c8 100644 --- a/code/go/0chain.net/blobbercore/handler/zcncore.go +++ b/code/go/0chain.net/blobbercore/handler/zcncore.go @@ -25,7 +25,7 @@ func (zcn *ZCNStatus) OnBalanceAvailable(status int, value int64, info string) { zcn.balance = value } -func (zcn *ZCNStatus) OnInfoAvailable(op int, status int, info string, err string) { +func (zcn *ZCNStatus) OnInfoAvailable(op, status int, info, err string) { defer zcn.wg.Done() if status == zcncore.StatusSuccess { zcn.success = true diff --git a/code/go/0chain.net/blobbercore/readmarker/entity.go b/code/go/0chain.net/blobbercore/readmarker/entity.go index 8f3d516ec..ee96680dd 100644 --- a/code/go/0chain.net/blobbercore/readmarker/entity.go +++ b/code/go/0chain.net/blobbercore/readmarker/entity.go @@ -191,7 +191,7 @@ func (rm *ReadMarkerEntity) UpdateStatus(ctx context.Context, return common.NewErrorf("rme_update_status", "marshaling latest RM: %v", err) } - if len(latestRMBytes) == 0 || string(latestRMBytes) == "" { + if len(latestRMBytes) == 0 { latestRMBytes = []byte("{}") } rmUpdates["latest_redeemed_rm"] = latestRMBytes diff --git a/code/go/0chain.net/blobbercore/readmarker/protocol.go b/code/go/0chain.net/blobbercore/readmarker/protocol.go index 87795e6c1..e5bc90bdd 100644 --- a/code/go/0chain.net/blobbercore/readmarker/protocol.go +++ b/code/go/0chain.net/blobbercore/readmarker/protocol.go @@ -36,12 +36,12 @@ func (rm *ReadMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.All } clientPublicKey := ctx.Value(constants.ContextKeyClientKey).(string) - if len(clientPublicKey) == 0 || clientPublicKey != rm.LatestRM.ClientPublicKey { + if clientPublicKey == "" || clientPublicKey != rm.LatestRM.ClientPublicKey { return common.NewError("read_marker_validation_failed", "Could not get the public key of the client") } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || clientID != rm.LatestRM.ClientID { + if clientID == "" || clientID != rm.LatestRM.ClientID { return common.NewError("read_marker_validation_failed", "Read Marker clientID does not match request clientID") } currentTS := common.Now() diff --git a/code/go/0chain.net/blobbercore/reference/object.go b/code/go/0chain.net/blobbercore/reference/object.go index 2cae89491..e538e020c 100644 --- a/code/go/0chain.net/blobbercore/reference/object.go +++ b/code/go/0chain.net/blobbercore/reference/object.go @@ -65,7 +65,7 @@ func LoadObjectTree(ctx context.Context, allocationID, path string) (*Ref, error } // DeleteObject delete object from tree, and return tree root and deleted content hash list -func DeleteObject(ctx context.Context, allocationID string, path string) (*Ref, map[string]bool, error) { +func DeleteObject(ctx context.Context, allocationID, path string) (*Ref, map[string]bool, error) { rootRef, err := LoadObjectTree(ctx, allocationID, "/") if err != nil { diff --git a/code/go/0chain.net/blobbercore/reference/objectpath.go b/code/go/0chain.net/blobbercore/reference/objectpath.go index 84d449131..a4193a750 100644 --- a/code/go/0chain.net/blobbercore/reference/objectpath.go +++ b/code/go/0chain.net/blobbercore/reference/objectpath.go @@ -60,7 +60,7 @@ func GetObjectPath(ctx context.Context, allocationID string, blockNum int64) (*O for idx, child := range curRef.Children { if child.NumBlocks < remainingBlocks { - remainingBlocks = remainingBlocks - child.NumBlocks + remainingBlocks -= child.NumBlocks continue } if child.Type == FILE { @@ -69,7 +69,7 @@ func GetObjectPath(ctx context.Context, allocationID string, blockNum int64) (*O break } curRef, err = GetRefWithSortedChildren(ctx, allocationID, child.Path) - if err != nil || len(curRef.Hash) == 0 { + if err != nil || curRef.Hash == "" { return nil, common.NewError("failed_object_path", "Failed to get the object path") } curResult = list[idx] diff --git a/code/go/0chain.net/blobbercore/reference/ref.go b/code/go/0chain.net/blobbercore/reference/ref.go index 078153fb1..970e1fd52 100644 --- a/code/go/0chain.net/blobbercore/reference/ref.go +++ b/code/go/0chain.net/blobbercore/reference/ref.go @@ -136,7 +136,7 @@ func (Ref) TableName() string { } // GetReferenceLookup hash(allocationID + ":" + path) -func GetReferenceLookup(allocationID string, path string) string { +func GetReferenceLookup(allocationID, path string) string { return encryption.Hash(allocationID + ":" + path) } @@ -174,7 +174,7 @@ func (r *Ref) SetAttributes(attr *Attributes) (err error) { } // Mkdir create dirs if they don't exits. do nothing if dir exists. last dir will be return without child -func Mkdir(ctx context.Context, allocationID string, destpath string) (*Ref, error) { +func Mkdir(ctx context.Context, allocationID, destpath string) (*Ref, error) { var dirRef *Ref db := datastore.GetStore().GetTransaction(ctx) // cleaning path to avoid edge case issues: append '/' prefix if not added and removing suffix '/' if added @@ -216,7 +216,7 @@ func Mkdir(ctx context.Context, allocationID string, destpath string) (*Ref, err } // GetReference get FileRef with allcationID and path from postgres -func GetReference(ctx context.Context, allocationID string, path string) (*Ref, error) { +func GetReference(ctx context.Context, allocationID, path string) (*Ref, error) { ref := &Ref{} db := datastore.GetStore().GetTransaction(ctx) err := db.Where(&Ref{AllocationID: allocationID, Path: path}).First(ref).Error @@ -226,7 +226,7 @@ func GetReference(ctx context.Context, allocationID string, path string) (*Ref, return nil, err } -func GetReferenceFromLookupHash(ctx context.Context, allocationID string, path_hash string) (*Ref, error) { +func GetReferenceFromLookupHash(ctx context.Context, allocationID, path_hash string) (*Ref, error) { ref := &Ref{} db := datastore.GetStore().GetTransaction(ctx) err := db.Where(&Ref{AllocationID: allocationID, LookupHash: path_hash}).First(ref).Error @@ -252,7 +252,7 @@ func GetSubDirsFromPath(p string) []string { return subDirs } -func GetRefWithChildren(ctx context.Context, allocationID string, path string) (*Ref, error) { +func GetRefWithChildren(ctx context.Context, allocationID, path string) (*Ref, error) { var refs []Ref db := datastore.GetStore().GetTransaction(ctx) db = db.Where(Ref{ParentPath: path, AllocationID: allocationID}).Or(Ref{Type: DIRECTORY, Path: path, AllocationID: allocationID}) @@ -277,7 +277,7 @@ func GetRefWithChildren(ctx context.Context, allocationID string, path string) ( return &refs[0], nil } -func GetRefWithSortedChildren(ctx context.Context, allocationID string, path string) (*Ref, error) { +func GetRefWithSortedChildren(ctx context.Context, allocationID, path string) (*Ref, error) { var refs []*Ref db := datastore.GetStore().GetTransaction(ctx) db = db.Where(Ref{ParentPath: path, AllocationID: allocationID}).Or(Ref{Type: DIRECTORY, Path: path, AllocationID: allocationID}) @@ -307,17 +307,19 @@ func (fr *Ref) GetFileHashData() string { fr.Attributes = datatypes.JSON("{}") } hashArray := make([]string, 0, 11) - hashArray = append(hashArray, fr.AllocationID) - hashArray = append(hashArray, fr.Type) - hashArray = append(hashArray, fr.Name) - hashArray = append(hashArray, fr.Path) - hashArray = append(hashArray, strconv.FormatInt(fr.Size, 10)) - hashArray = append(hashArray, fr.ContentHash) - hashArray = append(hashArray, fr.MerkleRoot) - hashArray = append(hashArray, strconv.FormatInt(fr.ActualFileSize, 10)) - hashArray = append(hashArray, fr.ActualFileHash) - hashArray = append(hashArray, string(fr.Attributes)) - hashArray = append(hashArray, strconv.FormatInt(fr.ChunkSize, 10)) + hashArray = append(hashArray, + fr.AllocationID, + fr.Type, + fr.Name, + fr.Path, + strconv.FormatInt(fr.Size, 10), + fr.ContentHash, + fr.MerkleRoot, + strconv.FormatInt(fr.ActualFileSize, 10), + fr.ActualFileHash, + string(fr.Attributes), + strconv.FormatInt(fr.ChunkSize, 10), + ) return strings.Join(hashArray, ":") } @@ -406,7 +408,7 @@ func (r *Ref) RemoveChild(idx int) { r.childrenLoaded = true } -func (r *Ref) UpdatePath(newPath string, parentPath string) { +func (r *Ref) UpdatePath(newPath, parentPath string) { r.Path = newPath r.ParentPath = parentPath r.PathLevel = len(GetSubDirsFromPath(r.Path)) + 1 //strings.Count(r.Path, "/") diff --git a/code/go/0chain.net/blobbercore/reference/referencepath.go b/code/go/0chain.net/blobbercore/reference/referencepath.go index 1e1580dd4..1816859c8 100644 --- a/code/go/0chain.net/blobbercore/reference/referencepath.go +++ b/code/go/0chain.net/blobbercore/reference/referencepath.go @@ -18,7 +18,7 @@ type ReferencePath struct { Ref *Ref } -func GetReferencePath(ctx context.Context, allocationID string, path string) (*Ref, error) { +func GetReferencePath(ctx context.Context, allocationID, path string) (*Ref, error) { return GetReferencePathFromPaths(ctx, allocationID, []string{path}) } @@ -80,7 +80,7 @@ func GetReferencePathFromPaths(ctx context.Context, allocationID string, paths [ return &refs[0], nil } -func PathExists(ctx context.Context, allocationID string, path string) (bool, error) { +func PathExists(ctx context.Context, allocationID, path string) (bool, error) { path = filepath.Clean(path) if path == "." || path == "/" { @@ -100,7 +100,7 @@ func PathExists(ctx context.Context, allocationID string, path string) (bool, er return true, nil } -func GetObjectTree(ctx context.Context, allocationID string, path string) (*Ref, error) { +func GetObjectTree(ctx context.Context, allocationID, path string) (*Ref, error) { path = filepath.Clean(path) var refs []Ref db := datastore.GetStore().GetTransaction(ctx) diff --git a/code/go/0chain.net/blobbercore/reference/shareinfo.go b/code/go/0chain.net/blobbercore/reference/shareinfo.go index 1caafae55..49e9cffea 100644 --- a/code/go/0chain.net/blobbercore/reference/shareinfo.go +++ b/code/go/0chain.net/blobbercore/reference/shareinfo.go @@ -28,7 +28,7 @@ func AddShareInfo(ctx context.Context, shareInfo ShareInfo) error { return db.Table(TableName()).Create(shareInfo).Error } -func DeleteShareInfo(ctx context.Context, shareInfo ShareInfo) error { +func DeleteShareInfo(ctx context.Context, shareInfo *ShareInfo) error { db := datastore.GetStore().GetTransaction(ctx) result := db.Table(TableName()). @@ -64,7 +64,7 @@ func UpdateShareInfo(ctx context.Context, shareInfo ShareInfo) error { Error } -func GetShareInfo(ctx context.Context, clientID string, filePathHash string) (*ShareInfo, error) { +func GetShareInfo(ctx context.Context, clientID, filePathHash string) (*ShareInfo, error) { db := datastore.GetStore().GetTransaction(ctx) shareInfo := &ShareInfo{} err := db.Table(TableName()). diff --git a/code/go/0chain.net/blobbercore/stats/challengestats.go b/code/go/0chain.net/blobbercore/stats/challengestats.go index 18c1f926b..98b2127be 100644 --- a/code/go/0chain.net/blobbercore/stats/challengestats.go +++ b/code/go/0chain.net/blobbercore/stats/challengestats.go @@ -1,16 +1,13 @@ package stats import ( + "time" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference" "gorm.io/datatypes" - "time" ) -func (ChallengeEntity) TableName() string { - return "challenges" -} - type ChallengeEntity struct { ChallengeID string `json:"id" gorm:"column:challenge_id;primary_key"` PrevChallengeID string `json:"prev_id" gorm:"column:prev_challenge_id"` @@ -34,6 +31,9 @@ type ChallengeEntity struct { UpdatedAt time.Time `gorm:"updated_at"` } +func (ChallengeEntity) TableName() string { + return "challenges" +} func getAllFailedChallenges(offset, limit int) ([]ChallengeEntity, int, error) { db := datastore.GetStore().GetDB() crs := []ChallengeEntity{} diff --git a/code/go/0chain.net/blobbercore/stats/filestats.go b/code/go/0chain.net/blobbercore/stats/filestats.go index b6aebb826..eb17c8e15 100644 --- a/code/go/0chain.net/blobbercore/stats/filestats.go +++ b/code/go/0chain.net/blobbercore/stats/filestats.go @@ -2,6 +2,7 @@ package stats import ( "context" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore" "gorm.io/gorm" ) @@ -16,8 +17,6 @@ type FileStats struct { LastChallengeResponseTxn string `gorm:"column:last_challenge_txn" json:"last_challenge_txn"` WriteMarkerRedeemTxn string `gorm:"-" json:"write_marker_txn"` datastore.ModelWithTS - - //NumBlockWrites int64 `gorm:"column:num_of_block_writes" json:"num_of_block_writes"` } func (FileStats) TableName() string { diff --git a/code/go/0chain.net/blobbercore/stats/handler.go b/code/go/0chain.net/blobbercore/stats/handler.go index 3ca5e9912..f4e7e263a 100644 --- a/code/go/0chain.net/blobbercore/stats/handler.go +++ b/code/go/0chain.net/blobbercore/stats/handler.go @@ -3,14 +3,15 @@ package stats import ( "context" "fmt" + "html/template" + "net/http" + "time" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore" "github.com/0chain/blobber/code/go/0chain.net/core/common" . "github.com/0chain/blobber/code/go/0chain.net/core/logging" "github.com/0chain/gosdk/constants" "go.uber.org/zap" - "html/template" - "net/http" - "time" ) func byteCountIEC(b int64) string { @@ -35,12 +36,8 @@ var funcMap = template.FuncMap{ "read_size": func(readCount int64) string { return byteCountIEC(readCount * readBlockSize) }, - "write_size": func(readCount int64) string { - return byteCountIEC(readCount) - }, - "byte_count_in_string": func(byteValue int64) string { - return byteCountIEC(byteValue) - }, + "write_size": byteCountIEC, + "byte_count_in_string": byteCountIEC, "time_in_string": func(timeValue time.Time) string { if timeValue.IsZero() { return "-" @@ -499,7 +496,7 @@ func GetStatsHandler(ctx context.Context, r *http.Request) (interface{}, error) defer db.Rollback() allocationID := ctx.Value(constants.ContextKeyAllocation).(string) bs := &BlobberStats{} - if len(allocationID) != 0 { + if allocationID != "" { // TODO: Get only the allocation info from DB bs.loadDetailedStats(ctx) for _, allocStat := range bs.AllocationStats { @@ -510,7 +507,7 @@ func GetStatsHandler(ctx context.Context, r *http.Request) (interface{}, error) return nil, common.NewError("allocation_stats_not_found", "Stats for allocation not found") } allocations := q.Get("allocations") - if len(allocations) != 0 { + if allocations != "" { return loadAllocationList(ctx) } bs.loadBasicStats(ctx) diff --git a/code/go/0chain.net/blobbercore/stats/pagination.go b/code/go/0chain.net/blobbercore/stats/pagination.go index fce3cadcf..a7a78954f 100644 --- a/code/go/0chain.net/blobbercore/stats/pagination.go +++ b/code/go/0chain.net/blobbercore/stats/pagination.go @@ -72,7 +72,7 @@ func GeneratePagination(page, limit, offset, totalItems int) *Pagination { p.TotalPages = totalItems / limit if totalItems%limit > 0 { - p.TotalPages = p.TotalPages + 1 + p.TotalPages++ } if p.TotalPages > p.CurrentPage { diff --git a/code/go/0chain.net/blobbercore/util/json.go b/code/go/0chain.net/blobbercore/util/json.go index 672eddfca..dbfce39ac 100644 --- a/code/go/0chain.net/blobbercore/util/json.go +++ b/code/go/0chain.net/blobbercore/util/json.go @@ -2,9 +2,10 @@ package util import ( "fmt" - "github.com/0chain/gosdk/zboxcore/fileref" "reflect" "strings" + + "github.com/0chain/gosdk/zboxcore/fileref" ) // Validate unmarshalled data with tag-based rules @@ -27,12 +28,12 @@ func UnmarshalValidation(v interface{}) error { return nil } -func GetParentPathHashes(allocationTx string, filePath string) []string { +func GetParentPathHashes(allocationTx, filePath string) []string { splitted := strings.Split(filePath, "/") pathHashes := []string{} for i := 0; i < len(splitted); i++ { - path := strings.Join(splitted[:len(splitted) - i], "/") + path := strings.Join(splitted[:len(splitted)-i], "/") if path == "" { path = "/" } diff --git a/code/go/0chain.net/blobbercore/writemarker/entity.go b/code/go/0chain.net/blobbercore/writemarker/entity.go index 52e4b10bb..38dceef0c 100644 --- a/code/go/0chain.net/blobbercore/writemarker/entity.go +++ b/code/go/0chain.net/blobbercore/writemarker/entity.go @@ -109,7 +109,7 @@ func GetWriteMarkerEntity(ctx context.Context, allocation_root string) (*WriteMa return wm, nil } -func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAllocationRoot string, endAllocationRoot string) ([]*WriteMarkerEntity, error) { +func GetWriteMarkersInRange(ctx context.Context, allocationID, startAllocationRoot, endAllocationRoot string) ([]*WriteMarkerEntity, error) { db := datastore.GetStore().GetTransaction(ctx) var seqRange []int64 err := db.Table((WriteMarkerEntity{}).TableName()). diff --git a/code/go/0chain.net/blobbercore/writemarker/protocol.go b/code/go/0chain.net/blobbercore/writemarker/protocol.go index cdad31027..e08b3e232 100644 --- a/code/go/0chain.net/blobbercore/writemarker/protocol.go +++ b/code/go/0chain.net/blobbercore/writemarker/protocol.go @@ -50,12 +50,12 @@ func (wm *WriteMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.Al } clientPublicKey := ctx.Value(constants.ContextKeyClientKey).(string) - if len(clientPublicKey) == 0 { + if clientPublicKey == "" { return common.NewError("write_marker_validation_failed", "Could not get the public key of the client") } clientID := ctx.Value(constants.ContextKeyClient).(string) - if len(clientID) == 0 || clientID != wm.WM.ClientID || clientID != co.ClientID || co.ClientID != wm.WM.ClientID { + if clientID == "" || clientID != wm.WM.ClientID || clientID != co.ClientID || co.ClientID != wm.WM.ClientID { return common.NewError("write_marker_validation_failed", "Write Marker is not by the same client who uploaded") } diff --git a/code/go/0chain.net/blobbercore/writemarker/worker.go b/code/go/0chain.net/blobbercore/writemarker/worker.go index 09fb734f4..9d2a73b74 100644 --- a/code/go/0chain.net/blobbercore/writemarker/worker.go +++ b/code/go/0chain.net/blobbercore/writemarker/worker.go @@ -41,7 +41,7 @@ func RedeemMarkersForAllocation(ctx context.Context, allocationObj *allocation.A if wm.WM.PreviousAllocationRoot == allocationObj.LatestRedeemedWM && !startredeem { startredeem = true } - if startredeem || len(allocationObj.LatestRedeemedWM) == 0 { + if startredeem || allocationObj.LatestRedeemedWM == "" { err := wm.RedeemMarker(rctx) if err != nil { Logger.Error("Error redeeming the write marker.", zap.Any("wm", wm.WM.AllocationID), zap.Any("error", err)) @@ -61,7 +61,6 @@ func RedeemMarkersForAllocation(ctx context.Context, allocationObj *allocation.A Where("allocation_root = ? AND allocation_root = latest_redeemed_write_marker", allocationObj.AllocationRoot). Update("is_redeem_required", false) } - //Logger.Info("Returning from redeem", zap.Any("wm", latestWmEntity), zap.Any("allocation", allocationID)) return nil } diff --git a/code/go/0chain.net/core/build/info.go b/code/go/0chain.net/core/build/info.go index 6bbd32618..15cc3cc04 100644 --- a/code/go/0chain.net/core/build/info.go +++ b/code/go/0chain.net/core/build/info.go @@ -1,4 +1,4 @@ package build -//BuildTag - the git commit for the build +// BuildTag - the git commit for the build var BuildTag string diff --git a/code/go/0chain.net/core/cache/lfu.go b/code/go/0chain.net/core/cache/lfu.go index 5ac53d31f..b5c91a1cf 100644 --- a/code/go/0chain.net/core/cache/lfu.go +++ b/code/go/0chain.net/core/cache/lfu.go @@ -8,19 +8,19 @@ type LFU struct { Cache cache.Cache } -//NewLFUCache - create a new LFU cache object +// NewLFUCache - create a new LFU cache object func NewLFUCache(size int) *LFU { c := &LFU{} c.Cache = cache.NewLFU(size) return c } -//Add - add a given key and value +// Add - add a given key and value func (c *LFU) Add(key string, value interface{}) error { return c.Cache.Set(key, value) } -//Get - get the value associated with the key +// Get - get the value associated with the key func (c *LFU) Get(key string) (interface{}, error) { value, err := c.Cache.Get(key) if err != nil { diff --git a/code/go/0chain.net/core/cache/lru.go b/code/go/0chain.net/core/cache/lru.go index 31c650b3a..53dd1e630 100644 --- a/code/go/0chain.net/core/cache/lru.go +++ b/code/go/0chain.net/core/cache/lru.go @@ -4,24 +4,24 @@ import ( lru "github.com/koding/cache" ) -//LRU - LRU cache +// LRU - LRU cache type LRU struct { Cache lru.Cache } -//NewLRUCache - create a new LRU cache +// NewLRUCache - create a new LRU cache func NewLRUCache(size int) *LRU { c := &LRU{} c.Cache = lru.NewLRU(size) return c } -//Add - add a key and a value +// Add - add a key and a value func (c *LRU) Add(key string, value interface{}) error { return c.Cache.Set(key, value) } -//Get - get the value associated with the key +// Get - get the value associated with the key func (c *LRU) Get(key string) (interface{}, error) { value, err := c.Cache.Get(key) if err != nil { diff --git a/code/go/0chain.net/core/common/context.go b/code/go/0chain.net/core/common/context.go index 8d69fdcba..d7bf5a520 100644 --- a/code/go/0chain.net/core/common/context.go +++ b/code/go/0chain.net/core/common/context.go @@ -41,10 +41,10 @@ func GetRootContext() context.Context { /*Done - call this when the program needs to stop and notify all workers */ func Done() { - //Logger.Info("Initiating shutdown...") + // Logger.Info("Initiating shutdown...") rootCancel() - //TODO: How do we ensure every worker is completed any shutdown sequence before we finally shut down - //the server using server.Shutdown(ctx) + // TODO: How do we ensure every worker is completed any shutdown sequence before we finally shut down + // the server using server.Shutdown(ctx) } /*HandleShutdown - handles various shutdown signals */ diff --git a/code/go/0chain.net/core/common/errors.go b/code/go/0chain.net/core/common/errors.go index eede50d36..9f09e5b06 100644 --- a/code/go/0chain.net/core/common/errors.go +++ b/code/go/0chain.net/core/common/errors.go @@ -15,12 +15,12 @@ func (err *Error) Error() string { } /*NewError - create a new error */ -func NewError(code string, msg string) *Error { +func NewError(code, msg string) *Error { return &Error{Code: code, Msg: msg} } /*NewErrorf - create a new error with format */ -func NewErrorf(code string, format string, args ...interface{}) *Error { +func NewErrorf(code, format string, args ...interface{}) *Error { return &Error{Code: code, Msg: fmt.Sprintf(format, args...)} } diff --git a/code/go/0chain.net/core/common/handler.go b/code/go/0chain.net/core/common/handler.go index f84af02e6..7a2ee0c23 100644 --- a/code/go/0chain.net/core/common/handler.go +++ b/code/go/0chain.net/core/common/handler.go @@ -50,10 +50,8 @@ func Respond(w http.ResponseWriter, data interface{}, err error) { buf := bytes.NewBuffer(nil) json.NewEncoder(buf).Encode(data) //nolint:errcheck // checked in previous step http.Error(w, buf.String(), 400) - } else { - if data != nil { - json.NewEncoder(w).Encode(data) //nolint:errcheck // checked in previous step - } + } else if data != nil { + json.NewEncoder(w).Encode(data) //nolint:errcheck // checked in previous step } } @@ -79,16 +77,14 @@ func ToByteStream(handler JSONResponderF) ReqRespHandlerf { http.Error(w, err.Error(), 400) } - } else { - if data != nil { - rawdata, ok := data.([]byte) - if ok { - w.Header().Set("Content-Type", "application/octet-stream") - w.Write(rawdata) //nolint:errcheck - } else { - w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(data) //nolint:errcheck - } + } else if data != nil { + rawdata, ok := data.([]byte) + if ok { + w.Header().Set("Content-Type", "application/octet-stream") + w.Write(rawdata) //nolint:errcheck + } else { + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(data) //nolint:errcheck } } } diff --git a/code/go/0chain.net/core/common/time.go b/code/go/0chain.net/core/common/time.go index d35503638..0f64daf90 100644 --- a/code/go/0chain.net/core/common/time.go +++ b/code/go/0chain.net/core/common/time.go @@ -16,7 +16,7 @@ func Now() Timestamp { } /*Within ensures a given timestamp is within certain number of seconds */ -func Within(ts int64, seconds int64) bool { +func Within(ts, seconds int64) bool { now := time.Now().Unix() return now > ts-seconds && now < ts+seconds } diff --git a/code/go/0chain.net/core/common/utils.go b/code/go/0chain.net/core/common/utils.go index 606e2bc74..26c4430a2 100644 --- a/code/go/0chain.net/core/common/utils.go +++ b/code/go/0chain.net/core/common/utils.go @@ -2,12 +2,12 @@ package common import "fmt" -/*IsEmpty checks whether the input string is empty or not */ +// IsEmpty checks whether the input string is empty or not func IsEmpty(s string) bool { - return len(s) == 0 + return s == "" } -/*ToKey - takes an interface and returns a Key */ +// ToKey - takes an interface and returns a Key func ToKey(key interface{}) string { switch v := key.(type) { case string: @@ -19,6 +19,6 @@ func ToKey(key interface{}) string { } } -func IsEqual(key1 string, key2 string) bool { +func IsEqual(key1, key2 string) bool { return key1 == key2 } diff --git a/code/go/0chain.net/core/encryption/keys.go b/code/go/0chain.net/core/encryption/keys.go index 977db108d..bb652f1bf 100644 --- a/code/go/0chain.net/core/encryption/keys.go +++ b/code/go/0chain.net/core/encryption/keys.go @@ -15,7 +15,7 @@ import ( /*ReadKeys - reads a publicKey and a privateKey from a Reader. They are assumed to be in two separate lines one followed by the other*/ -func ReadKeys(reader io.Reader) (publicKey string, privateKey string, publicIp string, port string) { +func ReadKeys(reader io.Reader) (publicKey, privateKey, publicIp, port string) { scanner := bufio.NewScanner(reader) scanner.Scan() publicKey = scanner.Text() @@ -29,8 +29,8 @@ func ReadKeys(reader io.Reader) (publicKey string, privateKey string, publicIp s return publicKey, privateKey, publicIp, port } -//Verify - given a public key and a signature and the hash used to create the signature, verify the signature -func Verify(publicKey string, signature string, hash string) (bool, error) { +// Verify - given a public key and a signature and the hash used to create the signature, verify the signature +func Verify(publicKey, signature, hash string) (bool, error) { publicKey = MiraclToHerumiPK(publicKey) signature = MiraclToHerumiSig(signature) signScheme := zcncrypto.NewSignatureScheme(config.Configuration.SignatureScheme) diff --git a/code/go/0chain.net/core/lock/lock.go b/code/go/0chain.net/core/lock/lock.go index 25ca8ea9a..bae3b1cc4 100644 --- a/code/go/0chain.net/core/lock/lock.go +++ b/code/go/0chain.net/core/lock/lock.go @@ -40,7 +40,7 @@ func (m *Mutex) Unlock() { } // GetMutex get mutex by table and key -func GetMutex(tablename string, key string) *Mutex { +func GetMutex(tablename, key string) *Mutex { lockKey := tablename + ":" + key lockMutex.Lock() diff --git a/code/go/0chain.net/core/logging/logger.go b/code/go/0chain.net/core/logging/logger.go index 31bf5ccb3..68c6c1735 100644 --- a/code/go/0chain.net/core/logging/logger.go +++ b/code/go/0chain.net/core/logging/logger.go @@ -13,7 +13,7 @@ var ( Logger *zap.Logger ) -func InitLogging(mode string, logDir string, logFile string) { +func InitLogging(mode, logDir, logFile string) { var logName = logDir + "/" + logFile var logWriter = getWriteSyncer(logName) diff --git a/code/go/0chain.net/core/node/self_node.go b/code/go/0chain.net/core/node/self_node.go index 6c1a0ad51..be910587c 100644 --- a/code/go/0chain.net/core/node/self_node.go +++ b/code/go/0chain.net/core/node/self_node.go @@ -20,7 +20,7 @@ type SelfNode struct { } /*SetKeys - setter */ -func (sn *SelfNode) SetKeys(publicKey string, privateKey string) { +func (sn *SelfNode) SetKeys(publicKey, privateKey string) { publicKeyBytes, err := hex.DecodeString(publicKey) if err != nil { panic(err) diff --git a/code/go/0chain.net/core/transaction/http.go b/code/go/0chain.net/core/transaction/http.go index c6ea69311..30d2792f6 100644 --- a/code/go/0chain.net/core/transaction/http.go +++ b/code/go/0chain.net/core/transaction/http.go @@ -8,7 +8,6 @@ import ( "fmt" "io" - "io/ioutil" "net" "net/http" "net/url" @@ -129,7 +128,7 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] hash := fnv.New32() //use fnv for better performance teeReader := io.TeeReader(resp.Body, hash) - resBody, err := ioutil.ReadAll(teeReader) + resBody, err := io.ReadAll(teeReader) resp.Body.Close() if err != nil { diff --git a/code/go/0chain.net/core/util/http.go b/code/go/0chain.net/core/util/http.go index a1e983f33..62f3f2694 100644 --- a/code/go/0chain.net/core/util/http.go +++ b/code/go/0chain.net/core/util/http.go @@ -3,7 +3,7 @@ package util import ( "bytes" "context" - "io/ioutil" + "io" "net/http" "sync" "time" @@ -19,7 +19,7 @@ import ( const MAX_RETRIES = 5 const SLEEP_BETWEEN_RETRIES = 5 -func NewHTTPRequest(method string, url string, data []byte) (*http.Request, context.Context, context.CancelFunc, error) { +func NewHTTPRequest(method, url string, data []byte) (*http.Request, context.Context, context.CancelFunc, error) { requestHash := encryption.Hash(data) req, err := http.NewRequest(method, url, bytes.NewBuffer(data)) req.Header.Set("Content-Type", "application/json; charset=utf-8") @@ -63,7 +63,7 @@ func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) ( if resp.StatusCode >= 200 && resp.StatusCode <= 299 { break } - body, _ = ioutil.ReadAll(resp.Body) + body, _ = io.ReadAll(resp.Body) if resp.Body != nil { resp.Body.Close() } @@ -83,6 +83,6 @@ func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) ( defer resp.Body.Close() } - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) return body, err } diff --git a/code/go/0chain.net/validatorcore/config/config.go b/code/go/0chain.net/validatorcore/config/config.go index 4b59c4bd7..7d100099b 100644 --- a/code/go/0chain.net/validatorcore/config/config.go +++ b/code/go/0chain.net/validatorcore/config/config.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/viper" ) -//SetupDefaultConfig - setup the default config options that can be overridden via the config file +// SetupDefaultConfig - setup the default config options that can be overridden via the config file func SetupDefaultConfig() { viper.SetDefault("logging.level", "info") viper.SetDefault("delegate_wallet", "") diff --git a/code/go/0chain.net/validatorcore/storage/models.go b/code/go/0chain.net/validatorcore/storage/models.go index a5f93d0fb..81ad0672d 100644 --- a/code/go/0chain.net/validatorcore/storage/models.go +++ b/code/go/0chain.net/validatorcore/storage/models.go @@ -98,17 +98,19 @@ type FileMetaData struct { func (fr *FileMetaData) GetHashData() string { hashArray := make([]string, 0) - hashArray = append(hashArray, fr.AllocationID) - hashArray = append(hashArray, fr.Type) - hashArray = append(hashArray, fr.Name) - hashArray = append(hashArray, fr.Path) - hashArray = append(hashArray, strconv.FormatInt(fr.Size, 10)) - hashArray = append(hashArray, fr.ContentHash) - hashArray = append(hashArray, fr.MerkleRoot) - hashArray = append(hashArray, strconv.FormatInt(fr.ActualFileSize, 10)) - hashArray = append(hashArray, fr.ActualFileHash) - hashArray = append(hashArray, fr.Attributes.String()) - hashArray = append(hashArray, strconv.FormatInt(fr.ChunkSize, 10)) + hashArray = append(hashArray, + fr.AllocationID, + fr.Type, + fr.Name, + fr.Path, + strconv.FormatInt(fr.Size, 10), + fr.ContentHash, + fr.MerkleRoot, + strconv.FormatInt(fr.ActualFileSize, 10), + fr.ActualFileHash, + fr.Attributes.String(), + strconv.FormatInt(fr.ChunkSize, 10), + ) return strings.Join(hashArray, ":") } @@ -207,7 +209,7 @@ func (op *ObjectPath) VerifyBlockNum(challengeRand int64) error { r := rand.New(rand.NewSource(challengeRand)) //rand.Seed(challengeRand) blockNum := r.Int63n(op.RootObject.NumBlocks) - blockNum = blockNum + 1 + blockNum++ if op.RootObject.NumBlocks < blockNum { return common.NewError("invalid_block_num", fmt.Sprintf("Invalid block number %d/%d", op.RootObject.NumBlocks, blockNum)) @@ -224,7 +226,7 @@ func (op *ObjectPath) VerifyBlockNum(challengeRand int64) error { } for _, child := range curRef.(*DirMetaData).Children { if child.GetNumBlocks() < remainingBlocks { - remainingBlocks = remainingBlocks - child.GetNumBlocks() + remainingBlocks -= child.GetNumBlocks() continue } if child.GetType() == FILE { diff --git a/code/go/0chain.net/validatorcore/storage/protocol.go b/code/go/0chain.net/validatorcore/storage/protocol.go index 192027a3d..1f09fbafc 100644 --- a/code/go/0chain.net/validatorcore/storage/protocol.go +++ b/code/go/0chain.net/validatorcore/storage/protocol.go @@ -83,7 +83,7 @@ func (sp *ValidatorProtocolImpl) VerifyAllocationTransaction(ctx context.Context func (sp *ValidatorProtocolImpl) VerifyChallengeTransaction(ctx context.Context, challengeRequest *ChallengeRequest) (*Challenge, error) { blobberID := ctx.Value(constants.ContextKeyClient).(string) - if len(blobberID) == 0 { + if blobberID == "" { return nil, common.NewError("invalid_client", "Call from an invalid client") } params := make(map[string]string) @@ -122,7 +122,7 @@ type WalletCallback struct { err string } -func (wb *WalletCallback) OnWalletCreateComplete(status int, wallet string, err string) { +func (wb *WalletCallback) OnWalletCreateComplete(status int, wallet, err string) { wb.err = err wb.wg.Done() } diff --git a/code/go/0chain.net/validatorcore/storage/writemarker/entity.go b/code/go/0chain.net/validatorcore/storage/writemarker/entity.go index b5850d1eb..bbae60270 100644 --- a/code/go/0chain.net/validatorcore/storage/writemarker/entity.go +++ b/code/go/0chain.net/validatorcore/storage/writemarker/entity.go @@ -44,7 +44,7 @@ func (wm *WriteMarker) VerifySignature(clientPublicKey string) bool { return true } -func (wm *WriteMarker) Verify(allocationID string, allocationRoot string, clientPublicKey string) error { +func (wm *WriteMarker) Verify(allocationID, allocationRoot, clientPublicKey string) error { if wm.AllocationID != allocationID { return common.NewError("challenge_validation_failed", "Invalid write marker. Allocation ID mismatch") } From 3fc5a6bcb7291392924d82fdcab1737839167689 Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 15:03:56 +0545 Subject: [PATCH 2/7] Fix issue raised by goimports linter --- code/go/0chain.net/blobbercore/convert/response_creator.go | 1 + .../blobbercore/handler/calculate_hash_integration_test.go | 3 ++- .../blobbercore/handler/collaborator_integration_test.go | 3 ++- .../blobbercore/handler/commit_meta_txn_integration_test.go | 3 ++- .../blobbercore/handler/copy_object_integration_test.go | 3 ++- .../blobbercore/handler/getfilemetadata_integration_test.go | 3 ++- .../blobbercore/handler/listentities_integration_test.go | 2 +- .../blobbercore/handler/renameobject_integration_test.go | 3 ++- .../blobbercore/handler/updateattributes_integration_test.go | 3 ++- code/go/0chain.net/blobbercore/mock/allocation.go | 2 +- code/go/0chain.net/blobbercore/stats/allocationstats.go | 3 ++- 11 files changed, 19 insertions(+), 10 deletions(-) diff --git a/code/go/0chain.net/blobbercore/convert/response_creator.go b/code/go/0chain.net/blobbercore/convert/response_creator.go index f228536fb..8b436c78f 100644 --- a/code/go/0chain.net/blobbercore/convert/response_creator.go +++ b/code/go/0chain.net/blobbercore/convert/response_creator.go @@ -2,6 +2,7 @@ package convert import ( "encoding/json" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/allocation" diff --git a/code/go/0chain.net/blobbercore/handler/calculate_hash_integration_test.go b/code/go/0chain.net/blobbercore/handler/calculate_hash_integration_test.go index 90285c35c..22126b88d 100644 --- a/code/go/0chain.net/blobbercore/handler/calculate_hash_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/calculate_hash_integration_test.go @@ -2,9 +2,10 @@ package handler import ( "context" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" "google.golang.org/grpc/metadata" diff --git a/code/go/0chain.net/blobbercore/handler/collaborator_integration_test.go b/code/go/0chain.net/blobbercore/handler/collaborator_integration_test.go index d06d60dcb..7f6c3eaa0 100644 --- a/code/go/0chain.net/blobbercore/handler/collaborator_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/collaborator_integration_test.go @@ -3,12 +3,13 @@ package handler import ( "context" "encoding/hex" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "net/http" "strconv" "testing" "time" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker" "github.com/0chain/blobber/code/go/0chain.net/core/common" diff --git a/code/go/0chain.net/blobbercore/handler/commit_meta_txn_integration_test.go b/code/go/0chain.net/blobbercore/handler/commit_meta_txn_integration_test.go index 23ddd72f9..380d1fb40 100644 --- a/code/go/0chain.net/blobbercore/handler/commit_meta_txn_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/commit_meta_txn_integration_test.go @@ -3,11 +3,12 @@ package handler import ( "context" "encoding/hex" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "strconv" "testing" "time" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference" "github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker" "github.com/0chain/blobber/code/go/0chain.net/core/common" diff --git a/code/go/0chain.net/blobbercore/handler/copy_object_integration_test.go b/code/go/0chain.net/blobbercore/handler/copy_object_integration_test.go index befc6f1f6..2f3e93185 100644 --- a/code/go/0chain.net/blobbercore/handler/copy_object_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/copy_object_integration_test.go @@ -3,9 +3,10 @@ package handler import ( "context" "encoding/hex" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" "google.golang.org/grpc/metadata" diff --git a/code/go/0chain.net/blobbercore/handler/getfilemetadata_integration_test.go b/code/go/0chain.net/blobbercore/handler/getfilemetadata_integration_test.go index f5dfef241..fe80e0a51 100644 --- a/code/go/0chain.net/blobbercore/handler/getfilemetadata_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/getfilemetadata_integration_test.go @@ -2,11 +2,12 @@ package handler import ( "context" + "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" "google.golang.org/grpc/metadata" - "testing" ) func TestGetFileMetaData_IntegrationTest(t *testing.T) { diff --git a/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go b/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go index 3df112dd4..c8343adf3 100644 --- a/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go @@ -2,9 +2,9 @@ package handler import ( "context" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" diff --git a/code/go/0chain.net/blobbercore/handler/renameobject_integration_test.go b/code/go/0chain.net/blobbercore/handler/renameobject_integration_test.go index ff053741a..96b530efb 100644 --- a/code/go/0chain.net/blobbercore/handler/renameobject_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/renameobject_integration_test.go @@ -3,9 +3,10 @@ package handler import ( "context" "encoding/hex" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" "google.golang.org/grpc/metadata" diff --git a/code/go/0chain.net/blobbercore/handler/updateattributes_integration_test.go b/code/go/0chain.net/blobbercore/handler/updateattributes_integration_test.go index 0050b8504..a6522c286 100644 --- a/code/go/0chain.net/blobbercore/handler/updateattributes_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/updateattributes_integration_test.go @@ -4,9 +4,10 @@ import ( "context" "encoding/hex" "encoding/json" - blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" "testing" + blobbergrpc "github.com/0chain/blobber/code/go/0chain.net/blobbercore/blobbergrpc/proto" + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference" "github.com/0chain/blobber/code/go/0chain.net/core/common" "github.com/0chain/blobber/code/go/0chain.net/core/encryption" diff --git a/code/go/0chain.net/blobbercore/mock/allocation.go b/code/go/0chain.net/blobbercore/mock/allocation.go index 5d1896cf4..5e797b5fc 100644 --- a/code/go/0chain.net/blobbercore/mock/allocation.go +++ b/code/go/0chain.net/blobbercore/mock/allocation.go @@ -1,7 +1,7 @@ package mock import ( - "github.com/selvatico/go-mocket" + gomocket "github.com/selvatico/go-mocket" ) func MockGetAllocationByID(allocationID string, allocation map[string]interface{}) { diff --git a/code/go/0chain.net/blobbercore/stats/allocationstats.go b/code/go/0chain.net/blobbercore/stats/allocationstats.go index a680d3245..55ddafaab 100644 --- a/code/go/0chain.net/blobbercore/stats/allocationstats.go +++ b/code/go/0chain.net/blobbercore/stats/allocationstats.go @@ -1,8 +1,9 @@ package stats import ( - "github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore" "time" + + "github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore" ) // Timestamp that implements standard fmt.Stringer interface. From d7536ed862624c78d265aedc050420c28da75dca Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 15:31:27 +0545 Subject: [PATCH 3/7] Fix issue raised by gosec linter --- code/go/0chain.net/blobbercore/convert/response_creator.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/go/0chain.net/blobbercore/convert/response_creator.go b/code/go/0chain.net/blobbercore/convert/response_creator.go index 8b436c78f..34cbd1b80 100644 --- a/code/go/0chain.net/blobbercore/convert/response_creator.go +++ b/code/go/0chain.net/blobbercore/convert/response_creator.go @@ -29,7 +29,8 @@ func GetFileMetaDataResponseCreator(httpResp interface{}) *blobbergrpc.GetFileMe var resp blobbergrpc.GetFileMetaDataResponse collaborators, _ := r["collaborators"].([]reference.Collaborator) - for _, c := range collaborators { + for i := 0; i < len(collaborators); i++ { + c := collaborators[i] resp.Collaborators = append(resp.Collaborators, CollaboratorToGRPCCollaborator(&c)) } @@ -171,7 +172,8 @@ func CollaboratorResponseCreator(r interface{}) *blobbergrpc.CollaboratorRespons } collabs, _ := r.([]reference.Collaborator) - for _, c := range collabs { + for i := 0; i < len(collabs); i++ { + c := collabs[i] resp.Collaborators = append(resp.Collaborators, CollaboratorToGRPCCollaborator(&c)) } From bd6af5660cf100fdecf8d8a347dc4bed4db3eeb6 Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 15:37:21 +0545 Subject: [PATCH 4/7] Fix issue raised by unconvert linter --- .../blobbercore/allocation/renamefilechange_test.go | 2 +- code/go/0chain.net/blobbercore/filestore/fs_store.go | 4 ++-- code/go/0chain.net/blobbercore/handler/grpc_middleware.go | 2 +- code/go/0chain.net/blobbercore/handler/handler_test.go | 2 +- code/go/0chain.net/core/common/utils.go | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go index d1079863b..9aafd38d8 100644 --- a/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go +++ b/code/go/0chain.net/blobbercore/allocation/renamefilechange_test.go @@ -38,7 +38,7 @@ func (MockFileBlockGetter) GetFileBlock( fileData *filestore.FileInputData, blockNum int64, numBlocks int64) ([]byte, error) { - return []byte(mockFileBlock), nil + return mockFileBlock, nil } func resetMockFileBlock() { diff --git a/code/go/0chain.net/blobbercore/filestore/fs_store.go b/code/go/0chain.net/blobbercore/filestore/fs_store.go index 80c632494..2d76372be 100644 --- a/code/go/0chain.net/blobbercore/filestore/fs_store.go +++ b/code/go/0chain.net/blobbercore/filestore/fs_store.go @@ -95,8 +95,8 @@ func (FileBlockGetter) GetFileBlock(fs *FileFSStore, allocationID string, fileDa if blockNum > maxBlockNum || blockNum < 1 { return nil, common.NewError("invalid_block_number", "Invalid block number") } - buffer := make([]byte, int64(fileData.ChunkSize)*numBlocks) - n, err := file.ReadAt(buffer, ((blockNum - 1) * int64(fileData.ChunkSize))) + buffer := make([]byte, fileData.ChunkSize*numBlocks) + n, err := file.ReadAt(buffer, ((blockNum - 1) * fileData.ChunkSize)) if err != nil && err != io.EOF { return nil, err } diff --git a/code/go/0chain.net/blobbercore/handler/grpc_middleware.go b/code/go/0chain.net/blobbercore/handler/grpc_middleware.go index f1e73d530..60e321e4a 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_middleware.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_middleware.go @@ -49,7 +49,7 @@ func unaryDatabaseTransactionInjector() grpc.UnaryServerInterceptor { func unaryTimeoutInterceptor() grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - deadline := time.Now().Add(time.Duration(TIMEOUT_SECONDS * time.Second)) + deadline := time.Now().Add(TIMEOUT_SECONDS * time.Second) ctx, canceler := context.WithDeadline(ctx, deadline) defer canceler() diff --git a/code/go/0chain.net/blobbercore/handler/handler_test.go b/code/go/0chain.net/blobbercore/handler/handler_test.go index d10bf853f..1de30deb5 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/handler_test.go @@ -51,7 +51,7 @@ func (MockFileBlockGetter) GetFileBlock( fileData *filestore.FileInputData, blockNum int64, numBlocks int64) ([]byte, error) { - return []byte(mockFileBlock), nil + return mockFileBlock, nil } func setMockFileBlock(data []byte) { diff --git a/code/go/0chain.net/core/common/utils.go b/code/go/0chain.net/core/common/utils.go index 26c4430a2..558bad211 100644 --- a/code/go/0chain.net/core/common/utils.go +++ b/code/go/0chain.net/core/common/utils.go @@ -11,11 +11,11 @@ func IsEmpty(s string) bool { func ToKey(key interface{}) string { switch v := key.(type) { case string: - return string(v) + return v case []byte: return string(v) default: - return string(fmt.Sprintf("%v", v)) + return fmt.Sprintf("%v", v) } } From 550ac5f039d4fe87e286a314827c0e2ff1cb488d Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 15:42:38 +0545 Subject: [PATCH 5/7] Fix issue raised by unparam linter --- code/go/0chain.net/core/common/handler.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/code/go/0chain.net/core/common/handler.go b/code/go/0chain.net/core/common/handler.go index 7a2ee0c23..379e65211 100644 --- a/code/go/0chain.net/core/common/handler.go +++ b/code/go/0chain.net/core/common/handler.go @@ -55,11 +55,6 @@ func Respond(w http.ResponseWriter, data interface{}, err error) { } } -func getContext(r *http.Request) (context.Context, error) { //nolint:unused,deadcode // might be used later? - ctx := r.Context() - return ctx, nil -} - var domainRE = regexp.MustCompile(`^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)`) //nolint:unused,deadcode,varcheck // might be used later? func ToByteStream(handler JSONResponderF) ReqRespHandlerf { From 1d87b9bf893b28f28305fa604794a664181ec6db Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 15:45:06 +0545 Subject: [PATCH 6/7] Fix issue raised by misspell linter --- code/go/0chain.net/blobbercore/filestore/fs_store.go | 2 +- code/go/0chain.net/blobbercore/handler/file_command.go | 2 +- code/go/0chain.net/blobbercore/handler/grpc_handler_test.go | 2 +- code/go/0chain.net/blobbercore/handler/storage_handler.go | 2 +- code/go/0chain.net/blobbercore/readmarker/readmarker.go | 2 +- code/go/0chain.net/blobbercore/reference/referencepath.go | 2 +- code/go/0chain.net/blobbercore/writemarker/entity.go | 2 +- code/go/0chain.net/core/common/handler.go | 2 +- code/go/0chain.net/core/lock/lock.go | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/go/0chain.net/blobbercore/filestore/fs_store.go b/code/go/0chain.net/blobbercore/filestore/fs_store.go index 2d76372be..05265740b 100644 --- a/code/go/0chain.net/blobbercore/filestore/fs_store.go +++ b/code/go/0chain.net/blobbercore/filestore/fs_store.go @@ -543,7 +543,7 @@ func (fs *FileFSStore) WriteChunk(allocationID string, fileData *FileInputData, fileRef := &FileOutputData{} - // the chunk has been rewitten. but it is lost when network is broken, and it is not save in db + // the chunk has been rewritten. but it is lost when network is broken, and it is not save in db if dest.size > fileData.UploadOffset { fileRef.ChunkUploaded = true } diff --git a/code/go/0chain.net/blobbercore/handler/file_command.go b/code/go/0chain.net/blobbercore/handler/file_command.go index 9601b5248..08ed1e076 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command.go +++ b/code/go/0chain.net/blobbercore/handler/file_command.go @@ -19,7 +19,7 @@ type FileCommand interface { // ProcessThumbnail flush thumbnail file to FileStorage if it has. ProcessThumbnail(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, connectionObj *allocation.AllocationChangeCollector) error - // UpdateChange update AllocationChangeProcessor. It will be president in db for commiting transcation + // UpdateChange update AllocationChangeProcessor. It will be president in db for committing transcation UpdateChange(ctx context.Context, connectionObj *allocation.AllocationChangeCollector) error } diff --git a/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go b/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go index 128b82296..49f676574 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go @@ -135,7 +135,7 @@ func Test_GetAllocation(t *testing.T) { wantAlloc: convert.AllocationToGRPCAllocation(alloc), }, { - name: "Commiting_Transaction_ERR", + name: "Committing_Transaction_ERR", mockSetup: func(mock sqlmock.Sqlmock) { mock.ExpectBegin() diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 1e8980d5c..bf7cd3754 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -969,7 +969,7 @@ func verifySignatureFromRequest(alloc, sign, pbK string) (bool, error) { } // pathsFromReq retrieves paths value from request which can be represented as single "path" value or "paths" values, -// marshalled to json. +// marshaled to json. func pathsFromReq(r *http.Request) ([]string, error) { var ( pathsStr = r.FormValue("paths") diff --git a/code/go/0chain.net/blobbercore/readmarker/readmarker.go b/code/go/0chain.net/blobbercore/readmarker/readmarker.go index 665e442a9..3ad1f495d 100644 --- a/code/go/0chain.net/blobbercore/readmarker/readmarker.go +++ b/code/go/0chain.net/blobbercore/readmarker/readmarker.go @@ -42,7 +42,7 @@ func redeemReadMarker(ctx context.Context) { db := datastore.GetStore().GetTransaction(redeemCtx) err = db.Commit().Error if err != nil { - logging.Logger.Error("Error commiting the readmarker redeem", zap.Error(err)) + logging.Logger.Error("Error committing the readmarker redeem", zap.Error(err)) } swg.Done() }(ctx, rmEntity) diff --git a/code/go/0chain.net/blobbercore/reference/referencepath.go b/code/go/0chain.net/blobbercore/reference/referencepath.go index 1816859c8..4f122c3ae 100644 --- a/code/go/0chain.net/blobbercore/reference/referencepath.go +++ b/code/go/0chain.net/blobbercore/reference/referencepath.go @@ -130,7 +130,7 @@ func GetObjectTree(ctx context.Context, allocationID, path string) (*Ref, error) return &refs[0], nil } -//This function retrieves refrence_objects tables rows with pagination. Check for issue https://github.com/0chain/gosdk/issues/117 +//This function retrieves reference_objects tables rows with pagination. Check for issue https://github.com/0chain/gosdk/issues/117 //Might need to consider covering index for efficient search https://blog.crunchydata.com/blog/why-covering-indexes-are-incredibly-helpful //To retrieve refs efficiently form pagination index is created in postgresql on path column so it can be used to paginate refs //very easily and effectively; Same case for offsetDate. diff --git a/code/go/0chain.net/blobbercore/writemarker/entity.go b/code/go/0chain.net/blobbercore/writemarker/entity.go index 38dceef0c..dc23790ac 100644 --- a/code/go/0chain.net/blobbercore/writemarker/entity.go +++ b/code/go/0chain.net/blobbercore/writemarker/entity.go @@ -83,7 +83,7 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, return // not committed or a deleting marker } - // work on pre-redeemd tokens and write-pools balances tracking + // work on pre-redeemed tokens and write-pools balances tracking var pend *allocation.Pending pend, err = allocation.GetPending(db, wm.WM.ClientID, wm.WM.AllocationID, diff --git a/code/go/0chain.net/core/common/handler.go b/code/go/0chain.net/core/common/handler.go index 379e65211..5b2bab5e0 100644 --- a/code/go/0chain.net/core/common/handler.go +++ b/code/go/0chain.net/core/common/handler.go @@ -22,7 +22,7 @@ const ( ClientSignatureHeader = "X-App-Client-Signature" ) -/*ReqRespHandlerf - a type for the default hanlder signature */ +/*ReqRespHandlerf - a type for the default handler signature */ type ReqRespHandlerf func(w http.ResponseWriter, r *http.Request) /*JSONResponderF - a handler that takes standard request (non-json) and responds with a json response diff --git a/code/go/0chain.net/core/lock/lock.go b/code/go/0chain.net/core/lock/lock.go index bae3b1cc4..dc673e52c 100644 --- a/code/go/0chain.net/core/lock/lock.go +++ b/code/go/0chain.net/core/lock/lock.go @@ -6,7 +6,7 @@ import ( ) var ( - // MutexCleanInterval start to clean unsed mutex at specified interval + // MutexCleanInterval start to clean unused mutex at specified interval MutexCleanInterval = 10 * time.Minute ) From 838ab4fc4ad376cde39efe5d050e12681abd580b Mon Sep 17 00:00:00 2001 From: Laxmi Prasad Oli Date: Mon, 31 Jan 2022 16:11:50 +0545 Subject: [PATCH 7/7] Fix issue raised by whitespace linter --- code/go/0chain.net/blobber/datastore.go | 2 - code/go/0chain.net/blobber/flags.go | 1 - code/go/0chain.net/blobber/grpc.go | 1 - code/go/0chain.net/blobber/http.go | 2 - code/go/0chain.net/blobber/main.go | 1 - code/go/0chain.net/blobber/node.go | 1 - code/go/0chain.net/blobber/zcn.go | 3 -- .../allocation/allocationchange.go | 1 - .../allocation/attributesfilechange.go | 4 +- .../allocation/deletefilechange.go | 1 - .../blobbercore/allocation/entity.go | 38 +++++-------------- .../allocation/file_changer_add.go | 4 +- .../allocation/file_changer_update.go | 1 - .../blobbercore/allocation/newfilechange.go | 4 +- .../blobbercore/allocation/protocol.go | 16 ++------ .../blobbercore/allocation/workers.go | 26 +++---------- .../blobbercore/challenge/challenge.go | 5 --- .../blobbercore/challenge/protocol.go | 2 - .../blobbercore/challenge/worker.go | 2 - .../0chain.net/blobbercore/config/config.go | 1 - .../0chain.net/blobbercore/convert/convert.go | 1 - .../blobbercore/datastore/mocket.go | 2 - .../blobbercore/datastore/sqlmock.go | 2 - .../filestore/chunk_writer_test.go | 2 - .../blobbercore/filestore/fs_store.go | 12 +----- .../blobbercore/filestore/mock_store.go | 2 - .../blobbercore/handler/file_command_add.go | 3 -- .../handler/file_command_delete.go | 2 - .../handler/file_command_update.go | 5 --- .../handler/getallocation_integration_test.go | 1 - .../handler/getfilestats_integration_test.go | 1 - .../handler/getobjecttree_integration_test.go | 1 - .../getreferencepath_integration_test.go | 1 - .../blobbercore/handler/grpc_handler_test.go | 3 -- .../0chain.net/blobbercore/handler/handler.go | 5 +-- .../blobbercore/handler/handler_test.go | 4 -- .../handler/helper_integration_test.go | 3 -- .../handler/listentities_integration_test.go | 1 - .../handler/object_operation_grpc_handler.go | 1 - .../handler/object_operation_handler.go | 26 +++---------- .../object_operation_handler_bench_test.go | 9 ----- .../handler/object_operation_handler_test.go | 1 - .../blobbercore/handler/protocol.go | 2 - .../blobbercore/handler/storage_handler.go | 7 +--- .../0chain.net/blobbercore/handler/worker.go | 3 +- .../0chain.net/blobbercore/handler/zcncore.go | 1 - code/go/0chain.net/blobbercore/mock/ctx.go | 1 - code/go/0chain.net/blobbercore/mock/init.go | 1 - .../blobbercore/readmarker/entity.go | 8 +--- .../blobbercore/readmarker/protocol.go | 12 +----- .../blobbercore/readmarker/readmarker.go | 1 - .../blobbercore/readmarker/worker.go | 8 +--- .../blobbercore/reference/object.go | 6 --- .../blobbercore/reference/objectpath.go | 2 - .../0chain.net/blobbercore/reference/ref.go | 3 -- .../blobbercore/reference/referencepath.go | 4 -- .../blobbercore/stats/blobberstats.go | 14 +------ .../blobbercore/writemarker/entity.go | 5 +-- .../blobbercore/writemarker/protocol.go | 1 - .../blobbercore/writemarker/worker.go | 1 - .../0chain.net/conductor/conductrpc/entity.go | 1 - .../0chain.net/conductor/conductrpc/state.go | 1 - code/go/0chain.net/core/common/handler.go | 1 - .../go/0chain.net/core/common/rate_limiter.go | 1 - code/go/0chain.net/core/lock/lock.go | 2 - code/go/0chain.net/core/lock/lock_test.go | 3 -- code/go/0chain.net/core/logging/logger.go | 1 - code/go/0chain.net/core/transaction/http.go | 7 ---- code/go/0chain.net/core/util/http.go | 4 +- code/go/0chain.net/validator/main.go | 1 - .../storage/challenge_handler.go | 1 - .../validatorcore/storage/models.go | 1 - .../validatorcore/storage/protocol.go | 1 - 73 files changed, 41 insertions(+), 268 deletions(-) diff --git a/code/go/0chain.net/blobber/datastore.go b/code/go/0chain.net/blobber/datastore.go index 5402cfdba..acb0e0506 100644 --- a/code/go/0chain.net/blobber/datastore.go +++ b/code/go/0chain.net/blobber/datastore.go @@ -12,7 +12,6 @@ func setupDatabase() error { fmt.Print("\r[7/11] connect data store") // check for database connection for i := 0; i < 600; i++ { - if i > 0 { fmt.Printf("\r[7/10] connect(%v) data store", i) } @@ -27,7 +26,6 @@ func setupDatabase() error { } time.Sleep(1 * time.Second) - } return nil diff --git a/code/go/0chain.net/blobber/flags.go b/code/go/0chain.net/blobber/flags.go index 436c23467..f41af64e9 100644 --- a/code/go/0chain.net/blobber/flags.go +++ b/code/go/0chain.net/blobber/flags.go @@ -25,7 +25,6 @@ var ( ) func init() { - flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet") flag.StringVar(&keysFile, "keys_file", "", "keys_file") flag.StringVar(&minioFile, "minio_file", "", "minio_file") diff --git a/code/go/0chain.net/blobber/grpc.go b/code/go/0chain.net/blobber/grpc.go index 4da0db458..cdb6ea692 100644 --- a/code/go/0chain.net/blobber/grpc.go +++ b/code/go/0chain.net/blobber/grpc.go @@ -18,7 +18,6 @@ import ( ) func startGRPCServer() { - common.ConfigRateLimits() r := mux.NewRouter() initHandlers(r) diff --git a/code/go/0chain.net/blobber/http.go b/code/go/0chain.net/blobber/http.go index 4f634e903..a946ebff9 100644 --- a/code/go/0chain.net/blobber/http.go +++ b/code/go/0chain.net/blobber/http.go @@ -18,7 +18,6 @@ import ( ) func startHttpServer() { - mode := "main net" if config.Development() { mode = "development" @@ -42,7 +41,6 @@ func startHttpServer() { fmt.Println("[11/11] start http server [OK]") wg.Wait() - } func startServer(wg *sync.WaitGroup, r *mux.Router, mode string, port int, isTls bool) { diff --git a/code/go/0chain.net/blobber/main.go b/code/go/0chain.net/blobber/main.go index c6a2455bb..2c5492f32 100644 --- a/code/go/0chain.net/blobber/main.go +++ b/code/go/0chain.net/blobber/main.go @@ -46,5 +46,4 @@ func main() { startGRPCServer() startHttpServer() - } diff --git a/code/go/0chain.net/blobber/node.go b/code/go/0chain.net/blobber/node.go index c2322903c..072e47241 100644 --- a/code/go/0chain.net/blobber/node.go +++ b/code/go/0chain.net/blobber/node.go @@ -16,7 +16,6 @@ func setupNode() error { reader, err := os.Open(keysFile) if err != nil { - return err } defer reader.Close() diff --git a/code/go/0chain.net/blobber/zcn.go b/code/go/0chain.net/blobber/zcn.go index 3c6cb4edd..896635ee0 100644 --- a/code/go/0chain.net/blobber/zcn.go +++ b/code/go/0chain.net/blobber/zcn.go @@ -45,13 +45,11 @@ func setupOnChain() { fmt.Print(" [SKIP]\n") break } else { - if err := registerBlobberOnChain(); err != nil { if i == 10 { // no more attempts panic(err) } fmt.Print("\n ", err.Error()+"\n") - } else { fmt.Print(" [OK]\n") break @@ -62,7 +60,6 @@ func setupOnChain() { fmt.Printf("\r - wait %v seconds to retry", ATTEMPT_DELAY-n) } } - } if !isIntegrationTest { go setupWorkers() diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 734064938..aecd93a52 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -102,7 +102,6 @@ func (cc *AllocationChangeCollector) AddChange(allocationChange *AllocationChang } func (cc *AllocationChangeCollector) Save(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) if cc.Status == NewConnection { cc.Status = InProgressConnection diff --git a/code/go/0chain.net/blobbercore/allocation/attributesfilechange.go b/code/go/0chain.net/blobbercore/allocation/attributesfilechange.go index 6b2860aab..aeb57be64 100644 --- a/code/go/0chain.net/blobbercore/allocation/attributesfilechange.go +++ b/code/go/0chain.net/blobbercore/allocation/attributesfilechange.go @@ -22,9 +22,7 @@ type AttributesChange struct { } // ProcessChange processes the attributes changes. -func (ac *AttributesChange) ProcessChange(ctx context.Context, - _ *AllocationChange, allocRoot string) (ref *reference.Ref, err error) { - +func (ac *AttributesChange) ProcessChange(ctx context.Context, _ *AllocationChange, allocRoot string) (ref *reference.Ref, err error) { var path, _ = filepath.Split(ac.Path) path = filepath.Clean(path) diff --git a/code/go/0chain.net/blobbercore/allocation/deletefilechange.go b/code/go/0chain.net/blobbercore/allocation/deletefilechange.go index 7844e768b..d878ffd21 100644 --- a/code/go/0chain.net/blobbercore/allocation/deletefilechange.go +++ b/code/go/0chain.net/blobbercore/allocation/deletefilechange.go @@ -23,7 +23,6 @@ type DeleteFileChange struct { } func (nf *DeleteFileChange) ProcessChange(ctx context.Context, change *AllocationChange, allocationRoot string) (*reference.Ref, error) { - rootRef, contentHash, err := reference.DeleteObject(ctx, nf.AllocationID, nf.Path) if err != nil { return nil, err diff --git a/code/go/0chain.net/blobbercore/allocation/entity.go b/code/go/0chain.net/blobbercore/allocation/entity.go index 6196ead9b..0bf78f663 100644 --- a/code/go/0chain.net/blobbercore/allocation/entity.go +++ b/code/go/0chain.net/blobbercore/allocation/entity.go @@ -49,9 +49,7 @@ func (Allocation) TableName() string { // RestDurationInTimeUnits returns number (float point) of time units until // allocation ends. -func (a *Allocation) RestDurationInTimeUnits(wmt common.Timestamp) ( - rdtu float64) { - +func (a *Allocation) RestDurationInTimeUnits(wmt common.Timestamp) (rdtu float64) { var ( wmtt = time.Unix(int64(wmt), 0) expt = time.Unix(int64(a.Expiration), 0) @@ -92,9 +90,7 @@ type WantWriter interface { // WantWrite returns amount of tokens (by current terms of the allocations that // should be loaded) by given size for given blobber. E.g. want is tokens // wanted. -func (a *Allocation) WantWrite(blobberID string, size int64, - wmt common.Timestamp) (value int64) { - +func (a *Allocation) WantWrite(blobberID string, size int64, wmt common.Timestamp) (value int64) { if size < 0 { return // deleting, ignore } @@ -111,9 +107,7 @@ func (a *Allocation) WantWrite(blobberID string, size int64, } // ReadPools from DB cache. -func ReadPools(tx *gorm.DB, clientID, allocID, blobberID string, - until common.Timestamp) (rps []*ReadPool, err error) { - +func ReadPools(tx *gorm.DB, clientID, allocID, blobberID string, until common.Timestamp) (rps []*ReadPool, err error) { const query = `client_id = ? AND allocation_id = ? AND blobber_id = ? AND @@ -127,9 +121,7 @@ func ReadPools(tx *gorm.DB, clientID, allocID, blobberID string, // HaveRead is sum of read pools (the list should be filtered by query // excluding pools expired and pools going to expired soon) minus pending reads. -func (a *Allocation) HaveRead(rps []*ReadPool, blobberID string, - pendNumBlocks int64) (have int64) { - +func (a *Allocation) HaveRead(rps []*ReadPool, blobberID string, pendNumBlocks int64) (have int64) { for _, rp := range rps { have += rp.Balance } @@ -150,9 +142,7 @@ func (*Pending) TableName() string { return "pendings" } -func GetPending(tx *gorm.DB, clientID, allocationID, blobberID string) ( - p *Pending, err error) { - +func GetPending(tx *gorm.DB, clientID, allocationID, blobberID string) (p *Pending, err error) { const query = `client_id = ? AND allocation_id = ? AND blobber_id = ?` @@ -180,9 +170,7 @@ func (p *Pending) SubPendingWrite(size int64) { } } -func (p *Pending) WritePools(tx *gorm.DB, blobberID string, - until common.Timestamp) (wps []*WritePool, err error) { - +func (p *Pending) WritePools(tx *gorm.DB, blobberID string, until common.Timestamp) (wps []*WritePool, err error) { const query = `client_id = ? AND allocation_id = ? AND blobber_id = ? AND @@ -194,9 +182,7 @@ func (p *Pending) WritePools(tx *gorm.DB, blobberID string, return } -func (p *Pending) HaveWrite(wps []*WritePool, ww WantWriter, - wmt common.Timestamp) (have int64) { - +func (p *Pending) HaveWrite(wps []*WritePool, ww WantWriter, wmt common.Timestamp) (have int64) { for _, wp := range wps { have += wp.Balance } @@ -254,11 +240,8 @@ func (*WritePool) TableName() string { return "write_pools" } -func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, - rps []*ReadPool) (err error) { - +func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, rps []*ReadPool) (err error) { // cleanup and batch insert (remove old pools, add / update new) - const query = `client_id = ? AND allocation_id = ? AND blobber_id = ?` @@ -282,9 +265,7 @@ func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, return } -func SetWritePools(db *gorm.DB, clientID, allocationID, blobberID string, - wps []*WritePool) (err error) { - +func SetWritePools(db *gorm.DB, clientID, allocationID, blobberID string, wps []*WritePool) (err error) { const query = `client_id = ? AND allocation_id = ? AND blobber_id = ?` @@ -319,7 +300,6 @@ type ReadPoolRedeem struct { // SubReadRedeemed subtracts tokens redeemed from read pools. func SubReadRedeemed(rps []*ReadPool, redeems []ReadPoolRedeem) { - var rm = make(map[string]int64) for _, rd := range redeems { diff --git a/code/go/0chain.net/blobbercore/allocation/file_changer_add.go b/code/go/0chain.net/blobbercore/allocation/file_changer_add.go index cd6dcc249..434afa0d5 100644 --- a/code/go/0chain.net/blobbercore/allocation/file_changer_add.go +++ b/code/go/0chain.net/blobbercore/allocation/file_changer_add.go @@ -19,9 +19,7 @@ type AddFileChanger struct { } // ProcessChange update references, and create a new FileRef -func (nf *AddFileChanger) ProcessChange(ctx context.Context, - change *AllocationChange, allocationRoot string) (*reference.Ref, error) { - +func (nf *AddFileChanger) ProcessChange(ctx context.Context, change *AllocationChange, allocationRoot string) (*reference.Ref, error) { path, _ := filepath.Split(nf.Path) path = filepath.Clean(path) tSubDirs := reference.GetSubDirsFromPath(path) diff --git a/code/go/0chain.net/blobbercore/allocation/file_changer_update.go b/code/go/0chain.net/blobbercore/allocation/file_changer_update.go index 0119e9bb7..53e7f7fcd 100644 --- a/code/go/0chain.net/blobbercore/allocation/file_changer_update.go +++ b/code/go/0chain.net/blobbercore/allocation/file_changer_update.go @@ -19,7 +19,6 @@ type UpdateFileChanger struct { } func (nf *UpdateFileChanger) ProcessChange(ctx context.Context, change *AllocationChange, allocationRoot string) (*reference.Ref, error) { - path, _ := filepath.Split(nf.Path) path = filepath.Clean(path) tSubDirs := reference.GetSubDirsFromPath(path) diff --git a/code/go/0chain.net/blobbercore/allocation/newfilechange.go b/code/go/0chain.net/blobbercore/allocation/newfilechange.go index 5b48dde8c..c4e05e678 100644 --- a/code/go/0chain.net/blobbercore/allocation/newfilechange.go +++ b/code/go/0chain.net/blobbercore/allocation/newfilechange.go @@ -115,9 +115,7 @@ func (nf *NewFileChange) CreateDir(ctx context.Context, allocationID, dirName, a return rootRef, nil } -func (nf *NewFileChange) ProcessChange(ctx context.Context, - change *AllocationChange, allocationRoot string) (*reference.Ref, error) { - +func (nf *NewFileChange) ProcessChange(ctx context.Context, change *AllocationChange, allocationRoot string) (*reference.Ref, error) { if change.Operation == constants.FileOperationCreateDir { err := nf.Unmarshal(change.Input) if err != nil { diff --git a/code/go/0chain.net/blobbercore/allocation/protocol.go b/code/go/0chain.net/blobbercore/allocation/protocol.go index 27905f669..66f928d93 100644 --- a/code/go/0chain.net/blobbercore/allocation/protocol.go +++ b/code/go/0chain.net/blobbercore/allocation/protocol.go @@ -16,9 +16,7 @@ import ( ) // GetAllocationByID from DB. This function doesn't load related terms. -func GetAllocationByID(ctx context.Context, allocID string) ( - a *Allocation, err error) { - +func GetAllocationByID(ctx context.Context, allocID string) (a *Allocation, err error) { var tx = datastore.GetStore().GetTransaction(ctx) a = new(Allocation) @@ -49,9 +47,7 @@ func (a *Allocation) LoadTerms(ctx context.Context) (err error) { } // VerifyAllocationTransaction try to get allocation from postgres.if it doesn't exists, get it from sharders, and insert it into postgres. -func VerifyAllocationTransaction(ctx context.Context, allocationTx string, - readonly bool) (a *Allocation, err error) { - +func VerifyAllocationTransaction(ctx context.Context, allocationTx string, readonly bool) (a *Allocation, err error) { var tx = datastore.GetStore().GetTransaction(ctx) a = new(Allocation) @@ -179,9 +175,7 @@ type PoolStat struct { ExpireAt common.Timestamp `json:"expire_at"` } -func RequestReadPools(clientID, allocationID string) ( - rps []*ReadPool, err error) { - +func RequestReadPools(clientID, allocationID string) (rps []*ReadPool, err error) { Logger.Info("request read pools") var ( @@ -228,9 +222,7 @@ func RequestReadPools(clientID, allocationID string) ( return // got them } -func RequestWritePools(clientID, allocationID string) ( - wps []*WritePool, err error) { - +func RequestWritePools(clientID, allocationID string) (wps []*WritePool, err error) { Logger.Info("request write pools") var ( diff --git a/code/go/0chain.net/blobbercore/allocation/workers.go b/code/go/0chain.net/blobbercore/allocation/workers.go index 2e588a07c..bc871ee5b 100644 --- a/code/go/0chain.net/blobbercore/allocation/workers.go +++ b/code/go/0chain.net/blobbercore/allocation/workers.go @@ -73,7 +73,6 @@ func waitOrQuit(ctx context.Context, d time.Duration) (quit bool) { } func updateWork(ctx context.Context) { - defer func() { if r := recover(); r != nil { Logger.Error("[recover] updateWork", zap.Any("err", r)) @@ -91,7 +90,6 @@ func updateWork(ctx context.Context) { // iterate all in loop accepting allocations with limit for start := true; start || (offset < count); start = false { - allocs, count, err = findAllocations(ctx, offset) if err != nil { Logger.Error("finding allocations in DB", zap.Error(err)) @@ -113,9 +111,7 @@ func updateWork(ctx context.Context) { } // not finalized, not cleaned up -func findAllocations(ctx context.Context, offset int64) ( - allocs []*Allocation, count int64, err error) { - +func findAllocations(ctx context.Context, offset int64) (allocs []*Allocation, count int64, err error) { const query = `finalized = false AND cleaned_up = false` ctx = datastore.GetStore().CreateTransaction(ctx) @@ -144,7 +140,6 @@ func shouldFinalize(sa *transaction.StorageAllocation) bool { } func updateAllocation(ctx context.Context, a *Allocation) { - if a.Finalized { cleanupAllocation(ctx, a) return @@ -174,12 +169,9 @@ func updateAllocation(ctx context.Context, a *Allocation) { if a.Finalized && !a.CleanedUp { cleanupAllocation(ctx, a) } - } -func requestAllocation(allocID string) ( - sa *transaction.StorageAllocation, err error) { - +func requestAllocation(allocID string) (sa *transaction.StorageAllocation, err error) { var b []byte b, err = transaction.MakeSCRestAPICall( transaction.STORAGE_CONTRACT_ADDRESS, @@ -202,9 +194,7 @@ func commit(tx *gorm.DB, err *error) { (*err) = tx.Commit().Error } -func updateAllocationInDB(ctx context.Context, a *Allocation, - sa *transaction.StorageAllocation) (ua *Allocation, err error) { - +func updateAllocationInDB(ctx context.Context, a *Allocation, sa *transaction.StorageAllocation) (ua *Allocation, err error) { ctx = datastore.GetStore().CreateTransaction(ctx) var tx = datastore.GetStore().GetTransaction(ctx) @@ -265,7 +255,6 @@ func (fr *finalizeRequest) marshal() string { } func sendFinalizeAllocation(a *Allocation) { - var tx, err = transaction.NewTransactionEntity() if err != nil { Logger.Error("creating new transaction entity", zap.Error(err)) @@ -287,7 +276,6 @@ func sendFinalizeAllocation(a *Allocation) { } func cleanupAllocation(ctx context.Context, a *Allocation) { - var err error if err = deleteInFakeConnection(ctx, a); err != nil { Logger.Error("cleaning finalized allocation", zap.Error(err)) @@ -330,9 +318,7 @@ func deleteInFakeConnection(ctx context.Context, a *Allocation) (err error) { } // delete references -func deleteFiles(ctx context.Context, allocID string, - conn *AllocationChangeCollector) (err error) { - +func deleteFiles(ctx context.Context, allocID string, conn *AllocationChangeCollector) (err error) { var ( tx = datastore.GetStore().GetTransaction(ctx) refs = make([]*reference.Ref, 0) @@ -355,9 +341,7 @@ func deleteFiles(ctx context.Context, allocID string, } // delete reference -func deleteFile(ctx context.Context, path string, - conn *AllocationChangeCollector) (err error) { - +func deleteFile(ctx context.Context, path string, conn *AllocationChangeCollector) (err error) { var fileRef *reference.Ref fileRef, err = reference.GetReference(ctx, conn.AllocationID, path) if err != nil { diff --git a/code/go/0chain.net/blobbercore/challenge/challenge.go b/code/go/0chain.net/blobbercore/challenge/challenge.go index ea8c0bc45..23f171d0f 100644 --- a/code/go/0chain.net/blobbercore/challenge/challenge.go +++ b/code/go/0chain.net/blobbercore/challenge/challenge.go @@ -43,7 +43,6 @@ func syncOpenChallenges(ctx context.Context) { if err != nil { logging.Logger.Error("[challenge]open: ", zap.Error(err)) } else { - bytesReader := bytes.NewBuffer(retBytes) d := json.NewDecoder(bytesReader) @@ -65,7 +64,6 @@ func syncOpenChallenges(ctx context.Context) { // challenge is not synced in db yet if errors.Is(err, gorm.ErrRecordNotFound) { - latestChallenge, err := GetLastChallengeEntity(tx) if err != nil { @@ -90,13 +88,11 @@ func syncOpenChallenges(ctx context.Context) { } else { logging.Logger.Error("[challenge]Challenge chain is not valid") } - } db.Commit() tx.Done() } } - } } @@ -136,7 +132,6 @@ func processAccepted(ctx context.Context) { logging.Logger.Error("[challenge]db: ", zap.Any("challenge_id", challengeEntity.ChallengeID), zap.Error(err)) return } - }(ctx, openchallenge) } swg.Wait() diff --git a/code/go/0chain.net/blobbercore/challenge/protocol.go b/code/go/0chain.net/blobbercore/challenge/protocol.go index 2af8a143a..8db4deefa 100644 --- a/code/go/0chain.net/blobbercore/challenge/protocol.go +++ b/code/go/0chain.net/blobbercore/challenge/protocol.go @@ -28,7 +28,6 @@ type ChallengeResponse struct { } func (cr *ChallengeEntity) SubmitChallengeToBC(ctx context.Context) (*transaction.Transaction, error) { - txn, err := transaction.NewTransactionEntity() if err != nil { return nil, err @@ -254,7 +253,6 @@ func (cr *ChallengeEntity) LoadValidationTickets(ctx context.Context) error { } func (cr *ChallengeEntity) CommitChallenge(ctx context.Context, verifyOnly bool) error { - if len(cr.LastCommitTxnIDs) > 0 { for _, lastTxn := range cr.LastCommitTxnIDs { Logger.Info("[challenge]commit: Verifying the transaction : " + lastTxn) diff --git a/code/go/0chain.net/blobbercore/challenge/worker.go b/code/go/0chain.net/blobbercore/challenge/worker.go index 10e6ec5c9..ecf7773f1 100644 --- a/code/go/0chain.net/blobbercore/challenge/worker.go +++ b/code/go/0chain.net/blobbercore/challenge/worker.go @@ -26,7 +26,6 @@ func startCommitProcessed(ctx context.Context) { } func startProcessAccepted(ctx context.Context) { - for { select { case <-ctx.Done(): @@ -39,7 +38,6 @@ func startProcessAccepted(ctx context.Context) { // startSyncOpen func startSyncOpen(ctx context.Context) { - for { select { case <-ctx.Done(): diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index db190dc15..c574c44eb 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -156,7 +156,6 @@ func Geolocation() GeolocationConfig { if g.Latitude > 90.00 || g.Latitude < -90.00 || g.Longitude > 180.00 || g.Longitude < -180.00 { panic("Fatal error in config file") - } return g } diff --git a/code/go/0chain.net/blobbercore/convert/convert.go b/code/go/0chain.net/blobbercore/convert/convert.go index c287ed756..ab399015f 100644 --- a/code/go/0chain.net/blobbercore/convert/convert.go +++ b/code/go/0chain.net/blobbercore/convert/convert.go @@ -477,7 +477,6 @@ func WriteFileGRPCToHTTP(req *blobbergrpc.UploadFileRequest) (*http.Request, err return nil, err } r.Header.Set("Content-Type", writer.FormDataContentType()) - } return r, nil diff --git a/code/go/0chain.net/blobbercore/datastore/mocket.go b/code/go/0chain.net/blobbercore/datastore/mocket.go index 248695263..3e8f9be7a 100644 --- a/code/go/0chain.net/blobbercore/datastore/mocket.go +++ b/code/go/0chain.net/blobbercore/datastore/mocket.go @@ -33,7 +33,6 @@ type Mocket struct { } func (store *Mocket) Open() error { - mocket.Catcher.Reset() mocket.Catcher.Register() mocket.Catcher.Logging = store.logging @@ -62,7 +61,6 @@ func (store *Mocket) Open() error { func (store *Mocket) Close() { if store.db != nil { - if db, _ := store.db.DB(); db != nil { db.Close() } diff --git a/code/go/0chain.net/blobbercore/datastore/sqlmock.go b/code/go/0chain.net/blobbercore/datastore/sqlmock.go index f13fbb365..1dc998035 100644 --- a/code/go/0chain.net/blobbercore/datastore/sqlmock.go +++ b/code/go/0chain.net/blobbercore/datastore/sqlmock.go @@ -31,7 +31,6 @@ type Sqlmock struct { } func (store *Sqlmock) Open() error { - db, mock, err := sqlmock.New() if err != nil { return err @@ -57,7 +56,6 @@ func (store *Sqlmock) Open() error { func (store *Sqlmock) Close() { if store.db != nil { - if db, _ := store.db.DB(); db != nil { db.Close() } diff --git a/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go b/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go index 1a22c36e8..54a28cffc 100644 --- a/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go +++ b/code/go/0chain.net/blobbercore/filestore/chunk_writer_test.go @@ -15,7 +15,6 @@ import ( ) func TestWrite(t *testing.T) { - fileName := filepath.Join(os.TempDir(), "testwrite_"+strconv.FormatInt(time.Now().Unix(), 10)) content := "this is full content" @@ -46,7 +45,6 @@ func TestWrite(t *testing.T) { } func TestWriteChunk(t *testing.T) { - chunk1 := "this is 1st chunked" tempFile, err := ioutil.TempFile("", "") diff --git a/code/go/0chain.net/blobbercore/filestore/fs_store.go b/code/go/0chain.net/blobbercore/filestore/fs_store.go index 05265740b..f68812872 100644 --- a/code/go/0chain.net/blobbercore/filestore/fs_store.go +++ b/code/go/0chain.net/blobbercore/filestore/fs_store.go @@ -247,7 +247,6 @@ func GetFilePathFromHash(h string) (string, string) { } func (fs *FileFSStore) generateTransactionPath(transID string) string { - var dir bytes.Buffer fmt.Fprintf(&dir, "%s%s", fs.RootDirectory, OSPathSeperator) for i := 0; i < 3; i++ { @@ -358,9 +357,7 @@ func (fs *FileFSStore) GetFileBlockForChallenge(allocationID string, fileData *F } func (fs *FileFSStore) GetFileBlock(allocationID string, fileData *FileInputData, blockNum, numBlocks int64) ([]byte, error) { - return fs.fileBlockGetter.GetFileBlock(fs, allocationID, fileData, blockNum, numBlocks) - } func (fs *FileFSStore) DeleteTempFile(allocationID string, fileData *FileInputData, connectionID string) error { @@ -454,9 +451,7 @@ func (fs *FileFSStore) DeleteDir(allocationID, dirPath, connectionID string) err return nil } -func (fs *FileFSStore) WriteFile(allocationID string, fileData *FileInputData, - infile multipart.File, connectionID string) (*FileOutputData, error) { - +func (fs *FileFSStore) WriteFile(allocationID string, fileData *FileInputData, infile multipart.File, connectionID string) (*FileOutputData, error) { if fileData.IsChunked { return fs.WriteChunk(allocationID, fileData, infile, connectionID) } @@ -486,7 +481,6 @@ func (fs *FileFSStore) WriteFile(allocationID string, fileData *FileInputData, } fileSize := int64(0) for { - written, err := io.CopyN(dest, tReader, CHUNK_SIZE) if err != io.EOF && err != nil { @@ -526,9 +520,7 @@ func (fs *FileFSStore) WriteFile(allocationID string, fileData *FileInputData, } // WriteChunk append chunk to temp file -func (fs *FileFSStore) WriteChunk(allocationID string, fileData *FileInputData, - infile multipart.File, connectionID string) (*FileOutputData, error) { - +func (fs *FileFSStore) WriteChunk(allocationID string, fileData *FileInputData, infile multipart.File, connectionID string) (*FileOutputData, error) { allocation, err := fs.SetupAllocation(allocationID, false) if err != nil { return nil, common.NewError("filestore_setup_error", "Error setting the fs store. "+err.Error()) diff --git a/code/go/0chain.net/blobbercore/filestore/mock_store.go b/code/go/0chain.net/blobbercore/filestore/mock_store.go index 2e5541eae..3eb356f76 100644 --- a/code/go/0chain.net/blobbercore/filestore/mock_store.go +++ b/code/go/0chain.net/blobbercore/filestore/mock_store.go @@ -19,7 +19,6 @@ var mockStore *MockStore func UseMock() { if mockStore == nil { mockStore = &MockStore{} - } fileStore = mockStore @@ -35,7 +34,6 @@ func (ms *MockStore) WriteFile(allocationID string, fileData *FileInputData, inf reader := io.TeeReader(infile, h) fileSize := int64(0) for { - written, err := io.CopyN(io.Discard, reader, fileData.ChunkSize) fileSize += written diff --git a/code/go/0chain.net/blobbercore/handler/file_command_add.go b/code/go/0chain.net/blobbercore/handler/file_command_add.go index 59db9ed6e..94c69a251 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_add.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_add.go @@ -52,7 +52,6 @@ func (cmd *AddFileCommand) IsAuthorized(ctx context.Context, req *http.Request, cmd.fileChanger = fileChanger return nil - } // ProcessContent flush file to FileStorage @@ -121,11 +120,9 @@ func (cmd *AddFileCommand) ProcessContent(ctx context.Context, req *http.Request // ProcessThumbnail flush thumbnail file to FileStorage if it has. func (cmd *AddFileCommand) ProcessThumbnail(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, connectionObj *allocation.AllocationChangeCollector) error { - thumbfile, thumbHeader, _ := req.FormFile("uploadThumbnailFile") if thumbHeader != nil { - defer thumbfile.Close() thumbInputData := &filestore.FileInputData{Name: thumbHeader.Filename, Path: cmd.fileChanger.Path} diff --git a/code/go/0chain.net/blobbercore/handler/file_command_delete.go b/code/go/0chain.net/blobbercore/handler/file_command_delete.go index d5bbab4e4..1cdb288dd 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_delete.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_delete.go @@ -46,7 +46,6 @@ func (cmd *FileCommandDelete) UpdateChange(ctx context.Context, connectionObj *a // ProcessContent flush file to FileStorage func (cmd *FileCommandDelete) ProcessContent(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, connectionObj *allocation.AllocationChangeCollector) (blobberhttp.UploadResult, error) { - deleteSize := cmd.exisitingFileRef.Size cmd.changeProcessor = &allocation.DeleteFileChange{ConnectionID: connectionObj.ConnectionID, @@ -67,7 +66,6 @@ func (cmd *FileCommandDelete) ProcessContent(ctx context.Context, req *http.Requ connectionObj.Size += cmd.allocationChange.Size return result, nil - } // ProcessThumbnail no thumbnail should be processed for delete. A deffered delete command has been added on ProcessContent diff --git a/code/go/0chain.net/blobbercore/handler/file_command_update.go b/code/go/0chain.net/blobbercore/handler/file_command_update.go index af07a536f..69b1fbd46 100644 --- a/code/go/0chain.net/blobbercore/handler/file_command_update.go +++ b/code/go/0chain.net/blobbercore/handler/file_command_update.go @@ -60,7 +60,6 @@ func (cmd *UpdateFileCommand) IsAuthorized(ctx context.Context, req *http.Reques // ProcessContent flush file to FileStorage func (cmd *UpdateFileCommand) ProcessContent(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, connectionObj *allocation.AllocationChangeCollector) (blobberhttp.UploadResult, error) { - result := blobberhttp.UploadResult{} result.Filename = cmd.fileChanger.Filename @@ -125,16 +124,13 @@ func (cmd *UpdateFileCommand) ProcessContent(ctx context.Context, req *http.Requ } return result, nil - } // ProcessThumbnail flush thumbnail file to FileStorage if it has. func (cmd *UpdateFileCommand) ProcessThumbnail(ctx context.Context, req *http.Request, allocationObj *allocation.Allocation, connectionObj *allocation.AllocationChangeCollector) error { - thumbfile, thumbHeader, _ := req.FormFile("uploadThumbnailFile") if thumbHeader != nil { - defer thumbfile.Close() thumbInputData := &filestore.FileInputData{Name: thumbHeader.Filename, Path: cmd.fileChanger.Path} @@ -151,7 +147,6 @@ func (cmd *UpdateFileCommand) ProcessThumbnail(ctx context.Context, req *http.Re } return nil - } func (cmd *UpdateFileCommand) reloadChange(connectionObj *allocation.AllocationChangeCollector) { diff --git a/code/go/0chain.net/blobbercore/handler/getallocation_integration_test.go b/code/go/0chain.net/blobbercore/handler/getallocation_integration_test.go index 171323bc1..4e44a5b9f 100644 --- a/code/go/0chain.net/blobbercore/handler/getallocation_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/getallocation_integration_test.go @@ -8,7 +8,6 @@ import ( ) func TestGetAllocation_IntegrationTest(t *testing.T) { - bClient, tdController := setupHandlerIntegrationTests(t) err := tdController.ClearDatabase() diff --git a/code/go/0chain.net/blobbercore/handler/getfilestats_integration_test.go b/code/go/0chain.net/blobbercore/handler/getfilestats_integration_test.go index 47d97f439..032c2d74c 100644 --- a/code/go/0chain.net/blobbercore/handler/getfilestats_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/getfilestats_integration_test.go @@ -82,5 +82,4 @@ func TestGetFilestats_IntegrationTest(t *testing.T) { t.Fatal("unexpected file name from GetFileStats rpc") } } - } diff --git a/code/go/0chain.net/blobbercore/handler/getobjecttree_integration_test.go b/code/go/0chain.net/blobbercore/handler/getobjecttree_integration_test.go index bb596a4a5..e4ea3d759 100644 --- a/code/go/0chain.net/blobbercore/handler/getobjecttree_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/getobjecttree_integration_test.go @@ -80,5 +80,4 @@ func TestBlobberGRPCService_GetObjectTree(t *testing.T) { t.Fatal("unexpected root name from GetObject") } } - } diff --git a/code/go/0chain.net/blobbercore/handler/getreferencepath_integration_test.go b/code/go/0chain.net/blobbercore/handler/getreferencepath_integration_test.go index f5344c43e..f21632fbc 100644 --- a/code/go/0chain.net/blobbercore/handler/getreferencepath_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/getreferencepath_integration_test.go @@ -11,7 +11,6 @@ import ( ) func TestBlobberGRPCService_GetReferencePath(t *testing.T) { - bClient, tdController := setupHandlerIntegrationTests(t) allocationTx := randString(32) diff --git a/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go b/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go index 49f676574..d2efa87b9 100644 --- a/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/grpc_handler_test.go @@ -123,7 +123,6 @@ func Test_GetAllocation(t *testing.T) { sqlmock.NewRows([]string{"id", "allocation_id"}). AddRow(alloc.Terms[0].ID, alloc.Terms[0].AllocationID), ) - }, args: args{ allocationR: &blobbergrpc.GetAllocationRequest{ @@ -154,7 +153,6 @@ func Test_GetAllocation(t *testing.T) { sqlmock.NewRows([]string{"id", "allocation_id"}). AddRow(alloc.Terms[0].ID, alloc.Terms[0].AllocationID), ) - }, args: args{ allocationR: &blobbergrpc.GetAllocationRequest{ @@ -185,7 +183,6 @@ func Test_GetAllocation(t *testing.T) { sqlmock.NewRows([]string{"id", "allocation_id"}). AddRow(expiredAlloc.Terms[0].ID, expiredAlloc.Terms[0].AllocationID), ) - }, args: args{ allocationR: &blobbergrpc.GetAllocationRequest{ diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index bf4df07a3..e1c90b8f7 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -40,7 +40,6 @@ func GetMetaDataStore() datastore.Store { /*SetupHandlers sets up the necessary API end points */ func SetupHandlers(r *mux.Router) { - r.Use(useRecovery, useCors, common.UseUserRateLimit) //object operations @@ -90,9 +89,7 @@ func WithReadOnlyConnection(handler common.JSONResponderF) common.JSONResponderF } func WithConnection(handler common.JSONResponderF) common.JSONResponderF { - return func(ctx context.Context, r *http.Request) ( - resp interface{}, err error) { - + return func(ctx context.Context, r *http.Request) (resp interface{}, err error) { ctx = GetMetaDataStore().CreateTransaction(ctx) resp, err = handler(ctx, r) diff --git a/code/go/0chain.net/blobbercore/handler/handler_test.go b/code/go/0chain.net/blobbercore/handler/handler_test.go index 1de30deb5..3149122e9 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/handler_test.go @@ -1361,7 +1361,6 @@ func TestHandlers_Requiring_Signature(t *testing.T) { mock.ExpectExec(regexp.QuoteMeta(`UPDATE "marketplace_share_info"`)). WithArgs(true, "da4b54d934890aa415bb043ce1126f2e30a96faf63a4c65c25bbddcb32824d77", filePathHash). WillReturnResult(sqlmock.NewResult(0, 1)) - }, wantCode: http.StatusOK, wantBody: "{\"message\":\"Path successfully removed from allocation\",\"status\":204}\n", @@ -1441,7 +1440,6 @@ func TestHandlers_Requiring_Signature(t *testing.T) { mock.ExpectExec(regexp.QuoteMeta(`UPDATE "marketplace_share_info"`)). WithArgs(true, "da4b54d934890aa415bb043ce1126f2e30a96faf63a4c65c25bbddcb32824d77", filePathHash). WillReturnResult(sqlmock.NewResult(0, 0)) - }, wantCode: http.StatusOK, wantBody: "{\"message\":\"Path not found\",\"status\":404}\n", @@ -1526,7 +1524,6 @@ func TestHandlers_Requiring_Signature(t *testing.T) { filePathHash := fileref.GetReferenceLookup(alloc.Tx, "/file.txt") mock.ExpectQuery(regexp.QuoteMeta(`SELECT * FROM "reference_objects" WHERE`)). WithArgs(alloc.ID, filePathHash).WillReturnError(gorm.ErrRecordNotFound) - }, wantCode: http.StatusBadRequest, wantBody: "{\"code\":\"download_file\",\"error\":\"download_file: invalid file path: record not found\"}\n\n", @@ -2305,7 +2302,6 @@ func TestHandlers_Requiring_Signature(t *testing.T) { sqlmock.NewRows([]string{"path", "type", "path_hash", "lookup_hash", "content_hash", "encrypted_key", "parent_path"}). AddRow("/folder1", "d", rootPathHash, rootPathHash, "content_hash", "", "/"), ) - }, wantCode: http.StatusBadRequest, wantBody: "{\"code\":\"download_file\",\"error\":\"download_file: cannot verify auth ticket: invalid_parameters: Auth ticket is not valid for the resource being requested\"}\n\n", diff --git a/code/go/0chain.net/blobbercore/handler/helper_integration_test.go b/code/go/0chain.net/blobbercore/handler/helper_integration_test.go index b06cc28b8..e8f61578e 100644 --- a/code/go/0chain.net/blobbercore/handler/helper_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/helper_integration_test.go @@ -33,7 +33,6 @@ const RetryAttempts = 8 const RetryTimeout = 3 func randString(n int) string { - const hexLetters = "abcdef0123456789" var sb strings.Builder @@ -503,7 +502,6 @@ VALUES (1234,'exampleId','exampleId:examplePath','exampleId:examplePath','d','ro } func GeneratePubPrivateKey(t *testing.T) (pubKey, privateKey string, signScheme zcncrypto.SignatureScheme) { - signScheme = zcncrypto.NewSignatureScheme("bls0chain") wallet, err := signScheme.GenerateKeys() if err != nil { @@ -516,7 +514,6 @@ func GeneratePubPrivateKey(t *testing.T) (pubKey, privateKey string, signScheme } func setupIntegrationTestConfig(t *testing.T) { - pwd, err := os.Getwd() if err != nil { t.Fatal(err) diff --git a/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go b/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go index c8343adf3..68adb0a79 100644 --- a/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go +++ b/code/go/0chain.net/blobbercore/handler/listentities_integration_test.go @@ -86,5 +86,4 @@ func TestBlobberGRPCService_ListEntities(t *testing.T) { t.Fatal("unexpected path from ListEntities rpc") } } - } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go index 8103ad612..518b19d31 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_grpc_handler.go @@ -88,7 +88,6 @@ func (b *blobberGRPCService) DownloadFile(ctx context.Context, req *blobbergrpc. } func (b *blobberGRPCService) UploadFile(ctx context.Context, req *blobbergrpc.UploadFileRequest) (*blobbergrpc.UploadFileResponse, error) { - r, err := convert.WriteFileGRPCToHTTP(req) if err != nil { return nil, err diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index 5eb218d6d..32d48d1f8 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -39,9 +39,7 @@ import ( "go.uber.org/zap" ) -func readPreRedeem(ctx context.Context, alloc *allocation.Allocation, - numBlocks, pendNumBlocks int64, payerID string) (err error) { - +func readPreRedeem(ctx context.Context, alloc *allocation.Allocation, numBlocks, pendNumBlocks int64, payerID string) (err error) { if numBlocks == 0 { return } @@ -105,9 +103,7 @@ func readPreRedeem(ctx context.Context, alloc *allocation.Allocation, return } -func writePreRedeem(ctx context.Context, alloc *allocation.Allocation, - writeMarker *writemarker.WriteMarker, payerID string) (err error) { - +func writePreRedeem(ctx context.Context, alloc *allocation.Allocation, writeMarker *writemarker.WriteMarker, payerID string) (err error) { // check out read pool tokens if read_price > 0 var ( db = datastore.GetStore().GetTransaction(ctx) @@ -178,11 +174,7 @@ func writePreRedeem(ctx context.Context, alloc *allocation.Allocation, return } -func (fsh *StorageHandler) DownloadFile( - ctx context.Context, - r *http.Request, -) (resp interface{}, err error) { - +func (fsh *StorageHandler) DownloadFile(ctx context.Context, r *http.Request) (resp interface{}, err error) { // get client and allocation ids var ( clientID = ctx.Value(constants.ContextKeyClient).(string) @@ -359,9 +351,7 @@ func (fsh *StorageHandler) DownloadFile( } } - if latestRM != nil && - latestRM.ReadCounter+(numBlocks) != readMarker.ReadCounter { - + if latestRM != nil && latestRM.ReadCounter+(numBlocks) != readMarker.ReadCounter { var response = &blobberhttp.DownloadResponse{ Success: false, LatestRM: latestRM, @@ -433,7 +423,6 @@ func (fsh *StorageHandler) DownloadFile( } if len(fileref.EncryptedKey) > 0 && authToken != nil { - // should not happen, just in case if shareInfo == nil { return nil, errors.New("client does not have permission to download the file. share does not exist") @@ -491,10 +480,10 @@ func (fsh *StorageHandler) DownloadFile( } func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*blobberhttp.CommitResult, error) { - if r.Method == "GET" { return nil, common.NewError("invalid_method", "Invalid method used for the upload URL. Use POST instead") } + allocationTx := ctx.Value(constants.ContextKeyAllocation).(string) clientID := ctx.Value(constants.ContextKeyClient).(string) clientKey := ctx.Value(constants.ContextKeyClientKey).(string) @@ -752,9 +741,7 @@ func (fsh *StorageHandler) RenameObject(ctx context.Context, r *http.Request) (i return result, nil } -func (fsh *StorageHandler) UpdateObjectAttributes(ctx context.Context, - r *http.Request) (resp interface{}, err error) { - +func (fsh *StorageHandler) UpdateObjectAttributes(ctx context.Context, r *http.Request) (resp interface{}, err error) { if r.Method != http.MethodPost { return nil, common.NewError("update_object_attributes", "Invalid method used. Use POST instead") @@ -1067,7 +1054,6 @@ func (fsh *StorageHandler) CreateDir(ctx context.Context, r *http.Request) (*blo //WriteFile stores the file into the blobber files system from the HTTP request func (fsh *StorageHandler) WriteFile(ctx context.Context, r *http.Request) (*blobberhttp.UploadResult, error) { - if r.Method == "GET" { return nil, common.NewError("invalid_method", "Invalid method used for the upload URL. Use multi-part form POST / PUT / DELETE / PATCH instead") } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler_bench_test.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler_bench_test.go index 2020ebaa9..4763c426d 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler_bench_test.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler_bench_test.go @@ -16,7 +16,6 @@ import ( ) func BenchmarkUploadFileWithDisk(b *testing.B) { - KB := 1024 MB := 1024 * KB //GB := 1024 * MB @@ -55,7 +54,6 @@ func BenchmarkUploadFileWithDisk(b *testing.B) { for _, bm := range benchmarks { b.Run(bm.Name, func(b *testing.B) { - fileName := strings.Replace(bm.Name, " ", "_", -1) + ".txt" chunkBytes := mock.GenerateRandomBytes(bm.ChunkSize) fileMeta := &sdk.FileMeta{ @@ -98,15 +96,12 @@ func BenchmarkUploadFileWithDisk(b *testing.B) { b.Fatal(err) return } - } }) } - } func BenchmarkUploadFileWithNoDisk(b *testing.B) { - KB := 1024 MB := 1024 * KB //GB := 1024 * MB @@ -146,7 +141,6 @@ func BenchmarkUploadFileWithNoDisk(b *testing.B) { for _, bm := range benchmarks { b.Run(bm.Name, func(b *testing.B) { - fileName := strings.Replace(bm.Name, " ", "_", -1) + ".txt" chunkBytes := mock.GenerateRandomBytes(bm.ChunkSize) fileMeta := &sdk.FileMeta{ @@ -180,7 +174,6 @@ func BenchmarkUploadFileWithNoDisk(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - ctx := GetMetaDataStore().CreateTransaction(context.TODO()) ctx = mock.SetupHandlerContext(ctx, req, allocationID) @@ -190,9 +183,7 @@ func BenchmarkUploadFileWithNoDisk(b *testing.B) { b.Fatal(err) return } - } }) } - } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler_test.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler_test.go index 82a6b4e02..f4dc23b8d 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler_test.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler_test.go @@ -589,7 +589,6 @@ func TestDownloadFile(t *testing.T) { require.EqualValues(t, test.want.errMsg, err.Error()) return } - }, ) } diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 302f3d4c3..7e45ec694 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -94,7 +94,6 @@ func getStorageNode() (*transaction.StorageNode, error) { // Add or update blobber on blockchain func BlobberAdd(ctx context.Context) (string, error) { - // initialize storage node (ie blobber) txn, err := transaction.NewTransactionEntity() if err != nil { @@ -131,7 +130,6 @@ func BlobberAdd(ctx context.Context) (string, error) { var ErrBlobberHasRemoved = errors.New("blobber has removed") func TransactionVerify(txnHash string) (t *transaction.Transaction, err error) { - for i := 0; i < util.MAX_RETRIES; i++ { time.Sleep(transaction.SLEEP_FOR_TXN_CONFIRMATION * time.Second) if t, err = transaction.VerifyTransaction(txnHash, chain.GetServerChain()); err == nil { diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index bf7cd3754..3c2b8c912 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -36,9 +36,7 @@ const ( type StorageHandler struct{} // verifyAllocation try to get allocation from postgres.if it doesn't exists, get it from sharders, and insert it into postgres. -func (fsh *StorageHandler) verifyAllocation(ctx context.Context, tx string, - readonly bool) (alloc *allocation.Allocation, err error) { - +func (fsh *StorageHandler) verifyAllocation(ctx context.Context, tx string, readonly bool) (alloc *allocation.Allocation, err error) { if tx == "" { return nil, common.NewError("verify_allocation", "invalid allocation id") @@ -424,7 +422,6 @@ func (fsh *StorageHandler) GetFileStats(ctx context.Context, r *http.Request) (i } func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (*blobberhttp.ListResult, error) { - clientID := ctx.Value(constants.ContextKeyClient).(string) allocationTx := ctx.Value(constants.ContextKeyAllocation).(string) allocationObj, err := fsh.verifyAllocation(ctx, allocationTx, false) @@ -506,7 +503,6 @@ func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (* result.Meta["collaborators"] = []reference.Collaborator{} } result.Meta["collaborators"] = append(result.Meta["collaborators"].([]reference.Collaborator), collaborators...) - } return &result, nil @@ -829,7 +825,6 @@ func (fsh *StorageHandler) GetRefs(ctx context.Context, r *http.Request) (*blobb } default: return nil, common.NewError("incomplete_request", "path, pathHash or authTicket is required") - } path = pathRef.Path diff --git a/code/go/0chain.net/blobbercore/handler/worker.go b/code/go/0chain.net/blobbercore/handler/worker.go index 4b27f760d..cb161e864 100644 --- a/code/go/0chain.net/blobbercore/handler/worker.go +++ b/code/go/0chain.net/blobbercore/handler/worker.go @@ -66,8 +66,8 @@ func cleanupTempFiles(ctx context.Context) { var openConnectionsToDelete []allocation.AllocationChangeCollector db.Table((&allocation.AllocationChangeCollector{}).TableName()).Where("updated_at < ? AND status IN (?,?)", then, allocation.NewConnection, allocation.InProgressConnection).Preload("Changes").Find(&openConnectionsToDelete) - for _, connection := range openConnectionsToDelete { + for _, connection := range openConnectionsToDelete { Logger.Info("Deleting temp files for the connection", zap.Any("connection", connection.ConnectionID)) connection.ComputeProperties() nctx := datastore.GetStore().CreateTransaction(ctx) @@ -171,7 +171,6 @@ func startMoveColdDataToCloud(ctx context.Context) { return case <-ticker.C: if !iterInprogress { - moveColdDataToCloud(ctx, coldStorageMinFileSize, limit) iterInprogress = false stats.LastMinioScan = time.Now() diff --git a/code/go/0chain.net/blobbercore/handler/zcncore.go b/code/go/0chain.net/blobbercore/handler/zcncore.go index e1bb3a7c8..1a50293bb 100644 --- a/code/go/0chain.net/blobbercore/handler/zcncore.go +++ b/code/go/0chain.net/blobbercore/handler/zcncore.go @@ -152,5 +152,4 @@ func Transfer(token float64, clientID string) error { return common.NewError("call_transfer_failed", "Failed to verify send transaction with statusBar success failed") } return nil - } diff --git a/code/go/0chain.net/blobbercore/mock/ctx.go b/code/go/0chain.net/blobbercore/mock/ctx.go index 7573aa48f..b41344c2e 100644 --- a/code/go/0chain.net/blobbercore/mock/ctx.go +++ b/code/go/0chain.net/blobbercore/mock/ctx.go @@ -9,7 +9,6 @@ import ( ) func SetupHandlerContext(ctx context.Context, r *http.Request, allocation string) context.Context { - ctx = context.WithValue(ctx, constants.ContextKeyClient, r.Header.Get(common.ClientHeader)) ctx = context.WithValue(ctx, constants.ContextKeyClientKey, diff --git a/code/go/0chain.net/blobbercore/mock/init.go b/code/go/0chain.net/blobbercore/mock/init.go index 768e21bd9..2564584ad 100644 --- a/code/go/0chain.net/blobbercore/mock/init.go +++ b/code/go/0chain.net/blobbercore/mock/init.go @@ -18,7 +18,6 @@ const ( // ) func NewBlobberClient() *blobber.Blobber { - z := sdks.New("9a566aa4f8e8c342fed97c8928040a21f21b8f574e5782c28568635ba9c75a85", "40cd10039913ceabacf05a7c60e1ad69bb2964987bc50f77495e514dc451f907c3d8ebcdab20eedde9c8f39b9a1d66609a637352f318552fb69d4b3672516d1a", "bls0chain") err := z.InitWallet(zboxWallet) if err != nil { diff --git a/code/go/0chain.net/blobbercore/readmarker/entity.go b/code/go/0chain.net/blobbercore/readmarker/entity.go index ee96680dd..f0e6a20de 100644 --- a/code/go/0chain.net/blobbercore/readmarker/entity.go +++ b/code/go/0chain.net/blobbercore/readmarker/entity.go @@ -126,7 +126,6 @@ func SaveLatestReadMarker(ctx context.Context, rm *ReadMarker, isCreate bool) er // Sync read marker with 0chain to be sure its correct. func (rm *ReadMarkerEntity) Sync(ctx context.Context) (err error) { - var db = datastore.GetStore().GetTransaction(ctx) ////////////////////////////////////////////////////////////////////////////// @@ -166,11 +165,8 @@ func (rm *ReadMarkerEntity) Sync(ctx context.Context) (err error) { return } -// UpdateStatus updates read marker status and all related on successful -// redeeming. -func (rm *ReadMarkerEntity) UpdateStatus(ctx context.Context, - rps []*allocation.ReadPool, txOutput, redeemTxn string) (err error) { - +// UpdateStatus updates read marker status and all related on successful redeeming. +func (rm *ReadMarkerEntity) UpdateStatus(ctx context.Context, rps []*allocation.ReadPool, txOutput, redeemTxn string) (err error) { var redeems []allocation.ReadPoolRedeem if err = json.Unmarshal([]byte(txOutput), &redeems); err != nil { Logger.Error("update read redeeming status: can't decode transaction"+ diff --git a/code/go/0chain.net/blobbercore/readmarker/protocol.go b/code/go/0chain.net/blobbercore/readmarker/protocol.go index e5bc90bdd..0aec3fd3f 100644 --- a/code/go/0chain.net/blobbercore/readmarker/protocol.go +++ b/code/go/0chain.net/blobbercore/readmarker/protocol.go @@ -70,7 +70,6 @@ func (rm *ReadMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.All // returns difference between latest redeemed read marker and current one // (till not redeemed). func (rme *ReadMarkerEntity) PendNumBlocks() (pendNumBlocks int64, err error) { - if !rme.RedeemRequired { return // (0, nil), everything is already redeemed } @@ -94,13 +93,11 @@ func (rme *ReadMarkerEntity) PendNumBlocks() (pendNumBlocks int64, err error) { pendNumBlocks = rme.LatestRM.ReadCounter - prev.ReadCounter return - } // getNumBlocks to redeem (difference between the previous RM and the // current one) func (rme *ReadMarkerEntity) getNumBlocks() (numBlocks int64, err error) { - if rme.LatestRM == nil { return 0, common.NewErrorf("rme_get_num_blocks", "missing latest read marker (nil)") @@ -126,10 +123,7 @@ func (rme *ReadMarkerEntity) getNumBlocks() (numBlocks int64, err error) { // a redeeming transaction regarding cache, pending reads (regardless since // pending reads is what we are going to redeem) and requesting 0chain to // refresh read pools -func (rme *ReadMarkerEntity) preRedeem(ctx context.Context, - alloc *allocation.Allocation, numBlocks int64) ( - rps []*allocation.ReadPool, err error) { - +func (rme *ReadMarkerEntity) preRedeem(ctx context.Context, alloc *allocation.Allocation, numBlocks int64) (rps []*allocation.ReadPool, err error) { // check out read pool tokens if read_price > 0 var ( db = datastore.GetStore().GetTransaction(ctx) @@ -198,9 +192,7 @@ func (rme *ReadMarkerEntity) preRedeem(ctx context.Context, } // RedeemReadMarker redeems the read marker. -func (rme *ReadMarkerEntity) RedeemReadMarker(ctx context.Context) ( - err error) { - +func (rme *ReadMarkerEntity) RedeemReadMarker(ctx context.Context) (err error) { if rme.LatestRM.Suspend == rme.LatestRM.ReadCounter { // suspended read marker, no tokens in related read pools // don't request 0chain to refresh the read pools; let user diff --git a/code/go/0chain.net/blobbercore/readmarker/readmarker.go b/code/go/0chain.net/blobbercore/readmarker/readmarker.go index 3ad1f495d..29198b2d1 100644 --- a/code/go/0chain.net/blobbercore/readmarker/readmarker.go +++ b/code/go/0chain.net/blobbercore/readmarker/readmarker.go @@ -16,7 +16,6 @@ func redeemReadMarker(ctx context.Context) { if r := recover(); r != nil { logging.Logger.Error("[recover] redeemReadMarker", zap.Any("err", r)) } - }() if !iterInprogress { diff --git a/code/go/0chain.net/blobbercore/readmarker/worker.go b/code/go/0chain.net/blobbercore/readmarker/worker.go index 7f30f838a..4b77669e9 100644 --- a/code/go/0chain.net/blobbercore/readmarker/worker.go +++ b/code/go/0chain.net/blobbercore/readmarker/worker.go @@ -17,9 +17,7 @@ func SetupWorkers(ctx context.Context) { go startRedeemMarkers(ctx) } -func RedeemReadMarker(ctx context.Context, rmEntity *ReadMarkerEntity) ( - err error) { - +func RedeemReadMarker(ctx context.Context, rmEntity *ReadMarkerEntity) (err error) { Logger.Info("Redeeming the read marker", zap.Any("rm", rmEntity.LatestRM)) var params = make(map[string]string) @@ -38,13 +36,10 @@ func RedeemReadMarker(ctx context.Context, rmEntity *ReadMarkerEntity) ( if err != nil { Logger.Error("Error from sc rest api call", zap.Error(err)) return // error - } else if err = json.Unmarshal(latestRMBytes, &latestRM); err != nil { Logger.Error("Error from unmarshal of rm bytes", zap.Error(err)) return // error - } else if latestRM.ReadCounter > 0 && latestRM.ReadCounter >= rmEntity.LatestRM.ReadCounter { - Logger.Info("updating the local state to match the block chain") if err = SaveLatestReadMarker(ctx, &latestRM, false); err != nil { return // error @@ -87,5 +82,4 @@ func startRedeemMarkers(ctx context.Context) { redeemReadMarker(ctx) } } - } diff --git a/code/go/0chain.net/blobbercore/reference/object.go b/code/go/0chain.net/blobbercore/reference/object.go index e538e020c..28575d38d 100644 --- a/code/go/0chain.net/blobbercore/reference/object.go +++ b/code/go/0chain.net/blobbercore/reference/object.go @@ -28,13 +28,11 @@ func LoadObjectTree(ctx context.Context, allocationID, path string) (*Ref, error err := db.FindInBatches(&objects, 100, func(tx *gorm.DB, batch int) error { // batch processing found records for _, object := range objects { - obejctTreeNodes[object.ParentPath] = append(obejctTreeNodes[object.ParentPath], object) for _, child := range obejctTreeNodes[object.Path] { object.AddChild(child) } - } return nil @@ -57,16 +55,13 @@ func LoadObjectTree(ctx context.Context, allocationID, path string) (*Ref, error } return nil, common.NewError("invalid_ref_tree", "/ is missing or invalid") - } return nil, common.NewError("invalid_ref_tree", "/ is missing") - } // DeleteObject delete object from tree, and return tree root and deleted content hash list func DeleteObject(ctx context.Context, allocationID, path string) (*Ref, map[string]bool, error) { - rootRef, err := LoadObjectTree(ctx, allocationID, "/") if err != nil { return nil, nil, err @@ -126,5 +121,4 @@ func DeleteObject(ctx context.Context, allocationID, path string) (*Ref, map[str } } return nil, nil, common.NewError("invalid_reference_path", "Invalid reference path from the blobber") - } diff --git a/code/go/0chain.net/blobbercore/reference/objectpath.go b/code/go/0chain.net/blobbercore/reference/objectpath.go index a4193a750..c36a79e72 100644 --- a/code/go/0chain.net/blobbercore/reference/objectpath.go +++ b/code/go/0chain.net/blobbercore/reference/objectpath.go @@ -19,7 +19,6 @@ type ObjectPath struct { // TODO needs to be refactored, current implementation can probably be heavily simplified func GetObjectPath(ctx context.Context, allocationID string, blockNum int64) (*ObjectPath, error) { - rootRef, err := GetRefWithSortedChildren(ctx, allocationID, "/") if err != nil { return nil, common.NewError("invalid_dir_struct", "Allocation root corresponds to an invalid directory structure") @@ -58,7 +57,6 @@ func GetObjectPath(ctx context.Context, allocationID string, blockNum int64) (*O } curResult["list"] = list for idx, child := range curRef.Children { - if child.NumBlocks < remainingBlocks { remainingBlocks -= child.NumBlocks continue diff --git a/code/go/0chain.net/blobbercore/reference/ref.go b/code/go/0chain.net/blobbercore/reference/ref.go index 970e1fd52..80deec905 100644 --- a/code/go/0chain.net/blobbercore/reference/ref.go +++ b/code/go/0chain.net/blobbercore/reference/ref.go @@ -212,7 +212,6 @@ func Mkdir(ctx context.Context, allocationID, destpath string) (*Ref, error) { } return dirRef, nil - } // GetReference get FileRef with allcationID and path from postgres @@ -499,7 +498,6 @@ func GetListingFieldsMap(refEntity interface{}, tagName string) map[string]inter for k, v := range listMap { result[k] = v } - } } else { fieldValue := v.FieldByName(field.Name).Interface() @@ -508,7 +506,6 @@ func GetListingFieldsMap(refEntity interface{}, tagName string) map[string]inter } result[tag] = fieldValue } - } return result } diff --git a/code/go/0chain.net/blobbercore/reference/referencepath.go b/code/go/0chain.net/blobbercore/reference/referencepath.go index 4f122c3ae..56eceb367 100644 --- a/code/go/0chain.net/blobbercore/reference/referencepath.go +++ b/code/go/0chain.net/blobbercore/reference/referencepath.go @@ -64,7 +64,6 @@ func GetReferencePathFromPaths(ctx context.Context, allocationID string, paths [ refMap := make(map[string]*Ref) refMap[rootRef.Path] = rootRef for i := 1; i < len(refs); i++ { - if _, ok := refMap[refs[i].ParentPath]; !ok { return nil, common.NewError("invalid_dir_tree", "DB has invalid tree.") } @@ -182,7 +181,6 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string, refs = &pRefs if len(pRefs) > 0 { newOffsetPath = pRefs[len(pRefs)-1].Path - } totalPages = int(math.Ceil(float64(totalRows) / float64(pageLimit))) return @@ -282,7 +280,6 @@ func GetDeletedRefs(ctx context.Context, allocationID, updatedDate, offsetPath, }() go func() { - db2 = db2.Model(&Ref{}).Unscoped().Where("allocation_id = ?", allocationID) if updatedDate == "" { @@ -299,7 +296,6 @@ func GetDeletedRefs(ctx context.Context, allocationID, updatedDate, offsetPath, lastIdx := len(pRefs) - 1 newOffsetDate = pRefs[lastIdx].DeletedAt.Time.Format(dateLayOut) newOffsetPath = pRefs[lastIdx].Path - } refs = &pRefs totalPages = int(math.Ceil(float64(totalRows) / float64(pageLimit))) diff --git a/code/go/0chain.net/blobbercore/stats/blobberstats.go b/code/go/0chain.net/blobbercore/stats/blobberstats.go index 831841c6f..0c30bafa1 100644 --- a/code/go/0chain.net/blobbercore/stats/blobberstats.go +++ b/code/go/0chain.net/blobbercore/stats/blobberstats.go @@ -230,7 +230,6 @@ func (bs *BlobberStats) loadFailedChallengeList(ctx context.Context) { } func (bs *BlobberStats) loadStats(ctx context.Context) { - const sel = ` COALESCE (SUM (reference_objects.size), 0) AS files_size, COALESCE (SUM (reference_objects.thumbnail_size), 0) AS thumbnails_size, @@ -267,7 +266,6 @@ func (bs *BlobberStats) loadStats(ctx context.Context) { } func (bs *BlobberStats) loadMinioStats(ctx context.Context) { - var ( db = datastore.GetStore().GetTransaction(ctx) row *sql.Row @@ -376,7 +374,6 @@ func (bs *BlobberStats) loadAllocationStats(ctx context.Context) { } func (bs *BlobberStats) loadChallengeStats(ctx context.Context) { - var ( db = datastore.GetStore().GetTransaction(ctx) rows *sql.Rows @@ -429,7 +426,6 @@ func (bs *BlobberStats) loadChallengeStats(ctx context.Context) { zap.Error(err)) return } - } func (bs *BlobberStats) loadAllocationChallengeStats(ctx context.Context) { @@ -499,11 +495,9 @@ func (bs *BlobberStats) loadAllocationChallengeStats(ctx context.Context) { zap.Error(err)) return } - } func loadAllocationList(ctx context.Context) (interface{}, error) { - var ( allocations = make([]AllocationId, 0) db = datastore.GetStore().GetTransaction(ctx) @@ -550,9 +544,7 @@ type ReadMarkerEntity struct { RedeemRequired bool `gorm:"column:redeem_required"` } -func loadAllocReadMarkersStat(ctx context.Context, allocationID string) ( - rms *ReadMarkersStat, err error) { - +func loadAllocReadMarkersStat(ctx context.Context, allocationID string) (rms *ReadMarkersStat, err error) { var ( db = datastore.GetStore().GetTransaction(ctx) rme ReadMarkerEntity @@ -601,9 +593,7 @@ const ( Failed // 2 ) -func loadAllocWriteMarkerStat(ctx context.Context, allocationID string) ( - wms *WriteMarkersStat, err error) { - +func loadAllocWriteMarkerStat(ctx context.Context, allocationID string) (wms *WriteMarkersStat, err error) { var ( db = datastore.GetStore().GetTransaction(ctx) rows *sql.Rows diff --git a/code/go/0chain.net/blobbercore/writemarker/entity.go b/code/go/0chain.net/blobbercore/writemarker/entity.go index dc23790ac..586efef35 100644 --- a/code/go/0chain.net/blobbercore/writemarker/entity.go +++ b/code/go/0chain.net/blobbercore/writemarker/entity.go @@ -51,10 +51,7 @@ func (WriteMarkerEntity) TableName() string { return "write_markers" } -func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, - status WriteMarkerStatus, statusMessage string, redeemTxn string) ( - err error) { - +func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, status WriteMarkerStatus, statusMessage, redeemTxn string) (err error) { db := datastore.GetStore().GetTransaction(ctx) statusBytes, _ := json.Marshal(statusMessage) diff --git a/code/go/0chain.net/blobbercore/writemarker/protocol.go b/code/go/0chain.net/blobbercore/writemarker/protocol.go index e08b3e232..5571cf005 100644 --- a/code/go/0chain.net/blobbercore/writemarker/protocol.go +++ b/code/go/0chain.net/blobbercore/writemarker/protocol.go @@ -73,7 +73,6 @@ func (wm *WriteMarkerEntity) VerifyMarker(ctx context.Context, sa *allocation.Al } func (wm *WriteMarkerEntity) RedeemMarker(ctx context.Context) error { - if len(wm.CloseTxnID) > 0 { t, err := transaction.VerifyTransaction(wm.CloseTxnID, chain.GetServerChain()) if err == nil { diff --git a/code/go/0chain.net/blobbercore/writemarker/worker.go b/code/go/0chain.net/blobbercore/writemarker/worker.go index 9d2a73b74..151e78d2a 100644 --- a/code/go/0chain.net/blobbercore/writemarker/worker.go +++ b/code/go/0chain.net/blobbercore/writemarker/worker.go @@ -78,5 +78,4 @@ func startRedeemWriteMarkers(ctx context.Context) { redeemWriteMarker(ctx) } } - } diff --git a/code/go/0chain.net/conductor/conductrpc/entity.go b/code/go/0chain.net/conductor/conductrpc/entity.go index fd983d2e4..ddf89fdf5 100644 --- a/code/go/0chain.net/conductor/conductrpc/entity.go +++ b/code/go/0chain.net/conductor/conductrpc/entity.go @@ -35,7 +35,6 @@ func (e *Entity) SetState(state *State) { // NewEntity creates RPC client for integration tests. func NewEntity(id string) (e *Entity) { - var ( client, err = newClient(viper.GetString("integration_tests.address")) interval = viper.GetDuration("integration_tests.lock_interval") diff --git a/code/go/0chain.net/conductor/conductrpc/state.go b/code/go/0chain.net/conductor/conductrpc/state.go index 7f723162f..5d3464e09 100644 --- a/code/go/0chain.net/conductor/conductrpc/state.go +++ b/code/go/0chain.net/conductor/conductrpc/state.go @@ -60,7 +60,6 @@ func (s *State) copy() (cp *State) { //nolint:unused,deadcode // might be used l cp = new(State) (*cp) = (*s) return - } func (s *State) send(poll chan *State) { //nolint:unused,deadcode // might be used later? diff --git a/code/go/0chain.net/core/common/handler.go b/code/go/0chain.net/core/common/handler.go index 5b2bab5e0..14233ddac 100644 --- a/code/go/0chain.net/core/common/handler.go +++ b/code/go/0chain.net/core/common/handler.go @@ -71,7 +71,6 @@ func ToByteStream(handler JSONResponderF) ReqRespHandlerf { } else { http.Error(w, err.Error(), 400) } - } else if data != nil { rawdata, ok := data.([]byte) if ok { diff --git a/code/go/0chain.net/core/common/rate_limiter.go b/code/go/0chain.net/core/common/rate_limiter.go index d1201be9d..c5a16db5c 100644 --- a/code/go/0chain.net/core/common/rate_limiter.go +++ b/code/go/0chain.net/core/common/rate_limiter.go @@ -54,7 +54,6 @@ func (r *GRPCRateLimiter) Limit() bool { //UserRateLimit - rate limiting for end user handlers func UserRateLimit(handler ReqRespHandlerf) ReqRespHandlerf { - if !userRateLimit.RateLimit { return handler } diff --git a/code/go/0chain.net/core/lock/lock.go b/code/go/0chain.net/core/lock/lock.go index dc673e52c..482963028 100644 --- a/code/go/0chain.net/core/lock/lock.go +++ b/code/go/0chain.net/core/lock/lock.go @@ -76,8 +76,6 @@ func cleanUnusedMutexs() { func startWorker() { for { time.Sleep(MutexCleanInterval) - cleanUnusedMutexs() - } } diff --git a/code/go/0chain.net/core/lock/lock_test.go b/code/go/0chain.net/core/lock/lock_test.go index d78eaff07..cdcc276ad 100644 --- a/code/go/0chain.net/core/lock/lock_test.go +++ b/code/go/0chain.net/core/lock/lock_test.go @@ -8,11 +8,9 @@ import ( ) func TestLock(t *testing.T) { - max := 100 for i := 0; i < max; i++ { - lock1 := GetMutex("testlock", strconv.Itoa(i)) lock1.Lock() @@ -39,5 +37,4 @@ func TestLock(t *testing.T) { _, ok := lockPool["testlock:"+strconv.Itoa(i)] require.Equal(t, false, ok) } - } diff --git a/code/go/0chain.net/core/logging/logger.go b/code/go/0chain.net/core/logging/logger.go index 68c6c1735..1e73d9571 100644 --- a/code/go/0chain.net/core/logging/logger.go +++ b/code/go/0chain.net/core/logging/logger.go @@ -31,7 +31,6 @@ func InitLogging(mode, logDir, logFile string) { cfg.EncoderConfig.StacktraceKey = "stacktrace" logWriter = zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), logWriter) - } _ = cfg.Level.UnmarshalText([]byte(viper.GetString("logging.level"))) cfg.Encoding = "console" diff --git a/code/go/0chain.net/core/transaction/http.go b/code/go/0chain.net/core/transaction/http.go index 30d2792f6..57ba421de 100644 --- a/code/go/0chain.net/core/transaction/http.go +++ b/code/go/0chain.net/core/transaction/http.go @@ -87,7 +87,6 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] } for _, sharder := range selectedSharders { - u := fmt.Sprintf("%v/%v%v%v", sharder, SC_REST_API_URL, scAddress, relativePath) urls = append(urls, u+"?"+q.Encode()) @@ -109,7 +108,6 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] var msgList = make([]string, 1, numSharders) r := resty.New(transport, func(req *http.Request, resp *http.Response, cancelFunc context.CancelFunc, err error) error { - if err != nil { //network issue msgList = append(msgList, err.Error()) return err @@ -123,7 +121,6 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] msgList = append(msgList, errorMsg) return errors.Throw(ErrBadRequest, errorMsg) - } hash := fnv.New32() //use fnv for better performance @@ -135,7 +132,6 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] errorMsg := "[sharder]body: " + url + " " + err.Error() msgList = append(msgList, errorMsg) return errors.Throw(ErrBadRequest, errorMsg) - } hashString := hex.EncodeToString(hash.Sum(nil)) @@ -171,16 +167,13 @@ func makeSCRestAPICall(scAddress string, relativePath string, params map[string] urls = []string{ fmt.Sprintf("%v/%v%v%v", network.Sharders[n], SC_REST_API_URL, scAddress, relativePath) + "?" + q.Encode(), } - } if hashMaxCounter < minNumConfirmation { - msgList[0] = fmt.Sprintf("min_confirmation is %v%%, but got %v/%v sharders", MinConfirmation, hashMaxCounter, numSharders) return nil, errors.Throw(ErrTooLessConfirmation, msgList...) } return resMaxCounterBody, nil - } diff --git a/code/go/0chain.net/core/util/http.go b/code/go/0chain.net/core/util/http.go index 62f3f2694..b37ba0668 100644 --- a/code/go/0chain.net/core/util/http.go +++ b/code/go/0chain.net/core/util/http.go @@ -41,9 +41,7 @@ func SendMultiPostRequest(urls []string, data []byte) { wg.Wait() } -func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) ( - body []byte, err error) { - +func SendPostRequest(url string, data []byte, wg *sync.WaitGroup) (body []byte, err error) { if wg != nil { defer wg.Done() } diff --git a/code/go/0chain.net/validator/main.go b/code/go/0chain.net/validator/main.go index 413d647d3..35541ea8d 100644 --- a/code/go/0chain.net/validator/main.go +++ b/code/go/0chain.net/validator/main.go @@ -162,7 +162,6 @@ func main() { } func RegisterValidator() { - registrationRetries := 0 //ctx := badgerdbstore.GetStorageProvider().WithConnection(common.GetRootContext()) for registrationRetries < 10 { diff --git a/code/go/0chain.net/validatorcore/storage/challenge_handler.go b/code/go/0chain.net/validatorcore/storage/challenge_handler.go index 28add0fd9..2222e2350 100644 --- a/code/go/0chain.net/validatorcore/storage/challenge_handler.go +++ b/code/go/0chain.net/validatorcore/storage/challenge_handler.go @@ -109,5 +109,4 @@ func ChallengeHandler(ctx context.Context, r *http.Request) (interface{}, error) lru.Add(challengeHash, &validationTicket) //nolint:errcheck // never returns an error anyway return &validationTicket, nil - } diff --git a/code/go/0chain.net/validatorcore/storage/models.go b/code/go/0chain.net/validatorcore/storage/models.go index 81ad0672d..59ca96e83 100644 --- a/code/go/0chain.net/validatorcore/storage/models.go +++ b/code/go/0chain.net/validatorcore/storage/models.go @@ -68,7 +68,6 @@ func (r *DirMetaData) GetHash() string { } func (r *DirMetaData) CalculateHash() string { - childHashes := make([]string, len(r.Children)) for index, childRef := range r.Children { childHashes[index] = childRef.GetHash() diff --git a/code/go/0chain.net/validatorcore/storage/protocol.go b/code/go/0chain.net/validatorcore/storage/protocol.go index 1f09fbafc..9d91977e4 100644 --- a/code/go/0chain.net/validatorcore/storage/protocol.go +++ b/code/go/0chain.net/validatorcore/storage/protocol.go @@ -128,7 +128,6 @@ func (wb *WalletCallback) OnWalletCreateComplete(status int, wallet, err string) } func (sp *ValidatorProtocolImpl) RegisterValidator(ctx context.Context) (string, error) { - wcb := &WalletCallback{} wcb.wg = &sync.WaitGroup{} wcb.wg.Add(1)