Skip to content

Commit

Permalink
Handle FTI messages in executor (#1787)
Browse files Browse the repository at this point in the history
Closes #1626

todo:

tests / requirements - 

- [x]  query the status of failed forced transactions
- [x]  prevent non-chargeable txs from being included
- [x] handle duplicate relayed txs ids (what should gql api report if
there are duplicate FTIs?)
- ~NOTE: The current solution is each duplicate gets added to the
`skipped_transactions` for the block. We might want to find a different
solution if UX is bad--but it's _findable_ at least currently.~ Edit: We
are now reporting duplicate txs just like any other execution error for
relayed txs. Since they will all have unique nonces in practice, all of
their ids will be unique.
- [x] ensure that skipped fti's due to invalid state (ie. missing utxo
inputs) have their status reported
- [x] ensure that sentry nodes also include the status of failed FTIs
without failing the processing of the block
- [x]  ensure users aren't double charged for gas payed on l1

---------

Co-authored-by: mitchell <[email protected]>
  • Loading branch information
Voxelot and MitchTurner authored Apr 13, 2024
1 parent e99b0b4 commit 376894e
Show file tree
Hide file tree
Showing 24 changed files with 1,245 additions and 102 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Description of the upcoming release here.

### Added

- [#1787](https://github.com/FuelLabs/fuel-core/pull/1787): Handle processing of relayed (forced) transactions
- [#1786](https://github.com/FuelLabs/fuel-core/pull/1786): Regenesis now includes off-chain tables.
- [#1716](https://github.com/FuelLabs/fuel-core/pull/1716): Added support of WASM state transition along with upgradable execution that works with native(std) and WASM(non-std) executors. The `fuel-core` now requires a `wasm32-unknown-unknown` target to build.
- [#1770](https://github.com/FuelLabs/fuel-core/pull/1770): Add the new L1 event type for forced transactions.
Expand Down
10 changes: 10 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ type Query {
messages(owner: Address, first: Int, after: String, last: Int, before: String): MessageConnection!
messageProof(transactionId: TransactionId!, nonce: Nonce!, commitBlockId: BlockId, commitBlockHeight: U32): MessageProof
messageStatus(nonce: Nonce!): MessageStatus!
relayedTransactionStatus(id: RelayedTransactionId!): RelayedTransactionStatus
}

type Receipt {
Expand Down Expand Up @@ -902,6 +903,15 @@ enum ReceiptType {
BURN
}

type RelayedTransactionFailed {
blockHeight: U32!
failure: String!
}

scalar RelayedTransactionId

union RelayedTransactionStatus = RelayedTransactionFailed

enum ReturnType {
RETURN
RETURN_DATA
Expand Down
21 changes: 21 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::client::{
contract::ContractBalanceQueryArgs,
gas_price::EstimateGasPrice,
message::MessageStatusArgs,
relayed_tx::RelayedTransactionStatusArgs,
tx::DryRunArg,
Tai64Timestamp,
TransactionId,
Expand All @@ -22,6 +23,7 @@ use crate::client::{
ContractId,
UtxoId,
},
RelayedTransactionStatus,
},
};
use anyhow::Context;
Expand All @@ -41,6 +43,7 @@ use fuel_core_types::{
Word,
},
fuel_tx::{
Bytes32,
Receipt,
Transaction,
TxId,
Expand Down Expand Up @@ -968,6 +971,24 @@ impl FuelClient {

Ok(proof)
}

pub async fn relayed_transaction_status(
&self,
id: &Bytes32,
) -> io::Result<Option<RelayedTransactionStatus>> {
let query = schema::relayed_tx::RelayedTransactionStatusQuery::build(
RelayedTransactionStatusArgs {
id: id.to_owned().into(),
},
);
let status = self
.query(query)
.await?
.relayed_transaction_status
.map(|status| status.try_into())
.transpose()?;
Ok(status)
}
}

#[cfg(any(test, feature = "test-helpers"))]
Expand Down
2 changes: 2 additions & 0 deletions crates/client/src/client/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub mod gas_price;
pub mod primitives;
pub mod tx;

pub mod relayed_tx;

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl", graphql_type = "Query")]
pub struct Health {
Expand Down
1 change: 1 addition & 0 deletions crates/client/src/client/schema/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ fuel_type_scalar!(AssetId, AssetId);
fuel_type_scalar!(ContractId, ContractId);
fuel_type_scalar!(Salt, Salt);
fuel_type_scalar!(TransactionId, Bytes32);
fuel_type_scalar!(RelayedTransactionId, Bytes32);
fuel_type_scalar!(Signature, Bytes64);
fuel_type_scalar!(Nonce, Nonce);

Expand Down
39 changes: 39 additions & 0 deletions crates/client/src/client/schema/relayed_tx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::client::schema::{
schema,
RelayedTransactionId,
U32,
};

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "RelayedTransactionStatusArgs"
)]
pub struct RelayedTransactionStatusQuery {
#[arguments(id: $id)]
pub relayed_transaction_status: Option<RelayedTransactionStatus>,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct RelayedTransactionStatusArgs {
/// Transaction id that contains the output message.
pub id: RelayedTransactionId,
}

#[allow(clippy::enum_variant_names)]
#[derive(cynic::InlineFragments, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum RelayedTransactionStatus {
/// Transaction was included in a block, but the execution was reverted
Failed(RelayedTransactionFailed),
#[cynic(fallback)]
Unknown,
}

#[derive(cynic::QueryFragment, Clone, Debug, PartialEq, Eq)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct RelayedTransactionFailed {
pub block_height: U32,
pub failure: String,
}
29 changes: 29 additions & 0 deletions crates/client/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub use message::{
pub use node_info::NodeInfo;

use crate::client::schema::{
relayed_tx::RelayedTransactionStatus as SchemaRelayedTransactionStatus,
tx::{
OpaqueTransaction,
TransactionStatus as SchemaTxStatus,
Expand Down Expand Up @@ -169,3 +170,31 @@ impl TryFrom<OpaqueTransaction> for TransactionResponse {
})
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RelayedTransactionStatus {
Failed {
block_height: BlockHeight,
failure: String,
},
}

impl TryFrom<SchemaRelayedTransactionStatus> for RelayedTransactionStatus {
type Error = ConversionError;

fn try_from(status: SchemaRelayedTransactionStatus) -> Result<Self, Self::Error> {
Ok(match status {
SchemaRelayedTransactionStatus::Failed(s) => {
RelayedTransactionStatus::Failed {
block_height: s.block_height.into(),
failure: s.failure,
}
}
SchemaRelayedTransactionStatus::Unknown => {
return Err(Self::Error::UnknownVariant(
"SchemaRelayedTransactionStatus",
));
}
})
}
}
1 change: 0 additions & 1 deletion crates/fuel-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ mod tests {
.insert(&prev_height, &CompressedBlock::default());

// Then
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
StorageError::from(DatabaseError::HeightsAreNotLinked {
Expand Down
Loading

0 comments on commit 376894e

Please sign in to comment.