ToolszkEVMArchitectureData streamer

Stream file

Next is an explanation of the stream file structure. The stream file is created in a binary format instead of a text file. It has a header page and one or more

Next is an explanation of the stream file structure.

The stream file is created in a binary format instead of a text file.

It has a header page and one or more data pages. The header page is first and has a fixed size of 4096 bytes. The data pages follow immediately after the header page, and the size of each data page is 1 MB.

Data pages contain entries.

If an entry does not fit in the remaining page space, it gets stored in the next page. This means the unused space in the previous data page gets filled with some padding.

Figure

Header page

Let's zoom into how the Header\texttt{Header}​ page looks like.

The HeaderEntry\texttt{HeaderEntry} consists of the following data; magicNumbers\texttt{magicNumbers}, packetType\texttt{packetType}, headerLength\texttt{headerLength}, streamType\texttt{streamType}, TotalLength\texttt{TotalLength}, and TotalEntries\texttt{TotalEntries}​.

  1. The HeaderEntry\texttt{HeaderEntry} starts with an array of 16 bytes, called magicNumbers\texttt{magicNumbers}​.

    u8[16] magicNumbers\texttt{u8[16] magicNumbers}

    The magicNumbers\texttt{magicNumbers} identify the application to which the data in the stream file belongs.

    In the Polygon zkEVM case, the magicNumbers\texttt{magicNumbers} is the ASCII-encoding of these sixteen (16) characters: polygonDATSTREAM\texttt{polygonDATSTREAM}.

  2. After the magicNumbers\texttt{magicNumbers} comes the packetType\texttt{packetType}, which indicates whether the current page is a Header\texttt{Header} page or a Data\texttt{Data} page.

    u8 packetType = 1 // 1: Header entry\texttt{u8 packetType = 1 // 1: Header entry}

    The packetType\texttt{packetType} for the Header\texttt{Header} entry is 1\texttt{1}, but it is 2\texttt{2} for the Data\texttt{Data} entry and 0\texttt{0} for a padding.

    Figure

  3. Included in the Header\texttt{Header} page is the streamType\texttt{streamType}​, which has the same meaning as seen in the Server-source protocol: It indicates the application, or in particular, the stream source node to which the stream server should connect.

    u64 streamType // 1: zkEVM Sequencer\texttt{u64 streamType // 1: zkEVM Sequencer}

    As mentioned in the above line of code, streamType = 1\texttt{streamType = 1} means the stream source node is the zkEVM Sequencer.

  4. The streamType\texttt{streamType} is then followed by the TotalLength\texttt{TotalLength}​ , which is the total number of bytes used in the stream file.

    u64 TotalLength // Total bytes used in the file\texttt{u64 TotalLength // Total bytes used in the file}
  5. After the TotalLength\texttt{TotalLength} is the TotalEntries\texttt{TotalEntries}​​, which is the total number of entries used in the file.

    u64 TotalEntries // Total number of data entries\texttt{u64 TotalEntries // Total number of data entries}

Data pages

A data page contains entries and some padding.

Since this is a data\texttt{data} page, and not a Header\texttt{Header} page, the entries are preceded by packetType = 2\texttt{packetType = 2}, while the padding is preceded by packetType = 0\texttt{packetType = 0}​.

1.u8 packetType // 2:Data entry, 0:Padding2.u32 Length // Total length of data entry3.u32 entryType // 0xb0:Bookmark, 1:Event1, 2:Event2,... 4.u64 entryNumber // Entry number (sequence from 0)5.u8[] data\begin{aligned} 1.\quad &\texttt{u8 packetType // 2:Data entry, 0:Padding} \\ 2.\quad &\texttt{u32 Length // Total length of data entry} \\ 3.\quad &\texttt{u32 entryType // 0xb0:Bookmark, 1:Event1, 2:Event2,... } \\ 4.\quad &\texttt{u64 entryNumber // Entry number (sequence from 0)} \\ 5.\quad &\texttt{u8[] data} \end{aligned}

The packetType\texttt{packetType} is followed by the Length\texttt{Length} of the data entry, then the entryType\texttt{entryType} of the entry. That is, whether it is a bookmark or an event entry.

A bookmark entryType\texttt{entryType} is indicated by 0xb0\texttt{0xb0}, while each event's entryType\texttt{entryType} is its position among a sequence of events. That is, each ii-th event is of entryType=i\mathtt{entryType = i}.

The next value after the entryType\texttt{entryType} is the entry number, denoted by entryNumber\texttt{entryNumber}. The next values in a data page are data\texttt{data}.

After the last entry in a data page, is the packetType = 0\texttt{packetType = 0} and some padding for any unused space.

Figure

Edit on GitHub

Last updated on