Skip to content

Commit

Permalink
fix(niporep): properly test aggregate fee payment at boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jun 25, 2024
1 parent 03c6878 commit bd5a81d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
13 changes: 8 additions & 5 deletions actors/miner/tests/prove_commit_niporep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ fn ni_prove_partialy_valid_sectors_not_required_activation() {

rt.set_epoch(activation_epoch);

let sector_nums = (0..rt.policy.max_aggregated_sectors_ni).collect::<Vec<_>>();
let num_fails = sector_nums.len() / 2;
let sector_nums = (0..7).collect::<Vec<_>>();
let num_fails = 5;
let num_success = sector_nums.len() - num_fails;
let mut params = h.make_prove_commit_ni_params(
miner,
Expand All @@ -203,7 +203,10 @@ fn ni_prove_partialy_valid_sectors_not_required_activation() {
&rt,
params,
true,
fail_for_seal_rand_epoch(num_fails, activation_epoch),
fail_for_seal_rand_epoch(
num_fails,
activation_epoch - policy.max_prove_commit_ni_randomness_lookback - 1,
),
);
assert!(res.is_ok());

Expand Down Expand Up @@ -524,11 +527,11 @@ fn ni_prove_fail_duplicated_sector_numbers() {

fn fail_for_seal_rand_epoch(
num_fails: usize,
activation_epoch: i64,
bad_seal_rand_epoch: i64,
) -> impl FnMut(&mut SectorNIActivationInfo, usize) -> bool {
move |s: &mut SectorNIActivationInfo, index: usize| {
if index < num_fails {
s.seal_rand_epoch = activation_epoch;
s.seal_rand_epoch = bad_seal_rand_epoch;
true
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion actors/miner/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ impl ActorHarness {

self.expect_query_network_info(rt);

if params.sectors.len() > 5 {
if params.sectors.len() - fail_count > 5 {
let aggregate_fee = aggregate_prove_commit_network_fee(
params.sectors.len() - fail_count - 5,
&rt.base_fee.borrow(),
Expand Down
37 changes: 17 additions & 20 deletions integration_tests/src/tests/prove_commit_niporep_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn prove_commit_ni_whole_success_test(v: &dyn VM) {

assert_eq!(pcsni_ret.activation_results.size(), 5);
assert!(pcsni_ret.activation_results.all_ok());
assert_eq!(pcsni_ret.activation_results.codes(), vec![ExitCode::OK].repeat(5));
assert_eq!(pcsni_ret.activation_results.codes(), [ExitCode::OK].repeat(5));

let events: Vec<EmittedEvent> = sector_nos
.iter()
Expand Down Expand Up @@ -166,13 +166,7 @@ pub fn prove_commit_ni_partial_success_not_required_test(v: &dyn VM) {
let activation_epoch = seal_rand_epoch + policy.max_prove_commit_ni_randomness_lookback / 2;
let expiration = activation_epoch + policy.min_sector_expiration + 1;
let first_sector_number: SectorNumber = 100;
let sector_nos = [
first_sector_number,
first_sector_number + 1,
first_sector_number + 2,
first_sector_number + 3,
first_sector_number + 4,
];
let sector_nos: Vec<_> = (first_sector_number..first_sector_number + 20).collect();
let proving_deadline = 7;

let mut sectors_info: Vec<SectorNIActivationInfo> = sector_nos
Expand All @@ -187,13 +181,20 @@ pub fn prove_commit_ni_partial_success_not_required_test(v: &dyn VM) {
})
.collect();

// non-fatal error
// non-fatal errors
sectors_info[0].seal_rand_epoch =
v.epoch() - policy.max_prove_commit_ni_randomness_lookback - 1;
sectors_info[2].sealer_id = miner_id + 1;

let invalid_sector_nos = sector_nos.iter().take(1).copied().collect::<Vec<_>>();
let valid_sector_nos = sector_nos.iter().skip(1).copied().collect::<Vec<_>>();
let valid_sectors_info = sectors_info.iter().skip(1).cloned().collect::<Vec<_>>();
let invalid_sector_nos = vec![sector_nos[0], sector_nos[2]];
let valid_sector_nos: Vec<_> =
sector_nos.iter().enumerate().filter(|&(i, _)| i != 0 && i != 2).map(|(_, &v)| v).collect();
let valid_sectors_info: Vec<_> = sectors_info
.iter()
.enumerate()
.filter(|&(i, _)| i != 0 && i != 2)
.map(|(_, v)| v.clone())
.collect();

// Prove-commit NI-PoRep
let aggregate_proof = RawBytes::new(vec![1, 2, 3, 4]);
Expand All @@ -219,17 +220,13 @@ pub fn prove_commit_ni_partial_success_not_required_test(v: &dyn VM) {
.deserialize()
.unwrap();

assert_eq!(pcsni_ret.activation_results.size(), 5);
assert_eq!(pcsni_ret.activation_results.size(), sector_nos.len());
assert!(!pcsni_ret.activation_results.all_ok());
assert_eq!(
pcsni_ret.activation_results.codes(),
vec![
ExitCode::USR_ILLEGAL_ARGUMENT,
ExitCode::OK,
ExitCode::OK,
ExitCode::OK,
ExitCode::OK
]
(0..sector_nos.len())
.map(|i| if i == 0 || i == 2 { ExitCode::USR_ILLEGAL_ARGUMENT } else { ExitCode::OK })
.collect::<Vec<_>>()
);

let events: Vec<EmittedEvent> = valid_sector_nos
Expand Down

0 comments on commit bd5a81d

Please sign in to comment.