Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message of dynamic fee calculations #3297

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions vms/platformvm/txs/fee/dynamic_calculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@
package fee

import (
"errors"
"fmt"

"github.com/ava-labs/avalanchego/vms/components/fee"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)

var _ Calculator = (*dynamicCalculator)(nil)
var (
_ Calculator = (*dynamicCalculator)(nil)

ErrCalculatingComplexity = errors.New("error calculating complexity")
ErrCalculatingGas = errors.New("error calculating gas")
ErrCalculatingCost = errors.New("error calculating cost")
)

func NewDynamicCalculator(
weights fee.Dimensions,
Expand All @@ -28,11 +37,27 @@ type dynamicCalculator struct {
func (c *dynamicCalculator) CalculateFee(tx txs.UnsignedTx) (uint64, error) {
complexity, err := TxComplexity(tx)
if err != nil {
return 0, err
return 0, fmt.Errorf("%w: %w", ErrCalculatingComplexity, err)
}
gas, err := complexity.ToGas(c.weights)
if err != nil {
return 0, err
return 0, fmt.Errorf(
"%w with complexity (%v) and weights (%v): %w",
ErrCalculatingGas,
complexity,
c.weights,
err,
)
}
fee, err := gas.Cost(c.price)
if err != nil {
return 0, fmt.Errorf(
"%w with gas (%d) and price (%d): %w",
ErrCalculatingCost,
gas,
c.price,
err,
)
}
return gas.Cost(c.price)
return fee, nil
}
Loading