shwap

package
v0.13.0-beta.9 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RowProofType is a sample proven via row root of the square.
	RowProofType = rsmt2d.Row
	// ColProofType is a sample proven via column root of the square.
	ColProofType = rsmt2d.Col
)
View Source
const DataIDSize = RowIDSize + share.NamespaceSize

DataIDSize is the size of the DataID in bytes.

View Source
const RowIDSize = 10

RowIDSize is the size of the RowID in bytes

View Source
const SampleIDSize = RowIDSize + 2

SampleIDSize is the size of the SampleID in bytes

Variables

This section is empty.

Functions

func NewBlockService

NewBlockService creates a new blockservice.BlockService with allowlist supporting the protocol.

Types

type BlockBuilder

type BlockBuilder interface {
	// TODO(@walldiss): don't like this name, but it collides with field name in RowID
	GetHeight() uint64
	BlockFromFile(ctx context.Context, file file.EdsFile) (blocks.Block, error)
}

BlockBuilder is an interface for building blocks from files.

func BlockBuilderFromCID

func BlockBuilderFromCID(cid cid.Cid) (BlockBuilder, error)

BlockBuilderFromCID returns a BlockBuilder from a CID. it acts as multiplexer for different block types.

type Data

type Data struct {
	DataID

	DataShares []share.Share
	DataProof  nmt.Proof
}

func DataFromBlock

func DataFromBlock(blk blocks.Block) (*Data, error)

DataFromBlock converts blocks.Block into Data.

func NewData

func NewData(id DataID, shares []share.Share, proof nmt.Proof) *Data

NewData constructs a new Data.

func NewDataFromEDS

func NewDataFromEDS(
	square *rsmt2d.ExtendedDataSquare,
	height uint64,
	namespace share.Namespace,
) ([]*Data, error)

NewDataFromEDS samples the EDS and constructs Data for each row with the given namespace.

func (*Data) IPLDBlock

func (s *Data) IPLDBlock() (blocks.Block, error)

IPLDBlock converts Data to an IPLD block for Bitswap compatibility.

func (*Data) MarshalBinary

func (s *Data) MarshalBinary() ([]byte, error)

MarshalBinary marshals Data to binary.

func (*Data) UnmarshalBinary

func (s *Data) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshal Data from binary.

func (*Data) Verify

func (s *Data) Verify(root *share.Root) error

Verify validates Data's fields and verifies Data inclusion.

type DataHasher

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

DataHasher implements hash.Hash interface for Data.

func (*DataHasher) BlockSize

func (h *DataHasher) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*DataHasher) Reset

func (h *DataHasher) Reset()

Reset resets the Hash to its initial state.

func (*DataHasher) Size

func (h *DataHasher) Size() int

Size returns the number of bytes Sum will return.

func (*DataHasher) Sum

func (h *DataHasher) Sum([]byte) []byte

Sum returns the "multihash" of the DataID.

func (*DataHasher) Write

func (h *DataHasher) Write(data []byte) (int, error)

Write expects a marshaled Data to validate.

type DataID

type DataID struct {
	// TODO(@walldiss): why embed instead of just having a field?
	RowID

	// DataNamespace is the namespace of the data
	// It's string formatted to keep DataID comparable
	DataNamespace string
}

DataID is an unique identifier of a namespaced Data inside EDS Row.

func DataIDFromCID

func DataIDFromCID(cid cid.Cid) (id DataID, err error)

DataIDFromCID coverts CID to DataID.

func NewDataID

func NewDataID(height uint64, rowIdx uint16, namespace share.Namespace, root *share.Root) (DataID, error)

NewDataID constructs a new DataID.

func (DataID) BlockFromFile

func (s DataID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error)

func (DataID) Cid

func (s DataID) Cid() cid.Cid

Cid returns DataID encoded as CID.

func (DataID) GetHeight

func (s DataID) GetHeight() uint64

func (DataID) MarshalBinary

func (s DataID) MarshalBinary() ([]byte, error)

MarshalBinary encodes DataID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (DataID) Namespace

func (s DataID) Namespace() share.Namespace

