-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(miner)!: remove DEAL_WEIGHT_MULTIPLIER and its input to QAP calc
- Loading branch information
Showing
3 changed files
with
111 additions
and
21 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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package miner_test | ||
|
||
import ( | ||
"testing" | ||
|
||
abi "github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/big" | ||
"github.com/filecoin-project/go-state-types/builtin" | ||
"github.com/filecoin-project/go-state-types/builtin/v15/miner" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
/* Rust version: | ||
#[test] | ||
fn quality_is_independent_of_size_and_duration() { | ||
// Quality of space with no deals. This doesn't depend on either the sector size or duration. | ||
let empty_quality = BigInt::from(1 << SECTOR_QUALITY_PRECISION); | ||
// Quality space filled with verified deals. | ||
let verified_quality = &empty_quality | ||
* (VERIFIED_DEAL_WEIGHT_MULTIPLIER.clone() / QUALITY_BASE_MULTIPLIER.clone()); | ||
// Quality space half filled with verified deals. | ||
let half_verified_quality = | ||
&empty_quality / BigInt::from(2) + &verified_quality / BigInt::from(2); | ||
let size_range: Vec<SectorSize> = vec![ | ||
SectorSize::_2KiB, | ||
SectorSize::_8MiB, | ||
SectorSize::_512MiB, | ||
SectorSize::_32GiB, | ||
SectorSize::_64GiB, | ||
]; | ||
let duration_range: Vec<ChainEpoch> = vec![ | ||
ChainEpoch::from(1), | ||
ChainEpoch::from(10), | ||
ChainEpoch::from(1000), | ||
1000 * EPOCHS_IN_DAY, | ||
]; | ||
for size in size_range { | ||
for duration in &duration_range { | ||
let sector_weight = weight(size, *duration); | ||
assert_eq!(empty_quality, quality_for_weight(size, *duration, &BigInt::zero())); | ||
assert_eq!(verified_quality, quality_for_weight(size, *duration, §or_weight)); | ||
assert_eq!( | ||
half_verified_quality, | ||
quality_for_weight( | ||
size, | ||
*duration, | ||
§or_weight.checked_div(&BigInt::from(2)).unwrap() | ||
) | ||
); | ||
} | ||
} | ||
} | ||
*/ | ||
|
||
func TestQualityForWeight(t *testing.T) { | ||
emptyQuality := big.NewInt(1 << builtin.SectorQualityPrecision) | ||
verifiedQuality := big.Mul(emptyQuality, big.Div(builtin.VerifiedDealWeightMultiplier, builtin.QualityBaseMultiplier)) | ||
halfVerifiedQuality := big.Add(big.Div(emptyQuality, big.NewInt(2)), big.Div(verifiedQuality, big.NewInt(2))) | ||
|
||
sizeRange := []abi.SectorSize{ | ||
abi.SectorSize(2 << 10), | ||
abi.SectorSize(8 << 20), | ||
abi.SectorSize(512 << 20), | ||
abi.SectorSize(32 << 30), | ||
abi.SectorSize(64 << 30), | ||
} | ||
durationRange := []abi.ChainEpoch{ | ||
abi.ChainEpoch(1), | ||
abi.ChainEpoch(10), | ||
abi.ChainEpoch(1000), | ||
1000 * builtin.EpochsInDay, | ||
} | ||
|
||
for _, size := range sizeRange { | ||
for _, duration := range durationRange { | ||
sectorWeight := big.NewInt(int64(size) * int64(duration)) | ||
require.Equal(t, emptyQuality, miner.QualityForWeight(size, duration, big.Zero())) | ||
require.Equal(t, verifiedQuality, miner.QualityForWeight(size, duration, sectorWeight)) | ||
require.Equal(t, halfVerifiedQuality, miner.QualityForWeight(size, duration, big.Div(sectorWeight, big.NewInt(2)))) | ||
} | ||
} | ||
} | ||
|
||
/* | ||
fn weight(size: SectorSize, duration: ChainEpoch) -> BigInt { | ||
BigInt::from(size as u64) * BigInt::from(duration) | ||
} | ||
fn weight_with_size_as_bigint(size: BigInt, duration: ChainEpoch) -> BigInt { | ||
size * BigInt::from(duration) | ||
} | ||
*/ |