Skip to content

Commit

Permalink
Merge branch 'sprint-july-4' into fix/redeem-rb
Browse files Browse the repository at this point in the history
  • Loading branch information
dabasov authored Aug 7, 2023
2 parents 7fe5c1f + 3a1a405 commit 98cfc3f
Show file tree
Hide file tree
Showing 37 changed files with 536 additions and 575 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build-&-publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:

- name: Clone blobber
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Docker Buildx
run: |
Expand Down Expand Up @@ -113,7 +115,9 @@ jobs:
go-version: ^1.20 # The Go version to download (if necessary) and use.

- name: Clone blobber
uses: actions/checkout@v1
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Docker Buildx
run: |
Expand Down Expand Up @@ -243,4 +247,4 @@ jobs:
repository: ${{ github.repository }}
status_name: "0Chain System Tests"
target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
github_token: ${{ github.token }}
github_token: ${{ github.token }}
39 changes: 20 additions & 19 deletions code/go/0chain.net/blobber/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,30 @@ func setupConfig(configDir string, deploymentMode int) {
func reloadConfig() error {
fmt.Print("> reload config")

db := datastore.GetStore().GetDB()
return datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
s, ok := config.Get(ctx, datastore.GetStore().GetDB())
if ok {
if err := s.CopyTo(&config.Configuration); err != nil {
return err
}
fmt.Print(" [OK]\n")
return nil
}

config.Configuration.Capacity = viper.GetInt64("capacity")

config.Configuration.MinLockDemand = viper.GetFloat64("min_lock_demand")
config.Configuration.NumDelegates = viper.GetInt("num_delegates")
config.Configuration.ReadPrice = viper.GetFloat64("read_price")
config.Configuration.ServiceCharge = viper.GetFloat64("service_charge")
config.Configuration.WritePrice = viper.GetFloat64("write_price")

s, ok := config.Get(context.TODO(), db)
if ok {
if err := s.CopyTo(&config.Configuration); err != nil {
if err := config.Update(ctx, datastore.GetStore().GetDB()); err != nil {
return err
}

fmt.Print(" [OK]\n")
return nil
}

config.Configuration.Capacity = viper.GetInt64("capacity")

config.Configuration.MinLockDemand = viper.GetFloat64("min_lock_demand")
config.Configuration.NumDelegates = viper.GetInt("num_delegates")
config.Configuration.ReadPrice = viper.GetFloat64("read_price")
config.Configuration.ServiceCharge = viper.GetFloat64("service_charge")
config.Configuration.WritePrice = viper.GetFloat64("write_price")

if err := config.Update(context.TODO(), db); err != nil {
return err
}

fmt.Print(" [OK]\n")
return nil
})
}
28 changes: 28 additions & 0 deletions code/go/0chain.net/blobber/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"net/http"
"net/http/pprof"
"runtime"
"strconv"
"sync"
Expand Down Expand Up @@ -53,19 +54,38 @@ func startServer(wg *sync.WaitGroup, r *mux.Router, mode string, port int, isTls
//address := publicIP + ":" + portString
address := ":" + strconv.Itoa(port)
var server *http.Server
var profServer *http.Server

if config.Development() {
// No WriteTimeout setup to enable pprof
server = &http.Server{
Addr: address,
ReadHeaderTimeout: 30 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
Handler: r,
}

pprofMux := http.NewServeMux()
profServer = &http.Server{
Addr: fmt.Sprintf(":%d", port-1000),
ReadTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
Handler: pprofMux,
}
initProfHandlers(pprofMux)
go func() {
err2 := profServer.ListenAndServe()
logging.Logger.Error("Http server shut down", zap.Error(err2))
}()

} else {
server = &http.Server{
Addr: address,
ReadHeaderTimeout: 30 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
IdleTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
Expand All @@ -91,3 +111,11 @@ func initHandlers(r *mux.Router) {
handler.SetupSwagger()
common.SetAdminCredentials()
}

func initProfHandlers(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", handler.RateLimitByGeneralRL(pprof.Index))
mux.HandleFunc("/debug/pprof/cmdline", handler.RateLimitByGeneralRL(pprof.Cmdline))
mux.HandleFunc("/debug/pprof/profile", handler.RateLimitByGeneralRL(pprof.Profile))
mux.HandleFunc("/debug/pprof/symbol", handler.RateLimitByGeneralRL(pprof.Symbol))
mux.HandleFunc("/debug/pprof/trace", handler.RateLimitByGeneralRL(pprof.Trace))
}
7 changes: 4 additions & 3 deletions code/go/0chain.net/blobber/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/handler"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/readmarker"
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/writemarker"
"github.com/0chain/blobber/code/go/0chain.net/core/common"
"github.com/0chain/blobber/code/go/0chain.net/core/logging"

"go.uber.org/zap"
Expand All @@ -30,13 +29,15 @@ func setupWorkers(ctx context.Context) {
// startRefreshSettings sync settings from blockchain
func startRefreshSettings(ctx context.Context) {
const REPEAT_DELAY = 60 * 3 // 3 minutes
var err error
for {
select {
case <-ctx.Done():
return
case <-time.After(REPEAT_DELAY * time.Second):
_, err = config.ReloadFromChain(common.GetRootContext(), datastore.GetStore().GetDB())
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
_, e := config.ReloadFromChain(ctx, datastore.GetStore().GetDB())
return e
})
if err != nil {
logging.Logger.Warn("failed to refresh blobber settings from chain", zap.Error(err))
continue
Expand Down
Loading

0 comments on commit 98cfc3f

Please sign in to comment.