This repository has been archived by the owner on Nov 3, 2024. It is now read-only.
forked from streamingfast/bstream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
95 lines (81 loc) · 2.59 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2019 dfuse Platform Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package forkable
import (
"time"
"github.com/streamingfast/bstream"
"go.uber.org/zap"
)
type Option func(f *Forkable)
func WithLogger(logger *zap.Logger) Option {
return func(f *Forkable) {
f.logger = logger
}
}
func WithWarnOnUnlinkableBlocks(count int) Option {
return func(f *Forkable) {
f.warnOnUnlinkableBlocksCount = count
}
}
func WithFailOnUnlinkableBlocks(count int, gracePeriod time.Duration) Option {
return func(f *Forkable) {
f.failOnUnlinkableBlocksCount = count
f.failOnUnlinkableBlocksGracePeriod = gracePeriod
}
}
func WithInclusiveLIB(irreversibleBlock bstream.BlockRef) Option {
return func(f *Forkable) {
f.includeInitialLIB = true
f.forkDB.InitLIB(irreversibleBlock)
}
}
func WithExclusiveLIB(irreversibleBlock bstream.BlockRef) Option {
return func(f *Forkable) {
f.forkDB.InitLIB(irreversibleBlock)
f.lastLIBSeen = irreversibleBlock
}
}
// WithFilters choses the steps we want to pass through the sub handler. It defaults to StepsAll upon creation.
func WithFilters(steps bstream.StepType) Option {
return func(f *Forkable) {
f.filterSteps = steps
}
}
func HoldBlocksUntilLIB() Option {
return func(f *Forkable) {
f.holdBlocksUntilLIB = true
}
}
func WithKeptFinalBlocks(count int) Option {
return func(f *Forkable) {
f.keptFinalBlocks = count
}
}
func EnsureBlockFlows(blockRef bstream.BlockRef) Option {
return func(f *Forkable) {
f.ensureBlockFlows = blockRef
}
}
// EnsureAllBlocksTriggerLongestChain will force every block to be
// considered as the longest chain, therefore making it appear as New
// at least once. The only edge case is if there is a hole between a
// block and LIB when it is received, and it is forked out: in this
// case, that block would never appear. It is extremely unlikely to
// happen, because incoming blocks should be linkable, and blocks that
// are not forked out will eventually be processed anyway.
func EnsureAllBlocksTriggerLongestChain() Option {
return func(f *Forkable) {
f.ensureAllBlocksTriggerLongestChain = true
}
}