Skip to content

Commit

Permalink
[config] move config.Indexer to blockindex package (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
huof6829 authored Jul 25, 2022
1 parent 3f74fb7 commit 99cc091
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
5 changes: 2 additions & 3 deletions blockindex/bloomfilterindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ import (
"time"

"github.com/iotexproject/go-pkgs/bloom"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

"github.com/iotexproject/iotex-core/action"
filter "github.com/iotexproject/iotex-core/api/logfilter"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/blockchain/blockdao"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/db/batch"
"github.com/iotexproject/iotex-core/pkg/util/byteutil"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -79,7 +78,7 @@ type (
)

// NewBloomfilterIndexer creates a new bloomfilterindexer struct by given kvstore and rangebloomfilter size
func NewBloomfilterIndexer(kv db.KVStore, cfg config.Indexer) (BloomFilterIndexer, error) {
func NewBloomfilterIndexer(kv db.KVStore, cfg Config) (BloomFilterIndexer, error) {
if kv == nil {
return nil, errors.New("empty kvStore")
}
Expand Down
5 changes: 2 additions & 3 deletions blockindex/bloomfilterindexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/api/logfilter"
"github.com/iotexproject/iotex-core/blockchain/block"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/test/identityset"
"github.com/iotexproject/iotex-core/testutil"
Expand Down Expand Up @@ -214,7 +213,7 @@ func TestBloomfilterIndexer(t *testing.T) {

testIndexer := func(kvStore db.KVStore, t *testing.T) {
ctx := context.Background()
cfg := config.Default.Indexer
cfg := DefaultConfig
cfg.RangeBloomFilterNumElements = 16
cfg.RangeBloomFilterSize = 4096
cfg.RangeBloomFilterNumHash = 4
Expand Down Expand Up @@ -276,7 +275,7 @@ func TestBloomfilterIndexer(t *testing.T) {
func BenchmarkBloomfilterIndexer(b *testing.B) {
require := require.New(b)

indexerCfg := config.Default.Indexer
indexerCfg := DefaultConfig
indexerCfg.RangeBloomFilterNumElements = 16
indexerCfg.RangeBloomFilterSize = 4096
indexerCfg.RangeBloomFilterNumHash = 4
Expand Down
24 changes: 24 additions & 0 deletions blockindex/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2022 IoTeX Foundation
// This is an alpha (internal) release and is not suitable for production. This source code is provided 'as is' and no
// warranties are given as to title or non-infringement, merchantability or fitness for purpose and, to the extent
// permitted by law, all liability for your use of the code is disclaimed. This source code is governed by Apache
// License 2.0 that can be found in the LICENSE file.

package blockindex

// Config is the config for indexer
type Config struct {
// RangeBloomFilterNumElements is the number of elements each rangeBloomfilter will store in bloomfilterIndexer
RangeBloomFilterNumElements uint64 `yaml:"rangeBloomFilterNumElements"`
// RangeBloomFilterSize is the size (in bits) of rangeBloomfilter
RangeBloomFilterSize uint64 `yaml:"rangeBloomFilterSize"`
// RangeBloomFilterNumHash is the number of hash functions of rangeBloomfilter
RangeBloomFilterNumHash uint64 `yaml:"rangeBloomFilterNumHash"`
}

// DefaultConfig is the default config of indexer
var DefaultConfig = Config{
RangeBloomFilterNumElements: 100000,
RangeBloomFilterSize: 1200000,
RangeBloomFilterNumHash: 8,
}
19 changes: 3 additions & 16 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/iotexproject/iotex-core/actpool"
"github.com/iotexproject/iotex-core/blockchain"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/blockindex"
"github.com/iotexproject/iotex-core/db"
"github.com/iotexproject/iotex-core/dispatcher"
"github.com/iotexproject/iotex-core/p2p"
Expand Down Expand Up @@ -130,11 +131,7 @@ var (
SplitDBHeight: 900000,
HistoryStateRetention: 2000,
},
Indexer: Indexer{
RangeBloomFilterNumElements: 100000,
RangeBloomFilterSize: 1200000,
RangeBloomFilterNumHash: 8,
},
Indexer: blockindex.DefaultConfig,
Genesis: genesis.Default,
}

Expand Down Expand Up @@ -237,16 +234,6 @@ type (
SystemLogDBPath string `yaml:"systemLogDBPath"`
}

// Indexer is the config for indexer
Indexer struct {
// RangeBloomFilterNumElements is the number of elements each rangeBloomfilter will store in bloomfilterIndexer
RangeBloomFilterNumElements uint64 `yaml:"rangeBloomFilterNumElements"`
// RangeBloomFilterSize is the size (in bits) of rangeBloomfilter
RangeBloomFilterSize uint64 `yaml:"rangeBloomFilterSize"`
// RangeBloomFilterNumHash is the number of hash functions of rangeBloomfilter
RangeBloomFilterNumHash uint64 `yaml:"rangeBloomFilterNumHash"`
}

// Config is the root config struct, each package's config should be put as its sub struct
Config struct {
Plugins map[int]interface{} `ymal:"plugins"`
Expand All @@ -260,7 +247,7 @@ type (
API API `yaml:"api"`
System System `yaml:"system"`
DB db.Config `yaml:"db"`
Indexer Indexer `yaml:"indexer"`
Indexer blockindex.Config `yaml:"indexer"`
Log log.GlobalConfig `yaml:"log"`
SubLogs map[string]log.GlobalConfig `yaml:"subLogs"`
Genesis genesis.Genesis `yaml:"genesis"`
Expand Down

0 comments on commit 99cc091

Please sign in to comment.