Namespace returns the namespace of the DataID.

func (*DataID) UnmarshalBinary

func (s *DataID) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes DataID from binary form.

func (DataID) Verify

func (s DataID) Verify(root *share.Root) error

Verify verifies DataID fields.

type Getter

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

TODO: GetRow method

func NewGetter

func NewGetter(fetch exchange.SessionExchange, bstore blockstore.Blockstore) *Getter

func (*Getter) GetEDS

GetEDS TODO(@Wondertan): Consider requesting randomized rows instead of ODS only

func (*Getter) GetShare

func (g *Getter) GetShare(ctx context.Context, header *header.ExtendedHeader, row, col int) (share.Share, error)

func (*Getter) GetShares

func (g *Getter) GetShares(ctx context.Context, hdr *header.ExtendedHeader, smplIdxs ...int) ([]share.Share, error)

TODO: Make GetSamples so it provides proofs to users. GetShares fetches in the Block/EDS by their indexes. Automatically caches them on the Blockstore. Guarantee that the returned shares are in the same order as shrIdxs.

func (*Getter) GetSharesByNamespace

func (g *Getter) GetSharesByNamespace(
	ctx context.Context,
	hdr *header.ExtendedHeader,
	ns share.Namespace,
) (share.NamespacedShares, error)

type Row

type Row struct {
	RowID

	// RowShares is the original non erasure-coded half of the Row.
	RowShares []share.Share
}

Row represents a Row of an EDS.

func NewRow

func NewRow(id RowID, axisHalf []share.Share) *Row

NewRow constructs a new Row.

func NewRowFromEDS

func NewRowFromEDS(
	height uint64,
	rowIdx int,
	square *rsmt2d.ExtendedDataSquare,
) (*Row, error)

NewRowFromEDS constructs a new Row from the given EDS.

func RowFromBlock

func RowFromBlock(blk blocks.Block) (*Row, error)

RowFromBlock converts blocks.Block into Row.

func (*Row) IPLDBlock

func (r *Row) IPLDBlock() (blocks.Block, error)

IPLDBlock converts Row to an IPLD block for Bitswap compatibility.

func (*Row) MarshalBinary

func (r *Row) MarshalBinary() ([]byte, error)

MarshalBinary marshals Row to binary.

func (*Row) UnmarshalBinary

func (r *Row) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshal Row from binary.

func (*Row) Verify

func (r *Row) Verify(root *share.Root) error

Verify validates Row's fields and verifies Row inclusion.

type RowHasher

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

RowHasher implements hash.Hash interface for Row.

func (*RowHasher) BlockSize

func (h *RowHasher) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*RowHasher) Reset

func (h *RowHasher) Reset()

Reset resets the Hash to its initial state.

func (*RowHasher) Size

func (h *RowHasher) Size() int

Size returns the number of bytes Sum will return.

func (*RowHasher) Sum

func (h *RowHasher) Sum([]byte) []byte

Sum returns the "multihash" of the RowID.

func (*RowHasher) Write

func (h *RowHasher) Write(data []byte) (int, error)

Write expects a marshaled Row to validate.

type RowID

type RowID struct {
	// Height of the block.
	// Needed to identify block's data square in the whole chain
	Height uint64
	// RowIndex is the index of the axis(row, col) in the data square
	RowIndex uint16
}

RowID is an unique identifier of a Row.

func NewRowID

func NewRowID(height uint64, rowIdx uint16, root *share.Root) (RowID, error)

NewRowID constructs a new RowID.

func RowIDFromCID

func RowIDFromCID(cid cid.Cid) (id RowID, err error)

RowIDFromCID coverts CID to RowID.

func (RowID) BlockFromFile

func (rid RowID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error)

func (RowID) Cid

func (rid RowID) Cid() cid.Cid

Cid returns RowID encoded as CID.

func (RowID) GetHeight

func (rid RowID) GetHeight() uint64

func (RowID) MarshalBinary

func (rid RowID) MarshalBinary() ([]byte, error)

MarshalBinary encodes RowID into binary form.

func (RowID) MarshalTo

func (rid RowID) MarshalTo(data []byte) (int, error)

