Skip to content

Commit

Permalink
Included the total gas and fee into TransactionStatus (#1831)
Browse files Browse the repository at this point in the history
Closes #1817


### Before requesting review
- [x] I have reviewed the code myself
  • Loading branch information
xgreenx authored Apr 17, 2024
1 parent df417f7 commit 7babe1a
Show file tree
Hide file tree
Showing 20 changed files with 241 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Description of the upcoming release here.

### Added

- [#1831](https://github.com/FuelLabs/fuel-core/pull/1831): Included the total gas and fee used by transaction into `TransactionStatus`.
- [#1821](https://github.com/FuelLabs/fuel-core/pull/1821): Propagate shutdown signal to (re)genesis. Also add progress bar for (re)genesis.
- [#1813](https://github.com/FuelLabs/fuel-core/pull/1813): Added back support for `/health` endpoint.
- [#1799](https://github.com/FuelLabs/fuel-core/pull/1799): Snapshot creation is now concurrent.
Expand Down
5 changes: 3 additions & 2 deletions benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ fn run_with_service_with_extra_inputs(
assert_eq!(res.sealed_block.entity.transactions().len(), 2);
assert_eq!(res.tx_status[0].id, tx_id);

let TransactionExecutionResult::Failed { result, receipts } =
&res.tx_status[0].result
let TransactionExecutionResult::Failed {
result, receipts, ..
} = &res.tx_status[0].result
else {
panic!("The execution should fails with out of gas")
};
Expand Down
2 changes: 2 additions & 0 deletions bin/fuel-core/src/cli/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ mod tests {
pc: self.rng.gen(),
is: self.rng.gen(),
}],
total_gas: self.rng.gen(),
total_fee: self.rng.gen(),
};

self.db
Expand Down
8 changes: 8 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ type DryRunFailureStatus {
programState: ProgramState
reason: String!
receipts: [Receipt!]!
totalGas: U64!
totalFee: U64!
}

type DryRunSuccessStatus {
programState: ProgramState
receipts: [Receipt!]!
totalGas: U64!
totalFee: U64!
}

type DryRunTransactionExecutionStatus {
Expand Down Expand Up @@ -309,6 +313,8 @@ type FailureStatus {
reason: String!
programState: ProgramState
receipts: [Receipt!]!
totalGas: U64!
totalFee: U64!
}

type FeeParameters {
Expand Down Expand Up @@ -1002,6 +1008,8 @@ type SuccessStatus {
time: Tai64Timestamp!
programState: ProgramState
receipts: [Receipt!]!
totalGas: U64!
totalFee: U64!
}

scalar Tai64Timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mutation($txs: [HexString!]!, $utxoValidation: Boolean) {
contractId
subId
}
totalGas
totalFee
}
... on DryRunFailureStatus {
programState {
Expand Down Expand Up @@ -78,9 +80,9 @@ mutation($txs: [HexString!]!, $utxoValidation: Boolean) {
contractId
subId
}
totalGas
totalFee
}
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ query($id: TransactionId!) {
contractId
subId
}
totalGas
totalFee
}
... on SqueezedOutStatus {
reason
Expand Down Expand Up @@ -95,9 +97,9 @@ query($id: TransactionId!) {
contractId
subId
}
totalGas
totalFee
}
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
contractId
subId
}
totalGas
totalFee
}
... on SqueezedOutStatus {
reason
Expand Down Expand Up @@ -98,6 +100,8 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
contractId
subId
}
totalGas
totalFee
}
}
}
Expand All @@ -110,5 +114,3 @@ query($owner: Address!, $after: String, $before: String, $first: Int, $last: Int
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ query($after: String, $before: String, $first: Int, $last: Int) {
contractId
subId
}
totalGas
totalFee
}
... on SqueezedOutStatus {
reason
Expand Down Expand Up @@ -98,6 +100,8 @@ query($after: String, $before: String, $first: Int, $last: Int) {
contractId
subId
}
totalGas
totalFee
}
}
}
Expand All @@ -110,5 +114,3 @@ query($after: String, $before: String, $first: Int, $last: Int) {
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ query($id: TransactionId!) {
contractId
subId
}
totalGas
totalFee
}
... on SqueezedOutStatus {
reason
Expand Down Expand Up @@ -179,6 +181,8 @@ query($id: TransactionId!) {
contractId
subId
}
totalGas
totalFee
}
}
witnesses
Expand Down
13 changes: 13 additions & 0 deletions crates/client/src/client/schema/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::client::{
PageInfo,
Tai64Timestamp,
TransactionId,
U64,
},
types::TransactionResponse,
PageDirection,
Expand Down Expand Up @@ -182,6 +183,8 @@ pub struct SuccessStatus {
pub time: Tai64Timestamp,
pub program_state: Option<ProgramState>,
pub receipts: Vec<Receipt>,
pub total_gas: U64,
pub total_fee: U64,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand All @@ -193,6 +196,8 @@ pub struct FailureStatus {
pub reason: String,
pub program_state: Option<ProgramState>,
pub receipts: Vec<Receipt>,
pub total_gas: U64,
pub total_fee: U64,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand Down Expand Up @@ -225,6 +230,8 @@ impl TryFrom<DryRunTransactionStatus> for TransactionExecutionResult {
TransactionExecutionResult::Success {
result: s.program_state.map(TryInto::try_into).transpose()?,
receipts,
total_gas: s.total_gas.0,
total_fee: s.total_fee.0,
}
}
DryRunTransactionStatus::FailureStatus(s) => {
Expand All @@ -236,6 +243,8 @@ impl TryFrom<DryRunTransactionStatus> for TransactionExecutionResult {
TransactionExecutionResult::Failed {
result: s.program_state.map(TryInto::try_into).transpose()?,
receipts,
total_gas: s.total_gas.0,
total_fee: s.total_fee.0,
}
}
DryRunTransactionStatus::Unknown => {
Expand All @@ -250,13 +259,17 @@ impl TryFrom<DryRunTransactionStatus> for TransactionExecutionResult {
pub struct DryRunSuccessStatus {
pub program_state: Option<ProgramState>,
pub receipts: Vec<Receipt>,
pub total_gas: U64,
pub total_fee: U64,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct DryRunFailureStatus {
pub program_state: Option<ProgramState>,
pub receipts: Vec<Receipt>,
pub total_gas: U64,
pub total_fee: U64,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
Expand Down
8 changes: 8 additions & 0 deletions crates/client/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub enum TransactionStatus {
time: Tai64,
program_state: Option<ProgramState>,
receipts: Vec<Receipt>,
total_gas: u64,
total_fee: u64,
},
SqueezedOut {
reason: String,
Expand All @@ -110,6 +112,8 @@ pub enum TransactionStatus {
reason: String,
program_state: Option<ProgramState>,
receipts: Vec<Receipt>,
total_gas: u64,
total_fee: u64,
},
}

Expand All @@ -130,6 +134,8 @@ impl TryFrom<SchemaTxStatus> for TransactionStatus {
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
total_gas: s.total_gas.0,
total_fee: s.total_fee.0,
},
SchemaTxStatus::FailureStatus(s) => TransactionStatus::Failure {
block_height: s.block.height.into(),
Expand All @@ -141,6 +147,8 @@ impl TryFrom<SchemaTxStatus> for TransactionStatus {
.into_iter()
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?,
total_gas: s.total_gas.0,
total_fee: s.total_fee.0,
},
SchemaTxStatus::SqueezedOutStatus(s) => {
TransactionStatus::SqueezedOut { reason: s.reason }
Expand Down
2 changes: 2 additions & 0 deletions crates/fuel-core/src/query/message/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ async fn can_build_message_proof() {
time: Tai64::UNIX_EPOCH,
result: None,
receipts: vec![],
total_gas: 0,
total_fee: 0,
})
});

Expand Down
4 changes: 4 additions & 0 deletions crates/fuel-core/src/query/subscriptions/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ fn success() -> TransactionStatus {
time: Tai64(0),
result: None,
receipts: vec![],
total_gas: 0,
total_fee: 0,
}
}

Expand All @@ -66,6 +68,8 @@ fn failed() -> TransactionStatus {
time: Tai64(0),
result: None,
receipts: vec![],
total_gas: 0,
total_fee: 0,
}
}

Expand Down
Loading

0 comments on commit 7babe1a

Please sign in to comment.