Skip to main content

In-Memory Cuckoo Filter Preflight Deduplication

1. The Duplicate Transaction Crisis​

In high-concurrency Solana trading systems, automated agents and trading bots frequently generate duplicate transaction requests. This happens during:

  • Network latency spikes where an inflight transaction's status is delayed.
  • Competing trigger conditions in arbitrage and liquidation loops.
  • Re-broadcast storms under cluster congestion.

Submitting duplicate transactions to Solana RPC nodes is disastrous:

  1. Wasted RPC Quotas: Consumes expensive RPC rate limits and compute units.
  2. Failed Preflight Simulations: RPC simulation engines return AlreadyProcessed errors, consuming time on the critical execution path.
  3. Double-Spend Hazards: In cases where blockhashes change, duplicates can inadvertently execute twice.

Why Bloom Filters Fail​

Standard Bloom filters are widely used for membership testing, but they have a fatal flaw for transaction management: they cannot delete entries.

Because Solana transactions have an exact 150-slot validity lifetime (~60 seconds), a transaction filter must evict expired signatures continuously. A Bloom filter cannot delete without rebuilding the entire filter, which causes latency spikes and memory bloat.


2. Mathematical Foundation of Sentry's Cuckoo Filter​

Sentry 2.0 implements a custom, zero-dependency Partial-Key Cuckoo Filter (lib/cuckoo-filter.ts).

Data Structure Specification​

  • Buckets: $M$ buckets, where $M$ is strictly a power of 2 ($M = 2^k$).
  • Slots per Bucket ($b$): 4 entries per bucket.
  • Fingerprint Size ($fp$): 16-bit non-zero hash computed via FNV-1a.
  • Alternate Index Calculation (Involution):
i_1 = hash(x) & (M - 1)
i_2 = (i_1 ^ hash(fp)) & (M - 1)

Because a ^ b ^ b = a, this operation is a true involution: either bucket index can be derived directly from the other bucket index and the fingerprint, without knowing the original transaction signature $x$.

Fast Bitmasked Modulo​

Because $M$ is a power of 2, the expensive modulo operator (% M) is replaced with a single bitwise AND operation:

index = hash & (M - 1)

This executes in a single CPU cycle (under 1ns).


3. Sliding Window Eviction Architecture​

Solana blockhashes expire after 150 slots. Sentry wraps the Cuckoo filter in a SlidingWindowCuckooDeduplicator:

class SlidingWindowCuckooDeduplicator {
private filter: CuckooFilter;
private slotEntries: Map<number, string[]>;

// Check and record transaction signature
public isDuplicate(signature: string, currentSlot: number): boolean {
if (this.filter.contains(signature)) {
return true; // Duplicate detected in in-memory micro-lookup (~150-300ns)!
}
this.filter.insert(signature);
this.recordSlot(currentSlot, signature);
return false;
}

// Sweep entries older than 150 slots
public evictOlderThan(oldestValidSlot: number): void {
for (const [slot, signatures] of this.slotEntries) {
if (slot < oldestValidSlot) {
for (const sig of signatures) {
this.filter.delete(sig); // Cuckoo filters natively support deletion!
}
this.slotEntries.delete(slot);
}
}
}
}

4. Performance & Invariant Guarantees​

MetricSentry 2.0 Cuckoo FilterStandard Bloom FilterIn-Memory Set / Map
Lookup Latency~150-300 ns~200 ns~800 ns
Deletion SupportNative ($O(1)$)Impossible$O(1)$ (high GC overhead)
Memory Allocation on Lookup0 bytes0 bytesVariable heap allocation
False-Positive Rate~0.012%Parameter dependent0%
False-Positive Failure ModeFail-Safe (drops duplicate)Fail-SafeN/A

Live Integration Points​

The Cuckoo filter is wired directly into the live execution pipeline:

  1. evaluatePolicy (lib/policy-engine.ts): Evaluates the transaction signature before running any simulation or policy rules. If duplicate, returns duplicate_suppressed in ~150-300ns via in-memory bitwise mask.
  2. executeAction (lib/action-engine.ts): Refuses to broadcast a transaction if an identical raw payload is currently inflight.
  3. Benchmark Verification: In the live 100-run Mainnet matrix, Run #48 was an injected duplicate that was intercepted preflight in ~200ns, spending 0 lamports and saving RPC compute.

5. Duplicate-Safe Multi-Rail Broadcast Semantics​

When dispatching transactions across multiple physical network rails (e.g., Solami Beam SWQoS TPU and secondary RPC nodes), Sentry 2.0 enforces strict protocol-level idempotency:

  1. Identical Signed Payload: The transaction is compiled and signed once using Ed25519 (tweetnacl), generating an exact 64-byte signature. The exact same serialized binary payload is dispatched concurrently across routes.
  2. Validator Protocol-Level Deduplication: Under the Solana protocol specification, validator leaders maintain a recent signature cache within the 150-slot valid blockhash window. Whichever network packet reaches the validator leader first processes the transaction; any subsequent arrivals with the identical signature are instantly dropped as duplicates by the leader's TPU scheduler. This guarantees zero risk of double-execution or double-spending.
  3. Cache Evaluation Order & Blockhash Expiration: Solana validators check their recent blockhash cache before checking their transaction signature cache. If an identical duplicate transaction is re-transmitted after its blockhash has expired, the validator RPC node returns BlockhashNotFound rather than AlreadyProcessed. Both responses indicate successful preflight isolation.