Skip to content

Commit 3691e8a

Browse files
onspeedhpclaude
andcommitted
feat(build): dual-cluster Cargo features for compile-time program ID
Apply Pattern D from lazorkit-protocol PR #9: the embedded program ID is now chosen by `--features mainnet` or `--features devnet`, with a `compile_error!` if neither (or both) is set. Prevents accidental cross-cluster deploys — a binary compiled with one ID malfunctions if deployed to the other cluster's slot. Mainnet feature embeds LazorjRFNavitUaBu5m3WaNPjU1maipvSW2rZfAFAKi — the SAME program ID as lazorkit-protocol. program-v2 (foundation, no-fee build) occupies that mainnet slot for the duration of the foundation contract; at contract end the upgrade authority swaps the binary at the same slot to lazorkit-protocol's commercial build. dApp integrators keep one stable program ID through the transition. Devnet feature keeps program-v2's existing FLb7fyAtkfA4TSa2uYcAT8QKHd2pkoMHgmqfnXFXo7ao. Build verification: cargo build-sbf --features mainnet → sha differs from devnet cargo build-sbf --features devnet → sha differs from mainnet cargo build-sbf → fails with compile_error cargo build-sbf --features mainnet --features devnet → fails Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 55c8e9d commit 3691e8a

4 files changed

Lines changed: 38 additions & 47 deletions

File tree

assertions/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ edition = "2021"
77
pinocchio = { workspace = true }
88
pinocchio-pubkey = { workspace = true }
99
pinocchio-system = { workspace = true }
10+
11+
# Cluster selection for the embedded program ID. Exactly one must be set
12+
# at build time; lib.rs emits a compile_error! otherwise.
13+
[features]
14+
mainnet = []
15+
devnet = []

assertions/src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,32 @@ use pinocchio::{
1010
use pinocchio_pubkey::declare_id;
1111
use pinocchio_system::ID as SYSTEM_ID;
1212

13-
// LazorKit Program ID
13+
// LazorKit Program ID — chosen at build time via the `mainnet` / `devnet`
14+
// cargo features. Exactly one must be enabled; otherwise the build fails
15+
// loudly via the `compile_error!` below. This prevents accidental cross-
16+
// cluster deploys (a binary compiled with one ID malfunctions if deployed
17+
// to a slot at the other ID — every internal `crate::ID` check fails).
18+
//
19+
// The mainnet ID intentionally matches lazorkit-protocol's mainnet ID:
20+
// program-v2 (no-fee foundation variant) is deployed to that slot for the
21+
// duration of the foundation contract; at contract end, the upgrade
22+
// authority swaps the binary at the same slot to lazorkit-protocol's
23+
// commercial build. dApp integrators keep using the same program ID
24+
// throughout — only the on-chain behavior changes.
25+
#[cfg(all(feature = "mainnet", not(feature = "devnet")))]
26+
declare_id!("LazorjRFNavitUaBu5m3WaNPjU1maipvSW2rZfAFAKi");
27+
28+
#[cfg(all(feature = "devnet", not(feature = "mainnet")))]
1429
declare_id!("FLb7fyAtkfA4TSa2uYcAT8QKHd2pkoMHgmqfnXFXo7ao");
1530

31+
#[cfg(any(
32+
all(feature = "mainnet", feature = "devnet"),
33+
all(not(feature = "mainnet"), not(feature = "devnet"))
34+
))]
35+
compile_error!(
36+
"LazorKit: pick exactly one cluster — `--features mainnet` OR `--features devnet`"
37+
);
38+
1639
#[allow(unused_imports)]
1740
use std::mem::MaybeUninit;
1841

program/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ edition = "2021"
66
[lib]
77
crate-type = ["cdylib", "lib"]
88

9+
# Cluster selection — forwards to the assertions crate where the program ID
10+
# is embedded via declare_id!. Exactly one must be set at build time:
11+
# cargo build-sbf --features mainnet
12+
# cargo build-sbf --features devnet
13+
[features]
14+
mainnet = ["assertions/mainnet"]
15+
devnet = ["assertions/devnet"]
16+
917
[dependencies]
1018
pinocchio = { workspace = true }
1119
pinocchio-pubkey = { workspace = true }

scripts/sync-program-id.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)