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

Versioning of ConsensusParameters and GasCosts #701

Merged
merged 3 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

#### Breaking

- [#701](https://github.com/FuelLabs/fuel-vm/pull/701): Wrapped `ConsensusParameters` and `GasCosts` into an enum to support versioning. Moved `block_gas_limit` from `fuel_core_chain_config::ChainConfig` to `ConsensusPataremeters`. Reduced default `MAX_SIZE` to be [110kb](https://github.com/FuelLabs/fuel-core/pull/1761) and `MAX_CONTRACT_SIZE` to be [100kb](https://github.com/FuelLabs/fuel-core/pull/1761).
- [#692](https://github.com/FuelLabs/fuel-vm/pull/692): Add GTF getters for tx size and address.
- [#698](https://github.com/FuelLabs/fuel-vm/pull/698): Store input, output and witness limits to u16, while keeping the values limited to 255.

Expand Down
33 changes: 19 additions & 14 deletions fuel-tx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,43 +228,53 @@ impl<Tx> TransactionBuilder<Tx> {
}

pub fn with_tx_params(&mut self, tx_params: TxParameters) -> &mut Self {
self.params.tx_params = tx_params;
self.params.set_tx_params(tx_params);
self
}

pub fn with_predicate_params(
&mut self,
predicate_params: PredicateParameters,
) -> &mut Self {
self.params.predicate_params = predicate_params;
self.params.set_predicate_params(predicate_params);
self
}

pub fn with_script_params(&mut self, script_params: ScriptParameters) -> &mut Self {
self.params.script_params = script_params;
self.params.set_script_params(script_params);
self
}

pub fn with_contract_params(
&mut self,
contract_params: ContractParameters,
) -> &mut Self {
self.params.contract_params = contract_params;
self.params.set_contract_params(contract_params);
self
}

pub fn with_fee_params(&mut self, fee_params: FeeParameters) -> &mut Self {
self.params.fee_params = fee_params;
self.params.set_fee_params(fee_params);
self
}

pub fn with_base_asset_id(&mut self, base_asset_id: AssetId) -> &mut Self {
self.params.base_asset_id = base_asset_id;
pub fn with_chain_id(&mut self, chain_id: ChainId) -> &mut Self {
self.params.set_chain_id(chain_id);
self
}

pub fn with_gas_costs(&mut self, gas_costs: GasCosts) -> &mut Self {
self.params.gas_costs = gas_costs;
self.params.set_gas_costs(gas_costs);
self
}

pub fn with_base_asset_id(&mut self, base_asset_id: AssetId) -> &mut Self {
self.params.set_base_asset_id(base_asset_id);
self
}

pub fn with_block_gas_limit(&mut self, block_gas_limit: u64) -> &mut Self {
self.params.set_block_gas_limit(block_gas_limit);
self
}
}
Expand All @@ -288,11 +298,6 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
self
}

pub fn with_chain_id(&mut self, chain_id: ChainId) -> &mut Self {
self.params.chain_id = chain_id;
self
}

pub fn maturity(&mut self, maturity: BlockHeight) -> &mut Self {
self.tx.set_maturity(maturity);

Expand Down Expand Up @@ -405,7 +410,7 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
let witness_len = u16::try_from(self.witnesses().len())
.expect("The number of witnesses can't exceed `u16::MAX`");

if u32::from(witness_len) > self.params.tx_params.max_witnesses {
if u32::from(witness_len) > self.params.tx_params().max_witnesses {
panic!("Max witnesses exceeded");
}

Expand Down
4 changes: 0 additions & 4 deletions fuel-tx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ pub use transaction::{
UniqueIdentifier,
};

#[cfg(feature = "alloc")]
#[allow(deprecated)]
pub use transaction::consensus_parameters::default_parameters;

#[cfg(feature = "alloc")]
pub use contract::Contract;

Expand Down
1 change: 1 addition & 0 deletions fuel-tx/src/tests/valid_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn test_params() -> ConsensusParameters {
CHAIN_ID,
Default::default(),
Default::default(),
Default::default(),
)
}

Expand Down
8 changes: 6 additions & 2 deletions fuel-tx/src/tests/valid_cases/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,9 @@ fn script__check__transaction_at_maximum_size_is_valid() {
let block_height = 100.into();
let mut params = test_params();
let max_size = 1024usize;
params.tx_params.max_size = max_size as u64;
let mut tx_params = *params.tx_params();
tx_params.max_size = max_size as u64;
params.set_tx_params(tx_params);

let base_size = {
let tx = TransactionBuilder::script(vec![], vec![])
Expand Down Expand Up @@ -1038,7 +1040,9 @@ fn script__check__transaction_exceeding_maximum_size_is_invalid() {
let block_height = 100.into();
let mut params = test_params();
let max_size = 1024usize;
params.tx_params.max_size = max_size as u64;
let mut tx_params = *params.tx_params();
tx_params.max_size = max_size as u64;
params.set_tx_params(tx_params);

let base_size = {
let tx = TransactionBuilder::script(vec![], vec![])
Expand Down
Loading
Loading