implement batch operation in handlers

This commit is contained in:
Christian Grothoff 2022-11-14 06:43:21 +01:00
parent 8bfc6583e7
commit 41e3c1ecbf
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 50 additions and 48 deletions

View File

@ -413,24 +413,24 @@ static MHD_RESULT
prepare_transaction (const struct TEH_RequestContext *rc,
struct BatchWithdrawContext *wc)
{
/* Note: We could check the reserve balance here,
just to be reasonably sure that the reserve has
a sufficient balance before doing the "expensive"
signatures... */
/* Sign before transaction! */
struct TEH_CoinSignData csds[wc->planchets_length];
struct TALER_BlindedDenominationSignature bss[wc->planchets_length];
for (unsigned int i = 0; i<wc->planchets_length; i++)
{
struct PlanchetContext *pc = &wc->planchets[i];
enum TALER_ErrorCode ec;
struct TEH_CoinSignData csds = {
.h_denom_pub = &pc->collectable.denom_pub_hash,
.bp = &pc->blinded_planchet
};
ec = TEH_keys_denomination_sign (
&csds,
csds[i].h_denom_pub = &pc->collectable.denom_pub_hash;
csds[i].bp = &pc->blinded_planchet;
}
{
enum TALER_ErrorCode ec;
ec = TEH_keys_denomination_batch_sign (
csds,
wc->planchets_length,
false,
&pc->collectable.sig);
bss);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
@ -439,6 +439,12 @@ prepare_transaction (const struct TEH_RequestContext *rc,
NULL);
}
}
for (unsigned int i = 0; i<wc->planchets_length; i++)
{
struct PlanchetContext *pc = &wc->planchets[i];
pc->collectable.sig = bss[i];
}
/* run transaction */
{

View File

@ -75,10 +75,11 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
{
struct TALER_ExchangeWithdrawValues ewvs[csr_requests_num];
{
struct TALER_CsNonce nonces[csr_requests_num];
struct TALER_DenominationHashP denom_pub_hashes[csr_requests_num];
struct TEH_CsDeriveData cdds[csr_requests_num];
struct TALER_DenominationCSPublicRPairP r_pubs[csr_requests_num];
for (unsigned int i = 0; i < csr_requests_num; i++)
{
@ -114,8 +115,6 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
const struct TALER_CsNonce *nonce = &nonces[i];
const struct TALER_DenominationHashP *denom_pub_hash =
&denom_pub_hashes[i];
struct TALER_DenominationCSPublicRPairP *r_pub
= &ewvs[i].details.cs_values;
ewvs[i].cipher = TALER_DENOMINATION_CS;
/* check denomination referenced by denom_pub_hash */
@ -176,28 +175,23 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
denom_pub_hash);
}
}
/* derive r_pub */
// FIXME-#7272: bundle all requests into one derivation request (TEH_keys_..., crypto helper, security module)
{
const struct TEH_CsDeriveData cdd = {
.h_denom_pub = denom_pub_hash,
.nonce = nonce
};
ec = TEH_keys_denomination_cs_r_pub (&cdd,
true,
r_pub);
}
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
return TALER_MHD_reply_with_ec (rc->connection,
ec,
NULL);
}
cdds[i].h_denom_pub = denom_pub_hash;
cdds[i].nonce = nonce;
} /* for (i) */
ec = TEH_keys_denomination_cs_batch_r_pub (cdds,
csr_requests_num,
true,
r_pubs);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
return TALER_MHD_reply_with_ec (rc->connection,
ec,
NULL);
}
}
for (unsigned int i = 0; i < csr_requests_num; i++)
ewvs[i].details.cs_values = r_pubs[i];
} /* end scope */
/* send response */
{

View File

@ -750,20 +750,21 @@ clean_age:
(unsigned int) rctx->num_fresh_coins);
/* create fresh coin signatures */
for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
{
struct TEH_CoinSignData csds[rctx->num_fresh_coins];
struct TALER_BlindedDenominationSignature bss[rctx->num_fresh_coins];
enum TALER_ErrorCode ec;
struct TEH_CoinSignData csd = {
.h_denom_pub = &rrcs[i].h_denom_pub,
.bp = &rcds[i].blinded_planchet
};
// FIXME #7272: replace with a batch call that
// passes all coins in once go!
ec = TEH_keys_denomination_sign (
&csd,
for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
{
csds[i].h_denom_pub = &rrcs[i].h_denom_pub;
csds[i].bp = &rcds[i].blinded_planchet;
}
ec = TEH_keys_denomination_batch_sign (
csds,
rctx->num_fresh_coins,
true,
&rrcs[i].coin_sig);
bss);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
@ -772,8 +773,9 @@ clean_age:
NULL);
goto cleanup;
}
for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
rrcs[i].coin_sig = bss[i];
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Signatures ready, starting DB interaction\n");