aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-10-12 22:16:40 +0200
committerChristian Grothoff <christian@grothoff.org>2022-10-12 22:16:40 +0200
commit4702b156dc8130a842745035c936de8817c7c700 (patch)
treef1c2d6c9013d2fa904c82b6cbc2b1effb9c6e16a /src/exchangedb
parent3b34acdb72cd450974a3bbde6169f1bf9644a302 (diff)
downloadexchange-4702b156dc8130a842745035c936de8817c7c700.tar.xz
-work on reserve control tests
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/common-0001.sql5
-rw-r--r--src/exchangedb/exchange-0001-part.sql4
-rw-r--r--src/exchangedb/pg_insert_records_by_table.c7
-rw-r--r--src/exchangedb/procedures.sql41
4 files changed, 33 insertions, 24 deletions
diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql
index 21f531102..68d8643ed 100644
--- a/src/exchangedb/common-0001.sql
+++ b/src/exchangedb/common-0001.sql
@@ -460,8 +460,7 @@ BEGIN
'CREATE TABLE IF NOT EXISTS %I'
'(reserve_open_deposit_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE / PRIMARY KEY'
',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=32)'
- ',request_timestamp INT8 NOT NULL'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
',contribution_val INT8 NOT NULL'
@@ -482,7 +481,7 @@ BEGIN
EXECUTE FORMAT (
'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve '
'ON ' || table_name || ' '
- '(reserve_pub,request_timestamp);'
+ '(reserve_pub);'
);
END
$$;
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
index c9c3e2f04..48515a478 100644
--- a/src/exchangedb/exchange-0001-part.sql
+++ b/src/exchangedb/exchange-0001-part.sql
@@ -259,8 +259,8 @@ SELECT create_table_reserves_open_deposits();
COMMENT ON TABLE reserves_open_deposits
IS 'coin contributions paying for a reserve to remain open';
-COMMENT ON COLUMN reserves_open_deposits.request_timestamp
- IS 'Identifies the specific reserve open request being paid for.';
+COMMENT ON COLUMN reserves_open_deposits.reserve_pub
+ IS 'Identifies the specific reserve being paid for (possibly together with reserve_sig).';
CREATE TABLE IF NOT EXISTS reserves_open_deposits_default
PARTITION OF reserves_open_deposits
diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c
index f70cce225..90d389873 100644
--- a/src/exchangedb/pg_insert_records_by_table.c
+++ b/src/exchangedb/pg_insert_records_by_table.c
@@ -358,8 +358,6 @@ irbt_cb_table_reserves_open_requests (struct PostgresClosure *pg,
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&td->serial),
GNUNET_PQ_query_param_timestamp (
- &td->details.reserves_open_requests.request_timestamp),
- GNUNET_PQ_query_param_timestamp (
&td->details.reserves_open_requests.expiration_date),
GNUNET_PQ_query_param_auto_from_type (
&td->details.reserves_open_requests.reserve_sig),
@@ -402,8 +400,6 @@ irbt_cb_table_reserves_open_deposits (
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_timestamp (
- &td->details.reserves_open_deposits.request_timestamp),
GNUNET_PQ_query_param_auto_from_type (
&td->details.reserves_open_deposits.coin_pub),
GNUNET_PQ_query_param_auto_from_type (
@@ -421,13 +417,12 @@ irbt_cb_table_reserves_open_deposits (
"(reserve_open_deposit_uuid"
",reserve_sig"
",reserve_pub"
- ",request_timestamp"
",coin_pub"
",coin_sig"
",contribution_val"
",contribution_frac"
") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8);");
+ "($1, $2, $3, $4, $5, $6, $7);");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_into_table_reserves_open_deposits",
params);
diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql
index 90fb7d321..912a37dbc 100644
--- a/src/exchangedb/procedures.sql
+++ b/src/exchangedb/procedures.sql
@@ -2119,7 +2119,6 @@ BEGIN
INSERT INTO exchange.reserves_open_deposits
(reserve_sig
,reserve_pub
- ,request_timestamp
,coin_pub
,coin_sig
,contribution_val
@@ -2128,7 +2127,6 @@ INSERT INTO exchange.reserves_open_deposits
VALUES
(in_reserve_sig
,in_reserve_pub
- ,in_request_timestamp
,in_coin_pub
,in_coin_sig
,in_coin_total_val
@@ -2237,8 +2235,9 @@ WHERE
IF NOT FOUND
THEN
- -- FIXME: do we need to set a 'not found'?
- RETURN;
+ -- FIXME: do we need to set a 'not found'?
+ RAISE NOTICE 'reserve not found';
+ RETURN;
END IF;
-- Do not allow expiration time to start in the past already
@@ -2272,9 +2271,10 @@ THEN
my_purses_allowed = my_purses_allowed + (in_default_purse_limit * my_years_tmp);
END IF;
+
-- Compute cost based on annual fees
IF (my_years > 0)
-THEN
+THEN
my_cost_val = my_years * in_open_fee_val;
my_cost_tmp = my_years * in_open_fee_frac / 100000000;
IF (CAST (my_cost_val + my_cost_tmp AS INT8) < my_cost_val)
@@ -2282,8 +2282,9 @@ THEN
out_open_cost_val=9223372036854775807;
out_open_cost_frac=2147483647;
out_final_expiration=my_expiration_date;
- out_no_funds=true;
- RETURN;
+ out_no_funds=FALSE;
+ RAISE NOTICE 'arithmetic issue computing amount';
+ RETURN;
END IF;
my_cost_val = CAST (my_cost_val + my_cost_tmp AS INT8);
my_cost_frac = my_years * in_open_fee_frac % 100000000;
@@ -2297,6 +2298,7 @@ THEN
out_open_cost_val = 0;
out_open_cost_frac = 0;
out_no_funds=FALSE;
+ RAISE NOTICE 'no change required';
RETURN;
END IF;
@@ -2305,10 +2307,22 @@ IF ( (in_total_paid_val < my_cost_val) OR
( (in_total_paid_val = my_cost_val) AND
(in_total_paid_frac < my_cost_frac) ) )
THEN
- out_final_expiration=my_reserve_expiration;
out_open_cost_val = my_cost_val;
out_open_cost_frac = my_cost_frac;
- out_no_funds=TRUE;
+ out_no_funds=FALSE;
+ -- We must return a failure, which is indicated by
+ -- the expiration being below the desired expiration.
+ IF (my_reserve_expiration >= in_desired_expiration)
+ THEN
+ -- This case is relevant especially if the purse
+ -- count was to be increased and the payment was
+ -- insufficient to cover this for the full period.
+ RAISE NOTICE 'forcing low expiration time';
+ out_final_expiration = 0;
+ ELSE
+ out_final_expiration = my_reserve_expiration;
+ END IF;
+ RAISE NOTICE 'amount paid too low';
RETURN;
END IF;
@@ -2329,11 +2343,12 @@ ELSE
my_balance_val=0;
my_balance_frac=my_balance_frac - in_reserve_payment_frac;
ELSE
- out_final_expiration=my_reserve_expiration;
+ out_final_expiration = my_reserve_expiration;
out_open_cost_val = my_cost_val;
out_open_cost_frac = my_cost_frac;
out_no_funds=TRUE;
- RETURN;
+ RAISE NOTICE 'reserve balance too low';
+ RETURN;
END IF;
END IF;
@@ -2341,12 +2356,12 @@ UPDATE reserves SET
current_balance_val=my_balance_val
,current_balance_frac=my_balance_frac
,gc_date=my_reserve_expiration + in_reserve_gc_delay
- ,expiration_date=my_reserve_expiration
+ ,expiration_date=my_expiration_date
,purses_allowed=my_purses_allowed
WHERE
reserve_pub=in_reserve_pub;
-out_final_expiration=my_reserve_expiration;
+out_final_expiration=my_expiration_date;
out_open_cost_val = my_cost_val;
out_open_cost_frac = my_cost_frac;
out_no_funds=FALSE;