feat: unify recover fn result type (#13897)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
DevOrbitlabs
2025-01-22 21:58:36 +07:00
committed by GitHub
parent 5170112c1f
commit 926ad2a639
24 changed files with 129 additions and 98 deletions

View File

@ -3,7 +3,7 @@ use alloc::{boxed::Box, string::String};
use alloy_eips::{BlockHashOrNumber, HashOrNumber};
use alloy_primitives::{Address, BlockHash, BlockNumber, TxNumber, B256};
use derive_more::Display;
use reth_primitives_traits::GotExpected;
use reth_primitives_traits::{transaction::signed::RecoveryError, GotExpected};
use reth_prune_types::PruneSegmentError;
use reth_static_file_types::StaticFileSegment;
@ -151,6 +151,12 @@ impl From<alloy_rlp::Error> for ProviderError {
}
}
impl From<RecoveryError> for ProviderError {
fn from(_: RecoveryError) -> Self {
Self::SenderRecoveryError
}
}
/// A root mismatch error at a given block height.
#[derive(Clone, Debug, PartialEq, Eq, Display)]
#[display("root mismatch at #{block_number} ({block_hash}): {root}")]

View File

@ -2640,7 +2640,7 @@ mod tests {
transaction_sender,
|block: &SealedBlock, tx_num: TxNumber, _: B256, _: &Vec<Vec<Receipt>>| (
tx_num,
block.body().transactions[test_tx_index].recover_signer()
block.body().transactions[test_tx_index].recover_signer().ok()
),
u64::MAX
),

View File

@ -693,9 +693,7 @@ impl<TX: DbTx + 'static, N: NodeTypesForProvider> DatabaseProvider<TX, N> {
match known_senders.get(&tx_num) {
None => {
// recover the sender from the transaction if not found
let sender = tx
.recover_signer_unchecked()
.ok_or(ProviderError::SenderRecoveryError)?;
let sender = tx.recover_signer_unchecked()?;
senders.push(sender);
}
Some(sender) => senders.push(*sender),

View File

@ -299,15 +299,14 @@ impl<N: NodePrimitives<SignedTx: Decompress + SignedTransaction>> TransactionsPr
range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Address>> {
let txs = self.transactions_by_tx_range(range)?;
reth_primitives_traits::transaction::recover::recover_signers(&txs)
.ok_or(ProviderError::SenderRecoveryError)
Ok(reth_primitives_traits::transaction::recover::recover_signers(&txs)?)
}
fn transaction_sender(&self, num: TxNumber) -> ProviderResult<Option<Address>> {
Ok(self
.cursor()?
.get_one::<TransactionMask<Self::Transaction>>(num.into())?
.and_then(|tx| tx.recover_signer()))
.and_then(|tx| tx.recover_signer().ok()))
}
}

View File

@ -1568,12 +1568,14 @@ impl<N: NodePrimitives<SignedTx: Decompress + SignedTransaction>> TransactionsPr
range: impl RangeBounds<TxNumber>,
) -> ProviderResult<Vec<Address>> {
let txes = self.transactions_by_tx_range(range)?;
reth_primitives_traits::transaction::recover::recover_signers(&txes)
.ok_or(ProviderError::SenderRecoveryError)
Ok(reth_primitives_traits::transaction::recover::recover_signers(&txes)?)
}
fn transaction_sender(&self, id: TxNumber) -> ProviderResult<Option<Address>> {
Ok(self.transaction_by_id_unhashed(id)?.and_then(|tx| tx.recover_signer()))
match self.transaction_by_id_unhashed(id)? {
Some(tx) => Ok(tx.recover_signer().ok()),
None => Ok(None),
}
}
}

View File

@ -368,7 +368,11 @@ impl TransactionsProvider for MockEthProvider {
.flat_map(|block| &block.body.transactions)
.enumerate()
.filter_map(|(tx_number, tx)| {
range.contains(&(tx_number as TxNumber)).then(|| tx.recover_signer()).flatten()
if range.contains(&(tx_number as TxNumber)) {
tx.recover_signer().ok()
} else {
None
}
})
.collect();