Skip to content

Commit 29e4e37

Browse files
authored
Add block author to pre-runtime digest (#64)
1 parent 13b7b62 commit 29e4e37

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

node/src/service.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use core::clone::Clone;
44
use std::sync::Arc;
55

6-
use academy_pow_runtime::{self, opaque::Block, RuntimeApi};
6+
use academy_pow_runtime::{self, opaque::Block, PreDigest, RuntimeApi};
77
use multi_pow::{ForkingConfig, MultiPow, SupportedHashes};
88
use parity_scale_codec::Encode;
99
use sc_consensus::LongestChain;
@@ -238,7 +238,7 @@ pub fn new_full(
238238
// This allows us to know which algo it was in the runtime.
239239
// TODO This also makes it possible to remove the algo info from
240240
// the seal.
241-
Some(mining_algo.encode()),
241+
Some(PreDigest::from((sr25519_public_key.into(), mining_algo)).encode()),
242242
// This code is copied from above. Would be better to not repeat it.
243243
move |_, ()| async move {
244244
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

runtime/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub type Index = u32;
7979
/// A hash of some data used by the chain.
8080
pub type Hash = sp_core::H256;
8181

82+
/// Consensus digest containing block author and supported hash algorithm.
83+
pub type PreDigest = (AccountId, SupportedHashes);
84+
8285
/// The BlockAuthor trait in `./block_author.rs`
8386
pub mod block_author;
8487

@@ -239,7 +242,8 @@ fn current_blocks_mining_algo() -> SupportedHashes {
239242
.iter()
240243
.find_map(|digest_item| {
241244
match digest_item {
242-
DigestItem::PreRuntime(POW_ENGINE_ID, encoded_algo) => SupportedHashes::decode(&mut &encoded_algo[..]).ok(),
245+
DigestItem::PreRuntime(POW_ENGINE_ID, pre_digest) =>
246+
PreDigest::decode(&mut &pre_digest[..]).map(|d| d.1).ok(),
243247
_ => None,
244248
}
245249
})

0 commit comments

Comments
 (0)