# Solana-Arweave Bridge The solana legder is growing very fast so there is a need of some persistent storage solution. This project will be used to store solana txs data in a Arweave. The data can be queried using parameters like public key, block hash, slot number, signature, etc. ## Algorithm As, we can store 2048 Bytes tag one Arweave transaction. We can go for two algorithms: 1. We can either store Solana tx data with slot number as tag and then create a separate arweave tx for mapping the slot # to the public key, signature, etc. 2. We can batch the solana txs till the tag size is less than 2048 bytes. This way we will be able to batch 5-12 txs together. In the first approach we can only fit 256 tx together, but the time to query the data will be slow because of the two separate arweave txs. Since storage is relatively cheap for direct accessibilty of data from Arweave, we have decided to go with the 2nd approach which will be faster. The steps for the same is mentioned below: ### Steps:- 1. Subscribe to Solana block using Pub-Sub Client. 2. Create a buffer to store txs. 3. Parse the transaction available in the block. Take out the parameters of each tx such as: * List of Public Keys * Slot Number * Signatures * Block Hash 4. Add every parameters of each txs as a tag for Arweave transaction. At the same time, update the bytes size variable. And, add the tx in the current buffer. 5. Once the size variable will reach 2048 Bytes, send the transactions with tags to Arweave. 6. Next Transaction will be added in next buffer. 7. Repeat step 3 to 6. ## Benchmarking (Transaction Data):- As per explained algorithm, we can store as much as 2048 Bytes tag in one Arweave Transaction. So, If we take condition of a solana voting transaction then, In the parameters, there will be 5 Public Keys, 1 Transaction Signature, 1 Slot and 1 Block Hash. So, If we calculates the Tag (parameter) size of 1 tx:- > 1 Slot = 8 Bytes > 1 Block Hash = 32 Bytes > 1 Signature = 64 Bytes > 5 Public Keys = (32 * 5) Bytes = 160 Bytes So, Total Tag size for one Solana Tx = (8 + 32 + 64 + 160) Bytes = **264 Bytes** Number of Solana Txs can be stored in One Arweave Tx: = 2048/264 = 7.75 = **7 Transactions** (Approx) *We are also thinking of a potential solution of data compression to reduce the size of tx data, to reduce tx cost.* ## Example Transaction As a small POC, we have stored one Solana tx on the Arweave using our Rust code. **Arweave Tx Link:** https://viewblock.io/arweave/tx/mWR4x0LS5r-htg6_rarPKxBzJ3I3h_qYCo_5OXUVY48 **Solana Tx Link:** https://explorer.solana.com/tx/3hnxv3Um3beiSp4zpL2ESL8sTmWND8ejwHYfakZg7NC4pNoAMxMRXVKuYJRuF3AtenBSZDc9WS7S9C3Vk1rpicRp **Screenshot:** ![Arweave_Tx](https://i.imgur.com/u18jw1m.png) **Cost for Arweave Tx:** $ 0.0000012948 (at $1.5/AT) **Javascript Code to check the stored transaction:** > const Arweave = require('arweave/node'); > > const arweave = Arweave.init({ > host: 'arweave.net', > port: 443, > protocol: 'https' > }); > > let data = await arweave.arql({ > op: "equals", > expr1: "Slot", > expr2: "26658576" > }); > > console.log(data); ## Cold Re-start Due to network issues or server failure some blocks can be missed so at the time of starting or restarting the server the latest block in the arweave storage will be checked. The server will always resume from the last stored tx. Using Arewave `last-tx` API, we can get the last transaction uploaded by the wallet. From that tx, we can fetch the tx info. ## Why Rust? We are using **Rust** as programming language because Rust performance is very much better than the Javascript. Although there is no Rust SDK available for Arweave, we are going to write our own code. 1. Rust has better performace: [Source](https://logdna.com/coding-for-performance-why-we-chose-rust/) > In one benchmark comparing REST API performance (using Rocket for Rust and Restify for Node.js), Rust handled 72,000 requests per second compared to Node.js’ 8,000, and used just over 1MB of memory when idle compared to Node.js’ 19MB. In another benchmark comparing web frameworks (nickel for Rust and restana for Node.js), Rust responded to requests nearly 100x faster on average than Node.js. 2. There is no chances of race condition. It will help sending tx on Arweave without any issue. 3. CPU usage of Rust is way less than other languages. 4. Memory usage is also less than other languages. ## References [1] https://solana-labs.github.io/solana-web3.js/ [2] https://docs.arweave.org/developers/ [3] https://docs.rs/solana-client/1.2.9/solana_client/ [4] https://docs.rs/solana-transaction-status/1.1.23/solana_transaction_status/ [5] https://docs.rs/solana-sdk/1.2.19/solana_sdk/ [6] https://docs.rs/arweaver/0.1.0/arweaver/ [7] https://logdna.com/coding-for-performance-why-we-chose-rust/