3.0 KiB
At a higher level, Block Exchange Module is responsible for sending and receiving blocks related to the given content. Formally a block is described as a tuple consisting of the sequence of bytes and the corresponding CID. Or, using a pseudo-language: (seq[byte], CID).
When uploading the content to the network, the following steps are taken:
- The content is chunked into fixed size blocks. The default block size is
64KiB. The last block will be padded with0s. - For each chunk, the corresponding
CIDis created, using(codex-block, 0xCD02)as a Multicodec and(sha2-256, 0x12)as Mutihash. - The resulting block,
(seq[byte], CID)becomes the input to the Block Exchange ModuleputBlockoperation.
When downloading the content from the network:
- Given the Codex Manifest CID, the corresponding Codex Manifest is retrieved. Using manifest attributes -
datasetSizeandblockSize, the number of blocks -blockCountis computed as\lceil datasetSize/blockSize \rceil. - For each
blockIndex \in [0 .. blockCount], aBlockAddressis defined as a tuple(treeCid, blockIndex)wheretreeCidis an attribute in the Codex Manifest.BlockAddressis the input of the Block Exchange ModulerequestBlockoperation.
The putBlock and requestBlock operations defined above, define the external interface of the Block Exchange Module. The Block Exchange Module directly interacts with other modules, mainly Discovery Module and the Repo Store, used for the node discovery and local storage respectively.
Functional Requirements
Before defining the operational model of the Block Exchange Module, which describes how the exchange module achieves its goals, let's the find the functional requirements that define what the exchange module is expected to achieve.
- Given
BlockAddress = (treeCid, blockIndex), retrieve the corresponding block from the network. In the operational model, we will see that the exchange module will attempt3000retires, waiting500msin each iteration for the block to be delivered. Thus, from the declarative perspective, here, we can claim that exchange module should deliver the block withing3000 \times 500ms = 1500s = 25min, or fail otherwise. - When uploading content
C, for each blockb \in C, storebin Repo Store and (1) announce the block presence to the peers signaling interest inb, (2) deliverbto the peers that earlier requestedb. Include Merkle Proof in the delivery ifbis not Codex Manifest block.
Operational Model
In this section we focus more how the exchange module operates to deliver on the #Functional Requirements.
In the image below, we provide a high level description of the exchange module operational model. A more detailed discussion follows.
The image above has SVG format which allows a high resolution local rendering. You can also access online version at: https://link.excalidraw.com/readonly/GLtqSUDCiRe38gDb2MOX.