from what I've learned so far, the OCW is designed specifically for executing heavy and time-consuming computations outside of the runtime. As the OCW is not a part of runtime/wasm, I guess the OCW should be able to use crates that depend on the rust std
lib.
However, when I'm trying to implement a simple OCW in a pallet lib.rs
file like this:
#[cfg(feature = "std")]
mod offchain; // module that implements OCW logic and uses external crates that depend on the `std`
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn offchain_worker(block_number: BlockNumberFor<T>) {
log::info!("Log message 1");
#[cfg(feature = "std")]
{
log::info!("Log message 2");
crate::offchain::offchain::perform_offchain_work();
}
}
}
then, compiling my node binary as:
cargo build --release --features std
and then, running it as:
./target/release/node --dev
I see only the output "Log message 1" string, and I never see the output with the "Log message 2" string in my console, which probably means my actual OCW implementation in perform_offchain_work()
never executes.
Can you help me understand better the design of the OCW and how I can get it working with external crates dependent on std
? What I'm doing wrong in my example? Maybe I should provide some extensions to the OCW via custom host functions? Is there any good example for that?