Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: share.Getter and getters.IPLDGetter #1518

Merged
merged 17 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (h *Handler) getShares(ctx context.Context, height uint64, nID namespace.ID
}
// perform request
shares, err := h.share.GetSharesByNamespace(ctx, header.DAH, nID)
return shares, header.Height, err
return shares.Flatten(), header.Height, err
}

func dataFromShares(shares []share.Share) ([][]byte, error) {
Expand Down
4 changes: 4 additions & 0 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ func TestAllReturnValuesAreMarshalable(t *testing.T) {
}

func implementsMarshaler(t *testing.T, typ reflect.Type) {
// TODO(@distractedm1nd): Write marshaller for ExtendedDataSquare
if typ.Name() == "ExtendedDataSquare" {
return
}
// the passed type may already implement json.Marshaler and we don't need to go deeper
if typ.Implements(reflect.TypeOf(new(json.Marshaler)).Elem()) {
return
Expand Down
7 changes: 4 additions & 3 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/celestiaorg/celestia-node/fraud"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/getters"
)

var timeout = time.Second * 15
Expand All @@ -32,7 +33,7 @@ var timeout = time.Second * 15
func TestDASerLifecycle(t *testing.T) {
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
bServ := mdutils.Bserv()
avail := light.TestAvailability(bServ)
avail := light.TestAvailability(getters.NewIPLDGetter(bServ))
// 15 headers from the past and 15 future headers
mockGet, sub, mockService := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down Expand Up @@ -72,7 +73,7 @@ func TestDASerLifecycle(t *testing.T) {
func TestDASer_Restart(t *testing.T) {
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
bServ := mdutils.Bserv()
avail := light.TestAvailability(bServ)
avail := light.TestAvailability(getters.NewIPLDGetter(bServ))
// 15 headers from the past and 15 future headers
mockGet, sub, mockService := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down Expand Up @@ -147,7 +148,7 @@ func TestDASer_stopsAfter_BEFP(t *testing.T) {
ps, err := pubsub.NewGossipSub(ctx, net.Hosts()[0],
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign))
require.NoError(t, err)
avail := full.TestAvailability(bServ)
avail := full.TestAvailability(getters.NewIPLDGetter(bServ))
// 15 headers from the past and 15 future headers
mockGet, sub, _ := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down
8 changes: 5 additions & 3 deletions docs/adr/adr-009-public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ SyncHead(ctx context.Context) (*header.ExtendedHeader, error)
// GetShare returns the Share from the given data Root at the given row/col
// coordinates.
GetShare(ctx context.Context, root *Root, row, col int) (Share, error)
// GetSharesByNamespace returns all shares of the given nID from the given data
// Root.
// GetEDS gets the full EDS identified by the given root.
GetEDS(ctx context.Context, root *share.Root) (*rsmt2d.ExtendedDataSquare, error)
// GetSharesByNamespace gets all shares from an EDS within the given namespace.
// Shares are returned in a row-by-row order if the namespace spans multiple rows.
GetSharesByNamespace(
ctx context.Context,
root *Root,
nID namespace.ID,
) ([]Share, error)
) (share.NamespacedShares, error)
// SharesAvailable subjectively validates if Shares committed to the given data
// Root are available on the network.
SharesAvailable(ctx context.Context, root *Root) error
Expand Down
17 changes: 15 additions & 2 deletions nodebuilder/das/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions nodebuilder/fraud/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions nodebuilder/header/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions nodebuilder/share/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"

"github.com/filecoin-project/dagstore"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/routing"
Expand All @@ -17,7 +16,6 @@ import (
"github.com/celestiaorg/celestia-node/share/availability/cache"
disc "github.com/celestiaorg/celestia-node/share/availability/discovery"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/service"
)

func discovery(cfg Config) func(routing.ContentRouting, host.Host) *disc.Discovery {
Expand All @@ -44,17 +42,8 @@ func cacheAvailability[A share.Availability](lc fx.Lifecycle, ds datastore.Batch
return ca
}

func newModule(lc fx.Lifecycle, bServ blockservice.BlockService, avail share.Availability) Module {
serv := service.NewShareService(bServ, avail)
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return serv.Start(ctx)
},
OnStop: func(ctx context.Context) error {
return serv.Stop(ctx)
},
})
return &module{serv}
func newModule(getter share.Getter, avail share.Availability) Module {
return &module{getter, avail}
}

// ensureEmptyCARExists adds an empty EDS to the provided EDS store.
Expand Down
37 changes: 19 additions & 18 deletions nodebuilder/share/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions nodebuilder/share/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
"github.com/celestiaorg/celestia-node/share/availability/full"
"github.com/celestiaorg/celestia-node/share/availability/light"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/getters"
"github.com/celestiaorg/celestia-node/share/p2p/shrexeds"

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

func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option {
Expand All @@ -27,6 +30,7 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
fx.Provide(discovery(*cfg)),
fx.Provide(newModule),
fx.Invoke(share.EnsureEmptySquareExists),
fxutil.ProvideAs(getters.NewIPLDGetter, new(share.Getter)),
)

switch tp {
Expand Down
31 changes: 17 additions & 14 deletions nodebuilder/share/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"

"github.com/celestiaorg/nmt/namespace"
"github.com/celestiaorg/rsmt2d"

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

var _ Module = (*API)(nil)
Expand Down Expand Up @@ -34,11 +34,13 @@ type Module interface {
// ProbabilityOfAvailability calculates the probability of the data square
// being available based on the number of samples collected.
ProbabilityOfAvailability(context.Context) float64
// GetShare gets a Share by coordinates in EDS.
GetShare(ctx context.Context, dah *share.Root, row, col int) (share.Share, error)
GetShares(ctx context.Context, root *share.Root) ([][]share.Share, error)
// GetSharesByNamespace iterates over a square's row roots and accumulates the found shares in the
// given namespace.ID.
GetSharesByNamespace(ctx context.Context, root *share.Root, namespace namespace.ID) ([]share.Share, error)
// GetEDS gets the full EDS identified by the given root.
GetEDS(ctx context.Context, root *share.Root) (*rsmt2d.ExtendedDataSquare, error)
// GetSharesByNamespace gets all shares from an EDS within the given namespace.
// Shares are returned in a row-by-row order if the namespace spans multiple rows.
GetSharesByNamespace(ctx context.Context, root *share.Root, namespace namespace.ID) (share.NamespacedShares, error)
}

// API is a wrapper around Module for the RPC.
Expand All @@ -52,15 +54,15 @@ type API struct {
dah *share.Root,
row, col int,
) (share.Share, error) `perm:"public"`
GetShares func(
GetEDS func(
ctx context.Context,
root *share.Root,
) ([][]share.Share, error) `perm:"public"`
) (*rsmt2d.ExtendedDataSquare, error) `perm:"public"`
GetSharesByNamespace func(
ctx context.Context,
root *share.Root,
namespace namespace.ID,
) ([]share.Share, error) `perm:"public"`
) (share.NamespacedShares, error) `perm:"public"`
}
}

Expand All @@ -76,22 +78,23 @@ func (api *API) GetShare(ctx context.Context, dah *share.Root, row, col int) (sh
return api.Internal.GetShare(ctx, dah, row, col)
}

func (api *API) GetShares(ctx context.Context, root *share.Root) ([][]share.Share, error) {
return api.Internal.GetShares(ctx, root)
func (api *API) GetEDS(ctx context.Context, root *share.Root) (*rsmt2d.ExtendedDataSquare, error) {
return api.Internal.GetEDS(ctx, root)
}

func (api *API) GetSharesByNamespace(
ctx context.Context,
root *share.Root,
namespace namespace.ID,
) ([]share.Share, error) {
) (share.NamespacedShares, error) {
return api.Internal.GetSharesByNamespace(ctx, root, namespace)
}

type module struct {
*service.ShareService
share.Getter
share.Availability
}

func (m *module) SharesAvailable(ctx context.Context, root *share.Root) error {
return m.ShareService.SharesAvailable(ctx, root)
func (m module) SharesAvailable(ctx context.Context, root *share.Root) error {
return m.Availability.SharesAvailable(ctx, root)
}
3 changes: 1 addition & 2 deletions nodebuilder/state/mocks/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading