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

ScriptExecutionResult + Call Receipt Updates (fuel-tx 0.8) #276

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
53 changes: 21 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions fuel-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ clap = { version = "3.1", features = ["derive"] }
cynic = { version = "0.14", features = ["surf"] }
derive_more = { version = "0.99" }
fuel-storage = "0.1"
fuel-tx = { version = "0.7", features = ["serde-types"] }
fuel-tx = { version = "0.8", features = ["serde-types"] }
fuel-types = { version = "0.3", features = ["serde-types"] }
fuel-vm = { version = "0.6", features = ["serde-types"] }
fuel-vm = { version = "0.7", features = ["serde-types"] }
futures = "0.3"
hex = "0.4"
itertools = "0.10"
Expand Down
4 changes: 2 additions & 2 deletions fuel-client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ type Receipt {
amount: U64
assetId: AssetId
gas: U64
a: U64
b: U64
param1: U64
param2: U64
val: U64
ptr: U64
digest: Bytes32
Expand Down
7 changes: 7 additions & 0 deletions fuel-client/src/client/schema/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::client::schema::ConversionError;
use crate::client::schema::ConversionError::HexStringPrefixError;
use core::fmt;
use cynic::impl_scalar;
use fuel_tx::InstructionResult;
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt::{Debug, Display, Formatter, LowerHex};
Expand Down Expand Up @@ -195,3 +196,9 @@ impl From<usize> for U64 {
U64(i as u64)
}
}

