Skip to content

Commit

Permalink
Merge pull request #960 from SiaFoundation/pj/adjusted-gouging-settings
Browse files Browse the repository at this point in the history
Ensure applying the MigrationSurchargeMultiplier never prevents a download
  • Loading branch information
ChrisSchinnerl authored Feb 14, 2024
2 parents 742aa13 + fee0b6c commit 7ac03a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func (gs GougingSettings) Validate() error {
if gs.MinPriceTableValidity < 10*time.Second {
return errors.New("MinPriceTableValidity must be at least 10 seconds")
}
_, overflow := gs.MaxDownloadPrice.Mul64WithOverflow(gs.MigrationSurchargeMultiplier)
if overflow {
maxMultiplier := types.MaxCurrency.Div(gs.MaxDownloadPrice).Big().Uint64()
return fmt.Errorf("MigrationSurchargeMultiplier must be less than %v, otherwise applying it to MaxDownloadPrice overflows the currency type", maxMultiplier)
}
return nil
}

Expand Down
9 changes: 4 additions & 5 deletions worker/gouging.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,16 @@ func WithGougingChecker(ctx context.Context, cs consensusState, gp api.GougingPa

// adjust the max download price if we are dealing with a critical
// migration that might be failing due to gouging checks
settings := gp.GougingSettings
if criticalMigration && gp.GougingSettings.MigrationSurchargeMultiplier > 0 {
if adjustedMaxDownloadPrice, overflow := gp.GougingSettings.MaxDownloadPrice.Mul64WithOverflow(gp.GougingSettings.MigrationSurchargeMultiplier); overflow {
return gougingChecker{}, errors.New("failed to apply the 'MigrationSurchargeMultiplier', overflow detected")
} else {
gp.GougingSettings.MaxDownloadPrice = adjustedMaxDownloadPrice
if adjustedMaxDownloadPrice, overflow := gp.GougingSettings.MaxDownloadPrice.Mul64WithOverflow(gp.GougingSettings.MigrationSurchargeMultiplier); !overflow {
settings.MaxDownloadPrice = adjustedMaxDownloadPrice
}
}

return gougingChecker{
consensusState: consensusState,
settings: gp.GougingSettings,
settings: settings,
txFee: gp.TransactionFee,

// NOTE:
Expand Down

0 comments on commit 7ac03a4

Please sign in to comment.