nim-codex/codex
Eric 570a1f7b67
[marketplace] Availability improvements (#535)
## Problem
When Availabilities are created, the amount of bytes in the Availability are reserved in the repo, so those bytes on disk cannot be written to otherwise. When a request for storage is received by a node, if a previously created Availability is matched, an attempt will be made to fill a slot in the request (more accurately, the request's slots are added to the SlotQueue, and eventually those slots will be processed). During download, bytes that were reserved for the Availability were released (as they were written to disk). To prevent more bytes from being released than were reserved in the Availability, the Availability was marked as used during the download, so that no other requests would match the Availability, and therefore no new downloads (and byte releases) would begin. The unfortunate downside to this, is that the number of Availabilities a node has determines the download concurrency capacity. If, for example, a node creates a single Availability that covers all available disk space the operator is willing to use, that single Availability would mean that only one download could occur at a time, meaning the node could potentially miss out on storage opportunities.

## Solution
To alleviate the concurrency issue, each time a slot is processed, a Reservation is created, which takes size (aka reserved bytes) away from the Availability and stores them in the Reservation object. This can be done as many times as needed as long as there are enough bytes remaining in the Availability. Therefore, concurrent downloads are no longer limited by the number of Availabilities. Instead, they would more likely be limited to the SlotQueue's `maxWorkers`.

From a database design perspective, an Availability has zero or more Reservations.

Reservations are persisted in the RepoStore's metadata, along with Availabilities. The metadata store key path for Reservations is ` meta / sales / reservations / <availabilityId> / <reservationId>`, while Availabilities are stored one level up, eg `meta / sales / reservations / <availabilityId> `, allowing all Reservations for an Availability to be queried (this is not currently needed, but may be useful when work to restore Availability size is implemented, more on this later).

### Lifecycle
When a reservation is created, its size is deducted from the Availability, and when a reservation is deleted, any remaining size (bytes not written to disk) is returned to the Availability. If the request finishes, is cancelled (expired), or an error occurs, the Reservation is deleted (and any undownloaded bytes returned to the Availability). In addition, when the Sales module starts, any Reservations that are not actively being used in a filled slot, are deleted.

Having a Reservation persisted until after a storage request is completed, will allow for the originally set Availability size to be reclaimed once a request contract has been completed. This is a feature that is yet to be implemented, however the work in this PR is a step in the direction towards enabling this.

### Unknowns
Reservation size is determined by the `StorageAsk.slotSize`. If during download, more bytes than `slotSize` are attempted to be downloaded than this, then the Reservation update will fail, and the state machine will move to a `SaleErrored` state, deleting the Reservation. This will likely prevent the slot from being filled.

### Notes
Based on #514
2023-09-29 14:33:08 +10:00
..
blockexchange Debug/extra logging (#509) 2023-08-22 08:35:16 +02:00
contracts Taiko L2 (#483) 2023-09-13 16:17:56 +02:00
erasure Erasure cleanup (#545) 2023-09-25 07:31:10 -07:00
manifest Erasure cleanup (#545) 2023-09-25 07:31:10 -07:00
merkletree Merkle tree construction (#504) 2023-08-15 13:23:35 +02:00
node [marketplace] Add Reservations Module (#340) 2023-04-04 17:05:16 +10:00
purchasing Cancel and wait for asyncstatemachine futures when stopping (#493) 2023-07-31 15:09:34 +10:00
rest [marketplace] Availability improvements (#535) 2023-09-29 14:33:08 +10:00
sales [marketplace] Availability improvements (#535) 2023-09-29 14:33:08 +10:00
storageproofs Bump deps take2 (#492) 2023-08-01 16:47:57 -07:00
stores Erasure cleanup (#545) 2023-09-25 07:31:10 -07:00
streams Debug/extra logging (#509) 2023-08-22 08:35:16 +02:00
utils [marketplace] Availability improvements (#535) 2023-09-29 14:33:08 +10:00
blockexchange.nim Change every dagger to codex (#102) 2022-05-19 13:56:03 -06:00
blocktype.nim Bump deps take2 (#492) 2023-08-01 16:47:57 -07:00
chunker.nim Plumbing in conf types (#472) 2023-07-06 16:23:27 -07:00
clock.nim [clock] waitUntil() completes immediately when block arrives (#475) 2023-07-13 11:19:45 +02:00
codex.nim Taiko L2 (#483) 2023-09-13 16:17:56 +02:00
conf.nim Taiko L2 (#483) 2023-09-13 16:17:56 +02:00
contracts.nim feat: contract address management (#405) 2023-05-03 09:24:25 +02:00
discovery.nim Bump deps take2 (#492) 2023-08-01 16:47:57 -07:00
erasure.nim Improving proc/func formatting consistency (#454) 2023-06-22 08:11:18 -07:00
errors.nim Bump deps take2 (#492) 2023-08-01 16:47:57 -07:00
formats.nim Bump deps take2 (#492) 2023-08-01 16:47:57 -07:00
manifest.nim Change every dagger to codex (#102) 2022-05-19 13:56:03 -06:00
market.nim Slot queue (#455) 2023-07-25 12:50:30 +10:00
namespaces.nim Add metrics (#478) 2023-07-20 09:56:28 +02:00
node.nim [marketplace] Availability improvements (#535) 2023-09-29 14:33:08 +10:00
periods.nim Validator (#387) 2023-04-19 15:06:00 +02:00
purchasing.nim Improving proc/func formatting consistency (#454) 2023-06-22 08:11:18 -07:00
rng.nim track latest nim-libp2p's master branch (#248) 2022-11-02 11:40:28 -06:00
sales.nim [marketplace] Availability improvements (#535) 2023-09-29 14:33:08 +10:00
storageproofs.nim Validator (#387) 2023-04-19 15:06:00 +02:00
stores.nim Blockstore maintenance (#347) 2023-03-08 16:04:54 +01:00
streams.nim adding AsyncStreamWrapper (#110) 2022-06-14 09:19:35 -06:00
systemclock.nim Blockstore maintenance (#347) 2023-03-08 16:04:54 +01:00
units.nim Plumbing in conf types (#472) 2023-07-06 16:23:27 -07:00
utils.nim Plumbing in conf types (#472) 2023-07-06 16:23:27 -07:00
validation.nim Improving proc/func formatting consistency (#454) 2023-06-22 08:11:18 -07:00