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

Ignore the message receipt if transaction is reverted #2045

Merged
merged 5 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- "gas-price-threshold-percent" - the threshold percent for determining if the gas price will be increase or decreased
And the following CLI flags are serving a new purpose
- "min-gas-price" - the minimum gas price that the gas price algorithm will return

### Fixed

#### Breaking
- [2045](https://github.com/FuelLabs/fuel-core/pull/2045): Include withdrawal message only if transaction is executed successfully.

## [Version 0.31.0]

### Added
Expand Down
83 changes: 82 additions & 1 deletion crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ mod tests {
RegId,
},
fuel_crypto::SecretKey,
fuel_merkle::sparse,
fuel_merkle::{
common::empty_sum_sha256,
sparse,
},
fuel_tx::{
consensus_parameters::gas::GasCostsValuesV1,
field::{
Expand Down Expand Up @@ -2528,6 +2531,84 @@ mod tests {
));
}

#[test]
fn withdrawal_message_included_in_header_for_successfully_executed_transaction() {
// Given
let amount_from_random_input = 1000;
let smo_tx = TransactionBuilder::script(
vec![
// The amount to send in coins.
op::movi(0x13, amount_from_random_input),
// Send the message output.
op::smo(0x0, 0x0, 0x0, 0x13),
op::ret(RegId::ONE),
]
.into_iter()
.collect(),
vec![],
)
.add_random_fee_input()
.script_gas_limit(1000000)
.finalize_as_transaction();

let block = PartialFuelBlock {
header: Default::default(),
transactions: vec![smo_tx],
};

// When
let ExecutionResult { block, .. } =
create_executor(Default::default(), Default::default())
.produce_and_commit(block)
.expect("block execution failed unexpectedly");
create_executor(Default::default(), Default::default())
.validate_and_commit(&block)
.expect("block validation failed unexpectedly");

// Then
let empty_root = empty_sum_sha256();
assert_ne!(block.header().message_outbox_root.as_ref(), empty_root)
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn withdrawal_message_not_included_in_header_for_failed_transaction() {
// Given
let amount_from_random_input = 1000;
let smo_tx = TransactionBuilder::script(
vec![
// The amount to send in coins.
op::movi(0x13, amount_from_random_input),
// Send the message output.
op::smo(0x0, 0x0, 0x0, 0x13),
op::rvrt(0x0),
]
.into_iter()
.collect(),
vec![],
)
.add_random_fee_input()
.script_gas_limit(1000000)
.finalize_as_transaction();

let block = PartialFuelBlock {
header: Default::default(),
transactions: vec![smo_tx],
};

// When
let ExecutionResult { block, .. } =
create_executor(Default::default(), Default::default())
.produce_and_commit(block)
.expect("block execution failed unexpectedly");
create_executor(Default::default(), Default::default())
.validate_and_commit(&block)
.expect("block validation failed unexpectedly");

// Then
let empty_root = empty_sum_sha256();
assert_eq!(block.header().message_outbox_root.as_ref(), empty_root)
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
}

#[test]
fn get_block_height_returns_current_executing_block() {
let mut rng = StdRng::seed_from_u64(1234);
Expand Down
10 changes: 7 additions & 3 deletions crates/services/executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1365,9 +1365,13 @@ where
.used_gas
.checked_add(used_gas)
.ok_or(ExecutorError::GasOverflow)?;
execution_data
.message_ids
.extend(receipts.iter().filter_map(|r| r.message_id()));

if !reverted {
execution_data
.message_ids
.extend(receipts.iter().filter_map(|r| r.message_id()));
}

let status = if reverted {
TransactionExecutionResult::Failed {
result: Some(state),
Expand Down
Loading