# Same-input Geyser processing and persistence

This crate compares two Rust arrangements of the same finite work. It does not compare programming languages. Artificial arrival or save delays are absent.

`before`: protobuf decode → detect target program invocations → encode JSONL → await real file persistence → next input.

`after`: the same decode / detection / JSONL encoding → bounded FIFO admission → next input. Exactly one writer persists accepted records in input order. A full queue retains the current record and waits; it does not discard the record or spawn another task.

## Scope and provenance

Use `synthetic` and `replay` for the local functional tutorial. The generated protobuf transactions, signatures, block metadata and receive offsets are artificial. They are not market captures or performance evidence. The application extracts target program invocations; it does not calculate prices or send orders.

Cargo.lock pins the dependencies used by the source. Direct Yellowstone proto/client versions correspond to the official Solana Stream SDK at commit `3b22307033ec6d7b78242d3b4cc9f3168209dcfd`; the entire transitive SDK workspace is not asserted identical.

The optional `capture` source and the guarded `run_comparison.py` utility are retained unchanged for source completeness and dependency-lock continuity. They are outside this article's run instructions, were not executed for this distribution, and provide no live-connection result. No endpoint, credentials, live capture, or comparison result is included.

## Fixture contract

The directory contains `updates.pb` and `manifest.json`.

- `updates.pb` concatenates `SubscribeUpdate::encode_length_delimited` messages. These are SDK-decoded and reencoded messages, not original HTTP/2 or gRPC wire bytes.
- Manifest schema version is 1. Required fields are `source_kind`, `data_file` (`updates.pb`), `data_sha256`, `record_count`, and ordered `records`.
- Each record has contiguous zero-based `seq`, nondecreasing `received_after_sdk_ns`, `payload_len`, and `payload_sha256`. Payload hashes exclude the protobuf length prefix. The file hash includes every prefix.
- Additional metadata is retained via `Manifest.metadata`. Capture offsets describe the recording, not a replay arrival schedule.
- Reader limits: 128 MiB input file / manifest; 16 MiB individual payload. It rejects missing/trailing data, hash/count/sequence/time errors and unusable live captures before replay.

All input is preloaded and validated before the replay clock starts. At replay start all records are ready; there is no arrival replay timer. The results cannot be called live network latency, NIC-to-decision latency, or server-to-client latency.

## The application work

The processor extracts invocations of an explicitly supplied 32-byte program key from transaction messages. It resolves static keys, loaded writable keys and loaded readonly keys; inspects outer and inner instructions; preserves account order and instruction data; and emits exactly one result per input, including zero matches. It records vote/error flags. It does not interpret a program ABI, compute prices, decide trades or verify signatures.

Both modes call the same `process_update`, `encode_result`, and `save` functions. `encode_result` emits one UTF-8 JSON object plus LF. Large chain integers are decimal strings. No timestamps or mode-specific fields appear in saved records, allowing exact byte comparison. A malformed message/index stops new input and retains remaining sequence states; it is not skipped.

