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

Unified Create and Script logic via ChargeableTransaction #706

Merged
merged 26 commits into from
Mar 26, 2024

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Mar 24, 2024

Created ChargeableTransaction that accumulates common logic of the Create and Script transactions. The same logic can be applied to any chargeable transaction. The Mint transaction is free and created by the block producer, so it is not chargeable and doesn't have policies, inputs, outputs, and witnesses.

Side changes:

  • Updated the canonical serialization and deserialization logic to ignore fields marked with canonical(skip). We already partially supported that, but if the skipped field used a generic, we required that generic to implement the corresponding trait. After the change, skipped fields don't impact the generic's constraints.

The change is breaking because affects JSON serialization and deserialization. Now Script and Create transactions have body fields that include unique transactions.

xgreenx and others added 14 commits March 21, 2024 07:37
Reduced default `MAX_SIZE` to be 110kb.
Reduced default `MAX_CONTRACT_SIZE` to be 100kb.
# Conflicts:
#	CHANGELOG.md
#	fuel-tx/src/builder.rs
#	fuel-tx/src/tests/valid_cases/transaction.rs
#	fuel-tx/src/transaction/consensus_parameters.rs
#	fuel-vm/src/checked_transaction.rs
#	fuel-vm/src/tests/limits.rs
#	fuel-vm/src/tests/validation.rs
@xgreenx xgreenx requested a review from a team March 24, 2024 16:19
@xgreenx xgreenx self-assigned this Mar 24, 2024
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[derivative(Eq, PartialEq, Hash, Debug)]
pub struct ChargeableTransaction<Body, MetadataBody> {
pub(crate) body: Body,
Copy link
Collaborator Author

@xgreenx xgreenx Mar 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is breaking because now old fields live under the body subfield. We could avoid it by flattening(serde(flatten)) the inner structure, but it is not supported properly by serde for the bincode.

@Dentosal
Copy link
Member

What's the difference between ChargeableTransaction and ExecutableTransaction?

@xgreenx
Copy link
Collaborator Author

xgreenx commented Mar 25, 2024

Hmm, basically no difference=D We also could use the name ExecutableTransasction.

I decided to call it "chargeable" because any executable transaction is chargeable by default, but not any chargeable transaction is executable. Executable transactions mean that they support predicate execution as well.

@Dentosal
Copy link
Member

I mean there's already an ExecutableTransaction trait:

pub trait ExecutableTransaction:

This is only implemented for Script and Create. So I was confused about the naming. But apparently ChargeableTransaction is a concrete type containing the common fields instead. The naming makes sense, but it's still a bit confusing.

@xgreenx
Copy link
Collaborator Author

xgreenx commented Mar 25, 2024

This PR Upgrade transaction that also implements the ExecutableTransaction trait. The idea is that ExecutableTransaction is defined by the Interpreter, and it is requirements from the VM to the transaction. While ChargeableTransaction is defined in the fuel-tx without any execution context.

…ansaction

# Conflicts:
#	fuel-tx/src/transaction/types/script.rs
#	fuel-vm/src/interpreter.rs
@@ -51,7 +51,6 @@ impl MintMetadata {
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
#[canonical(prefix = TransactionRepr::Mint)]
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wasm_bindgen doesn't know how to work with generics, so it is not possible to inherit for Create and Script transactions. So, I reworked how we are passing any transaction to typescript.

Co-authored-by: Hannes Karppila <hannes.karppila@gmail.com>
Base automatically changed from feature/common-payable-part to master March 26, 2024 14:41
Dentosal
Dentosal previously approved these changes Mar 26, 2024
@Dentosal
Copy link
Member

Now has conflicts, but looks correct otherwise.

# Conflicts:
#	CHANGELOG.md
#	fuel-tx/src/transaction/types/create.rs
#	fuel-tx/src/transaction/types/script.rs
@xgreenx xgreenx dismissed Dentosal’s stale review March 26, 2024 14:44

The merge-base changed after approval.

@xgreenx xgreenx requested review from Dentosal and a team March 26, 2024 14:44
@xgreenx xgreenx added this pull request to the merge queue Mar 26, 2024
Merged via the queue into master with commit ac31acf Mar 26, 2024
38 checks passed
@xgreenx xgreenx deleted the feature/chargeable-transaction branch March 26, 2024 16:30
@xgreenx xgreenx mentioned this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants