Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion substrate/frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,11 @@ where
// OffchainWorker RuntimeApi should skip initialization.
let digests = header.digest().clone();

<frame_system::Pallet<System>>::initialize(header.number(), header.parent_hash(), &digests);
// Let's deposit all the logs we are not yet aware of. These are the logs set by the `node`.
let existing_digest = frame_system::Pallet::<System>::digest();
for digest in digests.logs().iter().filter(|d| !existing_digest.logs.contains(d)) {
frame_system::Pallet::<System>::deposit_log(digest.clone());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what about well_known_keys::INTRABLOCK_ENTROPY it gets removed in finalize, maybe we should bring it back, some offchain worker could read into it.


// Frame system only inserts the parent hash into the block hashes as normally we don't know
// the hash for the header before. However, here we are aware of the hash and we can add it
Expand Down
7 changes: 7 additions & 0 deletions substrate/frame/executive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,14 @@ fn all_weights_are_recorded_correctly() {
fn offchain_worker_works_as_expected() {
new_test_ext(1).execute_with(|| {
let parent_hash = sp_core::H256::from([69u8; 32]);

// Emulate block production before running the offchain worker.
System::initialize(&1, &parent_hash, &Digest::default());
System::finalize();

let mut digest = Digest::default();
// As `Seal` is added by the node after the block was build, it was not part of
// `System::initialize` above.
digest.push(DigestItem::Seal([1, 2, 3, 4], vec![5, 6, 7, 8]));

let header = Header::new(1, H256::default(), H256::default(), parent_hash, digest.clone());
Expand Down
1 change: 1 addition & 0 deletions substrate/test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,7 @@ impl_runtime_apis! {
}.into(),
);
sp_io::offchain::submit_transaction(ext.encode()).unwrap();
Executive::offchain_worker(header);
}
}

Expand Down
Loading