Skip to content

Commit

Permalink
chore!: remove option return from predicate estimation (#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
segfault-magnet authored Jan 14, 2025
1 parent 3b03063 commit 19d32bc
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 83 deletions.
6 changes: 3 additions & 3 deletions packages/fuels-accounts/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ mod tests {
Ok(0)
}

async fn maybe_estimate_predicates(
async fn estimate_predicates(
&self,
_: &FuelTransaction,
_: Option<u32>,
) -> Result<Option<FuelTransaction>> {
Ok(None)
) -> Result<FuelTransaction> {
unimplemented!()
}
}

Expand Down
8 changes: 3 additions & 5 deletions packages/fuels-accounts/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,14 +869,12 @@ impl DryRunner for Provider {
Ok(self.estimate_gas_price(block_horizon).await?.gas_price)
}

async fn maybe_estimate_predicates(
async fn estimate_predicates(
&self,
tx: &FuelTransaction,
_latest_chain_executor_version: Option<u32>,
) -> Result<Option<FuelTransaction>> {
// We always delegate the estimation to the client because estimating locally is no longer
// possible due to the need of blob storage
Ok(Some(self.uncached_client().estimate_predicates(tx).await?))
) -> Result<FuelTransaction> {
Ok(self.uncached_client().estimate_predicates(tx).await?)
}

async fn consensus_parameters(&self) -> Result<ConsensusParameters> {
Expand Down
10 changes: 5 additions & 5 deletions packages/fuels-core/src/types/dry_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub trait DryRunner: Send + Sync {
async fn dry_run(&self, tx: FuelTransaction) -> Result<DryRun>;
async fn estimate_gas_price(&self, block_horizon: u32) -> Result<u64>;
async fn consensus_parameters(&self) -> Result<ConsensusParameters>;
async fn maybe_estimate_predicates(
async fn estimate_predicates(
&self,
tx: &FuelTransaction,
latest_chain_executor_version: Option<u32>,
) -> Result<Option<FuelTransaction>>;
) -> Result<FuelTransaction>;
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
Expand All @@ -48,13 +48,13 @@ impl<T: DryRunner> DryRunner for &T {
(*self).consensus_parameters().await
}

async fn maybe_estimate_predicates(
async fn estimate_predicates(
&self,
tx: &FuelTransaction,
latest_chain_executor_version: Option<u32>,
) -> Result<Option<FuelTransaction>> {
) -> Result<FuelTransaction> {
(*self)
.maybe_estimate_predicates(tx, latest_chain_executor_version)
.estimate_predicates(tx, latest_chain_executor_version)
.await
}
}
6 changes: 3 additions & 3 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,12 +1584,12 @@ mod tests {
Ok(0)
}

async fn maybe_estimate_predicates(
async fn estimate_predicates(
&self,
_tx: &FuelTransaction,
_: Option<u32>,
) -> Result<Option<FuelTransaction>> {
Ok(None)
) -> Result<FuelTransaction> {
unimplemented!("")
}
}

Expand Down
94 changes: 27 additions & 67 deletions packages/fuels-core/src/types/wrappers/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,19 +548,11 @@ impl EstimablePredicates for UploadTransaction {
provider: impl DryRunner,
latest_chain_executor_version: Option<u32>,
) -> Result<()> {
if let Some(tx) = provider
.maybe_estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?
{
tx.as_upload().expect("is upload").clone_into(&mut self.tx);
} else {
// We no longer estimate locally since we don't have the blob storage.
// maybe_estimate_predicates should always return an estimation
return Err(error!(
Other,
"Should have been given an estimation from the node. This is a bug."
));
}
let tx = provider
.estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?;

tx.as_upload().expect("is upload").clone_into(&mut self.tx);

Ok(())
}
Expand All @@ -574,21 +566,13 @@ impl EstimablePredicates for UpgradeTransaction {
provider: impl DryRunner,
latest_chain_executor_version: Option<u32>,
) -> Result<()> {
if let Some(tx) = provider
.maybe_estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?
{
tx.as_upgrade()
.expect("is upgrade")
.clone_into(&mut self.tx);
} else {
// We no longer estimate locally since we don't have the blob storage.
// maybe_estimate_predicates should always return an estimation
return Err(error!(
Other,
"Should have been given an estimation from the node. This is a bug."
));
}
let tx = provider
.estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?;

tx.as_upgrade()
.expect("is upgrade")
.clone_into(&mut self.tx);

Ok(())
}
Expand All @@ -602,19 +586,11 @@ impl EstimablePredicates for CreateTransaction {
provider: impl DryRunner,
latest_chain_executor_version: Option<u32>,
) -> Result<()> {
if let Some(tx) = provider
.maybe_estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?
{
tx.as_create().expect("is create").clone_into(&mut self.tx);
} else {
// We no longer estimate locally since we don't have the blob storage.
// maybe_estimate_predicates should always return an estimation
return Err(error!(
Other,
"Should have been given an estimation from the node. This is a bug."
));
}
let tx = provider
.estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?;

tx.as_create().expect("is create").clone_into(&mut self.tx);

Ok(())
}
Expand Down Expand Up @@ -642,19 +618,11 @@ impl EstimablePredicates for ScriptTransaction {
provider: impl DryRunner,
latest_chain_executor_version: Option<u32>,
) -> Result<()> {
if let Some(tx) = provider
.maybe_estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?
{
tx.as_script().expect("is script").clone_into(&mut self.tx);
} else {
// We no longer estimate locally since we don't have the blob storage.
// maybe_estimate_predicates should always return an estimation
return Err(error!(
Other,
"Should have been given an estimation from the node. This is a bug."
));
}
let tx = provider
.estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?;

tx.as_script().expect("is script").clone_into(&mut self.tx);

Ok(())
}
Expand All @@ -668,19 +636,11 @@ impl EstimablePredicates for BlobTransaction {
provider: impl DryRunner,
latest_chain_executor_version: Option<u32>,
) -> Result<()> {
if let Some(tx) = provider
.maybe_estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?
{
tx.as_blob().expect("is blob").clone_into(&mut self.tx);
} else {
// We no longer estimate locally since we don't have the blob storage.
// maybe_estimate_predicates should always return an estimation
return Err(error!(
Other,
"Should have been given an estimation from the node. This is a bug."
));
}
let tx = provider
.estimate_predicates(&self.tx.clone().into(), latest_chain_executor_version)
.await?;

tx.as_blob().expect("is blob").clone_into(&mut self.tx);

Ok(())
}
Expand Down

0 comments on commit 19d32bc

Please sign in to comment.