share

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Size is a system-wide size of a share, including both data and namespace GetNamespace
	Size = appconsts.ShareSize
)

Variables

View Source
var (
	MaxReservedNamespace     = Namespace(appns.MaxReservedNamespace.Bytes())
	ParitySharesNamespace    = Namespace(appns.ParitySharesNamespace.Bytes())
	TailPaddingNamespace     = Namespace(appns.TailPaddingNamespace.Bytes())
	ReservedPaddingNamespace = Namespace(appns.ReservedPaddingNamespace.Bytes())
	TxNamespace              = Namespace(appns.TxNamespace.Bytes())
	PayForBlobNamespace      = Namespace(appns.PayForBlobNamespace.Bytes())
)

Various reserved namespaces.

View Source
var (
	// DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares.
	DefaultRSMT2DCodec = appconsts.DefaultCodec
)
View Source
var (
	// ErrNotAvailable is returned whenever DA sampling fails.
	ErrNotAvailable = errors.New("share: data not available")
)

Functions

func BlobMinSquareSize added in v0.1.2

func BlobMinSquareSize(shareCount int) int

BlobMinSquareSize returns the minimum square size that can contain shareCount number of shares.

func NewReservedBytes added in v0.1.2

func NewReservedBytes(byteIndex uint32) ([]byte, error)

NewReservedBytes returns a byte slice of length appconsts.CompactShareReservedBytes that contains the byteIndex of the first unit that starts in a compact share.

func ParseReservedBytes added in v0.1.2

func ParseReservedBytes(reservedBytes []byte) (uint32, error)

ParseReservedBytes parses a byte slice of length appconsts.CompactShareReservedBytes into a byteIndex.

func RoundDownPowerOfTwo added in v0.1.2

func RoundDownPowerOfTwo[I constraints.Integer](input I) (I, error)

RoundDownPowerOfTwo returns the next power of two less than or equal to input.

func RoundUpPowerOfTwo added in v0.1.2

func RoundUpPowerOfTwo[I constraints.Integer](input I) I

RoundUpPowerOfTwo returns the next power of two greater than or equal to input.

func SubTreeWidth added in v0.1.2

func SubTreeWidth(shareCount, subtreeRootThreshold int) int

SubTreeWidth determines the maximum number of leaves per subtree in the share commitment over a given blob. The input should be the total number of shares used by that blob. The reasoning behind this algorithm is discussed in depth in ADR013 (celestia-app/docs/architecture/adr-013-non-interative-default-rules-for-zero-padding).

func ToBytes added in v0.1.2

func ToBytes(shares []Share) (bytes [][]byte)

Types

type Builder added in v0.1.2

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

func NewBuilder added in v0.1.2

func NewBuilder(ns namespace.Namespace, shareVersion uint8, isFirstShare bool) *Builder

Init() needs to be called right after this method

func NewEmptyBuilder added in v0.1.2

func NewEmptyBuilder() *Builder

func (*Builder) AddData added in v0.1.2

func (b *Builder) AddData(rawData []byte) (rawDataLeftOver []byte)

func (*Builder) AvailableBytes added in v0.1.2

func (b *Builder) AvailableBytes() int

func (*Builder) Build added in v0.1.2

func (b *Builder) Build() (*Share, error)

func (*Builder) FlipSequenceStart added in v0.1.2

func (b *Builder) FlipSequenceStart()

FlipSequenceStart flips the sequence start indicator of the share provided

func (*Builder) ImportRawShare added in v0.1.2

func (b *Builder) ImportRawShare(rawBytes []byte) *Builder

func (*Builder) Init added in v0.1.2

func (b *Builder) Init() (*Builder, error)

func (*Builder) IsEmptyShare added in v0.1.2

func (b *Builder) IsEmptyShare() bool

IsEmptyShare returns true if no data has been written to the share

func (*Builder) MaybeWriteReservedBytes added in v0.1.2

func (b *Builder) MaybeWriteReservedBytes() error

MaybeWriteReservedBytes will be a no-op if the reserved bytes have already been populated. If the reserved bytes are empty, it will write the location of the next unit of data to the reserved bytes.

func (*Builder) WriteSequenceLen added in v0.1.2

func (b *Builder) WriteSequenceLen(sequenceLen uint32) error

writeSequenceLen writes the sequence length to the first share.

func (*Builder) ZeroPadIfNecessary added in v0.1.2

func (b *Builder) ZeroPadIfNecessary() (bytesOfPadding int)

type DataHash

type DataHash []byte

DataHash is a representation of the Root hash.

