Skip to content

Commit

Permalink
fuel core 0.13 upgrade (#657)
Browse files Browse the repository at this point in the history
WIP to upgrade to fuel-core 0.13 with the new generic tx format

sway tests were compiled using forc from this PR:
FuelLabs/sway#3181

Because there were breaking changes to the fuel-vm opcodes, we have to
check in the compiled sway files for now until a new version of forc can
be released. However, releasing forc is blocked on the SDK supporting
fuel-core 0.13, so the upgrades were done concurrently.

Co-authored-by: green <xgreenx9999@gmail.com>
  • Loading branch information
2 people authored and MujkicA committed Nov 4, 2022
1 parent 659eec3 commit 150eebc
Show file tree
Hide file tree
Showing 194 changed files with 5,405 additions and 373 deletions.
84 changes: 43 additions & 41 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v1.24.3/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.11.2
FUEL_CORE_VERSION: 0.13.1
RUST_VERSION: 1.64.0
FORC_VERSION: 0.28.1
FORC_VERSION: 0.29.0

jobs:
setup-test-projects:
Expand All @@ -39,32 +39,32 @@ jobs:
run: |
git config --global core.bigfilethreshold 100m
- name: Install Forc
run: |
curl -sSLf https://github.com/FuelLabs/sway/releases/download/v${{ env.FORC_VERSION }}/forc-binaries-linux_amd64.tar.gz -L -o forc.tar.gz
tar -xvf forc.tar.gz
chmod +x forc-binaries/forc
mv forc-binaries/forc /usr/local/bin/forc
- name: Build Sway Examples
uses: actions-rs/cargo@v1
with:
command: run
args: --bin build-test-projects

- uses: actions/upload-artifact@v2
with:
retention-days: 2
name: sway-examples
# cache only the sway build artifacts, skip all src files
path: |
packages/fuels/tests
!packages/fuels/tests/*.rs
!packages/fuels/tests/**/*.rs
!packages/fuels/tests/**/*.sw
!packages/fuels/tests/**/Forc.toml
!packages/fuels/tests/**/Forc.lock
!packages/fuels/tests/.gitignore
# - name: Install Forc
# run: |
# curl -sSLf https://github.com/FuelLabs/sway/releases/download/v${{ env.FORC_VERSION }}/forc-binaries-linux_amd64.tar.gz -L -o forc.tar.gz
# tar -xvf forc.tar.gz
# chmod +x forc-binaries/forc
# mv forc-binaries/forc /usr/local/bin/forc
#
# - name: Build Sway Examples
# uses: actions-rs/cargo@v1
# with:
# command: run
# args: --bin build-test-projects

# - uses: actions/upload-artifact@v2
# with:
# retention-days: 2
# name: sway-examples
# # cache only the sway build artifacts, skip all src files
# path: |
# packages/fuels/tests
# !packages/fuels/tests/*.rs
# !packages/fuels/tests/**/*.rs
# !packages/fuels/tests/**/*.sw
# !packages/fuels/tests/**/Forc.toml
# !packages/fuels/tests/**/Forc.lock
# !packages/fuels/tests/.gitignore

get-workspace-members:
runs-on: ubuntu-latest
Expand All @@ -78,8 +78,8 @@ jobs:
# install dasel
curl -sSLf "$DASEL_VERSION" -L -o dasel && chmod +x dasel
mv ./dasel /usr/local/bin/dasel
members=$(cat Cargo.toml | dasel -r toml -w json 'workspace.members' | jq -r ".[]" | xargs -L 1 basename | jq -R '[.]' | jq -s -c 'add')
echo "::set-output name=members::$members"
members=$(cat Cargo.toml | dasel -r toml -w json 'workspace.members' | jq -r ".[]" | xargs -I '{}' dasel -f {}/Cargo.toml 'package.name' | jq -R '[.]' | jq -s -c 'add')
echo "members=$members" >> $GITHUB_OUTPUT
verify-rust-version:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -117,14 +117,16 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}
override: true
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the cache plugin, as it uses the current rustc version as its cache key
- uses: Swatinem/rust-cache@v1
- uses: Swatinem/rust-cache@v2.0.1
continue-on-error: true
with:
key: "${{ matrix.command }} ${{ matrix.args }} ${{ matrix.package }}"
Expand All @@ -135,10 +137,10 @@ jobs:

- name: Install WebAssembly Test harness
if: ${{ matrix.command == 'test' }}
uses: actions-rs/cargo@v1
uses: baptiste0928/cargo-install@v1
with:
command: install
args: webassembly-test-runner
crate: webassembly-test-runner
cache-key: '${{ matrix.command }} ${{ matrix.args }} ${{ matrix.package }}'

# TODO: Enable WASM tests
# - name: Test WASM package
Expand All @@ -164,12 +166,12 @@ jobs:
if: ${{ matrix.command == 'clippy' }}
run: rustup component add clippy

