github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/engine/access/state_stream/backend/engine.go (about) 1 package backend 2 3 import ( 4 "github.com/rs/zerolog" 5 6 "github.com/onflow/flow/protobuf/go/flow/executiondata" 7 8 "github.com/onflow/flow-go/model/flow" 9 "github.com/onflow/flow-go/module/component" 10 "github.com/onflow/flow-go/module/executiondatasync/execution_data/cache" 11 "github.com/onflow/flow-go/module/grpcserver" 12 "github.com/onflow/flow-go/module/irrecoverable" 13 "github.com/onflow/flow-go/storage" 14 ) 15 16 // Engine exposes the server with the state stream API. 17 // By default, this engine is not enabled. 18 // In order to run this engine a port for the GRPC server to be served on should be specified in the run config. 19 type Engine struct { 20 *component.ComponentManager 21 log zerolog.Logger 22 backend *StateStreamBackend 23 config Config 24 chain flow.Chain 25 handler *Handler 26 27 execDataCache *cache.ExecutionDataCache 28 headers storage.Headers 29 } 30 31 // NewEng returns a new ingress server. 32 func NewEng( 33 log zerolog.Logger, 34 config Config, 35 execDataCache *cache.ExecutionDataCache, 36 headers storage.Headers, 37 chainID flow.ChainID, 38 server *grpcserver.GrpcServer, 39 backend *StateStreamBackend, 40 ) (*Engine, error) { 41 logger := log.With().Str("engine", "state_stream_rpc").Logger() 42 43 e := &Engine{ 44 log: logger, 45 backend: backend, 46 headers: headers, 47 chain: chainID.Chain(), 48 config: config, 49 handler: NewHandler(backend, chainID.Chain(), config), 50 execDataCache: execDataCache, 51 } 52 53 e.ComponentManager = component.NewComponentManagerBuilder(). 54 AddWorker(func(ctx irrecoverable.SignalerContext, ready component.ReadyFunc) { 55 ready() 56 <-server.Done() 57 }). 58 Build() 59 60 executiondata.RegisterExecutionDataAPIServer(server.Server, e.handler) 61 62 return e, nil 63 }