utxorpc

package
v0.70.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 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 (
	DefaultMaxBlockRefs    = 100
	DefaultMaxUtxoKeys     = 1000
	DefaultMaxHistoryItems = 10000
	DefaultMaxDataKeys     = 1000
	// DefaultMaxRequestBody bounds each Connect message before it is decoded
	// or authenticated. 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
	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"`
	Auth apiconfig.AuthPolicy `yaml:"auth"`
}

ProviderConfig's TLS and Auth fields are documented in ARCHITECTURE.md's "API security" section. Composition (node.go) merges the top-level api.tls/api.auth defaults into these fields before this provider ever decodes them, so from this package's point of view they are always already-resolved-for-this-provider settings, identical in shape to a provider that set every field inline.

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 and Auth are the resolved (merged, validated) equivalents of
	// what was previously TlsCertFilePath/TlsKeyFilePath fields here --
	// see ProviderConfig's doc comment and ARCHITECTURE.md's "API
	// security" section.
	TLS  apiconfig.EffectiveTLS
	Auth apiconfig.EffectiveAuth
	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
	MaxDataKeys     int
	// MaxPoolFilter caps ReadState's pool_keyhashes filter length.
	MaxPoolFilter int
	// 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(hash []byte) (models.Block, error)
	CardanoNodeConfig() *cardano.CardanoNodeConfig
	Datum(hash []byte) (*models.Datum, error)
	EvaluateTx(
		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
	GetEpochs() ([]models.Epoch, error)
	GetIntersectPoint(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.
	PoolStakeDistribution(
		poolFilter []lcommon.PoolKeyHash,
	) (*ledger.PoolStakeDistribution, error)
	SlotToTime(slot uint64) (time.Time, error)
	SystemStart() (time.Time, error)
	Tip() ochainsync.Tip
	TransactionByHash(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(txType uint, txBytes []byte) error
	Transactions() []mempool.MempoolTransaction
}

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