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

Bugfix: more receipt generation issues with debugger #908

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- [895](https://github.com/FuelLabs/fuel-vm/pull/895): Fix elided lifetimes compilation warnings that became errors after the release of rust 1.83.0.
- [895](https://github.com/FuelLabs/fuel-vm/pull/895): Bump proptest-derive to version `0.5.1` to fix non-local impl errors on the derivation of `proptest_derive::Arbitrary` introduced by rust 1.83.0.
- [889](https://github.com/FuelLabs/fuel-vm/pull/889): Debugger breakpoint caused receipts to be produced incorrectly.
- [889](https://github.com/FuelLabs/fuel-vm/pull/889) and [908](https://github.com/FuelLabs/fuel-vm/pull/908): Debugger breakpoint caused receipts to be produced incorrectly.
- [903](https://github.com/FuelLabs/fuel-vm/pull/903): Fixed warning being emitted when using packages with Node@22+.

## [Version 0.59.1]
Expand Down
18 changes: 7 additions & 11 deletions fuel-vm/src/interpreter/executors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ where
&base_asset_id,
gas_price,
)?;
self.update_transaction_outputs()?;
ProgramState::Return(1)
} else if let Some(upgrade) = self.tx.as_upgrade_mut() {
Self::upgrade_inner(
Expand All @@ -920,6 +921,7 @@ where
&base_asset_id,
gas_price,
)?;
self.update_transaction_outputs()?;
ProgramState::Return(1)
} else if let Some(upload) = self.tx.as_upload_mut() {
Self::upload_inner(
Expand All @@ -931,6 +933,7 @@ where
&base_asset_id,
gas_price,
)?;
self.update_transaction_outputs()?;
ProgramState::Return(1)
} else if let Some(blob) = self.tx.as_blob_mut() {
Self::blob_inner(
Expand All @@ -942,13 +945,12 @@ where
&base_asset_id,
gas_price,
)?;
self.update_transaction_outputs()?;
ProgramState::Return(1)
} else {
// `Interpreter` supports only `Create` and `Script` transactions. It is not
// `Create` -> it is `Script`.
// This must be a `Script`.
self.run_program()?
};
self.update_transaction_outputs()?;

Ok(state)
}
Expand Down Expand Up @@ -1042,16 +1044,11 @@ where
&self.balances,
gas_price,
)?;
self.update_transaction_outputs()?;
*self.tx.as_script_mut().unwrap().receipts_root_mut() = self.receipts.root();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whiel it is true that we run only script, I still prefer to sue if let Some(script)=)

Copy link
Member Author

Choose a reason for hiding this comment

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

At the top of the function we error if as_script() cannot be used. We only access it again like this to satisfy borrow checker.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then would be nice to have expect and the comment that point to the top=D

Copy link
Member

Choose a reason for hiding this comment

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

I agree. I don't think we should unwrap anywhere in our prod code. I prefer the type-safe approach too--expect is more acceptable than unwrap but it's fragile still.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 690a381.


Ok(state)
}

/// Update tx fields after execution
pub(crate) fn post_execute(&mut self) {
if let Some(script) = self.tx.as_script_mut() {
*script.receipts_root_mut() = self.receipts.root();
}
}
}

impl<M, S, Tx, Ecal> Interpreter<M, S, Tx, Ecal>
Expand All @@ -1073,7 +1070,6 @@ where
self.verify_ready_tx(&tx)?;

let state_result = self.init_script(tx).and_then(|_| self.run());
self.post_execute();

#[cfg(feature = "profile-any")]
{
Expand Down
8 changes: 4 additions & 4 deletions fuel-vm/src/interpreter/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
{
pub(crate) fn update_memory_output(&mut self, idx: usize) -> SimpleResult<()> {
let tx_offset = self.tx_offset();
update_memory_output(&mut self.tx, self.memory.as_mut(), tx_offset, idx)
update_memory_output(&self.tx, self.memory.as_mut(), tx_offset, idx)
}
}

Expand Down Expand Up @@ -80,7 +80,7 @@ pub(crate) fn absolute_output_mem_range<Tx: Outputs>(
}

pub(crate) fn update_memory_output<Tx: ExecutableTransaction>(
tx: &mut Tx,
tx: &Tx,
memory: &mut MemoryInstance,
tx_offset: usize,
idx: usize,
Expand All @@ -89,8 +89,8 @@ pub(crate) fn update_memory_output<Tx: ExecutableTransaction>(
.ok_or(PanicReason::OutputNotFound)?;
let mut mem = memory.write_noownerchecks(range.start, range.len())?;
let output = tx
.outputs_mut()
.get_mut(idx)
.outputs()
.get(idx)
.expect("Invalid output index; checked above");
output
.encode(&mut mem)
Expand Down
2 changes: 1 addition & 1 deletion fuel-vm/src/interpreter/internal/message_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn test_update_memory_output(tx_offset: usize) -> SimpleResult<MemoryInstance> {
*tx.policies_mut() = Policies::default();
*tx.outputs_mut() = vec![Output::default()];
let mut memory: MemoryInstance = vec![0; MEM_SIZE].try_into().unwrap();
update_memory_output(&mut tx, &mut memory, tx_offset, 0).map(|_| memory)
update_memory_output(&tx, &mut memory, tx_offset, 0).map(|_| memory)
}

fn check_memory(result: MemoryInstance, expected: &[(usize, Vec<u8>)]) {
Expand Down
4 changes: 4 additions & 0 deletions fuel-vm/src/tests/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use fuel_asm::{
RegId,
};
use fuel_tx::{
field::ReceiptsRoot,
ConsensusParameters,
Finalizable,
GasCosts,
Expand Down Expand Up @@ -47,6 +48,7 @@ fn receipts_are_produced_correctly_with_stepping() {
let mut vm = Interpreter::<_, _, Script>::with_memory_storage();
vm.transact(tx.clone()).expect("panicked");
let receipts_without_debugger = vm.receipts().to_vec();
let receipts_root_without_debugger = vm.transaction().receipts_root();

let mut vm = Interpreter::<_, _, Script>::with_memory_storage();
vm.set_single_stepping(true);
Expand All @@ -67,6 +69,8 @@ fn receipts_are_produced_correctly_with_stepping() {
}
}
let receipts_with_debugger = vm.receipts();
let receipts_root_with_debugger = vm.transaction().receipts_root();

assert_eq!(receipts_without_debugger, receipts_with_debugger);
assert_eq!(receipts_root_without_debugger, receipts_root_with_debugger);
}
Loading