remote

package
v0.51.1-payloadless-2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client implements ledger.Ledger interface using gRPC calls to a remote ledger service.

func NewClient

func NewClient(grpcAddr string, logger zerolog.Logger, opts ...ClientOption) (*Client, error)

NewClient creates a new remote ledger client. grpcAddr can be either a TCP address (e.g., "localhost:9000") or a Unix domain socket. For Unix sockets, you can use either the full gRPC format (e.g., "unix:///tmp/ledger.sock") or just the absolute path (e.g., "/tmp/ledger.sock") - the unix:// prefix will be added automatically. Options can be provided to customize the client configuration. By default, max request and response sizes are 1 GiB.

func (*Client) Close

func (c *Client) Close() error

Close closes the gRPC connection.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done returns a channel that is closed when the client is done. This cancels any in-flight gRPC calls and closes the connection. The method is idempotent - multiple calls return the same channel.

func (*Client) Get

func (c *Client) Get(query *ledger.Query) ([]ledger.Value, error)

Get returns values for multiple keys at a specific state.

func (*Client) GetSingleValue

func (c *Client) GetSingleValue(query *ledger.QuerySingleValue) (ledger.Value, error)

GetSingleValue returns a single value for a given key at a specific state.

func (*Client) HasState

func (c *Client) HasState(state ledger.State) (bool, error)

HasState returns true if the given state exists in the ledger.

A gRPC failure is surfaced to the caller rather than collapsed into a false return: false must mean "state genuinely absent", not "the server was unreachable", otherwise callers (e.g. execution state) would misreport a reachable state as pruned.

No error returns are expected during normal operation.

func (*Client) InitialState

func (c *Client) InitialState() ledger.State

InitialState returns the initial state of the ledger.

func (*Client) Prove

func (c *Client) Prove(query *ledger.Query) (ledger.Proof, error)

Prove returns proofs for the given keys at a specific state.

func (*Client) Ready

func (c *Client) Ready() <-chan struct{}

Ready returns a channel that is closed when the client is ready.

Readiness has two phases. First, this client waits for the ledger service to finish initialization by calling InitialState() with retries (the server may still be replaying its WAL). Second, after the service responds, the client calls LedgerInfoService.ServerInfo to verify the server is running in FULL mode. A mode mismatch is treated as a configuration error and crashes the process via log.Fatal — clients of a payloadless server must use PayloadlessClient, not Client.

func (*Client) Set

func (c *Client) Set(update *ledger.Update) (ledger.State, *ledger.TrieUpdate, error)

Set updates keys with new values at a specific state and returns the new state.

func (*Client) StateByIndex

func (c *Client) StateByIndex(index int) (ledger.State, error)

StateByIndex returns the state at the given index. -1 is the last index. This is not supported for remote clients as it requires gRPC methods that are not yet implemented.

func (*Client) StateCount

func (c *Client) StateCount() int

StateCount returns the number of states in the ledger. This is not supported for remote clients as it requires gRPC methods that are not yet implemented.

type ClientOption

type ClientOption func(*clientConfig)

ClientOption is a function that configures a Client.

func WithCallTimeout

func WithCallTimeout(timeout time.Duration) ClientOption

WithCallTimeout sets the timeout for individual gRPC calls.

func WithMaxRequestSize

func WithMaxRequestSize(size uint) ClientOption

WithMaxRequestSize sets the maximum request message size in bytes.

func WithMaxResponseSize

func WithMaxResponseSize(size uint) ClientOption

WithMaxResponseSize sets the maximum response message size in bytes.

type InfoService

type InfoService struct {
	ledgerpb.UnimplementedLedgerInfoServiceServer
	// contains filtered or unexported fields
}

InfoService implements the gRPC LedgerInfoService interface. It is registered on every ledger gRPC server, regardless of the server's mode, so clients can discover the mode of the server they connected to before issuing mode-specific RPCs.

InfoService is stateless and concurrency-safe.

func NewInfoService

func NewInfoService(mode ledgerpb.LedgerMode) *InfoService

NewInfoService creates a new info service that reports the given mode. Callers MUST pass either ledgerpb.LedgerMode_LEDGER_MODE_FULL or ledgerpb.LedgerMode_LEDGER_MODE_PAYLOADLESS; passing UNSPECIFIED produces a server that reports UNSPECIFIED, which clients will treat as a misconfigured server and refuse to use.

func (*InfoService) ServerInfo

ServerInfo returns the server's operating mode.

No error returns are expected during normal operation.

type PayloadlessClient

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

PayloadlessClient is a gRPC client for a payloadless ledger server. Reads return leaf hashes (HashLeaf(path, value)) rather than payload values.

PayloadlessClient mirrors Client in dial / retry / lifecycle behavior; the difference is the registered service it talks to and the leaf-hash return types on the read methods. Both clients share the same dial helper and the same mode-discovery check in Ready().

func NewPayloadlessClient

func NewPayloadlessClient(grpcAddr string, logger zerolog.Logger, opts ...ClientOption) (*PayloadlessClient, error)

NewPayloadlessClient creates a new payloadless remote ledger client.

`grpcAddr` accepts the same forms as NewClient. Connection-establishment retries are identical: ~40 minutes of exponential backoff before log.Fatal. Mode verification happens in [Ready] (not here) — a wrong-mode server will be detected the first time the caller waits on Ready().

func (*PayloadlessClient) Close

func (c *PayloadlessClient) Close() error

Close closes the gRPC connection.

func (*PayloadlessClient) Done

func (c *PayloadlessClient) Done() <-chan struct{}

Done returns a channel that is closed when the client is done. Idempotent.

func (*PayloadlessClient) GetLeafHashes

