diff --git a/Dockerfile b/Dockerfile index 1f1705c2f3..bebd61a644 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 @@ -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 \ diff --git a/das/options.go b/das/options.go index 665fc5a7d6..e38e488c04 100644 --- a/das/options.go +++ b/das/options.go @@ -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), } } diff --git a/nodebuilder/header/constructors.go b/nodebuilder/header/constructors.go index 984d551434..be4bcbd427 100644 --- a/nodebuilder/header/constructors.go +++ b/nodebuilder/header/constructors.go @@ -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" @@ -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) { @@ -82,18 +83,19 @@ 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 @@ -101,7 +103,14 @@ func newInitStore[H libhead.Header[H]]( 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) }, }) diff --git a/nodebuilder/header/module.go b/nodebuilder/header/module.go index eaee6b047f..557cbcfab7 100644 --- a/nodebuilder/header/module.go +++ b/nodebuilder/header/module.go @@ -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" @@ -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 diff --git a/nodebuilder/header/module_test.go b/nodebuilder/header/module_test.go index c31cf546d8..23ca41050f 100644 --- a/nodebuilder/header/module_test.go +++ b/nodebuilder/header/module_test.go @@ -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( diff --git a/nodebuilder/p2p/network.go b/nodebuilder/p2p/network.go index b1f9be8401..a6197aa321 100644 --- a/nodebuilder/p2p/network.go +++ b/nodebuilder/p2p/network.go @@ -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. diff --git a/nodebuilder/testing.go b/nodebuilder/testing.go index 36f2c2f47f..8d49772aef 100644 --- a/nodebuilder/testing.go +++ b/nodebuilder/testing.go @@ -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" @@ -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