shares

package
v0.7.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncorrectNumberOfIndexes = errors.New(
		"number of malleated transactions is not identical to the number of wrapped transactions",
	)
	ErrUnexpectedFirstMessageShareIndex = errors.New(
		"the first message started at an unexpected index",
	)
)

Functions

func DelimLen

func DelimLen(size uint64) int

DelimLen calculates the length of the delimiter for a given message size

func ExtractShareIndexes

func ExtractShareIndexes(txs coretypes.Txs) []uint32

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

func FitsInSquare(cursor, squareSize int, msgShareLens ...int) (bool, int)

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

func MarshalDelimitedMessage(msg coretypes.Message) ([]byte, error)

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

func MarshalDelimitedTx(tx coretypes.Tx) ([]byte, error)

MarshalDelimitedTx prefixes a transaction with the length of the transaction encoded as a varint.

func Merge

Merge extracts block data from an extended data square.

func MessageShareCountsFromMessages

func MessageShareCountsFromMessages(msgs []*core.Message) []int

func MessagesFromProto

func MessagesFromProto(msgs []*core.Message) []coretypes.Message

func MessagesToProto

func MessagesToProto(msgs []coretypes.Message) []*core.Message

func MsgSharesUsed

func MsgSharesUsed(msgSize int) int

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

func NextAlignedPowerOfTwo(cursor, msgLen, squareSize int) (int, bool)

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 ParseMsgs

func ParseMsgs(shares [][]byte) (coretypes.Messages, error)

ParseMsgs collects all messages from the shares provided

func ParseTxs

func ParseTxs(shares [][]byte) (coretypes.Txs, error)

ParseTxs collects all of the transactions from the shares provided

func Split

func Split(data coretypes.Data, useShareIndexes bool) ([][]byte, error)

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) ([][]byte, error)

func SplitMessages

func SplitMessages(cursor int, indexes []uint32, msgs []coretypes.Message, useShareIndexes bool) ([][]byte, error)

func SplitTxs

func SplitTxs(txs coretypes.Txs) [][]byte

func TxsFromBytes

func TxsFromBytes(txs [][]byte) coretypes.Txs

func TxsToBytes

func TxsToBytes(txs coretypes.Txs) [][]byte

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() (count, availableBytes int)

Count returns the current number of shares that will be made if exporting and the number of availableBytes in the last pending share.

func (*CompactShareSplitter) Export

func (css *CompactShareSplitter) Export() NamespacedShares

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 InfoReservedByte

type InfoReservedByte byte

InfoReservedByte 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 NewInfoReservedByte

func NewInfoReservedByte(version uint8, isMessageStart bool) (InfoReservedByte, error)

func ParseInfoReservedByte

func ParseInfoReservedByte(i byte) (InfoReservedByte, error)

func (InfoReservedByte) IsMessageStart

func (i InfoReservedByte) IsMessageStart() bool

IsMessageStart returns whether this share is the start of a message.

func (InfoReservedByte) Version

func (i InfoReservedByte) Version() uint8

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

type NamespacedShare

type NamespacedShare struct {
	Share
	ID namespace.ID
}

NamespacedShare extends a Share with the corresponding namespace.

func AppendToShares

func AppendToShares(shares []NamespacedShare, nid namespace.ID, rawData []byte) []NamespacedShare

AppendToShares appends raw data as shares. Used for messages.

func (NamespacedShare) Data

func (n NamespacedShare) Data() []byte

func (NamespacedShare) NamespaceID

func (n NamespacedShare) NamespaceID() namespace.ID

type NamespacedShares

type NamespacedShares []NamespacedShare

NamespacedShares is just a list of NamespacedShare elements. It can be used to extract the raw shares.

func TailPaddingShares

func TailPaddingShares(n int) NamespacedShares

TailPaddingShares creates n tail padding shares.

func (NamespacedShares) RawShares

func (ns NamespacedShares) RawShares() [][]byte

RawShares returns the raw shares that can be fed into the erasure coding library (e.g. rsmt2d).

type Share

type Share []byte

Share contains the raw share data (including namespace ID).

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() NamespacedShares

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.

Jump to

Keyboard shortcuts

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