diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-03-19 01:36:15 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-03-19 01:36:15 +0100 |
commit | c75ac3b61295e380f8ea59a75d26426fefe2e4f9 (patch) | |
tree | 151a6283171e7503d60e47102e3359866b2dee64 /src/exchangedb | |
parent | b42ce7e80a1cc342722e3634c687fcb148f511d0 (diff) |
revise exchangedb structure eliminating duplicated wire transfer date from aggregations, instead joining it from wire_out when needed
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 27 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 56 |
2 files changed, 37 insertions, 46 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index c975edcff..f57ac5a29 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -226,11 +226,11 @@ postgres_drop_tables (void *cls) SQLEXEC_ (conn, "DROP TABLE IF EXISTS aggregation_tracking;"); SQLEXEC_ (conn, - "DROP TABLE IF EXISTS wire_out;"); + "DROP TABLE IF EXISTS wire_out CASCADE;"); SQLEXEC_ (conn, "DROP TABLE IF EXISTS wire_fee;"); SQLEXEC_ (conn, - "DROP TABLE IF EXISTS deposits;"); + "DROP TABLE IF EXISTS deposits CASCADE;"); SQLEXEC_ (conn, "DROP TABLE IF EXISTS refresh_out;"); SQLEXEC_ (conn, @@ -250,7 +250,7 @@ postgres_drop_tables (void *cls) SQLEXEC_ (conn, "DROP TABLE IF EXISTS reserves_in;"); SQLEXEC_ (conn, - "DROP TABLE IF EXISTS reserves;"); + "DROP TABLE IF EXISTS reserves CASCADE;"); SQLEXEC_ (conn, "DROP TABLE IF EXISTS denominations CASCADE;"); PQfinish (conn); @@ -493,7 +493,6 @@ postgres_create_tables (void *cls) "(aggregation_serial_id BIGSERIAL" ",deposit_serial_id INT8 PRIMARY KEY REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE" ",wtid_raw BYTEA CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE" - ",execution_time INT8 NOT NULL" ")"); /* Index for lookup_transactions statement on wtid */ SQLEXEC_INDEX("CREATE INDEX aggregation_tracking_wtid_index " @@ -1242,7 +1241,7 @@ postgres_prepare (PGconn *db_conn) ",deposits.h_wire" ",deposits.coin_pub" ",deposits.merchant_pub" - ",execution_time" + ",wire_out.execution_date" ",deposits.amount_with_fee_val" ",deposits.amount_with_fee_frac" ",deposits.amount_with_fee_curr" @@ -1253,6 +1252,7 @@ postgres_prepare (PGconn *db_conn) " JOIN deposits USING (deposit_serial_id)" " JOIN known_coins USING (coin_pub)" " JOIN denominations denom USING (denom_pub)" + " JOIN wire_out USING (wtid_raw)" " WHERE wtid_raw=$1", 1, NULL); @@ -1260,7 +1260,7 @@ postgres_prepare (PGconn *db_conn) PREPARE ("lookup_deposit_wtid", "SELECT" " aggregation_tracking.wtid_raw" - ",aggregation_tracking.execution_time" + ",wire_out.execution_date" ",amount_with_fee_val" ",amount_with_fee_frac" ",amount_with_fee_curr" @@ -1271,6 +1271,7 @@ postgres_prepare (PGconn *db_conn) " JOIN aggregation_tracking USING (deposit_serial_id)" " JOIN known_coins USING (coin_pub)" " JOIN denominations denom USING (denom_pub)" + " JOIN wire_out USING (wtid_raw)" " WHERE coin_pub=$1" " AND h_proposal_data=$2" " AND h_wire=$3" @@ -1282,10 +1283,9 @@ postgres_prepare (PGconn *db_conn) "INSERT INTO aggregation_tracking " "(deposit_serial_id" ",wtid_raw" - ",execution_time" /* TODO: this field should be eliminated and obtained from wire_out */ ") VALUES " - "($1, $2, $3)", - 3, NULL); + "($1, $2)", + 2, NULL); /* Used in #postgres_get_wire_fee() */ PREPARE ("get_wire_fee", @@ -4087,7 +4087,7 @@ postgres_lookup_wire_transfer (void *cls, GNUNET_PQ_result_spec_auto_from_type ("h_wire", &h_wire), GNUNET_PQ_result_spec_auto_from_type ("coin_pub", &coin_pub), GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", &merchant_pub), - GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time), + GNUNET_PQ_result_spec_absolute_time ("execution_date", &exec_time), TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee), TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee), GNUNET_PQ_result_spec_end @@ -4261,7 +4261,7 @@ postgres_wire_lookup_deposit_wtid (void *cls, struct TALER_Amount deposit_fee; struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_auto_from_type ("wtid_raw", &wtid), - GNUNET_PQ_result_spec_absolute_time ("execution_time", &exec_time), + GNUNET_PQ_result_spec_absolute_time ("execution_date", &exec_time), TALER_PQ_result_spec_amount ("amount_with_fee", &amount_with_fee), TALER_PQ_result_spec_amount ("fee_deposit", &deposit_fee), GNUNET_PQ_result_spec_end @@ -4293,21 +4293,18 @@ postgres_wire_lookup_deposit_wtid (void *cls, * @param session database connection * @param wtid the raw wire transfer identifier we used * @param deposit_serial_id row in the deposits table for which this is aggregation data - * @param execution_time when did we execute the transaction * @return #GNUNET_OK on success, #GNUNET_SYSERR on DB errors */ static int postgres_insert_aggregation_tracking (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_WireTransferIdentifierRawP *wtid, - unsigned long long deposit_serial_id, - struct GNUNET_TIME_Absolute execution_time) + unsigned long long deposit_serial_id) { uint64_t rid = deposit_serial_id; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_uint64 (&rid), GNUNET_PQ_query_param_auto_from_type (wtid), - GNUNET_PQ_query_param_absolute_time (&execution_time), GNUNET_PQ_query_param_end }; PGresult *result; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 93614ecb6..d645abeae 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -787,8 +787,8 @@ static struct TALER_CoinSpendPublicKeyP coin_pub_wt; static struct TALER_Amount coin_value_wt; static struct TALER_Amount coin_fee_wt; static struct TALER_Amount transfer_value_wt; -static struct GNUNET_TIME_Absolute execution_time_wt; -static struct TALER_WireTransferIdentifierRawP wtid_wt; +static struct GNUNET_TIME_Absolute wire_out_date; +static struct TALER_WireTransferIdentifierRawP wire_out_wtid; /** @@ -815,7 +815,7 @@ cb_wt_check (void *cls, GNUNET_assert (0 == memcmp (h_wire, &h_wire_wt, sizeof (struct GNUNET_HashCode))); - GNUNET_assert (exec_time.abs_value_us == execution_time_wt.abs_value_us); + GNUNET_assert (exec_time.abs_value_us == wire_out_date.abs_value_us); GNUNET_assert (0 == memcmp (h_proposal_data, &h_proposal_data_wt, sizeof (struct GNUNET_HashCode))); @@ -841,10 +841,10 @@ cb_wtid_check (void *cls, { GNUNET_assert (cls == &cb_wtid_never); GNUNET_assert (0 == memcmp (wtid, - &wtid_wt, + &wire_out_wtid, sizeof (struct TALER_WireTransferIdentifierRawP))); GNUNET_assert (execution_time.abs_value_us == - execution_time_wt.abs_value_us); + wire_out_date.abs_value_us); GNUNET_assert (0 == TALER_amount_cmp (coin_contribution, &coin_value_wt)); GNUNET_assert (0 == TALER_amount_cmp (coin_fee, @@ -1185,10 +1185,6 @@ test_wire_fees (struct TALER_EXCHANGEDB_Session *session) } -static struct GNUNET_TIME_Absolute wire_out_date; - -static struct TALER_WireTransferIdentifierRawP wire_out_wtid; - static json_t *wire_out_account; static struct TALER_Amount wire_out_amount; @@ -1256,7 +1252,7 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, h_wire_wt = deposit->h_wire; h_proposal_data_wt = deposit->h_proposal_data; coin_pub_wt = deposit->coin.coin_pub; - execution_time_wt = GNUNET_TIME_absolute_get (); + coin_value_wt = deposit->amount_with_fee; coin_fee_wt = fee_deposit; GNUNET_assert (GNUNET_OK == @@ -1266,7 +1262,7 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, FAILIF (GNUNET_NO != plugin->lookup_wire_transfer (plugin->cls, session, - &wtid_wt, + &wire_out_wtid, &cb_wt_never, NULL)); @@ -1284,18 +1280,31 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, &cb_wtid_never, NULL)); } - wtid_wt = wire_out_wtid; /* to statisfy foreign constraint */ /* insert WT data */ FAILIF (GNUNET_OK != plugin->insert_aggregation_tracking (plugin->cls, session, - &wtid_wt, - deposit_rowid, - execution_time_wt)); + &wire_out_wtid, + deposit_rowid)); + + /* Now let's fix the transient constraint violation by + putting in the WTID into the wire_out table */ + FAILIF (GNUNET_OK != + plugin->store_wire_transfer_out (plugin->cls, + session, + wire_out_date, + &wire_out_wtid, + wire_out_account, + &wire_out_amount)); + /* And now the commit should still succeed! */ + FAILIF (GNUNET_OK != + plugin->commit (plugin->cls, + session)); + FAILIF (GNUNET_OK != plugin->lookup_wire_transfer (plugin->cls, session, - &wtid_wt, + &wire_out_wtid, &cb_wt_check, &cb_wt_never)); FAILIF (GNUNET_OK != @@ -1307,16 +1316,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, &merchant_pub_wt, &cb_wtid_check, &cb_wtid_never)); - - /* Now let's fix the transient constraint violation by - putting in the WTID into the wire_out table */ - FAILIF (GNUNET_OK != - plugin->store_wire_transfer_out (plugin->cls, - session, - wire_out_date, - &wire_out_wtid, - wire_out_account, - &wire_out_amount)); FAILIF (GNUNET_OK != plugin->select_wire_out_above_serial_id (plugin->cls, session, @@ -1325,11 +1324,6 @@ test_wire_out (struct TALER_EXCHANGEDB_Session *session, NULL)); FAILIF (1 != auditor_row_cnt); - /* And now the commit should still succeed! */ - FAILIF (GNUNET_OK != - plugin->commit (plugin->cls, - session)); - return GNUNET_OK; drop: return GNUNET_SYSERR; |