Skip to content

Commit 95fdfd8

Browse files
committed
solana: pick up chain id from environment
Tiltfile: set CHAIN_ID in solana build config solana: add CHAIN_ID to Dockerfile.client and Dockerfile.wasm
1 parent 63b904d commit 95fdfd8

8 files changed

Lines changed: 52 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ jobs:
107107
RUSTFLAGS: -Dwarnings
108108
EMITTER_ADDRESS: CiByUvEcx7w2HA4VHcPCBUAFQ73Won9kB36zW9VjirSr
109109
BRIDGE_ADDRESS: Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o
110+
CHAIN_ID: 1
110111

111112
steps:
112113
- uses: actions/checkout@v3

Tiltfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def command_with_dlv(argv):
159159
] + argv[1:]
160160

161161
def generate_bootstrap_peers(num_guardians, port_num):
162-
# Improve the chances of the guardians discovering each other in tilt by making them all bootstrap peers.
162+
# Improve the chances of the guardians discovering each other in tilt by making them all bootstrap peers.
163163
# The devnet guardian uses deterministic P2P peer IDs based on the guardian index. The peer IDs here
164164
# were generated using `DeterministicP2PPrivKeyByIndex` in `node/pkg/devnet/deterministic_p2p_key.go`.
165165
peer_ids = [
@@ -181,7 +181,7 @@ def generate_bootstrap_peers(num_guardians, port_num):
181181
"12D3KooW9yvKfP5HgVaLnNaxWywo3pLAEypk7wjUcpgKwLznk5gQ",
182182
"12D3KooWRuYVGEsecrJJhZsSoKf1UNdBVYKFCmFLNj9ucZiSQCYj",
183183
"12D3KooWGEcD5sW5osB6LajkHGqiGc3W8eKfYwnJVVqfujkpLWX2",
184-
"12D3KooWQYz2inBsgiBoqNtmEn1qeRBr9B8cdishFuBgiARcfMcY"
184+
"12D3KooWQYz2inBsgiBoqNtmEn1qeRBr9B8cdishFuBgiARcfMcY"
185185
]
186186
bootstrap = ""
187187
for idx in range(num_guardians):
@@ -216,7 +216,7 @@ def build_node_yaml():
216216
bootstrapPeers,
217217
"--ccqP2pBootstrap",
218218
ccqBootstrapPeers,
219-
]
219+
]
220220

221221
if aptos:
222222
container["command"] += [
@@ -485,7 +485,7 @@ if solana or pythnet:
485485
dockerfile = "solana/Dockerfile",
486486
target = "builder",
487487
ignore = ["./solana/*/target", "./solana/tests"],
488-
build_args = {"BRIDGE_ADDRESS": "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"}
488+
build_args = {"BRIDGE_ADDRESS": "Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o", "CHAIN_ID": "1"},
489489
)
490490

