-
Notifications
You must be signed in to change notification settings - Fork 245
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
fix: remove app-layer usage of transport error #363
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use crate::{ | |
utils::{self, Eip1559Estimation, EstimatorFunction}, | ||
PendingTransactionBuilder, | ||
}; | ||
use alloy_json_rpc::{RpcParam, RpcReturn}; | ||
use alloy_json_rpc::{RpcError, RpcParam, RpcReturn}; | ||
use alloy_network::{Network, TransactionBuilder}; | ||
use alloy_primitives::{ | ||
hex, Address, BlockHash, BlockNumber, Bytes, StorageKey, StorageValue, TxHash, B256, U256, U64, | ||
|
@@ -762,41 +762,25 @@ pub trait Provider<N: Network, T: Transport + Clone = BoxTransport>: Send + Sync | |
&self, | ||
estimator: Option<EstimatorFunction>, | ||
) -> TransportResult<Eip1559Estimation> { | ||
let base_fee_per_gas = match self.get_block_by_number(BlockNumberOrTag::Latest, false).await | ||
{ | ||
Ok(Some(block)) => match block.header.base_fee_per_gas { | ||
Some(base_fee_per_gas) => base_fee_per_gas, | ||
None => return Err(TransportErrorKind::custom_str("EIP-1559 not activated")), | ||
}, | ||
|
||
Ok(None) => return Err(TransportErrorKind::custom_str("Latest block not found")), | ||
|
||
Err(err) => return Err(err), | ||
}; | ||
|
||
let fee_history = match self | ||
.get_fee_history( | ||
let (bf, fee_history) = futures::try_join!( | ||
self.get_block_by_number(BlockNumberOrTag::Latest, false), | ||
self.get_fee_history( | ||
U256::from(utils::EIP1559_FEE_ESTIMATION_PAST_BLOCKS), | ||
BlockNumberOrTag::Latest, | ||
&[utils::EIP1559_FEE_ESTIMATION_REWARD_PERCENTILE], | ||
) | ||
.await | ||
{ | ||
Ok(fee_history) => fee_history, | ||
Err(err) => return Err(err), | ||
}; | ||
|
||
// use the provided fee estimator function, or fallback to the default implementation. | ||
let (max_fee_per_gas, max_priority_fee_per_gas) = if let Some(es) = estimator { | ||
es(base_fee_per_gas, &fee_history.reward.unwrap_or_default()) | ||
} else { | ||
utils::eip1559_default_estimator( | ||
base_fee_per_gas, | ||
&fee_history.reward.unwrap_or_default(), | ||
) | ||
}; | ||
|
||
Ok(Eip1559Estimation { max_fee_per_gas, max_priority_fee_per_gas }) | ||
)?; | ||
|
||
let base_fee_per_gas = bf | ||
.ok_or(RpcError::NullResp)? | ||
.header | ||
.base_fee_per_gas | ||
.ok_or(RpcError::UnsupportedFeature("eip1559"))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this makes sense |
||
|
||
Ok(estimator.unwrap_or(utils::eip1559_default_estimator)( | ||
base_fee_per_gas, | ||
&fee_history.reward.unwrap_or_default(), | ||
)) | ||
} | ||
|
||
/// Get the account and storage values of the specified account including the merkle proofs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could also fail with a
-32601, message: Method not found
rpc error for the fee_history call?
some providers also return -32600, message: Unsupported method:
so perhaps we should be less restrictive here and also check the rpc error response?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could assume any error response is also a reason to retry as a legacy
i'm not 100% convinced that retrying as legacy is the correct thing to do here, as forcing legacy could conflict with users who have already put blobs onto their transaction request. We may want to just return errors here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense, so the unsupported feature check is okay because this looks at the base fee value of the header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to write down somewhere that 1559 is somewhat privileged by the library in ways that other tx types and HF features are not. I.e. we generally assume that 1559 is active and proactively attempt to use it in gas estimation even tho we acknowledge that there may be chains that don't support it