fn on_initialize(_: T::BlockNumber) -> Weight {
let mut weight = T::SystemWeightInfo::kill_storage(1);
// If the digest contain an existing ethereum block(encoded as PreLog), If contains,
// execute the imported block firstly and disable transact dispatch function.
if let Ok(log) = fp_consensus::find_pre_log(&frame_system::Pallet::<T>::digest()) {
let PreLog::Block(block) = log;
for transaction in block.transactions {
let source = Self::recover_signer(&transaction).expect(
"pre-block transaction signature invalid; the block cannot be built",
);
Self::validate_transaction_in_block(source, &transaction).expect(
"pre-block transaction verification failed; the block cannot be built",
);
let r = Self::apply_validated_transaction(source, transaction)
.expect("pre-block apply transaction failed; the block cannot be built");
weight = weight.saturating_add(r.actual_weight.unwrap_or_default());
}
}
This hook is part of the ethereum pallet defined in Frontier. I understand that in the wrapped block model, communication between the runtime and the node can be achieved through digest. It's used by the on_finalize
hook to pass data about the inner block, in so the client can keep a mapping of inner to outer block up to date.
The code I quoted seems to check that the provided block is valid and then execute the transactions it contains.
My problem is that I don't understand under which conditions exactly a block would be provided to the runtime by a PreRuntime
DigestItem
.
Also the logging of the block in the Digest
in the on_finalize
hook is disabled when a PreRuntime
block had been found. But I cannot see how having a PreRuntime
block prevent from more transactions to be added to the block through regular extrinsic execution.
Aslo, it seems to go against the 1-1 equivalence between wrapped and wrapper blocks.