From d88663502249379d0b8780258b4c73b270c965b4 Mon Sep 17 00:00:00 2001 From: rian Date: Mon, 20 May 2024 12:01:36 +0300 Subject: [PATCH] add flag --- cmd/juno/juno.go | 44 ++++++++++++++++++++++++-------------------- node/node.go | 9 +++++---- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/cmd/juno/juno.go b/cmd/juno/juno.go index e048a2e370..dc563d5e3d 100644 --- a/cmd/juno/juno.go +++ b/cmd/juno/juno.go @@ -84,6 +84,7 @@ const ( corsEnableF = "rpc-cors-enable" seqEnF = "seq-enable" seqBlockTimeF = "seq-block-time" + seqBootstrapToBlockF = "seq-bootstrap-to-block" genesisFileF = "genesis-file" defaultConfig = "" @@ -122,6 +123,7 @@ const ( defaultCorsEnable = false defaultSeqEn = false defaultSeqBlockTime = 60 + defaultSeqBootstrapToBlock = 0 defaultGenesisFile = "" configFlagUsage = "The YAML configuration file." @@ -154,26 +156,27 @@ const ( "These peers can be either Feeder or regular nodes." p2pFeederNodeUsage = "EXPERIMENTAL: Run juno as a feeder node which will only sync from feeder gateway and gossip the new" + " blocks to the network." - p2pPrivateKeyUsage = "EXPERIMENTAL: Hexadecimal representation of a private key on the Ed25519 elliptic curve." - metricsUsage = "Enables the Prometheus metrics endpoint on the default port." - metricsHostUsage = "The interface on which the Prometheus endpoint will listen for requests." - metricsPortUsage = "The port on which the Prometheus endpoint will listen for requests." - grpcUsage = "Enable the HTTP gRPC server on the default port." - grpcHostUsage = "The interface on which the gRPC server will listen for requests." - grpcPortUsage = "The port on which the gRPC server will listen for requests." - maxVMsUsage = "Maximum number for VM instances to be used for RPC calls concurrently" - maxVMQueueUsage = "Maximum number for requests to queue after reaching max-vms before starting to reject incoming requests" - remoteDBUsage = "gRPC URL of a remote Juno node" - rpcMaxBlockScanUsage = "Maximum number of blocks scanned in single starknet_getEvents call" - dbCacheSizeUsage = "Determines the amount of memory (in megabytes) allocated for caching data in the database." - dbMaxHandlesUsage = "A soft limit on the number of open files that can be used by the DB" - gwAPIKeyUsage = "API key for gateway endpoints to avoid throttling" //nolint: gosec - gwTimeoutUsage = "Timeout for requests made to the gateway" //nolint: gosec - callMaxStepsUsage = "Maximum number of steps to be executed in starknet_call requests" - corsEnableUsage = "Enable CORS on RPC endpoints" - seqEnUsage = "Enables sequencer mode of operation" - seqBlockTimeUsage = "Time to build a block, in seconds" - genesisFileUsage = "Path to the genesis file" + p2pPrivateKeyUsage = "EXPERIMENTAL: Hexadecimal representation of a private key on the Ed25519 elliptic curve." + metricsUsage = "Enables the Prometheus metrics endpoint on the default port." + metricsHostUsage = "The interface on which the Prometheus endpoint will listen for requests." + metricsPortUsage = "The port on which the Prometheus endpoint will listen for requests." + grpcUsage = "Enable the HTTP gRPC server on the default port." + grpcHostUsage = "The interface on which the gRPC server will listen for requests." + grpcPortUsage = "The port on which the gRPC server will listen for requests." + maxVMsUsage = "Maximum number for VM instances to be used for RPC calls concurrently" + maxVMQueueUsage = "Maximum number for requests to queue after reaching max-vms before starting to reject incoming requests" + remoteDBUsage = "gRPC URL of a remote Juno node" + rpcMaxBlockScanUsage = "Maximum number of blocks scanned in single starknet_getEvents call" + dbCacheSizeUsage = "Determines the amount of memory (in megabytes) allocated for caching data in the database." + dbMaxHandlesUsage = "A soft limit on the number of open files that can be used by the DB" + gwAPIKeyUsage = "API key for gateway endpoints to avoid throttling" //nolint: gosec + gwTimeoutUsage = "Timeout for requests made to the gateway" //nolint: gosec + callMaxStepsUsage = "Maximum number of steps to be executed in starknet_call requests" + corsEnableUsage = "Enable CORS on RPC endpoints" + seqEnUsage = "Enables sequencer mode of operation" + seqBlockTimeUsage = "Time to build a block, in seconds" + seqBootstrapToBlockUsage = "How many blocks to sycn from network before running sequencer" + genesisFileUsage = "Path to the genesis file" ) var Version string @@ -357,6 +360,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr junoCmd.AddCommand(GenP2PKeyPair()) junoCmd.Flags().Bool(seqEnF, defaultSeqEn, seqEnUsage) junoCmd.Flags().Uint(seqBlockTimeF, defaultSeqBlockTime, seqBlockTimeUsage) + junoCmd.Flags().Uint(seqBootstrapToBlockF, defaultSeqBootstrapToBlock, seqBootstrapToBlockUsage) junoCmd.Flags().String(genesisFileF, defaultGenesisFile, genesisFileUsage) return junoCmd diff --git a/node/node.go b/node/node.go index 72d2cc41a6..db4543501a 100644 --- a/node/node.go +++ b/node/node.go @@ -91,9 +91,10 @@ type Config struct { GatewayAPIKey string `mapstructure:"gw-api-key"` GatewayTimeout time.Duration `mapstructure:"gw-timeout"` - Sequencer bool `mapstructure:"seq-enable"` - SeqBlockTime uint `mapstructure:"seq-block-time"` - GenesisFile string `mapstructure:"genesis-file"` + Sequencer bool `mapstructure:"seq-enable"` + SeqBlockTime uint `mapstructure:"seq-block-time"` + SeqBootstrapToBlock uint64 `mapstructure:"seq-bootstrap-to-block"` + GenesisFile string `mapstructure:"genesis-file"` } type Node struct { @@ -163,7 +164,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen poolDB, _ := pebble.NewMem() p := mempool.New(poolDB) sequencer := builder.New(pKey, new(felt.Felt).SetUint64(1337), chain, nodeVM, time.Second*time.Duration(cfg.SeqBlockTime), p, //nolint: gomnd,lll - log).WithBootstrap(true).WithStarknetData(starknetData).WithBootstrapToBlock(2) + log).WithBootstrap(true).WithStarknetData(starknetData).WithBootstrapToBlock(cfg.SeqBootstrapToBlock) rpcHandler = rpc.New(chain, sequencer, throttledVM, version, &cfg.Network, log).WithMempool(p) services = append(services, sequencer) } else {