Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: upgrade fuel-core to 24.2 #1319

Merged
merged 38 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6e97446
support new version
MujkicA Mar 31, 2024
6acf123
cleanup deps
MujkicA Apr 2, 2024
ab07095
fix config conversion
MujkicA Apr 2, 2024
c89bcc5
fix offsets and fuel-core-lib
MujkicA Apr 4, 2024
5e2e7cc
fix remaining tests
MujkicA Apr 4, 2024
f0dee99
minimize breaking changes
MujkicA Apr 4, 2024
32a432d
Merge branch 'master' of github.com:FuelLabs/fuels-rs into feature/up…
MujkicA Apr 4, 2024
fac5cb7
remove double import
MujkicA Apr 4, 2024
1a89c0e
removed unused deps
MujkicA Apr 4, 2024
b359318
fix gas test
MujkicA Apr 4, 2024
96d364d
Merge branch 'master' into feature/upgrade-fuel-core-0.24.1
MujkicA Apr 4, 2024
8d81ef8
use adjusted consensus params
MujkicA Apr 4, 2024
3c15188
Merge branch 'feature/upgrade-fuel-core-0.24.1' of github.com:FuelLab…
MujkicA Apr 4, 2024
944a544
gas tet adjustment
MujkicA Apr 4, 2024
ed9d38e
fmt
MujkicA Apr 4, 2024
624a926
fix flag
MujkicA Apr 4, 2024
3f812d0
rev comments
MujkicA Apr 4, 2024
317e080
return rocksdb test
MujkicA Apr 5, 2024
decd187
remove comment
MujkicA Apr 5, 2024
00e08cd
remove unneeded sub cfg
MujkicA Apr 5, 2024
eb26db5
Merge branch 'master' into feature/upgrade-fuel-core-0.24.1
MujkicA Apr 5, 2024
0e8d904
upgrade to 0.24.2
MujkicA Apr 5, 2024
7542689
adjust witness num check
MujkicA Apr 5, 2024
2d24a1a
Merge branch 'master' into feature/upgrade-fuel-core-0.24.1
hal3e Apr 5, 2024
f3ec863
Merge branch 'master' into feature/upgrade-fuel-core-0.24.1
segfault-magnet Apr 8, 2024
051ec31
restore rocksdb feature flag
MujkicA Apr 9, 2024
9554c17
Merge branch 'feature/upgrade-fuel-core-0.24.1' of github.com:FuelLab…
MujkicA Apr 9, 2024
7db61e1
fix base asset id
MujkicA Apr 9, 2024
629966a
return rocksdb to doc summary
MujkicA Apr 9, 2024
b05805c
cargo lint
MujkicA Apr 9, 2024
3beec05
mdbook lint
MujkicA Apr 9, 2024
501fcce
clippy
MujkicA Apr 9, 2024
850c8c7
fix gas estimation test
MujkicA Apr 9, 2024
9879094
Merge branch 'master' into feature/upgrade-fuel-core-0.24.1
MujkicA Apr 10, 2024
37e6662
Update packages/fuels-test-helpers/Cargo.toml
MujkicA Apr 10, 2024
cac0adb
Update packages/fuels-test-helpers/Cargo.toml
MujkicA Apr 10, 2024
2f62757
ensure temp dir cleanup in rocksdb test
MujkicA Apr 10, 2024
2afa282
Merge branch 'feature/upgrade-fuel-core-0.24.1' of github.com:FuelLab…
MujkicA Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.23.0
FUEL_CORE_VERSION: 0.24.2
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.76.0
FORC_VERSION: 0.52.1
Expand Down
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ which = { version = "6.0.0", default-features = false }
zeroize = "1.7.0"

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

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.47.1" }
fuel-crypto = { version = "0.47.1" }
fuel-merkle = { version = "0.47.1" }
fuel-storage = { version = "0.47.1" }
fuel-tx = { version = "0.47.1" }
fuel-types = { version = "0.47.1" }
fuel-vm = { version = "0.47.1" }
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" }

