Skip to content

Commit

Permalink
Fuel Core v0.17.0 Upgrade (FuelLabs#3961)
Browse files Browse the repository at this point in the history
  • Loading branch information
Voxelot authored Feb 8, 2023
1 parent 8ba62b1 commit 67b37ce
Show file tree
Hide file tree
Showing 57 changed files with 716 additions and 630 deletions.
268 changes: 102 additions & 166 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

317 changes: 214 additions & 103 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ exclude = [

[profile.dev.package.sway-lsp]
debug = 2

[workspace.dependencies]
fuel-asm = "0.26"
fuel-crypto = "0.26"
fuel-tx = "0.26"
fuel-core-client = "0.17"
fuel-vm = "0.26"
fuels-core = "0.36.0"
fuels-signers = "0.36.0"
fuels-types = "0.36.0"
50 changes: 50 additions & 0 deletions ci_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# The script runs almost all CI checks locally.
#
# Tests below requires running `fuel-core` node locally:
# - `cargo run --locked --release --bin test -- --locked`
#
# You can install `fuel-core` node by:
# `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.16.1 --locked`
#
# And run it with:
# `fuel-core run --db-type in-memory`

# Requires installed:
# `cargo install cargo-sort`
# `cargo install cargo-generate`
# `cargo install cargo-udeps`

cargo clippy --all-features --all-targets &&
cargo sort -w --check &&
cargo sort -w --check templates/sway-test-rs/template &&
cargo fmt --all -- --check &&
cargo build --locked --workspace --all-features --all-targets &&
cargo test --locked &&
cargo +nightly udeps --locked --all-targets &&
cargo install --locked --debug --path ./forc &&
cargo install --locked --debug --path ./forc-plugins/forc-fmt &&
cargo install --locked --debug --path ./forc-plugins/forc-lsp &&
cargo install --locked --debug --path ./forc-plugins/forc-client &&
cargo install --locked --debug --path ./forc-plugins/forc-tx &&
cargo install --locked --debug forc-explore &&
cargo install --locked --debug --path ./scripts/mdbook-forc-documenter &&
forc build --path sway-lib-core &&
forc test --path sway-lib-core &&
forc build --path sway-lib-std &&
forc test --path sway-lib-std &&
cargo run --locked --bin examples-checker build --all-examples &&
cargo run --locked --bin examples-checker fmt --all-examples &&
rm -Rf test-proj &&
forc new test-proj &&
echo "std = { path = \"../sway-lib-std/\" }" >> test-proj/Forc.toml &&
forc build --path test-proj &&
(cd test-proj && cargo generate --init --path ../templates/sway-test-rs --name test-proj) &&
echo "[workspace]" >> test-proj/Cargo.toml &&
(cd test-proj && cargo test) &&
rm -R test-proj &&
cargo run --locked --release --bin test -- --target evm --locked &&
(cd test/src/sdk-harness && bash build.sh --locked) &&
cargo test --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture &&
cargo run --locked --release --bin test -- --locked
12 changes: 7 additions & 5 deletions forc-plugins/forc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ forc-pkg = { version = "0.34.0", path = "../../forc-pkg" }
forc-tracing = { version = "0.34.0", path = "../../forc-tracing" }
forc-tx = { version = "0.34.0", path = "../forc-tx" }
forc-util = { version = "0.34.0", path = "../../forc-util" }
fuel-gql-client = { version = "0.15", default-features = false }
fuel-tx = { version = "0.23", features = ["builder"] }
fuels-core = "0.33"
fuels-signers = "0.33"
fuels-types = "0.33"
fuel-core-client = { workspace = true, default-features = false }
fuel-crypto = { workspace = true }
fuel-tx = { workspace = true, features = ["builder"] }
fuel-vm = { workspace = true }
fuels-core = { workspace = true }
fuels-signers = { workspace = true }
fuels-types = { workspace = true }
futures = "0.3"
hex = "0.4.3"
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/cmd/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use fuel_gql_client::fuel_crypto::SecretKey;
use fuel_crypto::SecretKey;

pub use forc::cli::shared::{BuildOutput, BuildProfile, Minify, Pkg, Print};
pub use forc_tx::Gas;
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use fuel_gql_client::fuel_crypto::SecretKey;
use fuel_crypto::SecretKey;

pub use forc::cli::shared::{BuildOutput, BuildProfile, Minify, Pkg, Print};
pub use forc_tx::Gas;
Expand Down
10 changes: 4 additions & 6 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ use crate::{
};
use anyhow::{bail, Context, Result};
use forc_pkg::{self as pkg, PackageManifestFile};
use fuel_gql_client::client::types::TransactionStatus;
use fuel_gql_client::{
client::FuelClient,
fuel_tx::{Output, Salt, TransactionBuilder},
fuel_vm::prelude::*,
};
use fuel_core_client::client::types::TransactionStatus;
use fuel_core_client::client::FuelClient;
use fuel_tx::{Output, Salt, TransactionBuilder};
use fuel_vm::prelude::*;
use futures::FutureExt;
use pkg::BuiltPackage;
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/op/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use anyhow::{anyhow, bail, Context, Result};
use forc_pkg::{self as pkg, fuel_core_not_running, PackageManifestFile};
use forc_util::format_log_receipts;
use fuel_gql_client::client::FuelClient;
use fuel_core_client::client::FuelClient;
use fuel_tx::{ContractId, Transaction, TransactionBuilder, UniqueIdentifier};
use futures::TryFutureExt;
use pkg::BuiltPackage;
Expand Down
11 changes: 4 additions & 7 deletions forc-plugins/forc-client/src/util/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ use std::{io::Write, str::FromStr};

use anyhow::{Error, Result};
use async_trait::async_trait;
use fuel_gql_client::{
client::FuelClient,
fuel_crypto::{Message, SecretKey, Signature},
fuel_tx::{Address, ContractId, Input, Output, TransactionBuilder, Witness},
prelude::SerializableVec,
};
use fuel_tx::{field, Buildable};
use fuel_core_client::client::FuelClient;
use fuel_crypto::{Message, SecretKey, Signature};
use fuel_tx::{field, Address, Buildable, ContractId, Input, Output, TransactionBuilder, Witness};
use fuel_vm::prelude::SerializableVec;
use fuels_core::constants::BASE_ASSET_ID;
use fuels_signers::{provider::Provider, Wallet};
use fuels_types::bech32::Bech32Address;
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-doc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ description = "Build the documentation for the local package and all dependencie
[dependencies]
anyhow = "1.0.65"
clap = { version = "4.0.18", features = ["derive"] }
comrak = "0.15"
comrak = "0.16"
forc-pkg = { version = "0.34.0", path = "../../forc-pkg" }
forc-util = { version = "0.34.0", path = "../../forc-util"}
forc-util = { version = "0.34.0", path = "../../forc-util" }
horrorshow = "0.8.4"
include_dir = "0.7.3"
opener = "0.5.0"
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-tx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ path = "src/main.rs"
anyhow = "1"
clap = { version = "3", features = ["derive", "env"] }
devault = "0.1"
fuel-tx = { version = "0.23", features = ["serde"] }
fuel-tx = { workspace = true, features = ["serde"] }
serde = "1.0"
serde_json = { version = "1" }
4 changes: 2 additions & 2 deletions forc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ description = "A library for building and running Sway unit tests within Forc pa
[dependencies]
anyhow = "1"
forc-pkg = { version = "0.34.0", path = "../forc-pkg" }
fuel-tx = { version = "0.23", features = ["builder"] }
fuel-vm = { version = "0.22", features = ["random"] }
fuel-tx = { workspace = true, features = ["builder"] }
fuel-vm = { workspace = true, features = ["random"] }
rand = "0.8"
sway-core = { version = "0.34.0", path = "../sway-core" }
sway-types = { version = "0.34.0", path = "../sway-types" }
18 changes: 11 additions & 7 deletions forc-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{collections::HashMap, fs, path::PathBuf, sync::Arc};

use forc_pkg as pkg;
use fuel_tx as tx;
use fuel_vm::{self as vm, prelude::Opcode};
use fuel_vm::checked_transaction::builder::TransactionBuilderExt;
use fuel_vm::gas::GasCosts;
use fuel_vm::{self as vm, fuel_asm, prelude::Instruction};
use pkg::TestPassCondition;
use pkg::{Built, BuiltPackage, CONTRACT_ID_CONSTANT_NAME};
use rand::{Rng, SeedableRng};
Expand Down Expand Up @@ -405,7 +407,8 @@ fn deploy_test_contract(built_pkg: BuiltPackage) -> anyhow::Result<TestSetup> {
// Setup the interpreter for deployment.
let params = tx::ConsensusParameters::default();
let storage = vm::storage::MemoryStorage::default();
let mut interpreter = vm::interpreter::Interpreter::with_storage(storage, params);
let mut interpreter =
vm::interpreter::Interpreter::with_storage(storage, params, GasCosts::default());

// Create the deployment transaction.
let mut rng = rand::rngs::StdRng::seed_from_u64(TEST_METADATA_SEED);
Expand All @@ -423,7 +426,7 @@ fn deploy_test_contract(built_pkg: BuiltPackage) -> anyhow::Result<TestSetup> {
.add_unsigned_coin_input(secret_key, utxo_id, amount, asset_id, tx_pointer, maturity)
.add_output(tx::Output::contract_created(contract_id, state_root))
.maturity(maturity)
.finalize_checked(block_height, &params);
.finalize_checked(block_height, &params, &GasCosts::default());

// Deploy the contract.
interpreter.transact(tx)?;
Expand Down Expand Up @@ -471,15 +474,15 @@ fn run_tests(built: BuiltTests) -> anyhow::Result<Tested> {
fn patch_test_bytecode(bytecode: &[u8], test_offset: u32) -> std::borrow::Cow<[u8]> {
// TODO: Standardize this or add metadata to bytecode.
const PROGRAM_START_INST_OFFSET: u32 = 6;
const PROGRAM_START_BYTE_OFFSET: usize = PROGRAM_START_INST_OFFSET as usize * Opcode::LEN;
const PROGRAM_START_BYTE_OFFSET: usize = PROGRAM_START_INST_OFFSET as usize * Instruction::SIZE;

// If our desired entry point is the program start, no need to jump.
if test_offset == PROGRAM_START_INST_OFFSET {
return std::borrow::Cow::Borrowed(bytecode);
}

// Create the jump instruction and splice it into the bytecode.
let ji = Opcode::JI(test_offset);
let ji = fuel_asm::op::ji(test_offset);
let ji_bytes = ji.to_bytes();
let start = PROGRAM_START_BYTE_OFFSET;
let end = start + ji_bytes.len();
Expand Down Expand Up @@ -537,9 +540,10 @@ fn exec_test(
state_root: tx::Bytes32::zeroed(),
});
}
let tx = tx.finalize_checked(block_height, &params);
let tx = tx.finalize_checked(block_height, &params, &GasCosts::default());

let mut interpreter = vm::interpreter::Interpreter::with_storage(storage, params);
let mut interpreter =
vm::interpreter::Interpreter::with_storage(storage, params, GasCosts::default());

// Execute and return the result.
let start = std::time::Instant::now();
Expand Down
1 change: 0 additions & 1 deletion forc-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ ansi_term = "0.12"
anyhow = "1"
dirs = "3.0.2"
forc-tracing = { version = "0.34.0", path = "../forc-tracing" }
fuel-tx = { version = "0.23", features = ["builder"] }
hex = "0.4.3"
serde_json = "1.0.73"
sway-core = { version = "0.34.0", path = "../sway-core" }
Expand Down
1 change: 1 addition & 0 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use forc_tracing::{println_green_err, println_red_err, println_yellow_err};
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use std::str;
use sway_core::fuel_prelude::fuel_tx;
use sway_core::language::parsed::TreeType;
use sway_error::error::CompileError;
use sway_error::warning::CompileWarning;
Expand Down
2 changes: 1 addition & 1 deletion forc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ forc-test = { version = "0.34.0", path = "../forc-test" }
forc-tracing = { version = "0.34.0", path = "../forc-tracing" }
forc-util = { version = "0.34.0", path = "../forc-util" }
fs_extra = "1.2"
fuel-asm = "0.10"
fuel-asm = { workspace = true }
hex = "0.4.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.73"
Expand Down
45 changes: 21 additions & 24 deletions forc/src/cli/commands/parse_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ pub(crate) fn exec(command: Command) -> Result<()> {
.map_err(|_| anyhow!("{}: file not found", command.file_path))?;
let mut buffer = vec![0; metadata.len() as usize];
f.read_exact(&mut buffer).expect("buffer overflow");
let mut instructions = vec![];

for i in (0..buffer.len()).step_by(4) {
let raw = &buffer[i..i + 4];
unsafe {
let op = fuel_asm::Opcode::from_bytes_unchecked(raw);
instructions.push((raw, op));
};
}
let instructions = fuel_asm::from_bytes(buffer.iter().cloned())
.zip(buffer.chunks(fuel_asm::Instruction::SIZE));

let mut table = term_table::Table::new();
table.separate_rows = false;
table.add_row(Row::new(vec![
Expand All @@ -38,34 +33,36 @@ pub(crate) fn exec(command: Command) -> Result<()> {
TableCell::new("notes"),
]));
table.style = term_table::TableStyle::empty();
for (word_ix, instruction) in instructions.iter().enumerate() {
use fuel_asm::Opcode::*;
let notes = match instruction.1 {
JI(num) => format!("jump to byte {}", num * 4),
JNEI(_, _, num) => format!("conditionally jump to byte {}", num * 4),
JNZI(_, num) => format!("conditionally jump to byte {}", num * 4),
Undefined if word_ix == 2 || word_ix == 3 => {
let parsed_raw = u32::from_be_bytes([
instruction.0[0],
instruction.0[1],
instruction.0[2],
instruction.0[3],
]);
for (word_ix, (result, raw)) in instructions.enumerate() {
use fuel_asm::Instruction;
let notes = match result {
Ok(Instruction::JI(ji)) => format!("jump to byte {}", u32::from(ji.imm24()) * 4),
Ok(Instruction::JNEI(jnei)) => {
format!("conditionally jump to byte {}", u32::from(jnei.imm12()) * 4)
}
Ok(Instruction::JNZI(jnzi)) => {
format!("conditionally jump to byte {}", u32::from(jnzi.imm18()) * 4)
}
Err(fuel_asm::InvalidOpcode) if word_ix == 2 || word_ix == 3 => {
let parsed_raw = u32::from_be_bytes([raw[0], raw[1], raw[2], raw[3]]);
format!(
"data section offset {} ({})",
if word_ix == 2 { "lo" } else { "hi" },
parsed_raw
)
}
_ => "".into(),
Ok(_) | Err(fuel_asm::InvalidOpcode) => "".into(),
};
table.add_row(Row::new(vec![
TableCell::new_with_alignment(word_ix, 1, Alignment::Right),
TableCell::new(word_ix * 4),
TableCell::new(format!("{:?}", instruction.1)),
TableCell::new(match result {
Ok(inst) => format!("{inst:?}"),
Err(err) => format!("{err:?}"),
}),
TableCell::new(format!(
"{:02x} {:02x} {:02x} {:02x}",
instruction.0[0], instruction.0[1], instruction.0[2], instruction.0[3],
raw[0], raw[1], raw[2], raw[3],
)),
TableCell::new(notes),
]));
Expand Down
2 changes: 1 addition & 1 deletion scripts/examples-checker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ publish = false

[dependencies]
anyhow = "1.0.41"
clap = { version = "3.1", features = ["env", "derive"] }
clap = { version = "3.1", features = ["env", "derive"] }
3 changes: 1 addition & 2 deletions scripts/mdbook-forc-documenter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ path = "src/bin/mdbook-forc-documenter.rs"
name = "mdbook_forc_documenter"
path = "src/lib.rs"


[dependencies]
anyhow = "1"
clap = { version = "3.1", features = [ "derive" ] }
clap = { version = "3.1", features = [ "derive" ] }
mdbook = { version = "0.4", default-features = false }
semver = "1.0"
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ etk-asm = { package = "fuel-etk-asm", version = "0.3.1-dev", features = ["backtr
etk-dasm = { package = "fuel-etk-dasm", version = "0.3.1-dev" }
etk-ops = { package = "fuel-etk-ops", version = "0.3.1-dev" }
fuel-abi-types = "0.1"
fuel-vm = { version = "0.22", features = ["serde"] }
fuel-vm = { workspace = true, features = ["serde"] }
hashbrown = "0.13.1"
hex = { version = "0.4", optional = true }
im = "15.0"
Expand Down
7 changes: 3 additions & 4 deletions sway-core/src/asm_generation/finalized_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sway_error::error::CompileError;
use sway_types::span::Span;

use either::Either;
use std::{collections::BTreeMap, fmt, io::Read};
use std::{collections::BTreeMap, fmt};

/// Represents an ASM set which has had register allocation, jump elimination, and optimization
/// applied to it
Expand Down Expand Up @@ -143,14 +143,13 @@ fn to_bytecode_mut(
if ops.len() > 1 {
buf.resize(buf.len() + ((ops.len() - 1) * 4), 0);
}
for mut op in ops {
for op in ops {
if let Some(span) = &span {
source_map.insert(half_word_ix, span);
}
let read_range_upper_bound =
core::cmp::min(half_word_ix * 4 + std::mem::size_of_val(&op), buf.len());
op.read_exact(&mut buf[half_word_ix * 4..read_range_upper_bound])
.expect("Failed to write to in-memory buffer.");
buf[half_word_ix * 4..read_range_upper_bound].copy_from_slice(&op.to_bytes());
half_word_ix += 1;
}
}
Expand Down
Loading

0 comments on commit 67b37ce

Please sign in to comment.