@@ -406,8 +406,13 @@ fn write_commit<P: AsRef<Path>>(
406
406
let mut index = base
407
407
. as_ref ( )
408
408
. map_or ( ContractIndex :: default ( ) , |base| base. index . clone ( ) ) ;
409
- for c in & commit_contracts {
410
- index. insert ( * c. 0 , & c. 1 . memory ) ;
409
+
410
+ for ( contract_id, contract_data) in & commit_contracts {
411
+ if contract_data. is_new {
412
+ index. remove_and_insert ( * contract_id, & contract_data. memory ) ;
413
+ } else {
414
+ index. insert ( * contract_id, & contract_data. memory ) ;
415
+ }
411
416
}
412
417
413
418
let root = * index. root ( ) ;
@@ -497,6 +502,7 @@ fn write_commit_inner<P: AsRef<Path>>(
497
502
498
503
let mut pages = BTreeSet :: new ( ) ;
499
504
505
+ // Write dirty pages and keep track of the page indices.
500
506
for ( dirty_page, _, page_index) in contract_data. memory . dirty_pages ( ) {
501
507
let page_path = page_path ( & memory_dir, * page_index) ;
502
508
fs:: write ( page_path, dirty_page) ?;
@@ -507,13 +513,16 @@ fn write_commit_inner<P: AsRef<Path>>(
507
513
let module_path = bytecode_path. with_extension ( OBJECTCODE_EXTENSION ) ;
508
514
let metadata_path = bytecode_path. with_extension ( METADATA_EXTENSION ) ;
509
515
510
- // If the contract already existed in the base commit, we hard link the
511
- // bytecode, module, and metadata files to avoid duplicating them,
512
- // otherwise we write them to disk.
516
+ // If the contract is new, we write the bytecode, module, and metadata
517
+ // files to disk, otherwise we hard link them to avoid duplicating them.
513
518
//
514
519
// Also, if there is a base commit, we hard link the pages of the
515
520
// contracts that are not dirty.
516
- if let Some ( base) = & directories. base {
521
+ if contract_data. is_new {
522
+ fs:: write ( bytecode_path, & contract_data. bytecode ) ?;
523
+ fs:: write ( module_path, & contract_data. module . serialize ( ) ) ?;
524
+ fs:: write ( metadata_path, & contract_data. metadata ) ?;
525
+ } else if let Some ( base) = & directories. base {
517
526
if let Some ( elem) = base. inner . index . get ( contract) {
518
527
let base_bytecode_path = base. bytecode_dir . join ( & contract_hex) ;
519
528
let base_module_path =
@@ -539,10 +548,6 @@ fn write_commit_inner<P: AsRef<Path>>(
539
548
}
540
549
}
541
550
}
542
- } else {
543
- fs:: write ( bytecode_path, & contract_data. bytecode ) ?;
544
- fs:: write ( module_path, & contract_data. module . serialize ( ) ) ?;
545
- fs:: write ( metadata_path, & contract_data. metadata ) ?;
546
551
}
547
552
}
548
553
0 commit comments