github.com/koko1123/flow-go-1@v0.29.6/engine/collection/epochmgr/factories/builder.go (about)

     1  package factories
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/dgraph-io/badger/v3"
     7  	"github.com/rs/zerolog"
     8  
     9  	"github.com/koko1123/flow-go-1/module"
    10  	builder "github.com/koko1123/flow-go-1/module/builder/collection"
    11  	finalizer "github.com/koko1123/flow-go-1/module/finalizer/collection"
    12  	"github.com/koko1123/flow-go-1/module/mempool"
    13  	"github.com/koko1123/flow-go-1/network"
    14  	"github.com/koko1123/flow-go-1/storage"
    15  )
    16  
    17  type BuilderFactory struct {
    18  	db               *badger.DB
    19  	mainChainHeaders storage.Headers
    20  	trace            module.Tracer
    21  	opts             []builder.Opt
    22  	metrics          module.CollectionMetrics
    23  	pusher           network.Engine // engine for pushing finalized collection to consensus committee
    24  	log              zerolog.Logger
    25  }
    26  
    27  func NewBuilderFactory(
    28  	db *badger.DB,
    29  	mainChainHeaders storage.Headers,
    30  	trace module.Tracer,
    31  	metrics module.CollectionMetrics,
    32  	pusher network.Engine,
    33  	log zerolog.Logger,
    34  	opts ...builder.Opt,
    35  ) (*BuilderFactory, error) {
    36  
    37  	factory := &BuilderFactory{
    38  		db:               db,
    39  		mainChainHeaders: mainChainHeaders,
    40  		trace:            trace,
    41  		metrics:          metrics,
    42  		pusher:           pusher,
    43  		log:              log,
    44  		opts:             opts,
    45  	}
    46  	return factory, nil
    47  }
    48  
    49  func (f *BuilderFactory) Create(
    50  	clusterHeaders storage.Headers,
    51  	clusterPayloads storage.ClusterPayloads,
    52  	pool mempool.Transactions,
    53  ) (module.Builder, *finalizer.Finalizer, error) {
    54  
    55  	build, err := builder.NewBuilder(
    56  		f.db,
    57  		f.trace,
    58  		f.mainChainHeaders,
    59  		clusterHeaders,
    60  		clusterPayloads,
    61  		pool,
    62  		f.log,
    63  		f.opts...,
    64  	)
    65  	if err != nil {
    66  		return nil, nil, fmt.Errorf("could not create builder: %w", err)
    67  	}
    68  
    69  	final := finalizer.NewFinalizer(
    70  		f.db,
    71  		pool,
    72  		f.pusher,
    73  		f.metrics,
    74  	)
    75  
    76  	return build, final, nil
    77  }