eds

package
v0.17.0-rc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyAccessor = &Rsmt2D{ExtendedDataSquare: share.EmptyEDS()}

EmptyAccessor is an accessor of an empty EDS block.

View Source
var ErrOutOfBounds = errors.New("index is out of bounds")

ErrOutOfBounds is returned whenever an index is out of bounds.

View Source
var RetrieveQuadrantTimeout = blockTime / numQuadrants * 2

RetrieveQuadrantTimeout defines how much time Retriever waits before starting to retrieve another quadrant.

NOTE: - The whole data square must be retrieved in less than block time. - We have 4 quadrants from two sources(rows, cols) which equals to 8 in total.

Functions

func BenchGetHalfAxisFromAccessor

func BenchGetHalfAxisFromAccessor(
	ctx context.Context,
	b *testing.B,
	createAccessor createAccessor,
	minOdsSize, maxOdsSize int,
)

func BenchGetSampleFromAccessor

func BenchGetSampleFromAccessor(
	ctx context.Context,
	b *testing.B,
	createAccessor createAccessor,
	minOdsSize, maxOdsSize int,
)

func NamespaceData

func NamespaceData(
	ctx context.Context,
	eds Accessor,
	namespace share.Namespace,
) (shwap.NamespaceData, error)

NamespaceData extracts shares for a specific namespace from an EDS, considering each row independently. It uses root to determine which rows to extract data from, avoiding the need to recalculate the row roots for each row.

func ProveShares added in v0.15.0

func ProveShares(eds *rsmt2d.ExtendedDataSquare, start, end int) (*types.ShareProof, error)

ProveShares generates a share proof for a share range. The share range, defined by start and end, is end-exclusive.

func ReadShares

func ReadShares(r io.Reader, shareSize, odsSize int) ([]share.Share, error)

ReadShares reads shares from the provided io.Reader until EOF. If EOF is reached, the remaining shares are populated as tail padding shares. Provided reader must contain shares in row-major order.

func TestStreamer

func TestStreamer(
	ctx context.Context,
	t *testing.T,
	create createAccessorStreamer,
	odsSize int,
)

func TestSuiteAccessor

func TestSuiteAccessor(
	ctx context.Context,
	t *testing.T,
	createAccessor createAccessor,
	maxSize int,
)

TestSuiteAccessor runs a suite of tests for the given Accessor implementation.

Types

type Accessor

type Accessor interface {
	// Size returns square size of the Accessor.
	Size(ctx context.Context) int
	// DataHash returns data hash of the Accessor.
	DataHash(ctx context.Context) (share.DataHash, error)
	// AxisRoots returns share.AxisRoots (DataAvailabilityHeader) of the Accessor.
	AxisRoots(ctx context.Context) (*share.AxisRoots, error)
	// Sample returns share and corresponding proof for row and column indices. Implementation can
	// choose which axis to use for proof. Chosen axis for proof should be indicated in the returned
	// Sample.
	Sample(ctx context.Context, rowIdx, colIdx int) (shwap.Sample, error)
	// AxisHalf returns half of shares axis of the given type and index. Side is determined by
	// implementation. Implementations should indicate the side in the returned AxisHalf.
	AxisHalf(ctx context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error)
	// RowNamespaceData returns data for the given namespace and row index.
	RowNamespaceData(ctx context.Context, namespace share.Namespace, rowIdx int) (shwap.RowNamespaceData, error)
	// Shares returns data (ODS) shares extracted from the Accessor.
	Shares(ctx context.Context) ([]share.Share, error)
}

Accessor is an interface for accessing extended data square data.

func WithValidation

func WithValidation(f Accessor) Accessor

type AccessorStreamer

type AccessorStreamer interface {
	Accessor
	Streamer
}

AccessorStreamer is an interface that groups Accessor and Streamer interfaces.

func AccessorAndStreamer

func AccessorAndStreamer(a Accessor, s Streamer) AccessorStreamer

func WithClosedOnce

func WithClosedOnce(f AccessorStreamer) AccessorStreamer

func WithProofsCache

func WithProofsCache(ac AccessorStreamer) AccessorStreamer

WithProofsCache creates a new eds accessor with caching of proofs for rows and columns. It is used to speed up the process of building proofs for rows and columns, reducing the number of reads from the underlying accessor.

type AxisHalf

type AxisHalf struct {
	Shares []share.Share
	// IsParity indicates whether the half is parity or data.
	IsParity bool
}

AxisHalf represents a half of data for a row or column in the EDS.

func (AxisHalf) Extended

func (a AxisHalf) Extended() ([]share.Share, error)

Extended returns full axis shares from half axis shares.

func (AxisHalf) ToRow

func (a AxisHalf) ToRow() shwap.Row

ToRow converts the AxisHalf to a shwap.Row.

type Retriever