func (DataHash) String

func (dh DataHash) String() string

func (DataHash) Validate

func (dh DataHash) Validate() error

type InfoByte added in v0.1.2

type InfoByte byte

InfoByte is a byte with the following structure: the first 7 bits are reserved for version information in big endian form (initially `0000000`). The last bit is a "sequence start indicator", that is `1` if this is the first share of a sequence and `0` if this is a continuation share.

func NewInfoByte added in v0.1.2

func NewInfoByte(version uint8, isSequenceStart bool) (InfoByte, error)

func ParseInfoByte added in v0.1.2

func ParseInfoByte(i byte) (InfoByte, error)

func (InfoByte) IsSequenceStart added in v0.1.2

func (i InfoByte) IsSequenceStart() bool

IsSequenceStart returns whether this share is the start of a sequence.

func (InfoByte) Version added in v0.1.2

func (i InfoByte) Version() uint8

Version returns the version encoded in this InfoByte. Version is expected to be between 0 and appconsts.MaxShareVersion (inclusive).

type Namespace

type Namespace []byte

Namespace represents namespace of a Share. Consists of version byte and namespace ID.

func NamespaceFromBytes

func NamespaceFromBytes(b []byte) (Namespace, error)

NamespaceFromBytes converts bytes into Namespace and validates it.

func NewBlobNamespaceV0

func NewBlobNamespaceV0(id []byte) (Namespace, error)

NewBlobNamespaceV0 takes a variable size byte slice and creates a valid version 0 Blob Namespace. The byte slice must be <= 10 bytes. If it is less than 10 bytes, it will be left padded to size 10 with 0s. Use predefined namespaces above, if non-blob namespace is needed.

func (Namespace) Equals

func (n Namespace) Equals(target Namespace) bool

Equals compares two Namespaces.

func (Namespace) ID

func (n Namespace) ID() namespace.ID

ID reports ID of the Namespace.

func (Namespace) IsAboveMax

func (n Namespace) IsAboveMax(nodeHash []byte) bool

IsAboveMax checks if the namespace is above the maximum namespace of the given hash.

func (Namespace) IsBelowMin

func (n Namespace) IsBelowMin(nodeHash []byte) bool

IsBelowMin checks if the target namespace is below the minimum namespace of the given hash.

func (Namespace) IsGreater

func (n Namespace) IsGreater(target Namespace) bool

IsGreater reports if the Namespace is greater than the target.

func (Namespace) IsGreaterOrEqualThan

func (n Namespace) IsGreaterOrEqualThan(target Namespace) bool

IsGreaterOrEqualThan reports if the Namespace is greater or equal than the target.

func (Namespace) IsLess

func (n Namespace) IsLess(target Namespace) bool

IsLess reports if the Namespace is less than the target.

func (Namespace) IsLessOrEqual

func (n Namespace) IsLessOrEqual(target Namespace) bool

IsLessOrEqual reports if the Namespace is less than the target.

func (Namespace) IsOutsideRange

func (n Namespace) IsOutsideRange(leftNodeHash, rightNodeHash []byte) bool

IsOutsideRange checks if the namespace is outside the min-max range of the given hashes.

func (Namespace) Len

func (n Namespace) Len() int

Len reports the total length of the namespace.

func (Namespace) Repeat

func (n Namespace) Repeat(t int) []Namespace

Repeat copies the Namespace t times.

func (Namespace) String

func (n Namespace) String() string

String stringifies the Namespace.

func (Namespace) ToAppNamespace

func (n Namespace) ToAppNamespace() appns.Namespace

ToAppNamespace converts the Namespace to App's definition of Namespace. TODO: Unify types between node and app

func (Namespace) ToNMT

func (n Namespace) ToNMT() namespace.ID

ToNMT converts the whole Namespace(both Version and ID parts) into NMT's namespace.ID NOTE: Once https://github.com/celestiaorg/nmt/issues/206 is closed Namespace should become NNT's type.

func (Namespace) Validate

func (n Namespace) Validate() error

Validate checks if the namespace is correct.

func (Namespace) ValidateForBlob

func (n Namespace) ValidateForBlob() error

ValidateForBlob checks if the Namespace is valid blob namespace.

func (Namespace) ValidateForData

func (n Namespace) ValidateForData() error

ValidateForData checks if the Namespace is of real/useful data.

func (Namespace) Version

func (n Namespace) Version() byte

Version reports version of the Namespace.

type NamespacedRow

type NamespacedRow struct {
	Shares []Share    `json:"shares"`
	Proof  *nmt.Proof `json:"proof"`
}

