square

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlobShareRange

func BlobShareRange(txs [][]byte, txIndex, blobIndex int, appVersion uint64) (shares.Range, error)

BlobShareRange returns the range of share indexes that the blob, identified by txIndex and blobIndex, occupies. The range is end exclusive.

func Deconstruct

func Deconstruct(s Square, decoder types.TxDecoder) (core.Txs, error)

Deconstruct takes a square and returns the ordered list of block transactions that constructed that square

This method uses the wrapped pfbs in the PFB namespace to identify and decode the blobs. Data that may be included in the square but isn't recognised by the square construction algorithm will be ignored

func FullNamespace

func FullNamespace(blob core.Blob) []byte

TODO: celestia-core should provide this method for `Blob`s

func Size

func Size(len int) int

func TxShareRange

func TxShareRange(txs [][]byte, txIndex int, appVersion uint64) (shares.Range, error)

TxShareRange returns the range of share indexes that the tx, specified by txIndex, occupies. The range is end exclusive.

Types

type Builder

type Builder struct {

	// here we keep track of the pending data to go in a square
	Txs   [][]byte
	Pfbs  []*coretypes.IndexWrapper
	Blobs []*Element

	// for compact shares we use a counter to track the amount of shares needed
	TxCounter  *shares.CompactShareCounter
	PfbCounter *shares.CompactShareCounter
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder(maxSquareSize int, appVersion uint64, txs ...[]byte) (*Builder, error)

func (*Builder) AppendBlobTx

func (b *Builder) AppendBlobTx(blobTx coretypes.BlobTx) bool

AppendBlobTx attempts to allocate the blob transaction to the square. It returns false if there is not enough space in the square to fit the transaction.

func (*Builder) AppendTx

func (b *Builder) AppendTx(tx []byte) bool

AppendTx attempts to allocate the transaction to the square. It returns false if there is not enough space in the square to fit the transaction.

func (*Builder) BlobShareLength

func (b *Builder) BlobShareLength(pfbIndex, blobIndex int) (int, error)

BlobShareLength returns the amount of shares a blob takes up in the square. It takes the index of the pfb in the tx set and the index of the blob within the PFB. TODO: we could look in to creating a map to avoid O(n) lookup when we expect large numbers of blobs

func (*Builder) CurrentSize

func (b *Builder) CurrentSize() int

func (*Builder) Export

func (b *Builder) Export() (Square, error)

Export constructs the square.

func (*Builder) FindBlobStartingIndex

func (b *Builder) FindBlobStartingIndex(pfbIndex, blobIndex int) (int, error)

FindBlobStartingIndex returns the starting share index of the blob in the square. It takes the index of the pfb in the tx set and the index of the blob within the PFB.

func (*Builder) FindTxShareRange

func (b *Builder) FindTxShareRange(txIndex int) (shares.Range, error)

FindTxShareRange returns the range of shares occupied by the tx at txIndex. The indexes are both inclusive.

func (*Builder) GetWrappedPFB

func (b *Builder) GetWrappedPFB(txIndex int) (*coretypes.IndexWrapper, error)

func (*Builder) IsEmpty

func (b *Builder) IsEmpty() bool

func (*Builder) NumPFBs

func (b *Builder) NumPFBs() int

func (*Builder) NumTxs

func (b *Builder) NumTxs() int

func (*Builder) SubtreeRootThreshold

func (b *Builder) SubtreeRootThreshold() int

type Element

type Element struct {
	Blob       core.Blob
	PfbIndex   int
	BlobIndex  int
	NumShares  int
	MaxPadding int
}

type Square

type Square []shares.Share

Square is a 2D square of shares with symmetrical sides that are always a power of 2.

func Build

func Build(txs [][]byte, appVersion uint64, maxSquareSize int) (Square, [][]byte, error)

Build takes an arbitrary long list of (prioritized) transactions and builds a square that is never greater than maxSquareSize. It also returns the ordered list of transactions that are present in the square and which have all PFBs trailing regular transactions. Note, this function does not check the underlying validity of the transactions. Errors should not occur and would reflect a violation in an invariant.

func Construct

func Construct(txs [][]byte, appVersion uint64, maxSquareSize int) (Square, error)

Construct takes the exact list of ordered transactions and constructs a square, validating that

  • all blobTxs are ordered after non-blob transactions
  • the transactions don't collectively exceed the maxSquareSize.

Note that this function does not check the underlying validity of the transactions.

func EmptySquare

func EmptySquare() Square

EmptySquare returns a 1x1 square with a single tail padding share

func WriteSquare

func WriteSquare(
	txWriter, pfbWriter *shares.CompactShareSplitter,
	blobWriter *shares.SparseShareSplitter,
	nonReservedStart, squareSize int,
) (Square, error)

func (Square) Equals

func (s Square) Equals(other Square) bool

Equals returns true if two squares are equal

func (Square) IsEmpty

func (s Square) IsEmpty() bool

func (Square) Size

func (s Square) Size() int

Size returns the size of the sides of a square

func (Square) WrappedPFBs

func (s Square) WrappedPFBs() (core.Txs, error)

WrappedPFBs returns the wrapped PFBs in a square

Jump to

Keyboard shortcuts

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