Documentation ¶
Index ¶
- Constants
- Variables
- func BlobMinSquareSize(shareCount int) int
- func GetData(s Share) []byte
- func NewReservedBytes(byteIndex uint32) ([]byte, error)
- func NewSHA256Hasher() hash.Hash
- func ParseReservedBytes(reservedBytes []byte) (uint32, error)
- func RoundDownPowerOfTwo[I constraints.Integer](input I) (I, error)
- func RoundUpPowerOfTwo[I constraints.Integer](input I) I
- func SparseSharesNeeded(sequenceLen uint32) (sharesNeeded int)
- func SubTreeWidth(shareCount, subtreeRootThreshold int) int
- func ToBytes(shares []AppShare) (bytes [][]byte)
- type API
- type AppShare
- func FromBytes(bytes [][]byte) (shares []AppShare, err error)
- func NamespacePaddingShare(ns namespace.Namespace) (AppShare, error)
- func NamespacePaddingShares(ns namespace.Namespace, n int) ([]AppShare, error)
- func NewShare(data []byte) (*AppShare, error)
- func SplitBlobs(blobs ...core.CoreBlob) ([]AppShare, error)
- func (s *AppShare) DoesSupportVersions(supportedShareVersions []uint8) error
- func (s *AppShare) InfoByte() (InfoByte, error)
- func (s AppShare) IsCompactShare() (bool, error)
- func (s *AppShare) IsPadding() (bool, error)
- func (s *AppShare) IsSequenceStart() (bool, error)
- func (s *AppShare) Len() int
- func (s *AppShare) Namespace() (namespace.Namespace, error)
- func (s *AppShare) RawData() (rawData []byte, err error)
- func (s *AppShare) RawDataUsingReserved() (rawData []byte, err error)
- func (s *AppShare) SequenceLen() (sequenceLen uint32, err error)
- func (s *AppShare) ToBytes() []byte
- func (s *AppShare) Version() (uint8, error)
- type Builder
- func (b *Builder) AddData(rawData []byte) (rawDataLeftOver []byte)
- func (b *Builder) AvailableBytes() int
- func (b *Builder) Build() (*AppShare, error)
- func (b *Builder) FlipSequenceStart()
- func (b *Builder) ImportRawShare(rawBytes []byte) *Builder
- func (b *Builder) Init() (*Builder, error)
- func (b *Builder) IsEmptyShare() bool
- func (b *Builder) MaybeWriteReservedBytes() error
- func (b *Builder) WriteSequenceLen(sequenceLen uint32) error
- func (b *Builder) ZeroPadIfNecessary() (bytesOfPadding int)
- type DataHash
- type GetRangeResult
- type InfoByte
- type Namespace
- func (n Namespace) Equals(target Namespace) bool
- func (n Namespace) ID() namespace.ID
- func (n Namespace) IsAboveMax(nodeHash []byte) bool
- func (n Namespace) IsBelowMin(nodeHash []byte) bool
- func (n Namespace) IsGreater(target Namespace) bool
- func (n Namespace) IsGreaterOrEqualThan(target Namespace) bool
- func (n Namespace) IsLess(target Namespace) bool
- func (n Namespace) IsLessOrEqual(target Namespace) bool
- func (n Namespace) IsOutsideRange(leftNodeHash, rightNodeHash []byte) bool
- func (n Namespace) Len() int
- func (n Namespace) Repeat(t int) []Namespace
- func (n Namespace) String() string
- func (n Namespace) ToAppNamespace() appns.Namespace
- func (n Namespace) ToNMT() namespace.ID
- func (n Namespace) Validate() error
- func (n Namespace) ValidateForBlob() error
- func (n Namespace) ValidateForData() error
- func (n Namespace) Version() byte
- type NamespacedRow
- type NamespacedShares
- type Root
- type Share
- type ShareProof
- type SparseShareSplitter
Constants ¶
const ( // Size is a system-wide size of a share, including both data and namespace GetNamespace Size = appconsts.ShareSize )
Variables ¶
var ( MaxReservedNamespace = Namespace(appns.MaxReservedNamespace.Bytes()) TailPaddingNamespace = Namespace(appns.TailPaddingNamespace.Bytes()) ReservedPaddingNamespace = Namespace(appns.ReservedPaddingNamespace.Bytes()) TxNamespace = Namespace(appns.TxNamespace.Bytes()) PayForBlobNamespace = Namespace(appns.PayForBlobNamespace.Bytes()) )
Various reserved namespaces.
var DefaultRSMT2DCodec = appconsts.DefaultCodec
DefaultRSMT2DCodec sets the default rsmt2d.Codec for shares.
var ( // ErrNotAvailable is returned whenever DA sampling fails. ErrNotAvailable = errors.New("share: data not available") )
var MaxSquareSize = appconsts.SquareSizeUpperBound(appconsts.LatestVersion)
MaxSquareSize is currently the maximum size supported for unerasured data in rsmt2d.ExtendedDataSquare.
Functions ¶
func BlobMinSquareSize ¶
BlobMinSquareSize returns the minimum square size that can contain shareCount number of shares.
func NewReservedBytes ¶
NewReservedBytes returns a byte slice of length appconsts.CompactShareReservedBytes that contains the byteIndex of the first unit that starts in a compact share.
func NewSHA256Hasher ¶ added in v0.5.0
NewSHA256Hasher returns a new instance of a SHA-256 hasher.
func ParseReservedBytes ¶
ParseReservedBytes parses a byte slice of length appconsts.CompactShareReservedBytes into a byteIndex.
func RoundDownPowerOfTwo ¶
func RoundDownPowerOfTwo[I constraints.Integer](input I) (I, error)
RoundDownPowerOfTwo returns the next power of two less than or equal to input.
func RoundUpPowerOfTwo ¶
func RoundUpPowerOfTwo[I constraints.Integer](input I) I
RoundUpPowerOfTwo returns the next power of two greater than or equal to input.
func SparseSharesNeeded ¶ added in v0.5.0
func SubTreeWidth ¶
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).
Types ¶
type API ¶
type API struct { context.Context, eh *header.ExtendedHeader, row, col int, ) (*Share, error) `perm:"read"` GetEDS func( ctx context.Context, eh *header.ExtendedHeader, ) (*rsmt2d.ExtendedDataSquare, error) `perm:"read"` ctx context.Context, eh *header.ExtendedHeader, namespace Namespace, ) (*NamespacedShares, error) `perm:"read"` GetRange func( ctx context.Context, height uint64, start, end int, ) (*GetRangeResult, error) `perm:"read"` }ctx
type AppShare ¶ added in v0.5.0
type AppShare struct {
// contains filtered or unexported fields
}
func NamespacePaddingShare ¶
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 ¶
NamespacePaddingShares returns n namespace padding shares.
func SplitBlobs ¶ added in v0.5.0
SplitBlobs splits the provided blobs into shares.
func (*AppShare) DoesSupportVersions ¶ added in v0.5.0
func (AppShare) IsCompactShare ¶ added in v0.5.0
IsCompactShare returns true if this is a compact share.
func (*AppShare) IsPadding ¶ added in v0.5.0
IsPadding returns whether this *share is padding or not.
func (*AppShare) IsSequenceStart ¶ added in v0.5.0
IsSequenceStart returns true if this is the first share in a sequence.
func (*AppShare) RawData ¶ added in v0.5.0
RawData returns the raw share data. The raw share data does not contain the namespace ID, info byte, sequence length, or reserved bytes.
func (*AppShare) RawDataUsingReserved ¶ added in v0.5.0
RawDataWithReserved returns the raw share data while taking reserved bytes into account.
func (*AppShare) SequenceLen ¶ added in v0.5.0
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).
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func NewBuilder ¶
Init() needs to be called right after this method
func NewEmptyBuilder ¶
func NewEmptyBuilder() *Builder
func (*Builder) AvailableBytes ¶
func (*Builder) FlipSequenceStart ¶
func (b *Builder) FlipSequenceStart()
FlipSequenceStart flips the sequence start indicator of the share provided
func (*Builder) ImportRawShare ¶
func (*Builder) IsEmptyShare ¶
IsEmptyShare returns true if no data has been written to the share
func (*Builder) MaybeWriteReservedBytes ¶
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 ¶
writeSequenceLen writes the sequence length to the first share.
func (*Builder) ZeroPadIfNecessary ¶
type DataHash ¶
type DataHash []byte
DataHash is a representation of the Root hash.
func MustDataHashFromString ¶ added in v0.5.0
MustDataHashFromString converts a hex string to a valid datahash.
type GetRangeResult ¶ added in v0.5.0
type GetRangeResult struct { Proof *ShareProof }
GetRangeResult wraps the return value of the GetRange endpoint because Json-RPC doesn't support more than two return values.
type InfoByte ¶
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 ParseInfoByte ¶
func (InfoByte) IsSequenceStart ¶
IsSequenceStart returns whether this share is the start of a sequence.
type Namespace ¶
type Namespace []byte
Namespace represents namespace of a Share. Consists of version byte and namespace ID.
func GetNamespace ¶ added in v0.5.0
GetNamespace slices Namespace out of the Share.
func NamespaceFromBytes ¶
NamespaceFromBytes converts bytes into Namespace and validates it.
func NewBlobNamespaceV0 ¶
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) IsAboveMax ¶
IsAboveMax checks if the namespace is above the maximum namespace of the given hash.
func (Namespace) IsBelowMin ¶
IsBelowMin checks if the target namespace is below the minimum namespace of the given hash.
func (Namespace) IsGreaterOrEqualThan ¶
IsGreaterOrEqualThan reports if the Namespace is greater or equal than the target.
func (Namespace) IsLessOrEqual ¶
IsLessOrEqual reports if the Namespace is less than the target.
func (Namespace) IsOutsideRange ¶
IsOutsideRange checks if the namespace is outside the min-max range of the given hashes.
func (Namespace) ToAppNamespace ¶
ToAppNamespace converts the Namespace to App's definition of Namespace. TODO: Unify types between node and app
func (Namespace) ToNMT ¶
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) ValidateForBlob ¶
ValidateForBlob checks if the Namespace is valid blob namespace.
func (Namespace) ValidateForData ¶
ValidateForData checks if the Namespace is of real/useful data.
type NamespacedRow ¶
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 ¶
type Root = core.DataAvailabilityHeader
Root represents root commitment to multiple Shares. In practice, it is a commitment to all the Data in a square.
type Share ¶
type Share = []byte
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.
type ShareProof ¶ added in v0.5.0
type ShareProof struct { byte `json:"data"` // rows. There will be one ShareProof per row that the shares occupy. ShareProofs []*nmt.Proof `json:"share_proofs"` // NamespaceID is the namespace id of the shares being proven. This // namespace id is used when verifying the proof. If the namespace id doesn't // match the namespace of the shares, the proof will fail verification. }Data [][]
ShareProof is an NMT proof that a set of shares exist in a set of rows and a Merkle proof that those rows exist in a Merkle tree with a given data root.
type SparseShareSplitter ¶
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 ¶
func NewSparseShareSplitter() *SparseShareSplitter
func (*SparseShareSplitter) Count ¶
func (sss *SparseShareSplitter) Count() int
Count returns the current number of shares that will be made if exporting.
func (*SparseShareSplitter) Export ¶
func (sss *SparseShareSplitter) Export() []AppShare
Export finalizes and returns the underlying shares.
func (*SparseShareSplitter) Write ¶
func (sss *SparseShareSplitter) Write(blob coretypes.CoreBlob) error
func (*SparseShareSplitter) WriteNamespacePaddingShares ¶
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.