solana-runtime 4.0.0-beta.7

Solana runtime
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
#[allow(deprecated)]
use solana_stake_interface::config::Config as StakeConfig;
use {
    crate::{bank::VAT_TO_BURN_PER_EPOCH, stake_utils},
    agave_feature_set::{FEATURE_NAMES, FeatureSet, vote_state_v4},
    agave_votor_messages::{
        self,
        consensus_message::{BLS_KEYPAIR_DERIVE_SEED, Certificate, CertificateType},
        migration::GENESIS_CERTIFICATE_ACCOUNT,
    },
    bincode::serialize,
    log::*,
    solana_account::{Account, AccountSharedData, ReadableAccount, state_traits::StateMut},
    solana_bls_signatures::{
        Pubkey as BLSPubkey, Signature as BLSSignature, keypair::Keypair as BLSKeypair,
        pubkey::PubkeyCompressed as BLSPubkeyCompressed,
    },
    solana_clock::Epoch,
    solana_cluster_type::ClusterType,
    solana_config_interface::state::ConfigKeys,
    solana_feature_gate_interface::{self as feature, Feature},
    solana_fee_calculator::FeeRateGovernor,
    solana_genesis_config::GenesisConfig,
    solana_hash::Hash,
    solana_keypair::Keypair,
    solana_native_token::LAMPORTS_PER_SOL,
    solana_pubkey::Pubkey,
    solana_rent::Rent,
    solana_sdk_ids::{stake as stake_program, sysvar},
    solana_seed_derivable::SeedDerivable,
    solana_signer::Signer,
    solana_stake_interface::state::{Authorized, Lockup, Meta, StakeStateV2},
    solana_system_interface::program as system_program,
    solana_sysvar::{
        SysvarSerialize,
        epoch_rewards::{self, EpochRewards},
    },
    solana_vote_interface::state::{BLS_PUBLIC_KEY_COMPRESSED_SIZE, VoteStateV4},
    solana_vote_program::vote_state,
    std::{borrow::Borrow, sync::Arc},
};

// Default amount received by the validator
const VALIDATOR_LAMPORTS: u64 = 890_880;

// Minimum vote account balance required for VAT (SIMD-0357).
// Vote accounts need this minimum to pass VAT filtering.
pub fn minimum_vote_account_balance_for_vat(num_epochs: Epoch) -> u64 {
    VAT_TO_BURN_PER_EPOCH * num_epochs + Rent::default().minimum_balance(VoteStateV4::size_of())
}

// Minimum stake lamports required for a valid stake account with non-zero stake.
// This is rent_exempt_reserve + 1 lamport of actual stake.
pub fn minimum_stake_lamports_for_vat(rent: &Rent) -> u64 {
    rent.minimum_balance(StakeStateV2::size_of()) + 1
}

pub fn bootstrap_validator_stake_lamports() -> u64 {
    minimum_stake_lamports_for_vat(&Rent::default())
}

// Number of lamports automatically used for genesis accounts
pub const fn genesis_sysvar_and_builtin_program_lamports() -> u64 {
    const NUM_BUILTIN_PROGRAMS: u64 = 6;
    const NUM_PRECOMPILES: u64 = 2;
    const STAKE_HISTORY_MIN_BALANCE: u64 = 114_979_200;
    const CLOCK_SYSVAR_MIN_BALANCE: u64 = 1_169_280;
    const RENT_SYSVAR_MIN_BALANCE: u64 = 1_009_200;
    const EPOCH_SCHEDULE_SYSVAR_MIN_BALANCE: u64 = 1_120_560;
    const RECENT_BLOCKHASHES_SYSVAR_MIN_BALANCE: u64 = 42_706_560;

    STAKE_HISTORY_MIN_BALANCE
        + CLOCK_SYSVAR_MIN_BALANCE
        + RENT_SYSVAR_MIN_BALANCE
        + EPOCH_SCHEDULE_SYSVAR_MIN_BALANCE
        + RECENT_BLOCKHASHES_SYSVAR_MIN_BALANCE
        + NUM_BUILTIN_PROGRAMS
        + NUM_PRECOMPILES
}

pub struct ValidatorVoteKeypairs {
    pub node_keypair: Keypair,
    pub vote_keypair: Keypair,
    pub stake_keypair: Keypair,
    pub bls_keypair: BLSKeypair,
}

impl ValidatorVoteKeypairs {
    pub fn new(node_keypair: Keypair, vote_keypair: Keypair, stake_keypair: Keypair) -> Self {
        let bls_keypair =
            BLSKeypair::derive_from_signer(&vote_keypair, BLS_KEYPAIR_DERIVE_SEED).unwrap();
        Self {
            node_keypair,
            vote_keypair,
            stake_keypair,
            bls_keypair,
        }
    }