The outer-and-inner extraction contract requires available inner-instruction metadata. `inner_instructions_none: true` is rejected in both the Rust processor and Python oracle, including a contradictory nonempty inner list alongside that flag. `false` with an empty list is valid. On rejection, replay leaves that sequence and later inputs `unprocessed`, drains the already accepted prefix, and reports `failed`; it emits no zero-match result for unavailable data. This follows the upstream None/Some conversion, not a guess from list length: [proto field 10](https://github.com/rpcpool/yellowstone-grpc/blob/b9a4f56a43a1858c63bfe8c3904b98ef416ae1a9/yellowstone-grpc-proto/proto/solana-storage.proto), [encoding None](https://github.com/rpcpool/yellowstone-grpc/blob/b9a4f56a43a1858c63bfe8c3904b98ef416ae1a9/yellowstone-grpc-geyser/src/plugin/convert_to.rs), [decoding None and its tests](https://github.com/rpcpool/yellowstone-grpc/blob/b9a4f56a43a1858c63bfe8c3904b98ef416ae1a9/yellowstone-grpc-geyser/src/plugin/convert_from.rs).

## Queue, byte bound and completion

The normal channel capacity is 64. The byte semaphore defaults to 1 MiB and covers encoded bytes held by the writer, queued records, and the current record once it reserves bytes. A record larger than the entire byte limit fails immediately rather than waiting forever. Before byte reservation, the producer may hold exactly one current encoded record. The input corpus, decoder allocations, reports and ledger are separate memory consumers; the byte limit is not a claim that whole-process RSS is 1 MiB.

The channel can contain 64 records, with one more in the writer and at most one unaccepted current record in the producer. The byte bound can reduce this number. Sampled `max_reserved_*` fields are observed maxima at admission, not a continuous memory profiler; Tokio channel / semaphore enforce their configured bounds regardless of sampling.

For each record both modes await `write_all`, `flush`, and `sync_data` on the same single file. Flush waits for Tokio's pending write completion/error; it is not an extra durability sync. No batching is introduced. A successful save means `sync_data` returned successfully under this host's filesystem semantics. It is not proof of power-loss durability of an entire storage stack, and the directory entry is not separately synced.

Normal completion drops the sender, drains accepted work and joins the writer before reporting. Ctrl-C is honored at the next input boundary, then accepted work drains; it does not cancel an in-progress file write. `--stop-after` deterministically tests this boundary. No hard shutdown deadline is promised for a stalled filesystem.

Every input has one final state: `saved`, `accepted_unsaved`, `accepted_unknown`, `decided_unaccepted`, or `unprocessed`. On known pre-write failure the current record is unsaved. Once writing is attempted, a write/flush/sync error is conservatively unknown; queued records are recovered as accepted-unsaved. Writer failure closes both channel and byte capacity, waking blocked admission. A task join failure conservatively marks all accepted records unknown. No implicit retry can hide duplicates.

## Build and functional checks

Run these commands from this crate's directory with Rust/Cargo and Python 3 on PATH. The recorded run used Rust/Cargo 1.100.0. The first build downloads the versions pinned by `Cargo.lock`; add `--offline` to build/test only when those dependencies are already cached. The output directory for the functional runner must not already exist.

```sh
python3 build_release.py
cargo test --release --locked
python3 run_functional.py --out functional-results-local
python3 -m unittest discover -s checks -v
```

The functional runner checks 128 clearly synthetic records using a separate Python protobuf-wire parser. The oracle does not invoke the Rust implementation or consume Rust-produced expected output. It compares semantic content, order and every saved byte, and checks all sequence accounting and stage timestamp order.

`build_release.py` captures Cargo's actual `compiler-artifact` messages and checks that the reported executables are optimized with debug assertions disabled. It records the executable hashes, compiler, build command and source hashes. The comparison runner verifies those hashes before starting and after each run. A different binary, stale source, or missing release provenance is rejected before comparison; a directory named `target/release` alone is not proof of an optimized build. Do not edit source after recording a build without rebuilding and rerunning the relevant checks.

Functional scenarios include before/after completion, deterministic channel Full (capacity 64), byte Full, Closed, a pre-write save failure in both modes, a post-write/pre-sync unknown result, graceful stop, zero accepted inputs, and an oversized result. Rust tests additionally cover malformed references, corrupt/truncated fixtures, unusable live capture, malformed protobuf, empty inputs and waking a byte waiter after writer failure. Fault injection / the held-writer gate are rejected for real captures.

The 16 functional scenarios include explicit rejection of unavailable inner-instruction metadata. Both the independent oracle and the Rust processor reject `inner_instructions_none=true`, whether the inner list is empty or nonempty. The accepted prefix drains and the affected sequence remains unprocessed.

See `../verification/functional-summary.json` for this distribution's functional results. Runtime is fixed to two Tokio worker threads. Rust test and functional-runner elapsed times are not performance comparisons. Report stage timestamps are local replay instrumentation only; synthetic reports are explicitly `functional_only`. They do not measure live network or server-to-client latency.

## Not established by this tutorial

Live Geyser delivery or completeness, production load capacity, language ranking, latency improvement, trading outcomes, deadline-bounded shutdown, automatic retries, crash/power-loss recovery, and cancellation of a blocked file operation are not established. The finite ledger and preloaded corpus are not an unbounded streaming service design.
