Documentation
¶
Overview ¶
Package server runs the MidnightState gRPC service. It is a native google.golang.org/grpc server (not ConnectRPC) so that clients written against the Acropolis tonic service are byte-for-byte compatible. The UTxO-event query RPCs (GetAssetCreates, GetAssetSpends, GetRegistrations, GetDeregistrations, GetUtxoEvents) are backed by Config.Metadata (see midnight_state.go). The governance/parameters/block/epoch/stability RPCs are backed by Config.Database and Config.SlotTimer (see service.go). Any remaining RPC falls back to UnimplementedMidnightStateServer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Logger *slog.Logger
// Metadata is the store backing the MidnightState query RPCs
// (GetAssetCreates, GetAssetSpends, GetRegistrations,
// GetDeregistrations, GetUtxoEvents). Nil leaves those RPCs
// unimplemented. Any metadata.MetadataStore implementation satisfies
// this narrower interface structurally.
Metadata eventStore
// BlockNumberByHash resolves a Cardano block hash to its block number.
// It receives the RPC's context and must stop when it is done, so a
// canceled or timed-out request does not hold its admission slot.
// It backs GetUtxoEvents' end_block_hash boundary so that boundary is
// honored even when the target block has no Midnight events of its
// own (found=false for an unknown hash, not an error). Nil causes
// GetUtxoEvents to fail requests that set end_block_hash.
BlockNumberByHash func(ctx context.Context, hash []byte) (blockNumber uint64, found bool, err error)
// Host and Port are the gRPC listen address. Defaults to 127.0.0.1:50051.
Host string
Port uint
// TLSCertFilePath and TLSKeyFilePath enable TLS when both are set. When
// both are empty the server listens without TLS. Setting only one is an
// error.
TLSCertFilePath string
TLSKeyFilePath string
// ReflectionEnabled exposes gRPC service discovery. It defaults off.
ReflectionEnabled bool
// ShutdownTimeout bounds GracefulStop before escalating to a hard Stop.
// Defaults to 30s.
ShutdownTimeout time.Duration
// Database backs the governance/parameters/block/epoch/stability RPCs.
// Wrap a *database.Database with NewDatabase. Required for those RPCs to
// work; RPCs that only need Database are unaffected by a nil SlotTimer.
Database MidnightDatabase
// SlotTimer resolves block timestamps and, for the as-of-timestamp
// variants of the stability RPCs, converts a wall-clock time back to a
// slot. Required by GetBlockByHash, GetLatestBlock, GetStableBlock, and
// GetLatestStableBlock.
SlotTimer SlotTimer
// PromRegistry registers the server's request-count and latency
// instruments. Nil is safe -- they just never expose themselves to a
// registry.
PromRegistry prometheus.Registerer
}
Config holds the configuration for the Midnight gRPC server.
type MidnightDatabase ¶ added in v0.63.0
type MidnightDatabase interface {
GetLatestMidnightGovernanceDatum(
ctx context.Context,
datumType string,
blockNumber uint64,
) (*models.MidnightGovernanceDatum, error)
GetMidnightAriadneParamsAtOrBeforeEpoch(
ctx context.Context,
epoch uint64,
) (*models.MidnightAriadneParams, error)
GetMidnightEpochCandidatesByEpoch(
ctx context.Context,
epoch uint64,
) (*models.MidnightEpochCandidates, error)
// GetMidnightCommitteeCandidateRegistrationsByTxHashes returns the
// on-chain provenance (block/slot/tx-index/tx-inputs) for candidate
// UTxOs whose creating tx hash is in txHashes, for GetEpochCandidates to
// join against the (tx_hash, output_index, datum) membership decoded
// from a MidnightEpochCandidates snapshot.
GetMidnightCommitteeCandidateRegistrationsByTxHashes(
ctx context.Context,
txHashes [][]byte,
) ([]models.MidnightCommitteeCandidateRegistration, error)
GetPoolStakeSnapshotsByEpoch(
ctx context.Context,
epoch uint64,
snapshotType string,
) ([]*models.PoolStakeSnapshot, error)
GetEpoch(ctx context.Context, epochId uint64) (*models.Epoch, error)
GetEpochBySlot(ctx context.Context, slot uint64) (*models.Epoch, error)
BlockByHash(ctx context.Context, hash []byte) (models.Block, error)
// BlockByNumber returns the block at the given 0-based consensus block
// number, translating to the blob store's internal 1-based index.
BlockByNumber(ctx context.Context, number uint64) (models.Block, error)
BlocksRecent(ctx context.Context, count int) ([]models.Block, error)
BlockBeforeSlot(ctx context.Context, slot uint64) (models.Block, error)
}
MidnightDatabase is the subset of *database.Database needed by the governance/parameters/block/epoch/stability RPCs. Keeping this package dependent on a narrow interface (rather than *database.Database directly) matches the composition boundary documented in ARCHITECTURE.md: domain packages depend on constructor-injected narrow interfaces, and only the composition layer (here, adapter.go's NewDatabase) wires the concrete type. Read methods receive the RPC context so cancellation and the server deadline reach the metadata transaction.
func NewDatabase ¶ added in v0.63.0
func NewDatabase(db *database.Database) MidnightDatabase
NewDatabase wraps a *database.Database as a MidnightDatabase for use in the Midnight gRPC server config.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server runs the MidnightState gRPC service over its own listener.
func (*Server) Start ¶
Start binds the listener and serves the gRPC server in a background goroutine. Binding and any TLS keypair load happen synchronously so that address-in-use and certificate errors surface before Start returns. A goroutine watches ctx and performs a bounded graceful shutdown when it is cancelled.
type SlotTimer ¶ added in v0.63.0
type SlotTimer interface {
SlotToTime(slot uint64) (time.Time, error)
TimeToSlot(t time.Time) (uint64, error)
}
SlotTimer converts between slot numbers and wall-clock time. Satisfied by *ledger.LedgerState; kept as a narrow local interface so this package does not need to import the full ledger package.