Skip to content
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

Allow full node to verify author inherent #192

Merged
merged 4 commits into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions pallets/author-inherent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,15 @@ impl<T: Config> ProvideInherent for Module<T> {
Some(Call::set_author(author))
}

fn check_inherent(_call: &Self::Call, data: &InherentData) -> Result<(), Self::Error> {
let author_raw = data
.get_data::<InherentType>(&INHERENT_IDENTIFIER)
.expect("Gets and decodes authorship inherent data")
.ok_or_else(|| {
InherentError::Other(sp_runtime::RuntimeString::Borrowed(
"Decode authorship inherent data failed",
))
})?;
let author =
T::AccountId::decode(&mut &author_raw[..]).expect("Decodes author raw inherent data");
ensure!(
T::CanAuthor::can_author(&author),
InherentError::Other(sp_runtime::RuntimeString::Borrowed("Cannot Be Author"))
);
fn check_inherent(call: &Self::Call, _data: &InherentData) -> Result<(), Self::Error> {
// This if let should always be true. This is the only call that the inherent could make.
if let Self::Call::set_author(claimed_author) = call {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why it is needed to set the author in the check.

Copy link
Contributor Author

@JoshOrndorff JoshOrndorff Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pattern matching call, the parameter that was passed into the function, against the variants of the Self::Call enum. set_author is not actually a function and I'm not calling it. It is a variant of the Self::Call enum. This is hard to read because typically enum variants are written in ThisCaseStandard. But the Call enum is an exception because of how the FRAME macros work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be worthy of a comment, although that's probably true of a lot of other cases...

ensure!(
T::CanAuthor::can_author(&claimed_author),
InherentError::Other(sp_runtime::RuntimeString::Borrowed("Cannot Be Author"))
);
}

Ok(())
}
}