datasegment

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0, MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const BytesInInt = 8
View Source
const ChecksumSize = 16

Variables

View Source
var ErrValidation = validationError("unknown")

Functions

func ComputeDealPlacement

func ComputeDealPlacement(dealInfos []abi.PieceInfo) ([]merkletree.CommAndLoc, uint64, error)

ComputeDealPlacement takes in PieceInfos with Comm and Size, computes their placement in the tree and them in form of merkletree.CommAndLoc also returns number of bytes required and any errors

func DataSegmentIndexStartOffset

func DataSegmentIndexStartOffset(dealSize abi.PaddedPieceSize) uint64

DataSegmentIndexStartOffset takes in the padded size of the deal and returns the starting offset of data segment index in unpadded units.

func MakeSegDescs

func MakeSegDescs(segments []merkletree.Node, segmentSizes []uint64) ([]merkletree.Node, error)

func MaxIndexEntriesInDeal

func MaxIndexEntriesInDeal(dealSize abi.PaddedPieceSize) uint

MaxIndexEntriesInDeal defines the maximum number of index entries in for a given size of a deal

func SegmentRoot

func SegmentRoot(treeDepth int, segmentSize uint64, segmentOffset uint64) (int, uint64)

SegmentRoot computes the root of the client's segment's subtree treeDepth is the depth of the tree where the client segment is located segmentSize is the amount of leafs needed for the client's segment segmentOffset is the index of the first leaf where the client's segment starts. 0-indexed

func SerializeIndex

func SerializeIndex(index *IndexData) ([]byte, error)

SerializeIndex encodes a data segment Inclusion into a byte array, after validating that the structure is valid

Types

type Aggregate

type Aggregate struct {
	DealSize abi.PaddedPieceSize
	Index    IndexData
	Tree     merkletree.Hybrid
}

func NewAggregate

func NewAggregate(dealSize abi.PaddedPieceSize, subdeals []abi.PieceInfo) (*Aggregate, error)

NewAggregate creates the structure for verifiable deal aggregation based on target deal size and subdeals that should be included.

func (Aggregate) AggregateObjectReader

func (a Aggregate) AggregateObjectReader(subPieceReaders []io.Reader) (io.Reader, error)

AggregateStreamReader creates a reader for the whole aggregate, including the index. The subPieceReaders should be passed in the same order as subdeals in the construction call of the Aggregate. AggregateStreamReader assumes a non-manipulated Index as created by the Aggregate constructor.

func (Aggregate) IndexPieceCID

func (a Aggregate) IndexPieceCID() (cid.Cid, error)

IndexPieceCID returns the PieceCID of the index

func (Aggregate) IndexReader

func (a Aggregate) IndexReader() (io.Reader, error)

IndexReader returns a reader for the index containing unpadded bytes of the index

func (Aggregate) IndexSize

func (a Aggregate) IndexSize() (abi.PaddedPieceSize, error)

func (Aggregate) IndexStartPosition

func (a Aggregate) IndexStartPosition() (uint64, error)

IndexStartPosition returns the expected starting position where the index should be placed in the unpadded units

func (Aggregate) PieceCID

func (a Aggregate) PieceCID() (cid.Cid, error)

PieceCID returns the PieceCID of the deal containng all subdeals and the index

func (Aggregate) ProofForIndexEntry

func (a Aggregate) ProofForIndexEntry(idx int) (*InclusionProof, error)

ProofForIndexEntry gathers information required to produce an InclusionProof based on the index of data within the DataSegment Index.

func (Aggregate) ProofForPieceInfo

func (a Aggregate) ProofForPieceInfo(d abi.PieceInfo) (*InclusionProof, error)

ProofForPieceInfo searches for piece within the Aggregate based on PieceInfo and gathers all the information required to produce a proof.

type DataAggregationProof

type DataAggregationProof struct {
	Inclusion     InclusionProof
	AuxDataType   uint64 // always 0 for now
	AuxDataSource SingletonMarketSource
}

DataAggregationProof is the top level proof structure provided by the aggregator after the deal lands on chain.

func (DataAggregationProof) ComputeExpectedAuxData

func (dap DataAggregationProof) ComputeExpectedAuxData(verifierData InclusionVerifierData) (*InclusionAuxData, error)

ComputeExpectedAuxData exposes the raw AuxData computation from the proof for composability

func (*DataAggregationProof) MarshalCBOR

