(ctx *cli.Context, cfg *config.BlockchainConfig)
| 57 | } |
| 58 | |
| 59 | func setGenesis(ctx *cli.Context, cfg *config.BlockchainConfig) error { |
| 60 | if ctx.Bool(utils.GetFlagName(utils.EnableTestModeFlag)) { |
| 61 | cfg.Genesis.ConsensusType = config.CONSENSUS_TYPE_SOLO |
| 62 | cfg.Genesis.SOLO.GenBlockTime = ctx.Uint(utils.GetFlagName(utils.TestModeGenBlockTimeFlag)) |
| 63 | if cfg.Genesis.SOLO.GenBlockTime <= 1 { |
| 64 | cfg.Genesis.SOLO.GenBlockTime = config.DEFAULT_GEN_BLOCK_TIME |
| 65 | } |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | if !ctx.IsSet(utils.GetFlagName(utils.ConfigFlag)) { |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | genesisFile := ctx.String(utils.GetFlagName(utils.ConfigFlag)) |
| 74 | if !common.FileExisted(genesisFile) { |
| 75 | return fmt.Errorf("load genesis file failed") |
| 76 | } |
| 77 | |
| 78 | newGenesisCfg := config.NewGenesisConfig() |
| 79 | err := utils.GetJsonObjectFromFile(genesisFile, newGenesisCfg) |
| 80 | if err != nil { |
| 81 | return fmt.Errorf("load genesis from %s failed: %s", genesisFile, err) |
| 82 | } |
| 83 | cfg.Genesis = newGenesisCfg |
| 84 | log.Infof("Load genesis config:%s", genesisFile) |
| 85 | |
| 86 | switch cfg.Genesis.ConsensusType { |
| 87 | case config.CONSENSUS_TYPE_DBFT: |
| 88 | if len(cfg.Genesis.DBFT.Bookkeepers) < config.DBFT_MIN_NODE_NUM { |
| 89 | return fmt.Errorf("DBFT consensus at least need %d bookkeepers in config", config.DBFT_MIN_NODE_NUM) |
| 90 | } |
| 91 | if cfg.Genesis.DBFT.GenBlockTime <= 0 { |
| 92 | cfg.Genesis.DBFT.GenBlockTime = config.DEFAULT_GEN_BLOCK_TIME |
| 93 | } |
| 94 | case config.CONSENSUS_TYPE_VBFT: |
| 95 | err = governance.CheckVBFTConfig(cfg.Genesis.VBFT) |
| 96 | if err != nil { |
| 97 | return fmt.Errorf("VBFT config error %v", err) |
| 98 | } |
| 99 | if len(cfg.Genesis.VBFT.Peers) < config.VBFT_MIN_NODE_NUM { |
| 100 | return fmt.Errorf("VBFT consensus at least need %d peers in config", config.VBFT_MIN_NODE_NUM) |
| 101 | } |
| 102 | default: |
| 103 | return fmt.Errorf("Unknow consensus:%s", cfg.Genesis.ConsensusType) |
| 104 | } |
| 105 | |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | func setCommonConfig(ctx *cli.Context, cfg *config.CommonConfig) { |
| 110 | cfg.LogLevel = ctx.Uint(utils.GetFlagName(utils.LogLevelFlag)) |
no test coverage detected