Skip to content

Commit 7ca97ed

Browse files
authored
Round the contract code rent discount up. (#1631)
### What Round the contract code rent discount up. That's a protocol bug that will be included in p26. ### Why Rounding down was inconsistent with the rest computations and resulted in missing 1 stroop from rent computations from time to time. ### Known limitations N/A
1 parent e198925 commit 7ca97ed

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

soroban-env-host/src/fees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn rent_fee_per_entry_change(
389389
));
390390
}
391391
if entry_change.is_code_entry {
392-
fee /= CODE_ENTRY_RENT_DISCOUNT_FACTOR;
392+
fee = num_integer::div_ceil(fee, CODE_ENTRY_RENT_DISCOUNT_FACTOR);
393393
}
394394
fee
395395
}

soroban-env-host/tests/fees.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -547,9 +547,9 @@ fn test_rent_extend_fees_with_only_extend() {
547547
&fee_config,
548548
50_000,
549549
),
550-
// Rent: ceil(10 * 1024 * 1000 * 200_000 / (10_000 * 1024)) / 3 (=66_666)
550+
// Rent: ceil(10 * 1024 * 1000 * 200_000 / (10_000 * 1024)) / 3 (=66_667)
551551
// Expiration entry write entry/bytes: 34
552-
66_666 + 34
552+
66_667 + 34
553553
);
554554

555555
// Size decrease
@@ -654,10 +654,10 @@ fn test_rent_extend_fees_with_only_extend() {
654654
&fee_config,
655655
50_000,
656656
),
657-
// Rent: 20_000 + 200_000 + 66_666 + 1 + 20 + 200_000 + 20_000 (=506_687) +
657+
// Rent: 20_000 + 200_000 + 66_667 + 1 + 20 + 200_000 + 20_000 (=506_688) +
658658
// Expiration entry write bytes: ceil(7 * 500 * 48 / 1024) (=165) +
659659
// Expiration entry write: 10 * 7
660-
506_687 + 165 + 70
660+
506_688 + 165 + 70
661661
);
662662
}
663663

@@ -704,7 +704,7 @@ fn test_rent_extend_fees_with_only_size_change() {
704704
25_000,
705705
),
706706
// 99_999 * 1000 * (100_000 - 25_000 + 1) / (10_000 * 1024) / 3
707-
732_425 / 3
707+
num_integer::div_ceil(732_425, 3)
708708
);
709709

710710
// Large size increase, temp storage
@@ -794,7 +794,7 @@ fn test_rent_extend_fees_with_only_size_change() {
794794
25_000,
795795
),
796796
// 732_425 + 732_425 / 3 + 73_243
797-
1_049_809
797+
1_049_810
798798
);
799799
}
800800

@@ -845,7 +845,7 @@ fn test_rent_extend_with_size_change_and_extend() {
845845
// Rent: 100_000 * 1000 * 200_000 / (10_000 * 1024) / 2 +
846846
// 99_999 * 1000 * (100_000 - 25_000 + 1) / (10_000 * 1024)
847847
// Expiration entry write entry/bytes: 34
848-
2_685_550 / 3 + 34
848+
num_integer::div_ceil(2_685_550, 3) + 34
849849
);
850850

851851
// Temp entry
@@ -903,7 +903,7 @@ fn test_rent_extend_with_size_change_and_extend() {
903903
// Rent: 2_685_550 + 2_685_550 / 3 + 268_556
904904
// Expiration entry write bytes: ceil(3 * 500 * 48 / 1024) (=71) +
905905
// Expiration entry write: 10 * 3
906-
3_849_289 + 71 + 30
906+
3_849_290 + 71 + 30
907907
);
908908

909909
// Small increments

soroban-simulation/src/test/simulation.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn test_simulate_upload_wasm() {
146146
disk_read_bytes: 0,
147147
write_bytes: expected_write_bytes,
148148
},
149-
resource_fee: 4714773,
149+
resource_fee: 4714774,
150150
})
151151
);
152152
assert_eq!(res.simulated_instructions, expected_instructions);
@@ -200,7 +200,7 @@ fn test_simulate_upload_wasm() {
200200
disk_read_bytes: 0,
201201
write_bytes: expected_write_bytes + 300,
202202
},
203-
resource_fee: 7071426,
203+
resource_fee: 7071427,
204204
})
205205
);
206206
}
@@ -589,7 +589,7 @@ fn test_simulate_invoke_contract_with_autorestore() {
589589
disk_read_bytes: wasm_entry_size + contract_1_size,
590590
write_bytes: wasm_entry_size + contract_1_size,
591591
},
592-
resource_fee: 6231402,
592+
resource_fee: 6231403,
593593
})
594594
);
595595
assert_eq!(res.simulated_instructions, expected_instructions);
@@ -704,7 +704,7 @@ fn test_simulate_extend_ttl_op() {
704704
disk_read_bytes: 0,
705705
write_bytes: 0,
706706
},
707-
resource_fee: 6204121,
707+
resource_fee: 6204123,
708708
}
709709
}
710710
);
@@ -732,7 +732,7 @@ fn test_simulate_extend_ttl_op() {
732732
disk_read_bytes: 0,
733733
write_bytes: 0,
734734
},
735-
resource_fee: 104563088,
735+
resource_fee: 104563090,
736736
}
737737
}
738738
);
@@ -777,7 +777,7 @@ fn test_simulate_extend_ttl_op() {
777777
disk_read_bytes: 0,
778778
write_bytes: 0,
779779
},
780-
resource_fee: 156844607,
780+
resource_fee: 156844610,
781781
}
782782
}
783783
);
@@ -878,7 +878,7 @@ fn test_simulate_restore_op() {
878878
disk_read_bytes: expected_rw_bytes,
879879
write_bytes: expected_rw_bytes,
880880
},
881-
resource_fee: 10922801,
881+
resource_fee: 10922803,
882882
}
883883
}
884884
);
@@ -907,7 +907,7 @@ fn test_simulate_restore_op() {
907907
disk_read_bytes: expected_rw_bytes,
908908
write_bytes: expected_rw_bytes,
909909
},
910-
resource_fee: 11130765,
910+
resource_fee: 11130768,
911911
}
912912
}
913913
);
@@ -935,7 +935,7 @@ fn test_simulate_restore_op() {
935935
disk_read_bytes: (expected_rw_bytes as f64 * 1.2) as u32,
936936
write_bytes: (expected_rw_bytes as f64 * 1.3) as u32,
937937
},
938-
resource_fee: 16695904,
938+
resource_fee: 16695909,
939939
}
940940
}
941941
);

soroban-simulation/src/test/snapshot_source.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn test_automatic_restoration() {
169169
disk_read_bytes: 112,
170170
write_bytes: 112,
171171
},
172-
resource_fee: 23272,
172+
resource_fee: 23274,
173173
}
174174
})
175175
);

0 commit comments

Comments
 (0)