da

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// NamespaceVersionSize is the size of the namespace version in bytes
	NamespaceVersionSize = 1
	// NamespaceIDSize is the size of the namespace ID in bytes
	NamespaceIDSize = 28
	// NamespaceSize is the total size of a namespace (version + ID) in bytes
	NamespaceSize = NamespaceVersionSize + NamespaceIDSize

	// NamespaceVersionZero is the only supported user-specifiable namespace version
	NamespaceVersionZero = uint8(0)
	// NamespaceVersionMax is the max namespace version
	NamespaceVersionMax = uint8(255)

	// NamespaceVersionZeroPrefixSize is the number of leading zero bytes required for version 0
	NamespaceVersionZeroPrefixSize = 18
	// NamespaceVersionZeroDataSize is the number of data bytes available for version 0
	NamespaceVersionZeroDataSize = 10
)

Variables

View Source
var (
	ErrBlobNotFound               = errors.New("blob: not found")
	ErrBlobSizeOverLimit          = errors.New("blob: over size limit")
	ErrTxTimedOut                 = errors.New("timed out waiting for tx to be included in a block")
	ErrTxAlreadyInMempool         = errors.New("tx already in mempool")
	ErrTxIncorrectAccountSequence = errors.New("incorrect account sequence")
	ErrContextDeadline            = errors.New("context deadline")
	ErrHeightFromFuture           = errors.New("given height is from the future")
	ErrContextCanceled            = errors.New("context canceled")
)
View Source
var ErrHeightFromFutureStr = fmt.Errorf("given height is from the future")

Functions

func PrepareNamespace

func PrepareNamespace(identifier []byte) []byte

PrepareNamespace converts a namespace identifier (string or bytes) into a proper Celestia namespace This is the main function to be used when preparing namespaces for DA operations

func SplitID

func SplitID(id []byte) (uint64, []byte, error)

SplitID splits an ID into a height and a commitment. if len(id) <= 8, it returns 0 and nil.

Types

type BaseResult

type BaseResult struct {
	// Code is to determine if the action succeeded.
	Code StatusCode
	// Message may contain DA layer specific information (like DA block height/hash, detailed error message, etc)
	Message string
	// Height is the height of the block on Data Availability Layer for given result.
	Height uint64
	// SubmittedCount is the number of successfully submitted blocks.
	SubmittedCount uint64
	// BlobSize is the size of the blob submitted.
	BlobSize uint64
	// IDs is the list of IDs of the blobs submitted.
	IDs [][]byte
	// Timestamp is the timestamp of the posted data on Data Availability Layer.
	Timestamp time.Time
}

BaseResult contains basic information returned by DA layer.

type Blob

type Blob = []byte

Blob is the data submitted/received from DA interface.

type Commitment

type Commitment = []byte

Commitment should contain serialized cryptographic commitment to Blob value.

type DA

type DA interface {
	// Get returns Blob for each given ID, or an error.
	//
	// Error should be returned if ID is not formatted properly, there is no Blob for given ID or any other client-level
	// error occurred (dropped connection, timeout, etc).
	Get(ctx context.Context, ids []ID, namespace []byte) ([]Blob, error)

	// GetIDs returns IDs of all Blobs located in DA at given height.
	GetIDs(ctx context.Context, height uint64, namespace []byte) (*GetIDsResult, error)

	// GetProofs returns inclusion Proofs for Blobs specified by their IDs.
	GetProofs(ctx context.Context, ids []ID, namespace []byte) ([]Proof, error)

	// Commit creates a Commitment for each given Blob.
	Commit(ctx context.Context, blobs []Blob, namespace []byte) ([]Commitment, error)

	// Submit submits the Blobs to Data Availability layer.
	//
	// This method is synchronous. Upon successful submission to Data Availability layer, it returns the IDs identifying blobs
	// in DA.
	Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte) ([]ID, error)

	// SubmitWithOptions submits the Blobs to Data Availability layer with additional options.
	SubmitWithOptions(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte, options []byte) ([]ID, error)

	// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
	Validate(ctx context.Context, ids []ID, proofs []Proof, namespace []byte) ([]bool, error)

	// GasPrice returns the gas price for the DA layer.
	GasPrice(ctx context.Context) (float64, error)

	// GasMultiplier returns the gas multiplier for the DA layer.
	GasMultiplier(ctx context.Context) (float64, error)
}

DA defines very generic interface for interaction with Data Availability layers.

type DummyDA

type DummyDA struct {
	// contains filtered or unexported fields
}

DummyDA is a simple in-memory implementation of the DA interface for testing purposes.

func NewDummyDA

func NewDummyDA(maxBlobSize uint64, gasPrice float64, gasMultiplier float64, blockTime time.Duration) *DummyDA

NewDummyDA creates a new instance of DummyDA with the specified maximum blob size and block time.

func (*DummyDA) Commit

func (d *DummyDA) Commit(ctx context.Context, blobs []Blob, namespace []byte) ([]Commitment, error)

