Эх сурвалжийг харах

clean up remaining vote state v4 TODOs (#8540)

* vote-state-v4: clean up remaining TODOs

* vote: update tests/benches

* review
Joe C 1 сар өмнө
parent
commit
1609179ea3

+ 5 - 5
genesis/src/main.rs

@@ -43,7 +43,7 @@ use {
     solana_signer::Signer,
     solana_signer::Signer,
     solana_stake_interface::state::StakeStateV2,
     solana_stake_interface::state::StakeStateV2,
     solana_stake_program::stake_state,
     solana_stake_program::stake_state,
-    solana_vote_program::vote_state::{self, VoteStateV3},
+    solana_vote_program::vote_state::{self, VoteStateV4},
     std::{
     std::{
         collections::HashMap,
         collections::HashMap,
         error,
         error,
@@ -254,7 +254,7 @@ fn add_validator_accounts(
             identity_pubkey,
             identity_pubkey,
             identity_pubkey,
             identity_pubkey,
             commission,
             commission,
-            rent.minimum_balance(VoteStateV3::size_of()).max(1),
+            rent.minimum_balance(VoteStateV4::size_of()).max(1),
         );
         );
 
 
         genesis_config.add_account(
         genesis_config.add_account(
@@ -314,7 +314,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
 
 
     // vote account
     // vote account
     let default_bootstrap_validator_lamports = &(500 * LAMPORTS_PER_SOL)
     let default_bootstrap_validator_lamports = &(500 * LAMPORTS_PER_SOL)
-        .max(rent.minimum_balance(VoteStateV3::size_of()))
+        .max(rent.minimum_balance(VoteStateV4::size_of()))
         .to_string();
         .to_string();
     // stake account
     // stake account
     let default_bootstrap_validator_stake_lamports = &(LAMPORTS_PER_SOL / 2)
     let default_bootstrap_validator_stake_lamports = &(LAMPORTS_PER_SOL / 2)
@@ -1322,10 +1322,10 @@ mod tests {
                 // check vote account
                 // check vote account
                 let vote_pk = b64_account.vote_account.parse().unwrap();
                 let vote_pk = b64_account.vote_account.parse().unwrap();
                 let vote_data = genesis_config.accounts[&vote_pk].data.clone();
                 let vote_data = genesis_config.accounts[&vote_pk].data.clone();
-                let vote_state = VoteStateV3::deserialize(&vote_data).unwrap();
+                let vote_state = VoteStateV4::deserialize(&vote_data, &vote_pk).unwrap();
                 assert_eq!(vote_state.node_pubkey, identity_pk);
                 assert_eq!(vote_state.node_pubkey, identity_pk);
                 assert_eq!(vote_state.authorized_withdrawer, identity_pk);
                 assert_eq!(vote_state.authorized_withdrawer, identity_pk);
-                let authorized_voters = vote_state.authorized_voters();
+                let authorized_voters = &vote_state.authorized_voters;
                 assert_eq!(authorized_voters.first().unwrap().1, &identity_pk);
                 assert_eq!(authorized_voters.first().unwrap().1, &identity_pk);
 
 
                 // check stake account
                 // check stake account

+ 3 - 3
program-test/tests/setup.rs

@@ -12,7 +12,7 @@ use {
     solana_transaction::Transaction,
     solana_transaction::Transaction,
     solana_vote_program::{
     solana_vote_program::{
         vote_instruction,
         vote_instruction,
-        vote_state::{self, VoteInit, VoteStateV3},
+        vote_state::{self, VoteInit, VoteStateV4},
     },
     },
 };
 };
 
 
@@ -54,7 +54,7 @@ pub async fn setup_vote(context: &mut ProgramTestContext) -> Pubkey {
         0,
         0,
         &system_program::id(),
         &system_program::id(),
     ));
     ));
-    let vote_lamports = Rent::default().minimum_balance(VoteStateV3::size_of());
+    let vote_lamports = Rent::default().minimum_balance(VoteStateV4::size_of());
     let vote_keypair = Keypair::new();
     let vote_keypair = Keypair::new();
     let user_keypair = Keypair::new();
     let user_keypair = Keypair::new();
     instructions.append(&mut vote_instruction::create_account_with_config(
     instructions.append(&mut vote_instruction::create_account_with_config(
@@ -67,7 +67,7 @@ pub async fn setup_vote(context: &mut ProgramTestContext) -> Pubkey {
         },
         },
         vote_lamports,
         vote_lamports,
         vote_instruction::CreateVoteAccountConfig {
         vote_instruction::CreateVoteAccountConfig {
-            space: vote_state::VoteStateV3::size_of() as u64,
+            space: vote_state::VoteStateV4::size_of() as u64,
             ..vote_instruction::CreateVoteAccountConfig::default()
             ..vote_instruction::CreateVoteAccountConfig::default()
         },
         },
     ));
     ));

+ 6 - 8
rpc/src/rpc.rs

@@ -4588,7 +4588,7 @@ pub mod tests {
             EncodedConfirmedBlock, EncodedTransaction, EncodedTransactionWithStatusMeta,
             EncodedConfirmedBlock, EncodedTransaction, EncodedTransactionWithStatusMeta,
             TransactionDetails,
             TransactionDetails,
         },
         },