    pub fn new_rand() -> Self {
        let node_keypair = Keypair::new();
        let vote_keypair = Keypair::new();
        let stake_keypair = Keypair::new();
        Self::new(node_keypair, vote_keypair, stake_keypair)
    }
}

pub struct GenesisConfigInfo {
    pub genesis_config: GenesisConfig,
    pub mint_keypair: Keypair,
    pub voting_keypair: Keypair,
    pub validator_pubkey: Pubkey,
}

pub fn create_genesis_config(mint_lamports: u64) -> GenesisConfigInfo {
    // Note that zero lamports for validator stake will result in stake account
    // not being stored in accounts-db but still cached in bank stakes. This
    // causes discrepancy between cached stakes accounts in bank and
    // accounts-db which in particular will break snapshots test.
    create_genesis_config_with_leader(
        mint_lamports,
        &solana_pubkey::new_rand(), // validator_pubkey
        0,                          // validator_stake_lamports
    )
}

pub fn create_genesis_config_with_vote_accounts(
    mint_lamports: u64,
    voting_keypairs: &[impl Borrow<ValidatorVoteKeypairs>],
    stakes: Vec<u64>,
) -> GenesisConfigInfo {
    create_genesis_config_with_vote_accounts_and_cluster_type(
        mint_lamports,
        voting_keypairs,
        stakes,
        ClusterType::Development,
        &FeatureSet::all_enabled(),
        false,
    )
}

#[cfg(feature = "dev-context-only-utils")]
pub fn create_genesis_config_with_alpenglow_vote_accounts(
    mint_lamports: u64,
    voting_keypairs: &[impl Borrow<ValidatorVoteKeypairs>],
    stakes: Vec<u64>,
) -> GenesisConfigInfo {
    create_genesis_config_with_vote_accounts_and_cluster_type(
        mint_lamports,
        voting_keypairs,
        stakes,
        ClusterType::Development,
        &FeatureSet::all_enabled(),
        true,
    )
}

pub fn create_genesis_config_with_vote_accounts_and_cluster_type(
    mint_lamports: u64,
    voting_keypairs: &[impl Borrow<ValidatorVoteKeypairs>],
    stakes: Vec<u64>,
    cluster_type: ClusterType,
    feature_set: &FeatureSet,
    is_alpenglow: bool,
) -> GenesisConfigInfo {
    assert!(!voting_keypairs.is_empty());
    assert_eq!(voting_keypairs.len(), stakes.len());

    let mint_keypair = Keypair::new();
    let voting_keypair = voting_keypairs[0].borrow().vote_keypair.insecure_clone();

    let validator_pubkey = voting_keypairs[0].borrow().node_keypair.pubkey();
    let validator_bls_pubkey = Some(
        voting_keypairs[0]
            .borrow()
            .bls_keypair
            .public
            .to_bytes_compressed(),
    );
    let mut genesis_config = create_genesis_config_with_leader_ex(
        mint_lamports,
        &mint_keypair.pubkey(),
        &validator_pubkey,
        &voting_keypairs[0].borrow().vote_keypair.pubkey(),
        &voting_keypairs[0].borrow().stake_keypair.pubkey(),
        validator_bls_pubkey,
        stakes[0],
        VALIDATOR_LAMPORTS,
        FeeRateGovernor::new(0, 0), // most tests can't handle transaction fees
        Rent::free(),               // most tests don't expect rent
        cluster_type,
        feature_set,
        vec![],
    );

    if is_alpenglow {
        activate_all_features_alpenglow(&mut genesis_config);
    }

    let mut genesis_config_info = GenesisConfigInfo {
        genesis_config,
        mint_keypair,
        voting_keypair,
        validator_pubkey,
    };

    for (validator_voting_keypairs, stake) in voting_keypairs[1..].iter().zip(&stakes[1..]) {
        let node_pubkey = validator_voting_keypairs.borrow().node_keypair.pubkey();
        let vote_pubkey = validator_voting_keypairs.borrow().vote_keypair.pubkey();
        let stake_pubkey = validator_voting_keypairs.borrow().stake_keypair.pubkey();

        // Ensure minimum lamports for VAT filtering, but only when stake > 0.
        // When stake is explicitly 0, respect that (e.g., for testing unstaked validator filtering).
        let rent = &genesis_config_info.genesis_config.rent;
        let (vote_account_lamports, stake_lamports) = if *stake > 0 {
            (
                (*stake).max(minimum_vote_account_balance_for_vat(100)),
                (*stake).max(minimum_stake_lamports_for_vat(rent)),
            )
        } else {
            // Zero stake - just need rent exemption, no VAT minimums
            (
                rent.minimum_balance(VoteStateV4::size_of()),
                rent.minimum_balance(StakeStateV2::size_of()),
            )
        };

        // Create accounts
        let node_account = Account::new(VALIDATOR_LAMPORTS, 0, &system_program::id());
        let bls_pubkey_compressed = validator_voting_keypairs
            .borrow()
            .bls_keypair
            .public
            .to_bytes_compressed();
        let vote_account = if feature_set.is_active(&vote_state_v4::id()) {
            // Vote state v4 feature active. Create a v4 account.
            vote_state::create_v4_account_with_authorized(
                &node_pubkey,
                &vote_pubkey,
                bls_pubkey_compressed,
                &vote_pubkey,
                0,
                &vote_pubkey,
                0,
                &vote_pubkey,
                vote_account_lamports,
            )
        } else {
            vote_state::create_v3_account_with_authorized(
                &node_pubkey,
                &vote_pubkey,
                &vote_pubkey,
                0,
                vote_account_lamports,
            )
        };
        let stake_account = Account::from(stake_utils::create_stake_account(
            &stake_pubkey,
            &vote_pubkey,
            &vote_account,
            &genesis_config_info.genesis_config.rent,
            stake_lamports,
        ));

        let vote_account = Account::from(vote_account);

        // Put newly created accounts into genesis
        genesis_config_info.genesis_config.accounts.extend(vec![
            (node_pubkey, node_account),
            (vote_pubkey, vote_account),
            (stake_pubkey, stake_account),
        ]);
    }

    genesis_config_info
}

