diff --git a/code/go/0chain.net/blobber/config.go b/code/go/0chain.net/blobber/config.go index 0969f17ac..05bda0e44 100644 --- a/code/go/0chain.net/blobber/config.go +++ b/code/go/0chain.net/blobber/config.go @@ -83,9 +83,6 @@ func setupConfig(configDir string, deploymentMode int) { config.Configuration.MaxAllocationDirFiles = viper.GetInt("max_dirs_files") - if config.Configuration.MaxAllocationDirFiles < 50000 { - config.Configuration.MaxAllocationDirFiles = 50000 - } config.Configuration.DelegateWallet = viper.GetString("delegate_wallet") if w := config.Configuration.DelegateWallet; len(w) != 64 { diff --git a/code/go/0chain.net/blobber/main.go b/code/go/0chain.net/blobber/main.go index 7fcd4fedf..06db9d222 100644 --- a/code/go/0chain.net/blobber/main.go +++ b/code/go/0chain.net/blobber/main.go @@ -48,13 +48,8 @@ func main() { panic(err) } - if err := setCCTFromChain(); err != nil { - logging.Logger.Error("Error setCCTFromChain" + err.Error()) - panic(err) - } - - if err := setMaxFileSizeFromChain(); err != nil { - logging.Logger.Error("Error setMaxFileSizeFromChain" + err.Error()) + if err := setStorageScConfigFromChain(); err != nil { + logging.Logger.Error("Error setStorageScConfigFromChain" + err.Error()) panic(err) } diff --git a/code/go/0chain.net/blobber/settings.go b/code/go/0chain.net/blobber/settings.go index 5235ca620..eb90322b2 100644 --- a/code/go/0chain.net/blobber/settings.go +++ b/code/go/0chain.net/blobber/settings.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "errors" - "go.uber.org/zap" "strconv" "time" @@ -13,82 +12,53 @@ import ( "github.com/0chain/gosdk/zcncore" ) -type cctCB struct { +type storageScCB struct { done chan struct{} cct int64 - err error -} - -type maxFileSizeCB struct { - done chan struct{} mfs int64 err error } -func (c *cctCB) OnInfoAvailable(op int, status int, info string, errStr string) { +func (ssc *storageScCB) OnInfoAvailable(op int, status int, info string, errStr string) { defer func() { - c.done <- struct{}{} + ssc.done <- struct{}{} }() if errStr != "" { - c.err = errors.New(errStr) + ssc.err = errors.New(errStr) return } m := make(map[string]interface{}) err := json.Unmarshal([]byte(info), &m) if err != nil { - c.err = err + ssc.err = err return } m = m["fields"].(map[string]interface{}) cctString := m["max_challenge_completion_rounds"].(string) + mfsString := m["max_file_size"].(string) cct, err := strconv.ParseInt(cctString, 10, 64) if err != nil { - c.err = err - return - } - - c.cct = cct -} - -func (c *maxFileSizeCB) OnInfoAvailable(op int, status int, info string, errStr string) { - defer func() { - c.done <- struct{}{} - }() - - if errStr != "" { - c.err = errors.New(errStr) - return - } - - m := make(map[string]interface{}) - err := json.Unmarshal([]byte(info), &m) - if err != nil { - c.err = err + ssc.err = err return } - m = m["fields"].(map[string]interface{}) - - mfsString := m["max_file_size"].(string) - mfs, err := strconv.ParseInt(mfsString, 10, 64) if err != nil { - c.err = err + ssc.err = err return } - logging.Logger.Info("max file size from chain", zap.Int64("max_file_size", mfs)) - - c.mfs = mfs + ssc.cct = cct + ssc.mfs = mfs } -func setCCTFromChain() error { - cb := &cctCB{ +func setStorageScConfigFromChain() error { + cb := &storageScCB{ done: make(chan struct{}), } err := zcncore.GetStorageSCConfig(cb) @@ -101,43 +71,24 @@ func setCCTFromChain() error { } config.StorageSCConfig.ChallengeCompletionTime = cb.cct + config.StorageSCConfig.MaxFileSize = cb.mfs return nil } -func setMaxFileSizeFromChain() error { - logging.Logger.Info("getting max file size from chain") - - cb := &maxFileSizeCB{ - done: make(chan struct{}), - } - err := zcncore.GetStorageSCConfig(cb) - if err != nil { - return err - } - <-cb.done - if cb.err != nil { - return err +func updateStorageScConfigWorker(ctx context.Context) { + interval := time.Hour + if config.Development() { + interval = time.Second } - config.StorageSCConfig.MaxFileSize = cb.mfs - return nil -} - -func updateCCTWorker(ctx context.Context) { - ticker := time.NewTicker(time.Hour) + ticker := time.NewTicker(interval) for { select { case <-ctx.Done(): return case <-ticker.C: - // We'd panic if err occurred when calling setCCTFromChain from - // main.go file because cct would be initially 0 and we cannot - // work with 0 value. - // Upon updating cct, we only log error because cct is not 0 - // We should try to submit challenge as soon as possible regardless - // of cct value. - err := setCCTFromChain() + err := setStorageScConfigFromChain() if err != nil { logging.Logger.Error(err.Error()) } diff --git a/code/go/0chain.net/blobber/worker.go b/code/go/0chain.net/blobber/worker.go index f42bbc76e..92db82a86 100644 --- a/code/go/0chain.net/blobber/worker.go +++ b/code/go/0chain.net/blobber/worker.go @@ -28,7 +28,7 @@ func setupWorkers(ctx context.Context) { challenge.SetupChallengeCleanUpWorker(ctx) challenge.SetupChallengeTimingsCleanupWorker(ctx) stats.SetupStatsWorker(ctx) - updateCCTWorker(ctx) + updateStorageScConfigWorker(ctx) } // startRefreshSettings sync settings from blockchain diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index 37a93df60..6aee2b513 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -44,6 +44,8 @@ func SetupDefaultConfig() { viper.SetDefault("update_allocations_interval", time.Duration(-1)) viper.SetDefault("finalize_allocations_interval", time.Duration(-1)) + + viper.SetDefault("max_dirs_files", 50000) } /*SetupConfig - setup the configuration system */ diff --git a/code/go/0chain.net/blobbercore/handler/client_quota.go b/code/go/0chain.net/blobbercore/handler/client_quota.go index f432e6fca..1885fe8e2 100644 --- a/code/go/0chain.net/blobbercore/handler/client_quota.go +++ b/code/go/0chain.net/blobbercore/handler/client_quota.go @@ -18,8 +18,7 @@ var ( ) const ( - BlackListWorkerTime = 6 * time.Hour - Period = 60 * 60 * 24 * 30 // 30 days + Period = 60 * 60 * 24 * 30 // 30 days ) type ClientStats struct { @@ -136,6 +135,11 @@ func saveClientStats() { } func startBlackListWorker(ctx context.Context) { + BlackListWorkerTime := 6 * time.Hour + if config.Development() { + BlackListWorkerTime = 10 * time.Second + } + for { select { case <-ctx.Done():