func (t *DataAggregationProof) MarshalCBOR(w io.Writer) error

func (*DataAggregationProof) UnmarshalCBOR

func (t *DataAggregationProof) UnmarshalCBOR(r io.Reader) (err error)

func (DataAggregationProof) VerifyActive

func (dap DataAggregationProof) VerifyActive(verifierData InclusionVerifierData, auxDataFetch MarketAuxDataFetch) error

VerifyActive is the primary entrypoint for the verification routine auxDataResolver is de-factor call to the Market actor to fetch the aux data

type InclusionAuxData

type InclusionAuxData struct {
	// Piece Commitment to aggregator's deal
	CommPa cid.Cid
	// SizePa is padded size of aggregator's deal
	SizePa abi.PaddedPieceSize
}

InclusionAuxData is required for verification of the proof and needs to be cross-checked with the chain state

func (*InclusionAuxData) MarshalCBOR

func (t *InclusionAuxData) MarshalCBOR(w io.Writer) error

func (*InclusionAuxData) UnmarshalCBOR

func (t *InclusionAuxData) UnmarshalCBOR(r io.Reader) (err error)

type InclusionProof

type InclusionProof struct {
	// ProofSubtree is proof of inclusion of the client's data segment in the data aggregator's Merkle tree (includes position information)
	// I.e. a proof that the root node of the subtree containing all the nodes (leafs) of a data segment is contained in CommDA
	ProofSubtree merkletree.ProofData
	// ProofIndex is a proof that an entry for the user's data is contained in the index of the aggregator's deal.
	// I.e. a proof that the data segment index constructed from the root of the user's data segment subtree is contained in the index of the deal tree.
	ProofIndex merkletree.ProofData
}

InclusionPoof is produced by the aggregator (or possibly by the SP)

func CollectInclusionProof

func CollectInclusionProof(ht *merkletree.Hybrid, dealSize abi.PaddedPieceSize, pieceInfo merkletree.CommAndLoc, indexEntry int) (*InclusionProof, error)

func (InclusionProof) ComputeExpectedAuxData

func (ip InclusionProof) ComputeExpectedAuxData(veriferData InclusionVerifierData) (*InclusionAuxData, error)

func (*InclusionProof) MarshalCBOR

func (t *InclusionProof) MarshalCBOR(w io.Writer) error

func (*InclusionProof) UnmarshalCBOR

func (t *InclusionProof) UnmarshalCBOR(r io.Reader) (err error)

type InclusionVerifierData

type InclusionVerifierData struct {
	// Piece Commitment to client's data
	CommPc cid.Cid
	// SizePc is size of client's data
	SizePc abi.PaddedPieceSize
}

InclusionVerifierData is the information required for verification of the proof and is sourced from the client.

func VerifierDataForPieceInfo

func VerifierDataForPieceInfo(pi abi.PieceInfo) InclusionVerifierData

VerifierDataForPieceInfo returns information provided by the verifier based on PieceInfo

func (*InclusionVerifierData) MarshalCBOR

func (t *InclusionVerifierData) MarshalCBOR(w io.Writer) error

func (*InclusionVerifierData) UnmarshalCBOR

func (t *InclusionVerifierData) UnmarshalCBOR(r io.Reader) (err error)

type IndexData

type IndexData struct {
	Entries []SegmentDesc
}

func MakeIndex

func MakeIndex(entries []SegmentDesc) (*IndexData, error)

func MakeIndexFromCommLoc

func MakeIndexFromCommLoc(dealInfos []merkletree.CommAndLoc) (*IndexData, error)

func ParseDataSegmentIndex

func ParseDataSegmentIndex(unpaddedReader io.Reader) (IndexData, error)

ParseDataSegmentIndex takes in a reader of of unppaded deal data, it should start at offset returned by DataSegmentIndexStartOffset After parsing use IndexData#ValidEntries() to gather valid data segments

func (IndexData) IndexSize

func (i IndexData) IndexSize() uint64

IndexSize returns the size of the index. Defined to be number of entries * 64 bytes

func (IndexData) MarshalBinary

func (id IndexData) MarshalBinary() (data []byte, err error)

func (*IndexData) MarshalCBOR

func (t *IndexData) MarshalCBOR(w io.Writer) error

adjusted encoder, allowing 2Mi entries in the Index

func (IndexData) NumberEntries

func (i IndexData) NumberEntries() int

