Giter Club home page Giter Club logo

Comments (2)

meejah avatar meejah commented on September 18, 2024

If this is from the same log I looked at, I think it is transient -- or at least, some more tokens were added successfully later in the log.

from zkapauthorizer.

exarkun avatar exarkun commented on September 18, 2024

A closer reading of the log reveals:

2022-09-19T10:19:17-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 16
2022-09-19T10:19:19-0700 [_zkapauthorizer.resource._VoucherCollection#info] Accepting a voucher (VVV) for redemption.
2022-09-19T10:19:19-0700 [_zkapauthorizer.controller.PaymentController#info] Starting redemption of b'VVV'[0..16] for 150000 tokens.
2022-09-19T10:19:19-0700 [_zkapauthorizer.controller.PaymentController#info] Generating random tokens for a voucher (b'VVV').
2022-09-19T10:19:19-0700 [_zkapauthorizer.model.VoucherStore#info] Persisting 9375 random tokens for a voucher (VVV[0]).
2022-09-19T10:19:19-0700 [_zkapauthorizer.controller.PaymentController#info] Redeeming random tokens for a voucher (Voucher(number=b'VVV', expected_tokens=150000, created=datetime.datetime(2022, 9, 19, 17, 19, 19, 728643, tzinfo=+0:00:00 UTC), state=Pending(counter=0))).
2022-09-19T10:19:21-0700 [twisted.python.log#info] web: 127.0.0.1 PUT /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 -
2022-09-19T10:19:21-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:21-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher/VVV 200 239
2022-09-19T10:19:21-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:23-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:24-0700 [twisted.web.client._HTTP11ClientFactory#info] Starting factory _HTTP11ClientFactory(<function HTTPConnectionPool._newConnection.<locals>.quiescentCallback at 0x00000243CD6EAA70>, <twisted.internet.endpoints._WrapperEndpoint object at 0x00000243CDD16C80>)
2022-09-19T10:19:25-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:27-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:29-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:31-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:33-0700 [twisted.python.log#info] web: 127.0.0.1 GET /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 255
2022-09-19T10:19:34-0700 [_zkapauthorizer.resource._VoucherCollection#info] Accepting a voucher (VVV) for redemption.
2022-09-19T10:19:34-0700 [_zkapauthorizer.controller.PaymentController#info] Starting redemption of b'VVV'[0..16] for 150000 tokens.
2022-09-19T10:19:34-0700 [_zkapauthorizer.model.VoucherStore#info] Loaded 9375 random tokens for a voucher (VVV[0]).
2022-09-19T10:19:34-0700 [_zkapauthorizer.controller.PaymentController#info] Redeeming random tokens for a voucher (Voucher(number=b'VVV', expected_tokens=150000, created=datetime.datetime(2022, 9, 19, 17, 19, 19, 728643, tzinfo=+0:00:00 UTC), state=Pending(counter=0))).
2022-09-19T10:19:35-0700 [twisted.python.log#info] web: 127.0.0.1 PUT /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 -

In particular, notice two instances of:

PUT /storage-plugins/privatestorageio-zkapauthz-v2/voucher 200 -

and two instances of:

Accepting a voucher (VVV) for redemption.

It seems the same voucher was loaded into the node twice. This should be idempotent, I guess, to allow client retries in the face of errors. And it is ... kind of. The two vouchers will share the same set of tokens. However, PaymentController will try concurrent redemptions of those same tokens, too, and whichever of those processes loses the race will try to insert duplicate signed tokens into the database and provoke this UNIQUE constraint failure. PaymentController.redeem probably needs to notice if a voucher is already redeeming.

There's even some logic for that already too. But PaymentController.redeem jumps over it and goes straight to the database instead, woops.

from zkapauthorizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.