shwap

package
v0.20.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const EDSName = "eds_v0"

EDSName is the name identifier for the Extended Data Square.

View Source
const EdsIDSize = 8

EdsIDSize defines the byte size of the EdsID.

View Source
const NamespaceDataIDSize = EdsIDSize + libshare.NamespaceSize

NamespaceDataIDSize defines the total size of a NamespaceDataID in bytes, combining the size of a EdsID and the size of a Namespace.

View Source
const NamespaceDataName = "nd_v0"

NamespaceDataName is the name identifier for the namespace data container.

View Source
const RowIDSize = EdsIDSize + 2

RowIDSize defines the size in bytes of RowID, consisting of the size of EdsID and 2 bytes for RowIndex.

View Source
const RowName = "row_v0"

RowName is the name identifier for the row container.

View Source
const RowNamespaceDataIDSize = RowIDSize + libshare.NamespaceSize

RowNamespaceDataIDSize defines the total size of a RowNamespaceDataID in bytes, combining the size of a RowID and the size of a Namespace.

View Source
const RowNamespaceDataName = "rnd_v0"

RowNamespaceDataName is the name identifier for the row namespace data container.

View Source
const SampleIDSize = RowIDSize + 2

SampleIDSize defines the size of the SampleID in bytes, combining RowID size and 2 additional bytes for the ShareIndex.

View Source
const SampleName = "sample_v0"

SampleName is the name identifier for the sample container.

Variables

View Source
var (
	// ErrOperationNotSupported is used to indicate that the operation is not supported by the
	// implementation of the getter interface.
	ErrOperationNotSupported = errors.New("operation is not supported")
	// ErrNotFound is used to indicate that requested data could not be found.
	ErrNotFound = errors.New("data not found")
	// ErrInvalidID is used to indicate that an ID failed validation.
	ErrInvalidID = errors.New("invalid shwap ID")
	// ErrOutOfBounds is used to indicate that a passed row or column index is out of bounds of the
	// square size.
	ErrOutOfBounds = fmt.Errorf("index out of bounds: %w", ErrInvalidID)
	// ErrNoSampleIndicies is used to indicate that no indicies where given to process.
	ErrNoSampleIndicies = errors.New("no sample indicies to fetch")
)
View Source
var ErrFailedVerification = errors.New("failed to verify inclusion")

ErrFailedVerification is returned when inclusion proof verification fails. It is returned when the data and the proof do not match trusted data root.

View Source
var ErrNamespaceOutsideRange = errors.New("target namespace is outside of namespace range for the given root")

ErrNamespaceOutsideRange is returned by RowNamespaceDataFromShares when the target namespace is outside of the namespace range for the given row. In this case, the implementation cannot return the non-inclusion proof and will return ErrNamespaceOutsideRange.

Functions

func SampleCoordsAs1DIndex added in v0.20.4

func SampleCoordsAs1DIndex(idx SampleCoords, edsSize int) (int, error)

func ShareFromProto

func ShareFromProto(s *pb.Share) (libshare.Share, error)

ShareFromProto converts a protobuf Share object to the application's internal share representation. It returns nil if the input protobuf Share is nil, ensuring safe handling of nil values.

func SharesFromProto

func SharesFromProto(shrs []*pb.Share) ([]libshare.Share, error)

SharesFromProto converts a slice of protobuf Share objects to the application's internal slice of Shares. It ensures that each Share is correctly transformed using the ShareFromProto function.

func SharesToProto

func SharesToProto(shrs []libshare.Share) []*pb.Share

SharesToProto converts a slice of Shares from the application's internal representation to a slice of protobuf Share objects. This function allocates memory for the protobuf objects and copies data from the input slice.

Types

type EdsID

type EdsID struct {
	Height uint64 // Height specifies the block height.
}

EdsID represents a unique identifier for a row, using the height of the block to identify the data square in the chain.

func EdsIDFromBinary

func EdsIDFromBinary(data []byte) (EdsID, error)

EdsIDFromBinary decodes a byte slice into an EdsID, validating the length of the data. It returns an error if the data slice does not match the expected size of an EdsID.

func NewEdsID

func NewEdsID(height uint64) (EdsID, error)

NewEdsID creates a new EdsID using the given height.

func (*EdsID) Equals

func (eid *EdsID) Equals(other EdsID) bool

Equals checks equality of EdsIDs.

func (EdsID) MarshalBinary

func (eid EdsID) MarshalBinary() ([]byte, error)

MarshalBinary encodes an EdsID into its binary form, primarily for storage or network transmission.

func (*EdsID) ReadFrom

