-
Notifications
You must be signed in to change notification settings - Fork 175
/
builder.go
87 lines (77 loc) · 1.96 KB
/
builder.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
package factories
import (
"fmt"
"github.com/dgraph-io/badger/v2"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/module"
builder "github.com/onflow/flow-go/module/builder/collection"
finalizer "github.com/onflow/flow-go/module/finalizer/collection"
"github.com/onflow/flow-go/module/mempool"
"github.com/onflow/flow-go/network"
clusterstate "github.com/onflow/flow-go/state/cluster"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/storage"
)
type BuilderFactory struct {
db *badger.DB
protoState protocol.State
mainChainHeaders storage.Headers
trace module.Tracer
opts []builder.Opt
metrics module.CollectionMetrics
pusher network.Engine // engine for pushing finalized collection to consensus committee
log zerolog.Logger
}
func NewBuilderFactory(
db *badger.DB,
protoState protocol.State,
mainChainHeaders storage.Headers,
trace module.Tracer,
metrics module.CollectionMetrics,
pusher network.Engine,
log zerolog.Logger,
opts ...builder.Opt,
) (*BuilderFactory, error) {
factory := &BuilderFactory{
db: db,
protoState: protoState,
mainChainHeaders: mainChainHeaders,
trace: trace,
metrics: metrics,
pusher: pusher,
log: log,
opts: opts,
}
return factory, nil
}
func (f *BuilderFactory) Create(
clusterState clusterstate.State,
clusterHeaders storage.Headers,
clusterPayloads storage.ClusterPayloads,
pool mempool.Transactions,
epoch uint64,
) (module.Builder, *finalizer.Finalizer, error) {
build, err := builder.NewBuilder(
f.db,
f.trace,
f.protoState,
clusterState,
f.mainChainHeaders,
clusterHeaders,
clusterPayloads,
pool,
f.log,
epoch,
f.opts...,
)
if err != nil {
return nil, nil, fmt.Errorf("could not create builder: %w", err)
}
final := finalizer.NewFinalizer(
f.db,
pool,
f.pusher,
f.metrics,
)
return build, final, nil
}