Documentation
¶
Index ¶
- Constants
- Variables
- func PrepareNamespace(identifier []byte) []byte
- func SplitID(id []byte) (uint64, []byte, error)
- type BaseResult
- type Blob
- type Commitment
- type DA
- type DummyDA
- func (d *DummyDA) Commit(ctx context.Context, blobs []Blob, namespace []byte) ([]Commitment, error)
- func (d *DummyDA) GasMultiplier(ctx context.Context) (float64, error)
- func (d *DummyDA) GasPrice(ctx context.Context) (float64, error)
- func (d *DummyDA) Get(ctx context.Context, ids []ID, namespace []byte) ([]Blob, error)
- func (d *DummyDA) GetIDs(ctx context.Context, height uint64, namespace []byte) (*GetIDsResult, error)
- func (d *DummyDA) GetProofs(ctx context.Context, ids []ID, namespace []byte) ([]Proof, error)
- func (d *DummyDA) SetSubmitFailure(shouldFail bool)
- func (d *DummyDA) StartHeightTicker()
- func (d *DummyDA) StopHeightTicker()
- func (d *DummyDA) Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte) ([]ID, error)
- func (d *DummyDA) SubmitWithOptions(ctx context.Context, blobs []Blob, gasPrice float64, namespace []byte, ...) ([]ID, error)
- func (d *DummyDA) Validate(ctx context.Context, ids []ID, proofs []Proof, namespace []byte) ([]bool, error)
- type GetIDsResult
- type ID
- type Namespace
- type Proof
- type ResultRetrieve
- type ResultSubmit
- type StatusCode
Constants ¶
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 ¶
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") )
var ErrHeightFromFutureStr = fmt.Errorf("given height is from the future")
Functions ¶
func PrepareNamespace ¶
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
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 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) GasMultiplier ¶
GasMultiplier returns the gas multiplier for the DA layer.
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) SetSubmitFailure ¶
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.
type GetIDsResult ¶
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 ¶
NamespaceFromBytes creates a namespace from a 29-byte slice
func NamespaceFromString ¶
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 ¶
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 ¶
ParseHexNamespace parses a hex string into a namespace
func (Namespace) IsValidForVersion0 ¶
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.