commit 4faa54e7483a0cb2a33843b725f2a857be88583c
parent b23172286c615f2e3a72e8b960d07f4fe75d9d46
Author: Antoine A <>
Date: Tue, 13 Oct 2026 11:21:25 +0200
common: lock for commit ordered ids
Diffstat:
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -833,9 +833,9 @@ dependencies = [
[[package]]
name = "deranged"
-version = "0.5.8"
+version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
+checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
[[package]]
name = "derive_more"
diff --git a/depolymerizer-bitcoin/db/depolymerizer-bitcoin-procedures.sql b/depolymerizer-bitcoin/db/depolymerizer-bitcoin-procedures.sql
@@ -155,6 +155,8 @@ IF out_reserve_pub_reuse THEN
RETURN;
END IF;
+-- Lock for revenue id commit ordering
+LOCK TABLE tx_in IN SHARE ROW EXCLUSIVE MODE;
-- Insert new incoming transaction
INSERT INTO tx_in (
txid,
@@ -179,7 +181,9 @@ ELSIF in_type IS NOT NULL THEN
SET tx_in_id = out_tx_row_id
WHERE (tx_in_id IS NULL AND account_pub = in_metadata AND in_type=type AND type='reserve')
OR authorization_pub = local_authorization_pub;
- -- Insert new incoming talerable tranreceived_atsaction
+ -- Lock for incoming history id commit ordering
+ LOCK TABLE taler_in IN SHARE ROW EXCLUSIVE MODE;
+ -- Insert new incoming talerable transaction
INSERT INTO taler_in (
tx_in_id,
type,
@@ -308,6 +312,8 @@ IF in_confirmed THEN
END IF;
out_new = TRUE;
+ -- Lock for outgoing history id commit ordering
+ LOCK TABLE tx_out IN SHARE ROW EXCLUSIVE MODE;
-- Insert new outgoing transaction
INSERT INTO tx_out (
amount,
@@ -389,24 +395,23 @@ IF out_reserve_pub_reuse THEN
END IF;
IF in_recurrent THEN
- -- Finalize one pending right now
- WITH moved_tx AS (
- DELETE FROM pending_recurrent_in
- WHERE tx_in_id = (
- SELECT tx_in_id
- FROM pending_recurrent_in
- JOIN tx_in USING (tx_in_id)
- WHERE authorization_pub = in_authorization_pub
- ORDER BY received_at ASC
- LIMIT 1
- )
- RETURNING tx_in_id
+ -- Finalize one pending right now.
+ DELETE FROM pending_recurrent_in
+ WHERE tx_in_id = (
+ SELECT tx_in_id
+ FROM pending_recurrent_in
+ JOIN tx_in USING (tx_in_id)
+ WHERE authorization_pub = in_authorization_pub
+ ORDER BY received_at ASC
+ LIMIT 1
)
- INSERT INTO taler_in (tx_in_id, type, metadata, authorization_pub, authorization_sig)
- SELECT moved_tx.tx_in_id, in_type, in_account_pub, in_authorization_pub, in_authorization_sig
- FROM moved_tx
- RETURNING tx_in_id, taler_in_id INTO talerable_tx, local_taler_in_id;
+ RETURNING tx_in_id INTO talerable_tx;
IF talerable_tx IS NOT NULL THEN
+ -- Lock for incoming history id commit ordering
+ LOCK TABLE taler_in IN SHARE ROW EXCLUSIVE MODE;
+ INSERT INTO taler_in (tx_in_id, type, metadata, authorization_pub, authorization_sig)
+ VALUES (talerable_tx, in_type, in_account_pub, in_authorization_pub, in_authorization_sig)
+ RETURNING taler_in_id INTO local_taler_in_id;
PERFORM pg_notify('taler_in', local_taler_in_id::text);
END IF;
ELSE