NUT-19: Cached Responses #195

Merged
a1denvalu3 merged 19 commits from cached-responses into main 2024-12-03 12:44:22 +00:00
a1denvalu3 commented 2024-11-23 08:40:08 +00:00 (Migrated from github.com)

Cache every successful PostMintResponse, PostMeltResponse and PostSwapResponse using the respective requests as keys.
In case of a network error, clients can replay the same exact requests receive the same responses. This safe-guards against clients accidentally losing money because of connectivity issues.

Implementations:

Cache every successful `PostMintResponse`, `PostMeltResponse` and `PostSwapResponse` using the respective requests as keys. In case of a network error, clients can replay the same exact requests receive the same responses. This safe-guards against clients accidentally losing money because of connectivity issues. Implementations: * [x] Nutshell : cashubtc/nutshell#624 * [x] CDK : cashubtc/cdk#361 * [ ] Nutmix * [ ] goNuts
gandlafbtc (Migrated from github.com) reviewed 2024-11-24 09:32:11 +00:00
gandlafbtc (Migrated from github.com) left a comment

Not a grammar pro myself, but I think this is correct?

Not a grammar pro myself, but I think this is correct?
gandlafbtc (Migrated from github.com) commented 2024-11-24 09:30:54 +00:00
`Bob` **MUST** cache every successful `PostSwapResponse` using `PostSwapRequest` as the key.
```suggestion `Bob` **MUST** cache every successful `PostSwapResponse` using `PostSwapRequest` as the key. ```
gandlafbtc (Migrated from github.com) commented 2024-11-24 09:31:15 +00:00
`Bob` **MUST** cache every successful `PostMintBolt11Response` using `PostMintBolt11Request` as the key.
```suggestion `Bob` **MUST** cache every successful `PostMintBolt11Response` using `PostMintBolt11Request` as the key. ```
gandlafbtc (Migrated from github.com) commented 2024-11-24 09:31:27 +00:00
`Bob` **MUST** cache every successful `PostMeltBolt11Response` using `PostMeltBolt11Request` as the key.
```suggestion `Bob` **MUST** cache every successful `PostMeltBolt11Response` using `PostMeltBolt11Request` as the key. ```
callebtc commented 2024-11-24 11:45:09 +00:00 (Migrated from github.com)

Awesome work and thank you for the implementations. I wonder whether we want to add this to the existing NUTs or formulate it as a separate NUT.

In both cases, I think it would be better to formulate this as an optional feature. Right now it is formulated as a MUST.

Awesome work and thank you for the implementations. I wonder whether we want to add this to the existing NUTs or formulate it as a separate NUT. In both cases, I think it would be better to formulate this as an optional feature. Right now it is formulated as a MUST.
callebtc commented 2024-11-24 11:49:02 +00:00 (Migrated from github.com)

One argument for putting this in its own NUT would be that we would have to add a note about caching into every method that we add (like bolt12) whereas it could be formulated more generally as "any endpoint that produces outputs" and we could reference the specific NUTs for mint/melt/swap (and further future methods).

This NUT should also defined a setting flag for each cached endpoint that we announce in the mint info (together with a TTL)

One argument for putting this in its own NUT would be that we would have to add a note about caching into every method that we add (like bolt12) whereas it could be formulated more generally as "any endpoint that produces outputs" and we could reference the specific NUTs for mint/melt/swap (and further future methods). This NUT should also defined a setting flag for each cached endpoint that we announce in the mint info (together with a TTL)
callebtc commented 2024-11-24 17:11:06 +00:00 (Migrated from github.com)

There are two unrelated files in the PR.

Questions in my mind:

  • Should we announce the TTL in the NUT-XX info setting?
  • Should we announce all cached paths in the NUT-XX setting or should we add a boolean setting flag to each cached nut (swap, mint, melt)?
There are two unrelated files in the PR. Questions in my mind: - Should we announce the TTL in the NUT-XX info setting? - Should we announce all cached paths in the NUT-XX setting or should we add a boolean setting flag to each cached nut (swap, mint, melt)?
callebtc (Migrated from github.com) reviewed 2024-11-24 23:13:13 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:13:13 +00:00