# Workspace projects
fuels = { version = "0.56.0", path = "./packages/fuels" }
Expand Down
10 changes: 8 additions & 2 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
mod tests {
use fuels::{
core::codec::{DecoderConfig, EncoderConfig},
prelude::{Config, LoadConfiguration, StorageConfiguration},
prelude::{LoadConfiguration, NodeConfig, StorageConfiguration},
test_helpers::{ChainConfig, StateConfig},
types::{
errors::{transaction::Reason, Result},
Bits256,
Expand All @@ -15,7 +16,12 @@ mod tests {
use fuels::prelude::{FuelService, Provider};

// Run the fuel node.
let server = FuelService::start(Config::default()).await?;
let server = FuelService::start(
NodeConfig::default(),
ChainConfig::default(),
StateConfig::default(),
)
.await?;

// Create a client that will talk to the node created above.
let client = Provider::from(server.bound_address()).await?;
Expand Down
14 changes: 6 additions & 8 deletions examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,9 @@ mod tests {
.with_max_inputs(2);
let fee_params = FeeParameters::default().with_gas_price_factor(10);

let consensus_parameters = ConsensusParameters {
tx_params,
fee_params,
..Default::default()
};
let mut consensus_parameters = ConsensusParameters::default();
consensus_parameters.set_tx_params(tx_params);
consensus_parameters.set_fee_params(fee_params);

let chain_config = ChainConfig {
consensus_parameters,
Expand All @@ -134,7 +132,7 @@ mod tests {
// ANCHOR_END: custom_chain_coins

// ANCHOR: custom_chain_provider
let node_config = Config::default();
let node_config = NodeConfig::default();
let _provider =
setup_test_provider(coins, vec![], Some(node_config), Some(chain_config)).await?;
// ANCHOR_END: custom_chain_provider
Expand Down Expand Up @@ -210,9 +208,9 @@ mod tests {

use fuels::prelude::*;
// ANCHOR: create_or_use_rocksdb
let provider_config = Config {
let provider_config = NodeConfig {
database_type: DbType::RocksDb(Some(PathBuf::from("/tmp/.spider/db"))),
..Config::default()
..NodeConfig::default()
};
// ANCHOR_END: create_or_use_rocksdb

Expand Down
2 changes: 1 addition & 1 deletion examples/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod tests {
use std::str::FromStr;

#[cfg(feature = "fuel-core-lib")]
use fuels::prelude::Config;
use fuels::prelude::NodeConfig;
use fuels::{
prelude::Result,
types::{Bits256, EvmAddress, Identity},
Expand Down
2 changes: 1 addition & 1 deletion packages/fuels-accounts/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ mod tests {
assert_eq!(signature, tx_signature);

// Check if the signature is what we expect it to be
assert_eq!(signature, Signature::from_str("37cf6bdefc9e673f99a7fdbbeff454cb5c1bdf632c072f19cf8ac68fa1ede2749c568c56f87d73fc5c97f73b76dfe637422b77c1fdc6010fb4f488444ff5df1a")?);
assert_eq!(signature, Signature::from_str("8afd30de7039faa07aac1cf2676970a77dc8ef3f779b44c1510ad7bf58ea56f43727b23142bd7252b79ae2c832e073927f84f6b0857fedf2f6d86e9535e48fd0")?);

// Recover the address that signed the transaction
let recovered_address = signature.recover(&message)?;
Expand Down
4 changes: 2 additions & 2 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Provider {
}

pub fn base_asset_id(&self) -> &AssetId {
&self.consensus_parameters.base_asset_id
self.consensus_parameters.base_asset_id()
}

fn ensure_client_version_is_supported(node_info: &NodeInfo) -> Result<()> {
Expand Down Expand Up @@ -276,7 +276,7 @@ impl Provider {
}

pub fn chain_id(&self) -> ChainId {
self.consensus_parameters.chain_id
self.consensus_parameters.chain_id()
}

pub async fn node_info(&self) -> Result<NodeInfo> {
Expand Down
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.23.0".parse().expect("is valid version")
"0.24.2".parse().expect("is valid version")
}

#[derive(Debug, PartialEq, Eq)]
Expand Down
66 changes: 36 additions & 30 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use async_trait::async_trait;
use fuel_asm::{op, GTFArgs, RegId};
use fuel_crypto::{Message as CryptoMessage, Signature};
use fuel_tx::{
field::{Inputs, Policies as PoliciesField, WitnessLimit, Witnesses},
field::{Inputs, Policies as PoliciesField, ScriptGasLimit, WitnessLimit, Witnesses},
input::coin::{CoinPredicate, CoinSigned},
policies::{Policies, PolicyType},
Buildable, Chargeable, ConsensusParameters, Create, Input as FuelInput, Output, Script,
StorageSlot, Transaction as FuelTransaction, TransactionFee, TxPointer, UniqueIdentifier,
Witness,
Chargeable, ConsensusParameters, Create, Input as FuelInput, Output, Script, StorageSlot,
Transaction as FuelTransaction, TransactionFee, TxPointer, UniqueIdentifier, Witness,
};
use fuel_types::{bytes::padded_len_usize, canonical::Serialize, Bytes32, ChainId, Salt};
use itertools::Itertools;
Expand Down Expand Up @@ -187,8 +186,8 @@ macro_rules! impl_tx_trait {
}

Ok(TransactionFee::checked_from_tx(
&consensus_parameters.gas_costs,
&consensus_parameters.fee_params,
&consensus_parameters.gas_costs(),
&consensus_parameters.fee_params(),
&tx.tx,
provider
.estimate_gas_price(self.gas_price_estimation_block_horizon)
Expand Down Expand Up @@ -288,17 +287,17 @@ macro_rules! impl_tx_trait {
.any(|input| matches!(input, Input::ResourcePredicate { .. }))
}

fn num_witnesses(&self) -> Result<u8> {
fn num_witnesses(&self) -> Result<u16> {
let num_witnesses = self.witnesses().len();

if num_witnesses + self.unresolved_signers.len() > 256 {
if num_witnesses + self.unresolved_signers.len() > u16::MAX as usize {
return Err(error_transaction!(
Builder,
"tx cannot have more than 256 witnesses"
"tx exceeds maximum number of witnesses"
));
}

Ok(num_witnesses as u8)
Ok(num_witnesses as u16)
}

fn calculate_witnesses_size(&self) -> Option<u64> {
Expand All @@ -318,7 +317,7 @@ macro_rules! impl_tx_trait {
let consensus_parameters = provider.consensus_parameters();

let tx_fee = TransactionFee::checked_from_tx(
&consensus_parameters.gas_costs,
&consensus_parameters.gas_costs(),
consensus_parameters.fee_params(),
tx,
gas_price,
Expand Down Expand Up @@ -362,7 +361,7 @@ pub struct ScriptTransactionBuilder {
#[derive(Default)]
pub struct CreateTransactionBuilder {
pub bytecode_length: u64,
pub bytecode_witness_index: u8,
pub bytecode_witness_index: u16,
pub storage_slots: Vec<StorageSlot>,
pub inputs: Vec<Input>,
pub outputs: Vec<Output>,
Expand Down Expand Up @@ -398,7 +397,7 @@ impl ScriptTransactionBuilder {
// However, the node will check if the right number of witnesses is present.
// This function will create witnesses from a default `Signature` such that the total length matches the expected one.
// Using a `Signature` ensures that the calculated fee includes the fee generated by the witnesses.
fn create_dry_run_witnesses(&self, num_witnesses: u8) -> Vec<Witness> {
fn create_dry_run_witnesses(&self, num_witnesses: u16) -> Vec<Witness> {
let unresolved_witnesses_len = self.unresolved_witness_indexes.owner_to_idx_offset.len();
let witness: Witness = Signature::default().as_ref().into();
repeat(witness)
Expand All @@ -408,12 +407,12 @@ impl ScriptTransactionBuilder {

fn no_base_asset_input<'a>(
inputs: impl IntoIterator<Item = &'a FuelInput>,
base_asset_id: AssetId,
base_asset_id: &AssetId,
) -> bool {
let has_base_asset = inputs.into_iter().any(|i| match i {
FuelInput::CoinSigned(CoinSigned { asset_id, .. })
| FuelInput::CoinPredicate(CoinPredicate { asset_id, .. })
if *asset_id == base_asset_id =>
if asset_id == base_asset_id =>
{
true
}
Expand All @@ -430,7 +429,7 @@ impl ScriptTransactionBuilder {
tolerance: f32,
) -> Result<()> {
let consensus_params = provider.consensus_parameters();
let base_asset_id = provider.consensus_parameters().base_asset_id;
let base_asset_id = provider.consensus_parameters().base_asset_id();

// The dry-run validation will check if there is any base asset input.
// If we are dry-running without inputs we have to add a temporary one.
Expand All @@ -454,7 +453,7 @@ impl ScriptTransactionBuilder {
// Get `max_gas` used by everything except the script execution. Add `1` because of rounding.
let max_gas = tx.max_gas(consensus_params.gas_costs(), consensus_params.fee_params()) + 1;
// Increase `script_gas_limit` to the maximum allowed value.
tx.set_script_gas_limit(consensus_params.tx_params().max_gas_per_tx - max_gas);
*tx.script_gas_limit_mut() = consensus_params.tx_params().max_gas_per_tx() - max_gas;

let gas_used = provider
.dry_run_and_get_used_gas(tx.clone().into(), tolerance)
Expand All @@ -467,7 +466,7 @@ impl ScriptTransactionBuilder {
tx.set_witness_limit(tx.witness_limit() - WITNESS_STATIC_SIZE as u64);
}

tx.set_script_gas_limit(gas_used);
*tx.script_gas_limit_mut() = gas_used;

Ok(())
}
Expand All @@ -494,11 +493,11 @@ impl ScriptTransactionBuilder {
);

if has_no_code {
tx.set_script_gas_limit(0);
*tx.script_gas_limit_mut() = 0;

// Use the user defined value even if it makes the transaction revert.
} else if let Some(gas_limit) = self.tx_policies.script_gas_limit() {
tx.set_script_gas_limit(gas_limit);
*tx.script_gas_limit_mut() = gas_limit;

// If the `script_gas_limit` was not set by the user,
// dry-run the tx to get the `gas_used`
Expand All @@ -515,7 +514,7 @@ impl ScriptTransactionBuilder {
.await?;

let missing_witnesses = generate_missing_witnesses(
tx.id(&provider.consensus_parameters().chain_id),
tx.id(&provider.consensus_parameters().chain_id()),
&self.unresolved_signers,
)
.await?;
Expand Down Expand Up @@ -665,7 +664,7 @@ impl CreateTransactionBuilder {
};

let tx = self
.resolve_fuel_tx(base_offset, &consensus_parameters.chain_id, &provider)
.resolve_fuel_tx(base_offset, &consensus_parameters.chain_id(), &provider)
.await?;

Ok(CreateTransaction {
Expand Down Expand Up @@ -720,7 +719,7 @@ impl CreateTransactionBuilder {
self
}

pub fn with_bytecode_witness_index(mut self, bytecode_witness_index: u8) -> Self {
pub fn with_bytecode_witness_index(mut self, bytecode_witness_index: u16) -> Self {
self.bytecode_witness_index = bytecode_witness_index;
self
}
Expand Down Expand Up @@ -781,7 +780,7 @@ impl CreateTransactionBuilder {
fn resolve_fuel_inputs(
inputs: Vec<Input>,
mut data_offset: usize,
num_witnesses: u8,
num_witnesses: u16,
unresolved_witness_indexes: &UnresolvedWitnessIndexes,
) -> Result<Vec<FuelInput>> {
inputs
Expand Down Expand Up @@ -821,7 +820,7 @@ fn resolve_fuel_inputs(
fn resolve_signed_resource(
resource: CoinType,
data_offset: &mut usize,
num_witnesses: u8,
num_witnesses: u16,
unresolved_witness_indexes: &UnresolvedWitnessIndexes,
) -> Result<FuelInput> {
match resource {
Expand All @@ -837,7 +836,7 @@ fn resolve_signed_resource(
"signature missing for coin with owner: `{owner:?}`"
))
.map(|witness_idx_offset| {
create_coin_input(coin, num_witnesses + *witness_idx_offset as u8)
create_coin_input(coin, num_witnesses + *witness_idx_offset as u16)
})
}
CoinType::Message(message) => {
Expand All @@ -852,7 +851,7 @@ fn resolve_signed_resource(
"signature missing for message with recipient: `{recipient:?}`"
))
.map(|witness_idx_offset| {
create_coin_message_input(message, num_witnesses + *witness_idx_offset as u8)
create_coin_message_input(message, num_witnesses + *witness_idx_offset as u16)
})
}
}
Expand Down Expand Up @@ -885,7 +884,7 @@ fn resolve_predicate_resource(
}
}

pub fn create_coin_input(coin: Coin, witness_index: u8) -> FuelInput {
pub fn create_coin_input(coin: Coin, witness_index: u16) -> FuelInput {
FuelInput::coin_signed(
coin.utxo_id,
coin.owner.into(),
Expand All @@ -896,7 +895,7 @@ pub fn create_coin_input(coin: Coin, witness_index: u8) -> FuelInput {
)
}

pub fn create_coin_message_input(message: Message, witness_index: u8) -> FuelInput {
pub fn create_coin_message_input(message: Message, witness_index: u16) -> FuelInput {
if message.data.is_empty() {
FuelInput::message_coin_signed(
message.sender.into(),
Expand Down Expand Up @@ -1069,11 +1068,18 @@ mod tests {
repeat_with(Witness::default).take(num_witnesses).collect()
}

#[derive(Default)]
struct MockDryRunner {
c_param: ConsensusParameters,
}

impl Default for MockDryRunner {
fn default() -> Self {
Self {
c_param: ConsensusParameters::standard(),
}
}
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl DryRunner for MockDryRunner {
Expand Down