Documentation
¶
Overview ¶
Package share contains logic related to the retrieval and random sampling of shares of block data.
Though this package contains several useful methods for getting specific shares and/or sampling them at random, a particularly useful method is GetSharesByNamespace which retrieves all shares of block data of the given namespace.ID from the block associated with the given DataAvailabilityHeader (DAH, but referred to as Root within this package).
This package also contains both implementations of the Availability interface: lightAvailability which samples for 16 shares of block data (enough to verify the block's availability on the network) and fullAvailability which samples for as many shares as necessary to fully reconstruct the block data.
TODO(@Wondertan): Instead of doing sampling over the coordinates do a random walk over NMT trees.
Index ¶
- Constants
- Variables
- func EnsureEmptySquareExists(ctx context.Context, bServ blockservice.BlockService) error
- func NewTestDAGNet(ctx context.Context, t *testing.T) *dagNet
- func RandFullLocalServiceWithSquare(t *testing.T, n int) (*Service, *Root)
- func RandFullServiceWithSquare(t *testing.T, n int) (*Service, *Root)
- func RandLightLocalServiceWithSquare(t *testing.T, n int) (*Service, *Root)
- func RandLightServiceWithSquare(t *testing.T, n int) (*Service, *Root)
- type Availability
- type CacheAvailability
- type Root
- type Sample
- type Service
- func (s *Service) GetShare(ctx context.Context, dah *Root, row, col int) (Share, error)
- func (s *Service) GetShares(ctx context.Context, root *Root) ([][]Share, error)
- func (s *Service) GetSharesByNamespace(ctx context.Context, root *Root, nID namespace.ID) ([]Share, error)
- func (s *Service) Start(context.Context) error
- func (s *Service) Stop(context.Context) error
- type Share
Constants ¶
const AvailabilityTimeout = 20 * time.Minute
AvailabilityTimeout specifies timeout for DA validation during which data have to be found on the network, otherwise ErrNotAvailable is fired. TODO: https://github.com/celestiaorg/celestia-node/issues/10
Variables ¶
var DefaultSampleAmount = 16
DefaultSampleAmount sets the default amount of samples to be sampled from the network by lightAvailability.
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 )
var ErrNotAvailable = errors.New("da: data not available")
ErrNotAvailable is returned whenever DA sampling fails.
var GetData = ipld.ShareData
GetData extracts data out of a Share.
var GetID = ipld.ShareID
GetID extracts namespace ID out of a Share.
Functions ¶
func EnsureEmptySquareExists ¶ added in v0.3.0
func EnsureEmptySquareExists(ctx context.Context, bServ blockservice.BlockService) error
EnsureEmptySquareExists checks if the given DAG contains an empty block data square. If it does not, it stores an empty block. This optimization exists to prevent redundant storing of empty block data so that it is only stored once and returned upon request for a block with an empty data square. Ref: header/header.go#L56
func NewTestDAGNet ¶ added in v0.3.0
NewTestDAGNet creates a new testing swarm utility to spawn different nodes and test how they interact and/or exchange data.
func RandFullLocalServiceWithSquare ¶ added in v0.3.0
RandFullLocalServiceWithSquare is the same as RandFullServiceWithSquare, except the Availability is wrapped with CacheAvailability.
func RandFullServiceWithSquare ¶ added in v0.2.0
RandFullServiceWithSquare provides a share.Service filled with 'n' NMT trees of 'n' random shares, essentially storing a whole square.
func RandLightLocalServiceWithSquare ¶ added in v0.3.0
RandLightLocalServiceWithSquare is the same as RandLightServiceWithSquare, except the Availability is wrapped with CacheAvailability.
Types ¶
type Availability ¶
Availability defines interface for validation of Shares' availability.
func NewBrokenAvailability ¶
func NewBrokenAvailability() Availability
func NewFullAvailability ¶ added in v0.2.0
func NewFullAvailability(bServ blockservice.BlockService) Availability
NewFullAvailability creates a new full Availability.
func NewLightAvailability ¶
func NewLightAvailability(bserv blockservice.BlockService) Availability
NewLightAvailability creates a new light Availability.
type CacheAvailability ¶ added in v0.3.0
type CacheAvailability struct {
// contains filtered or unexported fields
}
CacheAvailability wraps a given Availability (whether it's light or full) and stores the results of a successful sampling routine over a given Root's hash to disk.
func NewCacheAvailability ¶ added in v0.3.0
func NewCacheAvailability(avail Availability, ds datastore.Batching) *CacheAvailability
NewCacheAvailability wraps the given Availability with an additional datastore for sampling result caching.
func (*CacheAvailability) Close ¶ added in v0.3.0
func (ca *CacheAvailability) Close(ctx context.Context) error
Close flushes all queued writes to disk.
func (*CacheAvailability) SharesAvailable ¶ added in v0.3.0
func (ca *CacheAvailability) SharesAvailable(ctx context.Context, root *Root) error
SharesAvailable will store, upon success, the hash of the given Root to disk.
type Root ¶
type Root = da.DataAvailabilityHeader
Root represents root commitment to multiple Shares. In practice, it is a commitment to all the Data in a square.
func FillBS ¶ added in v0.3.0
func FillBS(t *testing.T, bServ blockservice.BlockService, shares []Share) *Root
FillBS fills the given BlockService with the given shares.
func RandFillBS ¶ added in v0.3.0
func RandFillBS(t *testing.T, n int, bServ blockservice.BlockService) *Root
RandFillBS fills the given BlockService with a random block of a given size.
type Service ¶
type Service struct {
Availability
// contains filtered or unexported fields
}
Service provides access to any data square or block share on the network.
All Get methods provided on Service follow the following flow:
- Check local storage for the requested Share.
- If exists
- Load from disk
- Return
- If not
- Find provider on the network
- Fetch the Share from the provider
- Store the Share
- Return
TODO(@Wondertan): Simple thread safety for Start and Stop would not hurt.
func NewService ¶
func NewService(bServ blockservice.BlockService, avail Availability) *Service
NewService creates new basic share.Service.
func RandLightService ¶ added in v0.3.0
func RandLightService() (*Service, blockservice.BlockService)
RandLightService provides an unfilled share.Service with corresponding blockservice.BlockService than can be filled by the test.