NumberEntries returns the number of entries

func (IndexData) SegmentDesc

func (i IndexData) SegmentDesc(index int) *SegmentDesc

SegmentDesc returns the SegmentDesc in position of index. 0-indexed

func (*IndexData) UnmarshalBinary

func (id *IndexData) UnmarshalBinary(data []byte) error

func (*IndexData) UnmarshalCBOR

func (t *IndexData) UnmarshalCBOR(r io.Reader) (err error)

adjusted decoder, allowing 2Mi entries in the Index

func (IndexData) ValidEntries

func (id IndexData) ValidEntries() ([]SegmentDesc, error)

ValidEntries returns a slice of entries in the index which pass validation checks

func (IndexData) Validate

func (id IndexData) Validate() error

type SegmentDesc

type SegmentDesc struct {
	// Commitment to the data segment (Merkle node which is the root of the subtree containing all the nodes making up the data segment)
	CommDs merkletree.Node
	// Ofset is the offset from the start of the deal in padded bytes
	Offset uint64
	// Size is the number of padded bytes that is contained in the sub-deal reflected by this SegmentDesc
	Size uint64
	// Checksum is a 126 bit checksum (SHA256) computes on CommDs || Offset || Size
	Checksum [ChecksumSize]byte
}

SegmentDesc contains a data segment description to be contained as two Fr32 elements in 2 leaf nodes of the data segment index

func MakeDataSegmentIdx

func MakeDataSegmentIdx(commDs *fr32.Fr32, offset uint64, size uint64) (SegmentDesc, error)

func MakeDataSegmentIdxWithChecksum

func MakeDataSegmentIdxWithChecksum(commDs *fr32.Fr32, offset uint64, size uint64, checksum *[ChecksumSize]byte) (SegmentDesc, error)

func MakeDataSegmentIndexEntry

func MakeDataSegmentIndexEntry(CommP *fr32.Fr32, offset uint64, size uint64) (*SegmentDesc, error)

func (SegmentDesc) CommAndLoc

func (sd SegmentDesc) CommAndLoc() merkletree.CommAndLoc

func (SegmentDesc) IntoNodes

func (sd SegmentDesc) IntoNodes() [2]merkletree.Node

func (SegmentDesc) MakeNode

func (ds SegmentDesc) MakeNode() (merkletree.Node, merkletree.Node, error)

func (SegmentDesc) MarshalBinary

func (sd SegmentDesc) MarshalBinary() ([]byte, error)

func (*SegmentDesc) MarshalCBOR

func (t *SegmentDesc) MarshalCBOR(w io.Writer) error

func (SegmentDesc) PieceCID

func (sd SegmentDesc) PieceCID() cid.Cid

PieceCID returns the PieceCID of the sub-deal

func (SegmentDesc) SerializeFr32

func (sd SegmentDesc) SerializeFr32() []byte

func (SegmentDesc) SerializeFr32Into

func (sd SegmentDesc) SerializeFr32Into(slice []byte)

SerializeFr32Into serializes the Segment Desctipion into given slice Panics if len(slice) < EntrySize

func (*SegmentDesc) UnmarshalBinary

func (sd *SegmentDesc) UnmarshalBinary(data []byte) error

func (*SegmentDesc) UnmarshalCBOR

func (t *SegmentDesc) UnmarshalCBOR(r io.Reader) (err error)

func (SegmentDesc) UnpaddedLength

func (sd SegmentDesc) UnpaddedLength() uint64

UnpaddedLength returns unpadded length of the sub-deal

func (SegmentDesc) UnpaddedOffest

func (sd SegmentDesc) UnpaddedOffest() uint64

UnpaddedOffest returns unpadded offset of the sub-deal relative to the deal start

func (SegmentDesc) Validate

func (sd SegmentDesc) Validate() error

type SingletonMarketAuxData

type SingletonMarketAuxData struct {
	DealActive bool
	AuxData    InclusionAuxData
}

type SingletonMarketSource

type SingletonMarketSource struct {
	DealID abi.DealID
}

func (*SingletonMarketSource) MarshalCBOR

func (t *SingletonMarketSource) MarshalCBOR(w io.Writer) error

func (*SingletonMarketSource) UnmarshalCBOR

func (t *SingletonMarketSource) UnmarshalCBOR(r io.Reader) (err error)

Jump to

Keyboard shortcuts

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