Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/max file size updateWorker and added config for storagesc update interval #1308

Merged
merged 16 commits into from Nov 1, 2023
Merged
3 changes: 0 additions & 3 deletions code/go/0chain.net/blobber/config.go
Expand Up @@ -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 {
Expand Down
71 changes: 52 additions & 19 deletions code/go/0chain.net/blobber/settings.go
Expand Up @@ -105,8 +105,6 @@ func setCCTFromChain() error {
}

func setMaxFileSizeFromChain() error {
logging.Logger.Info("getting max file size from chain")

cb := &maxFileSizeCB{
done: make(chan struct{}),
}
Expand All @@ -120,27 +118,62 @@ func setMaxFileSizeFromChain() error {
}

config.StorageSCConfig.MaxFileSize = cb.mfs

return nil
}

func updateCCTWorker(ctx context.Context) {
ticker := time.NewTicker(time.Hour)

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()
if err != nil {
logging.Logger.Error(err.Error())
go func() {
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
interval := time.Hour
if config.Development() {
interval = time.Second
}

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()
if err != nil {
logging.Logger.Error(err.Error())
}
}
}
}
}()
}

func updateMaxFileSizeWorker(ctx context.Context) {
go func() {
interval := time.Hour
if config.Development() {
interval = time.Second
}

ticker := time.NewTicker(interval)

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
// We'd panic if err occurred when calling setMaxFileSizeFromChain from
// main.go file because mfs would be initially 0 and we cannot
// work with 0 value.
// Upon updating mfs, we only log error because mfs is not 0
err := setMaxFileSizeFromChain()
if err != nil {
logging.Logger.Error(err.Error())
}
}
}
}()
}
1 change: 1 addition & 0 deletions code/go/0chain.net/blobber/worker.go
Expand Up @@ -28,6 +28,7 @@ func setupWorkers(ctx context.Context) {
challenge.SetupChallengeCleanUpWorker(ctx)
challenge.SetupChallengeTimingsCleanupWorker(ctx)
stats.SetupStatsWorker(ctx)
updateMaxFileSizeWorker(ctx)
updateCCTWorker(ctx)
}

Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/blobbercore/config/config.go
Expand Up @@ -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 */
Expand Down
8 changes: 6 additions & 2 deletions code/go/0chain.net/blobbercore/handler/client_quota.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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():
Expand Down