Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[solana] Ensure window length cannot exceed checkpoint account limit #252

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion solana/programs/staking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ crate-type = ["cdylib", "lib"]
name = "staking"

[features]
testing = []
no-entrypoint = []
no-idl = []
no-log-ix-name = []
@@ -17,7 +18,7 @@ wasm = ["no-entrypoint", "js-sys", "bincode"]
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build", "wormhole-anchor-sdk/idl-build"]
default = ["testnet", "idl-build"]
localnet = ["wormhole-solana-consts/localnet"]
testnet = ["wormhole-solana-consts/testnet", "wormhole-anchor-sdk/solana-devnet"]
testnet = ["testing", "wormhole-solana-consts/testnet", "wormhole-anchor-sdk/solana-devnet"]
mainnet = ["wormhole-solana-consts/mainnet", "wormhole-anchor-sdk/mainnet"]

[dependencies]
6 changes: 6 additions & 0 deletions solana/programs/staking/src/lib.rs
Original file line number Diff line number Diff line change
@@ -99,6 +99,12 @@ pub mod staking {
// The checkpoint account contains 8 + 32 + 8 = 48 bytes of fixed data
// Every checkpoint is 8 + 8 = 16 bytes, so we can fit in (10485760 - 48) / 16 = 655,357 checkpoints
require!(args.max_checkpoints_account_limit <= 655_000, ErrorCode::InvalidCheckpointAccountLimit);
// Similarly make sure max_checkpoints_account_limit > MAX_VOTE_WEIGHT_WINDOW_LENGTH so we can't have
// 3 checkpoint accounts fall across a window. We don't mind for our tests
#[cfg(not(feature = "testing"))]
{
require!(args.max_checkpoints_account_limit > state::vote_weight_window_lengths::VoteWeightWindowLengths::MAX_VOTE_WEIGHT_WINDOW_LENGTH as u32, ErrorCode::InvalidCheckpointAccountLimit);
}
config_account.max_checkpoints_account_limit = args.max_checkpoints_account_limit;
config_account.pending_governance_authority = None;
config_account.pending_vesting_admin = None;