Skip to content

Commit

Permalink
solana: porting over contracts (#366)
Browse files Browse the repository at this point in the history
* solana: porting over contracts

Co-authored-by: Agustina Aldasoro <[email protected]>
Co-authored-by: Tobías Lichtig <[email protected]>
Co-authored-by: Jonghyeon Park <[email protected]>
Co-authored-by: PabloMansanet <[email protected]>

* cleanup gitignore

* add solana build cache

* enable tests

* enable linting

* fix lint

* reorganize tests

* use ccip-onchain-solana team as codeowner

* Update chains/solana/.gitignore

Co-authored-by: Agustina Aldasoro <[email protected]>

* move contracts/generated -> gobindings

* add readme

* go fmt

---------

Co-authored-by: Agustina Aldasoro <[email protected]>
Co-authored-by: Tobías Lichtig <[email protected]>
Co-authored-by: Jonghyeon Park <[email protected]>
Co-authored-by: PabloMansanet <[email protected]>
  • Loading branch information
5 people authored Dec 17, 2024
1 parent cbbe23d commit 814a10a
Show file tree
Hide file tree
Showing 325 changed files with 58,713 additions and 0 deletions.
203 changes: 203 additions & 0 deletions .github/workflows/solana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
name: Solana

on:
push:
branches:
- main
pull_request:

concurrency:
group: solana-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
working-directory: ./chains/solana

jobs:
get_anchor_version:
name: Get Anchor Version
runs-on: ubuntu-latest
outputs:
anchor_version: ${{ steps.anchorversion.outputs.anchor }}
steps:
- name: Checkout the repo
uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Get Anchor Version
id: anchorversion
run: |
anchor=$(make anchor_version)
echo "anchor=${anchor}" >>$GITHUB_OUTPUT
build_solana:
name: cache build artifacts
runs-on: ubuntu-latest-8cores-32GB
needs: [get_anchor_version]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
lookup-only: true
path: chains/solana/contracts/docker-build.tar
key: ${{ runner.os }}-solana-build-${{ needs.get_anchor_version.outputs.anchor_version }}-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo target dir
id: cache-target
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
lookup-only: true
path: chains/solana/contracts/target
key: ${{ runner.os }}-solana-contract-artifacts-${{ hashFiles('**/Cargo.lock') }}
- name: build & save image
if: steps.cache-image.outputs.cache-hit != 'true'
run: |
cd contracts
docker buildx build . -t ccip-solana:build --build-arg ANCHOR_CLI=${{ needs.get_anchor_version.outputs.anchor_version }}
docker save -o docker-build.tar ccip-solana
- name: build & save contract compilation artifacts
if: steps.cache-target.outputs.cache-hit != 'true'
run: |
docker run -v "$(pwd)/":/solana ccip-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
cd /solana/contracts &&\
anchor build &&\
chmod -R 755 ./target"
rust:
name: rust tests
runs-on: ubuntu-latest
needs: [get_anchor_version, build_solana]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/target
key: ${{ runner.os }}-solana-contract-artifacts-${{ hashFiles('**/Cargo.lock') }}
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/docker-build.tar
key: ${{ runner.os }}-solana-build-${{ needs.get_anchor_version.outputs.anchor_version }}-${{ hashFiles('**/Cargo.lock') }}
- name: load cached image
run: |
docker load --input contracts/docker-build.tar
- name: run tests
run: |
docker run -v "$(pwd)/":/solana ccip-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
cd /solana/contracts &&\
anchor build &&\
cargo check &&\
cargo clippy -- -D warnings &&\
cargo test --workspace"
go:
name: go tests
runs-on: ubuntu-latest-8cores-32GB
needs: [get_anchor_version, build_solana]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/target
key: ${{ runner.os }}-solana-contract-artifacts-${{ hashFiles('**/Cargo.lock') }}
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/docker-build.tar
key: ${{ runner.os }}-solana-build-${{ needs.get_anchor_version.outputs.anchor_version }}-${{ hashFiles('**/Cargo.lock') }}
- name: load cached image
run: |
docker load --input contracts/docker-build.tar
- name: Setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: "./chains/solana/go.mod"
check-latest: true
cache-dependency-path: "./chains/solana/go.sum"
- name: Install gotestloghelper
run: go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@latest
- name: Install Solana CLI
run: |
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)" # always use latest stable release from solana
echo "PATH=$HOME/.local/share/solana/install/active_release/bin:$PATH" >> $GITHUB_ENV
- name: build + test
run: |
set -eoux pipefail
# compile artifacts
docker run -v "$(pwd)/":/solana ccip-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
cd /solana/contracts &&\
anchor build"
make go-tests
lint:
name: lint + check artifacts
runs-on: ubuntu-latest
needs: [get_anchor_version, build_solana]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/target
key: ${{ runner.os }}-solana-contract-artifacts-${{ hashFiles('**/Cargo.lock') }}
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
fail-on-cache-miss: true
path: chains/solana/contracts/docker-build.tar
key: ${{ runner.os }}-solana-build-${{ needs.get_anchor_version.outputs.anchor_version }}-${{ hashFiles('**/Cargo.lock') }}
- name: load cached image
run: |
docker load --input contracts/docker-build.tar
- name: Setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version-file: "./chains/solana/go.mod"
check-latest: true
cache-dependency-path: "./chains/solana/go.sum"
- name: check artifacts
run: |
set -eoux pipefail
# compile artifacts
docker run -v "$(pwd)/":/solana ccip-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
cd /solana/contracts &&\
rm -rf target/idl &&\
anchor build"
go install github.com/gagliardetto/[email protected]
./scripts/anchor-go-gen.sh
make format
git diff --exit-code
- name: Install linter
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.62.2
- name: Run linter
run: make lint-go
- name: Print lint report artifact
if: failure()
shell: bash
run: cat ./golangci-lint-report.xml


