Skip to content

Commit

Permalink
export CalculateDynamicFee (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Jun 15, 2023
1 parent 0eb8685 commit 0d02ea7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugin/evm/export_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (utx *UnsignedExportTx) SemanticVerify(
if err != nil {
return err
}
txFee, err := calculateDynamicFee(gasUsed, baseFee)
txFee, err := CalculateDynamicFee(gasUsed, baseFee)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/export_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ func TestExportTxGasCost(t *testing.T) {
t.Fatalf("Expected gasUsed to be %d, but found %d", test.ExpectedGasUsed, gasUsed)
}

fee, err := calculateDynamicFee(gasUsed, test.BaseFee)
fee, err := CalculateDynamicFee(gasUsed, test.BaseFee)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/evm/import_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func (utx *UnsignedImportTx) SemanticVerify(
if err != nil {
return err
}
txFee, err := calculateDynamicFee(gasUsed, baseFee)
txFee, err := CalculateDynamicFee(gasUsed, baseFee)
if err != nil {
return err
}
Expand Down Expand Up @@ -375,11 +375,11 @@ func (vm *VM) newImportTxWithUTXOs(
}
gasUsedWithChange := gasUsedWithoutChange + EVMOutputGas

txFeeWithoutChange, err = calculateDynamicFee(gasUsedWithoutChange, baseFee)
txFeeWithoutChange, err = CalculateDynamicFee(gasUsedWithoutChange, baseFee)
if err != nil {
return nil, err
}
txFeeWithChange, err = calculateDynamicFee(gasUsedWithChange, baseFee)
txFeeWithChange, err = CalculateDynamicFee(gasUsedWithChange, baseFee)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/import_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestNewImportTx(t *testing.T) {
if err != nil {
t.Fatal(err)
}
actualFee, err = calculateDynamicFee(actualCost, initialBaseFee)
actualFee, err = CalculateDynamicFee(actualCost, initialBaseFee)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -853,7 +853,7 @@ func TestImportTxGasCost(t *testing.T) {
t.Fatalf("Expected gasUsed to be %d, but found %d", test.ExpectedGasUsed, gasUsed)
}

fee, err := calculateDynamicFee(gasUsed, test.BaseFee)
fee, err := CalculateDynamicFee(gasUsed, test.BaseFee)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (tx *Tx) BlockFeeContribution(fixedFee bool, avaxAssetID ids.ID, baseFee *b
if err != nil {
return nil, nil, err
}
txFee, err := calculateDynamicFee(gasUsed, baseFee)
txFee, err := CalculateDynamicFee(gasUsed, baseFee)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func IsSortedAndUniqueEVMOutputs(outputs []EVMOutput) bool {

// calculates the amount of AVAX that must be burned by an atomic transaction
// that consumes [cost] at [baseFee].
func calculateDynamicFee(cost uint64, baseFee *big.Int) (uint64, error) {
func CalculateDynamicFee(cost uint64, baseFee *big.Int) (uint64, error) {
if baseFee == nil {
return 0, errNilBaseFee
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestCalculateDynamicFee(t *testing.T) {
}

for _, test := range tests {
cost, err := calculateDynamicFee(test.gas, test.baseFee)
cost, err := CalculateDynamicFee(test.gas, test.baseFee)
if test.expectedErr == nil {
if err != nil {
t.Fatalf("Unexpectedly failed to calculate dynamic fee: %s", err)
Expand Down
6 changes: 3 additions & 3 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ func (vm *VM) GetSpendableAVAXWithFee(
return nil, nil, err
}

initialFee, err := calculateDynamicFee(cost, baseFee)
initialFee, err := CalculateDynamicFee(cost, baseFee)
if err != nil {
return nil, nil, err
}
Expand All @@ -1562,13 +1562,13 @@ func (vm *VM) GetSpendableAVAXWithFee(
break
}

prevFee, err := calculateDynamicFee(cost, baseFee)
prevFee, err := CalculateDynamicFee(cost, baseFee)
if err != nil {
return nil, nil, err
}

newCost := cost + EVMInputGas
newFee, err := calculateDynamicFee(newCost, baseFee)
newFee, err := CalculateDynamicFee(newCost, baseFee)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 0d02ea7

Please sign in to comment.