Skip to content

Commit

Permalink
Merge branch 'main-celestia' into discovery_metrics
Browse files Browse the repository at this point in the history
# Conflicts:
#	share/availability/discovery/discovery.go
  • Loading branch information
walldiss committed May 9, 2023
2 parents 894ee4e + 7f556f0 commit f722beb
Show file tree
Hide file tree
Showing 28 changed files with 295 additions and 140 deletions.
6 changes: 6 additions & 0 deletions cmd/celestia/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func persistentPreRunEnv(cmd *cobra.Command, nodeType node.Type, _ []string) err
return err
}
ctx = cmdnode.WithNetwork(ctx, parsedNetwork)
ctx = cmdnode.WithNodeBuildInfo(ctx, &node.BuildInfo{
LastCommit: lastCommit,
SemanticVersion: semanticVersion,
SystemVersion: systemVersion,
GolangVersion: golangVersion,
})

// loads existing config into the environment
ctx, err = cmdnode.ParseNodeFlags(ctx, cmd, cmdnode.Network(ctx))
Expand Down
7 changes: 5 additions & 2 deletions cmd/celestia/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ var (
buildTime string
lastCommit string
semanticVersion string

systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS)
golangVersion = runtime.Version()
)

var versionCmd = &cobra.Command{
Expand All @@ -24,6 +27,6 @@ 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)
fmt.Printf("System version: %s/%s\n", runtime.GOARCH, runtime.GOOS)
fmt.Printf("Golang version: %s\n", runtime.Version())
fmt.Printf("System version: %s\n", systemVersion)
fmt.Printf("Golang version: %s\n", golangVersion)
}
11 changes: 11 additions & 0 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func NodeConfig(ctx context.Context) nodebuilder.Config {
return cfg
}

// NodeInfo reads the node build inforamtion from the context.
func NodeInfo(ctx context.Context) node.BuildInfo {
return ctx.Value(buildInfo{}).(node.BuildInfo)
}

// WithNodeType sets the node type in the given context.
func WithNodeType(ctx context.Context, tp node.Type) context.Context {
return context.WithValue(ctx, nodeTypeKey{}, tp)
Expand Down Expand Up @@ -73,10 +78,16 @@ func WithNodeConfig(ctx context.Context, config *nodebuilder.Config) context.Con
return context.WithValue(ctx, configKey{}, *config)
}

// WithNodeConfig sets the node config build information.
func WithNodeBuildInfo(ctx context.Context, info *node.BuildInfo) context.Context {
return context.WithValue(ctx, buildInfo{}, *info)
}

type (
optionsKey struct{}
configKey struct{}
storePathKey struct{}
nodeTypeKey struct{}
networkKey struct{}
buildInfo struct{}
)
2 changes: 1 addition & 1 deletion cmd/flags_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func ParseMiscFlags(ctx context.Context, cmd *cobra.Command) (context.Context, e
opts = append(opts, otlpmetrichttp.WithInsecure())
}

ctx = WithNodeOptions(ctx, nodebuilder.WithMetrics(opts, NodeType(ctx)))
ctx = WithNodeOptions(ctx, nodebuilder.WithMetrics(opts, NodeType(ctx), NodeInfo(ctx)))
}