reception of a mint (POST /v1/mint/{method}), swap (POST v1/swap) or melt (POST /v1/melt/{method}) request

Should refer and link to NUTs

> reception of a mint (`POST /v1/mint/{method}`), swap (`POST v1/swap`) or melt (`POST /v1/melt/{method}`) `request` Should refer and link to NUTs
callebtc (Migrated from github.com) reviewed 2024-11-24 23:13:38 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:13:37 +00:00

Example: Redis?

Example: Redis?
callebtc (Migrated from github.com) reviewed 2024-11-24 23:14:27 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:14:27 +00:00
Upon the reception of a mint (`POST /v1/mint/{method}`), swap (`POST v1/swap`) or melt (`POST /v1/melt/{method}`) `request`, the mint derives a key `k` for it. `k` should depend on the path of `request` as well as the contents of `request`'s payload.
```suggestion Upon the reception of a mint (`POST /v1/mint/{method}`), swap (`POST v1/swap`) or melt (`POST /v1/melt/{method}`) `request`, the mint derives a key `k` for it. `k` should depend on the path of `request` as well as the contents of `request`'s payload. ```
callebtc (Migrated from github.com) reviewed 2024-11-24 23:15:25 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:15:24 +00:00
The mint uses `k` to look up a `response = D[k]` and discriminates execution based on the following checks:
```suggestion The mint uses `k` to look up a `response = D[k]` and discriminates execution based on the following checks: ```
callebtc (Migrated from github.com) reviewed 2024-11-24 23:16:48 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:16:48 +00:00
* If no cached `response` is found: `request` has no matching `response`. The mint processes `request` as per usual.
* If a cached `response` is found: `request` has a matching `response`. The mint returns the cached `response`.

I think this sounds overly technical but I've corrected your version here.

```suggestion * If no cached `response` is found: `request` has no matching `response`. The mint processes `request` as per usual. * If a cached `response` is found: `request` has a matching `response`. The mint returns the cached `response`. ``` I think this sounds overly technical but I've corrected your version here.
callebtc (Migrated from github.com) reviewed 2024-11-24 23:17:46 +00:00
callebtc (Migrated from github.com) commented 2024-11-24 23:17:46 +00:00
Support for NUT-XX is announced as an extension to the `nuts` field of the `GetInfoResponse` described in [NUT-6](06).
```suggestion Support for NUT-XX is announced as an extension to the `nuts` field of the `GetInfoResponse` described in [NUT-6](06). ```
callebtc (Migrated from github.com) reviewed 2024-11-24 23:19:46 +00:00
callebtc (Migrated from github.com) left a comment

Left some minor corrections on first pass

Left some minor corrections on first pass
callebtc (Migrated from github.com) commented 2024-11-24 23:17:57 +00:00
The entry is structured as follows:
```suggestion The entry is structured as follows: ```
callebtc (Migrated from github.com) commented 2024-11-24 23:18:39 +00:00
Where `ttl` is the number of seconds the responses are cached for and `cached_endpoints` is a list of the methods and paths for which caching is enabled.
```suggestion Where `ttl` is the number of seconds the responses are cached for and `cached_endpoints` is a list of the methods and paths for which caching is enabled. ```
callebtc (Migrated from github.com) commented 2024-11-24 23:18:56 +00:00

Should be in the previous sentence.

Should be in the previous sentence.
callebtc (Migrated from github.com) commented 2024-11-24 23:19:32 +00:00
If `ttl` is `null`, the responses are expected to be cached *indefinitely*.
```suggestion If `ttl` is `null`, the responses are expected to be cached *indefinitely*. ```
a1denvalu3 (Migrated from github.com) reviewed 2024-11-25 13:59:14 +00:00
a1denvalu3 (Migrated from github.com) commented 2024-11-25 13:59:14 +00:00

?

?
callebtc (Migrated from github.com) approved these changes 2024-12-03 12:43:52 +00:00
Sign in to join this conversation.
No description provided.