diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5477a4829..2661dd42eff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ Description of the upcoming release here. - [#1408](https://github.com/FuelLabs/fuel-core/pull/1408): Update gas benchmarks for storage opcodes to use a pre-populated database to get more accurate worst-case costs. #### Breaking +- [#1472](https://github.com/FuelLabs/fuel-core/pull/1472): Upgraded `fuel-vm` to `v0.42.0`. It introduces transaction policies that changes layout of the transaction. FOr more information check the [v0.42.0](https://github.com/FuelLabs/fuel-vm/pull/635) release. - [#1470](https://github.com/FuelLabs/fuel-core/pull/1470): Divide `DependentCost` into "light" and "heavy" operations. - [#1464](https://github.com/FuelLabs/fuel-core/pull/1464): Avoid possible truncation of higher bits. It may invalidate the code that truncated higher bits causing different behavior on 32-bit vs. 64-bit systems. The change affects some endpoints that now require lesser integers. - [#1432](https://github.com/FuelLabs/fuel-core/pull/1432): All subscriptions and requests have a TTL now. So each subscription lifecycle is limited in time. If the subscription is closed because of TTL, it means that you subscribed after your transaction had been dropped by the network. diff --git a/Cargo.lock b/Cargo.lock index 6160d7bac39..94bd9cbdc19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -632,6 +632,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", + "serde", ] [[package]] @@ -732,6 +733,9 @@ name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +dependencies = [ + "serde", +] [[package]] name = "bitvec" @@ -1356,9 +1360,9 @@ dependencies = [ [[package]] name = "crc-catalog" -version = "2.4.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" [[package]] name = "crc32fast" @@ -1621,9 +1625,9 @@ dependencies = [ [[package]] name = "curve25519-dalek-derive" -version = "0.1.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", @@ -2719,11 +2723,11 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad6cf3a1d10eb176d845d92bc6c6e2b3089c641c675b38aa537a5a707b391489" +checksum = "3f6c74190f51c347e8df9254c11828082dd143870271c2c490dc498efc306699" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "fuel-types", "serde", "strum 0.24.1", @@ -2801,6 +2805,8 @@ dependencies = [ "fuel-core-types", "futures", "p256 0.13.2", + "primitive-types", + "quanta", "rand 0.8.5", "serde", "serde_json", @@ -3236,9 +3242,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c1a032a03b1bf57bc5c3bd281cd67237f96431e77820fb0aba4c190c5412f4" +checksum = "ed59e6b5d69ab5cacda0eb29d34920e1709567271cf2c40d62cb1ad920c44c00" dependencies = [ "coins-bip32", "coins-bip39", @@ -3257,9 +3263,9 @@ dependencies = [ [[package]] name = "fuel-derive" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce3a426f67fb1be14c3118e1d44e549f109924ae55fa8827a54fb1f106c6ade4" +checksum = "27a9c356fe5489b62f7dade3c07c93dacd52d86bd236f8e9b8c359a936def4ae" dependencies = [ "proc-macro2", "quote", @@ -3269,9 +3275,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c231a584c82b0e456db5b91d051b4d9d755f6b17e90192f88884ab5befde9178" +checksum = "ef8c8e4fe5d8f6fab234ccea69ef893df502b9a01af2d53e7a70e35d3ffa035a" dependencies = [ "derive_more", "digest 0.10.7", @@ -3284,16 +3290,17 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12971117f8b2f048a5906ee59299580d5885ba68f184a53a3f6e76da42ce4607" +checksum = "5da0820260094843088c8612590ec052ceeef64b51ab96883f7678ce72552cb4" [[package]] name = "fuel-tx" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c37a0625a4f215fe04af9ffb8b4e4cc9e141a8e16cbade41ecc48881f2026bdd" +checksum = "44b16c51f3d78c71f864939d31798a512ae781d45358a54fc051cba33f125296" dependencies = [ + "bitflags 2.4.1", "derivative", "derive_more", "fuel-asm", @@ -3302,7 +3309,6 @@ dependencies = [ "fuel-types", "hashbrown 0.14.2", "itertools 0.10.5", - "num-integer", "rand 0.8.5", "serde", "serde_json", @@ -3312,9 +3318,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a798d25d589bceccd9714146a827227bb2d54d88fa5109a9c46b0e7381a253a" +checksum = "e712ef330eed942b456691919f7a62e23563377fd2d59d6e04d54162863ba071" dependencies = [ "fuel-derive", "hex", @@ -3324,13 +3330,14 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.41.0" +version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db140c559a9cb3e86067e2752dfd02381a6860cd8f0881dcf015df950e521aca" +checksum = "98a12f59ae11283c656894d3092f3d8e47d1f8a91a17de35a6a977d16084543b" dependencies = [ "anyhow", "async-trait", - "bitflags 1.3.2", + "backtrace", + "bitflags 2.4.1", "derivative", "derive_more", "ethnum", @@ -4054,9 +4061,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -4193,9 +4200,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -4820,28 +4827,6 @@ dependencies = [ "yamux", ] -[[package]] -name = "libredox" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" -dependencies = [ - "bitflags 2.4.1", - "libc", - "redox_syscall 0.4.1", -] - -[[package]] -name = "libredox" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607" -dependencies = [ - "bitflags 2.4.1", - "libc", - "redox_syscall 0.4.1", -] - [[package]] name = "librocksdb-sys" version = "0.11.0+8.1.1" @@ -4990,6 +4975,15 @@ dependencies = [ "libc", ] +[[package]] +name = "mach2" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0d1830bcd151a6fc4aea1369af235b36c1528fe976b8ff678683c9995eade8" +dependencies = [ + "libc", +] + [[package]] name = "match_cfg" version = "0.1.0" @@ -5773,7 +5767,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.1.0", + "indexmap 2.0.2", ] [[package]] @@ -5903,9 +5897,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "platforms" -version = "3.2.0" +version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" [[package]] name = "plotters" @@ -6100,9 +6094,9 @@ dependencies = [ [[package]] name = "primeorder" -version = "0.13.3" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7dbe9ed3b56368bd99483eb32fe9c17fdd3730aebadc906918ce78d54c7eeb4" +checksum = "3c2fcef82c0ec6eefcc179b978446c399b3cdf73c392c35604e399eee6df1ee3" dependencies = [ "elliptic-curve 0.13.6", ] @@ -6352,6 +6346,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "quanta" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "577c55a090a94ed7da0e6580cc38a553558e2d736398b5d8ebf81bc9880f8acd" +dependencies = [ + "crossbeam-utils", + "libc", + "mach2", + "once_cell", + "raw-cpuid", + "wasi 0.11.0+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -6504,6 +6514,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "raw-cpuid" +version = "11.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d86a7c4638d42c44551f4791a20e687dbb4c3de1f33c43dd71e355cd429def1" +dependencies = [ + "bitflags 2.4.1", +] + [[package]] name = "rayon" version = "1.8.0" @@ -6569,18 +6588,21 @@ dependencies = [ [[package]] name = "redox_termios" -version = "0.1.3" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall 0.2.16", +] [[package]] name = "redox_users" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ "getrandom 0.2.10", - "libredox 0.0.1", + "redox_syscall 0.2.16", "thiserror", ] @@ -7275,9 +7297,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -7333,7 +7355,7 @@ version = "0.9.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -7738,9 +7760,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "svm-rs" -version = "0.3.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0cc95be7cc2c384a2f57cac56548d2178650905ebe5725bc8970ccc25529060" +checksum = "597e3a746727984cb7ea2487b6a40726cad0dbe86628e7d429aa6b8c4c153db4" dependencies = [ "dirs 5.0.1", "fs2", @@ -7902,13 +7924,13 @@ dependencies = [ [[package]] name = "termion" -version = "2.0.3" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4648c7def6f2043b2568617b9f9b75eae88ca185dbc1f1fda30e95a85d49d7d" +checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" dependencies = [ "libc", - "libredox 0.0.2", "numtoa", + "redox_syscall 0.2.16", "redox_termios", ] @@ -8246,7 +8268,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "serde", "serde_spanned", "toml_datetime", @@ -8259,7 +8281,7 @@ version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "toml_datetime", "winnow", ] @@ -8741,9 +8763,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -8751,9 +8773,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", @@ -8766,9 +8788,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ "cfg-if", "js-sys", @@ -8778,9 +8800,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -8788,9 +8810,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", @@ -8801,9 +8823,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasm-timer" @@ -8822,9 +8844,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" dependencies = [ "js-sys", "wasm-bindgen", @@ -9275,9 +9297,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] @@ -9428,18 +9450,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.25" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd369a67c0edfef15010f980c3cbe45d7f651deac2cd67ce097cd801de16557" +checksum = "ede7d7c7970ca2215b8c1ccf4d4f354c4733201dfaaba72d44ae5b37472e4901" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.25" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f140bda219a26ccc0cdb03dba58af72590c53b22642577d88a927bc5c87d6b" +checksum = "4b27b1bb92570f989aac0ab7e9cbfbacdd65973f7ee920d9f0e71ebac878fd0b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 35c4cb4484b..b795c800334 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" } fuel-core-xtask = { version = "0.0.0", path = "./xtask" } # Fuel dependencies -fuel-vm-private = { version = "0.41.0", package = "fuel-vm", default-features = false } +fuel-vm-private = { version = "0.42.0", package = "fuel-vm", default-features = false } # Common dependencies anyhow = "1.0" @@ -86,6 +86,7 @@ cynic = { version = "2.2.1", features = ["http-reqwest"] } clap = "4.1" derive_more = { version = "0.99" } hyper = { version = "0.14.26" } +primitive-types = "0.12" rand = "0.8" parking_lot = "0.12" tokio = { version = "1.27", default-features = false } diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 21bbf31380f..0a8aa55e8a8 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -20,6 +20,8 @@ fuel-core-sync = { path = "./../crates/services/sync", features = ["benchmarking fuel-core-types = { path = "./../crates/types", features = ["test-helpers"] } futures = "0.3" p256 = { version = "0.13", default-features = false, features = ["digest", "ecdsa"] } +primitive-types = { workspace = true } +quanta = "0.12" rand = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } diff --git a/benches/benches/block_target_gas.rs b/benches/benches/block_target_gas.rs index 22fac802426..85266b69be8 100644 --- a/benches/benches/block_target_gas.rs +++ b/benches/benches/block_target_gas.rs @@ -97,7 +97,7 @@ fn run( script.clone().into_iter().collect(), script_data.clone(), ) - .gas_limit(TARGET_BLOCK_GAS_LIMIT - BASE) + .script_gas_limit(TARGET_BLOCK_GAS_LIMIT - BASE) .gas_price(1) .add_unsigned_coin_input( SecretKey::random(&mut rng), diff --git a/benches/benches/transaction_throughput.rs b/benches/benches/transaction_throughput.rs index 64313ac20af..820e8fc3972 100644 --- a/benches/benches/transaction_throughput.rs +++ b/benches/benches/transaction_throughput.rs @@ -156,7 +156,7 @@ where fn signed_transfers(c: &mut Criterion) { let generator = |rng: &mut StdRng| { TransactionBuilder::script(vec![], vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .gas_price(1) .add_unsigned_coin_input( SecretKey::random(rng), @@ -187,7 +187,7 @@ fn predicate_transfers(c: &mut Criterion) { let owner = Input::predicate_owner(&predicate); let mut tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .gas_price(1) .add_input(Input::coin_predicate( rng.gen(), @@ -256,7 +256,7 @@ fn predicate_transfers_eck1(c: &mut Criterion) { .collect(); let mut tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .gas_price(1) .add_input(Input::coin_predicate( rng.gen(), diff --git a/benches/benches/vm.rs b/benches/benches/vm.rs index 89732406b7c..9d1217e02fd 100644 --- a/benches/benches/vm.rs +++ b/benches/benches/vm.rs @@ -32,54 +32,33 @@ where instruction, diff, } = &mut i; - let checkpoint = vm - .as_mut() - .database_mut() - .checkpoint() - .expect("Should be able to create a checkpoint"); - let original_db = core::mem::replace(vm.as_mut().database_mut(), checkpoint); - let final_time; - loop { - // Measure the total time to revert the VM to the initial state. - // It should always do the same things regardless of the number of - // iterations because we use a `diff` from the `VmBenchPrepared` initialization. - let start = std::time::Instant::now(); - for _ in 0..iters { - vm.reset_vm_state(diff); - } - let time_to_reset = start.elapsed(); + let clock = quanta::Clock::new(); - let start = std::time::Instant::now(); - for _ in 0..iters { - match instruction { - Instruction::CALL(call) => { - let (ra, rb, rc, rd) = call.unpack(); - vm.prepare_call(ra, rb, rc, rd).unwrap(); - } - _ => { - black_box(vm.instruction(*instruction).unwrap()); - } - } - vm.reset_vm_state(diff); - } - let only_instruction = start.elapsed().checked_sub(time_to_reset); + let mut total = core::time::Duration::ZERO; + for _ in 0..iters { + let original_db = vm.as_mut().database_mut().clone(); + let database_tx = original_db.transaction().as_ref().clone(); + *vm.as_mut().database_mut() = database_tx; - // It may overflow when the benchmarks run in an unstable environment. - // If the hardware is busy during the measuring time to reset the VM, - // it will produce `time_to_reset` more than the actual time - // to run the instruction and reset the VM. - if let Some(result) = only_instruction { - final_time = result; - break - } else { - println!("The environment is unstable. Rerunning the benchmark."); + let start = black_box(clock.raw()); + match instruction { + Instruction::CALL(call) => { + let (ra, rb, rc, rd) = call.unpack(); + black_box(vm.prepare_call(ra, rb, rc, rd)).unwrap(); + } + _ => { + black_box(vm.instruction(*instruction).unwrap()); + } } + black_box(&vm); + let end = black_box(clock.raw()); + total += clock.delta(start, end); + vm.reset_vm_state(diff); + // restore original db + *vm.as_mut().database_mut() = original_db; } - - // restore original db - *vm.as_mut().database_mut() = original_db; - final_time + total }) }); } diff --git a/benches/benches/vm_set/alu.rs b/benches/benches/vm_set/alu.rs index 0f9bfefc3d2..2cb5d63fe92 100644 --- a/benches/benches/vm_set/alu.rs +++ b/benches/benches/vm_set/alu.rs @@ -117,9 +117,9 @@ pub fn run(c: &mut Criterion) { &mut c.benchmark_group("mldv"), "mldv", VmBench::new(op::mldv(0x10, 0x11, 0x12, 0x13)).with_prepare_script(vec![ - op::movi(0x11, 1234567), + op::movi(0x11, 123456), op::not(0x12, RegId::ZERO), - op::movi(0x13, 3456789), + op::movi(0x13, 234567), ]), ); diff --git a/benches/benches/vm_set/blockchain.rs b/benches/benches/vm_set/blockchain.rs index a555d80b6d7..3b0cb5f2f4e 100644 --- a/benches/benches/vm_set/blockchain.rs +++ b/benches/benches/vm_set/blockchain.rs @@ -39,7 +39,7 @@ use rand::{ }; pub struct BenchDb { - db: RocksDb, + db: Database, /// Used for RAII cleanup. Contents of this directory are deleted on drop. _tmp_dir: ShallowTempDir, } @@ -51,14 +51,17 @@ impl BenchDb { let tmp_dir = ShallowTempDir::new(); let db = Arc::new(RocksDb::default_open(tmp_dir.path(), None).unwrap()); + let mut storage_key = primitive_types::U256::zero(); + let mut key_bytes = Bytes32::zeroed(); - let mut database = Database::new(db.clone()); + let mut database = Database::new(db); database.init_contract_state( contract, - (0..Self::STATE_SIZE).map(|k| { - let mut key = Bytes32::zeroed(); - key.as_mut()[..8].copy_from_slice(&k.to_be_bytes()); - (key, key) + (0..Self::STATE_SIZE).map(|_| { + use fuel_core::database::vm_database::IncreaseStorageKey; + storage_key.to_big_endian(key_bytes.as_mut()); + storage_key.increase().unwrap(); + (key_bytes, key_bytes) }), )?; database.init_contract_balances( @@ -76,20 +79,17 @@ impl BenchDb { (asset, key + 1_000) }), )?; + database.clone().flush()?; - drop(database); // Drops one reference to the db wrapper, but we still hold the last one Ok(Self { _tmp_dir: tmp_dir, - db: Arc::into_inner(db).expect("All other references must be dropped"), + db: database, }) } - /// Create a new separate database instance using a rocksdb checkpoint - fn checkpoint(&self) -> VmDatabase { - use fuel_core::state::TransactableStorage; - let database = TransactableStorage::checkpoint(&self.db) - .expect("Unable to create checkpoint"); - VmDatabase::default_from_database(database) + /// Creates a `VmDatabase` instance. + fn to_vm_database(&self) -> VmDatabase { + VmDatabase::default_from_database(self.db.clone()) } } @@ -108,7 +108,7 @@ pub fn run(c: &mut Criterion) { linear.extend(l); let asset: AssetId = rng.gen(); - let contract: ContractId = rng.gen(); + let contract: ContractId = VmBench::CONTRACT; let db = BenchDb::new(&contract).expect("Unable to fill contract storage"); @@ -124,28 +124,46 @@ pub fn run(c: &mut Criterion) { .with_dummy_contract(contract), ); - run_group_ref( - &mut c.benchmark_group("sww"), - "sww", - VmBench::contract_using_db( + { + let mut start_key = Bytes32::zeroed(); + // The checkpoint was initialized with entries starting `0..Self::STATE_SIZE`. + // We want to write new entry to the database, so the starting key is far. + start_key.as_mut()[0] = 255; + let data = start_key.iter().copied().collect::>(); + + let post_call = vec![ + op::gtf_args(0x10, 0x00, GTFArgs::ScriptData), + op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, AssetId::LEN.try_into().unwrap()), + ]; + let mut bench = VmBench::contract_using_db( rng, - db.checkpoint(), - op::sww(RegId::ZERO, 0x29, RegId::ONE), + db.to_vm_database(), + op::sww(0x11, 0x29, RegId::ONE), ) - .expect("failed to prepare contract"), - ); + .expect("failed to prepare contract") + .with_post_call(post_call); + bench.data.extend(data); + + run_group_ref(&mut c.benchmark_group("sww"), "sww", bench); + } { - let mut input = - VmBench::contract_using_db(rng, db.checkpoint(), op::srw(0x13, 0x14, 0x15)) - .expect("failed to prepare contract"); - input.prepare_script.extend(vec![op::movi(0x15, 2000)]); + let input = VmBench::contract_using_db( + rng, + db.to_vm_database(), + op::srw(0x13, 0x14, 0x10), + ) + .expect("failed to prepare contract"); run_group_ref(&mut c.benchmark_group("srw"), "srw", input); } let mut scwq = c.benchmark_group("scwq"); for i in linear_short.clone() { + // We want to clear entries from the checkpoint, so the starting key is zero. let start_key = Bytes32::zeroed(); let data = start_key.iter().copied().collect::>(); @@ -154,12 +172,16 @@ pub fn run(c: &mut Criterion) { op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, AssetId::LEN.try_into().unwrap()), op::movi(0x12, i as u32), ]; - let mut bench = - VmBench::contract_using_db(rng, db.checkpoint(), op::scwq(0x11, 0x29, 0x12)) - .expect("failed to prepare contract") - .with_post_call(post_call); + let mut bench = VmBench::contract_using_db( + rng, + db.to_vm_database(), + op::scwq(0x11, 0x29, 0x12), + ) + .expect("failed to prepare contract") + .with_post_call(post_call); bench.data.extend(data); scwq.throughput(Throughput::Bytes(i)); @@ -172,7 +194,10 @@ pub fn run(c: &mut Criterion) { let mut swwq = c.benchmark_group("swwq"); for i in linear_short.clone() { - let start_key = Bytes32::zeroed(); + let mut start_key = Bytes32::zeroed(); + // The checkpoint was initialized with entries starting `0..Self::STATE_SIZE`. + // We want to write new entries to the database, so the starting key is far. + start_key.as_mut()[0] = 255; let data = start_key.iter().copied().collect::>(); let post_call = vec![ @@ -180,12 +205,13 @@ pub fn run(c: &mut Criterion) { op::addi(0x11, 0x10, ContractId::LEN.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), op::addi(0x11, 0x11, WORD_SIZE.try_into().unwrap()), + op::addi(0x11, 0x11, AssetId::LEN.try_into().unwrap()), op::movi(0x12, i as u32), ]; let mut bench = VmBench::contract_using_db( rng, - db.checkpoint(), - op::swwq(0x10, 0x11, 0x20, 0x12), + db.to_vm_database(), + op::swwq(0x11, 0x20, RegId::ZERO, 0x12), ) .expect("failed to prepare contract") .with_post_call(post_call); @@ -230,7 +256,7 @@ pub fn run(c: &mut Criterion) { &mut call, format!("{i}"), VmBench::new(op::call(0x10, RegId::ZERO, 0x11, 0x12)) - .with_db(db.checkpoint()) + .with_db(db.to_vm_database()) .with_contract_code(code) .with_data(data) .with_prepare_script(prepare_script), @@ -376,7 +402,7 @@ pub fn run(c: &mut Criterion) { "mint", VmBench::contract_using_db( rng, - db.checkpoint(), + db.to_vm_database(), op::mint(RegId::ONE, RegId::ZERO), ) .expect("failed to prepare contract"), @@ -385,9 +411,13 @@ pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("burn"), "burn", - VmBench::contract_using_db(rng, db.checkpoint(), op::burn(RegId::ONE, RegId::HP)) - .expect("failed to prepare contract") - .prepend_prepare_script(vec![op::movi(0x10, 32), op::aloc(0x10)]), + VmBench::contract_using_db( + rng, + db.to_vm_database(), + op::burn(RegId::ONE, RegId::HP), + ) + .expect("failed to prepare contract") + .prepend_prepare_script(vec![op::movi(0x10, 32), op::aloc(0x10)]), ); run_group_ref( @@ -401,9 +431,12 @@ pub fn run(c: &mut Criterion) { ); { - let mut input = - VmBench::contract_using_db(rng, db.checkpoint(), op::tr(0x15, 0x14, 0x15)) - .expect("failed to prepare contract"); + let mut input = VmBench::contract_using_db( + rng, + db.to_vm_database(), + op::tr(0x15, 0x14, 0x15), + ) + .expect("failed to prepare contract"); input .prepare_script .extend(vec![op::movi(0x15, 2000), op::movi(0x14, 100)]); @@ -413,7 +446,7 @@ pub fn run(c: &mut Criterion) { { let mut input = VmBench::contract_using_db( rng, - db.checkpoint(), + db.to_vm_database(), op::tro(RegId::ZERO, 0x15, 0x14, RegId::HP), ) .expect("failed to prepare contract"); @@ -484,7 +517,7 @@ pub fn run(c: &mut Criterion) { for i in linear.clone() { let mut input = VmBench::contract_using_db( rng, - db.checkpoint(), + db.to_vm_database(), op::smo(0x15, 0x16, 0x17, 0x18), ) .expect("failed to prepare contract"); @@ -522,43 +555,34 @@ pub fn run(c: &mut Criterion) { smo.finish(); - let mut srwq = c.benchmark_group("srwq"); - - for i in linear_short.clone() { - let start_key = Bytes32::zeroed(); - let data = start_key.iter().copied().collect::>(); + { + let mut srwq = c.benchmark_group("srwq"); + + for i in linear_short.clone() { + // We want to iterate over initialized entries starting key 0. + let start_key = Bytes32::zeroed(); + let data = start_key.iter().copied().collect::>(); + + let post_call = vec![ + op::movi(0x16, i as u32), + op::movi(0x17, 2000), + op::move_(0x15, 0x16), + op::muli(0x15, 0x15, 32), + op::addi(0x15, 0x15, 1), + op::aloc(0x15), + op::move_(0x14, RegId::HP), + ]; + let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16)) + .expect("failed to prepare contract") + .with_post_call(post_call); + bench.data.extend(data); + srwq.throughput(Throughput::Bytes(i)); + run_group_ref(&mut srwq, format!("{i}"), bench); + } - let post_call = vec![ - op::movi(0x16, i as u32), - op::movi(0x17, 2000), - op::move_(0x15, 0x16), - op::muli(0x15, 0x15, 32), - op::addi(0x15, 0x15, 1), - op::aloc(0x15), - op::move_(0x14, RegId::HP), - ]; - let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16)) - .expect("failed to prepare contract") - .with_post_call(post_call) - .with_prepare_db(move |mut db| { - let slots = (0u64..i).map(|key_number| { - let mut key = Bytes32::zeroed(); - key.as_mut()[..8].copy_from_slice(&key_number.to_be_bytes()); - (key, key) - }); - db.database_mut() - .init_contract_state(&contract, slots) - .unwrap(); - - Ok(db) - }); - bench.data.extend(data); - srwq.throughput(Throughput::Bytes(i)); - run_group_ref(&mut srwq, format!("{i}"), bench); + srwq.finish(); } - srwq.finish(); - run_group_ref( &mut c.benchmark_group("time"), "time", diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 38b7c9c0382..7f694daf97b 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -92,7 +92,6 @@ pub struct VmBench { pub prepare_call: Option, pub dummy_contract: Option, pub contract_code: Option, - pub prepare_db: Option anyhow::Result>>, } #[derive(Debug, Clone)] @@ -131,7 +130,6 @@ impl VmBench { prepare_call: None, dummy_contract: None, contract_code: None, - prepare_db: None, } } @@ -220,7 +218,7 @@ impl VmBench { self } - pub fn with_gas_limit(mut self, gas_limit: Word) -> Self { + pub fn with_script_gas_limit(mut self, gas_limit: Word) -> Self { self.gas_limit = gas_limit; self } @@ -289,14 +287,6 @@ impl VmBench { self } - pub fn with_prepare_db(mut self, prepare_db: F) -> Self - where - F: FnMut(VmDatabase) -> anyhow::Result + 'static, - { - self.prepare_db.replace(Box::new(prepare_db)); - self - } - pub fn prepare(self) -> anyhow::Result { self.try_into() } @@ -323,7 +313,6 @@ impl TryFrom for VmBenchPrepared { prepare_call, dummy_contract, contract_code, - prepare_db, } = case; let mut db = db.unwrap_or_else(new_db); @@ -394,11 +383,6 @@ impl TryFrom for VmBenchPrepared { db.deploy_contract_with_id(&salt, &slots, &contract, &root, &id)?; } - let db = match prepare_db { - Some(mut prepare_db) => prepare_db(db)?, - None => db, - }; - inputs.into_iter().for_each(|i| { tx.add_input(i); }); @@ -414,18 +398,18 @@ impl TryFrom for VmBenchPrepared { // add at least one coin input tx.add_random_fee_input(); - let mut p = params.clone(); - p.fee_params.gas_per_byte = 0; - p.gas_costs = GasCosts::free(); + let mut params = params; + params.fee_params.gas_per_byte = 0; + params.gas_costs = GasCosts::free(); let mut tx = tx .gas_price(gas_price) - .gas_limit(gas_limit) + .script_gas_limit(gas_limit) .maturity(maturity) - .with_params(p.clone()) + .with_params(params.clone()) .finalize(); - tx.estimate_predicates(&CheckPredicateParams::from(&p)) + tx.estimate_predicates(&CheckPredicateParams::from(¶ms)) .unwrap(); - let tx = tx.into_checked(height, &p).unwrap(); + let tx = tx.into_checked(height, ¶ms).unwrap(); let mut txtor = Transactor::new(db, InterpreterParams::from(¶ms)); @@ -444,6 +428,9 @@ impl TryFrom for VmBenchPrepared { } let start_vm = vm.clone(); + let original_db = vm.as_mut().database_mut().clone(); + let database_tx = original_db.transaction().as_ref().clone(); + *vm.as_mut().database_mut() = database_tx; let mut vm = vm.add_recording(); match instruction { Instruction::CALL(call) => { @@ -460,6 +447,7 @@ impl TryFrom for VmBenchPrepared { diff += storage_diff; let diff: diff::Diff = diff.into(); vm.reset_vm_state(&diff); + *vm.as_mut().database_mut() = original_db; Ok(Self { vm, diff --git a/bin/e2e-test-client/src/test_context.rs b/bin/e2e-test-client/src/test_context.rs index b5f555ad6e5..da465fdf70f 100644 --- a/bin/e2e-test-client/src/test_context.rs +++ b/bin/e2e-test-client/src/test_context.rs @@ -157,7 +157,7 @@ impl Wallet { // build transaction let mut tx = TransactionBuilder::script(Default::default(), Default::default()); tx.gas_price(1); - tx.gas_limit(BASE_AMOUNT); + tx.script_gas_limit(BASE_AMOUNT); for coin in coins { if let CoinType::Coin(coin) = coin { @@ -235,7 +235,6 @@ impl Wallet { let state_root = Contract::initial_state_root(slots.iter()); let mut tx = TransactionBuilder::create(bytes.into(), salt, slots); tx.gas_price(1); - tx.gas_limit(BASE_AMOUNT); for coin in coins { if let CoinType::Coin(coin) = coin { diff --git a/bin/e2e-test-client/src/tests/script.rs b/bin/e2e-test-client/src/tests/script.rs index 128c0761686..d2c257e3a00 100644 --- a/bin/e2e-test-client/src/tests/script.rs +++ b/bin/e2e-test-client/src/tests/script.rs @@ -5,6 +5,10 @@ use crate::test_context::{ use fuel_core_chain_config::ContractConfig; use fuel_core_types::{ fuel_tx::{ + field::{ + GasPrice, + ScriptGasLimit, + }, Receipt, ScriptExecutionResult, Transaction, @@ -102,9 +106,14 @@ pub async fn non_specific_transaction(ctx: &TestContext) -> Result<(), Failed> { let dry_run = include_str!("test_data/non_specific_tx.raw"); let bytes = dry_run.replace("0x", ""); let hex_tx = hex::decode(bytes).expect("Expected hex string"); - let dry_run: Transaction = Transaction::from_bytes(hex_tx.as_ref()) + let mut dry_run: Transaction = Transaction::from_bytes(hex_tx.as_ref()) .expect("Should be able do decode the Transaction"); + if let Some(script) = dry_run.as_script_mut() { + *script.script_gas_limit_mut() = 100000; + script.set_gas_price(0); + } + _dry_runs(ctx, &dry_run, 1000, DryRunResult::MayFail).await } diff --git a/bin/e2e-test-client/src/tests/test_data/large_state/tx.json b/bin/e2e-test-client/src/tests/test_data/large_state/tx.json index 40bdaa7dd4c..5facfcc8cfa 100644 --- a/bin/e2e-test-client/src/tests/test_data/large_state/tx.json +++ b/bin/e2e-test-client/src/tests/test_data/large_state/tx.json @@ -1,8 +1,6 @@ { "Script": { - "gas_price": 0, - "gas_limit": 100000000, - "maturity": 0, + "script_gas_limit": 1000000, "script": [ 144, 0, @@ -4100,6 +4098,10 @@ 74, 162 ], + "policies": { + "bits": "GasPrice", + "values": [0, 0, 0, 0] + }, "inputs": [ { "Contract": { diff --git a/bin/e2e-test-client/src/tests/test_data/non_specific_tx.raw b/bin/e2e-test-client/src/tests/test_data/non_specific_tx.raw index 6c625a4ca9f..08002701b0c 100644 --- a/bin/e2e-test-client/src/tests/test_data/non_specific_tx.raw +++ b/bin/e2e-test-client/src/tests/test_data/non_specific_tx.raw @@ -1 +1 @@ -0x000000000000000000000000000000010000000005f5e1000000000000000000000000000000000400000000000000000000000000000001000000000000000200000000000000010000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000008b5a47933cbb7ddbc0392a45a124a2a01f17c657d34d4951324003a2f9aff24a000000000000000157cd0f26d30e6e0361742800f0cb39b87d2bd58e052c4389d7e507e39e504a01000000001d34a76e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000eeb709945b9058c3d50f3922bd1b49f92ced2950a9ecaf810aa7829295550cd200000000000027100000000000000000000000000000000000000000000000000000000000000000000000000000000357cd0f26d30e6e0361742800f0cb39b87d2bd58e052c4389d7e507e39e504a01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file +0x00000000000000000000000005f5e1000000000000000004000000000000000000000000000000000000000000000001000000000000000200000000000000010000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000008b5a47933cbb7ddbc0392a45a124a2a01f17c657d34d4951324003a2f9aff24a000000000000000157cd0f26d30e6e0361742800f0cb39b87d2bd58e052c4389d7e507e39e504a01000000001d34a76e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000186a0000000000000000000000000000000000000000000000000000000000000000000eeb709945b9058c3d50f3922bd1b49f92ced2950a9ecaf810aa7829295550cd200000000000027100000000000000000000000000000000000000000000000000000000000000000000000000000000357cd0f26d30e6e0361742800f0cb39b87d2bd58e052c4389d7e507e39e504a01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \ No newline at end of file diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap index bfd8f2681af..cfaa28af3fc 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap @@ -238,7 +238,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap index d276df7aaa3..7640278e013 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap @@ -250,7 +250,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap index 810ef7d7825..d6b84b6294b 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap @@ -250,7 +250,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap index aec92bb0857..062d8932325 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap @@ -246,7 +246,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap index 3315488e557..5bc1d94df28 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap @@ -246,7 +246,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap index 3813e39fc29..6b040e9f5d1 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap @@ -264,7 +264,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap index 565c10a791f..675fef4cfbc 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap @@ -249,7 +249,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap index 0d6cacdfaf4..8395f288f3e 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap @@ -244,7 +244,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap index 6f258d46db8..f28cd82ecd4 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap @@ -247,7 +247,9 @@ expression: json "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 1, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index 71e09b1e285..5f4dbd97485 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -386,6 +386,8 @@ type GasCosts { swwq: DependentCost! contractRoot: DependentCost! stateRoot: DependentCost! + vmInitialization: U64! + newStoragePerByte: U64! } type Genesis { @@ -653,6 +655,13 @@ type PoAConsensus { signature: Signature! } +type Policies { + gasPrice: U64 + witnessLimit: U64 + maturity: U32 + maxFee: U64 +} + type PredicateParameters { maxPredicateLength: U64! maxPredicateDataLength: U64! @@ -850,8 +859,9 @@ type Transaction { inputAssetIds: [AssetId!] inputContracts: [Contract!] inputContract: InputContract + policies: Policies gasPrice: U64 - gasLimit: U64 + scriptGasLimit: U64 maturity: U32 mintAmount: U64 mintAssetId: AssetId diff --git a/crates/client/src/client/schema/chain.rs b/crates/client/src/client/schema/chain.rs index 96095106684..8272ec3216c 100644 --- a/crates/client/src/client/schema/chain.rs +++ b/crates/client/src/client/schema/chain.rs @@ -244,6 +244,8 @@ include_from_impls_and_cynic! { // Non-opcodes prices pub contract_root: DependentCost, pub state_root: DependentCost, + pub vm_initialization: U64, + pub new_storage_per_byte: U64, } } diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap index aecc94e5e19..32ab61e4597 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap @@ -364,6 +364,8 @@ query { gasPerUnit } } + vmInitialization + newStoragePerByte } } } diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap index 857c23770ec..fd1ae1375b3 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap @@ -4,8 +4,7 @@ expression: operation.query --- query($id: TransactionId!) { transaction(id: $id) { - gasLimit - gasPrice + scriptGasLimit id txPointer inputAssetIds @@ -93,7 +92,6 @@ query($id: TransactionId!) { balanceRoot stateRoot } - maturity mintAmount mintAssetId receiptsRoot @@ -164,6 +162,12 @@ query($id: TransactionId!) { } script scriptData + policies { + gasPrice + maturity + witnessLimit + maxFee + } salt storageSlots bytecodeWitnessIndex diff --git a/crates/client/src/client/schema/tx/transparent_tx.rs b/crates/client/src/client/schema/tx/transparent_tx.rs index cda250c7385..d6fe6a3b163 100644 --- a/crates/client/src/client/schema/tx/transparent_tx.rs +++ b/crates/client/src/client/schema/tx/transparent_tx.rs @@ -31,6 +31,7 @@ use fuel_core_types::{ field::ReceiptsRoot, input, output, + policies::PolicyType, StorageSlot, }, fuel_types, @@ -80,10 +81,8 @@ pub struct TransactionEdge { #[derive(cynic::QueryFragment, Debug)] #[cynic(schema_path = "./assets/schema.sdl")] pub struct Transaction { - /// The field of the `Transaction` type. - pub gas_limit: Option, - /// The field of the `Transaction` type. - pub gas_price: Option, + /// The field of the `Transaction::Script` type. + pub script_gas_limit: Option, /// The field of the `Transaction` type. pub id: TransactionId, /// The field of the `Transaction::Mint`. @@ -121,8 +120,6 @@ pub struct Transaction { pub outputs: Vec, /// The field of the `Transaction::Mint`. pub output_contract: Option, - /// The field of the `Transaction::Script` and `Transaction::Create`. - pub maturity: Option, /// The field of the `Transaction::Mint`. pub mint_amount: Option, /// The field of the `Transaction::Mint`. @@ -139,6 +136,8 @@ pub struct Transaction { pub script: Option, /// The field of the `Transaction::Script`. pub script_data: Option, + /// The field of the `Transaction::Script` and `Transaction::Create`. + pub policies: Option, /// The field of the `Transaction::Create`. pub salt: Option, /// The field of the `Transaction::Create`. @@ -158,19 +157,11 @@ impl TryFrom for fuel_tx::Transaction { fn try_from(tx: Transaction) -> Result { let tx = if tx.is_script { let mut script = fuel_tx::Transaction::script( - tx.gas_price - .ok_or_else(|| { - ConversionError::MissingField("gas_price".to_string()) - })? - .into(), - tx.gas_limit + tx.script_gas_limit .ok_or_else(|| { - ConversionError::MissingField("gas_limit".to_string()) + ConversionError::MissingField("script_gas_limit".to_string()) })? .into(), - tx.maturity - .ok_or_else(|| ConversionError::MissingField("maturity".to_string()))? - .into(), tx.script .ok_or_else(|| ConversionError::MissingField("script".to_string()))? .into(), @@ -179,6 +170,9 @@ impl TryFrom for fuel_tx::Transaction { ConversionError::MissingField("script_data".to_string()) })? .into(), + tx.policies + .ok_or_else(|| ConversionError::MissingField("policies".to_string()))? + .into(), tx.inputs .ok_or_else(|| ConversionError::MissingField("inputs".to_string()))? .into_iter() @@ -205,19 +199,6 @@ impl TryFrom for fuel_tx::Transaction { script.into() } else if tx.is_create { let create = fuel_tx::Transaction::create( - tx.gas_price - .ok_or_else(|| { - ConversionError::MissingField("gas_price".to_string()) - })? - .into(), - tx.gas_limit - .ok_or_else(|| { - ConversionError::MissingField("gas_limit".to_string()) - })? - .into(), - tx.maturity - .ok_or_else(|| ConversionError::MissingField("maturity".to_string()))? - .into(), tx.bytecode_witness_index .ok_or_else(|| { ConversionError::MissingField( @@ -225,6 +206,9 @@ impl TryFrom for fuel_tx::Transaction { ) })? .try_into()?, + tx.policies + .ok_or_else(|| ConversionError::MissingField("policies".to_string()))? + .into(), tx.salt .ok_or_else(|| ConversionError::MissingField("salt".to_string()))? .into(), @@ -541,3 +525,29 @@ impl TryFrom for output::contract::Contract { }) } } + +#[derive(cynic::QueryFragment, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub struct Policies { + pub gas_price: Option, + pub maturity: Option, + pub witness_limit: Option, + pub max_fee: Option, +} + +impl From for fuel_tx::policies::Policies { + fn from(value: Policies) -> Self { + let mut policies = fuel_tx::policies::Policies::new(); + policies.set(PolicyType::GasPrice, value.gas_price.map(Into::into)); + policies.set( + PolicyType::Maturity, + value.maturity.map(|maturity| maturity.0 as u64), + ); + policies.set( + PolicyType::WitnessLimit, + value.witness_limit.map(Into::into), + ); + policies.set(PolicyType::MaxFee, value.max_fee.map(Into::into)); + policies + } +} diff --git a/crates/client/src/client/types/gas_costs.rs b/crates/client/src/client/types/gas_costs.rs index 0fc768f7228..a26e8e72523 100644 --- a/crates/client/src/client/types/gas_costs.rs +++ b/crates/client/src/client/types/gas_costs.rs @@ -143,6 +143,8 @@ include_from_impls! { // Non-opcode prices pub contract_root: DependentCost, pub state_root: DependentCost, + pub vm_initialization: u64, + pub new_storage_per_byte: u64, } } diff --git a/crates/fuel-core/Cargo.toml b/crates/fuel-core/Cargo.toml index 01b7b7de5b3..474f0fa4f4a 100644 --- a/crates/fuel-core/Cargo.toml +++ b/crates/fuel-core/Cargo.toml @@ -43,7 +43,7 @@ hyper = { workspace = true } itertools = { workspace = true } parking_lot = { workspace = true } postcard = { workspace = true, features = ["use-std"] } -primitive-types = "0.12" +primitive-types = { workspace = true } rand = { workspace = true } rocksdb = { version = "0.21", default-features = false, features = [ "lz4", diff --git a/crates/fuel-core/src/database/state.rs b/crates/fuel-core/src/database/state.rs index 295a97c2026..d43864e868f 100644 --- a/crates/fuel-core/src/database/state.rs +++ b/crates/fuel-core/src/database/state.rs @@ -164,6 +164,12 @@ impl Database { where S: Iterator, { + let slots = slots.collect_vec(); + + if slots.is_empty() { + return Ok(()) + } + if self .storage::() .contains_key(contract_id)? @@ -171,8 +177,6 @@ impl Database { return Err(anyhow::anyhow!("The contract state is already initialized").into()) } - let slots = slots.collect_vec(); - // Keys and values should be original without any modifications. // Key is `ContractId` ++ `StorageKey` self.batch_insert( diff --git a/crates/fuel-core/src/database/transaction.rs b/crates/fuel-core/src/database/transaction.rs index 33a13fe42ad..b9c47d954bf 100644 --- a/crates/fuel-core/src/database/transaction.rs +++ b/crates/fuel-core/src/database/transaction.rs @@ -31,7 +31,7 @@ impl AsRef for DatabaseTransaction { impl AsMut for DatabaseTransaction { fn as_mut(&mut self) -> &mut Database { - self.deref_mut() + &mut self.database } } diff --git a/crates/fuel-core/src/database/vm_database.rs b/crates/fuel-core/src/database/vm_database.rs index 33737910e1c..cb461da1edb 100644 --- a/crates/fuel-core/src/database/vm_database.rs +++ b/crates/fuel-core/src/database/vm_database.rs @@ -48,7 +48,7 @@ pub struct VmDatabase { database: Database, } -trait IncreaseStorageKey { +pub trait IncreaseStorageKey { fn increase(&mut self) -> anyhow::Result<()>; } @@ -276,7 +276,7 @@ impl InterpreterStorage for VmDatabase { contract_id: &ContractId, start_key: &Bytes32, values: &[Bytes32], - ) -> Result, Self::DataError> { + ) -> Result { let mut current_key = U256::from_big_endian(start_key.as_ref()); // verify key is in range current_key @@ -286,7 +286,7 @@ impl InterpreterStorage for VmDatabase { })?; let mut key_bytes = Bytes32::zeroed(); - let mut found_unset = false; + let mut found_unset = 0u32; for value in values { current_key.to_big_endian(key_bytes.as_mut()); @@ -295,16 +295,16 @@ impl InterpreterStorage for VmDatabase { .storage::() .insert(&(contract_id, &key_bytes).into(), value)?; - found_unset |= option.is_none(); + if option.is_none() { + found_unset = found_unset + .checked_add(1) + .expect("We've checked it above via `values.len()`"); + } current_key.increase()?; } - if found_unset { - Ok(None) - } else { - Ok(Some(())) - } + Ok(found_unset as usize) } fn merkle_contract_state_remove_range( @@ -515,7 +515,7 @@ mod tests { .collect::>(), ) .map_err(|_| ()) - .map(|v| v.is_some()); + .map(|v| v == 0); // check stored data let results: Vec<_> = (0..insertion_range.len()) diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index 0f75bfa3d7d..294465555b3 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -77,6 +77,7 @@ use fuel_core_types::{ TxPointer, UniqueIdentifier, UtxoId, + ValidityError, }, fuel_types::{ canonical::Serialize, @@ -85,6 +86,7 @@ use fuel_core_types::{ }, fuel_vm::{ checked_transaction::{ + CheckError, CheckPredicateParams, CheckPredicates, Checked, @@ -133,6 +135,7 @@ use fuel_core_types::{ }, input, output, + Chargeable, }, fuel_vm, }; @@ -884,21 +887,20 @@ where ::Metadata: Fee + CheckedMetadata + Clone + Send + Sync, { let tx_id = checked_tx.id(); - let min_fee = checked_tx.metadata().min_fee(); let max_fee = checked_tx.metadata().max_fee(); - checked_tx = checked_tx - .check_predicates(&CheckPredicateParams::from( - &self.config.consensus_parameters, - )) - .map_err(|_| { - ExecutorError::TransactionValidity( - TransactionValidityError::InvalidPredicate(tx_id), - ) - })?; - debug_assert!(checked_tx.checks().contains(Checks::Predicates)); - if options.utxo_validation { + checked_tx = checked_tx + .check_predicates(&CheckPredicateParams::from( + &self.config.consensus_parameters, + )) + .map_err(|_| { + ExecutorError::TransactionValidity( + TransactionValidityError::InvalidPredicate(tx_id), + ) + })?; + debug_assert!(checked_tx.checks().contains(Checks::Predicates)); + // validate utxos exist and maturity is properly set self.verify_input_state( tx_db_transaction.deref(), @@ -961,8 +963,7 @@ where } // update block commitment - let (used_gas, tx_fee) = - self.total_fee_paid(min_fee, max_fee, tx.price(), &receipts)?; + let (used_gas, tx_fee) = self.total_fee_paid(&tx, max_fee, &receipts)?; // Check or set the executed transaction. match execution_kind { @@ -1234,30 +1235,34 @@ where Ok(()) } - fn total_fee_paid( + fn total_fee_paid( &self, - min_fee: u64, - max_fee: u64, - gas_price: u64, + tx: &Tx, + max_fee: Word, receipts: &[Receipt], ) -> ExecutorResult<(Word, Word)> { let mut used_gas = 0; for r in receipts { if let Receipt::ScriptResult { gas_used, .. } = r { used_gas = *gas_used; - let fee = TransactionFee::gas_refund_value( - self.config.consensus_parameters.fee_params(), - used_gas, - gas_price, - ) - .and_then(|refund| max_fee.checked_sub(refund)) - .ok_or(ExecutorError::FeeOverflow)?; - - return Ok((used_gas, fee)) + break; } } + + let fee = tx + .refund_fee( + self.config.consensus_parameters.gas_costs(), + self.config.consensus_parameters.fee_params(), + used_gas, + ) + .ok_or(ExecutorError::FeeOverflow)?; // if there's no script result (i.e. create) then fee == base amount - Ok((used_gas, min_fee)) + Ok(( + used_gas, + max_fee + .checked_sub(fee) + .expect("Refunded fee can't be more than `max_fee`."), + )) } /// Computes all zeroed or variable inputs. @@ -1799,7 +1804,6 @@ mod tests { Outputs, Script as ScriptField, }, - CheckError, ConsensusParameters, Create, Finalizable, @@ -1888,7 +1892,7 @@ mod tests { .collect(); let script = TxBuilder::new(2322) - .gas_limit(fuel_tx::TxParameters::DEFAULT.max_gas_per_tx) + .script_gas_limit(fuel_tx::TxParameters::DEFAULT.max_gas_per_tx >> 1) .start_script(script, script_data) .contract_input(contract_id) .coin_input(asset_id, input_amount) @@ -1907,7 +1911,7 @@ mod tests { let transactions = (1..num_txs + 1) .map(|i| { TxBuilder::new(2322u64) - .gas_limit(10) + .script_gas_limit(10) .coin_input(AssetId::default(), (i as Word) * 100) .coin_output(AssetId::default(), (i as Word) * 50) .change_output(AssetId::default()) @@ -2034,7 +2038,7 @@ mod tests { let limit = 0; let gas_price_factor = 1; let script = TxBuilder::new(1u64) - .gas_limit(limit) + .script_gas_limit(limit) // Set a price for the test .gas_price(price) .coin_input(AssetId::BASE, 10000) @@ -2126,7 +2130,7 @@ mod tests { assert_eq!(amount, expected_fee_amount_1); let script = TxBuilder::new(2u64) - .gas_limit(limit) + .script_gas_limit(limit) // Set a price for the test .gas_price(price) .coin_input(AssetId::BASE, 10000) @@ -2211,7 +2215,7 @@ mod tests { let limit = 0; let gas_price_factor = 1; let script = TxBuilder::new(2322u64) - .gas_limit(limit) + .script_gas_limit(limit) // Set a price for the test .gas_price(price) .coin_input(AssetId::BASE, 10000) @@ -2251,7 +2255,7 @@ mod tests { let limit = 0; let gas_price_factor = 1; let script = TxBuilder::new(2322u64) - .gas_limit(limit) + .script_gas_limit(limit) // Set a price for the test .gas_price(price) .coin_input(AssetId::BASE, 10000) @@ -2329,7 +2333,7 @@ mod tests { expected_in_tx_coinbase: ContractId, ) -> bool { let script = TxBuilder::new(2322u64) - .gas_limit(100000) + .script_gas_limit(100000) // Set a price for the test .gas_price(0) .start_script(vec![ @@ -2494,9 +2498,9 @@ mod tests { .expect_err("Expected error because coinbase if invalid"); assert!(matches!( validation_err, - ExecutorError::InvalidTransaction( - CheckError::TransactionMintIncorrectBlockHeight - ) + ExecutorError::InvalidTransaction(CheckError::Validity( + ValidityError::TransactionMintIncorrectBlockHeight + )) )); } @@ -2522,9 +2526,9 @@ mod tests { .expect_err("Expected error because coinbase if invalid"); assert!(matches!( validation_err, - ExecutorError::InvalidTransaction( - CheckError::TransactionMintNonBaseAsset - ) + ExecutorError::InvalidTransaction(CheckError::Validity( + ValidityError::TransactionMintNonBaseAsset + )) )); } @@ -2558,17 +2562,13 @@ mod tests { fn executor_invalidates_missing_gas_input() { let mut rng = StdRng::seed_from_u64(2322u64); let producer = Executor::test(Default::default(), Default::default()); - let factor = producer - .config - .consensus_parameters - .fee_params() - .gas_price_factor as f64; + let consensus_parameters = &producer.config.consensus_parameters; let verifier = Executor::test(Default::default(), Default::default()); let gas_limit = 100; let gas_price = 1; - let tx = TransactionBuilder::script(vec![], vec![]) + let script = TransactionBuilder::script(vec![], vec![]) .add_unsigned_coin_input( SecretKey::random(&mut rng), rng.gen(), @@ -2577,9 +2577,17 @@ mod tests { Default::default(), Default::default(), ) - .gas_limit(gas_limit) + .script_gas_limit(gas_limit) .gas_price(gas_price) - .finalize_as_transaction(); + .finalize(); + let max_fee: u64 = script + .max_fee( + consensus_parameters.gas_costs(), + consensus_parameters.fee_params(), + ) + .try_into() + .unwrap(); + let tx: Transaction = script.into(); let mut block = PartialFuelBlock { header: Default::default(), @@ -2602,7 +2610,11 @@ mod tests { let produce_result = &skipped_transactions[0].1; assert!(matches!( produce_result, - &ExecutorError::InvalidTransaction(CheckError::InsufficientFeeAmount { expected, .. }) if expected == (gas_limit as f64 / factor).ceil() as u64 + &ExecutorError::InvalidTransaction( + CheckError::Validity( + ValidityError::InsufficientFeeAmount { expected, .. } + ) + ) if expected == max_fee )); // Produced block is valid @@ -2629,7 +2641,11 @@ mod tests { ); assert!(matches!( verify_result, - Err(ExecutorError::InvalidTransaction(CheckError::InsufficientFeeAmount { expected, ..})) if expected == (gas_limit as f64 / factor).ceil() as u64 + Err(ExecutorError::InvalidTransaction( + CheckError::Validity( + ValidityError::InsufficientFeeAmount { expected, .. } + ) + )) if expected == max_fee )) } @@ -2800,7 +2816,7 @@ mod tests { let fake_output_amount = 100; let tx: Transaction = TxBuilder::new(2322u64) - .gas_limit(1) + .script_gas_limit(1) .coin_input(Default::default(), input_amount) .change_output(Default::default()) .build() @@ -2845,7 +2861,7 @@ mod tests { fn executor_invalidates_blocks_with_diverging_tx_commitment() { let mut rng = StdRng::seed_from_u64(2322u64); let tx: Transaction = TxBuilder::new(2322u64) - .gas_limit(1) + .script_gas_limit(1) .coin_input(Default::default(), 10) .change_output(Default::default()) .build() @@ -2911,7 +2927,9 @@ mod tests { // assert block failed to validate when transaction didn't contain any coin inputs assert!(matches!( err, - &ExecutorError::InvalidTransaction(CheckError::NoSpendableInput) + &ExecutorError::InvalidTransaction(CheckError::Validity( + ValidityError::NoSpendableInput + )) )); } @@ -3033,7 +3051,7 @@ mod tests { // transaction `tx1` and produce a block [tx2, tx3] with the expected order. let tx1 = TransactionBuilder::script(vec![], vec![]) .add_random_fee_input() - .gas_limit(1000000) + .script_gas_limit(1000000) .gas_price(1000000) .finalize_as_transaction(); let (tx2, tx3) = setup_executable_script(); @@ -3120,7 +3138,7 @@ mod tests { let (create, contract_id) = create_contract(vec![], &mut rng); let non_modify_state_tx: Transaction = TxBuilder::new(2322) - .gas_limit(10000) + .script_gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) .start_script(vec![op::ret(1)], vec![]) .contract_input(contract_id) @@ -3300,7 +3318,7 @@ mod tests { .collect(); let modify_balance_and_state_tx = TxBuilder::new(2322) - .gas_limit(10000) + .script_gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) .start_script(script, script_data) .contract_input(contract_id) @@ -3416,7 +3434,7 @@ mod tests { .collect(); let modify_balance_and_state_tx = TxBuilder::new(2322) - .gas_limit(10000) + .script_gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) .start_script(script, script_data) .contract_input(contract_id) @@ -3496,7 +3514,7 @@ mod tests { let transfer_amount = 100 as Word; let asset_id = AssetId::from([2; 32]); let mut foreign_transfer = TxBuilder::new(2322) - .gas_limit(10000) + .script_gas_limit(10000) .coin_input(AssetId::zeroed(), 10000) .start_script(vec![op::ret(1)], vec![]) .coin_input(asset_id, transfer_amount) @@ -4263,7 +4281,7 @@ mod tests { // return current block height let script = vec![op::bhei(0x10), op::ret(0x10)]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .add_unsigned_coin_input( SecretKey::random(&mut rng), rng.gen(), @@ -4341,7 +4359,7 @@ mod tests { // return current block height let script = vec![op::bhei(0x10), op::time(0x11, 0x10), op::ret(0x11)]; let tx = TransactionBuilder::script(script.into_iter().collect(), vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .add_unsigned_coin_input( SecretKey::random(&mut rng), rng.gen(), diff --git a/crates/fuel-core/src/p2p_test_helpers.rs b/crates/fuel-core/src/p2p_test_helpers.rs index e488ea6bfee..a572bbad608 100644 --- a/crates/fuel-core/src/p2p_test_helpers.rs +++ b/crates/fuel-core/src/p2p_test_helpers.rs @@ -197,7 +197,7 @@ pub async fn make_nodes( vec![op::ret(RegId::ONE)].into_iter().collect(), vec![], ) - .gas_limit(100000) + .script_gas_limit(100000) .add_unsigned_coin_input( secret, utxo_id, diff --git a/crates/fuel-core/src/schema/chain.rs b/crates/fuel-core/src/schema/chain.rs index 4366ac3091c..45de1022d9a 100644 --- a/crates/fuel-core/src/schema/chain.rs +++ b/crates/fuel-core/src/schema/chain.rs @@ -648,6 +648,14 @@ impl GasCosts { async fn state_root(&self) -> DependentCost { self.0.state_root.into() } + + async fn vm_initialization(&self) -> U64 { + self.0.vm_initialization.into() + } + + async fn new_storage_per_byte(&self) -> U64 { + self.0.new_storage_per_byte.into() + } } #[Object] diff --git a/crates/fuel-core/src/schema/dap.rs b/crates/fuel-core/src/schema/dap.rs index 38ed5b4f885..97ac733970c 100644 --- a/crates/fuel-core/src/schema/dap.rs +++ b/crates/fuel-core/src/schema/dap.rs @@ -102,7 +102,7 @@ impl ConcreteStorage { let tx = Self::dummy_tx(); let checked_tx = tx .into_checked_basic(vm_database.block_height()?, &self.params) - .map_err(|e| anyhow::anyhow!(e))?; + .map_err(|e| anyhow::anyhow!("{:?}", e))?; self.tx .get_mut(&id) .map(|tx| tx.extend_from_slice(txs)) @@ -135,7 +135,7 @@ impl ConcreteStorage { let checked_tx = tx .into_checked_basic(vm_database.block_height()?, &self.params) - .map_err(|e| anyhow::anyhow!(e))?; + .map_err(|e| anyhow::anyhow!("{:?}", e))?; let mut vm = Interpreter::with_storage(vm_database, (&self.params).into()); vm.transact(checked_tx).map_err(|e| anyhow::anyhow!(e))?; @@ -372,7 +372,8 @@ impl DapMutation { let db = locked.db.get(&id).ok_or("Invalid debugging session ID")?; let checked_tx = tx - .into_checked_basic(db.latest_height()?, &locked.params)? + .into_checked_basic(db.latest_height()?, &locked.params) + .map_err(|err| anyhow::anyhow!("{:?}", err))? .into(); let vm = locked diff --git a/crates/fuel-core/src/schema/tx.rs b/crates/fuel-core/src/schema/tx.rs index 248e72769f2..813fcd9911e 100644 --- a/crates/fuel-core/src/schema/tx.rs +++ b/crates/fuel-core/src/schema/tx.rs @@ -214,7 +214,8 @@ impl TxQuery { tx.estimate_predicates_async::(&CheckPredicateParams::from( &config.consensus_parameters, )) - .await?; + .await + .map_err(|err| anyhow::anyhow!("{:?}", err))?; Ok(Transaction::from_tx( tx.id(&config.consensus_parameters.chain_id), diff --git a/crates/fuel-core/src/schema/tx/types.rs b/crates/fuel-core/src/schema/tx/types.rs index 00d279d5101..64c5348489d 100644 --- a/crates/fuel-core/src/schema/tx/types.rs +++ b/crates/fuel-core/src/schema/tx/types.rs @@ -58,14 +58,17 @@ use fuel_core_types::{ MintAssetId, OutputContract, Outputs, + Policies as PoliciesField, ReceiptsRoot, Salt as SaltField, Script as ScriptField, ScriptData, + ScriptGasLimit, StorageSlots, TxPointer as TxPointerField, Witnesses, }, + policies::PolicyType, Chargeable, Executable, }, @@ -271,6 +274,31 @@ impl From for TxStatus { } } } + +pub struct Policies(fuel_tx::policies::Policies); + +#[Object] +impl Policies { + async fn gas_price(&self) -> Option { + self.0.get(PolicyType::GasPrice).map(Into::into) + } + + async fn witness_limit(&self) -> Option { + self.0.get(PolicyType::WitnessLimit).map(Into::into) + } + + async fn maturity(&self) -> Option { + self.0 + .get(PolicyType::Maturity) + .and_then(|value| u32::try_from(value).ok()) + .map(Into::into) + } + + async fn max_fee(&self) -> Option { + self.0.get(PolicyType::MaxFee).map(Into::into) + } +} + pub struct Transaction(pub(crate) fuel_tx::Transaction, pub(crate) fuel_tx::TxId); impl Transaction { @@ -326,6 +354,14 @@ impl Transaction { } } + async fn policies(&self) -> Option { + match &self.0 { + fuel_tx::Transaction::Script(script) => Some((*script.policies()).into()), + fuel_tx::Transaction::Create(create) => Some((*create.policies()).into()), + fuel_tx::Transaction::Mint(_) => None, + } + } + async fn gas_price(&self) -> Option { match &self.0 { fuel_tx::Transaction::Script(script) => Some(script.price().into()), @@ -334,18 +370,20 @@ impl Transaction { } } - async fn gas_limit(&self) -> Option { + async fn script_gas_limit(&self) -> Option { match &self.0 { - fuel_tx::Transaction::Script(script) => Some(script.limit().into()), - fuel_tx::Transaction::Create(create) => Some(create.limit().into()), + fuel_tx::Transaction::Script(script) => { + Some((*script.script_gas_limit()).into()) + } + fuel_tx::Transaction::Create(_) => Some(0.into()), fuel_tx::Transaction::Mint(_) => None, } } async fn maturity(&self) -> Option { match &self.0 { - fuel_tx::Transaction::Script(script) => Some((*script.maturity()).into()), - fuel_tx::Transaction::Create(create) => Some((*create.maturity()).into()), + fuel_tx::Transaction::Script(script) => Some(script.maturity().into()), + fuel_tx::Transaction::Create(create) => Some(create.maturity().into()), fuel_tx::Transaction::Mint(_) => None, } } @@ -563,3 +601,9 @@ pub(crate) fn get_tx_status( }, } } + +impl From for Policies { + fn from(value: fuel_tx::policies::Policies) -> Self { + Policies(value) + } +} diff --git a/crates/fuel-core/src/service/adapters/executor.rs b/crates/fuel-core/src/service/adapters/executor.rs index 9385f5d5bb8..304864a01a4 100644 --- a/crates/fuel-core/src/service/adapters/executor.rs +++ b/crates/fuel-core/src/service/adapters/executor.rs @@ -77,14 +77,14 @@ impl crate::executor::RelayerPort for MaybeRelayerAdapter { fn get_message( &self, id: &Nonce, - da_height: &DaBlockHeight, + _da_height: &DaBlockHeight, ) -> anyhow::Result> { #[cfg(feature = "relayer")] { match self.relayer_synced.as_ref() { - Some(sync) => sync.get_message(id, da_height), + Some(sync) => sync.get_message(id, _da_height), None => { - if *da_height <= self.da_deploy_height { + if *_da_height <= self.da_deploy_height { Ok(fuel_core_storage::StorageAsRef::storage::< fuel_core_storage::tables::Messages, >(&self.database) @@ -98,9 +98,11 @@ impl crate::executor::RelayerPort for MaybeRelayerAdapter { } #[cfg(not(feature = "relayer"))] { - let _ = id; - let _ = da_height; - Ok(None) + Ok(fuel_core_storage::StorageAsRef::storage::< + fuel_core_storage::tables::Messages, + >(&self.database) + .get(id)? + .map(std::borrow::Cow::into_owned)) } } } diff --git a/crates/services/consensus_module/poa/src/service_test.rs b/crates/services/consensus_module/poa/src/service_test.rs index 472d2c15e24..864a4e7d94b 100644 --- a/crates/services/consensus_module/poa/src/service_test.rs +++ b/crates/services/consensus_module/poa/src/service_test.rs @@ -30,7 +30,7 @@ use fuel_core_types::{ }, fuel_crypto::SecretKey, fuel_tx::{ - field::GasLimit, + field::ScriptGasLimit, *, }, fuel_types::{ @@ -227,7 +227,7 @@ impl MockTransactionPool { .lock() .unwrap() .iter() - .map(|tx| *tx.gas_limit()) + .map(|tx| *tx.script_gas_limit()) .sum() }); let removed = txs.clone(); @@ -252,7 +252,7 @@ impl MockTransactionPool { fn make_tx(rng: &mut StdRng) -> Script { TransactionBuilder::script(vec![], vec![]) .gas_price(0) - .gas_limit(rng.gen_range(1..TxParameters::DEFAULT.max_gas_per_tx)) + .script_gas_limit(rng.gen_range(1..TxParameters::DEFAULT.max_gas_per_tx)) .finalize_without_signature() } diff --git a/crates/services/importer/src/importer.rs b/crates/services/importer/src/importer.rs index ed5a51d2e11..ca1256005bb 100644 --- a/crates/services/importer/src/importer.rs +++ b/crates/services/importer/src/importer.rs @@ -34,6 +34,7 @@ use fuel_core_types::{ }, }; use std::{ + ops::Deref, sync::Arc, time::{ Instant, @@ -251,7 +252,7 @@ where importer_metrics().total_txs_count.set(total_txs as i64); importer_metrics() .block_height - .set(actual_height.as_usize() as i64); + .set(*actual_height.deref() as i64); let current_time = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -281,7 +282,7 @@ where .set(total_tx_count as i64); importer_metrics() .block_height - .set(current_block_height.as_usize() as i64); + .set(*current_block_height.deref() as i64); // on init just set to current time since it's not worth tracking in the db let current_time = SystemTime::now() .duration_since(UNIX_EPOCH) diff --git a/crates/services/producer/src/block_producer.rs b/crates/services/producer/src/block_producer.rs index ae41b800e59..3e57c794195 100644 --- a/crates/services/producer/src/block_producer.rs +++ b/crates/services/producer/src/block_producer.rs @@ -18,7 +18,6 @@ use fuel_core_types::{ }, fuel_asm::Word, fuel_tx::{ - field::GasLimit, Receipt, Transaction, }, @@ -147,15 +146,10 @@ where // It is deterministic from the result perspective, plus it is more performant // because we don't need to wait for the relayer to sync. let header = self._new_header(height, Tai64::now())?; - let gas_limit = match &transaction { - Transaction::Script(script) => *script.gas_limit(), - Transaction::Create(create) => *create.gas_limit(), - Transaction::Mint(_) => 0, - }; let component = Components { header_to_produce: header, transactions_source: transaction, - gas_limit, + gas_limit: u64::MAX, }; let executor = self.executor.clone(); diff --git a/crates/services/producer/src/mocks.rs b/crates/services/producer/src/mocks.rs index 187a56a5938..69ca3d482dd 100644 --- a/crates/services/producer/src/mocks.rs +++ b/crates/services/producer/src/mocks.rs @@ -42,6 +42,7 @@ use fuel_core_types::{ use std::{ borrow::Cow, collections::HashMap, + ops::Deref, sync::{ Arc, Mutex, @@ -226,7 +227,7 @@ impl BlockProducerDatabase for MockDb { fn block_header_merkle_root(&self, height: &BlockHeight) -> StorageResult { Ok(Bytes32::new( - [u8::try_from(height.as_usize()).expect("Test use small values"); 32], + [u8::try_from(*height.deref()).expect("Test use small values"); 32], )) } diff --git a/crates/services/txpool/src/service/test_helpers.rs b/crates/services/txpool/src/service/test_helpers.rs index 6c95f3c3ce1..decaf2f98d1 100644 --- a/crates/services/txpool/src/service/test_helpers.rs +++ b/crates/services/txpool/src/service/test_helpers.rs @@ -46,7 +46,7 @@ impl TestContext { let (_, gas_coin) = self.setup_coin(); let mut tx = TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price) - .gas_limit(1000) + .script_gas_limit(1000) .add_input(gas_coin) .finalize_as_transaction(); @@ -171,7 +171,7 @@ impl TestContextBuilder { let (_, gas_coin) = self.setup_coin(); TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price) - .gas_limit(1000) + .script_gas_limit(1000) .add_input(gas_coin) .finalize_as_transaction() } diff --git a/crates/services/txpool/src/transaction_selector.rs b/crates/services/txpool/src/transaction_selector.rs index 1aedf1c824e..dec49e01820 100644 --- a/crates/services/txpool/src/transaction_selector.rs +++ b/crates/services/txpool/src/transaction_selector.rs @@ -80,7 +80,7 @@ mod tests { let fee_params = FeeParameters { gas_price_factor: 1, - ..FeeParameters::default() + gas_per_byte: 0, }; let mut txs = txs @@ -91,7 +91,7 @@ mod tests { vec![], ) .gas_price(tx_gas.price) - .gas_limit(tx_gas.limit) + .script_gas_limit(tx_gas.limit) .add_unsigned_coin_input( SecretKey::random(&mut rng), rng.gen(), @@ -118,7 +118,7 @@ mod tests { select_transactions(txs.into_iter(), block_gas_limit) .into_iter() .map(|tx| TxGas { - limit: tx.limit(), + limit: tx.script_gas_limit().unwrap_or_default(), price: tx.price(), }) .collect() @@ -132,33 +132,30 @@ mod tests { #[rstest::rstest] #[test] - #[case(1000, vec![])] - #[case(2500, vec![TxGas { price: 5, limit: 1000 }])] - #[case(5000, vec![ - TxGas { price: 5, limit: 1000 }, - TxGas { price: 2, limit: 1000 }]) - ] - #[case(7500, vec![ + #[case(999, vec![])] + #[case(1000, vec![TxGas { price: 5, limit: 1000 }])] + #[case(2500, vec![TxGas { price: 5, limit: 1000 }, TxGas { price: 2, limit: 1000 }])] + #[case(4000, vec![ TxGas { price: 5, limit: 1000 }, TxGas { price: 4, limit: 3000 } ])] - #[case(10_000, vec![ + #[case(5000, vec![ TxGas { price: 5, limit: 1000 }, TxGas { price: 4, limit: 3000 }, - TxGas { price: 2, limit: 1000 } - ])] - #[case(12_500, vec![ + TxGas { price: 2, limit: 1000 }]) + ] + #[case(6_000, vec![ TxGas { price: 5, limit: 1000 }, TxGas { price: 4, limit: 3000 }, TxGas { price: 3, limit: 2000 } ])] - #[case(15_000, vec![ + #[case(7_000, vec![ TxGas { price: 5, limit: 1000 }, TxGas { price: 4, limit: 3000 }, TxGas { price: 3, limit: 2000 }, TxGas { price: 2, limit: 1000 } ])] - #[case(17_500, vec![ + #[case(8_000, vec![ TxGas { price: 5, limit: 1000 }, TxGas { price: 4, limit: 3000 }, TxGas { price: 3, limit: 2000 }, diff --git a/crates/services/txpool/src/txpool.rs b/crates/services/txpool/src/txpool.rs index 2e1bf6283e9..50c7d2484e0 100644 --- a/crates/services/txpool/src/txpool.rs +++ b/crates/services/txpool/src/txpool.rs @@ -302,7 +302,7 @@ where /// The amount of gas in all includable transactions combined pub fn consumable_gas(&self) -> u64 { - self.by_hash.values().map(|tx| tx.limit()).sum() + self.by_hash.values().map(|tx| tx.max_gas()).sum() } /// Return all sorted transactions that are includable in next block. @@ -337,6 +337,11 @@ where for tx_id in tx_ids { let rem = self.remove_by_tx_id(tx_id); tx_status_sender.send_squeezed_out(*tx_id, Error::Removed); + for dependent_tx in rem.iter() { + if tx_id != &dependent_tx.id() { + tx_status_sender.send_squeezed_out(dependent_tx.id(), Error::Removed); + } + } removed.extend(rem.into_iter()); } removed @@ -409,7 +414,7 @@ pub async fn check_single_tx( .await .map_err(|e| anyhow::anyhow!("{e:?}"))?; - debug_assert!(tx.checks().contains(Checks::All)); + debug_assert!(tx.checks().contains(Checks::all())); tx } else { diff --git a/crates/services/txpool/src/txpool/tests.rs b/crates/services/txpool/src/txpool/tests.rs index dc858a33bbd..2e4c7706d56 100644 --- a/crates/services/txpool/src/txpool/tests.rs +++ b/crates/services/txpool/src/txpool/tests.rs @@ -82,7 +82,7 @@ async fn insert_simple_tx_succeeds() { let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -103,7 +103,7 @@ async fn insert_simple_tx_dependency_chain_succeeds() { let (output, unset_input) = create_output_and_input(&mut rng, 1); let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(1) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(output) .finalize_as_transaction(); @@ -112,7 +112,7 @@ async fn insert_simple_tx_dependency_chain_succeeds() { let input = unset_input.into_input(UtxoId::new(tx1.id(&Default::default()), 0)); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(1) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .add_input(gas_coin) .finalize_as_transaction(); @@ -143,7 +143,6 @@ async fn faulty_t2_collided_on_contract_id_from_tx1() { Default::default(), ) .gas_price(10) - .gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(create_contract_output(contract_id)) .add_output(output) @@ -160,7 +159,6 @@ async fn faulty_t2_collided_on_contract_id_from_tx1() { Default::default(), ) .gas_price(9) - .gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_input(input) .add_output(create_contract_output(contract_id)) @@ -196,14 +194,13 @@ async fn fail_to_insert_tx_with_dependency_on_invalid_utxo_type() { ) .add_input(gas_coin) .add_output(create_contract_output(contract_id)) - .gas_limit(GAS_LIMIT) .finalize_as_transaction(); // create a second transaction with utxo id referring to // the wrong type of utxo (contract instead of coin) let tx = TransactionBuilder::script(vec![], vec![]) .gas_price(1) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(random_predicate( &mut rng, AssetId::BASE, @@ -263,7 +260,7 @@ async fn try_to_insert_tx2_missing_utxo() { let (_, input) = setup_coin(&mut rng, None); let tx = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -288,13 +285,13 @@ async fn higher_priced_tx_removes_lower_priced_tx() { let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(coin_input.clone()) .finalize_as_transaction(); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(20) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(coin_input) .finalize_as_transaction(); @@ -321,7 +318,7 @@ async fn underpriced_tx1_not_included_coin_collision() { let (output, unset_input) = create_output_and_input(&mut rng, 10); let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(20) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(output) .finalize_as_transaction(); @@ -330,13 +327,13 @@ async fn underpriced_tx1_not_included_coin_collision() { let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(20) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input.clone()) .finalize_as_transaction(); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -374,7 +371,6 @@ async fn overpriced_tx_contract_input_not_inserted() { Default::default(), ) .gas_price(10) - .gas_limit(GAS_LIMIT) .add_input(gas_funds) .add_output(create_contract_output(contract_id)) .finalize_as_transaction(); @@ -382,7 +378,7 @@ async fn overpriced_tx_contract_input_not_inserted() { let (_, gas_funds) = setup_coin(&mut rng, Some(&txpool.database)); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(11) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_funds) .add_input(create_contract_input( Default::default(), @@ -422,7 +418,6 @@ async fn dependent_contract_input_inserted() { Default::default(), ) .gas_price(10) - .gas_limit(GAS_LIMIT) .add_input(gas_funds) .add_output(create_contract_output(contract_id)) .finalize_as_transaction(); @@ -430,7 +425,7 @@ async fn dependent_contract_input_inserted() { let (_, gas_funds) = setup_coin(&mut rng, Some(&txpool.database)); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_funds) .add_input(create_contract_input( Default::default(), @@ -457,7 +452,7 @@ async fn more_priced_tx3_removes_tx1_and_dependent_tx2() { let (output, unset_input) = create_output_and_input(&mut rng, 10); let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin.clone()) .add_output(output) .finalize_as_transaction(); @@ -466,13 +461,13 @@ async fn more_priced_tx3_removes_tx1_and_dependent_tx2() { let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(9) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(20) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -508,19 +503,19 @@ async fn more_priced_tx2_removes_tx1_and_more_priced_tx3_removes_tx2() { let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin.clone()) .finalize_as_transaction(); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(11) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin.clone()) .finalize_as_transaction(); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(12) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -553,14 +548,14 @@ async fn tx_limit_hit() { let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx1 = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(create_coin_output()) .finalize_as_transaction(); let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx2 = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -592,7 +587,7 @@ async fn tx_depth_hit() { let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let (output, unset_input) = create_output_and_input(&mut rng, 10_000); let tx1 = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(output) .finalize_as_transaction(); @@ -600,14 +595,14 @@ async fn tx_depth_hit() { let input = unset_input.into_input(UtxoId::new(tx1.id(&Default::default()), 0)); let (output, unset_input) = create_output_and_input(&mut rng, 5_000); let tx2 = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .add_output(output) .finalize_as_transaction(); let input = unset_input.into_input(UtxoId::new(tx2.id(&Default::default()), 0)); let tx3 = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -636,21 +631,21 @@ async fn sorted_out_tx1_2_4() { let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(9) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(20) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -684,7 +679,7 @@ async fn find_dependent_tx1_tx2() { let (output, unset_input) = create_output_and_input(&mut rng, 10_000); let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(11) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .add_output(output) .finalize_as_transaction(); @@ -693,7 +688,7 @@ async fn find_dependent_tx1_tx2() { let (output, unset_input) = create_output_and_input(&mut rng, 7_500); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .add_output(output) .finalize_as_transaction(); @@ -701,7 +696,7 @@ async fn find_dependent_tx1_tx2() { let input = unset_input.into_input(UtxoId::new(tx2.id(&Default::default()), 0)); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(9) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -746,7 +741,7 @@ async fn tx_at_least_min_gas_price_is_insertable() { let (_, gas_coin) = setup_coin(&mut rng, Some(&txpool.database)); let tx = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -762,7 +757,7 @@ async fn tx_below_min_gas_price_is_not_insertable() { let (_, gas_coin) = setup_coin(&mut rng, Some(&db)); let tx = TransactionBuilder::script(vec![], vec![]) .gas_price(10) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -788,7 +783,7 @@ async fn tx_inserted_into_pool_when_input_message_id_exists_in_db() { let (message, input) = create_message_predicate_from_message(5000, 0); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -810,7 +805,7 @@ async fn tx_rejected_when_input_message_id_is_spent() { let (message, input) = create_message_predicate_from_message(5_000, 0); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -833,7 +828,7 @@ async fn tx_rejected_when_input_message_id_is_spent() { async fn tx_rejected_from_pool_when_input_message_id_does_not_exist_in_db() { let (message, input) = create_message_predicate_from_message(5000, 0); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(input) .finalize_as_transaction(); @@ -862,13 +857,13 @@ async fn tx_rejected_from_pool_when_gas_price_is_lower_than_another_tx_with_same let tx_high = TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price_high) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(conflicting_message_input.clone()) .finalize_as_transaction(); let tx_low = TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price_low) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(conflicting_message_input) .finalize_as_transaction(); @@ -910,7 +905,7 @@ async fn higher_priced_tx_squeezes_out_lower_priced_tx_with_same_message_id() { // Insert a tx for the message id with a low gas amount let tx_low = TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price_low) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(conflicting_message_input.clone()) .finalize_as_transaction(); @@ -928,7 +923,7 @@ async fn higher_priced_tx_squeezes_out_lower_priced_tx_with_same_message_id() { // price is lower, we accept the new transaction and squeeze out the old transaction. let tx_high = TransactionBuilder::script(vec![], vec![]) .gas_price(gas_price_high) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(conflicting_message_input) .finalize_as_transaction(); let tx_high = check_unwrap_tx(tx_high, db.clone(), &txpool.config).await; @@ -952,20 +947,20 @@ async fn message_of_squeezed_out_tx_can_be_resubmitted_at_lower_gas_price() { // Insert a tx for the message id with a low gas amount let tx1 = TransactionBuilder::script(vec![], vec![]) .gas_price(2) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(message_input_1.clone()) .add_input(message_input_2.clone()) .finalize_as_transaction(); let tx2 = TransactionBuilder::script(vec![], vec![]) .gas_price(3) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(message_input_1) .finalize_as_transaction(); let tx3 = TransactionBuilder::script(vec![], vec![]) .gas_price(1) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(message_input_2) .finalize_as_transaction(); @@ -996,7 +991,7 @@ async fn predicates_with_incorrect_owner_fails() { let (_, gas_coin) = add_coin_to_state(coin, Some(&db.clone())); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -1037,7 +1032,7 @@ async fn predicate_without_enough_gas_returns_out_of_gas() { let (_, gas_coin) = add_coin_to_state(coin, Some(&db.clone())); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); @@ -1046,7 +1041,8 @@ async fn predicate_without_enough_gas_returns_out_of_gas() { .expect_err("Transaction should be err, got ok"); assert!( - err.to_string().contains("PredicateExhaustedGas"), + err.to_string() + .contains("PredicateVerificationFailed(OutOfGas)"), "unexpected error: {err}", ) } @@ -1067,7 +1063,7 @@ async fn predicate_that_returns_false_is_invalid() { let (_, gas_coin) = add_coin_to_state(coin, Some(&db.clone())); let tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(GAS_LIMIT) + .script_gas_limit(GAS_LIMIT) .add_input(gas_coin) .finalize_as_transaction(); diff --git a/crates/types/src/services/executor.rs b/crates/types/src/services/executor.rs index 2b826226ffb..3850c0af556 100644 --- a/crates/types/src/services/executor.rs +++ b/crates/types/src/services/executor.rs @@ -9,9 +9,9 @@ use crate::{ primitives::BlockId, }, fuel_tx::{ - CheckError, TxId, UtxoId, + ValidityError, }, fuel_types::{ Bytes32, @@ -19,6 +19,7 @@ use crate::{ Nonce, }, fuel_vm::{ + checked_transaction::CheckError, Backtrace, InterpreterError, ProgramState, @@ -318,6 +319,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: ValidityError) -> Self { + Self::InvalidTransaction(CheckError::Validity(e)) + } +} + #[allow(missing_docs)] #[derive(thiserror::Error, Debug)] #[non_exhaustive] @@ -363,3 +370,9 @@ impl From for TransactionValidityError { Self::Validation(e) } } + +impl From for TransactionValidityError { + fn from(e: ValidityError) -> Self { + Self::Validation(CheckError::Validity(e)) + } +} diff --git a/crates/types/src/services/txpool.rs b/crates/types/src/services/txpool.rs index 7cf88a1367f..aa85e5a0c23 100644 --- a/crates/types/src/services/txpool.rs +++ b/crates/types/src/services/txpool.rs @@ -7,6 +7,7 @@ use crate::{ field::{ Inputs, Outputs, + ScriptGasLimit, }, Cacheable, Chargeable, @@ -58,11 +59,11 @@ impl PoolTransaction { } } - /// Returns the gas limit. - pub fn limit(&self) -> Word { + /// Returns the maximum amount of gas that the transaction can consume. + pub fn max_gas(&self) -> Word { match self { - PoolTransaction::Script(script) => script.transaction().limit(), - PoolTransaction::Create(create) => create.transaction().limit(), + PoolTransaction::Script(script) => script.metadata().fee.max_gas(), + PoolTransaction::Create(create) => create.metadata().fee.max_gas(), } } @@ -85,6 +86,15 @@ impl PoolTransaction { #[allow(missing_docs)] impl PoolTransaction { + pub fn script_gas_limit(&self) -> Option { + match self { + PoolTransaction::Script(script) => { + Some(*script.transaction().script_gas_limit()) + } + PoolTransaction::Create(_) => None, + } + } + pub fn is_computed(&self) -> bool { match self { PoolTransaction::Script(script) => script.transaction().is_computed(), @@ -105,13 +115,6 @@ impl PoolTransaction { PoolTransaction::Create(create) => create.transaction().outputs(), } } - - pub fn max_gas(&self) -> Word { - match self { - PoolTransaction::Script(script) => script.metadata().fee.max_gas(), - PoolTransaction::Create(create) => create.metadata().fee.max_gas(), - } - } } impl From<&PoolTransaction> for Transaction { diff --git a/deployment/scripts/chainspec/beta_chainspec.json b/deployment/scripts/chainspec/beta_chainspec.json index 89817954f84..cd8d0fcf366 100644 --- a/deployment/scripts/chainspec/beta_chainspec.json +++ b/deployment/scripts/chainspec/beta_chainspec.json @@ -270,7 +270,9 @@ "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 100, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/deployment/scripts/chainspec/dev_chainspec.json b/deployment/scripts/chainspec/dev_chainspec.json index 333c6f6cc0f..bb9408e07f8 100644 --- a/deployment/scripts/chainspec/dev_chainspec.json +++ b/deployment/scripts/chainspec/dev_chainspec.json @@ -240,7 +240,9 @@ "base": 412, "units_per_gas": 1 } - } + }, + "new_storage_per_byte": 100, + "vm_initialization": 2000 }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" }, diff --git a/tests/test-helpers/src/builder.rs b/tests/test-helpers/src/builder.rs index 8c36892d3a3..5087db79538 100644 --- a/tests/test-helpers/src/builder.rs +++ b/tests/test-helpers/src/builder.rs @@ -20,6 +20,7 @@ use fuel_core_types::{ CoinPredicate, CoinSigned, }, + policies::Policies, *, }, fuel_types::BlockHeight, @@ -58,11 +59,10 @@ impl TestContext { ) -> io::Result { let script = op::ret(0x10).to_bytes().to_vec(); let tx = Transaction::script( - Default::default(), 1_000_000, - Default::default(), script, vec![], + Policies::new().with_gas_price(0), vec![Input::coin_signed( self.rng.gen(), from, diff --git a/tests/tests/balances.rs b/tests/tests/balances.rs index 5f12ca679e6..2fae1386297 100644 --- a/tests/tests/balances.rs +++ b/tests/tests/balances.rs @@ -92,7 +92,7 @@ async fn balance() { .unwrap(); let mut tx = TransactionBuilder::script(vec![], vec![]) - .gas_limit(1_000_000) + .script_gas_limit(1_000_000) .to_owned(); for coins in coins_per_asset { for coin in coins { diff --git a/tests/tests/contract.rs b/tests/tests/contract.rs index d8d4236b583..b72da64bf9a 100644 --- a/tests/tests/contract.rs +++ b/tests/tests/contract.rs @@ -132,6 +132,8 @@ async fn can_get_message_proof() { .unwrap() .clone(); + let slots_to_read = 2; + let contract = vec![ // Save the ptr to the script data to register 16. // Start db key @@ -140,7 +142,7 @@ async fn can_get_message_proof() { op::movi(0x11, 100), op::aloc(0x11), op::move_(0x11, RegId::HP), - op::movi(0x13, 2), + op::movi(0x13, slots_to_read), // Write read to 0x11. // Write status to 0x30. // Get the db key the memory location in 0x10. @@ -241,11 +243,10 @@ async fn can_get_message_proof() { // Create the contract calling script. let script = Transaction::script( - Default::default(), 1_000_000, - Default::default(), script, script_data, + policies::Policies::new().with_gas_price(0), inputs, outputs, vec![], @@ -291,10 +292,10 @@ async fn can_get_message_proof() { .collect::>(); assert_eq!(log[0].ra().unwrap(), 0); assert_eq!(log[0].rb().unwrap(), 0); - assert_eq!(log[0].rc().unwrap(), 0); + assert_eq!(log[0].rc().unwrap(), slots_to_read as u64); assert_eq!(log[0].rd().unwrap(), 1); - assert_eq!(log[1].ra().unwrap(), 1); + assert_eq!(log[1].ra().unwrap(), 0); assert_eq!(log[1].rb().unwrap(), 1); assert_eq!(logd.data().unwrap(), db_data); } diff --git a/tests/tests/example_tx.json b/tests/tests/example_tx.json index b3cfde444c2..ba9b5a2c8af 100755 --- a/tests/tests/example_tx.json +++ b/tests/tests/example_tx.json @@ -1,10 +1,12 @@ { "Script": { - "gas_price": 0, - "gas_limit": 1000000, - "maturity": 0, + "script_gas_limit": 10000, "script": [80,64,0,202,80,68,0,186,51,65,16,0,36,4,0,0], "script_data": [], + "policies": { + "bits": "GasPrice | Maturity", + "values": [0, 0, 0, 0] + }, "inputs": [ { "CoinSigned": { diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index 0801c5ed3c4..7ba51d35d46 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -259,11 +259,10 @@ async fn message_status__can_get_spent() { let output = Output::coin(output_recipient, amount, Default::default()); let tx = Transaction::script( - Default::default(), 1_000_000, - Default::default(), vec![], vec![], + policies::Policies::new().with_gas_price(0), vec![input], vec![output], vec![Vec::new().into()], @@ -438,11 +437,10 @@ async fn can_get_message_proof() { // Create the contract calling script. let script = Transaction::script( - Default::default(), 1_000_000, - Default::default(), script, script_data, + policies::Policies::new().with_gas_price(0), inputs, outputs, vec![], diff --git a/tests/tests/messages/relayer.rs b/tests/tests/messages/relayer.rs index e203dfba00a..1714e9a2179 100644 --- a/tests/tests/messages/relayer.rs +++ b/tests/tests/messages/relayer.rs @@ -22,7 +22,7 @@ async fn can_submit_genesis_message() { da_height: DaBlockHeight(0), }; let tx1 = TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) - .gas_limit(100000) + .script_gas_limit(100000) .add_unsigned_message_input( secret_key, msg1.sender, diff --git a/tests/tests/metrics.rs b/tests/tests/metrics.rs index 417c37cd4ad..c7cc992ce63 100644 --- a/tests/tests/metrics.rs +++ b/tests/tests/metrics.rs @@ -40,7 +40,7 @@ async fn test_metrics_endpoint() { client .submit_and_await_commit( &TransactionBuilder::script(script, vec![]) - .gas_limit(1000000) + .script_gas_limit(1000000) .add_random_fee_input() .finalize_as_transaction(), ) diff --git a/tests/tests/relayer.rs b/tests/tests/relayer.rs index f94bc281dbf..0bba7965d64 100644 --- a/tests/tests/relayer.rs +++ b/tests/tests/relayer.rs @@ -191,7 +191,7 @@ async fn messages_are_spendable_after_relayer_is_synced() { // attempt to spend the message downloaded from the relayer let tx = TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]) - .gas_limit(10_000) + .script_gas_limit(10_000) .gas_price(0) .add_unsigned_message_input(secret_key, sender, nonce, amount, vec![]) .add_output(Output::change(rng.gen(), 0, AssetId::BASE)) diff --git a/tests/tests/tx.rs b/tests/tests/tx.rs index e96c8d53378..fcc08abe88f 100644 --- a/tests/tests/tx.rs +++ b/tests/tests/tx.rs @@ -83,7 +83,7 @@ async fn dry_run_script() { .collect(); let tx = TransactionBuilder::script(script, vec![]) - .gas_limit(gas_limit) + .script_gas_limit(gas_limit) .gas_price(gas_price) .maturity(maturity) .add_random_fee_input() @@ -160,7 +160,7 @@ async fn submit() { .collect(); let tx = TransactionBuilder::script(script, vec![]) - .gas_limit(gas_limit) + .script_gas_limit(gas_limit) .gas_price(gas_price) .maturity(maturity) .add_random_fee_input() diff --git a/tests/tests/tx/predicates.rs b/tests/tests/tx/predicates.rs index b9d8e6fbdc7..526b14e416a 100644 --- a/tests/tests/tx/predicates.rs +++ b/tests/tests/tx/predicates.rs @@ -47,7 +47,7 @@ async fn transaction_with_valid_predicate_is_executed() { vec![], )) .add_output(Output::change(rng.gen(), 0, asset_id)) - .gas_limit(limit) + .script_gas_limit(limit) .finalize(); assert_eq!(predicate_tx.inputs()[0].predicate_gas_used().unwrap(), 0); @@ -159,7 +159,8 @@ async fn transaction_with_predicates_that_exhaust_gas_limit_are_rejected() { .expect_err("expected tx to fail"); assert!( - err.to_string().contains("PredicateExhaustedGas"), + err.to_string() + .contains("PredicateVerificationFailed(OutOfGas)"), "got unexpected error {err}" ) } diff --git a/tests/tests/tx/tx_pointer.rs b/tests/tests/tx/tx_pointer.rs index 3233215c933..61972596674 100644 --- a/tests/tests/tx/tx_pointer.rs +++ b/tests/tests/tx/tx_pointer.rs @@ -230,7 +230,7 @@ fn script_tx( change_owner: Address, ) -> Script { TransactionBuilder::script(vec![], vec![]) - .gas_limit(10000) + .script_gas_limit(10000) .gas_price(1) .add_unsigned_coin_input( secret_key, diff --git a/tests/tests/tx/txn_status_subscription.rs b/tests/tests/tx/txn_status_subscription.rs index 4fdd338df92..f5b481956e5 100644 --- a/tests/tests/tx/txn_status_subscription.rs +++ b/tests/tests/tx/txn_status_subscription.rs @@ -69,11 +69,12 @@ async fn subscribe_txn_status() { vec![], ); let mut tx: Transaction = Transaction::script( - gas_price + (i as u64), gas_limit, - maturity, script, vec![], + policies::Policies::new() + .with_gas_price(gas_price + (i as u64)) + .with_maturity(maturity), vec![coin_input], vec![], vec![], @@ -151,10 +152,9 @@ async fn test_regression_in_subscribe() { let mut empty_script = TransactionBuilder::script(vec![op::ret(0)].into_iter().collect(), vec![]); - empty_script.gas_limit(100000); + empty_script.script_gas_limit(100000); - let mut empty_create = TransactionBuilder::create(rng.gen(), rng.gen(), vec![]); - empty_create.gas_limit(100000); + let empty_create = TransactionBuilder::create(rng.gen(), rng.gen(), vec![]); let txs = [ empty_script.clone().add_input(coin_pred).finalize().into(), empty_create diff --git a/tests/tests/tx/txpool.rs b/tests/tests/tx/txpool.rs index 2be250f536c..ede0a23e271 100644 --- a/tests/tests/tx/txpool.rs +++ b/tests/tests/tx/txpool.rs @@ -22,7 +22,7 @@ use std::{ }; #[tokio::test] -async fn txs_max_gas_limit() { +async fn txs_max_script_gas_limit() { const MAX_GAS_LIMIT: u64 = 50_000_000; let mut rng = StdRng::seed_from_u64(2322); let mut test_builder = TestSetupBuilder::new(2322); @@ -34,7 +34,7 @@ async fn txs_max_gas_limit() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(MAX_GAS_LIMIT / 2) + .script_gas_limit(MAX_GAS_LIMIT / 2) .gas_price(1) .add_unsigned_coin_input( SecretKey::random(&mut rng), diff --git a/tests/tests/tx/utxo_validation.rs b/tests/tests/tx/utxo_validation.rs index f91aa63dfe3..4d4d846d8bf 100644 --- a/tests/tests/tx/utxo_validation.rs +++ b/tests/tests/tx/utxo_validation.rs @@ -38,7 +38,7 @@ async fn submit_utxo_verified_tx_with_min_gas_price() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(10000) + .script_gas_limit(10000) .gas_price(1) .add_unsigned_coin_input( SecretKey::random(&mut rng), @@ -111,7 +111,7 @@ async fn submit_utxo_verified_tx_below_min_gas_price_fails() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(100) + .script_gas_limit(100) .gas_price(1) .finalize_as_transaction(); @@ -145,7 +145,7 @@ async fn dry_run_override_utxo_validation() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(10000) + .script_gas_limit(10000) .add_input(Input::coin_signed( rng.gen(), rng.gen(), @@ -190,7 +190,7 @@ async fn dry_run_no_utxo_validation_override() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(1000) + .script_gas_limit(1000) .add_input(Input::coin_signed( rng.gen(), rng.gen(), @@ -235,7 +235,7 @@ async fn concurrent_tx_submission_produces_expected_blocks() { op::ret(RegId::ONE).to_bytes().into_iter().collect(), vec![], ) - .gas_limit(10000) + .script_gas_limit(10000) .add_unsigned_coin_input( secret, rng.gen(),