@@ -2213,11 +2213,12 @@ fn do_process_program_write_and_deploy(
2213
2213
let blockhash = rpc_client. get_latest_blockhash ( ) ?;
2214
2214
2215
2215
// Initialize buffer account or complete if already partially initialized
2216
- let ( initial_instructions, balance_needed) = if let Some ( account) = rpc_client
2217
- . get_account_with_commitment ( buffer_pubkey, config. commitment ) ?
2218
- . value
2216
+ let ( initial_instructions, balance_needed, buffer_program_data) = if let Some ( mut account) =
2217
+ rpc_client
2218
+ . get_account_with_commitment ( buffer_pubkey, config. commitment ) ?
2219
+ . value
2219
2220
{
2220
- complete_partial_program_init (
2221
+ let ( ixs , balance_needed ) = complete_partial_program_init (
2221
2222
loader_id,
2222
2223
& fee_payer_signer. pubkey ( ) ,
2223
2224
buffer_pubkey,
@@ -2229,7 +2230,11 @@ fn do_process_program_write_and_deploy(
2229
2230
} ,
2230
2231
min_rent_exempt_program_data_balance,
2231
2232
allow_excessive_balance,
2232
- ) ?
2233
+ ) ?;
2234
+ let buffer_program_data = account
2235
+ . data
2236
+ . split_off ( UpgradeableLoaderState :: size_of_buffer_metadata ( ) ) ;
2237
+ ( ixs, balance_needed, buffer_program_data)
2233
2238
} else if loader_id == & bpf_loader_upgradeable:: id ( ) {
2234
2239
(
2235
2240
bpf_loader_upgradeable:: create_buffer (
@@ -2240,6 +2245,7 @@ fn do_process_program_write_and_deploy(
2240
2245
program_len,
2241
2246
) ?,
2242
2247
min_rent_exempt_program_data_balance,
2248
+ vec ! [ 0 ; program_len] ,
2243
2249
)
2244
2250
} else {
2245
2251
(
@@ -2251,6 +2257,7 @@ fn do_process_program_write_and_deploy(
2251
2257
loader_id,
2252
2258
) ] ,
2253
2259
min_rent_exempt_program_data_balance,
2260
+ vec ! [ 0 ; program_len] ,
2254
2261
)
2255
2262
} ;
2256
2263
let initial_message = if !initial_instructions. is_empty ( ) {
@@ -2281,7 +2288,10 @@ fn do_process_program_write_and_deploy(
2281
2288
let mut write_messages = vec ! [ ] ;
2282
2289
let chunk_size = calculate_max_chunk_size ( & create_msg) ;
2283
2290
for ( chunk, i) in program_data. chunks ( chunk_size) . zip ( 0 ..) {
2284
- write_messages. push ( create_msg ( ( i * chunk_size) as u32 , chunk. to_vec ( ) ) ) ;
2291
+ let offset = i * chunk_size;
2292
+ if chunk != & buffer_program_data[ offset..offset + chunk. len ( ) ] {
2293
+ write_messages. push ( create_msg ( offset as u32 , chunk. to_vec ( ) ) ) ;
2294
+ }
2285
2295
}
2286
2296
2287
2297
// Create and add final message
@@ -2370,31 +2380,37 @@ fn do_process_program_upgrade(
2370
2380
let ( initial_message, write_messages, balance_needed) =
2371
2381
if let Some ( buffer_signer) = buffer_signer {
2372
2382
// Check Buffer account to see if partial initialization has occurred
2373
- let ( initial_instructions, balance_needed) = if let Some ( account) = rpc_client
2374
- . get_account_with_commitment ( & buffer_signer. pubkey ( ) , config. commitment ) ?
2375
- . value
2376
- {
2377
- complete_partial_program_init (
2378
- & bpf_loader_upgradeable:: id ( ) ,
2379
- & fee_payer_signer. pubkey ( ) ,
2380
- & buffer_signer. pubkey ( ) ,
2381
- & account,
2382
- UpgradeableLoaderState :: size_of_buffer ( program_len) ,
2383
- min_rent_exempt_program_data_balance,
2384
- true ,
2385
- ) ?
2386
- } else {
2387
- (
2388
- bpf_loader_upgradeable:: create_buffer (
2383
+ let ( initial_instructions, balance_needed, buffer_program_data) =
2384
+ if let Some ( mut account) = rpc_client
2385
+ . get_account_with_commitment ( & buffer_signer. pubkey ( ) , config. commitment ) ?
2386
+ . value
2387
+ {
2388
+ let ( ixs, balance_needed) = complete_partial_program_init (
2389
+ & bpf_loader_upgradeable:: id ( ) ,
2389
2390
& fee_payer_signer. pubkey ( ) ,
2390
- buffer_pubkey,
2391
- & upgrade_authority. pubkey ( ) ,
2391
+ & buffer_signer. pubkey ( ) ,
2392
+ & account,
2393
+ UpgradeableLoaderState :: size_of_buffer ( program_len) ,
2392
2394
min_rent_exempt_program_data_balance,
2393
- program_len,
2394
- ) ?,
2395
- min_rent_exempt_program_data_balance,
2396
- )
2397
- } ;
2395
+ true ,
2396
+ ) ?;
2397
+ let buffer_program_data = account
2398
+ . data
2399
+ . split_off ( UpgradeableLoaderState :: size_of_buffer_metadata ( ) ) ;
2400
+ ( ixs, balance_needed, buffer_program_data)
2401
+ } else {
2402
+ (
2403
+ bpf_loader_upgradeable:: create_buffer (
2404
+ & fee_payer_signer. pubkey ( ) ,
2405
+ buffer_pubkey,
2406
+ & upgrade_authority. pubkey ( ) ,
2407
+ min_rent_exempt_program_data_balance,
2408
+ program_len,
2409
+ ) ?,
2410
+ min_rent_exempt_program_data_balance,
2411
+ vec ! [ 0 ; program_len] ,
2412
+ )
2413
+ } ;
2398
2414
2399
2415
let initial_message = if !initial_instructions. is_empty ( ) {
2400
2416
Some ( Message :: new_with_blockhash (
@@ -2426,7 +2442,10 @@ fn do_process_program_upgrade(
2426
2442
let mut write_messages = vec ! [ ] ;
2427
2443
let chunk_size = calculate_max_chunk_size ( & create_msg) ;
2428
2444
for ( chunk, i) in program_data. chunks ( chunk_size) . zip ( 0 ..) {
2429
- write_messages. push ( create_msg ( ( i * chunk_size) as u32 , chunk. to_vec ( ) ) ) ;
2445
+ let offset = i * chunk_size;
2446
+ if chunk != & buffer_program_data[ offset..offset + chunk. len ( ) ] {
2447
+ write_messages. push ( create_msg ( offset as u32 , chunk. to_vec ( ) ) ) ;
2448
+ }
2430
2449
}
2431
2450
2432
2451
( initial_message, write_messages, balance_needed)
0 commit comments