github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/collection/epochmgr/factories/compliance.go (about)

     1  package factories
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/rs/zerolog"
     7  
     8  	"github.com/onflow/flow-go/consensus/hotstuff"
     9  	"github.com/onflow/flow-go/engine/collection/compliance"
    10  	"github.com/onflow/flow-go/module"
    11  	"github.com/onflow/flow-go/module/buffer"
    12  	"github.com/onflow/flow-go/module/chainsync"
    13  	modulecompliance "github.com/onflow/flow-go/module/compliance"
    14  	"github.com/onflow/flow-go/network"
    15  	"github.com/onflow/flow-go/state/cluster"
    16  	"github.com/onflow/flow-go/state/protocol"
    17  	"github.com/onflow/flow-go/storage"
    18  )
    19  
    20  type ComplianceEngineFactory struct {
    21  	log            zerolog.Logger
    22  	me             module.Local
    23  	net            network.EngineRegistry
    24  	colMetrics     module.CollectionMetrics
    25  	engMetrics     module.EngineMetrics
    26  	mempoolMetrics module.MempoolMetrics
    27  	protoState     protocol.State
    28  	transactions   storage.Transactions
    29  	config         modulecompliance.Config
    30  }
    31  
    32  // NewComplianceEngineFactory returns a new collection compliance engine factory.
    33  func NewComplianceEngineFactory(
    34  	log zerolog.Logger,
    35  	net network.EngineRegistry,
    36  	me module.Local,
    37  	colMetrics module.CollectionMetrics,
    38  	engMetrics module.EngineMetrics,
    39  	mempoolMetrics module.MempoolMetrics,
    40  	protoState protocol.State,
    41  	transactions storage.Transactions,
    42  	config modulecompliance.Config,
    43  ) (*ComplianceEngineFactory, error) {
    44  
    45  	factory := &ComplianceEngineFactory{
    46  		log:            log,
    47  		me:             me,
    48  		net:            net,
    49  		colMetrics:     colMetrics,
    50  		engMetrics:     engMetrics,
    51  		mempoolMetrics: mempoolMetrics,
    52  		protoState:     protoState,
    53  		transactions:   transactions,
    54  		config:         config,
    55  	}
    56  	return factory, nil
    57  }
    58  
    59  func (f *ComplianceEngineFactory) Create(
    60  	hotstuffMetrics module.HotstuffMetrics,
    61  	notifier hotstuff.ProposalViolationConsumer,
    62  	clusterState cluster.MutableState,
    63  	headers storage.Headers,
    64  	payloads storage.ClusterPayloads,
    65  	syncCore *chainsync.Core,
    66  	hot module.HotStuff,
    67  	voteAggregator hotstuff.VoteAggregator,
    68  	timeoutAggregator hotstuff.TimeoutAggregator,
    69  	validator hotstuff.Validator,
    70  ) (*compliance.Engine, error) {
    71  
    72  	cache := buffer.NewPendingClusterBlocks()
    73  	core, err := compliance.NewCore(
    74  		f.log,
    75  		f.engMetrics,
    76  		f.mempoolMetrics,
    77  		hotstuffMetrics,
    78  		f.colMetrics,
    79  		notifier,
    80  		headers,
    81  		clusterState,
    82  		cache,
    83  		syncCore,
    84  		validator,
    85  		hot,
    86  		voteAggregator,
    87  		timeoutAggregator,
    88  		f.config,
    89  	)
    90  	if err != nil {
    91  		return nil, fmt.Errorf("could create cluster compliance core: %w", err)
    92  	}
    93  
    94  	engine, err := compliance.NewEngine(
    95  		f.log,
    96  		f.me,
    97  		f.protoState,
    98  		payloads,
    99  		core,
   100  	)
   101  	return engine, err
   102  }