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

Add chain selector to account #406

Merged
merged 8 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
65 changes: 65 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
repos:
- repo: local
hooks:
- id: cargo-clippy
name: Run cargo clippy
entry: bash -c "echo 'Running cargo clippy '; cargo clippy --manifest-path ./chains/solana/contracts/programs/ccip-router/Cargo.toml"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: anchor-go-gen
name: Generate Anchor Go Contract Interfaces
entry: bash -c "echo 'Running make anchor-go-gen'; make -C ./chains/solana anchor-go-gen"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: format-contracts
name: Format Rust Solana Contracts and Typescript tests
entry: bash -c "echo 'Running make format-contracts'; make -C ./chains/solana format-contracts"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: gomodtidy
name: Run Go Mod Tidy
entry: bash -c "echo 'Running make gomodtidy'; make -C ./chains/solana gomodtidy"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: lint-go
name: Run Go Linter and fix if possible
entry: bash -c "echo 'Running make lint-go-fix'; make -C ./chains/solana lint-go-fix"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: rust-tests
name: Run Rust tests
entry: bash -c "echo 'Running Rust Tests'; cd ./chains/solana/contracts && make rust-tests"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: e2e-tests-go
name: Run Go E2E tests
entry: bash -c "echo 'Running Go E2E Tests'; cd ./chains/solana && make go-tests"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: generate-idl
name: Generate Solana IDL
entry: bash -c "echo 'Running make generate-idl'; make -C ./chains/solana generate-idl"
language: system
stages: [pre-commit]
files: ^chains/solana/
verbose: true
- id: tap-yubikey
name: Reminder
entry: bash -c "echo 'Remember to tap your Yubikey!'"
language: system
stages: [pre-commit]
verbose: true
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ the `main` branch of chainlink-ccip. You can do this by:
4. Once your chainlink-ccip PR is approved, merge it.
5. Go back to your chainlink PR and bump the chainlink-ccip version to the latest main.
6. Once the integration test passes, merge your chainlink PR into `develop`.

## Pre commit hook

