3

Offchain workers storage comes in two flavors: Persistent and Local.

pub enum StorageKind {
    /// Persistent storage is non-revertible and not fork-aware. It means that any value
    /// set by the offchain worker triggered at block `N(hash1)` is persisted even
    /// if that block is reverted as non-canonical and is available for the worker
    /// that is re-run at block `N(hash2)`.
    /// This storage can be used by offchain workers to handle forks
    /// and coordinate offchain workers running on different forks.
    PERSISTENT = 1_isize,
    /// Local storage is revertible and fork-aware. It means that any value
    /// set by the offchain worker triggered at block `N(hash1)` is reverted
    /// if that block is reverted as non-canonical and is NOT available for the worker
    /// that is re-run at block `N(hash2)`.
    LOCAL = 2_isize,
}

source

My question is, even though one of these StorageKind is defined as PERSISTENT, it sounds that it is only persistent as long as it exists in memory, and so persistent between different runs of the worker, as long memory is not dropped. Is this the case ?

2 Answers 2

2

I think StorageKind is used to distinguish between different behavior when block revert or fork happens.

And, if storage use memory or disk is depends on the DatabaseSettings.source configuration, such as you choose to use RocksDb or so.

0

Indeed, my first assumption was not correct. What was leading me to thinking about it only living in memory was this in-memory implementation https://github.com/paritytech/substrate/blob/master/primitives/core/src/offchain/storage.rs#L18 But thanks to @chino-chang for the heads up about it being mostly used for testing.

The writes to db will happen in the Offchain column and these entries can get a prefix appended to the key so they are a bit more isolated.

After this bit much of research around the code I feel that my initial questions doesn't bring much value in general, but I would rather leave this thread open just in case it may help someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.