diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-05-17 11:21:20 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-05-17 11:21:20 +0200 |
commit | d8f1f7b761a41fc027c53dcd85c2b07dd73c6d1b (patch) | |
tree | 40a92a23af452f01af6260f4de138438cb46cc0d /src/exchangedb | |
parent | 802649c2703cb1b9991316073ca0b9e20cebe16f (diff) | |
download | exchange-d8f1f7b761a41fc027c53dcd85c2b07dd73c6d1b.tar.xz |
integrate purse expiration into test, bugfixes
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/common-0001.sql | 8 | ||||
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 29 |
2 files changed, 21 insertions, 16 deletions
diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql index 05394246c..cb64f446e 100644 --- a/src/exchangedb/common-0001.sql +++ b/src/exchangedb/common-0001.sql @@ -1193,6 +1193,14 @@ BEGIN '(merge_pub);' ); + -- FIXME: drop index on master (crosses shards)? + -- Or use materialized index? (needed?) + EXECUTE FORMAT ( + 'CREATE INDEX IF NOT EXISTS ' || table_name || '_purse_expiration ' + 'ON ' || table_name || ' ' + '(purse_expiration);' + ); + END $$; diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index 97c26cb05..1b1d2a38e 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -2505,8 +2505,7 @@ UPDATE known_coins THEN 1 ELSE 0 END - WHERE coin_pub=in_coin_pub - LIMIT 1; -- just to be extra safe + WHERE coin_pub=in_coin_pub; out_conflict=FALSE; @@ -3363,7 +3362,6 @@ END $$; CREATE OR REPLACE FUNCTION exchange_do_expire_purse( - IN in_partner_id INT8, IN in_start_time INT8, IN in_end_time INT8, OUT out_found BOOLEAN) @@ -3375,25 +3373,26 @@ DECLARE my_deposit record; BEGIN -UPDATE purse_requests - SET refunded=TRUE, - finished=TRUE +SELECT purse_pub + INTO my_purse_pub + FROM purse_requests WHERE (purse_expiration >= in_start_time) AND (purse_expiration < in_end_time) AND (NOT finished) AND (NOT refunded) - RETURNING purse_pub - ,in_reserve_quota - ,flags - INTO my_purse_pub - ,my_rq - ,my_flags; + ORDER BY purse_expiration ASC + LIMIT 1; out_found = FOUND; IF NOT FOUND THEN RETURN; END IF; +UPDATE purse_requests + SET refunded=TRUE, + finished=TRUE + WHERE purse_pub=my_purse_pub; + -- restore balance to each coin deposited into the purse FOR my_deposit IN SELECT coin_pub @@ -3402,7 +3401,7 @@ FOR my_deposit IN FROM purse_deposits WHERE purse_pub = my_purse_pub LOOP - UPDATE + UPDATE known_coins SET remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac - CASE WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000 @@ -3415,9 +3414,7 @@ LOOP THEN 1 ELSE 0 END - FROM known_coins - WHERE coin_pub = my_deposit.coin_pub - LIMIT 1; -- just to be extra safe + WHERE coin_pub = my_deposit.coin_pub; END LOOP; END $$; |