pub fn create_genesis_config_with_leader(
    mint_lamports: u64,
    validator_pubkey: &Pubkey,
    validator_stake_lamports: u64,
) -> GenesisConfigInfo {
    // Use deterministic keypair so we don't get confused by randomness in tests
    let mint_keypair = Keypair::from_seed(&[
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
        25, 26, 27, 28, 29, 30, 31,
    ])
    .unwrap();

    create_genesis_config_with_leader_with_mint_keypair(
        mint_keypair,
        mint_lamports,
        validator_pubkey,
        validator_stake_lamports,
    )
}

pub fn create_genesis_config_with_leader_with_mint_keypair(
    mint_keypair: Keypair,
    mint_lamports: u64,
    validator_pubkey: &Pubkey,
    validator_stake_lamports: u64,
) -> GenesisConfigInfo {
    // Use deterministic keypair so we don't get confused by randomness in tests
    let voting_keypair = Keypair::from_seed(&[
        32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
        55, 56, 57, 58, 59, 60, 61, 62, 63,
    ])
    .unwrap();

    let bls_keypair =
        BLSKeypair::derive_from_signer(&voting_keypair, BLS_KEYPAIR_DERIVE_SEED).unwrap();
    let validator_bls_pubkey = Some(bls_keypair.public.to_bytes_compressed());

    let genesis_config = create_genesis_config_with_leader_ex(
        mint_lamports,
        &mint_keypair.pubkey(),
        validator_pubkey,
        &voting_keypair.pubkey(),
        &Pubkey::new_unique(),
        validator_bls_pubkey,
        validator_stake_lamports,
        VALIDATOR_LAMPORTS,
        FeeRateGovernor::new(0, 0), // most tests can't handle transaction fees
        Rent::free(),               // most tests don't expect rent
        ClusterType::Development,
        &FeatureSet::all_enabled(),
        vec![],
    );

    GenesisConfigInfo {
        genesis_config,
        mint_keypair,
        voting_keypair,
        validator_pubkey: *validator_pubkey,
    }
}

pub fn activate_all_features_alpenglow(genesis_config: &mut GenesisConfig) {
    do_activate_all_features::<true>(genesis_config);

    // This is a dev cluster with alpenglow enabled at genesis. We don't want to test the migration pathway
    // so we add a fake genesis certificate.
    let cert = Certificate {
        cert_type: CertificateType::Genesis(0, Hash::default()),
        signature: BLSSignature::default(),
        bitmap: Vec::default(),
    };
    let cert_size = bincode::serialized_size(&cert).unwrap();
    let lamports = Rent::default().minimum_balance(cert_size as usize);
    let certificate_account = Account::new_data(lamports, &cert, &system_program::ID).unwrap();

    genesis_config
        .accounts
        .insert(*GENESIS_CERTIFICATE_ACCOUNT, certificate_account);
}

