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

Process Upgrade transaction inside of the Interpreter #712

Merged
merged 60 commits into from
Apr 11, 2024

Conversation

xgreenx
Copy link
Collaborator

@xgreenx xgreenx commented Apr 2, 2024

The Interpreter supports the processing of the Upgrade transaction. The change affects InterpreterStorage, adding 5 new methods that must be implemented.

xgreenx and others added 30 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
…ction

# Conflicts:
#	fuel-tx/src/transaction/consensus_parameters.rs
# Conflicts:
#	fuel-tx/src/transaction/consensus_parameters.rs
#	fuel-vm/src/tests/validation.rs
…ansaction

# Conflicts:
#	fuel-tx/src/transaction/types/script.rs
#	fuel-vm/src/interpreter.rs
Base automatically changed from feature/upgrade-transaction to master April 9, 2024 19:22
…-interpreter

# Conflicts:
#	CHANGELOG.md
#	fuel-tx/src/lib.rs
#	fuel-tx/src/transaction/types.rs
Comment on lines +490 to +493
debug_assert!(
metadata.is_some(),
"`upgrade_inner` is called without cached metadata"
);
Copy link
Member

Choose a reason for hiding this comment

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

Can't we compute the metadata here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can, but it was calculated before in the Checked transaction. It is just a debug assert for the future if someone decides to change the code or behavior later.

Recalculation of it breaks the idea of the metadata=D

.map_err(RuntimeError::Storage)?;
let next_version = current_version
.checked_add(1)
.ok_or(InterpreterError::Panic(PanicReason::ArithmeticOverflow))?;
Copy link
Member

Choose a reason for hiding this comment

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

Introducing a new PanicReason for this would be nice. ArithmeticOverflow is meant to be used for arithmetic opcodes only.

.map_err(RuntimeError::Storage)?;
let next_version = current_version
.checked_add(1)
.ok_or(InterpreterError::Panic(PanicReason::ArithmeticOverflow))?;
Copy link
Member

Choose a reason for hiding this comment

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

As above

@@ -83,6 +84,11 @@ impl<Ecal: EcalHandler> MemoryClient<Ecal> {
self.transactor.deploy(tx).ok()
}

/// Executes `Upgrade` transaction.
pub fn upgrade(&mut self, tx: Checked<Upgrade>) -> Option<Upgrade> {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we erasing the error type here?

Copy link
Member

@Dentosal Dentosal left a comment

Choose a reason for hiding this comment

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

Needs some clarifications

Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

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

Made it part way through.

fuel-asm/src/panic_reason.rs Outdated Show resolved Hide resolved
fuel-asm/src/panic_reason.rs Outdated Show resolved Hide resolved
}

#[test]
fn transact_fails_when_try_to_override_state_bytecode() {
Copy link
Member

Choose a reason for hiding this comment

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

This case is confusing me. Isn't the point of the upgrade to override some previous state?

Other than the first time it's run, under what circumstances will this not fail?

Copy link
Member

Choose a reason for hiding this comment

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

Same question for the consensus params.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Each version contains only one associated consensus parameter or state transition function. If it was set before, it is not allowed to be overridden for the same version. You can only increase the version and set it for a new one.

xgreenx and others added 3 commits April 10, 2024 22:25
Co-authored-by: Mitchell Turner <james.mitchell.turner@gmail.com>
Co-authored-by: Mitchell Turner <james.mitchell.turner@gmail.com>
@xgreenx xgreenx requested review from MitchTurner, Dentosal and a team April 10, 2024 21:08
@xgreenx xgreenx force-pushed the feature/process-upgrade-transaction-within-interpreter branch from 9f128fa to e871566 Compare April 10, 2024 21:50
..Default::default()
};

let ready_tx = TransactionBuilder::upgrade(UpgradePurpose::StateTransition {
Copy link
Member

Choose a reason for hiding this comment

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

Similar to the "Upload" PR, this could be moved to a helper to declutter this test.

// when
let mut transactor =
Transactor::<_, Upgrade>::new(MemoryStorage::default(), interpreter_params);
let err = transactor.execute_ready_upgrade_tx(ready_tx).unwrap_err();
Copy link
Member

Choose a reason for hiding this comment

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

This test isn't testing Upgrade it's testing execute_ready_upgrade_tx. I know this is what upgrade uses under the hood, but is that actually the public function we want to support?

@xgreenx xgreenx requested review from MitchTurner and a team April 11, 2024 00:02
Comment on lines +570 to +572
// It shouldn't be possible since `Check<Upgrade>` guarantees that.
Err(InterpreterError::CheckError(CheckError::Validity(
ValidityError::TransactionMetadataMismatch,
Copy link
Member

Choose a reason for hiding this comment

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

nit: Considering just using unreachable! here if this is actually impossible

@xgreenx xgreenx added this pull request to the merge queue Apr 11, 2024
Merged via the queue into master with commit f43210a Apr 11, 2024
38 checks passed
@xgreenx xgreenx deleted the feature/process-upgrade-transaction-within-interpreter branch April 11, 2024 18:54
@xgreenx xgreenx mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking api change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants