|
| 1 | +# NeoFS block storage |
| 2 | + |
| 3 | +Using NeoFS to store chain's blocks and snapshots was proposed in |
| 4 | +[#3463](https://github.com/neo-project/neo/issues/3463). NeoGo contains several |
| 5 | +extensions utilizing NeoFS block storage aimed to improve node synchronization |
| 6 | +efficiency and reduce node storage size. |
| 7 | + |
| 8 | +## Components and functionality |
| 9 | + |
| 10 | +### Block storage schema |
| 11 | + |
| 12 | +A single NeoFS container is used to store blocks and index files. Each block |
| 13 | +is stored in a binary form as a separate object with a unique OID and a set of |
| 14 | +attributes: |
| 15 | + - block object identifier with block index value (`block:1`) |
| 16 | + - primary node index (`primary:0`) |
| 17 | + - block hash in the LE form (`hash:5412a781caf278c0736556c0e544c7cfdbb6e3c62ae221ef53646be89364566b`) |
| 18 | + - previous block hash in the LE form (`prevHash:3654a054d82a8178c7dfacecc2c57282e23468a42ee407f14506368afe22d929`) |
| 19 | + - millisecond-precision block timestamp (`time:1627894840919`) |
| 20 | + |
| 21 | +Each index file is an object containing a constant-sized batch of raw block object |
| 22 | +IDs in binary form ordered by block index. Each index file is marked with the |
| 23 | +following attributes: |
| 24 | + - index file identifier with consecutive file index value (`oid:0`) |
| 25 | + - the number of OIDs included into index file (`size:128000`) |
| 26 | + |
| 27 | +### NeoFS BlockFetcher |
| 28 | + |
| 29 | +NeoFS BlockFetcher service is designed as an alternative to P2P synchronisation |
| 30 | +protocol. It allows to download blocks from a trusted container in the NeoFS network |
| 31 | +and persist them to database using standard verification flow. NeoFS BlockFetcher |
| 32 | +service primarily used during the node's bootstrap, providing a fast alternative to |
| 33 | +P2P blocks synchronisation. |
| 34 | + |
| 35 | +NeoFS BlockFetcher service has two modes of operation: |
| 36 | +- Index File Search: Search for index files, which contain batches of block object |
| 37 | + IDs and fetch blocks from NeoFS by retrieved OIDs. |
| 38 | +- Direct Block Search: Search and fetch blocks directly from NeoFS container via |
| 39 | + built-in NeoFS object search mechanism. |
| 40 | + |
| 41 | +Operation mode of BlockFetcher can be configured via `SkipIndexFilesSearch` |
| 42 | +parameter. |
| 43 | + |
| 44 | +#### Operation flow |
| 45 | + |
| 46 | +1. **OID Fetching**: |
| 47 | + Depending on the mode, the service either: |
| 48 | + - Searches for index files by index file attribute and reads block OIDs from index |
| 49 | + file object-by-object. |
| 50 | + - Searches batches of blocks directly by block attribute (the batch size is |
| 51 | + configured via `OIDBatchSize` parameter). |
| 52 | + |
| 53 | + Once the OIDs are retrieved, they are immediately redirected to the |
| 54 | + block downloading routines for further processing. The channel that |
| 55 | + is used to redirect block OIDs to downloading routines is buffered |
| 56 | + to provide smooth OIDs delivery without delays. The size of this channel |
| 57 | + can be configured via `OIDBatchSize` parameter and equals to `2*OIDBatchSize`. |
| 58 | +2. **Parallel Block Downloading**: |
| 59 | + The number of downloading routines can be configured via |
| 60 | + `DownloaderWorkersCount` parameter. It's up to the user to find the |
| 61 | + balance between the downloading speed and blocks persist speed for every |
| 62 | + node that uses NeoFS BlockFetcher. Downloaded blocks are placed into a |
| 63 | + buffered channel of size `IDBatchSize` with further redirection to the |
| 64 | + block queue. |
| 65 | +3. **Block Insertion**: |
| 66 | + Downloaded blocks are inserted into the blockchain using the same logic |
| 67 | + as in the P2P synchronisation protocol. The block queue is used to order |
| 68 | + downloaded blocks before they are inserted into the blockchain. The |
| 69 | + size of the queue can be configured via the `BQueueSize` parameter |
| 70 | + and should be larger than the `OIDBatchSize` parameter to avoid blocking |
| 71 | + the downloading routines. |
| 72 | + |
| 73 | +Once all blocks available in the NeoFS container are processed, the service |
| 74 | +shuts down automatically. |
0 commit comments