adding a few more uniqueness constraints to DB

This commit is contained in:
Christian Grothoff 2016-05-31 09:13:03 +02:00
parent ef81e9db22
commit 94e1679955
5 changed files with 69 additions and 37 deletions

View File

@ -22,12 +22,12 @@ pkgcfg_DATA = \
EXTRA_DIST = \
taler.conf
SUBDIRS = include util json $(PQ_DIR) $(BANK_LIB) wire exchangedb exchange exchange-tools benchmark
SUBDIRS = include util json $(PQ_DIR) $(BANK_LIB) wire exchangedb exchange exchange-tools
if HAVE_LIBCURL
SUBDIRS += exchange-lib
SUBDIRS += exchange-lib benchmark
else
if HAVE_LIBGNURL
SUBDIRS += exchange-lib
SUBDIRS += exchange-lib benchmark
endif
endif

View File

@ -645,7 +645,7 @@ run_test ()
.label = "do-deposit-2a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 2,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:1",
.details.deposit.deposit_fee = "EUR:0.1"
@ -655,7 +655,7 @@ run_test ()
.label = "do-deposit-2b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 3,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:1",
.details.deposit.deposit_fee = "EUR:0.1"
@ -683,7 +683,7 @@ run_test ()
.label = "do-deposit-3a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 4,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:1",
.details.deposit.deposit_fee = "EUR:0.1"
@ -693,7 +693,7 @@ run_test ()
.label = "do-deposit-3b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 5,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 5,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:1",
.details.deposit.deposit_fee = "EUR:0.1"
@ -744,7 +744,7 @@ run_test ()
.label = "do-deposit-4a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 6,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.2",
.details.deposit.deposit_fee = "EUR:0.1"
@ -754,7 +754,7 @@ run_test ()
.label = "do-deposit-4b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 7,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.2",
.details.deposit.deposit_fee = "EUR:0.1"
@ -790,7 +790,7 @@ run_test ()
.label = "do-deposit-5a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 8,
.details.deposit.wire_deadline = { 1000LL * 1000 * 10 }, /* 10s */
.details.deposit.amount_with_fee = "EUR:0.2",
.details.deposit.deposit_fee = "EUR:0.1"
@ -800,7 +800,7 @@ run_test ()
.label = "do-deposit-5b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 9,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.2",
.details.deposit.deposit_fee = "EUR:0.1"
@ -836,7 +836,7 @@ run_test ()
.label = "do-deposit-6a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 10,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.102",
.details.deposit.deposit_fee = "EUR:0.1"
@ -854,7 +854,7 @@ run_test ()
.label = "do-deposit-6b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 11,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.102",
.details.deposit.deposit_fee = "EUR:0.1"
@ -864,7 +864,7 @@ run_test ()
.label = "do-deposit-6c",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 12,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.102",
.details.deposit.deposit_fee = "EUR:0.1"
@ -882,7 +882,7 @@ run_test ()
.label = "do-deposit-6d",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 13,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.102",
.details.deposit.deposit_fee = "EUR:0.1"
@ -900,7 +900,7 @@ run_test ()
.label = "do-deposit-6e",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 14,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.102",
.details.deposit.deposit_fee = "EUR:0.1"
@ -923,7 +923,7 @@ run_test ()
.label = "do-deposit-7a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 15,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.109",
.details.deposit.deposit_fee = "EUR:0.1"
@ -941,7 +941,7 @@ run_test ()
.label = "do-deposit-7b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 16,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.109",
.details.deposit.deposit_fee = "EUR:0.1"
@ -963,7 +963,7 @@ run_test ()
.label = "do-deposit-7c",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 17,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.122",
.details.deposit.deposit_fee = "EUR:0.1"
@ -986,7 +986,7 @@ run_test ()
.label = "do-deposit-8a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 18,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.109",
.details.deposit.deposit_fee = "EUR:0.1"
@ -1004,7 +1004,7 @@ run_test ()
.label = "do-deposit-8b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 19,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.109",
.details.deposit.deposit_fee = "EUR:0.1"
@ -1023,7 +1023,7 @@ run_test ()
.label = "do-deposit-8c",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 20,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.122",
.details.deposit.deposit_fee = "EUR:0.1"
@ -1047,7 +1047,7 @@ run_test ()
.label = "do-deposit-9a",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 21,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.104",
.details.deposit.deposit_fee = "EUR:0.1"
@ -1065,7 +1065,7 @@ run_test ()
.label = "do-deposit-9b",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 22,
.details.deposit.wire_deadline = { 1000LL * 1000 * 5 }, /* 5s */
.details.deposit.amount_with_fee = "EUR:0.105",
.details.deposit.deposit_fee = "EUR:0.1"
@ -1084,7 +1084,7 @@ run_test ()
.label = "do-deposit-9c",
.details.deposit.merchant_name = "bob",
.details.deposit.merchant_account = 4,
.details.deposit.transaction_id = 1,
.details.deposit.transaction_id = 23,
.details.deposit.wire_deadline = { 1000LL * 1000 * 0 }, /* 0s */
.details.deposit.amount_with_fee = "EUR:0.112",
.details.deposit.deposit_fee = "EUR:0.1"

