Skip to content

Commit 0e9cfeb

Browse files
committed
[solana] Ensure window length cannot exceed checkpoint account limit
1 parent 252285d commit 0e9cfeb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

solana/programs/staking/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ crate-type = ["cdylib", "lib"]
99
name = "staking"
1010

1111
[features]
12+
testing = []
1213
no-entrypoint = []
1314
no-idl = []
1415
no-log-ix-name = []
@@ -17,7 +18,7 @@ wasm = ["no-entrypoint", "js-sys", "bincode"]
1718
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build", "wormhole-anchor-sdk/idl-build"]
1819
default = ["testnet", "idl-build"]
1920
localnet = ["wormhole-solana-consts/localnet"]
20-
testnet = ["wormhole-solana-consts/testnet", "wormhole-anchor-sdk/solana-devnet"]
21+
testnet = ["testing", "wormhole-solana-consts/testnet", "wormhole-anchor-sdk/solana-devnet"]
2122
mainnet = ["wormhole-solana-consts/mainnet", "wormhole-anchor-sdk/mainnet"]
2223

2324
[dependencies]

solana/programs/staking/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ pub mod staking {
9999
// The checkpoint account contains 8 + 32 + 8 = 48 bytes of fixed data
100100
// Every checkpoint is 8 + 8 = 16 bytes, so we can fit in (10485760 - 48) / 16 = 655,357 checkpoints
101101
require!(args.max_checkpoints_account_limit <= 655_000, ErrorCode::InvalidCheckpointAccountLimit);
102+
// Similarly make sure max_checkpoints_account_limit > MAX_VOTE_WEIGHT_WINDOW_LENGTH so we can't have
103+
// 3 checkpoint accounts fall across a window. We don't mind for our tests
104+
#[cfg(not(feature = "testing"))]
105+
{
106+
require!(args.max_checkpoints_account_limit > state::vote_weight_window_lengths::VoteWeightWindowLengths::MAX_VOTE_WEIGHT_WINDOW_LENGTH as u32, ErrorCode::InvalidCheckpointAccountLimit);
107+
}
102108
config_account.max_checkpoints_account_limit = args.max_checkpoints_account_limit;
103109
config_account.pending_governance_authority = None;
104110
config_account.pending_vesting_admin = None;

0 commit comments

Comments
 (0)