github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/cmd/ghost/main.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/spf13/pflag"
     5  
     6  	"github.com/onflow/flow-go/cmd"
     7  	"github.com/onflow/flow-go/engine/ghost/engine"
     8  	"github.com/onflow/flow-go/module"
     9  	"github.com/onflow/flow-go/network"
    10  	"github.com/onflow/flow-go/network/validator"
    11  	"github.com/onflow/flow-go/utils/grpcutils"
    12  )
    13  
    14  func main() {
    15  	var (
    16  		rpcConf engine.Config
    17  	)
    18  
    19  	nodeBuilder := cmd.FlowNode("ghost")
    20  	nodeBuilder.ExtraFlags(func(flags *pflag.FlagSet) {
    21  		flags.StringVarP(&rpcConf.ListenAddr, "rpc-addr", "r", "localhost:9000", "the address the GRPC server listens on")
    22  		flags.UintVar(&rpcConf.MaxMsgSize, "rpc-max-message-size", grpcutils.DefaultMaxMsgSize, "the maximum message size in bytes for messages sent or received over grpc")
    23  	})
    24  
    25  	if err := nodeBuilder.Initialize(); err != nil {
    26  		nodeBuilder.Logger.Fatal().Err(err).Send()
    27  	}
    28  
    29  	nodeBuilder.
    30  		Module("message validators", func(node *cmd.NodeConfig) error {
    31  			validators := []network.MessageValidator{
    32  				// filter out messages sent by this node itself
    33  				validator.ValidateNotSender(node.Me.NodeID()),
    34  				// but retain all the 1-k messages even if they are not intended for this node
    35  			}
    36  			node.MsgValidators = validators
    37  			return nil
    38  		}).
    39  		Component("RPC engine", func(node *cmd.NodeConfig) (module.ReadyDoneAware, error) {
    40  			rpcEng, err := engine.New(node.EngineRegistry, node.Logger, node.Me, node.State, rpcConf)
    41  			return rpcEng, err
    42  		})
    43  
    44  	node, err := nodeBuilder.Build()
    45  	if err != nil {
    46  		nodeBuilder.Logger.Fatal().Err(err).Send()
    47  	}
    48  	node.Run()
    49  }