Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning

Overview

versioning-solana

This repo demonstrates ONE rudimentary way to upgrade/migrate account data changes with solana program changes.

What is data versioning?

Fundamentally to version data means to create a unique reference for a collection of data. This reference can take the form of a query, an ID, or also commonly a datetime identifier.

Simple scenario:

  1. You create a program that stores a u64 value in your program's accounts data, assume you initialized the account and set somevalue to 50u64

alt text

  1. Later on you decide that you want to also have some String value to reside in the account data that the rest of your program requires to be present

What do you do? There are a few options:

  1. If the initial allocation of your program account has room to spare, and you had the foresite to include a 'data version' indicator in the account data: This repo will demonstrate an approach

  2. If the initial allocation was sized specifically to the u64:

    • If you are running with a Solana version that incorporates the 'account re-allocation feature' (v 1.10.?) then leverage that
    • Otherwise, leveraging PDAs may help but someone else can demonstrate that

On with the show

alt text In your initial planning, make sure to include a 'data version' field in your data. It can be a simple incrementing ordinal (e.g. u8) or something more sophisticated, up to you.

alt text When creating the Program account, allocate enough space for data growth

Demonstration

First Version (data_version = 0)

  1. Clone this repo
  2. Change to repo folder
  3. git checkout v0.0.1
  4. Change to program folder
  5. cargo build-bpf
  6. Change back to repo folder
  7. code .
  8. Open the prechange.rs file in the main test folder
  9. Click Run Test on fn test_load_pass()
  10. Open the postchange.rs file 11 Click Run Test on fn test_pre_data_change_load_pass()
  11. Exit code
  12. mkdir stored
  13. Open another terminal and change to this repo folder then
  14. solana-test-validator -l ./.ledger
  15. From the first folder terminal:
    • solana account -o stored/user1.json --output json-compact keys/accounts/user1_account.json
    • solana account -o stored/user2.json --output json-compact keys/accounts/user2_account.json
  16. In the terminal running solana-test-validator hit Ctrl+C to kill it

This will create two accounts with somevalue to 1 and then modify each of their 1's value to 50u64. Steps 13 - 16 are to export the accounts from the ledger for use in the next steps.

First Version (data_version = 1)

  1. From repo main folder run cargo clean
  2. git checkout main
  3. Change to program folder
  4. cargo build-bpf
  5. Change back to repo folder
  6. code .
  7. Open the postchange.rs file in the main test folder
  8. Click Run Test on fn test_post_data_change_u2_pass()

The results will be as below

alt text

You might also like...
This is the Repo used to learn blockchain development in conjusction with the CyberGen NFT Project.

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

A pairing-based threshold cryptosystem for collaborative decryption and signatures used in HoneybadgerBFT implementation

threshold_crypto A pairing-based threshold cryptosystem for collaborative decryption and signatures. The threshold_crypto crate provides cryptographic

CLI tool written in Rust which can be used to generate hashes

rustgenhash rustgenhash is a tool to generate hashes on the commandline from stdio. It can be used to generate single or multiple hashes for usage in

A Rust port of the password primitives used in Django Project.

Rust DjangoHashers A Rust port of the password primitives used in Django Project. Django's django.contrib.auth.models.User class has a few methods to

A secure development tool box and fintech application made with Rust to be used for developing cryptocurrencies on the blockchain.

Crypto Fintech Tools for Rust (CFT) Dependencies Rust MacOS Homebrew # xcode cli tools xcode-select --install # install dependencies using Homebrew b

Dexios-Core is a library used for managing cryptographic functions and headers that adhere to the Dexios format.
Dexios-Core is a library used for managing cryptographic functions and headers that adhere to the Dexios format.

What is it? Dexios-Core is a library used for managing cryptographic functions and headers that adhere to the Dexios format. Security Dexios-Core uses

Package used by the cosmos-rust-interface. Makes direct use of cosmos-rust.

Package used by the cosmos-rust-interface. Makes direct use of cosmos-rust (cosmos‑sdk‑proto, osmosis-proto, cosmrs).

Common cryptographic library used in software at Mysten Labs.

[fastcrypto] fastcrypto is a common cryptography library used in software at Mysten Labs. It is published as an independent crate to encourage reusabi

Benchmarks of most widely used web frameworks built in rust.
Benchmarks of most widely used web frameworks built in rust.

Rust framework benchmarks Benchmarking utility to test the performance of all the rust web frameworks. Built with rust 🚀 . Demo (Last updated: Thu Ju

Owner
Frank V. Castellucci
Frank V. Castellucci
A tool for bulk downloading and exporting the account data inside Solana snapshots.

Memento Memento is a tool used to load and save accounts from old Solana snapshots in Google Cloud Storage. Why should I use Memento? No fighting sola

null 23 Dec 16, 2023
a Solana program for granting friends permissions on your account without revealing your private key.

Delegatooooor Granting Permission: An account holder (the delegator) decides to grant permission to a delegate. They create and sign a transaction tha

0xGhostMac 3 Apr 3, 2024
A Substrate-based PoA node supporting dynamic addition/removal of authorities.

Substrate PoA A sample Substrate runtime for a PoA blockchain that allows: Dynamically add/remove authorities. Automatically remove authorities when t

Gautam Dhameja 10 Jun 16, 2022
An all-in-one IBC protocol providing fungible token transfer, interchain account, and async query functionalities

ICS-999 An all-in-one IBC protocol providing fungible token transfer, interchain account (ICA), and query (ICQ) functionalities, implemented in CosmWa

larry 9 Apr 1, 2023
My attempt at learning Solana program (smart contract) development through RareSkill's Solana course.

60-days-of-solana My attempt at learning Solana program (smart contract) development through RareSkill's Solana course. Originally, I was trying to cr

Jasper 3 Feb 25, 2024
Extract data from helium-programs via Solana RPC and serves it via HTTP

hnt-explorer This application extracts data from helium-programs via Solana RPC and serves it via HTTP. There are CLI commands meant to run and test t

Louis Thiery 3 May 4, 2023
Automated Solana tool for quick arbitrage, customizable, with real-time data and wallet integration. Trade responsibly.

Solana Arbitrage Trading Tool The Solana Arbitrage Trading Tool is an automated solution crafted to spot and capitalize on arbitrage opportunities wit

null 43 Mar 12, 2024
A guide for Mozilla's developers and data scientists to analyze and interpret the data gathered by our data collection systems.

Mozilla Data Documentation This documentation was written to help Mozillians analyze and interpret data collected by our products, such as Firefox and

Mozilla 75 Dec 1, 2022
A Rust port of the password primitives used in Django Project.

Rust DjangoHashers A Rust port of the password primitives used in Django Project. Django's django.contrib.auth.models.User class has a few methods to

Ronaldo Ferreira 52 Nov 17, 2022
A temporary repo for ETH connector to be used by EVM

ETH connector for Rainbow bridge Definitions bridgedETH - NEP-141 fungible-token representation of ETH inside Near. nETH - native ETH inside Near EVM.

Project Aurora 36 Jul 26, 2022