-
Notifications
You must be signed in to change notification settings - Fork 175
/
compliance.go
102 lines (93 loc) · 2.49 KB
/
compliance.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
96
97
98
99
100
101
102
package factories
import (
"fmt"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/consensus/hotstuff"
"github.com/onflow/flow-go/engine/collection/compliance"
"github.com/onflow/flow-go/module"
"github.com/onflow/flow-go/module/buffer"
"github.com/onflow/flow-go/module/chainsync"
modulecompliance "github.com/onflow/flow-go/module/compliance"
"github.com/onflow/flow-go/network"
"github.com/onflow/flow-go/state/cluster"
"github.com/onflow/flow-go/state/protocol"
"github.com/onflow/flow-go/storage"
)
type ComplianceEngineFactory struct {
log zerolog.Logger
me module.Local
net network.Network
colMetrics module.CollectionMetrics
engMetrics module.EngineMetrics
mempoolMetrics module.MempoolMetrics
protoState protocol.State
transactions storage.Transactions
config modulecompliance.Config
}
// NewComplianceEngineFactory returns a new collection compliance engine factory.
func NewComplianceEngineFactory(
log zerolog.Logger,
net network.Network,
me module.Local,
colMetrics module.CollectionMetrics,
engMetrics module.EngineMetrics,
mempoolMetrics module.MempoolMetrics,
protoState protocol.State,
transactions storage.Transactions,
config modulecompliance.Config,
) (*ComplianceEngineFactory, error) {
factory := &ComplianceEngineFactory{
log: log,
me: me,
net: net,
colMetrics: colMetrics,
engMetrics: engMetrics,
mempoolMetrics: mempoolMetrics,
protoState: protoState,
transactions: transactions,
config: config,
}
return factory, nil
}
func (f *ComplianceEngineFactory) Create(
hotstuffMetrics module.HotstuffMetrics,
notifier hotstuff.ProposalViolationConsumer,
clusterState cluster.MutableState,
headers storage.Headers,
payloads storage.ClusterPayloads,
syncCore *chainsync.Core,
hot module.HotStuff,
voteAggregator hotstuff.VoteAggregator,
timeoutAggregator hotstuff.TimeoutAggregator,
validator hotstuff.Validator,
) (*compliance.Engine, error) {
cache := buffer.NewPendingClusterBlocks()
core, err := compliance.NewCore(
f.log,
f.engMetrics,
f.mempoolMetrics,
hotstuffMetrics,
f.colMetrics,
notifier,
headers,
clusterState,
cache,
syncCore,
validator,
hot,
voteAggregator,
timeoutAggregator,
f.config,
)
if err != nil {
return nil, fmt.Errorf("could create cluster compliance core: %w", err)
}
engine, err := compliance.NewEngine(
f.log,
f.me,
f.protoState,
payloads,
core,
)
return engine, err
}