-
Notifications
You must be signed in to change notification settings - Fork 127
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
simd: "0201" | ||
title: Create Cluster Sysvar | ||
authors: | ||
- [email protected] | ||
category: Standard | ||
type: Core | ||
status: Draft | ||
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. | ||
Check failure on line 15 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
## 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. | ||
Check failure on line 19 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
## Alternatives Considered | ||
|
||
- **SDK Abstraction** - It would be possible but difficult to maintain separate SDKs per cluster or dynamic resolution based on genesis hash | ||
Check failure on line 23 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
## New Terminology | ||
|
||
**ClusterDetails** - The sysvar structure which provides the relevant details for a program to determine which cluster it's executing on. | ||
Check failure on line 27 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
## 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. | ||
Check failure on line 31 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
```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, | ||
} | ||
``` | ||
|
||
## 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. | ||
Check failure on line 58 in proposals/0201-create-cluster-sysvar.md
|
||
|
||
## 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. | ||
Check failure on line 62 in proposals/0201-create-cluster-sysvar.md
|
There was a problem hiding this comment.
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:
I guess that introduces the problem of where to "register" chain IDs, but I think we were going to have that problem anyway, right?
There was a problem hiding this comment.
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!