func (c *PayloadlessClient) GetLeafHashes(query *ledger.Query) ([]*hash.Hash, error)

GetLeafHashes returns leaf hashes for multiple keys at a specific state. A nil entry in the returned slice indicates an unallocated register.

Expected error returns during normal operation:

  • generic error wrapping the underlying gRPC failure when the call fails.

func (*PayloadlessClient) GetSingleLeafHash

func (c *PayloadlessClient) GetSingleLeafHash(query *ledger.QuerySingleValue) (*hash.Hash, error)

GetSingleLeafHash returns the leaf hash for a single key at a specific state. Returns nil if the key has no allocated register.

Expected error returns during normal operation:

  • generic error wrapping the underlying gRPC failure when the call fails.

func (*PayloadlessClient) HasPaths

func (c *PayloadlessClient) HasPaths(query *ledger.Query) ([]bool, error)

HasPaths reports, for each key in `query.Keys()`, whether the key has an allocated register at `query.State()`.

Expected error returns during normal operation:

  • generic error wrapping the underlying gRPC failure when the call fails.

func (*PayloadlessClient) HasState

func (c *PayloadlessClient) HasState(state ledger.State) (bool, error)

HasState returns true if the given state exists in the payloadless ledger.

A gRPC failure is surfaced to the caller rather than collapsed into a false return: false must mean "state genuinely absent", not "the server was unreachable", otherwise callers (e.g. execution state) would misreport a reachable state as pruned.

No error returns are expected during normal operation.

func (*PayloadlessClient) InitialState

func (c *PayloadlessClient) InitialState() ledger.State

InitialState returns the initial state of the payloadless ledger.

func (*PayloadlessClient) Prove

Prove returns a payloadless batch proof for the given keys at a specific state. The proof is decoded with ledger.DecodePayloadlessTrieBatchProof.

Expected error returns during normal operation:

  • generic error wrapping the underlying gRPC failure or a decode failure.

func (*PayloadlessClient) Ready

func (c *PayloadlessClient) Ready() <-chan struct{}

Ready returns a channel that is closed when the client is ready.

Readiness has two phases. First, the client waits for the ledger service to finish initialization by calling InitialState() with retries. Second, it calls LedgerInfoService.ServerInfo to verify the server is running in PAYLOADLESS mode. A mode mismatch is treated as a configuration error and crashes the process via log.Fatal — clients of a full server must use Client, not PayloadlessClient.

func (*PayloadlessClient) Set

Set updates keys with new values at a specific state and returns the new state plus the trie update that was applied.

Expected error returns during normal operation:

  • generic error wrapping the underlying gRPC failure when the call fails, or when the response is malformed.

type PayloadlessService

type PayloadlessService struct {
	ledgerpb.UnimplementedPayloadlessLedgerServiceServer
	// contains filtered or unexported fields
}

PayloadlessService implements the gRPC PayloadlessLedgerService interface on top of a ledger.PayloadlessLedger. Reads return leaf hashes rather than payload values.

A ledger gRPC server registers either Service (full mode) or PayloadlessService (payloadless mode), never both. The mode is chosen at startup config.

func NewPayloadlessService

func NewPayloadlessService(l ledger.PayloadlessLedger, logger zerolog.Logger) *PayloadlessService

NewPayloadlessService creates a new payloadless ledger gRPC service. In production the ledger argument is a *complete.PayloadlessLedger; tests may pass any value that satisfies ledger.PayloadlessLedger.

func (*PayloadlessService) GetLeafHashes

GetLeafHashes returns leaf hashes for multiple keys. Unallocated registers are reported as `LeafHash` entries with empty `hash` fields.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil or has the wrong length, or when `req.Keys` is empty.

func (*PayloadlessService) GetSingleLeafHash

GetSingleLeafHash returns the leaf hash for a single key. An unallocated register is reported as an empty `hash` field.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil or has the wrong length, or when `req.Key` is nil.

func (*PayloadlessService) HasPaths

HasPaths reports, for each key in `req.Keys`, whether the key has an allocated register at `req.State`.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil or has the wrong length, or when `req.Keys` is empty.

func (*PayloadlessService) HasState

HasState checks if the given state exists in the payloadless ledger.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil or has the wrong length.

func (*PayloadlessService) InitialState

InitialState returns the initial state of the payloadless ledger.

No error returns are expected during normal operation.

func (*PayloadlessService) Prove

Prove returns a payloadless batch proof for the given keys at a specific state. The proof is encoded with ledger.EncodePayloadlessTrieBatchProof.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil/wrong length or `req.Keys` is empty.

func (*PayloadlessService) Set

Set updates keys with new values at a specific state and returns the new state. The server discards the keys after hashing; only the values contribute to the trie.

Expected error returns during normal operation:

  • gRPC InvalidArgument: when `req.State` is nil/wrong length, keys are empty, or keys/values lengths mismatch.

type Service

type Service struct {
	ledgerpb.UnimplementedLedgerServiceServer
	// contains filtered or unexported fields
}

Service implements the gRPC LedgerService interface

func NewService

func NewService(l ledger.Ledger, logger zerolog.Logger) *Service

NewService creates a new ledger service

func (*Service) Get

Get returns values for multiple keys at a specific state

func (*Service) GetSingleValue

GetSingleValue returns a single value for a given key at a specific state

func (*Service) HasState

HasState checks if the given state exists in the ledger

func (*Service) InitialState

func (s *Service) InitialState(ctx context.Context, req *emptypb.Empty) (*ledgerpb.StateResponse, error)

InitialState returns the initial state of the ledger

func (*Service) Prove

Prove returns proofs for the given keys at a specific state

func (*Service) Set

Set updates keys with new values at a specific state and returns the new state

Jump to

Keyboard shortcuts

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