Skip to content

Commit

Permalink
services: add default values for NeoFSBlockFetcher configuration
Browse files Browse the repository at this point in the history
The minimum sufficient configuration is Addresses and ContainerID,
example:
```
  NeoFSBlockFetcher:
    Enabled: true
    Addresses:
      - st1.storage.fs.neo.org:8080
      - st2.storage.fs.neo.org:8080
      - st3.storage.fs.neo.org:8080
      - st4.storage.fs.neo.org:8080
    ContainerID: "87JRc7vyWcjW8uS32LMoLTAj4ckCzFZWfKbacjU3sAob"
```

Close #3718

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Dec 10, 2024
1 parent 727262a commit 311eda4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
26 changes: 0 additions & 26 deletions pkg/config/application_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,6 @@ func TestNeoFSBlockFetcherValidation(t *testing.T) {
shouldFail: true,
errMsg: "addresses are not set",
},
{
cfg: NeoFSBlockFetcher{
InternalService: InternalService{Enabled: true},
Timeout: time.Second,
ContainerID: validContainerID,
Addresses: []string{"127.0.0.1"},
OIDBatchSize: 10,
BQueueSize: 5,
},
shouldFail: true,
errMsg: "BQueueSize (5) is lower than OIDBatchSize (10)",
},
{
cfg: NeoFSBlockFetcher{
InternalService: InternalService{Enabled: true},
Timeout: time.Second,
ContainerID: validContainerID,
Addresses: []string{"127.0.0.1"},
OIDBatchSize: 10,
BQueueSize: 20,
SkipIndexFilesSearch: false,
IndexFileSize: 0,
},
shouldFail: true,
errMsg: "IndexFileSize is not set",
},
}

for _, c := range cases {
Expand Down
6 changes: 0 additions & 6 deletions pkg/config/blockfetcher_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,8 @@ func (cfg *NeoFSBlockFetcher) Validate() error {
if err != nil {
return fmt.Errorf("invalid container ID: %w", err)
}
if cfg.BQueueSize < cfg.OIDBatchSize {
return fmt.Errorf("BQueueSize (%d) is lower than OIDBatchSize (%d)", cfg.BQueueSize, cfg.OIDBatchSize)
}
if len(cfg.Addresses) == 0 {
return errors.New("addresses are not set")
}
if !cfg.SkipIndexFilesSearch && cfg.IndexFileSize == 0 {
return errors.New("IndexFileSize is not set")
}
return nil
}
19 changes: 16 additions & 3 deletions pkg/services/blockfetcher/blockfetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/config"
"github.com/nspcc-dev/neo-go/pkg/core/block"
gio "github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/network/bqueue"
"github.com/nspcc-dev/neo-go/pkg/services/oracle/neofs"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neofs-sdk-go/client"
Expand All @@ -34,9 +35,15 @@ const (
// defaultTimeout is the default timeout for NeoFS requests.
defaultTimeout = 5 * time.Minute
// defaultOIDBatchSize is the default number of OIDs to search and fetch at once.
defaultOIDBatchSize = 8000
defaultOIDBatchSize = bqueue.DefaultCacheSize
// defaultDownloaderWorkersCount is the default number of workers downloading blocks.
defaultDownloaderWorkersCount = 100
// defaultIndexFileSize is the default size of the index file.
defaultIndexFileSize = 128000
// defaultBlockAttribute is the default attribute name for block objects.
defaultBlockAttribute = "Block"
// defaultIndexFileAttribute is the default attribute name for index file objects.
defaultIndexFileAttribute = "Index"
)

// Constants related to NeoFS pool request timeouts.
Expand Down Expand Up @@ -151,8 +158,14 @@ func New(chain Ledger, cfg config.NeoFSBlockFetcher, logger *zap.Logger, putBloc
if cfg.DownloaderWorkersCount <= 0 {
cfg.DownloaderWorkersCount = defaultDownloaderWorkersCount
}
if len(cfg.Addresses) == 0 {
return nil, errors.New("no addresses provided")
if cfg.IndexFileSize <= 0 {
cfg.IndexFileSize = defaultIndexFileSize
}
if cfg.BlockAttribute == "" {
cfg.BlockAttribute = defaultBlockAttribute
}
if cfg.IndexFileAttribute == "" {
cfg.IndexFileAttribute = defaultIndexFileAttribute
}

params := pool.DefaultOptions()
Expand Down

0 comments on commit 311eda4

Please sign in to comment.