-
Notifications
You must be signed in to change notification settings - Fork 718
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
Transaction Policies #514
Transaction Policies #514
Conversation
While we move some of the fields to policies, we don't plan to change the API of the The changes will affect the serialization and deserialization of the transactions, and a minimal fee to include Another hidden change is that What should be changed to support policies:
|
I don't think specifying a witness limit should be mandatory at the protocol level, but maybe the SDK's should validate this for users. |
I also realized this PR needs to update the GTF opcode, although I don't think this will impact sway a lot except for some additive changes to the std-lib. |
add gtf args for policies pad gtf args to avoid conflicts
@xgreenx I've updated the PR to move gasPrice to policies, added requirements to tx-validity specifying that the gasPrice policy is required for now, and also added policies to the GTF args. |
@xgreenx fixed the comments you left, and pushed a separate commit for a different idea I had about using bitfields to index policies and reduce the amount of data that policies consume. |
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.
I like the idea of using bitmask as the length provider and type of policy provider. It saves 8 bytes per policy. It makes implementation a little bit complicated, but it is worth of that.
src/tx-format/transaction.md
Outdated
|--------------------|-----------------------------|----------------------------------------| | ||
| `scriptLength` | `uint16` | Script length, in instructions. | | ||
| `scriptDataLength` | `uint16` | Length of script input data, in bytes. | | ||
| `policyTypes` | `uint32` | Bitfield of used policy types. | |
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.
I think it's okay to use u64
here since it takes 8 bytes in canonical format.
| `policyTypes` | `uint32` | Bitfield of used policy types. | | |
| `policyTypes` | `uint64` | Bitfield of used policy types. | |
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.
True but it could save data outside of the VM for things like DA
segregate predicateGasUsed from tx.gasLimit
# Conflicts: # src/tx-format/constants.md
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.
LGTM!
src/tx-format/transaction.md
Outdated
@@ -83,7 +83,11 @@ Transaction is invalid if: | |||
- `scriptDataLength > MAX_SCRIPT_DATA_LENGTH` | |||
- `scriptLength * 4 != len(script)` | |||
- `scriptDataLength != len(scriptData)` | |||
- `gasLimit` is less than the sum of all `predicateGasUsed` for `InputType.Coin` or `InputType.Message` where predicate length is greater than zero. | |||
- No policy of type `PolicyType.GasPrice` | |||
- No policy of type `PolicyType.GasLimit` |
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.
I think we can allow not havePolicyType.GasLimit
in the case of an empty script
.
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.
I just made gas limit a default field for script transactions. The only reason to keep it as a policy is to save a u64 off of basic transfers that don't use any script logic.
Frontend:The
small - up to one day |
Co-authored-by: Green Baneling <[email protected]>
@luizstacio could this time be shortened by using fuel-tx wasm for serialization? cc @digorithm |
I think if we change fuel-tx this will be a big push on the fuels-ts side and potentially include multiple break changes. This means more time on ts-sdk and more time on FE. |
Summary
Use a dynamic set of policies for transaction validation requirements such as gaslimit & maturity. This will reduce the size of transactions that always leave these fields unset, and also future proof the transaction format for later requirements such as multi-dimensional pricing.
A new policy that's been added is
witnessLimit
. Having a witness limit allows the network to charge for witness data without exposing users to malicious basefee manipulation by third-parties / relayers. Without a charge & limit for witness data, blockspace could be easily saturated with spurious spammy witness data.Another significant change is to separate base costs of the transaction from the transaction gas limit. Gas limit will now only apply to script execution, and everything else is charged as part of the minimum transaction fee.
Since the gas limit can't restrict the total cost of the transaction anymore, another policy called
MaxFee
was added. This is a more direct way to place an upper bound on transaction costs and is also future compatible with multi-dimensional pricing.Multi-dimension pricing preparation
In order for resources such as execution and storage to be charged for independently, transactions must be able to specify an anticipated consumption limit for each resource kind. By abstracting these limits into a dynamic set of policies, new resource types can be added in the future more easily.