Skip to content

Commit 61f9344

Browse files
authored
Optimize config (#95)
1 parent 6dc67a9 commit 61f9344

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

blockchain/sync/core/adapter.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ import (
1414
const defaultRpcRetry = 3
1515

1616
type AdapterConfig struct {
17-
URL string
17+
AdapterOption `mapstructure:",squash"`
1818

19-
Option AdapterOption
19+
URL string
2020
}
2121

2222
type AdapterOption struct {
2323
// RPC
2424
RequestTimeout time.Duration `default:"3s"`
2525

2626
// latest block number
27-
LatestBlockNumberTag string `default:"latest_state"`
28-
LatestBlockNumberOffset uint64 `default:"5"`
27+
LatestBlockNumberTag string `default:"latest_state"` // latest_mined, latest_state, latest_confirmed or latest_finalized
28+
LatestBlockNumberOffset uint64 `default:"5"` // N blocks behind the `LatestBlockNumberTag`
2929
latestEpoch *types.Epoch
3030

3131
// allow to ignore receipts and/or traces, only block and transactions are required
@@ -73,7 +73,7 @@ func NewAdapterWithConfig(config AdapterConfig) (*Adapter, error) {
7373
return nil, errors.New("URL not specified")
7474
}
7575

76-
return NewAdapter(config.URL, config.Option)
76+
return NewAdapter(config.URL, config.AdapterOption)
7777
}
7878

7979
// Close closes the underlying RPC client.

blockchain/sync/evm/adapter.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import (
1313
)
1414

1515
type AdapterConfig struct {
16-
URL string
16+
AdapterOption `mapstructure:",squash"`
1717

18-
Option AdapterOption
18+
URL string
1919
}
2020

2121
type AdapterOption struct {
2222
// RPC
2323
RequestTimeout time.Duration `default:"3s"`
2424

2525
// latest block number
26-
LatestBlockNumberTag int64 `default:"-1"` // "latest" block
27-
LatestBlockNumberOffset uint64 `default:"5"`
26+
LatestBlockNumberTag int64 `default:"-1"` // -1: "latest", -3: "finalized", -4: "safe"
27+
LatestBlockNumberOffset uint64 `default:"5"` // N blocks behind the `LatestBlockNumberTag`
2828

2929
// allow to ignore receipts and/or traces, only block and transactions are required
3030
IgnoreReceipts bool
@@ -62,7 +62,7 @@ func NewAdapterWithConfig(config AdapterConfig) (*Adapter, error) {
6262
return nil, errors.New("URL not specified")
6363
}
6464

65-
return NewAdapter(config.URL, config.Option)
65+
return NewAdapter(config.URL, config.AdapterOption)
6666
}
6767

6868
// Close closes the underlying RPC client.

blockchain/sync/poll/parallel_worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
type ParallelOption struct {
14-
parallel.SerialOption
14+
parallel.SerialOption `mapstructure:",squash"`
1515

1616
RetryInterval time.Duration `default:"1s"`
1717

blockchain/sync/process/db/processor_agg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ type Processor[T any] interface {
1818
type Option struct {
1919
RetryInterval time.Duration `default:"3s"`
2020

21-
Health health.CounterConfig
21+
Health health.TimedCounterConfig
2222
}
2323

2424
// AggregateProcessor aggregates multiple processor to process blockchain data in batch.
2525
type AggregateProcessor[T any] struct {
2626
option Option
2727
db *gorm.DB
2828
processors []Processor[T]
29-
health *health.Counter
29+
health *health.TimedCounter
3030
}
3131

3232
func NewAggregateProcessor[T any](option Option, db *gorm.DB, processors ...Processor[T]) *AggregateProcessor[T] {
@@ -36,7 +36,7 @@ func NewAggregateProcessor[T any](option Option, db *gorm.DB, processors ...Proc
3636
option: option,
3737
db: db,
3838
processors: processors,
39-
health: health.NewCounter(option.Health),
39+
health: health.NewTimedCounter(option.Health),
4040
}
4141
}
4242

blockchain/sync/process/db/processor_batch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type BatchProcessor[T any] interface {
2626
}
2727

2828
type BatchOption struct {
29-
Processor Option
29+
Option `mapstructure:",squash"`
3030

3131
BatchSize int `default:"3000"`
3232
BatchTimeout time.Duration `default:"3s"`
@@ -54,7 +54,7 @@ func NewBatchAggregateProcessor[T any](option BatchOption, db *gorm.DB, processo
5454
}
5555

5656
return &BatchAggregateProcessor[T]{
57-
AggregateProcessor: NewAggregateProcessor(option.Processor, db, innerProcessors...),
57+
AggregateProcessor: NewAggregateProcessor(option.Option, db, innerProcessors...),
5858
option: option,
5959
processors: processors,
6060
lastBatchTime: time.Now(),

0 commit comments

Comments
 (0)