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
//! Fixtures-only instrumentation for the production protected-relay
//! allocation witness (`tests/subnet_relay_alloc_e2e.rs`).
//!
//! `tests/subnet_route_hop_alloc.rs` proves the sealing *primitive*
//! allocates nothing, and the `protected_forward_allocation_pins`
//! module in `mesh.rs` structurally pins that `relay_protected_hop`
//! still calls it. Neither measures the production branch: the relay
//! runs on a tokio worker thread where *reception* allocates per
//! packet, so a bare process-wide allocation counter cannot attribute
//! anything to the relay.
//!
//! This module gives the witness that attribution. The relay branch
//! opens a [`RelaySection`] for exactly its own extent; the witness's
//! counting `#[global_allocator]` consults [`in_relay_section`] on
//! every allocation and charges only those made *inside* the section,
//! on whichever thread the relay happens to run. [`sections_entered`]
//! exists so the witness can prove the marker actually executed — an
//! allocation count of zero over a section that never ran would be a
//! vacuous pass, which is the exact failure mode this witness was owed
//! to close (SUBNET_AUTH_PLAN.md D9).
//!
//! Everything here must itself be allocation-free on the measured
//! path: the thread-local is const-initialized (no lazy allocation,
//! and `Cell<bool>` has no destructor to register) and the entry
//! counter is a plain atomic. The module is compiled only for tests
//! and the `fixtures` feature; production builds carry neither the
//! marker nor this file's code.
use Cell;
use ;
thread_local!
/// Total number of times the relay section was entered, across all
/// threads, since process start. Monotonic; read two samples to
/// attribute a window.
static SECTIONS_ENTERED: AtomicU64 = new;
/// RAII marker for the production relay branch. Constructed at the
/// top of `relay_protected_hop`; the drop covers every early return
/// in the branch.
/// Is the current thread inside the production relay branch?
///
/// Called from the witness's global allocator: must never allocate.
/// How many times the relay section has been entered process-wide.