[age-withdraw] WIP: change schema to use new support for array types, 11/n

This commit is contained in:
Özgür Kesim 2023-05-12 15:10:23 +02:00
parent 5ee567d1ba
commit a04425df34
Signed by: oec
GPG Key ID: 3D76A56D79EDD9D7
6 changed files with 50 additions and 44 deletions

View File

@ -466,10 +466,12 @@ batch_withdraw_transaction (void *cls,
return qs; return qs;
} }
wc->kyc.ok = true; wc->kyc.ok = true;
qs = TEH_plugin->do_batch_withdraw (TEH_plugin->cls, qs = TEH_plugin->do_batch_withdraw (TEH_plugin->cls,
wc->now, wc->now,
wc->reserve_pub, wc->reserve_pub,
&wc->batch_total, &wc->batch_total,
/* TODO[oec]: add parameter for maximum age and [out]parameter for required age */
&found, &found,
&balance_ok, &balance_ok,
&ruuid); &ruuid);
@ -493,6 +495,9 @@ batch_withdraw_transaction (void *cls,
NULL); NULL);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
/* TODO[oec]: add error handling for age restriction requirements */
if (! balance_ok) if (! balance_ok)
{ {
TEH_plugin->rollback (TEH_plugin->cls); TEH_plugin->rollback (TEH_plugin->cls);

View File

@ -26,20 +26,22 @@ BEGIN
PERFORM create_partitioned_table( PERFORM create_partitioned_table(
'CREATE TABLE %I' 'CREATE TABLE %I'
'(age_withdraw_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY' '(age_withdraw_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
',h_commitment BYTEA CHECK (LENGTH(h_commitment)=64)' ',h_commitment BYTEA NOT NULL CONSTRAINT h_commitment_length CHECK(LENGTH(h_commitment)=64)'
',amount_with_fee_val INT8 NOT NULL' ',max_age SMALLINT NOT NULL CONSTRAINT max_age_positive CHECK(max_age>=0)'
',amount_with_fee_frac INT4 NOT NULL' ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length CHECK(LENGTH(reserve_pub)=32)'
',max_age INT2 NOT NULL' ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length CHECK(LENGTH(reserve_sig)=64)'
',reserve_pub BYTEA CHECK (LENGTH(reserve_pub)=32)' ',num_coins SMALLINT NOT NULL CONSTRAINT num_coins_positive CHECK(num_coins>0)'
',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)' ',denominations_serials INT8[] NOT NULL CONSTRAINT denominations_serial_array_length CHECK(cardinality(denominations_serials)=num_coins)'
',noreveal_index INT4 NOT NULL' ',denom_sigs BYTEA[] NOT NULL CONSTRAINT denom_sigs_array_length CHECK(cardinality(denom_sigs)=num_coins)'
',noreveal_index SMALLINT NOT NULL CONSTRAINT noreveal_index_positive CHECK(noreveal_index>=0)'
') %s ;' ') %s ;'
,table_name ,table_name
,'PARTITION BY HASH (reserve_pub)' ,'PARTITION BY HASH (reserve_pub)'
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_table( PERFORM comment_partitioned_table(
'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange.' 'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange. '
'It also contains the blindly signed coins and related denominations.'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
@ -68,11 +70,29 @@ BEGIN
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Signature of the reserve''s private key over the withdraw-age request' 'Signature of the reserve''s private key over the age-withdraw request'
,'reserve_sig' ,'reserve_sig'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
PERFORM comment_partinioned_column(
'Number of coins to be withdrawn'
,'num_coins'
,table_name
,partition_suffix
);
PERFORM comment_partitioned_column(
'Array of #num_coins of references to the denominations'
,'denominations_serials'
,table_name
,partition_suffix
);
PERFORM comment_partitioned_column(
'Array of #num_coins signatures over the blinded envelopes'
,'denom_sigs'
,table_name
,partition_suffix
);
END END
$$; $$;

View File

@ -27,14 +27,11 @@ BEGIN
'CREATE TABLE %I' 'CREATE TABLE %I'
'(age_withdraw_revealed_coins_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE '(age_withdraw_revealed_coins_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
',h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=64)' ',h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=64)'
',freshcoin_index INT4 NOT NULL' ',coin_index INT4 NOT NULL'
',denominations_serial INT8 NOT NULL'
',coin_ev BYTEA NOT NULL'
',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=64)' ',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=64)'
',ev_sig BYTEA NOT NULL'
') %s ;' ') %s ;'
,table_name ,table_name
,'PARTITION BY HASH (h_commitment)' ,'PARTITION BY HASH (h_coin_ev)'
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_table( PERFORM comment_partitioned_table(
@ -49,35 +46,17 @@ BEGIN
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Index of the coin in the withdraw-age request, which is implicitly a batch request' 'Index of the coin in the age-withdraw request, which is implicitly a batch request'
,'freshcoin_index' ,'coin_index'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column( PERFORM comment_partitioned_column(
'Foreign key reference to the denominations' 'Hash of the envelope of the new coin to be signed (for lookups). The corresponding signatures are stores in age_withdraw_commitments.denom_sigs.'
,'denominations_serial'
,table_name
,partition_suffix
);
PERFORM comment_partitioned_column(
'Envelope of the new coin to be signed'
,'coin_ev'
,table_name
,partition_suffix
);
PERFORM comment_partitioned_column(
'Hash of the envelope of the new coin to be signed (for lookups)'
,'h_coin_ev' ,'h_coin_ev'
,table_name ,table_name
,partition_suffix ,partition_suffix
); );
PERFORM comment_partitioned_column(
'Exchange signature over the envelope'
,'ev_sig'
,table_name
,partition_suffix
);
END END
$$; $$;
@ -118,12 +97,6 @@ BEGIN
' FOREIGN KEY (h_commitment)' ' FOREIGN KEY (h_commitment)'
' REFERENCES age_withdraw_commitments (h_commitment) ON DELETE CASCADE;' ' REFERENCES age_withdraw_commitments (h_commitment) ON DELETE CASCADE;'
); );
EXECUTE FORMAT (
'ALTER TABLE ' || table_name ||
' ADD CONSTRAINT ' || table_name || '_foreign_denominations_serial'
' FOREIGN KEY (denominations_serial) '
' REFERENCES denominations (denominations_serial) ON DELETE CASCADE;'
);
END END
$$; $$;

View File

@ -20,6 +20,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
IN rpub BYTEA, IN rpub BYTEA,
IN now INT8, IN now INT8,
IN min_reserve_gc INT8, IN min_reserve_gc INT8,
-- TODO[oec]: add [IN] parameter for maximum age and [OUT] parameter for required age
OUT reserve_found BOOLEAN, OUT reserve_found BOOLEAN,
OUT balance_ok BOOLEAN, OUT balance_ok BOOLEAN,
OUT ruuid INT8) OUT ruuid INT8)
@ -38,11 +39,13 @@ BEGIN
-- reserves_in by reserve_pub (SELECT) -- reserves_in by reserve_pub (SELECT)
-- wire_targets by wire_target_h_payto -- wire_targets by wire_target_h_payto
SELECT SELECT
current_balance_val current_balance_val
,current_balance_frac ,current_balance_frac
,gc_date ,gc_date
,reserve_uuid ,reserve_uuid
-- TODO[oec]: get age requirements
INTO INTO
reserve_val reserve_val
,reserve_frac ,reserve_frac
@ -60,6 +63,8 @@ THEN
RETURN; RETURN;
END IF; END IF;
-- TODO[oec]: check age requirements
-- Check reserve balance is sufficient. -- Check reserve balance is sufficient.
IF (reserve_val > amount_val) IF (reserve_val > amount_val)
THEN THEN
@ -99,6 +104,7 @@ balance_ok=TRUE;
END $$; END $$;
-- TODO[oec]: Update comment re: age requirements are implemented
COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8) COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8)
IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.'; IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.';

View File

@ -15,7 +15,7 @@
-- --
-- TODO[oec]: add min. age requirements handling
CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert( CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert(
IN cs_nonce BYTEA, IN cs_nonce BYTEA,

View File

@ -31,6 +31,7 @@ TEH_PG_do_batch_withdraw (
void *cls, void *cls,
struct GNUNET_TIME_Timestamp now, struct GNUNET_TIME_Timestamp now,
const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReservePublicKeyP *reserve_pub,
/* TODO[oec]: add parameter for maximum age and [out]parameter for required age */
const struct TALER_Amount *amount, const struct TALER_Amount *amount,
bool *found, bool *found,
bool *balance_ok, bool *balance_ok,
@ -68,6 +69,7 @@ TEH_PG_do_batch_withdraw (
" reserve_found" " reserve_found"
",balance_ok" ",balance_ok"
",ruuid" ",ruuid"
/* TODO[oec]: add parameter for maximum age and [out] parameter for required age */
" FROM exchange_do_batch_withdraw" " FROM exchange_do_batch_withdraw"
" ($1,$2,$3,$4,$5);"); " ($1,$2,$3,$4,$5);");
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,