To introduce our new proposal for website storage optimization on DeWeb, we’re addressing the inefficiencies of the current system, which forces users to re-upload entire websites for minor edits, leading to higher costs.
We propose two solutions: File-Based Storage, which allows users to update individual files, and Directory-Based Storage, which stores entire directories as compressed zip files. Both approaches aim to reduce costs by minimizing the number of operations required for updates while overcoming blockchain limitations on chunk sizes, improving overall efficiency and scalability.
Current System:
In the current system, websites are stored on the blockchain in chunks to overcome the block size limit. They are stored as zip files, which are divided into chunks based on a set CHUNK_SIZE
. The contract stores these chunks, and clients can retrieve the website by fetching all chunks and reassembling them.
The CHUNK_SIZE
is a client-side constant that defines the maximum size of a chunk in bytes. As the smart contract does not know the CHUNK_SIZE
and it is not required to reassemble the website, the CHUNK_SIZE
can be modified by the client without affecting the contract’s functionality. The CHUNK_SIZE
is particularly interesting on the long term as it can be modified to adapt to the blockchain’s usage, for example, if most blocks are full, the CHUNK_SIZE
can be reduced to ensure that chunks are not too big to fit in a block.
For reference, here’s the current implementation.
Proposed Solutions:
1. File-Based Storage
-
How it Works: Each file on the website is divided into chunks based on a set
CHUNK_SIZE
. If the file is smaller than theCHUNK_SIZE
limit, it will be stored as a single chunk, while larger files are split into multiple chunks. Each file is uploaded and managed independently. -
Benefits: Users can update only specific files instead of the entire site, reducing costs and the number of operations. This is ideal for websites with small, frequently updated files.
-
Drawbacks: Managing metadata for individual file chunks can add complexity and requires additional processing power for the smart contract to track file versions and their corresponding chunks.
2. Directory-Based Storage
-
How it Works: Files within a directory are compressed into a zip file. This zip file is chunked and stored if it exceeds the block size limit. Rather than updating individual files, users update directories containing the files.
-
Benefits: This method allows better compression for directories with similar file types (e.g., CSS or images). Managing metadata is easier because the contract is only tracking directories, not individual files.
-
Drawbacks: Updating a single file in a large directory still requires re-uploading the entire directory, which may not be cost-efficient for smaller changes.
Optimized Multi-File/Directory Upload:
To further optimize, the new upload function will handle multiple files or directories at once by bundling small files together to fill the CHUNK_SIZE
limit. For example, we have the following files:
- File A: 10KB
- File B: 5KB
- File C: 15KB
- File D: 29KB
- File E: 2MB
The files could be bundled as follow:
- File A (10KB), File B (5KB), and File C (15KB) total 30KB, will be sent in one operation.
- File D (29KB), it will be sent alone.
- File E (2MB), will be divided into 32KB chunks and sent across multiple operations.
With operations looking like:
-
First Operation:
[ { "filename": "A", "chunkID": 0, "bytes": [10KB] }, { "filename": "B", "chunkID": 0, "bytes": [5KB] }, { "filename": "C", "chunkID": 0, "bytes": [15KB] } ]
-
Second Operation:
[ { "filename": "D", "chunkID": 0, "bytes": [29KB] } ]
-
Third Operation and subsequent operations for large files:
[ { "filename": "E", "chunkID": 0, "bytes": [32KB] } ] [ { "filename": "E", "chunkID": 1, "bytes": [32KB] } ] ...
Depending on the File E last chunk size, files could be uploaded on a different way, for example bundling the last chunk of file E with file D.
Note that this format is only for demonstration purpose and not fully defined yet.
This method minimizes the number of operations, helping users to save on gas fees while maintaining flexibility for both small and large files.
Community Feedback:
We invite the community to provide feedback on these proposed solutions. By implementing this new system, we aim to make DeWeb’s website storage more cost-efficient and scalable, benefiting all users. We plan to work on this upgrade for release with DeWeb 1.0.
Your suggestions will help us refine and improve the solution, so please share your thoughts in the comments below.