Commit creates commitments for the given blobs.

func (*DummyDA) GasMultiplier

func (d *DummyDA) GasMultiplier(ctx context.Context) (float64, error)

GasMultiplier returns the gas multiplier for the DA layer.

func (*DummyDA) GasPrice

func (d *DummyDA) GasPrice(ctx context.Context) (float64, error)

GasPrice returns the gas price for the DA layer.

func (*DummyDA) Get

func (d *DummyDA) Get(ctx context.Context, ids []ID, namespace []byte) ([]Blob, error)

Get returns blobs for the given IDs.

func (*DummyDA) GetIDs

func (d *DummyDA) GetIDs(ctx context.Context, height uint64, namespace []byte) (*GetIDsResult, error)

GetIDs returns IDs of all blobs at the given height.

func (*DummyDA) GetProofs

func (d *DummyDA) GetProofs(ctx context.Context, ids []ID, namespace []byte) ([]Proof, error)

GetProofs returns proofs for the given IDs.

func (*DummyDA) SetSubmitFailure

func (d *DummyDA) SetSubmitFailure(shouldFail bool)

SetSubmitFailure simulates DA layer going down by making Submit calls fail

func (*DummyDA) StartHeightTicker

func (d *DummyDA) StartHeightTicker()

StartHeightTicker starts a goroutine that increments currentHeight every blockTime.

func (*DummyDA) StopHeightTicker

func (d *DummyDA) StopHeightTicker()

StopHeightTicker stops the height ticker goroutine.

func (*DummyDA) Submit

func (d *DummyDA) Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte) ([]ID, error)

Submit submits blobs to the DA layer.

func (*DummyDA) SubmitWithOptions

func (d *DummyDA) SubmitWithOptions(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte, options []byte) ([]ID, error)

SubmitWithOptions submits blobs to the DA layer with additional options.

func (*DummyDA) Validate

func (d *DummyDA) Validate(ctx context.Context, ids []ID, proofs []Proof, namespace []byte) ([]bool, error)

Validate validates commitments against proofs.

type GetIDsResult

type GetIDsResult struct {
	IDs       []ID
	Timestamp time.Time
}

GetIDsResult holds the result of GetIDs call: IDs and timestamp of corresponding block.

type ID

type ID = []byte

ID should contain serialized data required by the implementation to find blob in Data Availability layer.

type Namespace

type Namespace struct {
	Version uint8
	ID      [NamespaceIDSize]byte
}

Namespace represents a Celestia namespace

func NamespaceFromBytes

func NamespaceFromBytes(b []byte) (*Namespace, error)

NamespaceFromBytes creates a namespace from a 29-byte slice

func NamespaceFromString

func NamespaceFromString(s string) *Namespace

NamespaceFromString creates a version 0 namespace from a string identifier The string is hashed and the first 10 bytes of the hash are used as the namespace data

func NewNamespaceV0

func NewNamespaceV0(data []byte) (*Namespace, error)

NewNamespaceV0 creates a new version 0 namespace from the provided data The data should be up to 10 bytes and will be placed in the last 10 bytes of the ID The first 18 bytes will be zeros as required by the specification

func ParseHexNamespace

func ParseHexNamespace(hexStr string) (*Namespace, error)

ParseHexNamespace parses a hex string into a namespace

func (Namespace) Bytes

func (n Namespace) Bytes() []byte

Bytes returns the namespace as a byte slice

func (Namespace) HexString

func (n Namespace) HexString() string

HexString returns the hex representation of the namespace

func (Namespace) IsValidForVersion0

func (n Namespace) IsValidForVersion0() bool

IsValidForVersion0 checks if the namespace is valid for version 0 Version 0 requires the first 18 bytes of the ID to be zero

type Proof

type Proof = []byte

Proof should contain serialized proof of inclusion (publication) of Blob in Data Availability layer.

type ResultRetrieve

type ResultRetrieve struct {
	BaseResult
	// Data is the block data retrieved from Data Availability Layer.
	// If Code is not equal to StatusSuccess, it has to be nil.
	Data [][]byte
}

ResultRetrieveHeaders contains batch of block headers returned from DA layer client.

type ResultSubmit

type ResultSubmit struct {
	BaseResult
}

ResultSubmit contains information returned from DA layer after block headers/data submission.

type StatusCode

type StatusCode uint64

StatusCode is a type for DA layer return status. TODO: define an enum of different non-happy-path cases that might need to be handled by Evolve independent of the underlying DA chain.

const (
	StatusUnknown StatusCode = iota
	StatusSuccess
	StatusNotFound
	StatusNotIncludedInBlock
	StatusAlreadyInMempool
	StatusTooBig
	StatusContextDeadline
	StatusError
	StatusIncorrectAccountSequence
	StatusContextCanceled
	StatusHeightFromFuture
)

Data Availability return codes.

Jump to

Keyboard shortcuts

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