rpcdb

package
v1.26.26 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package rpcdb is luxd's canonical Layer C home for the rpcdb service: one Service implementation backed by a database.Database, with a transport adapter per supported wire protocol.

Layered topology:

Layer A — wire framing                   (github.com/luxfi/api/zap)
Layer B — service spec (data carriers)   (github.com/luxfi/proto/rpcdb)
Layer C — service impl + transports      (this package)

One Service. Many transport adapters. Adding a new transport is a new file that wraps `*Service`; the storage logic stays here and stays orthogonal to framing concerns.

Files:

  • service.go (this) — transport-neutral Service struct + methods
  • grpc_server.go (build tag `grpc`) — gRPC adapter
  • zap_server.go (default) — ZAP adapter

Index

Constants

View Source
const (
	MsgDBHas             zapwire.MessageType = 1
	MsgDBGet             zapwire.MessageType = 2
	MsgDBPut             zapwire.MessageType = 3
	MsgDBDelete          zapwire.MessageType = 4
	MsgDBWriteBatch      zapwire.MessageType = 5
	MsgDBCompact         zapwire.MessageType = 6
	MsgDBClose           zapwire.MessageType = 7
	MsgDBHealthCheck     zapwire.MessageType = 8
	MsgDBIteratorNew     zapwire.MessageType = 9
	MsgDBIteratorNext    zapwire.MessageType = 10
	MsgDBIteratorError   zapwire.MessageType = 11
	MsgDBIteratorRelease zapwire.MessageType = 12
)

ZAP db channel MsgType IDs. These are the wire-level Layer-A dispatch tags for the rpcdb service over ZAP. They live in their own listener (one per VM plugin); they do NOT collide with the VM lifecycle MsgTypes (1..31) or sender (40..49) or warp (50..59) because each listener has its own dispatch table.

Order is the canonical Lane A assignment — the cevm side hard-codes these numbers in `RemoteZapDB::call`. Do not reorder.

Variables

This section is empty.

Functions

func CodeToErr added in v1.26.26

func CodeToErr(code rpcdb.Error) error

CodeToErr maps a wire-typed Error back to a database sentinel. Used by remote clients on the receive side; lives here so server and client agree on the inverse of errToCode.

Types

type Service added in v1.26.26

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

Service is the rpcdb service implementation. It holds one `database.Database` and a server-managed iterator pool, and exposes every rpcdb operation as a (request → response) method on Go data carriers from the proto/rpcdb wire-types package.

Service is transport-agnostic: it knows nothing about gRPC, ZAP, or any other framing. Each transport adapter wraps `*Service` and translates its own wire format into these method calls.

func NewService added in v1.26.26

func NewService(db database.Database) *Service

NewService wraps `db` so it can be served over any transport.

func (*Service) Close added in v1.26.26

Close services rpcdb.Close.

func (*Service) CloseIterators added in v1.26.26

func (s *Service) CloseIterators()

CloseIterators releases every server-side iterator. Adapters call this on shutdown so iterators don't leak past the listener.

func (*Service) Compact added in v1.26.26

Compact services rpcdb.Compact.

func (*Service) DB added in v1.26.26

func (s *Service) DB() database.Database

DB returns the underlying database. Adapters that need to surface transport-specific behavior (eg. health-check serialization) can reach in for it; everyone else uses the methods.

func (*Service) Delete added in v1.26.26

Delete services rpcdb.Delete.

func (*Service) Get added in v1.26.26

Get services rpcdb.Get.

func (*Service) Has added in v1.26.26

Has services rpcdb.Has.

func (*Service) HealthCheck added in v1.26.26

func (s *Service) HealthCheck(ctx context.Context) (*rpcdb.HealthCheckResponse, error)

HealthCheck services rpcdb.HealthCheck.

func (*Service) IteratorError added in v1.26.26

IteratorError services rpcdb.IteratorError.

func (*Service) IteratorNext added in v1.26.26

IteratorNext services rpcdb.IteratorNext, returning up to iterationBatchBytes worth of (key, value) pairs per call. An empty Data slice signals exhaustion.

Returned bytes are deep-copied so the caller can hold them past the next iterator advance; the underlying database.Iterator is allowed to recycle its internal buffers.

func (*Service) IteratorRelease added in v1.26.26

IteratorRelease services rpcdb.IteratorRelease. Idempotent: calling it twice for the same id returns UNSPECIFIED on the second call.

func (*Service) NewIteratorWithStartAndPrefix added in v1.26.26

NewIteratorWithStartAndPrefix services rpcdb.NewIteratorWithStartAndPrefix.

func (*Service) Put added in v1.26.26

Put services rpcdb.Put.

func (*Service) WriteBatch added in v1.26.26

WriteBatch services rpcdb.WriteBatch.

type ZAPServer added in v1.26.26

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

ZAPServer is the ZAP transport adapter for the rpcdb Service. It owns the listener and the dispatch loop; the actual storage logic lives in *Service. To swap the wire format (eg. to add framing over a different reliable byte stream) write a new file with a new adapter — never edit Service.

func NewZAPServer added in v1.26.26

func NewZAPServer(db database.Database) *ZAPServer

NewZAPServer wraps a database.Database for serving over ZAP.

Equivalent to NewZAPServerFromService(NewService(db)) — kept as a one-liner because cevm-side test fixtures and the production rpcchainvm/zap path both build it this way.

func NewZAPServerFromService added in v1.26.26

func NewZAPServerFromService(svc *Service) *ZAPServer

NewZAPServerFromService wraps an existing Service for serving over ZAP. Useful when a single Service needs multiple transport adapters at once (eg. tests that want both ZAP and direct in-process calls).

func (*ZAPServer) Addr added in v1.26.26

func (s *ZAPServer) Addr() net.Addr

Addr returns the bound address (or nil if not yet listening).

func (*ZAPServer) Close added in v1.26.26

func (s *ZAPServer) Close() error

Close releases all iterators and closes the listener. Caller is expected to also cancel the context passed to Serve so the accept loop exits cleanly. Safe to call multiple times.

We deliberately do NOT call s.server.Close() because the upstream zapwire.Server.Close races with in-flight accept (it nils its conns map mid-Serve, causing "assignment to entry in nil map"). Closing the listener is enough to make Accept return; ctx cancellation does the rest.

func (*ZAPServer) Listen added in v1.26.26

func (s *ZAPServer) Listen(addr string) error

Listen binds the ZAP listener to addr.

func (*ZAPServer) ListenOn added in v1.26.26

func (s *ZAPServer) ListenOn(raw net.Listener)

ListenOn wraps an existing net.Listener (for ephemeral ports etc.).

func (*ZAPServer) Serve added in v1.26.26

func (s *ZAPServer) Serve(ctx context.Context) error

Serve blocks until ctx is cancelled or Close is called.

Jump to

Keyboard shortcuts

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