diff --git a/store/migrations/000003_fix_immutable_block_hash.down.sql b/store/migrations/000003_fix_immutable_block_hash.down.sql new file mode 100644 index 0000000..a4dff9c --- /dev/null +++ b/store/migrations/000003_fix_immutable_block_hash.down.sql @@ -0,0 +1 @@ +-- No-op: we don't want to re-wipe block_hash values. diff --git a/store/migrations/000003_fix_immutable_block_hash.up.sql b/store/migrations/000003_fix_immutable_block_hash.up.sql new file mode 100644 index 0000000..57676a9 --- /dev/null +++ b/store/migrations/000003_fix_immutable_block_hash.up.sql @@ -0,0 +1,8 @@ +-- Repopulate block_hash on transactions that were wiped when transitioning to IMMUTABLE. +-- Joins through processed_blocks to ensure we use the canonical chain's block hash. +UPDATE transactions +SET block_hash = mp.block_hash +FROM merkle_paths mp +JOIN processed_blocks pb ON mp.block_hash = pb.block_hash AND pb.on_chain = 1 +WHERE transactions.txid = mp.txid + AND transactions.block_hash IS NULL; diff --git a/store/sqlite/sqlite.go b/store/sqlite/sqlite.go index a5d00e9..beb4147 100644 --- a/store/sqlite/sqlite.go +++ b/store/sqlite/sqlite.go @@ -161,18 +161,16 @@ func (s *Store) UpdateStatus(ctx context.Context, status *models.TransactionStat UPDATE transactions SET status = ?, timestamp = ?, - block_hash = ?, extra_info = ?, competing_txs = json_set(competing_txs, '$.' || ?, json('true')) WHERE txid = ? AND status NOT IN (%s) `, strings.Join(placeholders, ",")) - args = make([]interface{}, 0, 6+len(disallowed)) + args = make([]interface{}, 0, 5+len(disallowed)) args = append(args, status.Status, status.Timestamp, - nullString(status.BlockHash), nullString(status.ExtraInfo), status.CompetingTxs[0], status.TxID, @@ -190,17 +188,15 @@ WHERE txid = ? UPDATE transactions SET status = ?, timestamp = ?, - block_hash = ?, extra_info = ? WHERE txid = ? AND status NOT IN (%s) `, strings.Join(placeholders, ",")) - args = make([]interface{}, 0, 5+len(disallowed)) + args = make([]interface{}, 0, 4+len(disallowed)) args = append(args, status.Status, status.Timestamp, - nullString(status.BlockHash), nullString(status.ExtraInfo), status.TxID, )