pub fn activate_all_features(genesis_config: &mut GenesisConfig) {
    do_activate_all_features::<false>(genesis_config);
}

fn do_activate_all_features<const IS_ALPENGLOW: bool>(genesis_config: &mut GenesisConfig) {
    // Activate all features at genesis in development mode
    for feature_id in FeatureSet::default().inactive() {
        if IS_ALPENGLOW || *feature_id != agave_feature_set::alpenglow::id() {
            activate_feature(genesis_config, *feature_id);
        }
    }
}

pub fn deactivate_features(
    genesis_config: &mut GenesisConfig,
    features_to_deactivate: &Vec<Pubkey>,
) {
    // Remove all features in `features_to_skip` from genesis
    for deactivate_feature_pk in features_to_deactivate {
        if FEATURE_NAMES.contains_key(deactivate_feature_pk) {
            genesis_config.accounts.remove(deactivate_feature_pk);
        } else {
            warn!(
                "Feature {deactivate_feature_pk:?} set for deactivation is not a known Feature \
                 public key"
            );
        }
    }
}

pub fn activate_feature(genesis_config: &mut GenesisConfig, feature_id: Pubkey) {
    genesis_config.accounts.insert(
        feature_id,
        Account::from(feature::create_account(
            &Feature {
                activated_at: Some(0),
            },
            std::cmp::max(genesis_config.rent.minimum_balance(Feature::size_of()), 1),
        )),
    );
}

pub fn bls_pubkey_to_compressed_bytes(
    bls_pubkey: &BLSPubkey,
) -> [u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE] {
    let key = BLSPubkeyCompressed::try_from(bls_pubkey).unwrap();
    bincode::serialize(&key).unwrap().try_into().unwrap()
}

#[allow(clippy::too_many_arguments)]
pub fn create_genesis_config_with_leader_ex_no_features(
    mint_lamports: u64,
    mint_pubkey: &Pubkey,
    validator_pubkey: &Pubkey,
    validator_vote_account_pubkey: &Pubkey,
    validator_stake_account_pubkey: &Pubkey,
    validator_bls_pubkey: Option<[u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE]>,
    validator_stake_lamports: u64,
    validator_lamports: u64,
    fee_rate_governor: FeeRateGovernor,
    rent: Rent,
    cluster_type: ClusterType,
    feature_set: &FeatureSet,
    mut initial_accounts: Vec<(Pubkey, AccountSharedData)>,
) -> GenesisConfig {
    // Ensure minimum lamports for VAT filtering, but only when stake > 0.
    // VAT requires: non-zero stake, BLS pubkey, and lamports >= VAT_TO_BURN_PER_EPOCH + rent_exempt_minimum.
    let (vote_account_lamports, stake_lamports) = if validator_stake_lamports > 0 {
        (
            validator_stake_lamports.max(minimum_vote_account_balance_for_vat(100)),
            validator_stake_lamports.max(minimum_stake_lamports_for_vat(&rent)),
        )
    } else {
        // Zero stake - just need rent exemption, no VAT minimums
        (
            rent.minimum_balance(VoteStateV4::size_of()),
            rent.minimum_balance(StakeStateV2::size_of()),
        )
    };

    let validator_vote_account = if feature_set.is_active(&vote_state_v4::id()) {
        // Vote state v4 feature active. Create a v4 account.
        vote_state::create_v4_account_with_authorized(
            validator_pubkey,
            validator_vote_account_pubkey,
            validator_bls_pubkey.unwrap_or([0u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE]),
            validator_vote_account_pubkey,
            0,
            validator_vote_account_pubkey,
            0,
            validator_vote_account_pubkey,
            vote_account_lamports,
        )
    } else {
        // Vote state v4 feature inactive. Create a v3 account.
        if validator_bls_pubkey.is_some() {
            warn!(
                "BLS pubkey provided but vote_state_v4 feature is not active. BLS pubkey will be \
                 ignored."
            );
        }
        vote_state::create_v3_account_with_authorized(
            validator_pubkey,
            validator_vote_account_pubkey,
            validator_vote_account_pubkey,
            0,
            vote_account_lamports,
        )
    };

    let validator_stake_account = stake_utils::create_stake_account(
        validator_stake_account_pubkey,
        validator_vote_account_pubkey,
        &validator_vote_account,
        &rent,
        stake_lamports,
    );

    initial_accounts.push((
        *mint_pubkey,
        AccountSharedData::new(mint_lamports, 0, &system_program::id()),
    ));
    initial_accounts.push((
        *validator_pubkey,
        AccountSharedData::new(validator_lamports, 0, &system_program::id()),
    ));
    initial_accounts.push((*validator_vote_account_pubkey, validator_vote_account));
    initial_accounts.push((*validator_stake_account_pubkey, validator_stake_account));

    let native_mint_account = solana_account::AccountSharedData::from(Account {
        owner: spl_generic_token::token::id(),
        data: spl_generic_token::token::native_mint::ACCOUNT_DATA.to_vec(),
        lamports: LAMPORTS_PER_SOL,
        executable: false,
        rent_epoch: 1,
    });
    initial_accounts.push((
        spl_generic_token::token::native_mint::id(),
        native_mint_account,
    ));

    let mut genesis_config = GenesisConfig {
        accounts: initial_accounts
            .iter()
            .cloned()
            .map(|(key, account)| (key, Account::from(account)))
            .collect(),
        fee_rate_governor,
        rent,
        cluster_type,
        ..GenesisConfig::default()
    };

    add_genesis_stake_config_account(&mut genesis_config);
    add_genesis_epoch_rewards_account(&mut genesis_config);

    genesis_config
}

