syncer

package
v0.2201.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package syncer provides the read-only sync interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDirtyRoot is the error returned when a ReadSyncer tries to sync from a
	// tree with a dirty root (e.g., a root with local modifications).
	ErrDirtyRoot = errors.New("mkvs: root is dirty")
	// ErrInvalidRoot is the error returned when a ReadSyncer tries to sync from a
	// tree with a different root.
	ErrInvalidRoot = errors.New("mkvs: invalid root")
	// ErrUnsupported is the error returned when a ReadSyncer method is not supported.
	ErrUnsupported = errors.New("mkvs: method not supported")
)
View Source
var NopReadSyncer = &nopReadSyncer{}

NopReadSyncer is a no-op read syncer.

Functions

This section is empty.

Types

type GetPrefixesRequest

type GetPrefixesRequest struct {
	Tree     TreeID   `json:"tree"`
	Prefixes [][]byte `json:"prefixes"`
	Limit    uint16   `json:"limit"`
}

GetPrefixesRequest is a request for the SyncGetPrefixes operation.

type GetRequest

type GetRequest struct {
	Tree            TreeID `json:"tree"`
	Key             []byte `json:"key"`
	IncludeSiblings bool   `json:"include_siblings,omitempty"`
}

GetRequest is a request for the SyncGet operation.

type IterateRequest

type IterateRequest struct {
	Tree     TreeID `json:"tree"`
	Key      []byte `json:"key"`
	Prefetch uint16 `json:"prefetch"`
}

IterateRequest is a request for the SyncIterate operation.

type Proof

type Proof struct {
	// UntrustedRoot is the root hash this proof is for. This should only be
	// used as a quick sanity check and proof verification MUST use an
	// independently obtained root hash as the prover can provide any root.
	UntrustedRoot hash.Hash `json:"untrusted_root"`
	// Entries are the proof entries in pre-order traversal.
	Entries [][]byte `json:"entries"`
}

Proof is a Merkle proof for a subtree.

type ProofBuilder

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

ProofBuilder is a Merkle proof builder.

func NewProofBuilder

func NewProofBuilder(root, subtree hash.Hash) *ProofBuilder

NewProofBuilder creates a new Merkle proof builder for the given root.

func (*ProofBuilder) Build

func (b *ProofBuilder) Build(ctx context.Context) (*Proof, error)

Build tries to build the proof.

func (*ProofBuilder) GetSubtreeRoot added in v0.2100.0

func (b *ProofBuilder) GetSubtreeRoot() hash.Hash

GetSubtree returns the subtree root hash for this proof.

func (*ProofBuilder) HasSubtreeRoot added in v0.2100.0

func (b *ProofBuilder) HasSubtreeRoot() bool

HasSubtree returns true if the subtree root node has already been included.

func (*ProofBuilder) Include

func (b *ProofBuilder) Include(n node.Node)

Include adds a node to the set of included nodes.

The node must be clean.

func (*ProofBuilder) Size

func (b *ProofBuilder) Size() uint64

Size returns the current size of this proof.

type ProofResponse

type ProofResponse struct {
	Proof Proof `json:"proof"`
}

ProofResponse is a response for requests that produce proofs.

type ProofVerifier

type ProofVerifier struct{}

ProofVerifier enables verifying proofs returned by the ReadSyncer API.

func (*ProofVerifier) VerifyProof

func (pv *ProofVerifier) VerifyProof(ctx context.Context, root hash.Hash, proof *Proof) (*node.Pointer, error)

VerifyProof verifies a proof and generates an in-memory subtree representing the nodes which are included in the proof.

type ReadSyncer

type ReadSyncer interface {
	// SyncGet fetches a single key and returns the corresponding proof.
	SyncGet(ctx context.Context, request *GetRequest) (*ProofResponse, error)

	// SyncGetPrefixes fetches all keys under the given prefixes and returns
	// the corresponding proofs.
	SyncGetPrefixes(ctx context.Context, request *GetPrefixesRequest) (*ProofResponse, error)

	// SyncIterate seeks to a given key and then fetches the specified
	// number of following items based on key iteration order.
	SyncIterate(ctx context.Context, request *IterateRequest) (*ProofResponse, error)
}

ReadSyncer is the interface for synchronizing the in-memory cache with another (potentially untrusted) MKVS.

type StatsCollector

type StatsCollector struct {
	SyncGetCount         int
	SyncGetPrefixesCount int
	SyncIterateCount     int
	// contains filtered or unexported fields
}

StatsCollector is a ReadSyncer which collects call statistics.

func NewStatsCollector

func NewStatsCollector(rs ReadSyncer) *StatsCollector

NewnopReadSyncer creates a new no-op read syncer.

func (*StatsCollector) SyncGet

func (c *StatsCollector) SyncGet(ctx context.Context, request *GetRequest) (*ProofResponse, error)

func (*StatsCollector) SyncGetPrefixes

func (c *StatsCollector) SyncGetPrefixes(ctx context.Context, request *GetPrefixesRequest) (*ProofResponse, error)

func (*StatsCollector) SyncIterate

func (c *StatsCollector) SyncIterate(ctx context.Context, request *IterateRequest) (*ProofResponse, error)

type SubtreeMerger

type SubtreeMerger struct{}

func (*SubtreeMerger) MergeVerifiedSubtree

func (m *SubtreeMerger) MergeVerifiedSubtree(
	ctx context.Context,
	dst *node.Pointer,
	subtree *node.Pointer,
	committer func(*node.Pointer) error,
) error

MergeVerifiedSubtree merges a previously verified subtree with an existing tree.

type TreeID

type TreeID struct {
	// Root is the Merkle tree root.
	Root node.Root `json:"root"`
	// Position is the caller's position in the tree structure to allow
	// returning partial proofs if possible.
	Position hash.Hash `json:"position"`
}

TreeID identifies a specific tree and a position within that tree.

Jump to

Keyboard shortcuts

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