Skip to content

Commit

Permalink
Merge branch 'feat/storage-v2' into akhilesh/storageV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayashsatolia403 authored Oct 30, 2024
2 parents d90ab6b + a4c3fdd commit 1cfde7b
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 246 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/system_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: 0chain/actions/.github/workflows/manual_system_tests.yml@master
with:
zbox_cli_branch: ${{ github.ref_name }}
repo_snapshots_branch: ${{ github.event.inputs.repo_snapshots_branch }}
repo_snapshots_branch: fix/refactor-zboxcore
test_file_filter: ${{ github.event.inputs.test_file_filter }}
skip_tests: ${{ github.event.inputs.skip_tests }}
run_smoke_tests: ${{ github.event.inputs.run_smoke_tests }}
Expand Down
65 changes: 65 additions & 0 deletions cmd/downloaddir.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cmd

import (
"context"
"os"
"sync"

"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)

// downloadCmd represents download directory command
var downdirCmd = &cobra.Command{
Use: "downloaddir",
Short: "download directory from blobbers",
Long: `download directory from blobbers`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fflags := cmd.Flags() // fflags is a *flag.FlagSet
if !(fflags.Changed("remotepath") || fflags.Changed("authticket")) {
PrintError("Error: remotepath / authticket flag is missing")
os.Exit(1)
}

remotePath := cmd.Flag("remotepath").Value.String()
authTicket := cmd.Flag("authticket").Value.String()
localPath := cmd.Flag("localpath").Value.String()
allocationID := cmd.Flag("allocation").Value.String()

var allocationObj *sdk.Allocation
if !fflags.Changed("allocation") { // check if the flag "path" is set
PrintError("Error: allocation flag is missing") // If not, we'll let the user know
os.Exit(1) // and return
}
allocationObj, err := sdk.GetAllocation(allocationID)
if err != nil {
PrintError("Error fetching the allocation", err)
os.Exit(1)
}
wg := &sync.WaitGroup{}
statusBar := &StatusBar{wg: wg}
wg.Add(1)
errE := allocationObj.DownloadDirectory(context.Background(), remotePath, localPath, authTicket, statusBar)
if errE == nil {
wg.Wait()
} else {
PrintError("Download failed.", errE.Error())
os.Exit(1)
}
if !statusBar.success {
os.Exit(1)
}
},
}

func init() {
rootCmd.AddCommand(downdirCmd)
downdirCmd.PersistentFlags().String("allocation", "", "Allocation ID")
downdirCmd.PersistentFlags().String("remotepath", "", "Remote path of directory to download")
downdirCmd.PersistentFlags().String("localpath", "", "Local path of directory to download")
downdirCmd.PersistentFlags().String("authticket", "", "Auth ticket fot the file to download if you dont own it")
downdirCmd.MarkFlagRequired("allocation")
downdirCmd.MarkFlagRequired("localpath")
downdirCmd.MarkFlagRequired("remotepath")
}
157 changes: 0 additions & 157 deletions cmd/readpool.go

This file was deleted.

63 changes: 7 additions & 56 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
package cmd

import (
_ "embed"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/logger"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/0chain/gosdk/zboxcore/blockchain"
"github.com/0chain/gosdk/core/client"
"github.com/0chain/zboxcli/util"

"github.com/0chain/gosdk/core/zcncrypto"
Expand All @@ -37,9 +35,6 @@ var allocUnderRepair bool

var walletJSON string

//go:embed config.yaml
var configStr string

var rootCmd = &cobra.Command{
Use: "zbox",
Short: "zbox is a decentralized storage application written on the 0Chain platform",
Expand Down Expand Up @@ -83,48 +78,21 @@ func initConfig() {
cfg, err := conf.LoadConfigFile(filepath.Join(configDir, cfgFile))
if err != nil {
fmt.Println("Can't read config:", err)
fmt.Println("using default config")
fmt.Printf("config: %v", configStr)
v := viper.New()
v.SetConfigType("yaml")
err := v.ReadConfig(strings.NewReader(configStr))
if err != nil {
fmt.Println("error reading default config:", err)
os.Exit(1)
}
cfg, err = conf.LoadConfig(v)
if err != nil {
fmt.Println("error loading default config:", err)
os.Exit(1)
}
os.Exit(1)
}

if networkFile == "" {
networkFile = "network.yaml"
}
network, _ := conf.LoadNetworkFile(filepath.Join(configDir, networkFile))

// syncing loggers
logger.SyncLoggers([]*logger.Logger{zcncore.GetLogger(), sdk.GetLogger()})

// set the log file
zcncore.SetLogFile("cmdlog.log", !bSilent)
sdk.SetLogFile("cmdlog.log", !bSilent)
sdk.SetMinSubmit(cfg.MinSubmit)

if network.IsValid() {
zcncore.SetNetwork(network.Miners, network.Sharders)
conf.InitChainNetwork(&conf.Network{
Miners: network.Miners,
Sharders: network.Sharders,
})
}

err = zcncore.InitZCNSDK(cfg.BlockWorker, cfg.SignatureScheme,
zcncore.WithChainID(cfg.ChainID),
zcncore.WithMinSubmit(cfg.MinSubmit),
zcncore.WithMinConfirmation(cfg.MinConfirmation),
zcncore.WithConfirmationChainLength(cfg.ConfirmationChainLength))
err = client.Init(context.Background(), cfg)
if err != nil {
fmt.Println("Error initializing core SDK.", err)
os.Exit(1)
Expand Down Expand Up @@ -198,35 +166,18 @@ func initConfig() {
}

//init the storage sdk with the known miners, sharders and client wallet info
if err = sdk.InitStorageSDK(
if err = client.InitSDK(
walletJSON,
cfg.BlockWorker,
cfg.ChainID,
cfg.SignatureScheme,
cfg.PreferredBlobbers,
nonce,
zcncore.ConvertToValue(txFee),
false, true,
int(zcncore.ConvertToValue(txFee)),
); err != nil {
fmt.Println("Error in sdk init", err)
os.Exit(1)
}

// set wallet info along whether split key is used
err = zcncore.SetWalletInfo(walletJSON, false)
if err != nil {
fmt.Println("Error in wallet info initialization", err)
os.Exit(1)
}

// additional settings depending network latency
blockchain.SetMaxTxnQuery(cfg.MaxTxnQuery)
blockchain.SetQuerySleepTime(cfg.QuerySleepTime)

conf.InitClientConfig(&cfg)

if network.IsValid() {
sdk.SetNetwork(network.Miners, network.Sharders)
}

sdk.SetNumBlockDownloads(10)
}
10 changes: 5 additions & 5 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var lsBlobers = &cobra.Command{
}
list, err := sdk.GetBlobbers(isActive, isStakable)
if err != nil {
log.Fatalf("Failed to get storage SC configurations: %v", err)
log.Fatalf("Failed to get blobbers: %v", err)
}

if doJSON {
Expand Down Expand Up @@ -315,10 +315,10 @@ var blobberUpdateCmd = &cobra.Command{
}

var resetBlobberStatsCmd = &cobra.Command{
Use: "reset-blobber-stats",
Short: "Reset blobber stats",
Long: `Reset blobber stats`,
Args: cobra.MinimumNArgs(0),
Use: "reset-blobber-stats",
Short: "Reset blobber stats",
Long: `Reset blobber stats`,
Args: cobra.MinimumNArgs(0),
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
var (
Expand Down
Loading

0 comments on commit 1cfde7b

Please sign in to comment.