@@ -120,15 +120,14 @@ pub fn resize_price_account(
120120 check_id ( system_program. key ) ,
121121 OracleError :: InvalidSystemAccount . into ( ) ,
122122 ) ?;
123- //throw an error if not a price account
124- //need to makre sure it goes out of scope immediatly to avoid mutable borrow errors
123+ // Check that it is a valid initialized price account
125124 {
126125 load_checked :: < PriceAccount > ( price_account_info, PC_VERSION ) ?;
127126 }
128127 let account_len = price_account_info. try_data_len ( ) ?;
129128 match account_len {
130129 PRICE_T_SIZE => {
131- //ensure account is still rent exempt after resizing
130+ // Ensure account is still rent exempt after resizing
132131 let rent: Rent = Default :: default ( ) ;
133132 let lamports_needed: u64 = rent
134133 . minimum_balance ( size_of :: < PriceAccountWrapper > ( ) )
@@ -141,15 +140,19 @@ pub fn resize_price_account(
141140 lamports_needed,
142141 ) ?;
143142 }
144- //resize
145- //we do not need to zero initialize since this is the first time this memory
146- //is allocated
143+ // We do not need to zero allocate because we won't access the data in the same
144+ // instruction
147145 price_account_info. realloc ( size_of :: < PriceAccountWrapper > ( ) , false ) ?;
148- //The load below would fail if the account was not a price account, reverting the whole
149- // transaction
146+
147+ // Check that everything is ok
148+ check_valid_signable_account (
149+ program_id,
150+ price_account_info,
151+ size_of :: < PriceAccountWrapper > ( ) ,
152+ ) ?;
150153 let mut price_account =
151154 load_checked :: < PriceAccountWrapper > ( price_account_info, PC_VERSION ) ?;
152- //Initialize Time Machine
155+ // Initialize Time Machine
153156 price_account. initialize_time_machine ( ) ?;
154157 Ok ( ( ) )
155158 }
0 commit comments