Documentation
¶
Overview ¶
Package fixture provides graduated in-process tapd fixtures used by benchmarks under bench/. Each fixture composes the minimum set of subsystems required to exercise a given class of RPC handler without the noise of spinning up a real lnd/btcd subprocess.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandBench ¶
func CommandBench[Req, Resp any]( b *testing.B, call func(context.Context, Req) (Resp, error), req Req, )
CommandBench measures the cost of issuing a state-mutating RPC. It runs call once per b.N iteration with allocs reporting on. The handler is invoked directly (no gRPC wire) so the signal reflects subsystem cost, not transport.
Use this shape for RPCs whose dominant cost is a chain mutation, a db write, or a heavy fan-out (Mint, Send, Burn, FundBatch, etc.).
func QueryBench ¶
func QueryBench[Req, Resp any]( b *testing.B, call func(context.Context, Req) (Resp, error), req Req, )
QueryBench measures the cost of issuing a read-only RPC. Identical to CommandBench at the call site, but kept separate so the bench classifier (and future per-shape harness behaviour like cold/warm cache modes) can distinguish read from write paths.
Use this shape for RPCs that only read state (List*, Query*, Fetch*, Decode*, Verify*).
Types ¶
type Minimal ¶
Minimal is the smallest fixture: just config primitives, no subsystems. It is sufficient for handlers that only consume ChainParams, LogMgr, and the like — decoders, marshallers, GetInfo-shape calls.
func NewMinimal ¶
NewMinimal constructs a Minimal fixture and registers cleanup with the provided testing.TB so the server is stopped at the end of the benchmark.
type Mint ¶
type Mint struct {
*Storage
MintingStore *tapdb.AssetMintingStore
Planter *tapgarden.ChainPlanter
ChainBridge *tapgarden.MockChainBridge
Wallet *tapgarden.MockWalletAnchor
GenSigner *tapgarden.MockGenSigner
}
Mint extends Storage with a running ChainPlanter wired to mock chain / wallet / key-ring / gen-signer. Sufficient for the mintrpc surface (MintAsset, FundBatch, SealBatch, FinalizeBatch, CancelBatch, ListBatches, SubscribeMintEvents) provided callers do not require a real on-chain confirmation.
type MintDriver ¶
type MintDriver struct {
*Mint
// contains filtered or unexported fields
}
MintDriver wraps a Mint fixture with a background pump that drains every signal channel the planter's caretaker emits during a mint flow and feeds back synthetic chain confirmations. The driver lets benchmarks call Mint(n) repeatedly without re-implementing the chain/wallet mock choreography.
The pump is started in NewMintDriver and torn down via tb.Cleanup. All state belongs to the driver instance; Mint calls are safe to issue from the same goroutine that constructed it.
func NewMintDriver ¶
func NewMintDriver(tb testing.TB) *MintDriver
NewMintDriver constructs a Mint fixture and a pump that responds to the planter's chain/wallet signals. The pump runs until the testing.TB cleanup fires.
func (*MintDriver) EnqueueSeedlings ¶
func (d *MintDriver) EnqueueSeedlings(tb testing.TB, n int)
EnqueueSeedlings queues n random Normal seedlings on the planter and waits for each to reach MintingStateSeed.
func (*MintDriver) FinalizeBatch ¶
func (d *MintDriver) FinalizeBatch(tb testing.TB)
FinalizeBatch fires FinalizeBatch and blocks until the pump has driven the caretaker through funding, publishing, and confirmation. The planter's FinalizeBatch returns on broadcast (BroadcastCompleteChan), not on confirmation; we then wait on the batch state to reach Confirmed so the caller has the full async confirmation/finalization cost in its timing window.
func (*MintDriver) FundPendingBatch ¶
func (d *MintDriver) FundPendingBatch(tb testing.TB)
FundPendingBatch drives the planter through the funding step on the current pending batch, leaving the batch in the frozen state ready for SealBatch. The chain pump consumes the fee/fund signals.
This is exposed so per-RPC bench setup can stage state without going through the rpcserver.FundBatch handler (which needs cfg.Lnd).
func (*MintDriver) MintOne ¶
func (d *MintDriver) MintOne(tb testing.TB, n int)
MintOne runs one full mint of n assets: enqueue n seedlings, finalize the batch, let the pump drive it to confirmation. This is the unit a scenario bench cycles over.
The method name avoids the embedded *Mint fixture's identifier.
type Send ¶
type Send struct {
*Storage
CoinSelect *tapfreighter.CoinSelect
}
Send extends Storage with the parts of the send/transfer path that do not require a real lnd Signer: CoinSelect (backed by the AssetStore).
ChainPorter and AssetWallet need a real Signer to construct vPSBT witnesses; in-process benches that exercise those paths drive them through scenario harnesses rather than full RPC handlers. The Send fixture leaves those fields nil so any handler that needs them returns a clear error rather than silently misbehaving.
type Storage ¶
type Storage struct {
*Minimal
DB *tapdb.SqliteStore
AssetStore *tapdb.AssetStore
TapAddrBook *tapdb.TapAddressBook
AddrBook *address.Book
Multiverse *tapdb.MultiverseStore
UniverseStats universe.Telemetry
UniverseArchive *universe.Archive
UniverseSyncer *universe.SimpleSyncer
UniverseFederation *universe.FederationEnvoy
FederationDB *tapdb.UniverseFederationDB
ProofArchive proof.NotifyArchiver
KeyRing *tapgarden.MockKeyRing
}
Storage layers a sqlite-backed db and the most common subsystems onto Minimal. It is sufficient for query/marshalling RPCs (List*, Query*, Decode-with-marshal, Fetch*) and for universe read RPCs.
Heavy subsystems that need lnd (Planter/Porter/Custodian, channel deps) are not populated here — see Mint, Send and Universe fixtures.
func NewStorage ¶
NewStorage constructs a Storage fixture, populates the rpcserver config with all subsystem fields it provides, and registers cleanup.