Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD-0201: Create a Cluster Sysvar #201

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions proposals/0201-create-cluster-sysvar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
simd: "0201"
title: Create Cluster Sysvar
authors:
- [email protected]
category: Standard
type: Core
status: Review
created: 2024-11-22
feature:
---

## Summary

There should be a natively accessible Sysvar (like Rent or Clock) that provides
Cluster details in order to determine the specific SVM environment.

## Motivation

It is currently not possible to determine which cluster a Solana program is
executing on from within the program itself. This makes dynamic behavior based
on different SVM environments difficult without requiring multiple builds of a
single protocol. Native determination of the SVM cluster would improve DevEx and
diminish opportunities to introduce bugs by allowing more dynamic program execution.

## Alternatives Considered

- **SDK Abstraction** - It would be possible but difficult to maintain separate
SDKs per cluster or dynamic resolution based on genesis hash

## New Terminology

**ClusterDetails** - The sysvar structure which provides the relevant details
for a program to determine which cluster it's executing on.

## Detailed Design

The following Cluster type and ClusterDetails struct would provide sufficient
details for a program to properly determine the environment on which it's
executing. String tags are included because using genesis hash alone is
insufficient for clusters that don't guarantee permanence such as devnet,
testnet, or roll-ups.

```rust
/// The cluster type, usually the first three with an optional named
/// field for more diverse clusters (alt-devnets, roll-ups).
#[repr(C)]
pub enum ClusterType: {
mainnet,
devnet,
testnet,
other(String),
}

#[repr(C)]
pub struct ClusterDetails {
/// The genesis hash for the cluster, guaranteed for mainnet but
/// possibly variable for other cluster types.
pub genesis_hash: Hash,
/// A named tag for the SVM chain on which the program is executing.
pub blockchain: String,
/// Cluster Type
pub cluster_type: ClusterType,
}
```
Comment on lines +55 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would advocate for a static layout here. Can we accomplish the stated goal with IDs? Something like:

genesis_hash: [u8; 32] // (Hash)
blockchain: [u8; 8]
cluster: [u8; 8]

I guess that introduces the problem of where to "register" chain IDs, but I think we were going to have that problem anyway, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be nice to have the cluster identifier be typed but that could easily be accomplished with helpers in the SDK.

I think the static type makes sense. The chain ID is really for continuity for Devnet resets and debugging so relying on an external registry also works!


## Impact

Dynamic determination of cluster would allow programs to perform better
validation of cluster-specific feature such as variable protocol fees,
irreplicable PDAs or derivations, or variable features across different blockchains.

## Security Considerations

Certain named fields could be invalidated due to changes to the underlying SVM
runtime. Program developers should be sure to validate and fail gracefully if
unexpected changes occur.
Loading