How the Solana Blockchain works

Rsquadlab
5 min readApr 8, 2022

--

The Solana blockchain platform, founded in 2017, has managed to make a breakthrough in the world of blockchain technology. The project aims to create a platform that is scalable, secure, and as decentralized as possible that can support potentially thousands of nodes without sacrificing throughput, helping to avoid some of the problems that competing systems face.

Alexey Polyakov, leader of the blockchain activity at RSquad, shares his experience.

Theoretical basis for getting started with the Solana blockchain

Before starting work, it is necessary to highlight the main entities that are encountered in the process of creating applications. In most blockchains, such as Free TON and Ethereum, we use the term smart contract.

The peculiarity of development for Solana is that in this blockchain smart contracts are stateless, that is, they cannot change their state. That is why they are called programs here. it is this definition that fits such an implementation.

Solana programs are mostly written in Rust. It should be understood that not all language features are available for writing programs for this blockchain. For example, the standard println!() macro won’t work here, msg!() is available instead. And even if you do not know this language perfectly, this will not be a big obstacle to getting started with Solana.

The main unit in the Solana blockchain is an account, which, depending on the parameters, can be either a program (an account that contains instructions) or a storage (stores data in itself).

The execution of the program begins with the fact that a transaction is sent to the cluster. Multiple instructions can be placed in a transaction. Each of the instructions contained in the transaction will be executed in order and atomically. If any statement fails, all account changes in the transaction are cancelled.

Account

As already mentioned, an account is the main unit in the Solana blockchain. At the same time, the account has several roles, depending on what parameter values ​​were set for it during registration. Main roles:

executable — the account becomes a program;
read-only — can be used simultaneously by several programs;
changeable — for data storage.

Below is the structure of the account information:

The parameters that we are now interested in:

  • is_writable;
  • executable.

Program

It is easy to guess that if you set the executable = true parameter, this account will actually become a program that can only execute the code that it contained during deployment.

Initially, the account contains zero data, but we already know which structures will be stored, respectively, we know how much space will be occupied.

The newly created account is originally owned by the System program. She can transfer the account to another owner. The owner data is contained in the account information in the owner field. It contains the owner’s public key.

In the case of a program, the public key is the program_id. The account owner keeps a private key, which is used to sign transactions. These keys form a unique pair that can be used to verify ownership of an account.

The program always has an entry point — this is the place where the execution of the program begins. And it should be one for the program.

Program_id is a unique public key for calling a program from another program or from the client side.

An instruction is the smallest unit of program that a client can include in a transaction. In the processing code, an instruction may contain one or more interprogram calls.

Reading only

If you set the is_writable = false flag, this account will be read-only. Such accounts solve the problem of parallel transaction processing, where it is necessary to use common data. Since this account cannot be changed, we can be sure that the data we need is valid.

Data storage

Well, the third role is the storage of data that are the result of the execution of programs and are stored in the corresponding account. There is a charge for data storage.

A new account is created without data and with a zero balance. An account can be the owner of another account, the owner parameter is responsible for this. To be able to translate lampports means is_writable = true.

Data is stored in accounts, and it is necessary to correctly set the flags and maintain a positive balance. It must be non-executable and writable. There are two ways to maintain an account — deposit a sufficient amount to the balance or pay rent.

Minimum balance

Before deploying the program, you can calculate the value of the lampports parameter that needs to be added to the account. If there are more funds on the account than the calculated amount, then the account will be available and no funds will be debited from it.

Rent per era

Every two days a small number of lampports are written off. When the balance reaches zero, the account is deleted.

Transactions

The execution of the program begins with sending a transaction to the cluster. The Solana runtime will execute the program to process each of the instructions contained in the transaction in order and atomically.

A transaction contains a compact array of signatures followed by a message. Each element in the signatures array is a digital signature of the given message. The Solana runtime checks if the number of signatures matches the number in the first 8 bits of the message header. It also verifies that each signature is signed with the private key corresponding to the public key at the same index in the message’s account address array.

Repeating Protection

The transaction includes a last blockhash parameter to prevent duplication and increase the lifetime of transactions. Any transaction that is completely identical to the previous one is rejected, so adding a new block hash allows multiple transactions to repeat the same action.

Transactions also have a lifetime, which is determined by the block hash, as any transaction whose blockhash is too old will be rejected.

Instead of output

We reviewed the basic principles of the Solana blockchain from the side of the developer. The platform is promising, and the number of projects that use the Solana blockchain continues to grow. Along with impressive speed, the platform can boast with quiet developed and growing dApps ecosystem.

For developers of other platforms, a broad understanding of how third-party solutions work is a very important advantage in creating solutions that claim to be truly cross-platform.

--

--

Rsquadlab
Rsquadlab

Written by Rsquadlab

RSquad is a international team of experts specialized in the development of decentralized information systems based on blockchain technology.

No responses yet