Skip to content

Commit

Permalink
fixes from x-chin_priority_fees
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Apr 3, 2024
1 parent 0b269d7 commit 4d1556d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions vms/components/fees/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (m *Manager) CalculateFee(complexity Dimensions, tipPercentage TipPercentag

tipAddend, err := safemath.Mul64(baseFee, uint64(tipPercentage))
if err != nil {
tipAddend, err = safemath.Mul64(baseFee/uint64(MaxTipPercentage), uint64(tipPercentage))
tipAddend, err = safemath.Mul64(baseFee/uint64(TipDenonimator), uint64(tipPercentage))
if err != nil {
return 0, err
}
Expand All @@ -62,7 +62,7 @@ func (m *Manager) CalculateFee(complexity Dimensions, tipPercentage TipPercentag
return 0, err
}
} else {
tip, err = safemath.Add64(tip, tipAddend/MaxTipPercentage)
tip, err = safemath.Add64(tip, tipAddend/TipDenonimator)
if err != nil {
return 0, err
}
Expand Down
14 changes: 3 additions & 11 deletions vms/components/fees/tip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@ import (
// Tip is expressed as a percentage of the base fee and it is burned as the required fee.

const (
NoTip = 0
MaxTipPercentage = 1_000
NoTip = TipPercentage(0)
TipDenonimator = 1_000
)

var (
errTipPercentageNegative = errors.New("tip percentage negative")
errTipPercentageTooLarge = errors.New("tip percentage too large")
)
var errTipPercentageNegative = errors.New("tip percentage negative")

type TipPercentage int

func (t TipPercentage) Validate() error {
if t < 0 {
return fmt.Errorf("%w, tip percentage %d", errTipPercentageNegative, t)
}

if t > MaxTipPercentage {
return fmt.Errorf("%w, tip percentage %d", errTipPercentageTooLarge, t)
}

return nil
}
2 changes: 1 addition & 1 deletion vms/platformvm/txs/fees/calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,6 @@ func (fc *Calculator) CalculateTipPercentage(feesPaid uint64) error {
}

tip := feesPaid - fc.Fee
fc.TipPercentage = fees.TipPercentage(tip * fees.MaxTipPercentage / fc.Fee)
fc.TipPercentage = fees.TipPercentage(tip * fees.TipDenonimator / fc.Fee)
return fc.TipPercentage.Validate()
}

0 comments on commit 4d1556d

Please sign in to comment.