···192192// require a signing key. The caller must obtain a signature over uc.cbor and
193193// then call finaliseCommit.
194194func buildUnsignedCommit(ctx context.Context, bs blockstore.Blockstore, r *atp.Repo) (*unsignedCommit, error) {
195195+ // Write diff blocks BEFORE calling r.Commit(), because r.Commit()
196196+ // traverses the MST and clears the dirty flags, which would cause
197197+ // WriteDiffBlocks to do nothing if called afterwards.
198198+ if _, err := r.MST.WriteDiffBlocks(ctx, bs.(legacyblockstore.Blockstore)); err != nil { //nolint:staticcheck
199199+ return nil, fmt.Errorf("writing MST blocks: %w", err)
200200+ }
201201+195202 commit, err := r.Commit()
196203 if err != nil {
197204 return nil, fmt.Errorf("creating commit: %w", err)
198198- }
199199-200200- // Stamp the revision on the blockstore before writing any MST blocks so
201201- // that every block carries the correct Rev.
202202- if rs, ok := bs.(revSetter); ok {
203203- rs.SetRev(commit.Rev)
204204- }
205205-206206- if _, err := r.MST.WriteDiffBlocks(ctx, bs.(legacyblockstore.Blockstore)); err != nil { //nolint:staticcheck
207207- return nil, fmt.Errorf("writing MST blocks: %w", err)
208205 }
209206210207 buf := new(bytes.Buffer)