Skip to content

Commit

Permalink
Merge branch 'main' into jbowen93/pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowen93 authored Jan 7, 2022
2 parents ff7ecf6 + 6503125 commit 3dfaaa6
Show file tree
Hide file tree
Showing 46 changed files with 1,045 additions and 1,312 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG-PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ Month, DD, YYYY

### IMPROVEMENTS

- [cmd: introduce Env - an Environment for CLI commands #313](https://github.com/celestiaorg/celestia-node/pull/313) [@Wondertan](https://github.com/Wondertan)
- [chore: bump deps #297](https://github.com/celestiaorg/celestia-node/pull/297) [@Wondertan](https://github.com/Wondertan)
- [workflows/lint: update golangci-lint to v1.43 #308](https://github.com/celestiaorg/celestia-node/pull/308) [@Wondertan](https://github.com/Wondertan)
- [feat(node): extract overrides from Config into Settings #292](https://github.com/celestiaorg/celestia-node/pull/292) [@Wondertan](https://github.com/Wondertan)
- [node: Adding WithHost options to settings section #301](https://github.com/celestiaorg/celestia-node/pull/301) [@Bidon15](https://github.com/Bidon15)

- [node: Adding WithCoreClient option #305](https://github.com/celestiaorg/celestia-node/pull/305) [@Bidon15](https://github.com/Bidon15)
- [refactor(services/header): Refactor `HeaderService` to only manage its sub-services' lifecycles #317](https://github.com/celestiaorg/celestia-node/pull/317) [@renaynay](https://github.com/renaynay)
- [docker] Created `docker/` dir with `Dockerfile` and `entrypoint.sh` script.
- [chore(share): handle rows concurrently in GetSharesByNamespace #241](https://github.com/celestiaorg/celestia-node/pull/241) [@vgonkivs](https://github.com/vgonkivs)

### BUG FIXES

- [go package] (Link to PR) Description @username
- [Properly fetch Validators from Core and two more fixes #328](https://github.com/celestiaorg/celestia-node/pull/328) [@Wondertan](https://github.com/Wondertan)
- [header] Added missing `err` value in ErrorW logging calls. @jbowen93
- [service/block, node/p2p] [Fix race conditions in TestExtendedHeaderBroadcast and TestFull_P2P_Streams.](https://github.com/celestiaorg/celestia-node/pull/288) [@jenyasd209](https://github.com/jenyasd209)
- [ci: increase tokens ratio for dupl to fix false positive scenarios](https://github.com/celestiaorg/celestia-node/pull/314) [@Bidon15](https://github.com/Bidon15)
- [node: update vanilla datastore with Mutex one](https://github.com/celestiaorg/celestia-node/pull/325) [@Bidon15](https://github.com/Bidon15)

### MISC

Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ test:
@go test -v ./...
.PHONY: test

## benchmark: Running all benchmarks
benchmark:
@echo "--> Running benchmarks"
@go test -run="none" -bench=. -benchtime=100x -benchmem ./...
.PHONY: benchmark

PB_PKGS=$(shell find . -name 'pb' -type d)
PB_CORE=$(shell go list -f {{.Dir}} -m github.com/tendermint/tendermint)
PB_GOGO=$(shell go list -f {{.Dir}} -m github.com/gogo/protobuf)
Expand Down
5 changes: 4 additions & 1 deletion cmd/cel-shed/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package main

import (
"context"
"os"

"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/cmd"
)

func init() {
Expand All @@ -25,5 +28,5 @@ func main() {
}

func run() error {
return rootCmd.Execute()
return rootCmd.ExecuteContext(cmd.WithEnv(context.Background()))
}
59 changes: 48 additions & 11 deletions cmd/celestia/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,61 @@ package main
import (
"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/cmd"
cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/node"
)

// NOTE: We should always ensure that the added Flags below are parsed somewhere, like in the PersistenPreRun func on
// parent command.

func init() {
bridgeCmd.AddCommand(
cmd.Init(storeFlagName, node.Bridge),
cmd.Start(storeFlagName, node.Bridge),
)
bridgeCmd.PersistentFlags().StringP(
storeFlagName,
storeFlagShort,
"~/.celestia-bridge",
"The root/home directory of your Celestial Bridge Node",
cmdnode.Init(
cmdnode.NodeFlags(node.Bridge),
cmdnode.P2PFlags(),
cmdnode.CoreFlags(),
cmdnode.MiscFlags(),
),
cmdnode.Start(
cmdnode.NodeFlags(node.Bridge),
cmdnode.P2PFlags(),
cmdnode.CoreFlags(),
cmdnode.MiscFlags(),
),
)
}

var bridgeCmd = &cobra.Command{
Use: "bridge [subcommand]",
Args: cobra.NoArgs,
Use: "bridge [subcommand]",
Args: cobra.NoArgs,
Short: "Manage your Bridge node",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
env, err := cmdnode.GetEnv(cmd.Context())
if err != nil {
return err
}
env.SetNodeType(node.Bridge)

err = cmdnode.ParseNodeFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseP2PFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseCoreFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseMiscFlags(cmd)
if err != nil {
return err
}

return nil
},
}
59 changes: 48 additions & 11 deletions cmd/celestia/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,61 @@ package main
import (
"github.com/spf13/cobra"

"github.com/celestiaorg/celestia-node/cmd"
cmdnode "github.com/celestiaorg/celestia-node/cmd"
"github.com/celestiaorg/celestia-node/node"
)

// NOTE: We should always ensure that the added Flags below are parsed somewhere, like in the PersistenPreRun func on
// parent command.

func init() {
lightCmd.AddCommand(
cmd.Init(storeFlagName, node.Light),
cmd.Start(storeFlagName, node.Light),
)
lightCmd.PersistentFlags().StringP(
storeFlagName,
storeFlagShort,
"~/.celestia-light",
"The root/home directory of your Celestial Light Node",
cmdnode.Init(
cmdnode.NodeFlags(node.Light),
cmdnode.P2PFlags(),
cmdnode.HeadersFlags(),
cmdnode.MiscFlags(),
),
cmdnode.Start(
cmdnode.NodeFlags(node.Light),
cmdnode.P2PFlags(),
cmdnode.HeadersFlags(),
cmdnode.MiscFlags(),
),
)
}

var lightCmd = &cobra.Command{
Use: "light [subcommand]",
Args: cobra.NoArgs,
Use: "light [subcommand]",
Args: cobra.NoArgs,
Short: "Manage your Light node",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
env, err := cmdnode.GetEnv(cmd.Context())
if err != nil {
return err
}
env.SetNodeType(node.Light)

err = cmdnode.ParseNodeFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseP2PFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseHeadersFlags(cmd, env)
if err != nil {
return err
}

err = cmdnode.ParseMiscFlags(cmd)
if err != nil {
return err
}

return nil
},
}
12 changes: 7 additions & 5 deletions cmd/celestia/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package main

import (
"context"
"os"

"github.com/spf13/cobra"
)

const (
storeFlagName = "store.path"
storeFlagShort = "s"
"github.com/celestiaorg/celestia-node/cmd"
)

func init() {
Expand All @@ -17,6 +15,7 @@ func init() {
lightCmd,
versionCmd,
)
rootCmd.SetHelpCommand(&cobra.Command{})
}

func main() {
Expand All @@ -27,7 +26,7 @@ func main() {
}

func run() error {
return rootCmd.Execute()
return rootCmd.ExecuteContext(cmd.WithEnv(context.Background()))
}

var rootCmd = &cobra.Command{
Expand All @@ -39,4 +38,7 @@ var rootCmd = &cobra.Command{
\____/\___/_/\___/____/\__/_/\__,_/
`,
Args: cobra.NoArgs,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
}
4 changes: 2 additions & 2 deletions cmd/celestia/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Show information about the current binary build",
Args: cobra.NoArgs,
Run: getBuildInfo,
Run: printBuildInfo,
}

func getBuildInfo(cmd *cobra.Command, args []string) {
func printBuildInfo(_ *cobra.Command, _ []string) {
fmt.Printf("Semantic version: %s\n", semanticVersion)
fmt.Printf("Commit: %s\n", lastCommit)
fmt.Printf("Build Date: %s\n", buildTime)
Expand Down
58 changes: 58 additions & 0 deletions cmd/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cmd

import (
"context"
"fmt"

"github.com/celestiaorg/celestia-node/node"
)

// Env is an environment for CLI commands.
// It can be used to:
// 1. Propagate values from parent to child commands.
// 2. To group common logic that multiple commands rely on.
// Usage can be extended.
type Env struct {
NodeType node.Type
StorePath string

opts []node.Option
}

// WithEnv wraps given ctx with Env.
func WithEnv(ctx context.Context) context.Context {
_, err := GetEnv(ctx)
if err == nil {
panic("cmd: only one Env is allowed to be set in a ctx")
}

return context.WithValue(ctx, envCtxKey{}, &Env{})
}

// GetEnv takes Env from the given ctx, if any.
func GetEnv(ctx context.Context) (*Env, error) {
env, ok := ctx.Value(envCtxKey{}).(*Env)
if !ok {
return nil, fmt.Errorf("cmd: Env is not set in ctx.Context")
}

return env, nil
}

// SetNodeType sets Node Type to the Env.
func (env *Env) SetNodeType(tp node.Type) {
env.NodeType = tp
}

// Options returns Node Options parsed from Environment(Flags, ENV vars, etc)
func (env *Env) Options() []node.Option {
return env.opts
}

// AddOptions add new options to Env.
func (env *Env) AddOptions(opts ...node.Option) {
env.opts = append(env.opts, opts...)
}

// envCtxKey is a key used to identify Env on a ctx.Context.
type envCtxKey struct{}
48 changes: 0 additions & 48 deletions cmd/flags.go

This file was deleted.

Loading

0 comments on commit 3dfaaa6

Please sign in to comment.