-        solana_vote_interface::state::VoteStateV3,
+        solana_vote_interface::state::VoteStateV4,
         solana_vote_program::{
         solana_vote_program::{
             vote_instruction,
             vote_instruction,
             vote_state::{TowerSync, VoteInit, VoteStateVersions, MAX_LOCKOUT_HISTORY},
             vote_state::{TowerSync, VoteInit, VoteStateVersions, MAX_LOCKOUT_HISTORY},
@@ -5041,10 +5041,10 @@ pub mod tests {
             bank
             bank
         }
         }
 
 
-        fn store_vote_account(&self, vote_pubkey: &Pubkey, vote_state: VoteStateV3) {
+        fn store_vote_account(&self, vote_pubkey: &Pubkey, vote_state: VoteStateV4) {
             let bank = self.working_bank();
             let bank = self.working_bank();
-            let versioned = VoteStateVersions::new_v3(vote_state);
-            let space = VoteStateV3::size_of();
+            let versioned = VoteStateVersions::new_v4(vote_state);
+            let space = VoteStateV4::size_of();
             let balance = bank.get_minimum_balance_for_rent_exemption(space);
             let balance = bank.get_minimum_balance_for_rent_exemption(space);
             let mut vote_account =
             let mut vote_account =
                 AccountSharedData::new(balance, space, &solana_vote_program::id());
                 AccountSharedData::new(balance, space, &solana_vote_program::id());
@@ -7698,11 +7698,9 @@ pub mod tests {
         assert_eq!(bank.vote_accounts().len(), 1);
         assert_eq!(bank.vote_accounts().len(), 1);
 
 
         // Create a vote account with no stake.
         // Create a vote account with no stake.
-        // TODO: Update this test to use `VoteStateV4` after vote program
-        // migration is complete. Currently using `VoteStateV3` because this
-        // test invokes the vote program which hasn't been migrated to v4 yet.
         let alice_vote_keypair = Keypair::new();
         let alice_vote_keypair = Keypair::new();
-        let alice_vote_state = VoteStateV3::new(
+        let alice_vote_state = VoteStateV4::new(
+            &alice_vote_keypair.pubkey(),
             &VoteInit {
             &VoteInit {
                 node_pubkey: mint_keypair.pubkey(),
                 node_pubkey: mint_keypair.pubkey(),
                 authorized_voter: alice_vote_keypair.pubkey(),
                 authorized_voter: alice_vote_keypair.pubkey(),

+ 13 - 7
vote/benches/vote_account.rs

@@ -4,13 +4,14 @@ use {
     solana_account::AccountSharedData,
     solana_account::AccountSharedData,
     solana_pubkey::Pubkey,
     solana_pubkey::Pubkey,
     solana_vote::vote_account::VoteAccount,
     solana_vote::vote_account::VoteAccount,
-    solana_vote_interface::state::{VoteInit, VoteStateV3, VoteStateVersions},
+    solana_vote_interface::state::{VoteInit, VoteStateV4, VoteStateVersions},
 };
 };
 
 
 fn new_rand_vote_account<R: Rng>(
 fn new_rand_vote_account<R: Rng>(
     rng: &mut R,
     rng: &mut R,
     node_pubkey: Option<Pubkey>,
     node_pubkey: Option<Pubkey>,
-) -> (AccountSharedData, VoteStateV3) {
+) -> (AccountSharedData, VoteStateV4) {
+    let vote_pubkey = Pubkey::new_unique();
     let vote_init = VoteInit {
     let vote_init = VoteInit {
         node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
         node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
         authorized_voter: Pubkey::new_unique(),
         authorized_voter: Pubkey::new_unique(),
@@ -24,11 +25,10 @@ fn new_rand_vote_account<R: Rng>(
         leader_schedule_epoch: rng.gen(),
         leader_schedule_epoch: rng.gen(),
         unix_timestamp: rng.gen(),
         unix_timestamp: rng.gen(),
     };
     };
-    let mut vote_state = VoteStateV3::new(&vote_init, &clock);
-    vote_state.process_next_vote_slot(0, 0, 1);
+    let vote_state = VoteStateV4::new(&vote_pubkey, &vote_init, &clock);
     let account = AccountSharedData::new_data(
     let account = AccountSharedData::new_data(
         rng.gen(), // lamports
         rng.gen(), // lamports
-        &VoteStateVersions::new_v3(vote_state.clone()),
+        &VoteStateVersions::new_v4(vote_state.clone()),
         &solana_sdk_ids::vote::id(), // owner
         &solana_sdk_ids::vote::id(), // owner
     )
     )
     .unwrap();
     .unwrap();
@@ -43,8 +43,14 @@ fn bench_vote_account_try_from(b: &mut Bencher) {
         let vote_account = VoteAccount::try_from(account.clone()).unwrap();
         let vote_account = VoteAccount::try_from(account.clone()).unwrap();
         let vote_state_view = vote_account.vote_state_view();
         let vote_state_view = vote_account.vote_state_view();
         assert_eq!(&vote_state.node_pubkey, vote_state_view.node_pubkey());
         assert_eq!(&vote_state.node_pubkey, vote_state_view.node_pubkey());
-        assert_eq!(vote_state.commission, vote_state_view.commission());
-        assert_eq!(vote_state.credits(), vote_state_view.credits());
+        assert_eq!(
+            vote_state.inflation_rewards_commission_bps,
+            vote_state_view.inflation_rewards_commission()
+        );
+        assert_eq!(
+            vote_state.epoch_credits.len(),
+            vote_state_view.num_epoch_credits()
+        );
         assert_eq!(vote_state.last_timestamp, vote_state_view.last_timestamp());
         assert_eq!(vote_state.last_timestamp, vote_state_view.last_timestamp());
         assert_eq!(vote_state.root_slot, vote_state_view.root_slot());
         assert_eq!(vote_state.root_slot, vote_state_view.root_slot());
     });
     });

+ 8 - 6
vote/src/vote_account.rs

@@ -97,10 +97,11 @@ impl VoteAccount {
         use {
         use {
             rand::Rng as _,
             rand::Rng as _,
             solana_clock::Clock,
             solana_clock::Clock,
-            solana_vote_interface::state::{VoteInit, VoteStateV3, VoteStateVersions},
+            solana_vote_interface::state::{VoteInit, VoteStateV4, VoteStateVersions},
         };
         };
 
 
         let mut rng = rand::thread_rng();
         let mut rng = rand::thread_rng();
+        let vote_pubkey = Pubkey::new_unique();
 
 
         let vote_init = VoteInit {
         let vote_init = VoteInit {
             node_pubkey: Pubkey::new_unique(),
             node_pubkey: Pubkey::new_unique(),
@@ -115,10 +116,10 @@ impl VoteAccount {
             leader_schedule_epoch: rng.gen(),
             leader_schedule_epoch: rng.gen(),
             unix_timestamp: rng.gen(),
             unix_timestamp: rng.gen(),
         };
         };
-        let vote_state = VoteStateV3::new(&vote_init, &clock);
+        let vote_state = VoteStateV4::new(&vote_pubkey, &vote_init, &clock);
         let account = AccountSharedData::new_data(
         let account = AccountSharedData::new_data(
             rng.gen(), // lamports
             rng.gen(), // lamports
-            &VoteStateVersions::new_v3(vote_state.clone()),
+            &VoteStateVersions::new_v4(vote_state.clone()),
             &solana_sdk_ids::vote::id(), // owner
             &solana_sdk_ids::vote::id(), // owner
         )
         )
         .unwrap();
         .unwrap();
@@ -454,7 +455,7 @@ mod tests {
         solana_account::WritableAccount,
         solana_account::WritableAccount,
         solana_clock::Clock,
         solana_clock::Clock,
         solana_pubkey::Pubkey,
         solana_pubkey::Pubkey,
-        solana_vote_interface::state::{VoteInit, VoteStateV3, VoteStateVersions},
+        solana_vote_interface::state::{VoteInit, VoteStateV4, VoteStateVersions},
         std::iter::repeat_with,
         std::iter::repeat_with,
     };
     };
 
 
@@ -462,6 +463,7 @@ mod tests {
         rng: &mut R,
         rng: &mut R,
         node_pubkey: Option<Pubkey>,
         node_pubkey: Option<Pubkey>,
     ) -> AccountSharedData {
     ) -> AccountSharedData {
+        let vote_pubkey = Pubkey::new_unique();
         let vote_init = VoteInit {
         let vote_init = VoteInit {
             node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
             node_pubkey: node_pubkey.unwrap_or_else(Pubkey::new_unique),
             authorized_voter: Pubkey::new_unique(),
             authorized_voter: Pubkey::new_unique(),
@@ -475,10 +477,10 @@ mod tests {
             leader_schedule_epoch: rng.gen(),
             leader_schedule_epoch: rng.gen(),
             unix_timestamp: rng.gen(),
             unix_timestamp: rng.gen(),
         };
         };
-        let vote_state = VoteStateV3::new(&vote_init, &clock);
+        let vote_state = VoteStateV4::new(&vote_pubkey, &vote_init, &clock);
         AccountSharedData::new_data(
         AccountSharedData::new_data(
             rng.gen(), // lamports
             rng.gen(), // lamports
-            &VoteStateVersions::new_v3(vote_state.clone()),
+            &VoteStateVersions::new_v4(vote_state.clone()),
             &solana_sdk_ids::vote::id(), // owner
             &solana_sdk_ids::vote::id(), // owner
         )
         )
         .unwrap()
         .unwrap()