You should install [pre-commit](https://pre-commit.com/) so that automated linting and formatting checks are performed before each commit.
Currently, this pre-commit configuration only runs when modifiying Solana Files under `./solana` folder.
agusaldasoro marked this conversation as resolved.
Show resolved Hide resolved

Run:

```bash
pip3 install pre-commit
pre-commit install
```

If you need to commit something quickly without running the pre-commit checks, you can use the `--no-verify` flag.
12 changes: 12 additions & 0 deletions chains/solana/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ gomods: ## Install gomods
gomodtidy: gomods
gomods tidy

.PHONY: format-contracts
format-contracts:
cd ./contracts && cargo fmt && go fmt ./...

.PHONY: rust-tests
rust-tests:
cd ./contracts && cargo test

.PHONY: lint-go
lint-go:
golangci-lint --max-issues-per-linter 0 --max-same-issues 0 --color=always --exclude=dot-imports --timeout 15m --out-format checkstyle:golangci-lint-report.xml run

.PHONY: lint-go-fix
lint-go-fix:
golangci-lint --max-issues-per-linter 0 --max-same-issues 0 --color=always --exclude=dot-imports --timeout 15m run --verbose --fix

.PHONY: anchor-go-gen
anchor-go-gen:
cd ./contracts && rm -rf ./target && anchor build && cd .. && ./scripts/anchor-go-gen.sh
Expand Down
2 changes: 1 addition & 1 deletion chains/solana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go install github.com/gagliardetto/anchor-go@v0.2.3
anchor build

# go bindings need to be regenerated if contract changes were made
./scrips/anchor-go-gen.sh
./scripts/anchor-go-gen.sh
toblich marked this conversation as resolved.
Show resolved Hide resolved

# test contracts
go test ./... -v -count=1 -failfast
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub fn fee_for_msg(
Ok(SolanaTokenAmount { amount, token })
}

#[allow(dead_code)]
pub struct PackedPrice {
pub execution_cost: u128,
pub gas_price: u128,
Expand Down
4 changes: 4 additions & 0 deletions chains/solana/contracts/programs/ccip-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ pub mod ccip_router {
let source_chain_state = &mut ctx.accounts.source_chain_state;
validate_source_chain_config(new_chain_selector, &source_chain_config)?;
source_chain_state.version = 1;
source_chain_state.chain_selector = new_chain_selector;
source_chain_state.config = source_chain_config.clone();
source_chain_state.state = SourceChainState { min_seq_nr: 1 };

// Set dest chain config & state
let dest_chain_state = &mut ctx.accounts.dest_chain_state;
validate_dest_chain_config(new_chain_selector, &dest_chain_config)?;
dest_chain_state.version = 1;
dest_chain_state.chain_selector = new_chain_selector;
dest_chain_state.config = dest_chain_config.clone();
dest_chain_state.state = DestChainState {
sequence_number: 0,
Expand Down Expand Up @@ -1015,6 +1017,8 @@ pub mod ccip_router {

let clock: Clock = Clock::get()?;
commit_report.version = 1;
commit_report.chain_selector = report.merkle_root.source_chain_selector;
commit_report.merkle_root = report.merkle_root.merkle_root;
commit_report.timestamp = clock.unix_timestamp;
commit_report.execution_states = 0;
commit_report.min_msg_nr = root.min_seq_nr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ pub(crate) mod tests {
pub fn sample_dest_chain() -> DestChain {
DestChain {
version: 1,
chain_selector: 1,
state: crate::DestChainState {
sequence_number: 0,
usd_per_unit_gas: crate::TimestampedPackedU224 {
Expand Down
14 changes: 13 additions & 1 deletion chains/solana/contracts/programs/ccip-router/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub struct SourceChainState {
pub struct SourceChain {
// Config for Any2Solana
pub version: u8,
pub state: SourceChainState, // values that are updated automatically
pub chain_selector: u64, // Chain selector used for the seed
pub state: SourceChainState, // values that are updated automatically
pub config: SourceChainConfig, // values configured by an admin
}

Expand Down Expand Up @@ -90,6 +91,7 @@ pub struct DestChainConfig {
pub struct DestChain {
// Config for Solana2Any
pub version: u8,
pub chain_selector: u64, // Chain selector used for the seed
pub state: DestChainState, // values that are updated automatically
pub config: DestChainConfig, // values configured by an admin
}
Expand All @@ -109,6 +111,8 @@ pub struct ExternalExecutionConfig {}
#[derive(InitSpace)]
pub struct CommitReport {
pub version: u8,
pub chain_selector: u64,
pub merkle_root: [u8; 32],
pub timestamp: i64, // Expressed as Unix time (i.e. seconds since the Unix epoch).
pub min_msg_nr: u64,
pub max_msg_nr: u64, // TODO: Change this to [u128; 2] when supporting commit reports with 256 messages
Expand Down Expand Up @@ -252,6 +256,8 @@ mod tests {
fn test_set_state() {
let mut commit_report = CommitReport {
version: 1,
chain_selector: 0,
merkle_root: [0; 32],
timestamp: 0,
min_msg_nr: 0,
max_msg_nr: 64,
Expand Down Expand Up @@ -279,6 +285,8 @@ mod tests {
fn test_set_state_out_of_bounds() {
let mut commit_report = CommitReport {
version: 1,
chain_selector: 1,
merkle_root: [0; 32],
timestamp: 1,
min_msg_nr: 1500,
max_msg_nr: 1530,
Expand All @@ -292,6 +300,8 @@ mod tests {
fn test_get_state() {
let mut commit_report = CommitReport {
version: 1,
chain_selector: 1,
merkle_root: [0; 32],
timestamp: 1,
min_msg_nr: 1500,
max_msg_nr: 1530,
Expand Down Expand Up @@ -326,6 +336,8 @@ mod tests {
fn test_get_state_out_of_bounds() {
let commit_report = CommitReport {
version: 1,
chain_selector: 1,
merkle_root: [0; 32],
timestamp: 1,
min_msg_nr: 1500,
max_msg_nr: 1530,
Expand Down
21 changes: 21 additions & 0 deletions chains/solana/contracts/target/idl/ccip_router.json
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,10 @@
"name": "version",
"type": "u8"
},
{
"name": "chainSelector",
"type": "u64"
},
{
"name": "state",
"type": {
Expand All @@ -1490,6 +1494,10 @@
"name": "version",
"type": "u8"
},
{
"name": "chainSelector",
"type": "u64"
},
{
"name": "state",
"type": {
Expand Down Expand Up @@ -1537,6 +1545,19 @@
"name": "version",
"type": "u8"
},
{
"name": "chainSelector",
"type": "u64"
},
{
"name": "merkleRoot",
"type": {
"array": [
"u8",
32
]
}
},
{
"name": "timestamp",
"type": "i64"
Expand Down
56 changes: 50 additions & 6 deletions chains/solana/gobindings/ccip_router/accounts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading