utxorpc

package
v0.82.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 58 Imported by: 0

Documentation

Overview

Package utxorpc implements Dingo's UTxO RPC server, serving the utxorpc.v1alpha and utxorpc.v1beta gRPC APIs defined by the UTxO RPC spec.

The Utxorpc type is a gRPC server that translates incoming requests into queries against the ledger and mempool packages and streams results back to clients. It is only started when the node runs in "api" storage mode and DINGO_PLUGINS_API_UTXORPC_CONFIG_PORT is non-zero — "core" mode nodes do not index the data required to answer query requests.

Predicate evaluation

SearchUtxos uses UtxoPredicate filters over live UTxOs. Exact addresses are compared by complete output address bytes, while payment/delegation parts are credential-scoped; a nil SearchUtxos predicate scans all addresses. TxPredicate evaluation for transaction streams uses composite operators (not / all_of / any_of) around leaf predicates (address, policy, certificate, consumes, produces, …). That path is stricter: evalTxPredicateOutcome returns predNoMatch for a nil converted TxPredicate node.

Authentication

This server does not authenticate clients. Authentication, rate limiting, and TLS termination are expected to be handled by a reverse proxy or API gateway in front of the node. Do not add auth middleware here — keep the node itself transport-neutral.

Index

Constants

View Source
const (
	DefaultMaxStreams          = 1000
	DefaultMaxStreamsPerClient = 20
	DefaultMaxPredicateNodes   = 1000
	DefaultMaxReplayBlocks     = 10000
)

Defaults for the long-lived stream bounds on UtxorpcConfig.

View Source
const (
	DefaultMaxBlockRefs    = 100
	DefaultMaxUtxoKeys     = 1000
	DefaultMaxHistoryItems = 10000
	// DefaultHistoryPageItems is the DumpHistory page size when the request
	// omits max_items; it stays well below DefaultMaxHistoryItems so an
	// anonymous request without a limit cannot buffer the full maximum.
	DefaultHistoryPageItems = 100
	// DefaultMaxHistoryBytes bounds the serialized block data collected for
	// one DumpHistory response.
	DefaultMaxHistoryBytes = 8 << 20
	DefaultMaxDataKeys     = 1000
	DefaultMaxTxRefs       = 1000
	// DefaultMaxRequestBody bounds each Connect message before it is decoded.
	// Connect applies the same limit to the compressed wire
	// message and to its decompressed form, preventing a small compressed body
	// from expanding without bound during unary request decoding.
	DefaultMaxRequestBody = 1 << 20 // 1 MiB
	// DefaultMaxPoolFilter caps ReadState's pool_keyhashes filter. Matching
	// the other key-list caps: a caller wanting every pool sends an empty
	// filter, so a long explicit list is not the way to ask for the whole
	// distribution.
	DefaultMaxPoolFilter = 1000
	// DefaultMaxMempoolItems caps the transactions ReadMempool returns.
	DefaultMaxMempoolItems = 1000
	// DefaultMaxResponseBytes caps the payload a single unary bulk response
	// retains (UTxO, datum, block and mempool bodies).
	DefaultMaxResponseBytes = 16 << 20 // 16 MiB
	// DefaultMaxConcurrentBulkRequests caps how many bulk read handlers run
	// at once; further requests are refused with ResourceExhausted.
	DefaultMaxConcurrentBulkRequests = 32
	// DefaultBulkResponseWriteTimeout bounds delivery of a bulk unary
	// response without imposing a deadline on streaming RPCs.
	DefaultBulkResponseWriteTimeout = 30 * time.Second
	DefaultServerTimeout            = time.Hour
	// DefaultShutdownTimeout bounds Stop's graceful http.Server.Shutdown
	// before it escalates to a hard Close, matching midnight/server's
	// identical ShutdownTimeout/defaultShutdownTimeout pattern.
	DefaultShutdownTimeout = 30 * time.Second
)

Default request size limits to prevent denial-of-service via unbounded request arrays.

Variables

View Source
var ErrByronProtocolParams = errors.New(
	"protocol parameters unavailable in the Byron era",
)

ErrByronProtocolParams reports that the ledger holds no current protocol parameters because the chain is still in its Byron prefix. Byron carries no protocol-parameter CBOR, so this is an expected state during a from-genesis synchronization rather than a node fault, and no Shelley-shaped parameters may be substituted for it.

Functions

func RegisterProvider added in v0.68.0

func RegisterProvider(host *plugin.Host) error

Types

type ProviderConfig added in v0.68.0

type ProviderConfig struct {
	Port uint                `yaml:"port"`
	TLS  apiconfig.TLSPolicy `yaml:"tls"`
}

type ProviderDependencies added in v0.68.0

type ProviderDependencies struct {
	Logger             *slog.Logger
	EventBus           UtxorpcEventBus
	LedgerState        UtxorpcLedgerState
	Mempool            UtxorpcMempool
	Host               string
	CORSAllowedOrigins []string
}

type Utxorpc

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

func NewUtxorpc

func NewUtxorpc(cfg UtxorpcConfig) *Utxorpc

func (*Utxorpc) Start

func (u *Utxorpc) Start(ctx context.Context) error

func (*Utxorpc) Stop

func (u *Utxorpc) Stop(ctx context.Context) error

Stop shuts down the server and does not return until the listening socket has been released, so a capability restart on the same port can rebind -- see internal/apilistener.

type UtxorpcConfig

type UtxorpcConfig struct {
	Logger      *slog.Logger
	EventBus    UtxorpcEventBus
	LedgerState UtxorpcLedgerState
	Mempool     UtxorpcMempool
	TLS         apiconfig.EffectiveTLS
	Host        string
	Port        uint

	// Request size limits (0 = use default)
	MaxBlockRefs int
	MaxUtxoKeys  int
	// MaxHistoryItems caps DumpHistory and SearchUtxos page size; omitted
	// max_items uses this cap.
	MaxHistoryItems int
	// HistoryPageItems is the DumpHistory page size used when max_items is
	// omitted (0 = use default, capped at MaxHistoryItems).
	HistoryPageItems int
	// MaxHistoryBytes caps the serialized block bytes in one DumpHistory
	// response; a longer page is cut short and continues from next_token
	// (0 = use default).
	MaxHistoryBytes int
	MaxDataKeys     int
	// MaxTxRefs caps the transaction references in one WaitForTx
	// request (0 = use default).
	MaxTxRefs int
	// MaxStreams caps concurrent FollowTip, WatchTx, WatchMempool and WaitForTx streams
	// across all clients; MaxStreamsPerClient caps them per remote host
	// (0 = use default).
	MaxStreams          int
	MaxStreamsPerClient int
	// MaxPredicateNodes caps the total nodes of a watch predicate
	// (0 = use default).
	MaxPredicateNodes int
	// MaxReplayBlocks caps how far behind the tip a WatchTx intersect may
	// start, in blocks (0 = use default).
	MaxReplayBlocks int
	// MaxPoolFilter caps ReadState's pool_keyhashes filter length.
	MaxPoolFilter int
	// MaxMempoolItems caps ReadMempool's result size (0 = use default).
	MaxMempoolItems int
	// MaxResponseBytes caps the payload bytes one bulk read response may
	// retain (0 = use default).
	MaxResponseBytes int64
	// MaxConcurrentBulkRequests caps concurrently running bulk read handlers
	// (0 = use default).
	MaxConcurrentBulkRequests int
	// BulkResponseWriteTimeout bounds delivery of a bulk unary response
	// (0 = use default).
	BulkResponseWriteTimeout time.Duration
	// ServerTimeout bounds long-running UTxO RPC handlers server-side
	// (0 = use default).
	ServerTimeout time.Duration
	// ShutdownTimeout bounds Stop's graceful http.Server.Shutdown before it
	// escalates to a hard Close (0 = use default). Watch* RPCs are
	// unbounded streams, so a connected client can otherwise keep
	// Shutdown blocked indefinitely.
	ShutdownTimeout time.Duration
	// CORSAllowedOrigins configures Access-Control-Allow-Origin.
	// Empty disables CORS.
	CORSAllowedOrigins []string
}

type UtxorpcEventBus added in v0.55.0

type UtxorpcEventBus interface {
	SubscribeFunc(
		eventType event.EventType,
		handlerFunc event.EventHandlerFunc,
	) event.EventSubscriberId
	Unsubscribe(eventType event.EventType, subId event.EventSubscriberId)
	UnsubscribeAndWait(eventType event.EventType, subId event.EventSubscriberId)
}

UtxorpcEventBus is the subset of event.EventBus needed by the UTxO RPC server.

type UtxorpcLedgerState added in v0.55.0

type UtxorpcLedgerState interface {
	BlockByHash(ctx context.Context, hash []byte) (models.Block, error)
	CardanoNodeConfig() *cardano.CardanoNodeConfig
	Datum(hash []byte) (*models.Datum, error)
	EvaluateTxContext(
		ctx context.Context,
		tx lcommon.Transaction,
	) (uint64, lcommon.ExUnits, map[lcommon.RedeemerKey]lcommon.ExUnits, error)
	GetBlock(point ocommon.Point) (models.Block, error)
	GetChainFromPointContext(
		ctx context.Context,
		point ocommon.Point,
		inclusive bool,
	) (*chain.ChainIterator, error)
	GetCurrentPParams() lcommon.ProtocolParameters
	GetCurrentPParamsForReporting() lcommon.ProtocolParameters
	GetEpochs() ([]models.Epoch, error)
	GetIntersectPoint(
		ctx context.Context,
		points []ocommon.Point,
	) (*ocommon.Point, error)
	GetPParamsForEpoch(
		epoch uint64,
		era eras.EraDesc,
	) (lcommon.ProtocolParameters, error)
	// PoolStakeDistribution reports the active stake distribution across
	// block-producing pools. A nil filter asks for every pool; see the method
	// on ledger.LedgerState for why an empty non-nil filter differs. at is
	// the zero value and txn is nil here -- this RPC handler always answers
	// live, never pinned.
	PoolStakeDistribution(
		ctx context.Context,
		poolFilter []lcommon.PoolKeyHash,
		at ledger.QueryPoint,
		txn *database.Txn,
	) (*ledger.PoolStakeDistribution, error)
	// SecurityParam is the configured security parameter k, the deepest
	// rollback a chain follower can be asked to undo.
	SecurityParam() int
	SlotToTime(slot uint64) (time.Time, error)
	SystemStart() (time.Time, error)
	Tip() ochainsync.Tip
	TransactionByHash(ctx context.Context, hash []byte) (*models.Transaction, error)
	UtxoByRef(txId []byte, outputIdx uint32) (*models.Utxo, error)
	UtxosByRefs(refs []models.UtxoId) ([]models.Utxo, error)
	UtxosByAddressWithOrdering(
		q *models.UtxoWithOrderingQuery,
	) ([]models.UtxoWithOrdering, error)
}

UtxorpcLedgerState is the subset of ledger.LedgerState needed by the UTxO RPC server. Using this interface keeps the server and service handlers free of a direct *ledger.LedgerState dependency.

type UtxorpcMempool added in v0.55.0

type UtxorpcMempool interface {
	AddTransaction(ctx context.Context, txType uint, txBytes []byte) error
	// TransactionsBounded returns a prefix of the pool in its snapshot
	// order holding at most maxItems transactions whose CBOR totals at most
	// maxBytes, together with the pool's total transaction count. A bound of
	// zero or less is not applied. The first transaction is returned even
	// when it alone exceeds maxBytes, so a non-empty pool never yields an
	// empty result.
	TransactionsBounded(
		maxItems int,
		maxBytes int64,
	) ([]mempool.MempoolTransaction, int)
}

UtxorpcMempool is the subset of mempool.Mempool needed by the UTxO RPC server.

Jump to

Keyboard shortcuts

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