octane icon indicating copy to clipboard operation
octane copied to clipboard

[rfc] Add idempotence tokens to API to prevent duplicate transactions

Open steveluscher opened this issue 2 years ago • 5 comments

Preamble

The internet is a jerk. Sometimes connections go down. Requests rebroadcast as clients retry. Retry logic is often unsophisticated.

Problem statement

We have logic in Octane to prevent malicious consecutive signing requests (through locks) but we might also consider protecting against accidental dupes.

There are many reasons why a client might accidentally re-send a request.

  • It disconnected after sending the first request, but before receiving the response.
  • A fatal in the response handler re-triggered the request.
  • It's dumb.

Proposal

Require, as part of the transaction signing request API, that clients supply an idempotence token. Octane would store this token in a distributed storage system like Upstash (Redis). If Octane encounters a signing request having an idempotence token that it has seen before, it drops the request.

Details

  • It's important that the idempotence token be universally unique. In practice, this will probably look something like Octane taking whatever #yolo idempotence token the client sends and hashing it together with the transaction itself to create something unique. If a client insists on reusing idempotence tokens (eg. '') multiple times with the exact same transaction, it's gonna have a bad time.
  • The distributed data store probably needs to store three states for each idempotence token:
    • Nothing stored (never seen this transaction).
    • in-flight when the transaction has been received and validated, but not yet confirmed.
    • expended when the transaction associated with this idempotence token has been confirmed.

steveluscher avatar Jan 01 '22 03:01 steveluscher