Skip to content

Commit f75c9e3

Browse files
binarybaronclaude
andauthored
fix(asb): Bob's sqlite migration would cause Alice to fail with assertion (#942)
The migration used json_tree to find objects with an "xmr" key, but this also matched Alice states (which have xmr in state3). Added an explicit Bob-only filter to the target query. Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
1 parent 7def891 commit f75c9e3

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## [4.2.3] - 2026-03-31
1111

1212
- GUI: Fix an issue where we could get stuck in the "BtcCancelled" state if the swap was punished.
13+
- ASB: Fix issue where a database migration would cause the ASB to fail to start.
1314

1415
## [4.2.2] - 2026-03-31
1516

swap/migrations/20260331125446_add_punish_tx_fields_to_bob_states.sql renamed to swap/migrations/20260401150855_add_punish_tx_fields_to_bob_states_v2.sql

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
-- This migration adds tx_punish_fee and punish_address to all Bob state objects
2-
-- that contain the "xmr" field (State3, State4, State5, State6).
3-
-- These fields are needed to construct the punish transaction txid for explicit
4-
-- punish detection, but were previously only stored in State2 (ExecutionSetupDone).
5-
--
6-
-- Uses json_tree to generically find the parent object of "xmr" regardless of
7-
-- nesting depth, avoiding the need to enumerate each BobState variant individually.
8-
-- json_insert (not json_set) is used so existing values are never overwritten.
1+
-- Fix for 20260331125446_add_punish_tx_fields_to_bob_states which incorrectly
2+
-- matched Alice states containing "xmr" fields via json_tree. This v2 adds
3+
-- an explicit Bob-only filter. On databases where the original migration already
4+
-- ran successfully (Bob-only or empty), this is a no-op because json_insert
5+
-- with existing keys does nothing.
96

107
-- Step 1: Collect source values (tx_punish_fee, punish_address) per swap_id
118
-- from the ExecutionSetupDone state.
@@ -28,13 +25,15 @@ DROP TABLE _assert;
2825
-- Step 2: Collect target rows and the JSON path where the new fields should be
2926
-- inserted. json_tree's `path` column gives the parent object of the matched key,
3027
-- so appending '.tx_punish_fee' inserts as a sibling of "xmr", not under it.
28+
-- Only Bob states are considered (excludes Alice states which also have "xmr").
3129
CREATE TEMP TABLE _punish_target AS
3230
SELECT
3331
swap_states.id AS target_id,
3432
swap_states.swap_id,
3533
(SELECT jt.path FROM json_tree(swap_states.state) AS jt WHERE jt.key = 'xmr' LIMIT 1) AS parent_path
3634
FROM swap_states
37-
WHERE json_extract(state, '$.Bob.ExecutionSetupDone') IS NULL
35+
WHERE json_extract(state, '$.Bob') IS NOT NULL
36+
AND json_extract(state, '$.Bob.ExecutionSetupDone') IS NULL
3837
AND (SELECT jt.path FROM json_tree(swap_states.state) AS jt WHERE jt.key = 'xmr' LIMIT 1) IS NOT NULL;
3938

4039
-- Assert: every target row has a matching source row.

0 commit comments

Comments
 (0)