#[allow(clippy::too_many_arguments)]
pub fn create_genesis_config_with_leader_ex(
    mint_lamports: u64,
    mint_pubkey: &Pubkey,
    validator_pubkey: &Pubkey,
    validator_vote_account_pubkey: &Pubkey,
    validator_stake_account_pubkey: &Pubkey,
    validator_bls_pubkey: Option<[u8; BLS_PUBLIC_KEY_COMPRESSED_SIZE]>,
    validator_stake_lamports: u64,
    validator_lamports: u64,
    fee_rate_governor: FeeRateGovernor,
    rent: Rent,
    cluster_type: ClusterType,
    feature_set: &FeatureSet,
    initial_accounts: Vec<(Pubkey, AccountSharedData)>,
) -> GenesisConfig {
    let mut genesis_config = create_genesis_config_with_leader_ex_no_features(
        mint_lamports,
        mint_pubkey,
        validator_pubkey,
        validator_vote_account_pubkey,
        validator_stake_account_pubkey,
        validator_bls_pubkey,
        validator_stake_lamports,
        validator_lamports,
        fee_rate_governor,
        rent,
        cluster_type,
        feature_set,
        initial_accounts,
    );

    for feature_id in feature_set.active().keys() {
        // Skip alpenglow (existing behavior)
        if *feature_id == agave_feature_set::alpenglow::id() {
            continue;
        }
        activate_feature(&mut genesis_config, *feature_id);
    }

    genesis_config
}

#[allow(deprecated)]
pub fn add_genesis_stake_config_account(genesis_config: &mut GenesisConfig) -> u64 {
    let mut data = serialize(&ConfigKeys { keys: vec![] }).unwrap();
    data.extend_from_slice(&serialize(&StakeConfig::default()).unwrap());
    let lamports = std::cmp::max(genesis_config.rent.minimum_balance(data.len()), 1);
    let account = AccountSharedData::from(Account {
        lamports,
        data,
        owner: solana_sdk_ids::config::id(),
        ..Account::default()
    });

    genesis_config.add_account(solana_stake_interface::config::id(), account);

    lamports
}

pub fn add_genesis_epoch_rewards_account(genesis_config: &mut GenesisConfig) -> u64 {
    let data = vec![0; EpochRewards::size_of()];
    let lamports = std::cmp::max(genesis_config.rent.minimum_balance(data.len()), 1);

    let account = AccountSharedData::create_from_existing_shared_data(
        lamports,
        Arc::new(data),
        sysvar::id(),
        false,
        u64::MAX,
    );

    genesis_config.add_account(epoch_rewards::id(), account);

    lamports
}

// genesis investor accounts
pub fn create_lockup_stake_account(
    authorized: &Authorized,
    lockup: &Lockup,
    rent: &Rent,
    lamports: u64,
) -> AccountSharedData {
    let mut stake_account =
        AccountSharedData::new(lamports, StakeStateV2::size_of(), &stake_program::id());

    let rent_exempt_reserve = rent.minimum_balance(stake_account.data().len());
    assert!(
        lamports >= rent_exempt_reserve,
        "lamports: {lamports} is less than rent_exempt_reserve {rent_exempt_reserve}"
    );

    stake_account
        .set_state(&StakeStateV2::Initialized(Meta {
            authorized: *authorized,
            lockup: *lockup,
            rent_exempt_reserve,
        }))
        .expect("set_state");

    stake_account
}