Reassemble only complete envelopes, advancing the cursor after a successful page. Retrying an RPC cannot append its bytes twice. Ported verbatim from the legacy owner client (owner.rs `append_frozen_page`).
(
envelopes: &mut Vec<Vec<u8>>,
partial: &mut Vec<u8>,
cursor: &mut FrozenProvenanceCursor,
cutoff: u64,
page: FrozenProvenancePage,
)
| 233 | /// Ported verbatim from the legacy owner client (owner.rs |
| 234 | /// `append_frozen_page`). |
| 235 | pub fn append_frozen_page( |
| 236 | envelopes: &mut Vec<Vec<u8>>, |
| 237 | partial: &mut Vec<u8>, |
| 238 | cursor: &mut FrozenProvenanceCursor, |
| 239 | cutoff: u64, |
| 240 | page: FrozenProvenancePage, |
| 241 | ) -> Result<(), String> { |
| 242 | let end = FrozenProvenanceCursor { |
| 243 | seq: cutoff, |
| 244 | offset: 0, |
| 245 | }; |
| 246 | if page.next <= *cursor || page.next > end { |
| 247 | return Err("invalid frozen journal page continuation".to_string()); |
| 248 | } |
| 249 | let mut position = *cursor; |
| 250 | for fragment in page.fragments { |
| 251 | // Legacy journal records can leave sequence gaps, but never inside an envelope. |
| 252 | if fragment.cursor.seq >= cutoff |
| 253 | || fragment.cursor < position |
| 254 | || (fragment.cursor != position |
| 255 | && (position.offset != 0 || fragment.cursor.offset != 0)) |
| 256 | || (!fragment.complete && fragment.bytes.is_empty()) |
| 257 | { |
| 258 | return Err("invalid frozen journal fragment cursor".to_string()); |
| 259 | } |
| 260 | partial.extend_from_slice(&fragment.bytes); |
| 261 | position = if fragment.complete { |
| 262 | envelopes.push(std::mem::take(partial)); |
| 263 | FrozenProvenanceCursor { |
| 264 | seq: fragment.cursor.seq + 1, |
| 265 | offset: 0, |
| 266 | } |
| 267 | } else { |
| 268 | FrozenProvenanceCursor { |
| 269 | seq: fragment.cursor.seq, |
| 270 | offset: partial.len(), |
| 271 | } |
| 272 | }; |
| 273 | } |
| 274 | if page.next < position |
| 275 | || (page.next != position && (position.offset != 0 || page.next.offset != 0)) |
| 276 | || (page.next == end && !partial.is_empty()) |
| 277 | { |
| 278 | return Err("incomplete frozen journal page".to_string()); |
| 279 | } |
| 280 | *cursor = page.next; |
| 281 | Ok(()) |
| 282 | } |
| 283 | |
| 284 | /// Load the whole frozen journal by paging through it with strict |
| 285 | /// continuity validation. This is the in-process counterpart of the wire |
no test coverage detected