View File

@ -295,6 +295,8 @@ postgres_create_tables (void *cls)
/* index on reserves table */
SQLEXEC_INDEX ("CREATE INDEX reserves_reserve_pub_index ON "
"reserves (reserve_pub)");
SQLEXEC_INDEX ("CREATE INDEX reserves_expiration_index"
" ON reserves (expiration_date);");
/* reserves_in table collects the transactions which transfer funds
into the reserve. The rows of this table correspond to each
incoming transaction. */
@ -306,14 +308,10 @@ postgres_create_tables (void *cls)
",sender_account_details TEXT NOT NULL "
",transfer_details TEXT NOT NULL "
",execution_date INT8 NOT NULL"
",PRIMARY KEY (reserve_pub,transfer_details)"
",PRIMARY KEY (reserve_pub, transfer_details)"
");");
/* Create indices on reserves_in */
SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_index"
" ON reserves_in (reserve_pub);");
SQLEXEC_INDEX ("CREATE INDEX reserves_in_reserve_pub_details_index"
" ON reserves_in (reserve_pub,details);");
SQLEXEC_INDEX ("CREATE INDEX execution_index"
SQLEXEC_INDEX ("CREATE INDEX reserves_in_execution_index"
" ON reserves_in (execution_date);");
/* Table with the withdraw operations that have been performed on a reserve.
The 'h_blind_ev' is the hash of the blinded coin. It serves as a primary
@ -334,8 +332,8 @@ postgres_create_tables (void *cls)
/* Index blindcoins(reserve_pub) for get_reserves_out statement */
SQLEXEC_INDEX ("CREATE INDEX reserves_out_reserve_pub_index ON"
" reserves_out (reserve_pub)");
SQLEXEC_INDEX ("CREATE INDEX reserves_out_h_blind_ev_index ON "
"reserves_out (h_blind_ev)");
SQLEXEC_INDEX ("CREATE INDEX reserves_out_execution_date ON "
"reserves_out (execution_date)");
/* Table with coins that have been (partially) spent, used to track
coin information only once. */
SQLEXEC("CREATE TABLE IF NOT EXISTS known_coins "
@ -382,9 +380,10 @@ postgres_create_tables (void *cls)
",transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)"
",link_secret_enc BYTEA NOT NULL CHECK(LENGTH(link_secret_enc)=64)"
",cnc_index INT2 NOT NULL"
",UNIQUE (session_hash, cnc_index)"
")");
SQLEXEC_INDEX("CREATE INDEX refresh_commit_link_session_hash_index "
"ON refresh_commit_link(session_hash,cnc_index)");
"ON refresh_commit_link(session_hash, cnc_index)");
/* Table with the commitments for the new coins that are to be created
during a melting session. Includes the session, the cut-and-choose
@ -398,9 +397,10 @@ postgres_create_tables (void *cls)
",newcoin_index INT2 NOT NULL"
",link_vector_enc BYTEA NOT NULL CHECK(LENGTH(link_vector_enc)=64)"
",coin_ev BYTEA NOT NULL"
",UNIQUE (session_hash, cnc_index, newcoin_index)"
")");
SQLEXEC_INDEX("CREATE INDEX refresh_commit_coin_session_hash_index "
"ON refresh_commit_coin(session_hash,cnc_index,newcoin_index)");
"ON refresh_commit_coin(session_hash, cnc_index, newcoin_index)");
/* Table with the signatures over coins generated during a refresh
@ -410,9 +410,10 @@ postgres_create_tables (void *cls)
"(session_hash BYTEA NOT NULL REFERENCES refresh_sessions (session_hash) ON DELETE CASCADE"
",newcoin_index INT2 NOT NULL"
",ev_sig BYTEA NOT NULL"
",UNIQUE (session_hash, newcoin_index)"
")");
SQLEXEC_INDEX("CREATE INDEX refresh_out_session_hash_index "
"ON refresh_out(session_hash,newcoin_index)");
"ON refresh_out(session_hash, newcoin_index)");
/* This table contains the wire transfers the exchange is supposed to
execute to transmit funds to the merchants (and manage refunds). */
@ -433,6 +434,7 @@ postgres_create_tables (void *cls)
",wire TEXT NOT NULL"
",tiny BOOLEAN NOT NULL DEFAULT false"
",done BOOLEAN NOT NULL DEFAULT false"
",UNIQUE (coin_pub, transaction_id, merchant_pub)"
")");
/* Index for get_deposit statement on coin_pub, transaction_id and merchant_pub */
SQLEXEC_INDEX("CREATE INDEX deposits_coin_pub_index "
@ -456,7 +458,7 @@ postgres_create_tables (void *cls)
/* Table for the tracking API, mapping from wire transfer identifiers
to transactions and back */
SQLEXEC("CREATE TABLE IF NOT EXISTS aggregation_tracking "
"(deposit_serial_id INT8 NOT NULL REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE"
"(deposit_serial_id INT8 PRIMARY KEY REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE"
",wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=" TALER_WIRE_TRANSFER_IDENTIFIER_LEN_STR ")"
",execution_time INT8 NOT NULL"
")");
@ -4252,6 +4254,23 @@ postgres_wire_prepare_data_get (void *cls,
}
/**
* Function called to perform "garbage collection" on the
* database, expiring records we no longer require.
*
* @param cls closure
* @return #GNUNET_OK on success,
* #GNUNET_NO if there was nothing to GC
* #GNUNET_SYSERR on DB errors
*/
static int
postgres_gc (void *cls)
{
GNUNET_break (0); // #3485
return GNUNET_OK;
}
/**
* Initialize Postgres database subsystem.
*
@ -4342,6 +4361,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->wire_prepare_data_insert = &postgres_wire_prepare_data_insert;
plugin->wire_prepare_data_mark_finished = &postgres_wire_prepare_data_mark_finished;
plugin->wire_prepare_data_get = &postgres_wire_prepare_data_get;
plugin->gc = &postgres_gc;
return plugin;
}

View File

@ -1488,6 +1488,18 @@ struct TALER_EXCHANGEDB_Plugin
void *cb_cls);
/**
* Function called to perform "garbage collection" on the
* database, expiring records we no longer require.
*
* @param cls closure
* @return #GNUNET_OK on success,
* #GNUNET_NO if there was nothing to GC
* #GNUNET_SYSERR on DB errors
*/
int
(*gc) (void *cls);
};