Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

FindAuthor wrapper for Session #2949

@rphmeier

Description

@rphmeier

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    J0-enhancementAn additional feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions