-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(miner): no batch fee in PCD & lower batch balancer to 2
- Loading branch information
Showing
9 changed files
with
65 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,62 @@ | ||
use fil_actor_miner::aggregate_prove_commit_network_fee; | ||
use fil_actor_miner::detail::BATCH_BALANCER; | ||
use fil_actor_miner::{aggregate_pre_commit_network_fee, aggregate_prove_commit_network_fee}; | ||
use fvm_shared::econ::TokenAmount; | ||
use num_traits::zero; | ||
|
||
#[test] | ||
fn constant_fee_per_sector_when_base_fee_is_below_5_nfil() { | ||
for fee_func in [aggregate_prove_commit_network_fee, aggregate_pre_commit_network_fee] { | ||
let one_sector_fee = fee_func(1, &zero()); | ||
let ten_sector_fee = fee_func(10, &zero()); | ||
assert_eq!(&one_sector_fee * 10, ten_sector_fee); | ||
fn constant_fee_per_sector_when_base_fee_is_below_batch_balancer() { | ||
let one_sector_fee = aggregate_prove_commit_network_fee(1, &zero()); | ||
let ten_sector_fee = aggregate_prove_commit_network_fee(10, &zero()); | ||
assert_eq!(&one_sector_fee * 10, ten_sector_fee); | ||
|
||
let forty_sector_fee = fee_func(40, &TokenAmount::from_nano(1)); | ||
assert_eq!(&one_sector_fee * 40, forty_sector_fee); | ||
let forty_sector_fee = aggregate_prove_commit_network_fee(40, &TokenAmount::from_nano(1)); | ||
assert_eq!(&one_sector_fee * 40, forty_sector_fee); | ||
|
||
let two_hundred_sector_fee = fee_func(200, &TokenAmount::from_nano(3)); | ||
assert_eq!(one_sector_fee * 200, two_hundred_sector_fee); | ||
} | ||
let two_hundred_sector_fee = | ||
aggregate_prove_commit_network_fee(200, &TokenAmount::from_nano(2)); | ||
assert_eq!(one_sector_fee * 200, two_hundred_sector_fee); | ||
} | ||
|
||
#[test] | ||
fn fee_increases_if_basefee_crosses_threshold() { | ||
for fee_func in [aggregate_prove_commit_network_fee, aggregate_pre_commit_network_fee] { | ||
let at_no_base_fee = fee_func(10, &zero()); | ||
let at_balance_minus_one_base_fee = | ||
fee_func(10, &(&*BATCH_BALANCER - TokenAmount::from_atto(1))); | ||
let at_balance_base_fee = fee_func(10, &BATCH_BALANCER); | ||
let at_balance_plus_one_base_fee = | ||
fee_func(10, &(&*BATCH_BALANCER + TokenAmount::from_nano(1))); | ||
let at_balance_plus_two_base_fee = | ||
fee_func(10, &(&*BATCH_BALANCER + TokenAmount::from_nano(2))); | ||
let at_balance_times_two_base = fee_func(10, &(2 * &*BATCH_BALANCER)); | ||
|
||
assert_eq!(at_no_base_fee, at_balance_minus_one_base_fee); | ||
assert_eq!(at_no_base_fee, at_balance_base_fee); | ||
assert!(at_balance_base_fee < at_balance_plus_one_base_fee); | ||
assert!(at_balance_plus_one_base_fee < at_balance_plus_two_base_fee); | ||
assert_eq!(at_balance_times_two_base, 2 * at_balance_base_fee); | ||
} | ||
let at_no_base_fee = aggregate_prove_commit_network_fee(10, &zero()); | ||
let at_balance_minus_one_base_fee = | ||
aggregate_prove_commit_network_fee(10, &(&*BATCH_BALANCER - TokenAmount::from_atto(1))); | ||
let at_balance_base_fee = aggregate_prove_commit_network_fee(10, &BATCH_BALANCER); | ||
let at_balance_plus_one_base_fee = | ||
aggregate_prove_commit_network_fee(10, &(&*BATCH_BALANCER + TokenAmount::from_nano(1))); | ||
let at_balance_plus_two_base_fee = | ||
aggregate_prove_commit_network_fee(10, &(&*BATCH_BALANCER + TokenAmount::from_nano(2))); | ||
let at_balance_times_two_base = aggregate_prove_commit_network_fee(10, &(2 * &*BATCH_BALANCER)); | ||
|
||
assert_eq!(at_no_base_fee, at_balance_minus_one_base_fee); | ||
assert_eq!(at_no_base_fee, at_balance_base_fee); | ||
assert!(at_balance_base_fee < at_balance_plus_one_base_fee); | ||
assert!(at_balance_plus_one_base_fee < at_balance_plus_two_base_fee); | ||
assert_eq!(at_balance_times_two_base, 2 * at_balance_base_fee); | ||
} | ||
|
||
#[test] | ||
fn regression_tests() { | ||
let magic_number = 65733297; | ||
let magic_number = 49299973; | ||
let fee = |aggregate_size, base_fee_multiplier| { | ||
aggregate_prove_commit_network_fee( | ||
aggregate_size, | ||
&TokenAmount::from_nano(base_fee_multiplier), | ||
) + aggregate_pre_commit_network_fee( | ||
aggregate_size, | ||
&TokenAmount::from_nano(base_fee_multiplier), | ||
) | ||
}; | ||
|
||
// (5/20) * x * 10 = (5/2) * x | ||
let expected = (TokenAmount::from_nano(5) * magic_number).div_floor(2); | ||
// Under batch balancer (2), so these two are the same: | ||
// 2/20 * x * 10 = (2/2) * x = x | ||
let expected = TokenAmount::from_nano(magic_number); | ||
assert_eq!(expected, fee(10, 0)); | ||
assert_eq!(expected, fee(10, 1)); | ||
|
||
let expected = TokenAmount::from_nano(25) * magic_number; | ||
// 3/20 * x * 100 = 15 * x | ||
let expected = TokenAmount::from_nano(15) * magic_number; | ||
assert_eq!(expected, fee(100, 3)); | ||
|
||
// 6/20 * x * 100 = 30 * x | ||
let expected = TokenAmount::from_nano(30) * magic_number; | ||
assert_eq!(expected, fee(100, 6)); | ||
} | ||
|
||
#[test] | ||
fn split_25_75() { | ||
// check 25/75% split up to uFIL precision | ||
let one_micro_fil = TokenAmount::from_nano(1000); | ||
|
||
for base_fee_multiplier in [0, 5, 20] { | ||
for aggregate_size in [13, 303] { | ||
let fee_pre = aggregate_pre_commit_network_fee( | ||
aggregate_size, | ||
&TokenAmount::from_nano(base_fee_multiplier), | ||
) | ||
.atto() | ||
/ one_micro_fil.atto(); | ||
let fee_prove = aggregate_prove_commit_network_fee( | ||
aggregate_size, | ||
&TokenAmount::from_nano(base_fee_multiplier), | ||
) | ||
.atto() | ||
/ one_micro_fil.atto(); | ||
assert_eq!(fee_prove, 3 * fee_pre); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.