- name: Download sway example artifacts
if: ${{ matrix.command == 'test' || matrix.command == 'clippy' }}
uses: actions/download-artifact@v3
with:
name: sway-examples
path: packages/fuels/tests/
# - name: Download sway example artifacts
# if: ${{ matrix.command == 'test' || matrix.command == 'clippy' }}
# uses: actions/download-artifact@v3
# with:
# name: sway-examples
# path: packages/fuels/tests/

- name: Cargo (workspace-level)
if: ${{ !matrix.package }}
Expand All @@ -183,7 +185,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: ${{ matrix.command }}
args: ${{ matrix.args }}
args: -p ${{ matrix.package }} ${{ matrix.args }}

- name: Check Docs. Validity
uses: actions-rs/cargo@v1
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docs/book/
packages/fuels/tests/**/**/Forc.lock

# Don't add out/ files from test Sway projects.
packages/fuels/tests/**/**/out/
# packages/fuels/tests/**/**/out/

# Don't add target/ files from test Sway projects.
packages/fuels/tests/**/**/target/
3 changes: 3 additions & 0 deletions examples/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ description = "Fuel Rust SDK contract examples."
fuels = { version = "0.27.0", path = "../../packages/fuels" }
rand = "0.8"
tokio = { version = "1.10", features = ["full"] }

