Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dik654 committed Mar 26, 2024
1 parent 724ec13 commit 26cb0d9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions protocol/app/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,25 @@ func AddFlagsToCmd(cmd *cobra.Command) {
"This disables the pricing daemon and enables the full-node ProcessProposal logic. "+
"Validators should _never_ use this mode.",
)
// cobra 커맨드라인 argument로 string 값인 DdAgentHost를 선언
cmd.Flags().String(
DdAgentHost,
DefaultDdAgentHost,
"Sets the address to connect to for the Datadog Agent.",
)
// cobra 커맨드라인 argument로 uint16 값인 DdTraceAgentPort를 선언
cmd.Flags().Uint16(
DdTraceAgentPort,
DefaultDdTraceAgentPort,
"Sets the Datadog Agent port.",
)
// cobra 커맨드라인 argument로 bool 값인 DdErrorTrackingFormat 선언
cmd.Flags().Bool(
DdErrorTrackingFormat,
DefaultDdErrorTrackingFormat,
"Enable formatting of log error tags to datadog error tracking format",
)
// cobra 커맨드라인 argument로 bool 값인 GrpcStreamingEnabled 선언
cmd.Flags().Bool(
GrpcStreamingEnabled,
DefaultGrpcStreamingEnabled,
Expand Down
3 changes: 3 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ func AddInitCmdPostRunE(rootCmd *cobra.Command) {
// Add PostRun to configure required setups after `init`.
initCmd.PostRunE = func(cmd *cobra.Command, args []string) error {
// Get home directory.
// cmd에서 client.context에 해당하는 컨텍스트가 존재한다면 해당 컨텍스트를 리턴
// 없다면 새로운 컨텍스트를 생성하여 리턴
clientCtx := client.GetClientContextFromCmd(cmd)

// Add default pricefeed exchange config toml file if it does not exist.
// pricefeed exchange toml이 없다면 홈 디렉터리를 포함하여 생성
configs.WriteDefaultPricefeedExchangeToml(clientCtx.HomeDir)
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (

// NewRootCmd creates a new root command for `dydxprotocold`. It is called once in the main function.
// TODO(DEC-1097): improve `cmd/` by adding tests, custom app configs, custom init cmd, and etc.
// dydxprotocold를 실행시키면 나오는 명령어 리스트 생성
func NewRootCmd(
option *RootCmdOption,
homeDir string,
Expand All @@ -85,15 +86,22 @@ func NewRootCmdWithInterceptors(
appConfigInterceptor func(string, *DydxAppConfig) (string, *DydxAppConfig),
appInterceptor func(app *dydxapp.App) *dydxapp.App,
) *cobra.Command {
// viper 인스턴스 생성
initAppOptions := viper.New()
// 초기화를 위해 tempDir()로 임시 홈 디렉터리 설정
initAppOptions.Set(flags.FlagHome, tempDir())
// 초기화를 위해 임시 baseApp 인스턴스 생성
// 기본 설정, KVStore key, keeper등 설정
tempApp := dydxapp.New(
// logger와 DB설정
log.NewNopLogger(),
dbm.NewMemDB(),
nil,
true,
// 임시 디렉터리 설정된 viper 인스턴스
initAppOptions,
)
// 모든 작업 완료 후 baseApp 리소스 정리
defer func() {
if err := tempApp.Close(); err != nil {
panic(err)
Expand Down Expand Up @@ -134,9 +142,14 @@ func NewRootCmdWithInterceptors(
return err
}

// cmd/dydxprotocold/cmd/config.go의 initAppConfig()에서 기본 앱 설정 가져오기
customAppTemplate, customAppConfig := appConfigInterceptor(initAppConfig())
// 동일한 파일에서 tendermint 기본설정 가져오기
customTMConfig := initTendermintConfig()

// logger 설정
// 앱과 cometBFT 설정 파싱 후
// 해당 컨텍스트(serverCtx)를 cmd의 컨텍스트에 적용
if err := server.InterceptConfigsPreRunHandler(
cmd,
customAppTemplate,
Expand All @@ -146,6 +159,7 @@ func NewRootCmdWithInterceptors(
return err
}

// 적용한 서버 컨텍스트 가져오거나 생성
serverCtx := server.GetServerContextFromCmd(cmd)

// Format logs for error tracking if it is enabled via flags.
Expand Down
2 changes: 2 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/root_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ type RootCmdOption struct {
}

// newRootCmdOption returns an empty RootCmdOption.
// RootCmdOption 구조체 생성
func newRootCmdOption() *RootCmdOption {
return &RootCmdOption{}
}

// setCustomizeStartCmd accepts a handler to customize the start command and set it in the option.
// flag를 cmd에 등록
func (o *RootCmdOption) setCustomizeStartCmd(f func(startCmd *cobra.Command)) {
o.startCmdCustomizer = f
}
7 changes: 7 additions & 0 deletions protocol/cmd/dydxprotocold/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ func GetOptionWithCustomStartCmd() *RootCmdOption {
f := func(cmd *cobra.Command) {
// Add app flags.
// app/flags/flags.go
// 호스트명, 포트, GRPC 여부, 풀노드 여부 관련
// full node start 명령어의 flag argument 선언
appflags.AddFlagsToCmd(cmd)

// Add daemon flags.
// daemons/flags/flags.go
// price, bridge, liquidation oracle 관련
// full node start 명령어의 flag argument 선언
daemonflags.AddDaemonFlagsToCmd(cmd)

// Add indexer flags.
// indexer/flags.go
// full node start 명령어의 카프카 관련 flag argument 선언
indexer.AddIndexerFlagsToCmd(cmd)

// Add clob flags.
// x/clob/flags/flags.go
// full node start 명령어의 청산시도 횟수, Telemetry 관련 flag argument 선언
clobflags.AddClobFlagsToCmd(cmd)
}
// cmd/dydxprotocold/cmd/root_option.go
// 위의 flag argument들을 start에 등록
option.setCustomizeStartCmd(f)
return option
}
4 changes: 4 additions & 0 deletions protocol/cmd/dydxprotocold/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ func main() {
config.SetupConfig()

// cmd/dydxprotocold/cmd/start.go
// start에 flag argument 등록
option := cmd.GetOptionWithCustomStartCmd()
// cmd/dydxprotocold/cmd/root.go
// dydxprotocold를 실행시키면 나오는 명령어 리스트 생성
rootCmd := cmd.NewRootCmd(option, app.DefaultNodeHome)

// cmd/dydxprotocold/cmd/tendermint.go
// 개인키 생성 명령어 및 개인키, 코덱등 디버그 명령어 생성
cmd.AddTendermintSubcommands(rootCmd)
// cmd/dydxprotocold/cmd/init.go
// init 명령어 생성
cmd.AddInitCmdPostRunE(rootCmd)

if err := svrcmd.Execute(rootCmd, constants.AppDaemonName, app.DefaultNodeHome); err != nil {
Expand Down

0 comments on commit 26cb0d9

Please sign in to comment.