491491
# solana local devnet
@@ -658,7 +658,7 @@ if ci_tests:
658658
"BOOTSTRAP_PEERS", str(ccqBootstrapPeers)),
659659
"MAX_WORKERS", max_workers))
660660
)
661-
661+
662662
# separate resources to parallelize docker builds
663663
k8s_resource(
664664
"sdk-ci-tests",

solana/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ RUN mkdir -p /opt/solana/deps
2121

2222
ARG EMITTER_ADDRESS="11111111111111111111111111111115"
2323
ARG BRIDGE_ADDRESS
24+
ARG CHAIN_ID
2425
RUN [ -n "${BRIDGE_ADDRESS}" ]
26+
RUN [ -n "${CHAIN_ID}" ]
2527

2628
# Build Wormhole Solana programs
2729
RUN --mount=type=cache,target=target,id=build \

solana/Dockerfile.client

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ RUN solana config set --url "http://solana-devnet:8899"
3030

3131
ENV EMITTER_ADDRESS="11111111111111111111111111111115"
3232
ENV BRIDGE_ADDRESS="Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"
33+
ENV CHAIN_ID=1
3334

3435
RUN --mount=type=cache,target=/root/.cache \
3536
--mount=type=cache,target=target \

solana/Dockerfile.wasm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN cargo install wasm-pack --vers 0.9.1
1111
ENV RUST_LOG="solana_runtime::system_instruction_processor=trace,solana_runtime::message_processor=trace,solana_bpf_loader=debug,solana_rbpf=debug"
1212
ENV EMITTER_ADDRESS="11111111111111111111111111111115"
1313
ENV BRIDGE_ADDRESS="Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o"
14+
ENV CHAIN_ID=1
1415

1516
COPY rust-toolchain .
1617
COPY bridge bridge

solana/Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# Chain ids
2+
# ---------
3+
CHAIN_ID_solana=1
4+
CHAIN_ID_fogo=51
5+
16
# Solana addresses
27
# ----------------
38

@@ -72,7 +77,7 @@ check-svmchain-name:
7277
artifacts-$(SVM)-$(NETWORK): $(SOURCE_FILES)
7378
echo $@
7479
@echo "Building artifacts for ${SVM} ${NETWORK} (${bridge_ADDRESS_$${SVM}_${NETWORK}})"
75-
DOCKER_BUILDKIT=1 docker build -f Dockerfile --build-arg BRIDGE_ADDRESS=${bridge_ADDRESS_${SVM}_${NETWORK}} -o $@ .
80+
DOCKER_BUILDKIT=1 docker build -f Dockerfile --build-arg BRIDGE_ADDRESS=${bridge_ADDRESS_${SVM}_${NETWORK}} --build-arg CHAIN_ID=${CHAIN_ID_${SVM}} -o $@ .
7681
cd $@ && ls | xargs sha256sum > checksums.txt
7782

7883
payer-$(SVM)-$(NETWORK).json:
@@ -123,6 +128,7 @@ clippy: $(SOURCE_FILES)
123128

124129
test: $(SOURCE_FILES) check-svmchain-name
125130
DOCKER_BUILDKIT=1 docker build -f Dockerfile --build-arg BRIDGE_ADDRESS=${bridge_ADDRESS_${SVM}_devnet} \
131+
--build-arg CHAIN_ID=${CHAIN_ID_${SVM}} \
126132
--build-arg EMITTER_ADDRESS=CiByUvEcx7w2HA4VHcPCBUAFQ73Won9kB36zW9VjirSr -o target/deploy .
127133
BPF_OUT_DIR=$(realpath $(dir $(firstword $(MAKEFILE_LIST))))/target/deploy \
128134
cargo test --workspace \
@@ -131,6 +137,7 @@ test: $(SOURCE_FILES) check-svmchain-name
131137
.PHONY: build
132138
# Build for local use (not for deployment)
133139
build: check-network check-svmchain-name
140+
CHAIN_ID=${CHAIN_ID_${SVM}} \
134141
BRIDGE_ADDRESS=${bridge_ADDRESS_${SVM}_${NETWORK}} \
135142
EMITTER_ADDRESS=11111111111111111111111111111115 \
136143
cargo build

solana/bridge/program/src/lib.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,41 @@
55
use solitaire::*;
66

77
pub const MAX_LEN_GUARDIAN_KEYS: usize = 19;
8-
pub const OUR_CHAIN_ID: u16 = 1;
8+
pub const OUR_CHAIN_ID: u16 = parse_u16_const(env!("CHAIN_ID"));
99
pub const CHAIN_ID_GOVERNANCE: u16 = 1;
1010

11+
/// A const fn to parse a u16 from a string at compile time.
12+
/// A newer version of std includes a const parser function, but we depend on an
13+
/// old version, which doesn't.
14+
/// For good measure, we include a couple of static asserts below to make sure it works.
15+
pub const fn parse_u16_const(s: &str) -> u16 {
16+
let b = s.as_bytes();
17+
let mut i = 0;
18+
19+
let mut acc: u16 = 0;
20+
while i < b.len() {
21+
let c = b[i];
22+
if c >= b'0' && c <= b'9' {
23+
let d = (c - b'0') as u16;
24+
acc = acc * 10 + d;
25+
i += 1;
26+
} else {
27+
break;
28+
}
29+
}
30+
31+
if acc == 0 {
32+
panic!("Invalid chain id");
33+
}
34+
35+
acc
36+
}
37+
38+
const _: () = {
39+
assert!(parse_u16_const("1") == 1);
40+
assert!(parse_u16_const("65535") == 65535);
41+
};
42+
1143
#[cfg(feature = "instructions")]
1244
pub mod instructions;
1345

solana/modules/token_bridge/program/tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use bridge::{
55
PostedVAADerivationData,
66
},
77
SerializePayload,
8+
OUR_CHAIN_ID,
89
};
910
use libsecp256k1::SecretKey;
1011
use primitive_types::U256;
@@ -54,7 +55,6 @@ const GOVERNANCE_KEY: [u8; 64] = [
5455
88, 97, 199,
5556
];
5657

57-
const OUR_CHAIN_ID: u16 = 1;
5858
const CHAIN_ID_ETH: u16 = 2;
5959

6060
struct Context {

0 commit comments

Comments
 (0)