func (eid *EdsID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of EdsID from the provided reader.

func (EdsID) Validate

func (eid EdsID) Validate() error

Validate checks the integrity of an EdsID's fields against the provided Root. It ensures that the EdsID is not constructed with a zero Height and that the root is not nil.

func (EdsID) WriteTo

func (eid EdsID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of EdsID to the provided writer.

type Getter

type Getter interface {
	// GetSamples gets samples by their indices.
	// Returns Sample slice with requested number of samples in the requested order.
	// May return partial response with some samples being empty if they weren't found.
	GetSamples(ctx context.Context, header *header.ExtendedHeader, indices []SampleCoords) ([]Sample, error)

	// GetEDS gets the full EDS identified by the given extended header.
	GetEDS(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error)

	// GetNamespaceData 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.
	// Inclusion of returned data could be verified using Verify method on NamespacedShares.
	// If no shares are found for target namespace non-inclusion could be also verified by calling
	// Verify method.
	GetNamespaceData(context.Context, *header.ExtendedHeader, libshare.Namespace) (NamespaceData, error)
}

Getter interface provides a set of accessors for shares by the Root. Automatically verifies integrity of shares(exceptions possible depending on the implementation).

type NamespaceData

type NamespaceData []RowNamespaceData

NamespaceData stores collections of RowNamespaceData, each representing shares and their proofs within a namespace. NOTE: NamespaceData does not have it protobuf Container representation and its only *streamed* as RowNamespaceData. The protobuf might be added as need comes.

func (NamespaceData) Flatten

func (nd NamespaceData) Flatten() []libshare.Share

Flatten combines all shares from all rows within the namespace into a single slice.

func (*NamespaceData) ReadFrom

func (nd *NamespaceData) ReadFrom(reader io.Reader) (int64, error)

ReadFrom reads NamespaceData from the provided reader implementing io.ReaderFrom. It reads series of length-delimited RowNamespaceData until EOF draining the stream.

func (NamespaceData) Verify

func (nd NamespaceData) Verify(root *share.AxisRoots, namespace libshare.Namespace) error

Verify checks the integrity of the NamespaceData against a provided root and namespace.

func (NamespaceData) WriteTo

func (nd NamespaceData) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the length-delimited protobuf of NamespaceData to the provided writer. implementing io.WriterTo.

type NamespaceDataID

type NamespaceDataID struct {
	// Embedding EdsID to include the block height.
	EdsID
	// DataNamespace will be used to identify the data within the EDS.
	DataNamespace libshare.Namespace
}

NamespaceDataID filters the data in the EDS by a specific namespace.

func NamespaceDataIDFromBinary

func NamespaceDataIDFromBinary(data []byte) (NamespaceDataID, error)

NamespaceDataIDFromBinary deserializes a NamespaceDataID from its binary form. It returns an error if the binary data's length does not match the expected size.

func NewNamespaceDataID

func NewNamespaceDataID(height uint64, namespace libshare.Namespace) (NamespaceDataID, error)

NewNamespaceDataID creates a new NamespaceDataID with the specified parameters. It validates the namespace and returns an error if it is invalid.

func (*NamespaceDataID) Equals

func (ndid *NamespaceDataID) Equals(other NamespaceDataID) bool

Equals checks equality of NamespaceDataID.

func (NamespaceDataID) MarshalBinary

func (ndid NamespaceDataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes NamespaceDataID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*NamespaceDataID) ReadFrom

func (ndid *NamespaceDataID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of NamespaceDataID from the provided reader.

func (NamespaceDataID) Validate

func (ndid NamespaceDataID) Validate() error

Validate checks if the NamespaceDataID is valid. It checks the validity of the EdsID and the DataNamespace.

func (NamespaceDataID) WriteTo

func (ndid NamespaceDataID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of NamespaceDataID to the provided writer.

type Row

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

Row represents a portion of a row in an EDS, either left or right half.

func NewRow

func NewRow(halfShares []libshare.Share, side RowSide) Row

NewRow creates a new Row with the specified shares and side.

func RowFromProto

func RowFromProto(r *pb.Row) (Row, error)

RowFromProto converts a protobuf Row to a Row structure.

func RowFromShares

func RowFromShares(shares []libshare.Share, side RowSide) Row

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

func (Row) IsEmpty

func (r Row) IsEmpty() bool

IsEmpty reports whether the Row is empty, i.e. doesn't contain any shares.

func (Row) Shares

func (r Row) Shares() ([]libshare.Share, error)

Shares reconstructs the complete row shares from the half provided, using RSMT2D for data recovery if needed.

func (Row) ToProto

func (r Row) ToProto() *pb.Row

ToProto converts the Row to its protobuf representation.

func (Row) Verify

func (r Row) Verify(roots *share.AxisRoots, idx int) error

Verify checks if the row's shares match the expected number from the root data and validates the side of the row.

type RowID

type RowID struct {
	EdsID        // Embedding EdsID to include the block height in RowID.
	RowIndex int // RowIndex specifies the position of the row within the data share.
}

RowID uniquely identifies a row in the data square of a blockchain block, combining block height with the row's index.

func NewRowID

func NewRowID(height uint64, rowIdx, edsSize int) (RowID, error)

NewRowID creates a new RowID with the specified block height, row index, and EDS size. It returns an error if the validation fails, ensuring the RowID conforms to expected constraints.

func RowIDFromBinary

func RowIDFromBinary(data []byte) (RowID, error)

RowIDFromBinary decodes a RowID from its binary representation. It returns an error if the input data does not conform to the expected size or content format.

func (*RowID) Equals

func (rid *RowID) Equals(other RowID) bool

Equals checks equality of RowID.

func (RowID) MarshalBinary

func (rid RowID) MarshalBinary() ([]byte, error)

MarshalBinary encodes the RowID into a binary form for storage or network transmission.

func (*RowID) ReadFrom

func (rid *RowID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of RowID from the provided reader.

func (RowID) Validate

func (rid RowID) Validate() error

Validate performs basic field validation.

func (RowID) Verify

func (rid RowID) Verify(edsSize int) error

Verify validates the RowID fields and verifies that RowIndex is within the bounds of the square size

func (RowID) WriteTo

func (rid RowID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of RowID to the provided writer.

type RowNamespaceData

type RowNamespaceData struct {
	Shares []libshare.Share `json:"shares"` // Shares within the namespace.
	Proof  *nmt.Proof       `json:"proof"`  // Proof of the shares' inclusion in the namespace.
}

RowNamespaceData holds shares and their corresponding proof for a single row within a namespace.

func RowNamespaceDataFromProto

func RowNamespaceDataFromProto(row *pb.RowNamespaceData) (RowNamespaceData, error)

RowNamespaceDataFromProto constructs RowNamespaceData out of its protobuf representation.

func RowNamespaceDataFromShares

func RowNamespaceDataFromShares(
	shares []libshare.Share,
	namespace libshare.Namespace,
	rowIndex int,
) (RowNamespaceData, error)

RowNamespaceDataFromShares extracts and constructs a RowNamespaceData from shares within the specified namespace.

func (RowNamespaceData) IsEmpty

func (rnd RowNamespaceData) IsEmpty() bool

IsEmpty reports whether the RowNamespaceData is empty, i.e. doesn't contain a proof.

func (*RowNamespaceData) ReadFrom

func (rnd *RowNamespaceData) ReadFrom(reader io.Reader) (int64, error)

ReadFrom reads length-delimited protobuf representation of RowNamespaceData implementing io.ReaderFrom.

func (RowNamespaceData) ToProto

func (rnd RowNamespaceData) ToProto() *pb.RowNamespaceData

ToProto converts RowNamespaceData to its protobuf representation for serialization.

func (RowNamespaceData) Verify

func (rnd RowNamespaceData) Verify(roots *share.AxisRoots, namespace libshare.Namespace, rowIdx int) error

Verify checks validity of the RowNamespaceData against the AxisRoots, Namespace and Row index.

func (RowNamespaceData) WriteTo

func (rnd RowNamespaceData) WriteTo(writer io.Writer) (int64, error)

WriteTo writes length-delimited protobuf representation of RowNamespaceData. implementing io.WriterTo.

type RowNamespaceDataID

type RowNamespaceDataID struct {
	RowID // Embedded RowID representing the specific row in the EDS.
	// DataNamespace is used to facilitate comparisons.
	DataNamespace libshare.Namespace
}

RowNamespaceDataID uniquely identifies a piece of namespaced data within a row of an Extended Data Square (EDS).

func NewRowNamespaceDataID

func NewRowNamespaceDataID(
	height uint64,
	rowIdx int,
	namespace libshare.Namespace,
	edsSize int,
) (RowNamespaceDataID, error)

NewRowNamespaceDataID creates a new RowNamespaceDataID with the specified parameters. It validates the RowNamespaceDataID against the provided EDS size.

func RowNamespaceDataIDFromBinary

func RowNamespaceDataIDFromBinary(data []byte) (RowNamespaceDataID, error)

RowNamespaceDataIDFromBinary deserializes a RowNamespaceDataID from its binary form. It returns an error if the binary data's length does not match the expected size.

func (*RowNamespaceDataID) Equals

func (rndid *RowNamespaceDataID) Equals(other RowNamespaceDataID) bool

Equals checks equality of RowNamespaceDataID.

func (RowNamespaceDataID) MarshalBinary

func (rndid RowNamespaceDataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes RowNamespaceDataID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*RowNamespaceDataID) ReadFrom

func (rndid *RowNamespaceDataID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of RowNamespaceDataID from the provided reader.

func (RowNamespaceDataID) Validate

func (rndid RowNamespaceDataID) Validate() error

Validate performs basic field validation.

func (RowNamespaceDataID) Verify

func (rndid RowNamespaceDataID) Verify(edsSize int) error

Verify validates the RowNamespaceDataID and verifies the embedded RowID.

func (RowNamespaceDataID) WriteTo

func (rndid RowNamespaceDataID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of RowNamespaceDataID to the provided writer.

type RowSide

type RowSide int

RowSide enumerates the possible sides of a row within an Extended Data Square (EDS).

const (
	Left  RowSide = iota // Left side of the row.
	Right                // Right side of the row.
)

func (RowSide) ToProto

func (s RowSide) ToProto() pb.Row_HalfSide

ToProto converts a RowSide to its protobuf representation.

type Sample

type Sample struct {
	libshare.Share             // Embeds the Share which includes the data with namespace.
	Proof          *nmt.Proof  // Proof is the Merkle Proof validating the share's inclusion.
	ProofType      rsmt2d.Axis // ProofType indicates whether the proof is against a row or a column.
}

Sample represents a data share along with its Merkle proof, used to validate the share's inclusion in a data square.

func SampleFromProto

func SampleFromProto(s *pb.Sample) (Sample, error)

SampleFromProto converts a protobuf Sample back into its domain model equivalent.

func SampleFromShares

func SampleFromShares(shares []libshare.Share, proofType rsmt2d.Axis, idx SampleCoords) (Sample, error)

SampleFromShares creates a Sample from a list of shares, using the specified proof type and the share index to be included in the sample.

func (Sample) IsEmpty

func (s Sample) IsEmpty() bool

IsEmpty reports whether the Sample is empty, i.e. doesn't contain a proof.

func (Sample) ToProto

func (s Sample) ToProto() *pb.Sample

ToProto converts a Sample into its protobuf representation for serialization purposes.

func (Sample) Verify

func (s Sample) Verify(roots *share.AxisRoots, rowIdx, colIdx int) error

Verify checks the inclusion of the share using its Merkle proof under the specified AxisRoots. Returns an error if the proof is invalid or does not correspond to the indicated proof type.

type SampleCoords added in v0.20.4

type SampleCoords struct {
	Row int `json:"row"`
	Col int `json:"col"`
}

func SampleCoordsFrom1DIndex added in v0.20.4

func SampleCoordsFrom1DIndex(idx, squareSize int) (SampleCoords, error)

type SampleID

type SampleID struct {
	RowID          // Embeds RowID to incorporate block height and row index.
	ShareIndex int // ShareIndex specifies the index of the sample within the row.
}

SampleID uniquely identifies a specific sample within a row of an Extended Data Square (EDS).

func NewSampleID

func NewSampleID(height uint64, idx SampleCoords, edsSize int) (SampleID, error)

NewSampleID constructs a new SampleID using the provided block height, sample index, and EDS size. It calculates the row and share index based on the sample index and EDS size.

func SampleIDFromBinary

func SampleIDFromBinary(data []byte) (SampleID, error)

SampleIDFromBinary deserializes a SampleID from binary data, ensuring the data length matches the expected size.

func (*SampleID) Equals

func (sid *SampleID) Equals(other SampleID) bool

Equals checks equality of SampleID.

func (SampleID) MarshalBinary

func (sid SampleID) MarshalBinary() ([]byte, error)

MarshalBinary encodes SampleID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*SampleID) ReadFrom

func (sid *SampleID) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the binary form of SampleID from the provided reader.

func (SampleID) Validate

func (sid SampleID) Validate() error

Validate performs basic field validation.

func (SampleID) Verify

func (sid SampleID) Verify(edsSize int) error

Verify validates the SampleID and verifies that the ShareIndex is within the bounds of the square size.

func (SampleID) WriteTo

func (sid SampleID) WriteTo(w io.Writer) (int64, error)

WriteTo writes the binary form of SampleID to the provided writer.

Directories

Path Synopsis
mock
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.
p2p
shrex
Package shrex provides functionality that powers the share exchange protocols used by celestia-node.
Package shrex provides functionality that powers the share exchange protocols used by celestia-node.
shrex/peers
Package peers provides a peer manager that handles peer discovery and peer selection for the shrex getter.
Package peers provides a peer manager that handles peer discovery and peer selection for the shrex getter.
shrex/shrexeds
This package defines a protocol that is used to request extended data squares from peers in the network.
This package defines a protocol that is used to request extended data squares from peers in the network.
shrex/shrexnd
This package defines a protocol that is used to request namespaced data from peers in the network.
This package defines a protocol that is used to request namespaced data from peers in the network.
shrex/shrexsub
This package defines a protocol that is used to broadcast shares to peers over a pubsub network.
This package defines a protocol that is used to broadcast shares to peers over a pubsub network.

Jump to

Keyboard shortcuts

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