Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/crypto-0.…
Browse files Browse the repository at this point in the history
…13.0
  • Loading branch information
distractedm1nd committed Sep 12, 2023
2 parents 3a019ef + 8ca777e commit 66d6a42
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/golang:1.21-alpine3.18 as builder
FROM --platform=$BUILDPLATFORM docker.io/golang:1.21-alpine3.18 as builder

# hadolint ignore=DL3018
RUN apk update && apk add --no-cache \
Expand All @@ -15,7 +15,7 @@ COPY . .

RUN make build && make cel-key

FROM docker.io/alpine:3.18.3
FROM --platform=$BUILDPLATFORM docker.io/alpine:3.18.3

# Read here why UID 10001: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000
ARG UID=10001
Expand All @@ -30,6 +30,8 @@ ENV P2P_NETWORK mocha
# hadolint ignore=DL3018
RUN apk update && apk add --no-cache \
bash \
curl \
jq \
# Creates a user with $UID and $GID=$UID
&& adduser ${USER_NAME} \
-D \
Expand Down
2 changes: 1 addition & 1 deletion das/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func DefaultParameters() Parameters {
ConcurrencyLimit: concurrencyLimit,
BackgroundStoreInterval: 10 * time.Minute,
SampleFrom: 1,
// SampleTimeout = block time * max amount of catchup workers
// SampleTimeout = approximate block time (with a bit of wiggle room) * max amount of catchup workers
SampleTimeout: 15 * time.Second * time.Duration(concurrencyLimit),
}
}
Expand Down
25 changes: 17 additions & 8 deletions nodebuilder/header/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package header
import (
"context"

"github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
Expand Down Expand Up @@ -63,7 +64,7 @@ func newP2PExchange[H libhead.Header[H]](
func newSyncer[H libhead.Header[H]](
ex libhead.Exchange[H],
fservice libfraud.Service[H],
store InitStore[H],
store libhead.Store[H],
sub libhead.Subscriber[H],
cfg Config,
) (*sync.Syncer[H], *modfraud.ServiceBreaker[*sync.Syncer[H], H], error) {
Expand All @@ -82,26 +83,34 @@ func newSyncer[H libhead.Header[H]](
}, nil
}

// InitStore is a type representing initialized header store.
// NOTE: It is needed to ensure that Store is always initialized before Syncer is started.
type InitStore[H libhead.Header[H]] libhead.Store[H]

// newInitStore constructs an initialized store
func newInitStore[H libhead.Header[H]](
lc fx.Lifecycle,
cfg Config,
net modp2p.Network,
s libhead.Store[H],
ds datastore.Batching,
ex libhead.Exchange[H],
) (InitStore[H], error) {
) (libhead.Store[H], error) {
s, err := store.NewStore[H](ds, store.WithParams(cfg.Store))
if err != nil {
return nil, err
}

trustedHash, err := cfg.trustedHash(net)
if err != nil {
return nil, err
}

lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return store.Init(ctx, s, ex, trustedHash)
err = store.Init[H](ctx, s, ex, trustedHash)
if err != nil {
return err
}
return s.Start(ctx)
},
OnStop: func(ctx context.Context) error {
return s.Stop(ctx)
},
})

Expand Down
14 changes: 0 additions & 14 deletions nodebuilder/header/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/go-header/p2p"
"github.com/celestiaorg/go-header/store"
"github.com/celestiaorg/go-header/sync"

"github.com/celestiaorg/celestia-node/header"
Expand All @@ -31,19 +30,6 @@ func ConstructModule[H libhead.Header[H]](tp node.Type, cfg *Config) fx.Option {
fx.Supply(*cfg),
fx.Error(cfgErr),
fx.Provide(newHeaderService),
fx.Provide(fx.Annotate(
func(ds datastore.Batching) (libhead.Store[H], error) {
return store.NewStore[H](ds, store.WithParams(cfg.Store))
},
fx.OnStart(func(ctx context.Context, str libhead.Store[H]) error {
s := str.(*store.Store[H])
return s.Start(ctx)
}),
fx.OnStop(func(ctx context.Context, str libhead.Store[H]) error {
s := str.(*store.Store[H])
return s.Stop(ctx)
}),
)),
fx.Provide(newInitStore[H]),
fx.Provide(func(subscriber *p2p.Subscriber[H]) libhead.Subscriber[H] {
return subscriber
Expand Down
9 changes: 7 additions & 2 deletions nodebuilder/header/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ func TestConstructModule_StoreParams(t *testing.T) {

app := fxtest.New(t,
fx.Supply(modp2p.Private),
fx.Provide(func() datastore.Batching {
return datastore.NewMapDatastore()
fx.Supply(modp2p.Bootstrappers{}),
fx.Provide(context.Background),
fx.Provide(libp2p.New),
fx.Provide(conngater.NewBasicConnectionGater),
fx.Provide(func() (datastore.Batching, datastore.Datastore) {
ds := datastore.NewMapDatastore()
return ds, ds
}),
ConstructModule[*header.ExtendedHeader](node.Light, &cfg),
fx.Invoke(
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/p2p/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
Private Network = "private"
// BlockTime is a network block time.
// TODO @renaynay @Wondertan (#790)
BlockTime = time.Second * 15
BlockTime = time.Second * 10
)

// Network is a type definition for DA network run by Celestia Node.
Expand Down
4 changes: 2 additions & 2 deletions nodebuilder/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"go.uber.org/fx"

apptypes "github.com/celestiaorg/celestia-app/x/blob/types"
libhead "github.com/celestiaorg/go-header"

"github.com/celestiaorg/celestia-node/core"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/libs/fxutil"
modhead "github.com/celestiaorg/celestia-node/nodebuilder/header"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/nodebuilder/p2p"
"github.com/celestiaorg/celestia-node/nodebuilder/state"
Expand Down Expand Up @@ -48,7 +48,7 @@ func TestNodeWithConfig(t *testing.T, tp node.Type, cfg *Config, opts ...fx.Opti
// temp dir for the eds store FIXME: Should be in mem
fx.Replace(node.StorePath(t.TempDir())),
// avoid requesting trustedPeer during initialization
fxutil.ReplaceAs(headertest.NewStore(t), new(modhead.InitStore[*header.ExtendedHeader])),
fxutil.ReplaceAs(headertest.NewStore(t), new(libhead.Store[*header.ExtendedHeader])),
)

// in fact, we don't need core.Client in tests, but Bridge requires is a valid one
Expand Down

0 comments on commit 66d6a42

Please sign in to comment.