Skip to content

Commit

Permalink
feat(module/das): add WaitCatchUp method to the module (#1383)
Browse files Browse the repository at this point in the history
Also moves the stub test into the das module
  • Loading branch information
Wondertan committed Nov 21, 2022
1 parent 93b4474 commit a93a753
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
8 changes: 7 additions & 1 deletion nodebuilder/das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import (

var _ Module = (*daserStub)(nil)

var errStub = fmt.Errorf("module/das: stubbed: dasing is not available on bridge nodes")

// daserStub is a stub implementation of the DASer that is used on bridge nodes, so that we can
// provide a friendlier error when users try to access the daser over the API.
type daserStub struct{}

func (d daserStub) SamplingStats(context.Context) (das.SamplingStats, error) {
return das.SamplingStats{}, fmt.Errorf("moddas: dasing is not available on bridge nodes")
return das.SamplingStats{}, errStub
}

func (d daserStub) WaitCatchUp(context.Context) error {
return errStub
}

func newDaserStub() Module {
Expand Down
31 changes: 31 additions & 0 deletions nodebuilder/das/module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package das

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.uber.org/fx"
"go.uber.org/fx/fxtest"

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

// TestConstructModule_DASBridgeStub verifies that a bridge node implements a stub daser that
// returns an error and empty das.SamplingStats
func TestConstructModule_DASBridgeStub(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

var mod Module

cfg := DefaultConfig()
app := fxtest.New(t,
ConstructModule(node.Bridge, &cfg),
fx.Populate(&mod)).
RequireStart()
defer app.RequireStop()

_, err := mod.SamplingStats(ctx)
assert.ErrorIs(t, err, errStub)
}
3 changes: 3 additions & 0 deletions nodebuilder/das/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
type Module interface {
// SamplingStats returns the current statistics over the DA sampling process.
SamplingStats(ctx context.Context) (das.SamplingStats, error)
// WaitCatchUp blocks until DASer finishes catching up to the network head.
WaitCatchUp(ctx context.Context) error
}

// API is a wrapper around Module for the RPC.
// TODO(@distractedm1nd): These structs need to be autogenerated.
type API struct {
SamplingStats func(ctx context.Context) (das.SamplingStats, error)
WaitCatchUp func(ctx context.Context) error
}
22 changes: 0 additions & 22 deletions nodebuilder/node_bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-node/core"
"github.com/celestiaorg/celestia-node/das"
coremodule "github.com/celestiaorg/celestia-node/nodebuilder/core"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/nodebuilder/p2p"
Expand All @@ -31,23 +29,3 @@ func TestBridge_WithMockedCoreClient(t *testing.T) {
err = node.Stop(ctx)
require.NoError(t, err)
}

// TestBridge_HasStubDaser verifies that a bridge node implements a stub daser that returns an
// error and empty das.SamplingStats
func TestBridge_HasStubDaser(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

_, client := core.StartTestClient(ctx, t)
nd := TestNode(t, node.Bridge, coremodule.WithClient(client))
require.NotNil(t, nd)
err := nd.Start(ctx)
require.NoError(t, err)

stats, err := nd.DASer.SamplingStats(ctx)
assert.EqualError(t, err, "moddas: dasing is not available on bridge nodes")
assert.Equal(t, stats, das.SamplingStats{})

err = nd.Stop(ctx)
require.NoError(t, err)
}

0 comments on commit a93a753

Please sign in to comment.