NamespacedRow represents all shares with proofs within a specific namespace of a single EDS row.

type NamespacedShares

type NamespacedShares []NamespacedRow

NamespacedShares represents all shares with proofs within a specific namespace of an EDS.

type Root

Root represents root commitment to multiple Shares. In practice, it is a commitment to all the Data in a square.

type Share

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

Share contains the raw share data without the corresponding namespace. NOTE: Alias for the byte is chosen to keep maximal compatibility, especially with rsmt2d. Ideally, we should define reusable type elsewhere and make everyone(Core, rsmt2d, ipld) to rely on it. Share contains the raw share data (including namespace ID).

func FromBytes added in v0.1.2

func FromBytes(bytes [][]byte) (shares []Share, err error)

func NamespacePaddingShare added in v0.1.2

func NamespacePaddingShare(ns namespace.Namespace) (Share, error)

NamespacePaddingShare returns a share that acts as padding. Namespace padding shares follow a blob so that the next blob may start at an index that conforms to blob share commitment rules. The ns parameter provided should be the namespace of the blob that precedes this padding in the data square.

func NamespacePaddingShares added in v0.1.2

func NamespacePaddingShares(ns namespace.Namespace, n int) ([]Share, error)

NamespacePaddingShares returns n namespace padding shares.

func NewShare added in v0.1.2

func NewShare(data []byte) (*Share, error)

func (*Share) DoesSupportVersions added in v0.1.2

func (s *Share) DoesSupportVersions(supportedShareVersions []uint8) error

func (*Share) InfoByte added in v0.1.2

func (s *Share) InfoByte() (InfoByte, error)

func (Share) IsCompactShare added in v0.1.2

func (s Share) IsCompactShare() (bool, error)

IsCompactShare returns true if this is a compact share.

func (*Share) IsPadding added in v0.1.2

func (s *Share) IsPadding() (bool, error)

IsPadding returns whether this *share is padding or not.

func (*Share) IsSequenceStart added in v0.1.2

func (s *Share) IsSequenceStart() (bool, error)

IsSequenceStart returns true if this is the first share in a sequence.

func (*Share) Len added in v0.1.2

func (s *Share) Len() int

func (*Share) Namespace added in v0.1.2

func (s *Share) Namespace() (namespace.Namespace, error)

func (*Share) RawData added in v0.1.2

func (s *Share) RawData() (rawData []byte, err error)

RawData returns the raw share data. The raw share data does not contain the namespace ID, info byte, sequence length, or reserved bytes.

func (*Share) RawDataUsingReserved added in v0.1.2

func (s *Share) RawDataUsingReserved() (rawData []byte, err error)

RawDataWithReserved returns the raw share data while taking reserved bytes into account.

func (*Share) SequenceLen added in v0.1.2

func (s *Share) SequenceLen() (sequenceLen uint32, err error)

SequenceLen returns the sequence length of this *share and optionally an error. It returns 0, nil if this is a continuation share (i.e. doesn't contain a sequence length).

func (*Share) ToBytes added in v0.1.2

func (s *Share) ToBytes() []byte

func (*Share) Validate added in v0.1.2

func (s *Share) Validate() error

func (*Share) Version added in v0.1.2

func (s *Share) Version() (uint8, error)

type SparseShareSplitter added in v0.1.2

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

SparseShareSplitter lazily splits blobs into shares that will eventually be included in a data square. It also has methods to help progressively count how many shares the blobs written take up.

func NewSparseShareSplitter added in v0.1.2

func NewSparseShareSplitter() *SparseShareSplitter

func (*SparseShareSplitter) Count added in v0.1.2

func (sss *SparseShareSplitter) Count() int

Count returns the current number of shares that will be made if exporting.

func (*SparseShareSplitter) Export added in v0.1.2

func (sss *SparseShareSplitter) Export() []Share

Export finalizes and returns the underlying shares.

func (*SparseShareSplitter) Write added in v0.1.2

func (sss *SparseShareSplitter) Write(shareVersion uint32, ns, data []byte) error

Write writes the provided blob to this sparse share splitter. It returns an error or nil if no error is encountered.

func (*SparseShareSplitter) WriteNamespacePaddingShares added in v0.1.2

func (sss *SparseShareSplitter) WriteNamespacePaddingShares(count int) error

WriteNamespacePaddingShares adds padding shares with the namespace of the last written This is useful to follow the non-interactive default rules. This function assumes that at least one share has already been written.

Jump to

Keyboard shortcuts

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