MarshalTo encodes RowID into given byte slice. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*RowID) UnmarshalBinary

func (rid *RowID) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes RowID from binary form.

func (*RowID) UnmarshalFrom

func (rid *RowID) UnmarshalFrom(data []byte) (int, error)

UnmarshalFrom decodes RowID from given byte slice.

func (RowID) Verify

func (rid RowID) Verify(root *share.Root) error

Verify verifies RowID fields.

type Sample

type Sample struct {
	SampleID

	// SampleProofType of the Sample
	SampleProofType SampleProofType
	// SampleProof of SampleShare inclusion in the NMT
	SampleProof nmt.Proof
	// SampleShare is a share being sampled
	SampleShare share.Share
}

Sample represents a sample of an NMT in EDS.

func NewSample

func NewSample(id SampleID, shr share.Share, proof nmt.Proof, proofTp SampleProofType) *Sample

NewSample constructs a new Sample.

func NewSampleFromEDS

func NewSampleFromEDS(
	proofType SampleProofType,
	smplIdx int,
	square *rsmt2d.ExtendedDataSquare,
	height uint64,
) (*Sample, error)

NewSampleFromEDS samples the EDS and constructs a new row-proven Sample.

func SampleFromBlock

func SampleFromBlock(blk blocks.Block) (*Sample, error)

SampleFromBlock converts blocks.Block into Sample.

func (*Sample) IPLDBlock

func (s *Sample) IPLDBlock() (blocks.Block, error)

IPLDBlock converts Sample to an IPLD block for Bitswap compatibility.

func (*Sample) MarshalBinary

func (s *Sample) MarshalBinary() ([]byte, error)

MarshalBinary marshals Sample to binary.

func (*Sample) UnmarshalBinary

func (s *Sample) UnmarshalBinary(data []byte) error

UnmarshalBinary unmarshal Sample from binary.

func (*Sample) Verify

func (s *Sample) Verify(root *share.Root) error

Verify validates Sample's fields and verifies SampleShare inclusion.

type SampleHasher

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

SampleHasher implements hash.Hash interface for Sample.

func (*SampleHasher) BlockSize

func (h *SampleHasher) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*SampleHasher) Reset

func (h *SampleHasher) Reset()

Reset resets the Hash to its initial state.

func (*SampleHasher) Size

func (h *SampleHasher) Size() int

Size returns the number of bytes Sum will return.

func (*SampleHasher) Sum

func (h *SampleHasher) Sum([]byte) []byte

Sum returns the "multihash" of the SampleID.

func (*SampleHasher) Write

func (h *SampleHasher) Write(data []byte) (int, error)

Write expects a marshaled Sample to validate.

type SampleID

type SampleID struct {
	// TODO(@walldiss): why embed instead of just having a field?
	RowID

	// ShareIndex is the index of the sampled share in the Row
	ShareIndex uint16
}

SampleID is an unique identifier of a Sample.

func NewSampleID

func NewSampleID(height uint64, smplIdx int, root *share.Root) (SampleID, error)

NewSampleID constructs a new SampleID.

func SampleIDFromCID

func SampleIDFromCID(cid cid.Cid) (id SampleID, err error)

SampleIDFromCID coverts CID to SampleID.

func (SampleID) BlockFromFile

func (sid SampleID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error)

func (SampleID) Cid

func (sid SampleID) Cid() cid.Cid

Cid returns SampleID encoded as CID.

func (SampleID) GetHeight

func (sid SampleID) GetHeight() uint64

func (SampleID) MarshalBinary

func (sid SampleID) MarshalBinary() ([]byte, error)

MarshalBinary encodes SampleID into binary form. NOTE: Proto is avoided because * Its size is not deterministic which is required for IPLD. * No support for uint16

func (*SampleID) UnmarshalBinary

func (sid *SampleID) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes SampleID from binary form.

func (SampleID) Verify

func (sid SampleID) Verify(root *share.Root) error

Verify verifies SampleID fields.

type SampleProofType

type SampleProofType = rsmt2d.Axis

SampleProofType is either row or column proven Sample.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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