# TYP-002: Metadata Keys and RocksDB Defaults

| Link | Path |
|------|------|
| **Normative** | [NORMATIVE.md](../NORMATIVE.md) |
| **Verification** | [VERIFICATION.md](../VERIFICATION.md) |
| **Tracking** | [TRACKING.yaml](../TRACKING.yaml) |
| **Spec** | [SPEC.md](../../../../resources/SPEC.md) Section 2.2, 2.3 |

---

## Summary

The crate MUST define metadata key constants for CF_METADATA entries and RocksDB tuning default constants for store configuration.

---

## Specification

### Metadata Key Constants

```rust
/// Key for the current chain tip (ChainTip 40-byte encoding).
pub const META_TIP: &str = "tip";

/// Key for the genesis block hash (32 bytes).
pub const META_GENESIS_HASH: &str = "genesis_hash";

/// Key for the minimum retained block height (8 bytes little-endian u64).
pub const META_MIN_HEIGHT: &str = "min_height";

/// Key for the database schema version (8 bytes little-endian u64).
pub const META_SCHEMA_VERSION: &str = "schema_version";

/// Key for the trained zstd compression dictionary.
pub const META_ZSTD_DICT: &str = "zstd_dict";

/// Current schema version number.
pub const SCHEMA_VERSION: u64 = 1;
```

### RocksDB Tuning Defaults

```rust
/// Default RocksDB write buffer size: 64 MB.
pub const DEFAULT_WRITE_BUFFER_SIZE: usize = 64 * 1024 * 1024; // 67_108_864

/// Default RocksDB block cache size: 128 MB.
pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 128 * 1024 * 1024; // 134_217_728

/// Default maximum number of open files for RocksDB.
pub const DEFAULT_MAX_OPEN_FILES: i32 = 1000;

/// Default bloom filter bits per key.
pub const DEFAULT_BLOOM_BITS_PER_KEY: i32 = 10;

/// Default in-memory block cache capacity (number of blocks).
pub const DEFAULT_BLOCK_CACHE_CAPACITY: usize = 1000;

/// Default in-memory header cache capacity (number of headers).
pub const DEFAULT_HEADER_CACHE_CAPACITY: usize = 2000;

/// Default zstd compression level.
pub const ZSTD_COMPRESSION_LEVEL: i32 = 3;
```

---

## Acceptance Criteria

- [x] `META_TIP` equals `"tip"`
- [x] `META_GENESIS_HASH` equals `"genesis_hash"`
- [x] `META_MIN_HEIGHT` equals `"min_height"`
- [x] `META_SCHEMA_VERSION` equals `"schema_version"`
- [x] `META_ZSTD_DICT` equals `"zstd_dict"`
- [x] `SCHEMA_VERSION` equals `1`
- [x] `DEFAULT_WRITE_BUFFER_SIZE` equals `67_108_864`
- [x] `DEFAULT_BLOCK_CACHE_SIZE` equals `134_217_728`
- [x] `DEFAULT_MAX_OPEN_FILES` equals `1000`
- [x] `DEFAULT_BLOOM_BITS_PER_KEY` equals `10`
- [x] `DEFAULT_BLOCK_CACHE_CAPACITY` equals `1000`
- [x] `DEFAULT_HEADER_CACHE_CAPACITY` equals `2000`
- [x] `ZSTD_COMPRESSION_LEVEL` equals `3`

---

## Implementation Notes

- Define in `src/constants.rs` alongside the CF_* constants from TYP-001.
- Meta key constants are re-exported from the crate root per STR-003.
- DEFAULT_* constants are used by `BlockStoreConfig::default()` (TYP-008).
- SCHEMA_VERSION is written to CF_METADATA on first open and checked on subsequent opens.

---

## Test Plan

| Test Name | Type | Description |
|-----------|------|-------------|
| `test_meta_tip_value` | unit | Assert `META_TIP == "tip"` |
| `test_meta_genesis_hash_value` | unit | Assert `META_GENESIS_HASH == "genesis_hash"` |
| `test_meta_min_height_value` | unit | Assert `META_MIN_HEIGHT == "min_height"` |
| `test_meta_schema_version_value` | unit | Assert `META_SCHEMA_VERSION == "schema_version"` |
| `test_meta_zstd_dict_value` | unit | Assert `META_ZSTD_DICT == "zstd_dict"` |
| `test_schema_version` | unit | Assert `SCHEMA_VERSION == 1` |
| `test_write_buffer_size_default` | unit | Assert `DEFAULT_WRITE_BUFFER_SIZE == 64 * 1024 * 1024` |
| `test_block_cache_size_default` | unit | Assert `DEFAULT_BLOCK_CACHE_SIZE == 128 * 1024 * 1024` |
| `test_max_open_files_default` | unit | Assert `DEFAULT_MAX_OPEN_FILES == 1000` |
| `test_bloom_bits_default` | unit | Assert `DEFAULT_BLOOM_BITS_PER_KEY == 10` |
| `test_cache_capacity_defaults` | unit | Assert block=1000, header=2000 |
| `test_compression_level_default` | unit | Assert `ZSTD_COMPRESSION_LEVEL == 3` |

---

## Expected Test Files

- `tests/typ_002_tests.rs`
