v1

package
v0.0.0-...-2acf6bc Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackingSizeU256      = fr381.Bits - 1
	ByteLenEncodingBytes = 3
	NbElemsEncodingBytes = 2

	// These also impact the circuit constraints (compile / setup time)
	MaxUncompressedBytes = 756240    // ~738.5KB defines the max size we can handle for a blob (uncompressed) input
	MaxUsableBytes       = 32 * 4096 // defines the number of bytes available in a blob
)

Variables

This section is empty.

Functions

func DecodeBlockFromUncompressed

func DecodeBlockFromUncompressed(r *bytes.Reader) (encode.DecodedBlockData, error)

DecodeBlockFromUncompressed inverts EncodeBlockForCompression. It is primarily meant for testing and ensuring the encoding is bijective.

func DecodeTxFromUncompressed

func DecodeTxFromUncompressed(r *bytes.Reader, from *common.Address) (types.TxData, error)

func EncodeBlockForCompression

func EncodeBlockForCompression(block *types.Block, w io.Writer) error

EncodeBlockForCompression encodes a block for compression.

func PassRlpList

func PassRlpList(r *bytes.Reader) error

PassRlpList advances the reader through an RLP list assuming the reader is currently pointing to an RLP-encoded list. This is used to scan the encoded number of bytes of an encoded blocks and more specifically to find the boundaries of an RLP-encoded transaction.

func ScanBlockByteLen

func ScanBlockByteLen(b []byte) (int, error)

ScanBlockByteLen scans the stream of bytes `b`, expecting to find an encoded block starting from position 0 and returns the length of the block. It returns an error if the scanner goes out of bound.

Types

type BlobMaker

type BlobMaker struct {
	Limit int // maximum size of the compressed data

	Header Header
	// contains filtered or unexported fields
}

BlobMaker is a bm for RLP encoded blocks (see EIP-4844). It takes a batch of blocks as input (see StartNewBatch and Write). And it compresses them into a "blob" (see Bytes).

func NewBlobMaker

func NewBlobMaker(dataLimit int, dictPath string) (*BlobMaker, error)

NewBlobMaker returns a new bm.

func (*BlobMaker) Bytes

func (bm *BlobMaker) Bytes() []byte

Bytes returns the compressed data. Note that it returns a slice of the internal buffer, it is the caller's responsibility to copy the data if needed.

func (*BlobMaker) Clone

func (bm *BlobMaker) Clone() *BlobMaker

Clone returns a (almost) deep copy of the bm -- this is used for test purposes.

func (*BlobMaker) Equals

func (bm *BlobMaker) Equals(other *BlobMaker) bool

Equals returns true if the two compressors are ~equal -- this is used for test purposes.

func (*BlobMaker) Len

func (bm *BlobMaker) Len() int

Len returns the length of the compressed data, which includes the header.

func (*BlobMaker) RawCompressedSize

func (bm *BlobMaker) RawCompressedSize(data []byte) (int, error)

RawCompressedSize compresses the (raw) input and returns the length of the compressed data. The returned length account for the "padding" used by the blob maker to fit the data in field elements. Input size must be less than 256kB. If an error occurred, returns -1.

This function is thread-safe. Concurrent calls are allowed, but the other functions are not thread-safe.

func (*BlobMaker) Reset

func (bm *BlobMaker) Reset()

Reset resets the bm to its initial state.

func (*BlobMaker) StartNewBatch

func (bm *BlobMaker) StartNewBatch()

StartNewBatch starts a new batch of blocks.

func (*BlobMaker) WorstCompressedBlockSize

func (bm *BlobMaker) WorstCompressedBlockSize(rlpBlock []byte) (bool, int, error)

WorstCompressedBlockSize returns the size of the given block, as compressed by an "empty" blob maker. That is, with more context, blob maker could compress the block further, but this function returns the maximum size that can be achieved.

The input is a RLP encoded block. Returns the length of the compressed data, or -1 if an error occurred.

This function is thread-safe. Concurrent calls are allowed, but the other functions may not be thread-safe.

func (*BlobMaker) WorstCompressedTxSize

func (bm *BlobMaker) WorstCompressedTxSize(rlpTx []byte) (int, error)

WorstCompressedTxSize returns the size of the given transaction, as compressed by an "empty" blob maker. That is, with more context, blob maker could compress the transaction further, but this function returns the maximum size that can be achieved.

The input is a RLP encoded transaction. Returns the length of the compressed data, or -1 if an error occurred.

This function is thread-safe. Concurrent calls are allowed, but the other functions may not be thread-safe.

func (*BlobMaker) Write

func (bm *BlobMaker) Write(rlpBlock []byte, forceReset bool) (ok bool, err error)

Write attempts to append the RLP block to the current batch. if forceReset is set; this will NOT append the bytes but still returns true if the chunk could have been appended

func (*BlobMaker) Written

func (bm *BlobMaker) Written() int
type Header struct {
	BatchSizes         []int // BatchSizes[i] == byte size of the i-th batch
	CurrBatchBlocksLen []int // CurrBatchBlocksLen[i] == byte size of the i-th block in the current batch
	DictChecksum       [fr.Bytes]byte
}

A Header is a list of batches of blocks of len(blocks) len(BatchSizes) == nb of batches in the blob

func DecompressBlob

func DecompressBlob(b []byte, dictStore dictionary.Store) (blobHeader *Header, rawPayload []byte, blocks [][]byte, err error)

DecompressBlob decompresses a blob and returns the header and the blocks as they were compressed.

func (*Header) ByteSize

func (s *Header) ByteSize() int

func (*Header) ByteSizePacked

func (s *Header) ByteSizePacked() int

func (*Header) Equals

func (s *Header) Equals(other *Header) bool

func (*Header) NbBatches

func (s *Header) NbBatches() int

func (*Header) ReadFrom

func (s *Header) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the header BatchSizes from r.

func (*Header) WriteTo

func (s *Header) WriteTo(w io.Writer) (int64, error)

WriteTo writes the header to w. It tentatively considers the current batch as sealed.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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