3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# 2024-12-04 - The codeowners file is correct
* @smartcontractkit/ccip-offchain

# solana development ownership
/chains/solana @smartcontractkit/ccip-onchain-solana
29 changes: 29 additions & 0 deletions chains/solana/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.direnv
*.DS_Store
**/*.rs.bk
.idea
.vscode/

# ignore target folders except IDLs
contracts/target/*
!contracts/target/idl/
contracts/programs/*/target
contracts/.anchor
# keypair used by anchor/anchor test
contracts/id.json
# ignore all except shared localnet keys
contracts/artifacts/*
!contracts/artifacts/localnet/
test-ledger

# Test & linter reports
.test_summary/
*report.xml
*report.json
*.out
*coverage*
eslint-report.json
.run.id
override*.toml
# go work files
go.work*
156 changes: 156 additions & 0 deletions chains/solana/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
run:
timeout: 15m0s
linters:
enable:
- exhaustive
- exportloopref
- revive
- goimports
- gosec
- misspell
- rowserrcheck
- errorlint
- unconvert
- sqlclosecheck
- noctx
- whitespace
- depguard
- containedctx
- fatcontext
- mirror
- loggercheck
linters-settings:
exhaustive:
default-signifies-exhaustive: true
goimports:
local-prefixes: github.com/smartcontractkit/chainlink-ccip/chains/solana
golint:
min-confidence: 1.0
gosec:
excludes:
- G101
- G104
# - G204
# - G304
# - G404
govet:
enable:
- shadow
settings:
printf:
# Additionally check custom logger
funcs:
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Debugf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Infof
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Warnf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Errorf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Panicf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Fatalf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).AssumptionViolationf
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).Tracef
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).Criticalf
errorlint:
# Allow formatting of errors without %w
errorf: false
revive:
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
# - name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
# - name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: waitgroup-by-value
- name: unconditional-recursion
- name: struct-tag
# - name: string-format
- name: string-of-int
- name: range-val-address
- name: range-val-in-closure
- name: modifies-value-receiver
- name: modifies-parameter
- name: identical-branches
- name: get-return
# - name: flag-parameter
- name: early-return
- name: defer
- name: constant-logical-expr
# - name: confusing-naming
# - name: confusing-results
- name: bool-literal-in-expr
- name: atomic
depguard:
rules:
main:
list-mode: lax
deny:
- pkg: "cosmossdk.io/errors"
desc: Use the standard library instead
- pkg: "github.com/ethereum/go-ethereum"
desc: This is chain must be isolated from ethereum
- pkg: "github.com/go-gorm/gorm"
desc: Use github.com/jmoiron/sqlx directly instead
- pkg: "github.com/gofrs/uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/pkg/errors"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "github.com/satori/go.uuid"
desc: Use github.com/google/uuid instead
- pkg: "github.com/test-go/testify/assert"
desc: Use github.com/stretchr/testify/assert instead
- pkg: "github.com/test-go/testify/mock"
desc: Use github.com/stretchr/testify/mock instead
- pkg: "github.com/test-go/testify/require"
desc: Use github.com/stretchr/testify/require instead
- pkg: "go.uber.org/multierr"
desc: Use the standard library instead, for example https://pkg.go.dev/errors#Join
- pkg: "gopkg.in/guregu/null.v1"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v2"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: "gopkg.in/guregu/null.v3"
desc: Use gopkg.in/guregu/null.v4 instead
- pkg: github.com/go-gorm/gorm
desc: Use github.com/jmoiron/sqlx directly instead
loggercheck:
# Check that *w logging functions have even number of args (i.e., well formed key-value pairs).
rules:
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Debugw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Infow
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Warnw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Errorw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Panicw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.Logger).Fatalw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).AssumptionViolationw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).Tracew
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).Criticalw
- (github.com/smartcontractkit/chainlink-common/pkg/logger.SugaredLogger).With
issues:
exclude-rules:
- path: test
text: "^G404:"
linters:
- gosec
- path: _test.go
text: "G115:" # ignore integer overflow in test conversions
linters:
- gosec
Loading

0 comments on commit 814a10a

Please sign in to comment.