Skip to content

How to use find_author to get H160 ethereum address of block author? #1783

@hayotensor

Description

@hayotensor

Question

How can the chain get the current block author when running ./target/release/frontier-node-template --dev and deposit balance to it?

Using

let digest = frame_system::Pallet::<T>::digest();
let pre_runtime_digests = digest.logs.iter().filter_map(|d| d.as_pre_runtime());
let author = T::FindAuthor::find_author(pre_runtime_digests).unwrap_or_default();
let account_id = T::AddressMapping::into_account_id(author);

While running in --dev mode returns 0x15fdd31c61141abd04a99fd6822c8558854ccde3 which isn't Aliths account.

What I'm a bit confused about is in chain_spec, we have:

// H160 address of Alice dev account
// Derived from SS58 (42 prefix) address
// SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
// hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
// Using the full hex key, truncating to the first 20 bytes (the first 40 hex chars)
H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558")
	.expect("internal H160 is valid; qed"),
fp_evm::GenesisAccount {
	balance: U256::from_str("0xffffffffffffffffffffffffffffffff")
		.expect("internal U256 is valid; qed"),
	code: Default::default(),
	nonce: Default::default(),
	storage: Default::default(),
},

And in genesis_config_preset we have:

// H160 address of Alice dev account
// Derived from SS58 (42 prefix) address
// SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
// hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d
// Using the full hex key, truncating to the first 20 bytes (the first 40 hex chars)
H160::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
fp_evm::GenesisAccount {
	balance: U256::MAX,
	code: Default::default(),
	nonce: Default::default(),
	storage: Default::default(),
},

The comments are the same, but the resulting addresses differ. I'm wondering if I'm missing something or if this is a typo, and which one is right?

When using the following in place of FindAuthorTruncated (not overriding it, just another way to use find_author in a test pallet) :

pub struct FindAuthorTruncatedV2<F>(PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncatedV2<F> {
	fn find_author<'a, I>(digests: I) -> Option<H160>
	where
		I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
	{
		if let Some(author_index) = F::find_author(digests) {
			let authority_id =
				pallet_aura::Authorities::<Runtime>::get()[author_index as usize].clone();
			return Some(H160::from_slice(&authority_id.to_raw_vec()[0..20]));
		}
		None
	}
}

I am able to get 0xd43593c715fdd31c61141abd04a99fd6822c8558 which matches what I assume is supposed to be Alice's account. At the start I was assuming this should be 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac

Am I looking at this correctly or incorrectly?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions