Documentation
¶
Overview ¶
Package syncer provides the read-only sync interface.
Index ¶
- Variables
- type GetPrefixesRequest
- type GetRequest
- type IterateRequest
- type Proof
- type ProofBuilder
- type ProofResponse
- type ProofVerifier
- type ReadSyncer
- type StatsCollector
- func (c *StatsCollector) SyncGet(ctx context.Context, request *GetRequest) (*ProofResponse, error)
- func (c *StatsCollector) SyncGetPrefixes(ctx context.Context, request *GetPrefixesRequest) (*ProofResponse, error)
- func (c *StatsCollector) SyncIterate(ctx context.Context, request *IterateRequest) (*ProofResponse, error)
- type SubtreeMerger
- type TreeID
Constants ¶
This section is empty.
Variables ¶
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") )
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 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) GetRoot ¶
func (b *ProofBuilder) GetRoot() hash.Hash
GetRoot returns the root hash for this proof.
func (*ProofBuilder) HasRoot ¶
func (b *ProofBuilder) HasRoot() bool
HasRoot returns true if the 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.
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 {
}
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.