Skip to content

Commit

Permalink
Fix: mempool receiver block time
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Dec 9, 2021
1 parent 6ac6595 commit 504793f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cmd/mempool/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func NewIndexer(ctx context.Context, network string, indexerCfg config.Indexer,
}

memInd, err := receiver.New(indexerCfg.DataSource.RPC, network,
receiver.WithStorage(db, constants.TimeBetweenBlocks[0]),
receiver.WithStorage(db),
receiver.WithPrometheus(prom),
receiver.WithBlockTime(constants.TimeBetweenBlocks[0]),
)
if err != nil {
return nil, err
Expand Down
14 changes: 8 additions & 6 deletions cmd/mempool/receiver/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import (
type ReceiverOption func(*Receiver)

// WithStorage -
func WithStorage(db *database.PgGo, blockTime int64) ReceiverOption {
func WithStorage(db *database.PgGo) ReceiverOption {
return func(m *Receiver) {
if blockTime > 0 {
m.blockTime = blockTime
} else {
m.blockTime = 60
}
m.db = db
}
}
Expand All @@ -26,3 +21,10 @@ func WithPrometheus(prom *prometheus.Service) ReceiverOption {
m.prom = prom
}
}

// WithBlockTime -
func WithBlockTime(blockTime int64) ReceiverOption {
return func(m *Receiver) {
m.blockTime = blockTime
}
}
4 changes: 4 additions & 0 deletions cmd/mempool/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func New(urls []string, network string, opts ...ReceiverOption) (*Receiver, erro
opts[i](&indexer)
}

if indexer.blockTime == 0 {
indexer.blockTime = 30
}

return &indexer, nil
}

Expand Down

0 comments on commit 504793f

Please sign in to comment.