Commit c429c1e
authored
refactor(blockchain): consolidate XMSS preparation window advance logic (lambdaclass#388)
## 🗒️ Description / Motivation
This PR addresses review comments from lambdaclass#332.
`sign_with_attestation_key` and `sign_with_proposal_key` had inline
copies of the same advance loop that lives in the `advance_key` helper.
This PR routes them through the helper so there's a single
implementation.
Also switches the tracing field for elapsed durations from `elapsed_ms =
... as u64` to `elapsed = ?duration` so the `Duration`'s `Debug` impl is
used.
## What Changed
**`crates/blockchain/src/key_manager.rs`**
- `advance_key` now returns `Result<(), KeyManagerError>` and returns
the same `SigningError("XMSS key exhausted...")` the inline loops
previously produced.
- `sign_with_attestation_key` and `sign_with_proposal_key` replace their
inline advance loops with `advance_key(...)?`.
- `advance_keys_to` swallows the new `Result` via `inspect_err` so one
exhausted key doesn't abort iteration; logs a `warn` per failure.
- All three `elapsed_ms = ... as u64` fields → `elapsed =
?start.elapsed()`.
## Correctness / Behavior Guarantees
- Signing-path behavior is unchanged: same control flow, same
`is_prepared_for` check, same `advance_preparation` loop, same
exhaustion detection, same returned error string.
- The exhaustion error message no longer distinguishes attestation vs
proposal in its text (both say `"XMSS key exhausted..."`).
`validator_id` and `slot` are still in the message.
- Tracing field change is observability-only — printed value is now
human-readable (`1.234s`) instead of a raw millisecond count.
## Tests Added / Run
- `make fmt` clean
- `make lint` clean
- `make test` passes
The refactor is logic-preserving, so the existing `signature_spectests`
and `forkchoice_spectests` continue to exercise the signing paths
through the new `advance_key` indirection.
## Related Issues / PRs
- Closes lambdaclass#383
- Follow-up to lambdaclass#332
## ✅ Verification Checklist
- [x] `make fmt`
- [x] `make lint`
- [x] `make test`1 parent 955c160 commit c429c1e
1 file changed
Lines changed: 20 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 99 | + | |
115 | 100 | | |
116 | 101 | | |
117 | 102 | | |
| |||
141 | 126 | | |
142 | 127 | | |
143 | 128 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 129 | + | |
167 | 130 | | |
168 | 131 | | |
169 | 132 | | |
| |||
176 | 139 | | |
177 | 140 | | |
178 | 141 | | |
179 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
180 | 147 | | |
181 | | - | |
| 148 | + | |
182 | 149 | | |
183 | 150 | | |
184 | 151 | | |
185 | 152 | | |
186 | 153 | | |
187 | 154 | | |
188 | 155 | | |
189 | | - | |
190 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
191 | 160 | | |
192 | 161 | | |
193 | 162 | | |
194 | 163 | | |
195 | 164 | | |
196 | | - | |
| 165 | + | |
197 | 166 | | |
198 | 167 | | |
| 168 | + | |
199 | 169 | | |
200 | 170 | | |
201 | 171 | | |
| |||
0 commit comments