Create a Cluster SysVar

Every once and a while the question comes up of detecting the Solana cluster (mainnet, testnet, devnet) from within a program. As far as I know, this is still impossible. This issue has compounded recently with the explosion of SVM L2s, rollups, and new clusters.

To prevent the need to fragment codebases, or require additional program configs to be created, I propose the addition of a Cluster System Variable to indicate the SVM blockchain and specific cluster being used. This will allow programs to dynamically determine their execution environment.

My suggested format would be something like the following:

#[repr(C)]
pub enum Cluster: {
    mainnet,
    devnet,
    testnet,
    other(String),
}

#[repr(C)]
pub struct ClusterDetails {
    pub blockchain: String,
    pub cluster: Cluster,
}
3 Likes