ok, err = cmd.Flags().GetBool(p2pMetrics)
Expand Down
1 change: 1 addition & 0 deletions core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func StartTestNodeWithConfig(t *testing.T, cfg *TestConfig) testnode.Context {
state,
kr,
"private",
nil,
)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/BurntSushi/toml v1.2.1
github.com/alecthomas/jsonschema v0.0.0-20200530073317-71f438968921
github.com/benbjohnson/clock v1.3.0
github.com/celestiaorg/celestia-app v0.12.2
github.com/celestiaorg/celestia-app v0.13.0
github.com/celestiaorg/go-fraud v0.1.0
github.com/celestiaorg/go-header v0.2.7
github.com/celestiaorg/go-libp2p-messenger v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
github.com/celestiaorg/celestia-app v0.12.2 h1:Mlxzz2SS+uvE4RnbSuXAh4MagiJBW7GnhDa+8kVbzKE=
github.com/celestiaorg/celestia-app v0.12.2/go.mod h1:lKhL1Oxk4Z29M+GQ25luTHBgwSvgiT4puPeBrjdsgXc=
github.com/celestiaorg/celestia-app v0.13.0 h1:NPOR1P98YCCv+E2I9TdqsO1/UnGyzTHW5CBhctWHaOY=
github.com/celestiaorg/celestia-app v0.13.0/go.mod h1:OcPBfWDyowJgoEQ89NB2LgLOm9LSwloCgCzdZKjmi78=
github.com/celestiaorg/celestia-core v1.15.0-tm-v0.34.23 h1:BHvn41IHOtvHeX1VZqO/xBFIHj93llcw9ZQfNxyVRlI=
github.com/celestiaorg/celestia-core v1.15.0-tm-v0.34.23/go.mod h1:nL+vkAMKy/A8wWemWqMwBy4pOGWYYbboAVTEe3N5gIU=
github.com/celestiaorg/cosmos-sdk v1.8.0-sdk-v0.46.7 h1:EADZy33ufskVIy6Rj6jbi3SOVCeYYo26zUi7iYx+QR0=
Expand Down
1 change: 1 addition & 0 deletions logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func SetAllLoggers(level logging.LogLevel) {
_ = logging.SetLogLevel("net/identify", "ERROR")
_ = logging.SetLogLevel("shrex/nd", "WARN")
_ = logging.SetLogLevel("shrex/eds", "WARN")
_ = logging.SetLogLevel("fx", "FATAL")
}

func SetDebugLogging() {
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func DefaultConfig(tp node.Type) *Config {
P2P: p2p.DefaultConfig(tp),
RPC: rpc.DefaultConfig(),
Gateway: gateway.DefaultConfig(),
Share: share.DefaultConfig(),
Share: share.DefaultConfig(tp),
Header: header.DefaultConfig(tp),
}

Expand Down
6 changes: 3 additions & 3 deletions nodebuilder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/celestiaorg/celestia-node/nodebuilder/state"
)

var Timeout = time.Second * 30
var Timeout = time.Minute * 2

var (
log = logging.Logger("node")
Expand Down Expand Up @@ -100,7 +100,7 @@ func (n *Node) Start(ctx context.Context) error {
if err != nil {
log.Debugf("error starting %s Node: %s", n.Type, err)
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("node: failed to start within timeout(%s): %w", Timeout, errors.Unwrap(err))
return fmt.Errorf("node: failed to start within timeout(%s): %w", Timeout, err)
}
return fmt.Errorf("node: failed to start: %w", err)
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (n *Node) Stop(ctx context.Context) error {
if err != nil {
log.Debugf("error stopping %s Node: %s", n.Type, err)
if errors.Is(err, context.DeadlineExceeded) {
return fmt.Errorf("node: failed to stop within timeout(%s): %w", Timeout, errors.Unwrap(err))
return fmt.Errorf("node: failed to stop within timeout(%s): %w", Timeout, err)
}
return fmt.Errorf("node: failed to stop: %w", err)
}
Expand Down
9 changes: 9 additions & 0 deletions nodebuilder/node/buildInfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package node

// BuildInfo stores all necessary information for the current build.
type BuildInfo struct {
LastCommit string
SemanticVersion string
SystemVersion string
GolangVersion string
}
1 change: 1 addition & 0 deletions nodebuilder/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func TestLifecycle_WithMetrics(t *testing.T) {
otlpmetrichttp.WithInsecure(),
},
tt.tp,
node.BuildInfo{},
),
)
require.NotNil(t, node)
Expand Down
10 changes: 5 additions & 5 deletions nodebuilder/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ func WithPyroscope(endpoint string, nodeType node.Type) fx.Option {
}

// WithMetrics enables metrics exporting for the node.
func WithMetrics(metricOpts []otlpmetrichttp.Option, nodeType node.Type) fx.Option {
func WithMetrics(metricOpts []otlpmetrichttp.Option, nodeType node.Type, buildInfo node.BuildInfo) fx.Option {
baseComponents := fx.Options(
fx.Supply(metricOpts),
fx.Supply(buildInfo),
fx.Invoke(initializeMetrics),
fx.Invoke(state.WithMetrics),
fx.Invoke(fraud.WithMetrics),
Expand Down Expand Up @@ -110,6 +111,7 @@ func initializeMetrics(
lc fx.Lifecycle,
peerID peer.ID,
nodeType node.Type,
buildInfo node.BuildInfo,
opts []otlpmetrichttp.Option,
) error {
exp, err := otlpmetrichttp.New(ctx, opts...)
Expand All @@ -121,17 +123,15 @@ func initializeMetrics(
metric.WithReader(metric.NewPeriodicReader(exp, metric.WithTimeout(2*time.Second))),
metric.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String(fmt.Sprintf("Celestia-%s", nodeType.String())),
// TODO(@Wondertan): Versioning: semconv.ServiceVersionKey
semconv.ServiceNamespaceKey.String(fmt.Sprintf("Celestia-%s", nodeType.String())),
semconv.ServiceNameKey.String(fmt.Sprintf("semver-%s", buildInfo.SemanticVersion)),
semconv.ServiceInstanceIDKey.String(peerID.String()),
)))

lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return provider.Shutdown(ctx)
},
})
global.SetMeterProvider(provider)

