(ctx *cli.Context)
| 215 | } |
| 216 | |
| 217 | func EsNodeInit(ctx *cli.Context) error { |
| 218 | lg.Info("Will create data files for storage node") |
| 219 | l1Rpc := readRequiredFlag(ctx, flags.L1NodeAddr) |
| 220 | contract := readRequiredFlag(ctx, flags.StorageL1Contract) |
| 221 | if !common.IsHexAddress(contract) { |
| 222 | return fmt.Errorf("invalid contract address %s", contract) |
| 223 | } |
| 224 | |
| 225 | datadir := readRequiredFlag(ctx, flags.DataDir) |
| 226 | encodingType := ethstorage.ENCODE_BLOB_POSEIDON |
| 227 | miner := "0x" |
| 228 | if ctx.IsSet(encodingTypeFlagName) { |
| 229 | encodingType = ctx.Int(encodingTypeFlagName) |
| 230 | lg.Info("Read flag", "name", encodingTypeFlagName, "value", encodingType) |
| 231 | if encodingType > 3 || encodingType < 0 { |
| 232 | return fmt.Errorf("encoding_type must be an integer between 0 and 3") |
| 233 | } |
| 234 | } |
| 235 | if encodingType != ethstorage.NO_ENCODE { |
| 236 | miner = readRequiredFlag(ctx, flags.StorageMiner) |
| 237 | if !common.IsHexAddress(miner) { |
| 238 | return fmt.Errorf("invalid miner address %s", miner) |
| 239 | } |
| 240 | } |
| 241 | shardIndexes := ctx.Int64Slice(shardIndexFlagName) |
| 242 | lg.Info("Read flag", "name", shardIndexFlagName, "value", shardIndexes) |
| 243 | shardLen := 0 |
| 244 | if len(shardIndexes) == 0 { |
| 245 | shards := ctx.Int(shardLenFlagName) |
| 246 | lg.Info("Read flag", "name", shardLenFlagName, "value", shards) |
| 247 | if shards == 0 { |
| 248 | return fmt.Errorf("shard_len or shard_index must be specified") |
| 249 | } |
| 250 | shardLen = shards |
| 251 | } |
| 252 | cctx := context.Background() |
| 253 | client, err := ethclient.DialContext(cctx, l1Rpc) |
| 254 | if err != nil { |
| 255 | lg.Error("Failed to connect to the Ethereum client", "error", err, "l1Rpc", l1Rpc) |
| 256 | return err |
| 257 | } |
| 258 | defer client.Close() |
| 259 | |
| 260 | l1Contract := common.HexToAddress(contract) |
| 261 | storageCfg, err := initStorageConfig(cctx, client, l1Contract, common.HexToAddress(miner), lg) |
| 262 | if err != nil { |
| 263 | lg.Error("Failed to load storage config", "error", err) |
| 264 | return err |
| 265 | } |
| 266 | lg.Info("Storage config loaded", "storageCfg", storageCfg) |
| 267 | var shardIdxList []uint64 |
| 268 | if len(shardIndexes) > 0 { |
| 269 | out: |
| 270 | for i := 0; i < len(shardIndexes); i++ { |
| 271 | new := uint64(shardIndexes[i]) |
| 272 | // prevent duplicated |
| 273 | for _, s := range shardIdxList { |
| 274 | if s == new { |
nothing calls this directly
no test coverage detected