Skip to content

Commit

Permalink
feat: upgrade fuel-core to 0.26.0 (#1336)
Browse files Browse the repository at this point in the history
Upgrades fuel-core to 0.26.0 and fuel-vm to 0.49.0. Support for upgrade and upload transaction types is not fully implemented.
  • Loading branch information
MujkicA authored May 3, 2024
1 parent e898aea commit 52e25a6
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.24.3
FUEL_CORE_VERSION: 0.26.0
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.76.0
FORC_VERSION: 0.56.0
Expand Down
31 changes: 17 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ itertools = "0.12.0"
portpicker = "0.1.1"
proc-macro2 = "1.0.70"
quote = "1.0.33"
rand = { version = "0.8.5", default-features = false, features = ["std_rng", "getrandom"] }
rand = { version = "0.8.5", default-features = false, features = [
"std_rng",
"getrandom",
] }
regex = "1.10.2"
semver = "1.0.20"
serde = { version = "1.0.193", default-features = false }
Expand All @@ -72,21 +75,21 @@ which = { version = "6.0.0", default-features = false }
zeroize = "1.7.0"

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.24.3", default-features = false }
fuel-core-chain-config = { version = "0.24.3", default-features = false }
fuel-core-client = { version = "0.24.3", default-features = false }
fuel-core-poa = { version = "0.24.3", default-features = false }
fuel-core-services = { version = "0.24.3", default-features = false }
fuel-core-types = { version = "0.24.3", default-features = false }
fuel-core = { version = "0.26.0", default-features = false }
fuel-core-chain-config = { version = "0.26.0", default-features = false }
fuel-core-client = { version = "0.26.0", default-features = false }
fuel-core-poa = { version = "0.26.0", default-features = false }
fuel-core-services = { version = "0.26.0", default-features = false }
fuel-core-types = { version = "0.26.0", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.48.0" }
fuel-crypto = { version = "0.48.0" }
fuel-merkle = { version = "0.48.0" }
fuel-storage = { version = "0.48.0" }
fuel-tx = { version = "0.48.0" }
fuel-types = { version = "0.48.0" }
fuel-vm = { version = "0.48.0" }
fuel-asm = { version = "0.49.0" }
fuel-crypto = { version = "0.49.0" }
fuel-merkle = { version = "0.49.0" }
fuel-storage = { version = "0.49.0" }
fuel-tx = { version = "0.49.0" }
fuel-types = { version = "0.49.0" }
fuel-vm = { version = "0.49.0" }

# Workspace projects
fuels = { version = "0.59.0", path = "./packages/fuels" }
Expand Down
4 changes: 3 additions & 1 deletion packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ impl Provider {
TransactionExecutionResult::Success { receipts, .. } => {
TxStatus::Success { receipts }
}
TransactionExecutionResult::Failed { receipts, result } => TxStatus::Revert {
TransactionExecutionResult::Failed {
receipts, result, ..
} => TxStatus::Revert {
reason: TransactionExecutionResult::reason(&receipts, &result),
receipts,
revert_id: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/provider/supported_versions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use semver::Version;

fn get_supported_fuel_core_version() -> Version {
"0.24.2".parse().expect("is valid version")
"0.26.0".parse().expect("is valid version")
}

#[derive(Debug, PartialEq, Eq)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl ConfigurablesBoundedEncoder {
fn encode_raw_slice(mut data: Vec<u8>) -> Result<Vec<Data>> {
let len = data.len();

zeropad_to_word_alignment(&mut data);
zeropad_to_word_alignment(&mut data)?;

let encoded_data = vec![Data::Inline(data)];

Expand All @@ -261,15 +261,14 @@ impl ConfigurablesBoundedEncoder {
}

fn encode_string_array(arg_string: &StaticStringToken) -> Result<Data> {
Ok(Data::Inline(crate::types::pad_string(
arg_string.get_encodable_str()?,
)))
let padded = crate::types::pad_string(arg_string.get_encodable_str()?)?;
Ok(Data::Inline(padded))
}

fn encode_bytes(mut data: Vec<u8>) -> Result<Vec<Data>> {
let len = data.len();

zeropad_to_word_alignment(&mut data);
zeropad_to_word_alignment(&mut data)?;

let cap = data.len() as u64;
let encoded_data = vec![Data::Inline(data)];
Expand All @@ -282,7 +281,11 @@ impl ConfigurablesBoundedEncoder {
}
}

fn zeropad_to_word_alignment(data: &mut Vec<u8>) {
let padded_length = padded_len_usize(data.len());
fn zeropad_to_word_alignment(data: &mut Vec<u8>) -> Result<()> {
let padded_length = padded_len_usize(data.len())
.ok_or_else(|| error!(Codec, "data length exceeds maximum allowed length"))?;

data.resize(padded_length, 0);

Ok(())
}
9 changes: 6 additions & 3 deletions packages/fuels-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use fuel_types::{
};

pub use crate::types::{core::*, token::*, wrappers::*};
use crate::{error, types::errors::Result};

pub mod bech32;
mod core;
Expand Down Expand Up @@ -33,12 +34,14 @@ pub fn pad_u32(value: u32) -> ByteArray {
padded
}

pub fn pad_string(s: &str) -> Vec<u8> {
let pad = padded_len(s.as_bytes()) - s.len();
pub fn pad_string(s: &str) -> Result<Vec<u8>> {
let padded_len =
padded_len(s.as_bytes()).ok_or_else(|| error!(Codec, "string is too long to be padded"))?;
let pad = padded_len - s.len();

let mut padded = s.as_bytes().to_owned();

padded.extend_from_slice(&vec![0; pad]);

padded
Ok(padded)
}
2 changes: 0 additions & 2 deletions packages/fuels-core/src/types/core/raw_slice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[derive(Debug, PartialEq, Clone, Eq)]
// `RawSlice` is a mapping of the contract type "untyped raw slice" -- currently the only way of
// returning dynamically sized data from a script.
pub struct RawSlice(pub Vec<u8>);

impl From<RawSlice> for Vec<u8> {
Expand Down
1 change: 0 additions & 1 deletion packages/fuels-core/src/types/core/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
};

construct_uint! {
/// 256-bit unsigned integer.
pub struct U256(4);
}

Expand Down
52 changes: 28 additions & 24 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use itertools::Itertools;

use crate::{
constants::{SIGNATURE_WITNESS_SIZE, WITNESS_STATIC_SIZE, WORD_SIZE},
offsets,
error, offsets,
traits::Signer,
types::{
bech32::Bech32Address,
Expand Down Expand Up @@ -263,22 +263,19 @@ macro_rules! impl_tx_trait {
.collect();
}

fn generate_fuel_policies(&self) -> Policies {
let mut policies = Policies::default();
fn generate_fuel_policies(&self) -> Result<Policies> {
let witness_limit = match self.tx_policies.witness_limit() {
Some(limit) => limit,
None => self.calculate_witnesses_size()?,
};
let mut policies = Policies::default().with_witness_limit(witness_limit);

// `MaxFee` set to `tip` or `0` for `dry_run`
policies.set(PolicyType::MaxFee, self.tx_policies.tip().or(Some(0)));

policies.set(PolicyType::Maturity, self.tx_policies.maturity());

let witness_limit = self
.tx_policies
.witness_limit()
.or_else(|| self.calculate_witnesses_size());
policies.set(PolicyType::WitnessLimit, witness_limit);

policies.set(PolicyType::Tip, self.tx_policies.tip());

policies
Ok(policies)
}

fn is_using_predicates(&self) -> bool {
Expand All @@ -300,12 +297,14 @@ macro_rules! impl_tx_trait {
Ok(num_witnesses as u16)
}

fn calculate_witnesses_size(&self) -> Option<u64> {
fn calculate_witnesses_size(&self) -> Result<u64> {
let witnesses_size = calculate_witnesses_size(&self.witnesses);
let signature_size = SIGNATURE_WITNESS_SIZE
* self.unresolved_witness_indexes.owner_to_idx_offset.len();

Some(padded_len_usize(witnesses_size + signature_size) as u64)
let padded_len = padded_len_usize(witnesses_size + signature_size)
.ok_or_else(|| error!(Other, "witnesses size overflow"))?;
Ok(padded_len as u64)
}

async fn set_max_fee_policy<T: PoliciesField + Chargeable>(
Expand Down Expand Up @@ -380,7 +379,7 @@ impl ScriptTransactionBuilder {
async fn build(self, provider: impl DryRunner) -> Result<ScriptTransaction> {
let is_using_predicates = self.is_using_predicates();
let base_offset = if is_using_predicates {
self.base_offset(provider.consensus_parameters())
self.base_offset(provider.consensus_parameters())?
} else {
0
};
Expand Down Expand Up @@ -473,7 +472,7 @@ impl ScriptTransactionBuilder {

async fn resolve_fuel_tx(self, base_offset: usize, provider: impl DryRunner) -> Result<Script> {
let num_witnesses = self.num_witnesses()?;
let policies = self.generate_fuel_policies();
let policies = self.generate_fuel_policies()?;

let has_no_code = self.script.is_empty();
let dry_run_witnesses = self.create_dry_run_witnesses(num_witnesses);
Expand Down Expand Up @@ -523,10 +522,15 @@ impl ScriptTransactionBuilder {
Ok(tx)
}

fn base_offset(&self, consensus_parameters: &ConsensusParameters) -> usize {
offsets::base_offset_script(consensus_parameters)
+ padded_len_usize(self.script_data.len())
+ padded_len_usize(self.script.len())
fn base_offset(&self, consensus_parameters: &ConsensusParameters) -> Result<usize> {
let padded_script_data_len = padded_len_usize(self.script_data.len())
.ok_or_else(|| error!(Other, "script data len overflow {}", self.script_data.len()))?;
let padded_script_len = padded_len_usize(self.script.len())
.ok_or_else(|| error!(Other, "script len overflow {}", self.script.len()))?;

Ok(offsets::base_offset_script(consensus_parameters)
+ padded_script_data_len
+ padded_script_len)
}

pub fn with_script(mut self, script: Vec<u8>) -> Self {
Expand Down Expand Up @@ -680,7 +684,7 @@ impl CreateTransactionBuilder {
provider: impl DryRunner,
) -> Result<Create> {
let num_witnesses = self.num_witnesses()?;
let policies = self.generate_fuel_policies();
let policies = self.generate_fuel_policies()?;

let storage_slots_offset = self.storage_slots.len() * StorageSlot::SLOT_SIZE;
base_offset += storage_slots_offset + policies.size_dynamic();
Expand Down Expand Up @@ -840,7 +844,7 @@ fn resolve_signed_resource(
})
}
CoinType::Message(message) => {
*data_offset += offsets::message_signed_data_offset(message.data.len());
*data_offset += offsets::message_signed_data_offset(message.data.len())?;
let recipient = &message.recipient;

unresolved_witness_indexes
Expand All @@ -865,7 +869,7 @@ fn resolve_predicate_resource(
) -> Result<FuelInput> {
match resource {
CoinType::Coin(coin) => {
*data_offset += offsets::coin_predicate_data_offset(code.len());
*data_offset += offsets::coin_predicate_data_offset(code.len())?;

let data = data.resolve(*data_offset as u64);
*data_offset += data.len();
Expand All @@ -874,7 +878,7 @@ fn resolve_predicate_resource(
Ok(create_coin_predicate(coin, asset_id, code, data))
}
CoinType::Message(message) => {
*data_offset += offsets::message_predicate_data_offset(message.data.len(), code.len());
*data_offset += offsets::message_predicate_data_offset(message.data.len(), code.len())?;

let data = data.resolve(*data_offset as u64);
*data_offset += data.len();
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-core/src/types/wrappers/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use fuel_core_client::client::types::{
pub struct Header {
pub id: Bytes32,
pub da_height: u64,
pub transactions_count: u64,
pub message_receipt_count: u64,
pub transactions_count: u16,
pub message_receipt_count: u32,
pub transactions_root: Bytes32,
pub message_outbox_root: Bytes32,
pub event_inbox_root: Bytes32,
Expand Down
3 changes: 2 additions & 1 deletion packages/fuels-core/src/types/wrappers/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

use fuel_core_chain_config::MessageConfig;
use fuel_core_client::client::types::{
coins::MessageCoin as ClientMessageCoin, message::Message as ClientMessage, primitives::Nonce,
coins::MessageCoin as ClientMessageCoin, message::Message as ClientMessage,
};
use fuel_tx::{Input, MessageId};
use fuel_types::Nonce;

use crate::types::bech32::Bech32Address;

Expand Down
Loading

0 comments on commit 52e25a6

Please sign in to comment.