Conversation
- Replace count-based equal-split batching with FFD bin packing - Bound each batch by maxBatchSizeKB from server response - Add packKeychainsFFD private method with per-keychain size guard - Add packKeychainsFFD, processKeychainPasswordUpdatesInBatches and changePassword tests Ticket: WP-8343
kaustubhbitgo
approved these changes
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
changePasswordflow re-encrypts all of a user's keychains under the new password and sends them to the server in a single (or batched) payload. The original batching logic split keychains into N equal groups by count, where N came from the server'snoOfBatchesresponse. This breaks completely for mixed size keychains payloads.Root cause: Count-based equal-split cannot account for this because the server does not know individual keychain sizes — it only sees the total payload.
Solution: FFD bin packing
This PR replaces count-based batching with First Fit Decreasing (FFD) bin packing:
maxBatchSizeKB(e.g. 900 KB) instead ofnoOfBatchesmaxBatchSizeKB— guaranteed by constructionThis correctly handles mixed payloads regardless of how large and small keys are interleaved.
Changes
changePasswordnow passesbatchingFlowCheck.maxBatchSizeKB(instead ofnoOfBatches) to the batching methodpackKeychainsFFDmethod implements the FFD algorithm; V1 and V2 keychains are kept in separate maps per bin to match the existingPUT /user/keychainsAPI contractprocessKeychainPasswordUpdatesInBatchessignature changed fromnoOfBatchestomaxBatchSizeKB; it now delegates bin construction topackKeychainsFFDIssue Number
WP-8343
Type of change
How Has This Been Tested?
Unit tests added in
modules/sdk-api/test/unit/bitgoAPI.tscovering:packKeychainsFFD: empty inputs, single-bin fit, multi-bin split, oversized item throws, correct V1/V2 separation, FFD ordering (large item packed first)processKeychainPasswordUpdatesInBatches: single batch, two-bin split, retry-then-succeed, retries exhausted on HTTP errors, retries exhausted on failed-keychains responsechangePasswordbatching flow: batching enabled (PUT + keychain-free POST), batching disabled (legacy POST with keychains), batching check failure (falls back to legacy)Checklist
Ticket: WP-8343