[features]
fuel-core-lib = ["fuels/fuel-core-lib"]
12 changes: 6 additions & 6 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod tests {
.await?;
// ANCHOR_END: contract_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 592);
assert_eq!(transaction_cost.gas_used, 7146);

Ok(())
}
Expand Down Expand Up @@ -451,11 +451,11 @@ mod tests {
let contract_methods = MyContract::new(contract_id, wallet.clone()).methods();

// ANCHOR: call_params_gas
// Set the transaction `gas_limit` to 1000 and `gas_forwarded` to 200 to specify that the
// contract call transaction may consume up to 1000 gas, while the actual call may only use 200
// Set the transaction `gas_limit` to 10000 and `gas_forwarded` to 3000 to specify that the
// contract call transaction may consume up to 10000 gas, while the actual call may only use 3000
// gas
let tx_params = TxParameters::new(None, Some(1000), None);
let call_params = CallParameters::new(None, None, Some(200));
let tx_params = TxParameters::new(None, Some(10000), None);
let call_params = CallParameters::new(None, None, Some(3000));

let response = contract_methods
.get_msg_amount() // Our contract method.
Expand Down Expand Up @@ -554,7 +554,7 @@ mod tests {
.await?;
// ANCHOR_END: multi_call_cost_estimation

assert_eq!(transaction_cost.gas_used, 1006);
assert_eq!(transaction_cost.gas_used, 15176);

Ok(())
}
Expand Down
1 change: 0 additions & 1 deletion examples/predicates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ mod tests {
all_coins,
vec![],
Some(Config {
predicates: true,
utxo_validation: true,
..Config::local_node()
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ description = "Fuel Rust SDK contracts."
[dependencies]
anyhow = "1"
bytes = { version = "1.0.1", features = ["serde"] }
fuel-gql-client = { version = "0.11.2", default-features = false }
fuel-tx = "0.20.2"
fuel-gql-client = { version = "0.13", default-features = false }
fuel-tx = "0.23"
fuels-core = { version = "0.27.0", path = "../fuels-core" }
fuels-signers = { version = "0.27.0", path = "../fuels-signers" }
fuels-types = { version = "0.27.0", path = "../fuels-types" }
Expand Down
7 changes: 4 additions & 3 deletions packages/fuels-contract/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use fuel_gql_client::{
fuel_tx::{Contract as FuelContract, Output, Receipt, StorageSlot, Transaction},
fuel_types::{Address, AssetId, Salt},
};
use fuel_tx::{Checkable, Create};

use fuels_core::abi_decoder::ABIDecoder;
use fuels_core::abi_encoder::{ABIEncoder, UnresolvedBytes};
Expand Down Expand Up @@ -239,8 +240,8 @@ impl Contract {
let provider = wallet.get_provider()?;
let chain_info = provider.chain_info().await?;

tx.validate_without_signature(
chain_info.latest_block.height.0,
tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;
provider.send_transaction(&tx).await?;
Expand Down Expand Up @@ -303,7 +304,7 @@ impl Contract {
pub async fn contract_deployment_transaction(
compiled_contract: &CompiledContract,
params: TxParameters,
) -> Result<(Transaction, Bech32ContractId), Error> {
) -> Result<(Create, Bech32ContractId), Error> {
let bytecode_witness_index = 0;
let storage_slots: Vec<StorageSlot> = compiled_contract.storage_slots.clone();
let witnesses = vec![compiled_contract.raw.clone().into()];
Expand Down
50 changes: 23 additions & 27 deletions packages/fuels-contract/src/script.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use anyhow::Result;
use fuel_gql_client::fuel_tx::{ConsensusParameters, Receipt, Transaction};
use fuel_gql_client::fuel_tx::{Input, Output, TxPointer, UtxoId};
use fuel_gql_client::fuel_tx::{
field::Script as ScriptField, ConsensusParameters, Input, Output, Receipt, Transaction,
TxPointer, UtxoId,
};
use fuel_gql_client::fuel_types::{
bytes::padded_len_usize, AssetId, Bytes32, ContractId, Immediate18, Word,
};
use fuel_gql_client::fuel_vm::{consts::REG_ONE, prelude::Opcode};
use itertools::{chain, Itertools};

use fuel_gql_client::client::schema::coin::Coin;
use fuel_tx::{Metadata, ScriptExecutionResult, Witness};
use fuel_tx::{Checkable, ScriptExecutionResult, Witness};
use fuels_core::parameters::TxParameters;
use fuels_signers::provider::Provider;
use fuels_signers::{Signer, WalletUnlocked};
Expand All @@ -33,7 +35,7 @@ struct CallParamOffsets {
/// Script provides methods to create and a call/simulate a
/// script transaction that carries out contract method calls
pub struct Script {
pub tx: Transaction,
pub tx: fuels_core::tx::Script,
}

#[derive(Debug, Clone)]
Expand All @@ -43,7 +45,7 @@ pub struct CompiledScript {
}

impl Script {
pub fn new(tx: Transaction) -> Self {
pub fn new(tx: fuels_core::tx::Script) -> Self {
Self { tx }
}

Expand Down Expand Up @@ -365,16 +367,16 @@ impl Script {
len_script += Opcode::LEN;

ConsensusParameters::DEFAULT.tx_offset()
+ Transaction::script_offset()
+ fuel_tx::Script::script_offset_static()
+ padded_len_usize(len_script)
}

/// Execute the transaction in a state-modifying manner.
pub async fn call(self, provider: &Provider) -> Result<Vec<Receipt>, Error> {
let chain_info = provider.chain_info().await?;

self.tx.validate_without_signature(
chain_info.latest_block.height.0,
self.tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;

Expand All @@ -385,12 +387,12 @@ impl Script {
pub async fn simulate(self, provider: &Provider) -> Result<Vec<Receipt>, Error> {
let chain_info = provider.chain_info().await?;

self.tx.validate_without_signature(
chain_info.latest_block.height.0,
self.tx.check_without_signatures(
chain_info.latest_block.header.height.0,
&chain_info.consensus_parameters.into(),
)?;

let receipts = provider.dry_run(&self.tx).await?;
let receipts = provider.dry_run(&self.tx.clone().into()).await?;
if receipts
.iter()
.any(|r|
Expand Down Expand Up @@ -879,13 +881,11 @@ pub struct ScriptBuilder {
gas_price: Word,
gas_limit: Word,
maturity: Word,
receipts_root: Bytes32,
script: Vec<u8>,
script_data: Vec<u8>,
inputs: Vec<Input>,
outputs: Vec<Output>,
witnesses: Vec<Witness>,
metadata: Option<Metadata>,
asset_id: AssetId,
amount: u64,
}
Expand All @@ -896,13 +896,11 @@ impl ScriptBuilder {
gas_price: 0,
gas_limit: 0,
maturity: 0,
receipts_root: Default::default(),
script: vec![],
script_data: vec![],
inputs: vec![],
outputs: vec![],
witnesses: vec![],
metadata: None,
asset_id: AssetId::default(),
amount: 0,
}
Expand Down Expand Up @@ -955,18 +953,16 @@ impl ScriptBuilder {
}

pub async fn build(self, wallet: &WalletUnlocked) -> Result<Script, Error> {
let mut tx = Transaction::Script {
gas_price: self.gas_price,
gas_limit: self.gas_limit,
maturity: self.maturity,
receipts_root: self.receipts_root,
script: self.script,
script_data: self.script_data,
inputs: self.inputs,
outputs: self.outputs,
witnesses: self.witnesses,
metadata: self.metadata,
};
let mut tx = Transaction::script(
self.gas_price,
self.gas_limit,
self.maturity,
self.script,
self.script_data,
self.inputs.to_vec(),
self.outputs.to_vec(),
self.witnesses.to_vec(),
);

let base_amount = if self.asset_id == AssetId::default() {
self.amount
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description = "Fuel Rust SDK core."
[dependencies]
Inflector = "0.11"
anyhow = "1"
fuel-tx = "0.20.2"
fuel-tx = "0.23"
fuel-types = "0.5"
fuels-types = { version = "0.27.0", path = "../fuels-types" }
hex = { version = "0.4.3", features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const DEFAULT_MATURITY: u64 = 0;
// ANCHOR: default_call_parameters
pub const DEFAULT_CALL_PARAMS_AMOUNT: u64 = 0;
// Bytes representation of the asset ID of the "base" asset used for gas fees.
pub const BASE_ASSET_ID: AssetId = AssetId::new([0u8; 32]);
pub const BASE_ASSET_ID: AssetId = AssetId::BASE;
// ANCHOR_END: default_call_parameters

pub const BASE_MESSAGE_ID: MessageId = MessageId::zeroed();
Expand Down
Loading

0 comments on commit 150eebc

Please sign in to comment.