Documentation ¶
Overview ¶
Package shares provides primitives for splitting block data into shares and parsing shares back into block data.
Index ¶
- Variables
- func DelimLen(size uint64) int
- func ExtractShareIndexes(txs coretypes.Txs) []uint32
- func FitsInSquare(cursor, squareSize int, msgShareLens ...int) (bool, int)
- func MarshalDelimitedMessage(msg coretypes.Message) ([]byte, error)
- func MarshalDelimitedTx(tx coretypes.Tx) ([]byte, error)
- func Merge(eds *rsmt2d.ExtendedDataSquare) (coretypes.Data, error)
- func MessageShareCountsFromMessages(msgs []*core.Message) []int
- func MessagesFromProto(msgs []*core.Message) []coretypes.Message
- func MessagesToProto(msgs []coretypes.Message) []*core.Message
- func MsgSharesUsed(msgSize int) int
- func MsgSharesUsedNonInteractiveDefaults(cursor, squareSize int, msgShareLens ...int) (int, []uint32)
- func NextAlignedPowerOfTwo(cursor, msgLen, squareSize int) (int, bool)
- func ParseDelimiter(input []byte) (inputWithoutLengthDelimiter []byte, dataLength uint64, err error)
- func ParseEvd(shares [][]byte) (coretypes.EvidenceData, error)
- func ParseMsgs(shares [][]byte) (coretypes.Messages, error)
- func ParseTxs(shares [][]byte) (coretypes.Txs, error)
- func ToBytes(shares []Share) (bytes [][]byte)
- func TxsFromBytes(txs [][]byte) coretypes.Txs
- func TxsToBytes(txs coretypes.Txs) [][]byte
- type CompactShareSplitter
- func (css *CompactShareSplitter) Count() (shareCount int)
- func (css *CompactShareSplitter) Export() []Share
- func (css *CompactShareSplitter) WriteBytes(rawData []byte)
- func (css *CompactShareSplitter) WriteEvidence(evd coretypes.Evidence) error
- func (css *CompactShareSplitter) WriteTx(tx coretypes.Tx)
- type InfoByte
- type Share
- func AppendToShares(shares []Share, nid namespace.ID, rawData []byte) []Share
- func FromBytes(bytes [][]byte) (shares []Share)
- func Split(data coretypes.Data, useShareIndexes bool) ([]Share, error)
- func SplitEvidence(evd coretypes.EvidenceList) ([]Share, error)
- func SplitMessages(cursor int, indexes []uint32, msgs []coretypes.Message, useShareIndexes bool) ([]Share, error)
- func SplitTxs(txs coretypes.Txs) []Share
- func TailPaddingShares(n int) []Share
- type SparseShareSplitter
Constants ¶
This section is empty.
Variables ¶
var ( ErrIncorrectNumberOfIndexes = errors.New( "number of malleated transactions is not identical to the number of wrapped transactions", ) "the first message started at an unexpected index", ) )
Functions ¶
func ExtractShareIndexes ¶
ExtractShareIndexes iterates over the transactions and extracts the share indexes from wrapped transactions. It returns nil if the transactions are from an old block that did not have share indexes in the wrapped txs.
func FitsInSquare ¶
FitsInSquare uses the non interactive default rules to see if messages of some lengths will fit in a square of squareSize starting at share index cursor. See non-interactive default rules https://github.com/celestiaorg/celestia-specs/blob/master/src/rationale/message_block_layout.md#non-interactive-default-rules
func MarshalDelimitedMessage ¶
MarshalDelimitedMessage marshals the raw share data (excluding the namespace) of this message and prefixes it with the length of the message encoded as a varint.
func MarshalDelimitedTx ¶
MarshalDelimitedTx prefixes a transaction with the length of the transaction encoded as a varint.
func Merge ¶
func Merge(eds *rsmt2d.ExtendedDataSquare) (coretypes.Data, error)
Merge extracts block data from an extended data square.
func MsgSharesUsed ¶
MsgSharesUsed calculates the minimum number of shares a message will take up. It accounts for the necessary delimiter and potential padding.
func MsgSharesUsedNonInteractiveDefaults ¶
func MsgSharesUsedNonInteractiveDefaults(cursor, squareSize int, msgShareLens ...int) (int, []uint32)
MsgSharesUsedNonInteractiveDefaults calculates the number of shares used by a given set of messages share lengths. It follows the non-interactive default rules and returns the share indexes for each message.
func NextAlignedPowerOfTwo ¶
NextAlignedPowerOfTwo calculates the next index in a row that is an aligned power of two and returns false if the entire the msg cannot fit on the given row at the next aligned power of two. An aligned power of two means that the largest power of two that fits entirely in the msg or the square size. pls see specs for further details. Assumes that cursor < squareSize, all args are non negative, and that squareSize is a power of two. https://github.com/celestiaorg/celestia-specs/blob/master/src/rationale/message_block_layout.md#non-interactive-default-rules
func ParseDelimiter ¶
func ParseDelimiter(input []byte) (inputWithoutLengthDelimiter []byte, dataLength uint64, err error)
ParseDelimiter finds and returns the length delimiter of the share provided while also removing the delimiter bytes from the input. ParseDelimiter applies to both compact and sparse shares. Input should not contain the namespace ID or info byte of a share.
func ParseEvd ¶
func ParseEvd(shares [][]byte) (coretypes.EvidenceData, error)
ParseEvd collects all evidence from the shares provided.
func TxsFromBytes ¶
func TxsToBytes ¶
Types ¶
type CompactShareSplitter ¶
type CompactShareSplitter struct {
// contains filtered or unexported fields
}
CompactShareSplitter will write raw data compactly across a progressively increasing set of shares. It is used to lazily split block data such as transactions, intermediate state roots, and evidence into shares.
func NewCompactShareSplitter ¶
func NewCompactShareSplitter(ns namespace.ID, version uint8) *CompactShareSplitter
NewCompactShareSplitter returns a CompactShareSplitter using the provided namespace.
func (*CompactShareSplitter) Count ¶
func (css *CompactShareSplitter) Count() (shareCount int)
Count returns the number of shares that would be made if `Export` was invoked on this compact share splitter.
func (*CompactShareSplitter) Export ¶
func (css *CompactShareSplitter) Export() []Share
Export finalizes and returns the underlying compact shares.
func (*CompactShareSplitter) WriteBytes ¶
func (css *CompactShareSplitter) WriteBytes(rawData []byte)
WriteBytes adds the delimited data to the underlying compact shares.
func (*CompactShareSplitter) WriteEvidence ¶
func (css *CompactShareSplitter) WriteEvidence(evd coretypes.Evidence) error
func (*CompactShareSplitter) WriteTx ¶
func (css *CompactShareSplitter) WriteTx(tx coretypes.Tx)
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 "message start indicator", that is `1` if the share is at the start of a message and `0` otherwise.
func ParseInfoByte ¶
func (InfoByte) IsMessageStart ¶
IsMessageStart returns whether this share is the start of a message.
type Share ¶
type Share []byte
Share contains the raw share data (including namespace ID).
func AppendToShares ¶
AppendToShares appends raw data as shares. Used for messages.
func Split ¶
Split converts block data into encoded shares, optionally using share indexes that are encoded as wrapped transactions. Most use cases out of this package should use these share indexes and therefore set useShareIndexes to true.
func SplitEvidence ¶
func SplitEvidence(evd coretypes.EvidenceList) ([]Share, error)
func SplitMessages ¶
func TailPaddingShares ¶
TailPaddingShares creates n tail padding shares.
func (Share) MessageLength ¶
func (Share) NamespaceID ¶
type SparseShareSplitter ¶
type SparseShareSplitter struct {
// contains filtered or unexported fields
}
SparseShareSplitter lazily splits messages into shares that will eventually be included in a data square. It also has methods to help progressively count how many shares the messages 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() []Share
Export finalizes and returns the underlying shares.
func (*SparseShareSplitter) RemoveMessage ¶
func (sss *SparseShareSplitter) RemoveMessage(i int) (int, error)
RemoveMessage will remove a message from the underlying message state. If there is namespaced padding after the message, then that is also removed.
func (*SparseShareSplitter) Write ¶
func (sss *SparseShareSplitter) Write(msg coretypes.Message)
Write adds the delimited data to the underlying messages shares.
func (*SparseShareSplitter) WriteNamespacedPaddedShares ¶
func (sss *SparseShareSplitter) WriteNamespacedPaddedShares(count int)
WriteNamespacedPaddedShares adds empty shares using the namespace of the last written share. This is useful to follow the message layout rules. It assumes that at least one share has already been written, if not it panics.