impl From<U64> for InstructionResult {
fn from(s: U64) -> Self {
s.0.into()
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
source: fuel-client/src/client/schema/tx.rs
assertion_line: 271
expression: operation.query

---
query Query($_0: TransactionId!) {
transaction(id: $_0) {
Expand Down Expand Up @@ -101,8 +99,8 @@ query Query($_0: TransactionId!) {
}
witnesses
receipts {
a
b
param1
param2
amount
assetId
gas
Expand Down
16 changes: 8 additions & 8 deletions fuel-client/src/client/schema/tx/tests/transparent_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use fuel_types::Word;
#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Receipt {
pub a: Option<U64>,
pub b: Option<U64>,
pub param1: Option<U64>,
pub param2: Option<U64>,
pub amount: Option<U64>,
pub asset_id: Option<AssetId>,
pub gas: Option<U64>,
Expand Down Expand Up @@ -75,13 +75,13 @@ impl TryFrom<Receipt> for fuel_vm::prelude::Receipt {
.gas
.ok_or_else(|| MissingField("gas".to_string()))?
.into(),
a: schema
.a
.ok_or_else(|| MissingField("a".to_string()))?
param1: schema
.param1
.ok_or_else(|| MissingField("param1".to_string()))?
.into(),
b: schema
.b
.ok_or_else(|| MissingField("b".to_string()))?
param2: schema
.param2
.ok_or_else(|| MissingField("param2".to_string()))?
.into(),
pc: schema
.pc
Expand Down
4 changes: 2 additions & 2 deletions fuel-core-interfaces/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ derive_more = { version = "0.99" }
fuel-asm = "0.3"
fuel-crypto = { version = "0.4", default-features = false }
fuel-storage = "0.1"
fuel-tx = { version = "0.7", default-features = false }
fuel-tx = { version = "0.8", default-features = false }
fuel-types = { version = "0.3", default-features = false }
fuel-vm = { version = "0.6", default-features = false }
fuel-vm = { version = "0.7", default-features = false }
futures = "0.3"
lazy_static = "1.4"
parking_lot = "0.12"
Expand Down
10 changes: 5 additions & 5 deletions fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ fuel-asm = { version = "0.3", features = ["serde-types"] }
fuel-core-interfaces = { path = "../fuel-core-interfaces", version = "0.5.0", features = [
"serde-types",
] }
fuel-crypto = { version = "0.3" }
fuel-crypto = { version = "0.4" }
fuel-merkle = "0.1"
fuel-storage = { version = "0.1" }
fuel-tx = { version = "0.7", features = ["serde-types"] }
fuel-tx = { version = "0.8", features = ["serde-types"] }
fuel-txpool = { path = "../fuel-txpool", version = "0.5.0" }
fuel-types = { version = "0.3", features = ["serde-types"] }
fuel-vm = { version = "0.6", features = ["serde-types"] }
fuel-vm = { version = "0.7", features = ["serde-types"] }
futures = "0.3"
graphql-parser = "0.3.0"
hex = { version = "0.4", features = ["serde"] }
Expand Down Expand Up @@ -70,12 +70,12 @@ uuid = { version = "0.8", features = ["v4"] }

[dev-dependencies]
assert_matches = "1.5"
fuel-tx = { version = "0.7", features = [
fuel-tx = { version = "0.8", features = [
"serde-types",
"builder",
"internals",
] }
fuel-vm = { version = "0.6", features = [
fuel-vm = { version = "0.7", features = [
"serde-types",
"random",
"test-helpers",
Expand Down
41 changes: 18 additions & 23 deletions fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,24 @@ impl Executor {

let status = if vm_result.should_revert() {
self.log_backtrace(&vm, vm_result.receipts());
// if script result exists, log reason
if let Some((script_result, _)) = vm_result.receipts().iter().find_map(|r| {
if let Receipt::ScriptResult { result, gas_used } = r {
Some((result, gas_used))
} else {
None
}
}) {
TransactionStatus::Failed {
block_id: Default::default(),
time: block.header.time,
reason: format!("{:?}", script_result.reason()),
result: Some(*vm_result.state()),
}
}
// otherwise just log the revert arg
else {
TransactionStatus::Failed {
block_id: Default::default(),
time: block.header.time,
reason: format!("{:?}", vm_result.state()),
result: Some(*vm_result.state()),
}
// get reason for revert
let reason = vm_result
.receipts()
.iter()
.find_map(|receipt| match receipt {
// Format as `Revert($rA)`
Receipt::Revert { ra, .. } => Some(format!("Revert({})", ra)),
// Display PanicReason e.g. `OutOfGas`
Receipt::Panic { reason, .. } => Some(format!("{}", reason.reason())),
_ => None,
})
.unwrap_or_else(|| format!("{:?}", vm_result.state()));

TransactionStatus::Failed {
block_id: Default::default(),
time: block.header.time,
reason,
result: Some(*vm_result.state()),
}
} else {
// else tx was a success
Expand Down
10 changes: 5 additions & 5 deletions fuel-core/src/schema/tx/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ impl Receipt {
async fn gas(&self) -> Option<U64> {
self.0.gas().map(Into::into)
}
async fn a(&self) -> Option<U64> {
self.0.a().map(Into::into)
async fn param1(&self) -> Option<U64> {
self.0.param1().map(Into::into)
}
async fn b(&self) -> Option<U64> {
self.0.b().map(Into::into)
async fn param2(&self) -> Option<U64> {
self.0.param2().map(Into::into)
}
async fn val(&self) -> Option<U64> {
self.0.val().map(Into::into)
Expand All @@ -82,7 +82,7 @@ impl Receipt {
self.0.digest().copied().map(Into::into)
}
async fn reason(&self) -> Option<U64> {
self.0.reason().map(Into::into)
self.0.reason().map(|r| U64(r.into()))
}
async fn ra(&self) -> Option<U64> {
self.0.ra().map(Into::into)
Expand Down
2 changes: 1 addition & 1 deletion fuel-indexer/schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false

[dependencies]
diesel = { version = "1.4", optional = true, features = ["postgres", "serde_json"] }
fuel-tx = { version = "0.7", default-features = false }
fuel-tx = { version = "0.8", default-features = false }
fuel-types = { version = "0.3", default-features = false }
graphql-parser = "0.3"
itertools = { version = "0.10", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions fuel-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ chrono = { version = "0.4", features = ["serde"] }
fuel-core = { path = "../fuel-core", features = ["test-helpers"], default-features = false }
fuel-gql-client = { path = "../fuel-client", features = ["test-helpers"] }
fuel-storage = "0.1"
fuel-tx = { version = "0.7", features = ["serde-types"] }
fuel-tx = { version = "0.8", features = ["serde-types"] }
fuel-types = { version = "0.3", features = ["serde-types"] }
fuel-vm = { version = "0.6", features = ["serde-types", "random","test-helpers"] }
fuel-vm = { version = "0.7", features = ["serde-types", "random","test-helpers"] }
insta = "1.8"
itertools = "0.10"
rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion fuel-txpool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description = "Transaction pool"
anyhow = "1.0"
async-trait = "0.1"
fuel-core-interfaces = { path = "../fuel-core-interfaces", version = "0.5.0" }
fuel-tx = { version = "0.7", features = ["serde-types"] }
fuel-tx = { version = "0.8", features = ["serde-types"] }
fuel-types = { version = "0.3", features = ["serde-types"] }
futures = "0.3"
parking_lot = "0.11"
Expand Down