Skip to content

Commit

Permalink
update inject inherents
Browse files Browse the repository at this point in the history
  • Loading branch information
devdanco committed Jan 18, 2023
1 parent 7e98ed5 commit d2a3084
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use sp_arithmetic::traits::BaseArithmetic;
use sp_consensus::{Proposal, Proposer, SelectChain, SyncOracle};
use sp_consensus_slots::{Slot, SlotDuration};
use sp_core::{sr25519, ShufflingSeed};
use sp_inherents::{CreateInherentDataProviders, InherentDataProvider};
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
use sp_keystore::{vrf, SyncCryptoStore, SyncCryptoStorePtr};
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
use sp_ver::RandomSeedInherentDataProvider;
Expand Down Expand Up @@ -94,16 +94,16 @@ fn create_shuffling_seed_input_data<'a>(prev_seed: &'a ShufflingSeed) -> vrf::VR
async fn inject_inherents<'a, B: BlockT>(
keystore: SyncCryptoStorePtr,
public: &'a sr25519::Public,
slot_info: &'a mut SlotInfo<B>,
slot_info: &'a SlotInfo<B>,
in_data: &'a mut InherentData
) -> Result<(), sp_consensus::Error> {
let prev_seed = slot_info.chain_head.seed();
let mut inherited_data = slot_info.create_inherent_data.create_inherent_data().await?;

let seed = sp_ver::calculate_next_seed::<dyn SyncCryptoStore>(&(*keystore), public, prev_seed)
.ok_or(sp_consensus::Error::StateUnavailable(String::from("signing seed failure")))?;

RandomSeedInherentDataProvider(seed)
.provide_inherent_data(&mut inherited_data)
.provide_inherent_data(in_data)
.map_err(|_| {
sp_consensus::Error::StateUnavailable(String::from(
"cannot inject RandomSeed inherent data",
Expand Down Expand Up @@ -240,8 +240,13 @@ pub trait SimpleSlotWorker<B: BlockT> {
let slot = slot_info.slot;
let telemetry = self.telemetry();
let log_target = self.logging_target();
let keystore = self.keystore().clone();

let mut inherent_data = Self::create_inherent_data(&slot_info, &log_target).await?;

let key = self.get_key(&claim);

let inherent_data = Self::create_inherent_data(&slot_info, &log_target).await?;
inject_inherents(keystore, &key, &slot_info, &mut inherent_data).await.ok()?;

let proposing_remaining_duration = self.proposing_remaining_duration(&slot_info);
let logs = self.pre_digest_data(slot, claim);
Expand Down Expand Up @@ -394,9 +399,6 @@ pub trait SimpleSlotWorker<B: BlockT> {

let claim = self.claim_slot(&slot_info.chain_head, slot, &aux_data).await?;

let key = self.get_key(&claim);
inject_inherents(keystore, &key, &mut slot_info).await.ok()?;

if self.should_backoff(slot, &slot_info.chain_head) {
return None
}
Expand Down

0 comments on commit d2a3084

Please sign in to comment.