Fix FindAuthorAdapter (#19)

Current implementation was incorrect as `Babe::find_author` returns an
index, not the author's account.
Deferred the logic of looking up the author's account based on the index
to the `pallet_session::FindAccountFromAuthorIndex` function, and use
the existing conversion from `AccountId20` to `H160`.
This commit is contained in:
Steve Degosserie 2025-03-31 20:37:59 +02:00 committed by GitHub
parent b2031f4d00
commit 2cabedc223
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -340,16 +340,18 @@ impl FeeCalculator for TransactionPaymentAsGasPrice {
}
}
pub struct FindAuthorAdapter;
impl FindAuthor<H160> for FindAuthorAdapter {
pub struct FindAuthorAdapter<T>(core::marker::PhantomData<T>);
impl<T> FindAuthor<H160> for FindAuthorAdapter<T>
where
T: frame_system::Config + pallet_session::Config,
<T as pallet_session::Config>::ValidatorId: Into<H160>,
{
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (sp_runtime::ConsensusEngineId, &'a [u8])>,
{
if let Some(author) = Babe::find_author(digests) {
return Some(H160::from_slice(&author.encode()[0..20]));
}
None
pallet_session::FindAccountFromAuthorIndex::<T, Babe>::find_author(digests)
.map(|author| author.into())
}
}
@ -383,7 +385,7 @@ impl pallet_evm::Config for Runtime {
type Runner = pallet_evm::runner::stack::Runner<Self>;
type OnChargeTransaction = OnChargeEVMTransaction<()>;
type OnCreate = ();
type FindAuthor = FindAuthorAdapter;
type FindAuthor = FindAuthorAdapter<Self>;
type GasLimitPovSizeRatio = GasLimitPovSizeRatio;
type GasLimitStorageGrowthRatio = ();
type Timestamp = Timestamp;