-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathrun.go
More file actions
138 lines (115 loc) · 3.95 KB
/
run.go
File metadata and controls
138 lines (115 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package cmd
import (
"encoding/hex"
"fmt"
"path/filepath"
"github.com/spf13/cobra"
coreda "github.com/evstack/ev-node/core/da"
"github.com/evstack/ev-node/core/execution"
"github.com/evstack/ev-node/da/jsonrpc"
executiongrpc "github.com/evstack/ev-node/execution/grpc"
"github.com/evstack/ev-node/node"
rollcmd "github.com/evstack/ev-node/pkg/cmd"
"github.com/evstack/ev-node/pkg/config"
rollgenesis "github.com/evstack/ev-node/pkg/genesis"
"github.com/evstack/ev-node/pkg/p2p"
"github.com/evstack/ev-node/pkg/p2p/key"
"github.com/evstack/ev-node/pkg/store"
"github.com/evstack/ev-node/sequencers/single"
)
const (
// FlagGrpcExecutorURL is the flag for the gRPC executor endpoint
FlagGrpcExecutorURL = "grpc-executor-url"
)
var RunCmd = &cobra.Command{
Use: "start",
Aliases: []string{"node", "run"},
Short: "Run the evolve node with gRPC execution client",
Long: `Start a Evolve node that connects to a remote execution client via gRPC.
The execution client must implement the Evolve execution gRPC interface.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Create gRPC execution client
executor, err := createGRPCExecutionClient(cmd)
if err != nil {
return err
}
// Parse node configuration
nodeConfig, err := rollcmd.ParseConfig(cmd)
if err != nil {
return err
}
logger := rollcmd.SetupLogger(nodeConfig.Log)
headerNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.GetNamespace()))
dataNamespace := coreda.PrepareNamespace([]byte(nodeConfig.DA.GetDataNamespace()))
logger.Info().Str("headerNamespace", hex.EncodeToString(headerNamespace)).Str("dataNamespace", hex.EncodeToString(dataNamespace)).Msg("namespaces")
// Create DA client
daJrpc, err := jsonrpc.NewClient(cmd.Context(), logger, nodeConfig.DA.Address, nodeConfig.DA.AuthToken, nodeConfig.DA.GasPrice, nodeConfig.DA.GasMultiplier)
if err != nil {
return err
}
// Create datastore
datastore, err := store.NewDefaultKVStore(nodeConfig.RootDir, nodeConfig.DBPath, "grpc-single")
if err != nil {
return err
}
// Load genesis
genesis, err := rollgenesis.LoadGenesis(rollgenesis.GenesisPath(nodeConfig.RootDir))
if err != nil {
return err
}
// Create metrics provider
singleMetrics, err := single.DefaultMetricsProvider(nodeConfig.Instrumentation.IsPrometheusEnabled())(genesis.ChainID)
if err != nil {
return err
}
// Create sequencer
sequencer, err := single.NewSequencer(
cmd.Context(),
logger,
datastore,
&daJrpc.DA,
[]byte(genesis.ChainID),
nodeConfig.Node.BlockTime.Duration,
singleMetrics,
nodeConfig.Node.Aggregator,
)
if err != nil {
return err
}
// Load node key
nodeKey, err := key.LoadNodeKey(filepath.Dir(nodeConfig.ConfigPath()))
if err != nil {
return err
}
// Create P2P client
p2pClient, err := p2p.NewClient(nodeConfig.P2P, nodeKey.PrivKey, datastore, genesis.ChainID, logger, nil)
if err != nil {
return err
}
// Start the node
return rollcmd.StartNode(logger, cmd, executor, sequencer, &daJrpc.DA, p2pClient, datastore, nodeConfig, genesis, node.NodeOptions{})
},
}
func init() {
// Add evolve configuration flags
config.AddFlags(RunCmd)
// Add gRPC-specific flags
addGRPCFlags(RunCmd)
}
// createGRPCExecutionClient creates a new gRPC execution client from command flags
func createGRPCExecutionClient(cmd *cobra.Command) (execution.Executor, error) {
// Get the gRPC executor URL from flags
executorURL, err := cmd.Flags().GetString(FlagGrpcExecutorURL)
if err != nil {
return nil, fmt.Errorf("failed to get '%s' flag: %w", FlagGrpcExecutorURL, err)
}
if executorURL == "" {
return nil, fmt.Errorf("%s flag is required", FlagGrpcExecutorURL)
}
// Create and return the gRPC client
return executiongrpc.NewClient(executorURL), nil
}
// addGRPCFlags adds flags specific to the gRPC execution client
func addGRPCFlags(cmd *cobra.Command) {
cmd.Flags().String(FlagGrpcExecutorURL, "http://localhost:50051", "URL of the gRPC execution service")
}