Skip to content

Comments

[author-inherent] Move kick_off_authorship_validation() to post_inherents()#93

Open
arturgontijo wants to merge 1 commit intomainfrom
artur/post-inherents
Open

[author-inherent] Move kick_off_authorship_validation() to post_inherents()#93
arturgontijo wants to merge 1 commit intomainfrom
artur/post-inherents

Conversation

@arturgontijo
Copy link
Contributor

This PR moves the kick_off_authorship_validation() logic to the post_inherents().

It also adds integrity_test() hook with some checks.

Note: Do we need more integrity checks there? I decided to keep tests.rs simple as this new approach is.

As we see here, integrity_tests is also being tested too.

➜  moonkit git:(artur/post-inherents) cargo test -p pallet-author-inherent                                                        
warning: profile package spec `cranelift-wasm` in profile `dev` did not match any packages
    Finished `test` profile [unoptimized + debuginfo] target(s) in 1.27s
     Running unittests src/lib.rs (target/debug/deps/pallet_author_inherent-95dea1c55ff74551)

running 3 tests
test mock::__construct_runtime_integrity_test::runtime_integrity_tests ... ok
test mock::test_genesis_config_builds ... ok
test tests::test_author_is_extracted_and_stored_from_pre_runtime_digest ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

@arturgontijo arturgontijo self-assigned this Feb 9, 2026
// TODO better weight. For now we just set a somewhat conservative fudge factor
#[pallet::call_index(0)]
#[pallet::weight((T::WeightInfo::kick_off_authorship_validation(), DispatchClass::Mandatory))]
pub fn kick_off_authorship_validation(origin: OriginFor<T>) -> DispatchResultWithPostInfo {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is still referenced in benchmarks pallets/author-inherent/src/benchmarks.rs and weights pallets/author-inherent/src/weights.rs.

You can run cargo build --features runtime-benchmarks to check.

// https://github.com/paritytech/polkadot-sdk/issues/2841#issuecomment-1876040854
fn integrity_test() {
// Test that SlotBeacon can be called and returns a valid slot
let slot = T::SlotBeacon::slot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really test what is mentioned in the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was just to check if it can be called, as it returns u32 that is then used in the can_author() call.

T::CanAuthor::can_author(&Self::get(), &new_slot),
"Block invalid, supplied author is not eligible."
// Test that CanAuthor trait can be called
let _ = Pallet::<T>::can_author(
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are discarding the result of the call without testing "// Test that CanAuthor trait can be called".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The result is false as we are not touching storage there. Not sure if we should touch it though.

<Author<T>>::put(&author);
} else {
None
panic!("Block invalid, missing author in pre-runtime digest");
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be useful to add a #[should_panic] test to test this branch of execution.


[features]
default = [ "std" ]
std = [
Copy link
Contributor

Choose a reason for hiding this comment

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

Add sp-core/std

sp-api = { workspace = true }
sp-application-crypto = { workspace = true }
sp-core = { workspace = true }
sp-inherents = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be removed

Copy link
Contributor

Choose a reason for hiding this comment

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

The GH line comment is not very clear, I mean sp-inherents = { workspace = true }

@@ -15,6 +15,7 @@
scale-info = { workspace = true }
sp-api = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be removed

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here for sp-api = { workspace = true }

@@ -22,13 +22,10 @@

extern crate alloc;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this can be removed

// You should have received a copy of the GNU General Public License
// along with Moonkit. If not, see <http://www.gnu.org/licenses/>.

//! Pallet that allows block authors to include their identity in a block via an inherent.
Copy link
Contributor

Choose a reason for hiding this comment

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

Outdated

//! Pallet that extracts the block author identity from the pre-runtime digest and validates
//! eligibility via a `PostInherents` hook. Currently the author does not _prove_ their identity,
//! just states it. So it should not be used for things like equivocation slashing that require
//! authenticated authorship information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants