Learn how to write a simple Rust program that delegates and increments a counter on Solana
Software | Version | Installation Guide |
---|---|---|
Solana | 2.0.21 | Install Solana |
Rust | 1.82.0 | Install Rust |
InitializeCounter
: Initialize and sets the counter to 0 (called on Base Layer)IncreaseCounter
: Increments the initialized counter by X amount (called on Base Layer or ER)Delegate
: Delegates counter from Base Layer to ER (called on Base Layer)CommitAndUndelegate
: Schedules sync of counter from ER to Base Layer, and undelegates counter on ER (called on ER)Commit
: Schedules sync of counter from ER to Base Layer (called on ER)Undelegate
: Undelegates counter on the Base Layer (called on Base Layer through validator CPI)delegate_account
function. delegate_account
will CPI to the delegation program, which upon validation will gain ownership of the account.
After this step, an ephemeral validator can start processing transactions on the counter PDA and propose state diff trough the delegation program.
commit_accounts
function.
commit_and_undelegate_accounts
as part of some instruction.
Undelegation commit the latest state and give back the ownership of the PDA to the owner program. After undelegating and finalizing the state, the validator will create a callback CPI into “undelegate” on the Base Layer.
delegation
transactiondelegation
of your program. Send the transaction with the instruction to Base Layer (Solana) network.
commit
transactioncommit
of your program. Send the transaction with the instruction to ER network.
undelegation
transactionundelegation
of your program. Send the transaction with the instruction to ER network.