Skip to content

Parallel data buffers for chads who want to put data onchain fast af

License

Notifications You must be signed in to change notification settings

deanmlittle/chadbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chadbuffer

Ever find yourself having to put a lot of data onchain really fast? Use a chadbuffer!

chadbuffer

Features

chadbuffer is a heavily optimized Solana program that allows you to manage and manipulate permissioned data buffers on the Solana blockchain with parallel broadcast, optimal instruction size, self-healing state and priority fee support. It is also written in highly-performant Rust with inline assembly macros and weighs in at a mere 2.7kb in size!

  • Initialize: Create a new buffer account and initialize it with data.
  • Assign: Assign buffer authority to another address.
  • Write: Write additional data to an existing buffer.
  • Close: Finalize and close the buffer, ensuring all data is written correctly.

Installation

To use chadbuffer, you'll need to have the following installed:

Clone the Repository

git clone https://github.com/deanmlittle/chadbuffer.git
cd chadbuffer

Install Dependencies

yarn install

Configuration

Before running the program, ensure you have the necessary environment variables set up:

  • SIGNER: The path to the JSON file containing the signer's keypair.
  • RPC_URL: The RPC URL for your Solana cluster (e.g., http://127.0.0.1:8899 for local development).

Example:

export SIGNER=~/.config/solana/id.json
export RPC_URL=http://127.0.0.1:8899

Usage

Initialize a Buffer

To initialize a new buffer:

import { ChadBuffer, signAndSendWithBlockhash, connection, confirm, log } from './sdk';

const data = new Uint8Array([/* your data here */]);
const chadBuffer = new ChadBuffer(data);

async function initializeBuffer() {
    const txs = await chadBuffer.init_ixs(signer);
    await signAndSendWithBlockhash(txs[0], [signer, chadBuffer.keypair])
        .then(confirm)
        .then(log);
}

initializeBuffer().catch(console.error);

Write Data to a Buffer

To write additional data to an existing buffer:

async function writeBufferData() {
    await batchProcess(txs.slice(1), signer, 100);
}

writeBufferData().catch(console.error);

Close a Buffer

To close and finalize a buffer:

async function closeBuffer() {
    let account = await connection.getAccountInfo(chadBuffer.keypair.publicKey);
    let data = account!.data.subarray(32);
    let hashed = sha256(data);

    if (Buffer.compare(chadBuffer.hash, hashed) !== 0) {
        throw new Error("Hash mismatch");
    }

    await signAndSendWithBlockhash(chadBuffer.close_ix(signer), [signer])
        .then(confirm)
        .then(log);
}

closeBuffer().catch(console.error);

Testing

The chadbuffer program includes a suite of tests to ensure the correctness of the buffer operations. To run the tests:

yarn test

This will execute a series of Mocha tests that validate the initialization, writing, and closing operations.

Troubleshooting

Common Issues

  • Blockhash Expiry: If you encounter issues with transactions failing due to blockhash expiry, ensure you're refreshing the blockhash before processing large batches of transactions.
  • Invalid Signer: Ensure that the signer keypair is correctly configured and that the signer is authorized to perform the operations.

Debugging

If you run into issues, check the console output for detailed error messages. You can also add additional logging to the transaction processing steps to better understand where things might be going wrong.

Contributing

Contributions to chadbuffer are welcome! If you have any ideas for improvements or have found bugs, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Parallel data buffers for chads who want to put data onchain fast af

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published