1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/// Default capacity for the engine command channel.
pub const DEFAULT_ENGINE_CHANNEL_CAPACITY: usize = 8192;
/// Default batch size for SetMarketState close operations.
pub const DEFAULT_SET_MARKET_STATE_BATCH: u16 = 4096;
/// Default poll timeout for the engine loop in milliseconds.
pub const DEFAULT_ENGINE_POLL_TIMEOUT_MS: u64 = 100;
#[derive(Clone, Debug, Default, serde::Serialize, serde::Deserialize)]
pub struct ThreadPinning {
/// Pin the engine command-processing + publishing thread to this core id.
#[serde(default)]
pub engine_core: Option<usize>,
/// Pin the WAL poller thread to this core id.
#[serde(default)]
pub wal_poller_core: Option<usize>,
/// Pin disruptor consumer threads in registration order.
///
/// This applies to handlers registered via `EngineBuilder::{register_handler,...}` only.
#[serde(default)]
pub handler_cores: Vec<usize>,
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct JournalConfig {
/// Per-segment LMDB map size in bytes. Default: 256MB prod, 8MB test.
#[serde(default = "JournalConfig::default_segment_map_size_bytes")]
pub segment_map_size_bytes: usize,
/// Auto-rotate after N events (soft limit, checked at batch boundaries). Default: 5000.
#[serde(default = "JournalConfig::default_max_segment_events")]
pub max_segment_events: u64,
/// Run contiguity validation on startup. Default: true.
#[serde(default = "JournalConfig::default_validate_on_startup")]
pub validate_on_startup: bool,
/// On startup, move sealed segments where `end_seq <= confirmed_seq` to `trash/`.
/// This runs before optional trash deletion.
#[serde(default)]
pub prune_before_seq_on_startup: Option<u64>,
/// Remove queued `trash/` segments on startup. Default: true.
#[serde(default = "JournalConfig::default_clear_trash_on_startup")]
pub clear_trash_on_startup: bool,
}
impl JournalConfig {
fn default_segment_map_size_bytes() -> usize {
if cfg!(test) {
8 * 1024 * 1024 // 8MB for tests
} else {
256 * 1024 * 1024 // 256MB for prod
}
}
fn default_validate_on_startup() -> bool {
true
}
fn default_max_segment_events() -> u64 {
// Sizing basis (measured rkyv payload): `MarketOrdersSettled` with 4096 order ids
// encodes to ~32_904 bytes. At 5000 events/segment that's ~157 MiB raw payload,
// leaving practical headroom in the default 256 MiB LMDB map for index/page overhead.
5_000
}
fn default_clear_trash_on_startup() -> bool {
true
}
}
impl Default for JournalConfig {
fn default() -> Self {
Self {
segment_map_size_bytes: Self::default_segment_map_size_bytes(),
max_segment_events: Self::default_max_segment_events(),
validate_on_startup: Self::default_validate_on_startup(),
prune_before_seq_on_startup: None,
clear_trash_on_startup: Self::default_clear_trash_on_startup(),
}
}
}
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Config {
pub ring_size_pow2: usize,
pub response_timeout_ms: u64,
/// Initial capacity for per-market order storage.
///
/// This is used to pre-size the book's internal order arena to reduce reallocations
/// during warm-up and in-play bursts.
pub order_store_capacity: usize,
/// If set, enforce that all BinaryYes markets use this denominator (ticks per $1.00 payout).
///
/// Example: `Some(100)` enforces $0.01 per tick.
#[serde(default)]
pub enforce_binary_yes_max_price_ticks: Option<u16>,
#[serde(default)]
pub pinning: Option<ThreadPinning>,
#[serde(default)]
pub journal: JournalConfig,
}
impl Default for Config {
fn default() -> Self {
Self {
ring_size_pow2: 1024,
response_timeout_ms: 1000,
order_store_capacity: 20_000,
enforce_binary_yes_max_price_ticks: None,
pinning: None,
journal: JournalConfig::default(),
}
}
}