-
Notifications
You must be signed in to change notification settings - Fork 83
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
Include tip in fee #682
Merged
Merged
Include tip in fee #682
Changes from 43 commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
8175147
WIP
MitchTurner d1975eb
Revert "WIP"
MitchTurner bf31410
Replace gas price policy with tip, add gas price to transact interface
MitchTurner 90f4729
Update CHANGELOG
MitchTurner f13e6bb
fmt
MitchTurner ba0b1eb
WIP update tests
MitchTurner 9cbcadf
WIP
MitchTurner d1d11c8
Fix run_script to have free gas
MitchTurner d431e61
Deal with test gas prices that must be zero
MitchTurner ed7827b
Fix one test
MitchTurner c49d037
Fix predicate test
MitchTurner 2d307d2
Fix output update test
MitchTurner d9091fe
Fix snapshot tests and some other gas price issues in tests
MitchTurner 4ecb8fa
Maybe fix test?
MitchTurner b80bd39
Fix create test
MitchTurner fe7bd46
Removed todo
xgreenx 3f5d950
Removed todo for tip GTF
xgreenx b963c6b
Fix
xgreenx 0f756c3
Fix warnings
MitchTurner 0c3c8ff
Make ci check changes
MitchTurner 39a3036
Revert default impl changes
MitchTurner c548402
Replace gas_price in prop tests
MitchTurner 32e187e
Replace some tip stuff for serialization and snapshots
MitchTurner f13085a
Merge branch 'master' into use-gas-price-in-fee-calc
MitchTurner 394d89a
Fix function call
MitchTurner 935ba82
Fix tests
MitchTurner cb6fb93
Add `gas_price` to `InterpreterParams`
MitchTurner 295152c
Remove commented code
MitchTurner e2a26e8
Fix prop test to generate `gas_price`
MitchTurner 9c1c3d2
Merge branch 'master' into use-gas-price-in-fee-calc
MitchTurner 9dddcfe
Merge branch 'master' into use-gas-price-in-fee-calc
xgreenx d7546e2
Remove `gas_price` from predicate execution functions
MitchTurner fd747ba
Fix tests
MitchTurner 81e91b8
Replace encoding stuff for tip
MitchTurner 17cd96e
Replace the other encoding stuff
MitchTurner 6ef9e8e
Add failing test :)
MitchTurner 7a83a53
Add code for passing test
MitchTurner b00109a
Split test
MitchTurner 357fa3e
Update CHANGELOG
MitchTurner 9c61f28
Appease Clippy-sama
MitchTurner 1c26eff
Merge remote-tracking branch 'origin' into include-tip-in-fee
MitchTurner 5a766a6
Use public interfaces for UTs
MitchTurner cb65324
Merge branch 'master' into include-tip-in-fee
MitchTurner 5494ee4
Update fuel-tx/src/transaction/fee.rs
MitchTurner 529a0a5
Update fuel-tx/src/transaction/fee.rs
MitchTurner 7bb425a
Update fuel-tx/src/transaction/fee.rs
MitchTurner 822565f
Fix compilation, move tip into tx methods, include in more prop tests
MitchTurner da76d37
fmt
MitchTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
use crate::{ | ||
field, | ||
field::WitnessLimit, | ||
field::{ | ||
Tip, | ||
WitnessLimit, | ||
}, | ||
input::{ | ||
coin::{ | ||
CoinPredicate, | ||
|
@@ -13,6 +16,7 @@ use crate::{ | |
MessageDataSigned, | ||
}, | ||
}, | ||
policies::PolicyType, | ||
FeeParameters, | ||
GasCosts, | ||
Input, | ||
|
@@ -92,10 +96,17 @@ impl TransactionFee { | |
where | ||
T: Chargeable, | ||
{ | ||
let tip = tx.tip(); | ||
let min_gas = tx.min_gas(gas_costs, params); | ||
let max_gas = tx.max_gas(gas_costs, params); | ||
let min_fee = tx.min_fee(gas_costs, params, gas_price).try_into().ok()?; | ||
let max_fee = tx.max_fee(gas_costs, params, gas_price).try_into().ok()?; | ||
let min_fee = tx | ||
.min_fee(gas_costs, params, gas_price, tip) | ||
.try_into() | ||
.ok()?; | ||
let max_fee = tx | ||
.max_fee(gas_costs, params, gas_price, tip) | ||
.try_into() | ||
.ok()?; | ||
|
||
if min_fee > max_fee { | ||
return None; | ||
|
@@ -150,12 +161,14 @@ pub trait Chargeable: field::Inputs + field::Witnesses + field::Policies { | |
gas_costs: &GasCosts, | ||
fee: &FeeParameters, | ||
gas_price: Word, | ||
tip: Word, | ||
) -> u128 { | ||
gas_to_fee( | ||
let gas_fee = gas_to_fee( | ||
self.min_gas(gas_costs, fee), | ||
gas_price, | ||
fee.gas_price_factor, | ||
) | ||
); | ||
gas_fee + tip as u128 | ||
MitchTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Returns the maximum possible fee after the end of transaction execution. | ||
|
@@ -166,12 +179,14 @@ pub trait Chargeable: field::Inputs + field::Witnesses + field::Policies { | |
gas_costs: &GasCosts, | ||
fee: &FeeParameters, | ||
gas_price: Word, | ||
tip: Word, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you want to get it from the policies |
||
) -> u128 { | ||
gas_to_fee( | ||
let gas_fee = gas_to_fee( | ||
self.max_gas(gas_costs, fee), | ||
gas_price, | ||
fee.gas_price_factor, | ||
) | ||
); | ||
gas_fee + tip as u128 | ||
MitchTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/// Returns the fee amount that can be refunded back based on the `used_gas` and | ||
|
@@ -192,8 +207,9 @@ pub trait Chargeable: field::Inputs + field::Witnesses + field::Policies { | |
let total_used_gas = min_gas.saturating_add(used_gas); | ||
let used_fee = gas_to_fee(total_used_gas, gas_price, fee.gas_price_factor); | ||
MitchTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
let tip = self.policies().get(PolicyType::Tip).unwrap_or(0); | ||
let refund = self | ||
.max_fee(gas_costs, fee, gas_price) | ||
.max_fee(gas_costs, fee, gas_price, tip) | ||
.saturating_sub(used_fee); | ||
// It is okay to saturate everywhere above because it only can decrease the value | ||
// of `refund`. But here, because we need to return the amount we | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you want to get it from the policies