sui_indexer_alt_schema/
cp_blooms.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use diesel::prelude::*;
5use sui_field_count::FieldCount;
6
7use crate::blooms::bloom::BloomFilter;
8use crate::schema::cp_blooms;
9
10/// Size of the checkpoint bloom filter in bytes (16KB before folding).
11pub const CP_BLOOM_NUM_BYTES: usize = 16_384;
12
13/// Number of bits in the checkpoint bloom filter.
14pub const CP_BLOOM_NUM_BITS: usize = CP_BLOOM_NUM_BYTES * 8;
15
16/// Number of hash functions for checkpoint bloom filter.
17pub const CP_BLOOM_NUM_HASHES: u32 = 6;
18
19/// Global seed for checkpoint bloom filter hashing.
20pub const BLOOM_FILTER_SEED: u128 = 67;
21
22/// Minimum size after folding (1024 bytes = 1KB).
23///
24/// This prevents over-folding which causes correlated bits (from common items like
25/// popular packages) to concentrate and create hot spots with high false positive rates.
26pub const MIN_FOLD_BYTES: usize = 1024;
27
28/// Stop folding when bit density exceeds this threshold.
29pub const MAX_FOLD_DENSITY: f64 = 0.40;
30
31/// Bloom filter with checkpoint dimensions.
32pub type CpBloomFilter = BloomFilter<CP_BLOOM_NUM_BYTES, CP_BLOOM_NUM_HASHES, BLOOM_FILTER_SEED>;
33
34#[derive(Insertable, Selectable, Queryable, Debug, Clone, FieldCount, QueryableByName)]
35#[diesel(table_name = cp_blooms)]
36pub struct StoredCpBlooms {
37    /// Checkpoint sequence number.
38    pub cp_sequence_number: i64,
39    /// Folded bloom filter bytes.
40    pub bloom_filter: Vec<u8>,
41}