Commit 628b45e
fix(syncguard): spot-check proof by bnum offset, not tfile tail
Two bugs uncovered during end-to-end WSL smoke testing on mainnet:
1. sg_proof_match_tfile_tail() required the proof segment to sit
byte-exactly at the TAIL of the downloaded tfile. If the peer's
chain advanced between scan_quorum() (proof fetch) and resync()
(full tfile download) — even by a single block — the proof would
no longer be at the tail and the check would fire false positives.
Since tfile trailers are stored in bnum-continuous order starting
from genesis (trailer at byte offset N*sizeof(BTRAILER) has
bnum==N), we can instead seek directly to proof[0].bnum's offset
and compare the proof's historical trailers in place. The tfile
may have advanced past the proof's tip, but the proof's own range
is historical and cannot change without a reorg. Renamed to
sg_proof_match_tfile() to reflect the new semantics.
2. resync() called sg_session_reset() at entry, which also cleared
the proof cache that scan_quorum() had just populated. The proofs
must persist across the scan→resync boundary. Session reset is
no longer automatic on resync(); the session caches now persist
for the lifetime of the process (zero-initialized at startup via
static storage, overwritten naturally on re-scan). sg_session_reset()
remains available as an exported helper.
Also downgraded diagnostic logs in sg_proof_match_tfile() from plog()
to pdebug() so they only appear at debug log level.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 44d3549 commit 628b45e
3 files changed
Lines changed: 61 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
223 | 226 | | |
224 | 227 | | |
225 | 228 | | |
| |||
273 | 276 | | |
274 | 277 | | |
275 | 278 | | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
282 | 288 | | |
283 | 289 | | |
284 | 290 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
186 | 187 | | |
187 | 188 | | |
188 | 189 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
194 | 202 | | |
195 | 203 | | |
196 | 204 | | |
197 | 205 | | |
198 | 206 | | |
199 | 207 | | |
| 208 | + | |
200 | 209 | | |
201 | 210 | | |
202 | | - | |
203 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
204 | 219 | | |
205 | 220 | | |
206 | 221 | | |
| 222 | + | |
| 223 | + | |
207 | 224 | | |
208 | 225 | | |
209 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
210 | 230 | | |
211 | 231 | | |
212 | 232 | | |
213 | | - | |
214 | 233 | | |
215 | 234 | | |
216 | | - | |
| 235 | + | |
217 | 236 | | |
| 237 | + | |
218 | 238 | | |
219 | 239 | | |
220 | 240 | | |
221 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
222 | 247 | | |
223 | 248 | | |
224 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
17 | 24 | | |
18 | 25 | | |
19 | 26 | | |
| |||
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | | - | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
| |||
0 commit comments