After #2941 , there is an srml_support::traits::FindAuthor which is used to identify the author of a block based on information in a pre-runtime digest. It'll be implemented by modules like srml_babe and srml_aura.
However, what those modules will provide is (for chains using srml_session) only 1 part of the session key, and we want to fetch the account ID of the author.
In srml_session we'll want something like this:
struct SessionKeyLookup<SessionTrait, T, Index>(PhantomData<(SessionTrait, T, Index)>);
impl<Author, SessionTrait: session::Trait, Index: Typenum, T: FindAuthor<Author>> FindAuthor<SessionTrait::AccountId>
for SessionKeyLookup<SessionTrait, T, Index>
{
fn find_author(args...) -> Result<Option<SessionTrait::AccountId>, &'static str> {
let key = match T::find_author(args...)? {
Some(key) => key,
None => return Err("Session key lookup requires author to exist."),
};
let account: Option<SessionTrait::AccountId> = session::Module<SessionTrait>::some_lookup(key, Index::as_u32());
Ok(account.ok_or("unregistered session key")?)
}
}
It seems to require a lookup from (session::OpaqueKey, u32) -> AccountId which is probably O(n) in space or time.