Substrate: Authorship Pallet: Author storage is never set

Created on 4 Jun 2020  路  4Comments  路  Source: paritytech/substrate

Pallet authorship is supposed to extract the authorship information during on_initialize and store the author in a storage item. The write to storage happens here and appears to be correct to me.

But empirically, the storage item always contains none. Steps to reproduce:

  1. cargo run --release -- --dev and let a few blocks go by.
  2. Use polkadot JS Apps (or another tool) to query Authorship Author storage.
  3. Observe that None is stored.

The same author-not-set behavior happens with --chain local. It also happens when I install the authorship pallet in the node template and use Aura directly as the source of authorship information.

Z0-unconfirmed

All 4 comments

@JoshOrndorff I tested this by adding a print statement.

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
    fn on_nonzero_unbalanced(amount: NegativeImbalance) {
        let author = Authorship::author(); 
        if_std! {println!{"On unblanced author: {:#?} !", &author}};
        Balances::resolve_creating(&author, amount);
    }
}

Output

On unblanced author: d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d (5GrwvaEF...) !

Looks like the authorship pallet is storing it correctly however the UI is having troubles displaying the value, so this might be a bug for polkadotjs/apps

author is killed in on_finalize
https://github.com/paritytech/substrate/blob/3451ed181988ebc1c838c041578ff0f6a99d9864/frame/authorship/src/lib.rs#L204-L208

I guess one correct way to get the author offchain is to look at the pre_runtime_digest

Yes it is indeed killed so it is only ephemeral for the duration of the block execution. @thiolliere pointed out the documentation. You can still use it in the process of the block execution to for instance pay the author.

I understand now. The author is inserted in on_initialize, remains available while executing all the extrinsics, and is killed in on_finalize. Works as expected. Thanks :+1:

Was this page helpful?
0 / 5 - 0 ratings