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 ¶
const ( DefaultMaxConcurrentReplays = 4 DefaultMaxReplaysPerClient = 1 DefaultReplayBlocksPerSecond = 1000 DefaultMaxReplayBlocksPerClient = 20_000_000 DefaultReplayBudgetWindow = 24 * time.Hour )
Defaults for the FollowTip historical replay bounds on UtxorpcConfig.
const ( DefaultMaxStreams = 1000 DefaultMaxStreamsPerClient = 20 DefaultMaxPredicateNodes = 1000 DefaultMaxReplayBlocks = 10000 )
Defaults for the long-lived stream bounds on UtxorpcConfig.
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 DefaultMaxConcurrentEvalRequests = 4 DefaultMaxEvalRequestsPerClient = 2 // 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.
const ( DefaultMaxWatchHistoryBytes = 16 << 20 // 16 MiB per stream DefaultMaxWatchHistoryBytesTotal = 256 << 20 // 256 MiB across streams )
Defaults for the WatchTx undo-history byte bounds on UtxorpcConfig.
Variables ¶
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
Types ¶
type ProviderConfig ¶ added in v0.68.0
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
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 client, an IPv4
// address or IPv6 /64 (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
// MaxWatchHistoryBytes caps the bytes one WatchTx stream retains for
// rollback; older blocks are evicted and rebuilt from persisted blocks if
// a rollback needs them (0 = use default).
MaxWatchHistoryBytes int64
// MaxWatchHistoryBytesTotal caps the bytes all WatchTx streams retain
// for rollback together (0 = use default).
MaxWatchHistoryBytesTotal int64
// MaxConcurrentReplays caps FollowTip streams that are serving blocks
// behind the tip at once, across all clients; a further replay is refused
// with ResourceExhausted (0 = use default).
MaxConcurrentReplays int
// MaxReplaysPerClient caps the FollowTip streams one client may have
// serving blocks behind the tip at once, so one client cannot hold every
// MaxConcurrentReplays slot (0 = use default).
MaxReplaysPerClient int
// ReplayBlocksPerSecond paces the historical blocks FollowTip serves to
// one client across all its streams; replay slows down, it does not stop
// (0 = use default).
ReplayBlocksPerSecond int
// MaxReplayBlocksPerClient caps the historical blocks FollowTip serves to
// one client per ReplayBudgetWindow; a replay that spends it ends with
// ResourceExhausted (0 = use default).
MaxReplayBlocksPerClient int64
// ReplayBudgetWindow is the period MaxReplayBlocksPerClient covers
// (0 = use default).
ReplayBudgetWindow time.Duration
// 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
// MaxConcurrentEvalRequests caps EvalTx handlers before transaction
// decoding; MaxEvalRequestsPerClient applies the same bound per client.
MaxConcurrentEvalRequests int
MaxEvalRequestsPerClient 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 {
BlockTransactions(ctx context.Context, block models.Block) ([]lcommon.Transaction, error)
BlockByHash(ctx context.Context, hash []byte) (models.Block, error)
// BlockByHashIncludingRolledBack also finds blocks a primary-chain
// rollback has already removed from the database.
BlockByHashIncludingRolledBack(
ctx context.Context,
hash []byte,
) (models.Block, error)
CardanoNodeConfig() *cardano.CardanoNodeConfig
Datums(ctx context.Context, hashes [][]byte) ([]*models.Datum, error)
EvaluateTxContext(
ctx context.Context,
tx lcommon.Transaction,
) (uint64, lcommon.ExUnits, map[lcommon.RedeemerKey]lcommon.ExUnits, error)
ExistingTransactionHashes(
ctx context.Context,
hashes [][]byte,
) ([][]byte, error)
GetBlock(point ocommon.Point) (models.Block, error)
// GetBlockContext is GetBlock under the caller's context.
GetBlockContext(
ctx context.Context,
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)
// PoolStakeDistributionBounded reports the active stake distribution
// across at most maxPools 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.
PoolStakeDistributionBounded(
ctx context.Context,
poolFilter []lcommon.PoolKeyHash,
at ledger.QueryPoint,
txn *database.Txn,
maxPools int,
) (*ledger.PoolStakeDistribution, error)
// PrimaryChainTip is the tip of the chain FollowTip's iterator reads. It
// can be ahead of Tip while the ledger is still applying blocks.
PrimaryChainTip() ochainsync.Tip
// 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)
UtxosByRefsBounded(
ctx context.Context,
refs []models.UtxoId,
maxBytes int64,
) ([]models.Utxo, error)
UtxosByAddressBoundedPage(
ctx context.Context,
q *models.UtxoWithOrderingQuery,
maxCandidates int,
maxBytes int64,
) (models.UtxoAddressPage, 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.