|
| 1 | +# NeoFS BlockStorage |
| 2 | +This service was proposed as a part of [ Using NeoFS to store blocks and snapshots #3463](https://github.com/neo-project/neo/issues/3463). |
| 3 | +It is an alternative to the P2P synchronization protocol by using NeoFS to |
| 4 | +store and retrieve blockchain blocks and snapshots. This improves |
| 5 | +synchronization efficiency, reduces local storage, and streamlines node |
| 6 | +operations. |
| 7 | + |
| 8 | +## Components and functionality |
| 9 | + |
| 10 | +### Storage schema |
| 11 | +A single container is used to store blocks and index files. Each block |
| 12 | +is stored as a separate object with a unique OID and a set of attributes: |
| 13 | +- block index |
| 14 | +- block primary index |
| 15 | +- size. |
| 16 | + |
| 17 | +Index files contain OIDs of ordered blocks. Each index file is an object |
| 18 | +containing a constant number of OIDs in |
| 19 | +binary form, where every number represent the order of the index file. |
| 20 | + |
| 21 | +Attributes have the following structure: `AttributeName:IntValue`. |
| 22 | +In the container are stored blocks with attributes `block:1`, |
| 23 | +`block:2`, etc. And index files with attributes `oid:1`, `oid:2`, etc. |
| 24 | + |
| 25 | +### NeoFS BlockFetcher |
| 26 | +The NeoFS BlockFetcher service is designed as an alternative to P2P |
| 27 | +synchronisation protocol. It allows to fetch blocks, primarily used at |
| 28 | +the start of a node's lifecycle, providing an alternative to downloading |
| 29 | +blocks through the P2P NeoGo network. By default, the service is disabled. |
| 30 | + |
| 31 | +The NeoFS BlockFetcher service has two modes of operation: |
| 32 | +- Index File Search: Search for index files, which contain OIDs of blocks, |
| 33 | + and fetch blocks from NeoFS by provided OIDs. |
| 34 | +- Direct Block Search: Search and fetch blocks directly from NeoFS container. |
| 35 | + |
| 36 | +### BlockFetcher operation flow |
| 37 | +1. **OID Fetching**: |
| 38 | + Depending on the mode, the service either: |
| 39 | + - Searches for index files by attribute and reads blocks OIDs from it. |
| 40 | + - Searches batches of blocks directly by attributes. |
| 41 | + |
| 42 | + Once the OIDs are retrieved, they are immediately redirected to the |
| 43 | + block downloading routines for further processing. The channel that |
| 44 | + is used to redirect block OIDs to downloading routines is buffered |
| 45 | + to provide smooth OIDs delivery without delays. Size of this channel |
| 46 | + can be configured via `OIDBatchSize` parameter. |
| 47 | +2. **Parallel Block Downloading**: |
| 48 | + The number of downloading routines can be configured via |
| 49 | + `DownloaderWorkersCount` parameter. It's up to the user to find the |
| 50 | + balance between the downloading speed and blocks persist speed for every |
| 51 | + node that uses NeoFS BlockFetcher. Downloaded blocks are placed into a |
| 52 | + buffer with a size of `BQueueSize` parameter for further processing. |
| 53 | +3. **Block Insertion**: |
| 54 | + Downloaded blocks are inserted into the blockchain using the same logic |
| 55 | + as in the P2P synchronisation protocol. The bqueue is used to store |
| 56 | + downloaded blocks before they are inserted into the blockchain. The |
| 57 | + size of the bqueue can be configured via the `BQueueSize` parameter |
| 58 | + and should be larger than the `OIDBatchSize` parameter to avoid blocking |
| 59 | + the downloading routines. |
| 60 | + |
| 61 | +Once all blocks available in the NeoFS container are processed, the service |
| 62 | +shuts down automatically. |
| 63 | + |
| 64 | +### NeoFS BlockFetcher Configuration |
| 65 | +`NeoFSBlockFetcher` configuration section contains settings for NeoFS |
| 66 | +BlockFetcher module and has the following structure: |
| 67 | +``` |
| 68 | + NeoFSBlockFetcher: |
| 69 | + Enabled: true |
| 70 | + UnlockWallet: |
| 71 | + Path: "./wallet.json" |
| 72 | + Password: "pass" |
| 73 | + Addresses: |
| 74 | + - st1.storage.fs.neo.org:8080 |
| 75 | + Timeout: 10m |
| 76 | + DownloaderWorkersCount: 500 |
| 77 | + OIDBatchSize: 8000 |
| 78 | + BQueueSize: 16000 |
| 79 | + SkipIndexFilesSearch: false |
| 80 | + ContainerID: "EPGuD26wYgQJbmDdVBoYoNZiMKHwFMJT3A5WqPjdUHxH" |
| 81 | + BlockAttribute: "block" |
| 82 | + IndexFileAttribute: "oid" |
| 83 | +``` |
| 84 | +where: |
| 85 | +- `Enabled` enables NeoFS BlockFetcher module. |
| 86 | +- `UnlockWallet` contains wallet settings to retrieve account to sign requests to |
| 87 | + NeoFS. Without this setting, the module will use randomly generated private key. |
| 88 | + For configuration details see [Unlock Wallet Configuration](https://github.com/nspcc-dev/neo-go/blob/master/docs/node-configuration.md#unlock-wallet-configuration) |
| 89 | +- `Addresses` is a list of NeoFS storage nodes addresses. |
| 90 | +- `Timeout` is a timeout for a single request to NeoFS storage node. |
| 91 | +- `ContainerID` is a container ID to fetch blocks from. |
| 92 | +- `BlockAttribute` is an attribute name of NeoFS object that contains block |
| 93 | + data. |
| 94 | +- `IndexFileAttribute` is an attribute name of NeoFS object that contains OIDs of |
| 95 | + blocks objects. |
| 96 | +- `DownloaderWorkersCount` is a number of workers that download blocks from |
| 97 | + NeoFS. |
| 98 | +- `OIDBatchSize` is the number of blocks to search per a single request to NeoFS |
| 99 | + in case of disabled index files search. Also, for both modes of BlockFetcher |
| 100 | + operation this setting manages the buffer size of OIDs and blocks transferring channels. |
| 101 | +- `BQueueSize` is a size of the block queue used to manage consecutive blocks |
| 102 | + addition to the chain. It must be larger than |
| 103 | + `OIDBatchSize` and highly recommended to be 2*`OIDBatchSize` or 3*`OIDBatchSize`. |
| 104 | +- `SkipIndexFilesSearch` is a flag that allows skipping index files search |
| 105 | + in NeoFS storage nodes and search for blocks directly. It is set to `false` |
| 106 | + by default. |
0 commit comments