I'm trying to test offchain workers in my local substrate node.
It seems that by default the ocw is not enabled? I've only been able to see logs from ocw's when running the node with the --dev
option (e.g. when using --chain local there are no ocw logs) - but AFAIU --dev
will not persist the chain state nor the keystore when I run it multiple times.
I would definitely like the keys to persist, since my ocw needs to submit unsigned tx's with:
let (_, result) = Signer::<T, T::AuthorityId>::any_account()
.send_unsigned_transaction(
|account| SomePayload {
value: value.clone(),
public: account.public.clone(),
},
|payload, signature| Call::submit_value_from_unsigned_transaction {
some_payload: payload,
signature,
},
)
.ok_or("No local accounts accounts available.")?;
I also define the key for ocw to be pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"abcd");
, so I will need to generate a key and add it to keystore, right? Well I don't want to be adding it to keystore everytime I make a change to my node and rerun it with --dev
flag.
What's the best practice for testing whether my ocw functions as expected? I suppose that my question encompasses two questions really:
- how to add keys to the keystore such that they persist
- how to run the local node s.t. the ocw is enabled AND it picks up the added keys, without having to re-add them every time?
Many thanks for help on this one!