Sat. Jan 1st, 2022
    RSquad, Solana

    Founded in 2017, the Solana blockchain platform managed to make a breakthrough in the world of blockchain technology. The project aims to create a scalable, secure, and highly decentralized platform that can potentially support thousands of nodes without sacrificing throughput, helping to avoid some problems faced by competing systems.

    Alexey Polyakov, Blockchain Practice Leader at RSquad, shares his experience.

    Theoretical Framework For Getting Started With Solana Blockchain

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

    The feature of development under Solana is that, in this blockchain, smart contracts are stateless, which means they cannot change their state. That is why they are called programs here because that is the definition that fits such an implementation.

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

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

    Program execution begins with a transaction being sent to the cluster. Several instructions can be placed in a transaction. Each of the instructions in the transaction will be executed in order and atomically. If any instruction fails, all account changes in the transaction are canceled.

    Account

    As already mentioned, the account is the basic unit in the Solana blockchain. The account has several roles, depending on what parameter values are set for it during registration. Key roles:

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

    The account information structure is shown below:

    The parameters that we will be interested in now:

    • is_writable;
    • executable.

    Program

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

    Initially, the account contains zero data, but it is already known what structures will be stored, so we know how much space will be occupied.

    The newly created account originally belongs to the System program. It can transfer the account to another owner. Owner information is contained in the account information in the field owner. The owner’s public key is written to it.

    For a program, the public key is program_id. The account owner stores a private key that is used to sign transactions. These keys generate a unique pair that can be used to confirm ownership of the account.

    A program always has an entry point, which is where the program execution starts. And it must be the only one for the program.

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

    Instruction is the smallest unit of a program that a client can include in a transaction. Within its processing code, an instruction may contain one or more cross-program invocations.

    Read-only

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

    Data storage

    And the third role is data storage, which is the result of the execution of programs and is stored in the corresponding account. There is a fee 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 handles this. To transfer lamports funds, is_writable = true is required.

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

    Minimum Balance

    Before deploying the program, it is possible to calculate the value of the lamports parameter that needs to be deposited into the account. If there are more funds on the account than the calculated amount, the account will be available and funds will not be withdrawn from it.

    Rent Per Epoch

    A small number of lamports are withdrawn every two days. When the balance reaches zero, the account is deleted.

    Transactions

    Program execution begins with a transaction being submitted to the cluster. The Solana runtime will execute a 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 item in the signatures array is a digital signature of the given message. The Solana runtime verifies that the number of signatures matches the number in the first 8 bits of the message header. It also verifies that each signature was signed by the private key corresponding to the public key at the same index in the message’s account addresses array.

    Protection against repeating transactions

    A transaction includes a recent blockhash to prevent duplication and to give transactions lifetimes. Any transaction that is completely identical to a previous one is rejected, so adding a newer blockhash allows multiple transactions to repeat the exact same action.

    Transactions also have lifetimes that are defined by the blockhash, as any transaction whose blockhash is too old will be rejected.

    Instead Of A Conclusion

    We reviewed the basic principles of the Solana blockchain from a developer’s perspective. The platform is promising, and the number of projects that use Solana blockchain continues to grow. Along with impressive speeds, the platform boasts a fairly 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.

    9
    0