return nil
}
51 changes: 39 additions & 12 deletions nodebuilder/share/config.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
package share

import (
disc "github.com/celestiaorg/celestia-node/share/availability/discovery"
"fmt"

"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/share/availability/discovery"
"github.com/celestiaorg/celestia-node/share/availability/light"
"github.com/celestiaorg/celestia-node/share/p2p/peers"
"github.com/celestiaorg/celestia-node/share/p2p/shrexeds"
"github.com/celestiaorg/celestia-node/share/p2p/shrexnd"
)

// TODO: some params are pointers and other are not, Let's fix this.
type Config struct {
// UseShareExchange is a flag toggling the usage of shrex protocols for blocksync.
UseShareExchange bool
// ShrExEDSParams sets shrexeds client and server configuration parameters
ShrExEDSParams *shrexeds.Parameters
// ShrExNDParams sets shrexnd client and server configuration parameters
ShrExNDParams *shrexnd.Parameters
// PeerManagerParams sets peer-manager configuration parameters
PeerManagerParams peers.Parameters
// Discovery sets peer discovery configuration parameters.
Discovery disc.Parameters

LightAvailability light.Parameters `toml:",omitempty"`
Discovery discovery.Parameters
}

func DefaultConfig() Config {
return Config{
UseShareExchange: true,
func DefaultConfig(tp node.Type) Config {
cfg := Config{
Discovery: discovery.DefaultParameters(),
ShrExEDSParams: shrexeds.DefaultParameters(),
ShrExNDParams: shrexnd.DefaultParameters(),
UseShareExchange: true,
PeerManagerParams: peers.DefaultParameters(),
Discovery: disc.DefaultParameters(),
}

if tp == node.Light {
cfg.LightAvailability = light.DefaultParameters()
}

return cfg
}

// Validate performs basic validation of the config.
func (cfg *Config) Validate() error {
func (cfg *Config) Validate(tp node.Type) error {
if tp == node.Light {
if err := cfg.LightAvailability.Validate(); err != nil {
return fmt.Errorf("nodebuilder/share: %w", err)
}
}

if err := cfg.Discovery.Validate(); err != nil {
return fmt.Errorf("nodebuilder/share: %w", err)
}

if err := cfg.ShrExNDParams.Validate(); err != nil {
return err
return fmt.Errorf("nodebuilder/share: %w", err)
}

if err := cfg.ShrExEDSParams.Validate(); err != nil {
return err
return fmt.Errorf("nodebuilder/share: %w", err)
}
return cfg.PeerManagerParams.Validate()

if err := cfg.PeerManagerParams.Validate(); err != nil {
return fmt.Errorf("nodebuilder/share: %w", err)
}

return nil
}
5 changes: 3 additions & 2 deletions nodebuilder/share/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ import (
"github.com/celestiaorg/celestia-node/share/getters"
)

func discovery(cfg Config) func(routing.ContentRouting, host.Host) *disc.Discovery {
func newDiscovery(cfg Config) func(routing.ContentRouting, host.Host) *disc.Discovery {
return func(
r routing.ContentRouting,
h host.Host,
) *disc.Discovery {
return disc.NewDiscovery(
h,
routingdisc.NewRoutingDiscovery(r),
cfg.Discovery,
disc.WithPeersLimit(cfg.Discovery.PeersLimit),
disc.WithAdvertiseInterval(cfg.Discovery.AdvertiseInterval),
)
}
}
Expand Down
9 changes: 7 additions & 2 deletions nodebuilder/share/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option {
// sanitize config values before constructing module
cfgErr := cfg.Validate()
cfgErr := cfg.Validate(tp)

baseComponents := fx.Options(
fx.Supply(*cfg),
Expand All @@ -33,7 +33,7 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
fx.Provide(newModule),
fx.Invoke(func(disc *disc.Discovery) {}),
fx.Provide(fx.Annotate(
discovery(*cfg),
newDiscovery(*cfg),
fx.OnStart(func(ctx context.Context, d *disc.Discovery) error {
return d.Start(ctx)
}),
Expand Down Expand Up @@ -170,6 +170,11 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
return fx.Module(
"share",
baseComponents,
fx.Provide(func() []light.Option {
return []light.Option{
light.WithSampleAmount(cfg.LightAvailability.SampleAmount),
}
}),
shrexGetterComponents,
fx.Invoke(share.EnsureEmptySquareExists),
fx.Provide(getters.NewIPLDGetter),
Expand Down
6 changes: 2 additions & 4 deletions share/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"errors"

"github.com/celestiaorg/celestia-app/pkg/da"
da "github.com/celestiaorg/celestia-app/pkg/da"
)

// ErrNotAvailable is returned whenever DA sampling fails.
Expand All @@ -15,11 +15,9 @@ var ErrNotAvailable = errors.New("share: data not available")
type Root = da.DataAvailabilityHeader

// Availability defines interface for validation of Shares' availability.
//
//go:generate mockgen -destination=availability/mocks/availability.go -package=mocks . Availability
type Availability interface {
// SharesAvailable subjectively validates if Shares committed to the given Root are available on
// the Network by requesting the EDS from the provided peers.
// the Network.
SharesAvailable(context.Context, *Root) error
// ProbabilityOfAvailability calculates the probability of the data square
// being available based on the number of samples collected.
Expand Down
20 changes: 9 additions & 11 deletions share/availability/cache/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ import (
"github.com/celestiaorg/celestia-node/share"
)

var log = logging.Logger("share/cache")

var (
// DefaultWriteBatchSize defines the size of the batched header write.
// Headers are written in batches not to thrash the underlying Datastore with writes.
// TODO(@Wondertan, @renaynay): Those values must be configurable and proper defaults should be set
// for specific node type. (#709)
DefaultWriteBatchSize = 2048
cacheAvailabilityPrefix = datastore.NewKey("sampling_result")

log = logging.Logger("share/cache")
minRoot = da.MinDataAvailabilityHeader()

cacheAvailabilityPrefix = datastore.NewKey("sampling_result")
writeBatchSize = 2048
)

// ShareAvailability wraps a given share.Availability (whether it's light or full)
Expand All @@ -42,9 +37,12 @@ type ShareAvailability struct {

// NewShareAvailability wraps the given share.Availability with an additional datastore
// for sampling result caching.
func NewShareAvailability(avail share.Availability, ds datastore.Batching) *ShareAvailability {
func NewShareAvailability(
avail share.Availability,
ds datastore.Batching,
) *ShareAvailability {
ds = namespace.Wrap(ds, cacheAvailabilityPrefix)
autoDS := autobatch.NewAutoBatching(ds, DefaultWriteBatchSize)
autoDS := autobatch.NewAutoBatching(ds, writeBatchSize)

return &ShareAvailability{
avail: avail,
Expand Down
Loading

0 comments on commit f722beb

Please sign in to comment.