type Retriever struct {
	// contains filtered or unexported fields
}

Retriever retrieves rsmt2d.ExtendedDataSquares from the IPLD network. Instead of requesting data 'share by share' it requests data by quadrants minimizing bandwidth usage in the happy cases.

 ---- ----
| 0  | 1  |
 ---- ----
| 2  | 3  |
 ---- ----

Retriever randomly picks one of the data square quadrants and tries to request them one by one until it is able to reconstruct the whole square.

func NewRetriever

func NewRetriever(bServ blockservice.BlockService) *Retriever

NewRetriever creates a new instance of the Retriever over IPLD BlockService and rmst2d.Codec

func (*Retriever) Retrieve

func (r *Retriever) Retrieve(ctx context.Context, roots *share.AxisRoots) (*rsmt2d.ExtendedDataSquare, error)

Retrieve retrieves all the data committed to DataAvailabilityHeader.

If not available locally, it aims to request from the network only one quadrant (1/4) of the data square and reconstructs the other three quadrants (3/4). If the requested quadrant is not available within RetrieveQuadrantTimeout, it starts requesting another quadrant until either the data is reconstructed, context is canceled or ErrByzantine is generated.

type Rsmt2D

type Rsmt2D struct {
	*rsmt2d.ExtendedDataSquare
}

Rsmt2D is a rsmt2d based in-memory implementation of Accessor.

func ReadAccessor

func ReadAccessor(ctx context.Context, reader io.Reader, root *share.AxisRoots) (*Rsmt2D, error)

ReadAccessor reads up EDS out of the io.Reader until io.EOF and provides.

func Rsmt2DFromShares

func Rsmt2DFromShares(shares []share.Share, odsSize int) (*Rsmt2D, error)

Rsmt2DFromShares constructs an Extended Data Square from shares.

func (*Rsmt2D) AxisHalf

func (eds *Rsmt2D) AxisHalf(_ context.Context, axisType rsmt2d.Axis, axisIdx int) (AxisHalf, error)

AxisHalf returns Shares for the first half of the axis of the given type and index.

func (*Rsmt2D) AxisRoots

func (eds *Rsmt2D) AxisRoots(context.Context) (*share.AxisRoots, error)

AxisRoots returns AxisRoots of the Accessor.

func (*Rsmt2D) Close

func (eds *Rsmt2D) Close() error

func (*Rsmt2D) DataHash

func (eds *Rsmt2D) DataHash(context.Context) (share.DataHash, error)

DataHash returns data hash of the Accessor.

func (*Rsmt2D) HalfRow

func (eds *Rsmt2D) HalfRow(idx int, side shwap.RowSide) shwap.Row

HalfRow constructs a new shwap.Row from an Extended Data Square based on the specified index and side.

func (*Rsmt2D) Reader

func (eds *Rsmt2D) Reader() (io.Reader, error)

Reader returns binary reader for the file.

func (*Rsmt2D) RowNamespaceData

func (eds *Rsmt2D) RowNamespaceData(
	_ context.Context,
	namespace share.Namespace,
	rowIdx int,
) (shwap.RowNamespaceData, error)

RowNamespaceData returns data for the given namespace and row index.

func (*Rsmt2D) Sample

func (eds *Rsmt2D) Sample(
	_ context.Context,
	rowIdx, colIdx int,
) (shwap.Sample, error)

Sample returns share and corresponding proof for row and column indices.

func (*Rsmt2D) SampleForProofAxis

func (eds *Rsmt2D) SampleForProofAxis(
	rowIdx, colIdx int,
	proofType rsmt2d.Axis,
) (shwap.Sample, error)

SampleForProofAxis samples a share from an Extended Data Square based on the provided row and column indices and proof axis. It returns a sample with the share and proof.

func (*Rsmt2D) Shares

func (eds *Rsmt2D) Shares(_ context.Context) ([]share.Share, error)

Shares returns data (ODS) shares extracted from the EDS. It returns new copy of the shares each time.

func (*Rsmt2D) Size

func (eds *Rsmt2D) Size(context.Context) int

Size returns the size of the Extended Data Square.

type ShareReader

type ShareReader struct {
	// contains filtered or unexported fields
}

ShareReader implement io.Reader over general function that gets shares by their respective Row and Col coordinates. It enables share streaming over arbitrary storages.

func NewShareReader

func NewShareReader(odsSize int, getShare func(rowIdx, colIdx int) ([]byte, error)) *ShareReader

NewShareReader constructs a new ShareGetter from underlying ODS size and general share getting function.

func (*ShareReader) Read

func (r *ShareReader) Read(p []byte) (int, error)

type Streamer

type Streamer interface {
	// Reader returns binary reader for the shares. It should read the shares from the
	// ODS part of the square row by row.
	Reader() (io.Reader, error)
	io.Closer
}

Directories

Path Synopsis
pb

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL