From 23e7439ea8a1f545c42e2494e30aa6f100ed5948 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 20 Jan 2021 11:07:30 -0500 Subject: [PATCH 1/4] I think I found the issue. --- pallets/author-inherent/src/lib.rs | 49 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index 0a3b9617fc6..45943f7ce3a 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -195,21 +195,40 @@ impl ProvideInherent for Module { Some(Call::set_author(author)) } - fn check_inherent(_call: &Self::Call, data: &InherentData) -> Result<(), Self::Error> { - let author_raw = data - .get_data::(&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> { + use sp_std::if_std; + if_std!{ + println!("{:?}", call); + } + // This if let should always be true. This is the only call that the inehrent could make. + if let Self::Call::set_author(claimed_author) = call { + if_std!{ + println!("Made it into the if let"); + } + ensure!( + T::CanAuthor::can_author(&claimed_author), + InherentError::Other(sp_runtime::RuntimeString::Borrowed("Cannot Be Author")) + ); + } + + + // This is the old logic. It is incorrect because it is based on what the inherent would + // have contained if the verifying node created it, rather than the actual inherent + // that the actual author created. + // let author_raw = data + // .get_data::(&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")) + // ); Ok(()) } } From 0a1821f4c9bcec305e029852f3a2c5c2e835ed06 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 20 Jan 2021 11:37:10 -0500 Subject: [PATCH 2/4] clean up --- pallets/author-inherent/src/lib.rs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index 45943f7ce3a..f82254ef8fd 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -196,39 +196,14 @@ impl ProvideInherent for Module { } fn check_inherent(call: &Self::Call, data: &InherentData) -> Result<(), Self::Error> { - use sp_std::if_std; - if_std!{ - println!("{:?}", call); - } // This if let should always be true. This is the only call that the inehrent could make. if let Self::Call::set_author(claimed_author) = call { - if_std!{ - println!("Made it into the if let"); - } ensure!( T::CanAuthor::can_author(&claimed_author), InherentError::Other(sp_runtime::RuntimeString::Borrowed("Cannot Be Author")) ); } - - // This is the old logic. It is incorrect because it is based on what the inherent would - // have contained if the verifying node created it, rather than the actual inherent - // that the actual author created. - // let author_raw = data - // .get_data::(&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")) - // ); Ok(()) } } From bdaa268ca713a4a88bf2f6876f1e09c729029668 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 20 Jan 2021 12:22:52 -0500 Subject: [PATCH 3/4] unused variable --- pallets/author-inherent/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index f82254ef8fd..c3068148bdf 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -195,7 +195,7 @@ impl ProvideInherent for Module { Some(Call::set_author(author)) } - fn check_inherent(call: &Self::Call, data: &InherentData) -> Result<(), Self::Error> { + 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 inehrent could make. if let Self::Call::set_author(claimed_author) = call { ensure!( From b7a831a009f161d548405dfddc81ff75cc9ae715 Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Wed, 20 Jan 2021 12:34:05 -0500 Subject: [PATCH 4/4] Update pallets/author-inherent/src/lib.rs Co-authored-by: Amar Singh --- pallets/author-inherent/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/author-inherent/src/lib.rs b/pallets/author-inherent/src/lib.rs index c3068148bdf..637f1ac7c47 100644 --- a/pallets/author-inherent/src/lib.rs +++ b/pallets/author-inherent/src/lib.rs @@ -196,7 +196,7 @@ impl ProvideInherent for Module { } 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 inehrent could make. + // 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 { ensure!( T::CanAuthor::can_author(&claimed_author),