@@ -284,53 +284,7 @@ where
284284 return Err ( Error :: InvalidProtocolVersion ( new_protocol_version) ) ;
285285 }
286286
287- let system_upgrader: SystemUpgrader < S > = SystemUpgrader :: new (
288- new_protocol_version,
289- current_protocol_version,
290- tracking_copy. clone ( ) ,
291- ) ;
292-
293- info ! ( "attempting prune of contract packages" ) ;
294-
295- // Generate the list of keys to prune
296- let keys_to_prune = system_upgrader
297- . get_contracts_prune_list ( correlation_id, upgrade_config. global_state_update ( ) )
298- . unwrap_or_else ( |upgrade_error| {
299- warn ! ( "error in generating prune list: {:?}" , upgrade_error) ;
300- vec ! [ ]
301- } ) ;
302-
303- info ! ( "keys to prune {:?}" , keys_to_prune) ;
304-
305- let prune_config = PruneConfig :: new ( pre_state_hash, keys_to_prune) ;
306- let post_prune_state_root_hash = match self . commit_prune ( correlation_id, prune_config) {
307- Ok ( PruneResult :: Success {
308- post_state_hash : new_state_root_hash,
309- ..
310- } ) => {
311- info ! (
312- "prune success with new state root hash {:?}" ,
313- new_state_root_hash
314- ) ;
315- new_state_root_hash
316- }
317- Ok ( _) | Err ( _) => {
318- warn ! ( "failed to prune, reusing previous state root hash" ) ;
319- pre_state_hash
320- }
321- } ;
322-
323- info ! (
324- "post-prune: pre-state-hash: {:?} post-state-hash: {:?}" ,
325- pre_state_hash, post_prune_state_root_hash,
326- ) ;
327-
328- let post_prune_tracking_copy = match self . tracking_copy ( post_prune_state_root_hash) ? {
329- Some ( tracking_copy) => Rc :: new ( RefCell :: new ( tracking_copy) ) ,
330- None => return Err ( Error :: RootNotFound ( post_prune_state_root_hash) ) ,
331- } ;
332-
333- let registry = if let Ok ( registry) = post_prune_tracking_copy
287+ let registry = if let Ok ( registry) = tracking_copy
334288 . borrow_mut ( )
335289 . get_system_contracts ( correlation_id)
336290 {
@@ -383,7 +337,7 @@ where
383337
384338 // We write the checksums of the chainspec settings to global state
385339 // allowing verification of the chainspec data reported via the RPC.
386- post_prune_tracking_copy . borrow_mut ( ) . write (
340+ tracking_copy . borrow_mut ( ) . write (
387341 Key :: ChainspecRegistry ,
388342 StoredValue :: CLValue ( cl_value_chainspec_registry) ,
389343 ) ;
@@ -393,7 +347,7 @@ where
393347 let system_upgrader: SystemUpgrader < S > = SystemUpgrader :: new (
394348 new_protocol_version,
395349 current_protocol_version,
396- post_prune_tracking_copy . clone ( ) ,
350+ tracking_copy . clone ( ) ,
397351 ) ;
398352
399353 system_upgrader
@@ -417,7 +371,7 @@ where
417371 // 3.1.1.1.1.7 new total validator slots is optional
418372 if let Some ( new_validator_slots) = upgrade_config. new_validator_slots ( ) {
419373 // 3.1.2.4 if new total validator slots is provided, update auction contract state
420- let auction_contract = post_prune_tracking_copy
374+ let auction_contract = tracking_copy
421375 . borrow_mut ( )
422376 . get_contract ( correlation_id, * auction_hash) ?;
423377
@@ -426,14 +380,12 @@ where
426380 CLValue :: from_t ( new_validator_slots)
427381 . map_err ( |_| Error :: Bytesrepr ( "new_validator_slots" . to_string ( ) ) ) ?,
428382 ) ;
429- post_prune_tracking_copy
430- . borrow_mut ( )
431- . write ( validator_slots_key, value) ;
383+ tracking_copy. borrow_mut ( ) . write ( validator_slots_key, value) ;
432384 }
433385
434386 if let Some ( new_auction_delay) = upgrade_config. new_auction_delay ( ) {
435387 debug ! ( %new_auction_delay, "Auction delay changed as part of the upgrade" ) ;
436- let auction_contract = post_prune_tracking_copy
388+ let auction_contract = tracking_copy
437389 . borrow_mut ( )
438390 . get_contract ( correlation_id, * auction_hash) ?;
439391
@@ -442,13 +394,11 @@ where
442394 CLValue :: from_t ( new_auction_delay)
443395 . map_err ( |_| Error :: Bytesrepr ( "new_auction_delay" . to_string ( ) ) ) ?,
444396 ) ;
445- post_prune_tracking_copy
446- . borrow_mut ( )
447- . write ( auction_delay_key, value) ;
397+ tracking_copy. borrow_mut ( ) . write ( auction_delay_key, value) ;
448398 }
449399
450400 if let Some ( new_locked_funds_period) = upgrade_config. new_locked_funds_period_millis ( ) {
451- let auction_contract = post_prune_tracking_copy
401+ let auction_contract = tracking_copy
452402 . borrow_mut ( )
453403 . get_contract ( correlation_id, * auction_hash) ?;
454404
@@ -457,7 +407,7 @@ where
457407 CLValue :: from_t ( new_locked_funds_period)
458408 . map_err ( |_| Error :: Bytesrepr ( "new_locked_funds_period" . to_string ( ) ) ) ?,
459409 ) ;
460- post_prune_tracking_copy
410+ tracking_copy
461411 . borrow_mut ( )
462412 . write ( locked_funds_period_key, value) ;
463413 }
@@ -468,7 +418,7 @@ where
468418 Ratio :: new ( numer. into ( ) , denom. into ( ) )
469419 } ;
470420
471- let mint_contract = post_prune_tracking_copy
421+ let mint_contract = tracking_copy
472422 . borrow_mut ( )
473423 . get_contract ( correlation_id, * mint_hash) ?;
474424
@@ -477,13 +427,15 @@ where
477427 CLValue :: from_t ( new_round_seigniorage_rate)
478428 . map_err ( |_| Error :: Bytesrepr ( "new_round_seigniorage_rate" . to_string ( ) ) ) ?,
479429 ) ;
480- post_prune_tracking_copy
430+ tracking_copy
481431 . borrow_mut ( )
482432 . write ( locked_funds_period_key, value) ;
483433 }
484434
435+ // We insert the new unbonding delay once the purses to be paid out have been transformed
436+ // based on the previous unbonding delay.
485437 if let Some ( new_unbonding_delay) = upgrade_config. new_unbonding_delay ( ) {
486- let auction_contract = post_prune_tracking_copy
438+ let auction_contract = tracking_copy
487439 . borrow_mut ( )
488440 . get_contract ( correlation_id, * auction_hash) ?;
489441
@@ -492,48 +444,72 @@ where
492444 CLValue :: from_t ( new_unbonding_delay)
493445 . map_err ( |_| Error :: Bytesrepr ( "new_unbonding_delay" . to_string ( ) ) ) ?,
494446 ) ;
495- post_prune_tracking_copy
496- . borrow_mut ( )
497- . write ( unbonding_delay_key, value) ;
447+ tracking_copy. borrow_mut ( ) . write ( unbonding_delay_key, value) ;
498448 }
499449
500- info ! ( "apply the accepted modifications to global state" ) ;
501450 // apply the accepted modifications to global state.
502451 for ( key, value) in upgrade_config. global_state_update ( ) {
503452 // Skip the key hashes associated with values as we mark these as records to be
504453 // pruned.
505454 let is_unit_value = value. is_unit_cl_value ( ) ;
506455 if key. into_hash ( ) . is_some ( ) && is_unit_value {
507- debug ! (
508- "found marker record for package prune; skipping normal operation of write {}" ,
456+ info ! (
457+ "found marker record for package overwrite {}" ,
509458 key. to_formatted_string( )
510459 ) ;
511- continue ;
460+ {
461+ let contract_package =
462+ match tracking_copy. borrow_mut ( ) . read ( correlation_id, key) {
463+ Ok ( Some ( StoredValue :: ContractPackage ( contract_package) ) ) => {
464+ contract_package
465+ }
466+ Ok ( _) | Err ( _) => {
467+ error ! (
468+ "error in retrieving contract package: {}" ,
469+ key. to_formatted_string( )
470+ ) ;
471+ continue ;
472+ }
473+ } ;
474+ for contract_hash in contract_package. versions ( ) . values ( ) {
475+ let contract_key = Key :: Hash ( contract_hash. value ( ) ) ;
476+ let mut contract = match tracking_copy
477+ . borrow_mut ( )
478+ . read ( correlation_id, & contract_key)
479+ {
480+ Ok ( Some ( StoredValue :: Contract ( contract) ) ) => contract,
481+ Ok ( _) | Err ( _) => {
482+ error ! (
483+ "error in retrieving contract : {}" ,
484+ contract_key. to_formatted_string( )
485+ ) ;
486+ continue ;
487+ }
488+ } ;
489+ contract. clear_named_keys ( ) ;
490+ tracking_copy
491+ . borrow_mut ( )
492+ . write ( contract_key, StoredValue :: Contract ( contract) ) ;
493+ }
494+ } ;
512495 } else {
513496 info ! ( "update for key: {}" , key. to_formatted_string( ) ) ;
514- post_prune_tracking_copy
515- . borrow_mut ( )
516- . write ( * key, value. clone ( ) ) ;
497+ tracking_copy. borrow_mut ( ) . write ( * key, value. clone ( ) ) ;
517498 }
518499 }
519- info ! ( "finished applying accepted modifications to global state" ) ;
520500
521- let execution_effect = post_prune_tracking_copy . borrow ( ) . effect ( ) ;
501+ let execution_effect = tracking_copy . borrow ( ) . effect ( ) ;
522502
523503 // commit
524504 let post_state_hash = self
525505 . state
526506 . commit (
527507 correlation_id,
528- post_prune_state_root_hash ,
508+ pre_state_hash ,
529509 execution_effect. transforms . to_owned ( ) ,
530510 )
531511 . map_err ( Into :: into) ?;
532512
533- info ! (
534- "upgrade success with post state hash: {:?}" ,
535- post_state_hash
536- ) ;
537513 // return result and effects
538514 Ok ( UpgradeSuccess {
539515 post_state_hash,
0 commit comments