Skip to content

Commit 3c6608b

Browse files
committed
clean up lib and move docs
1 parent 7c37272 commit 3c6608b

File tree

10 files changed

+1566
-403
lines changed

10 files changed

+1566
-403
lines changed

book/src/SUMMARY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,13 @@
4545
- [Components](developing/developing_components.md)
4646
- [Releasing modules](releasing_modules.md)
4747

48+
---
49+
- [Lib (Legacy, *Deprecated*)](lib.md)
50+
- [Blockchain](lib/blockchain.md)
51+
- [Kubernetes](lib/k8s/KUBERNETES.md)
52+
- [K8s Remote Run](lib/k8s/REMOTE_RUN.md)
53+
- [K8s Tutorial](lib/k8s/TUTORIAL.md)
54+
- [Config](lib/config/config.md)
55+
4856
---
4957
- [Build info](build_info.md)

book/src/lib.md

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.

book/src/lib/blockchain.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Blockchain Clients
2+
3+
This folder contains the bulk of code that handles integrating with different EVM chains. If you're looking to run tests on a new EVM chain, and are having issues with the default implementation, you've come to the right place.
4+
5+
### Some Terminology
6+
7+
- [L2 Chain](https://ethereum.org/en/layer-2/): A Layer 2 chain "branching" off Ethereum.
8+
- [EVM](https://ethereum.org/en/developers/docs/evm/): Ethereum Virtual Machine that underpins the Ethereum blockchain.
9+
- [EVM Compatible](https://blog.thirdweb.com/evm-compatible-blockchains-and-ethereum-virtual-machine/#:~:text=What%20does%20'EVM%20compatibility'%20mean,significant%20changes%20to%20their%20code.): A chain that has some large, underlying differences from how base Ethereum works, but can still be interacted with largely the same way as Ethereum.
10+
- [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559): The Ethereum Improvement Proposal that changed how gas fees are calculated and paid on Ethereum
11+
- Legacy Transactions: Transactions that are sent using the old gas fee calculation method, the one used before EIP-1559.
12+
- Dynamic Fee Transaction: Transactions that are sent using the new gas fee calculation method, the one used after EIP-1559.
13+
14+
## How Client Integrations Work
15+
16+
In order to test Chainlink nodes, the `chainlink-testing-framework` needs to be able to interact with the chain that the node is running on. This is done through the `blockchain.EVMClient` interface. The `EVMClient` interface is a wrapper around [geth](https://geth.ethereum.org/) to interact with the blockchain. We conduct all our testing blockchain operations through this wrapper, like sending transactions and monitoring on-chain events. The primary implementation of this wrapper is built for [Ethereum](./ethereum.go). Most others, like the [Metis](./metis.go) and [Optimism](./optimism.go) integrations, extend and modify the base Ethereum implementation.
17+
18+
## Do I Need a New Integration?
19+
20+
If you're reading this, probably. The default EVM integration is designed to work with mainnet Ethereum, which covers most other EVM chain interactions, but it's not guaranteed to work with all of them. If you're on a new chain and the test framework is throwing errors while doing basic things like send transactions, receive new headers, or deploy contracts, you'll likely need to create a new integration. The most common issue with new chains (especially L2s) is gas estimations and lack of support for dynamic transactions.
21+
22+
## Creating a New Integration
23+
24+
Take a look at the [Metis](./metis.go) integration as an example. Metis is an L2, EVM compatible chain. It's largely the same as the base Ethereum integration, so we'll extend from that.
25+
26+
```go
27+
type MetisMultinodeClient struct {
28+
*EthereumMultinodeClient
29+
}
30+
31+
type MetisClient struct {
32+
*EthereumClient
33+
}
34+
```
35+
36+
Now we need to let other libraries (like our tests in the main Chainlink repo) that this integration exists. So we add the new implementation to the [known_networks.go](./known_networks.go) file. We can then add that network to our tests' own [known_networks.go](https://github.com/smartcontractkit/chainlink/blob/develop/integration-tests/known_networks.go) file (it's annoying, there are plans to simplify).
37+
38+
Now our Metis integration is the exact same as our base Ethereum one, which doesn't do us too much good. I'm assuming you came here to make some changes, so first let's find out what we need to change. This is a mix of reading developer documentation on the chain you're testing and trial and error. Mostly the latter in later stages. In the case of Metis, like many L2s, they [have their own spin on gas fees](https://docs.metis.io/dev/protocol-in-detail/transaction-fees-on-the-metis-platform). They also only support Legacy transactions. So we'll need to override any methods that deal with gas estimations, `Fund`, `DeployContract`, and `ReturnFunds`.

book/src/lib/config/config.md

Lines changed: 370 additions & 0 deletions
Large diffs are not rendered by default.

book/src/lib/k8s/KUBERNETES.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Kubernetes
2+
3+
We run our software in Kubernetes.
4+
5+
### Local k3d setup
6+
7+
1. `make install`
8+
2. (Optional) Install `Lens` from [here](https://k8slens.dev/) or use `k9s` as a low resource consumption alternative from [here](https://k9scli.io/topics/install/)
9+
or from source [here](https://github.com/smartcontractkit/helmenv)
10+
3. Setup your docker resources, 6vCPU/10Gb RAM are enough for most CL related tasks
11+
4. `make create_cluster`
12+
5. `make install_monitoring` Note: this will be actively connected to the server, the final log when it is ready is`Forwarding from [::1]:3000 -> 3000` and you can continue with the steps below in another terminal.
13+
6. Check your contexts with `kubectl config get-contexts`
14+
7. Switch context `kubectl config use-context k3d-local`
15+
8. Read [here](README.md) and do some deployments
16+
9. Open Grafana on `localhost:3000` with `admin/sdkfh26!@bHasdZ2` login/password and check the default dashboard
17+
10. `make stop_cluster`
18+
11. `make delete_cluster`
19+
20+
### Typical problems
21+
22+
1. Not enough memory/CPU or cluster is slow
23+
Recommended settings for Docker are (Docker -> Preferences -> Resources):
24+
- 6 CPU
25+
- 10Gb MEM
26+
- 50-150Gb Disk
27+
2. `NodeHasDiskPressure` errors, pods get evicted
28+
Use `make docker_prune` to clean up all pods and volumes

book/src/lib/k8s/REMOTE_RUN.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## How to run the same environment deployment inside k8s
2+
3+
You can build a `Dockerfile` to run exactly the same environment interactions inside k8s in case you need to run long-running tests
4+
Base image is [here](Dockerfile.base)
5+
6+
```Dockerfile
7+
FROM <account number>.dkr.ecr.us-west-2.amazonaws.com/test-base-image:latest
8+
COPY . .
9+
RUN env GOOS=linux GOARCH=amd64 go build -o test ./examples/remote-test-runner/env.go
10+
RUN chmod +x ./test
11+
ENTRYPOINT ["./test"]
12+
```
13+
14+
Build and upload it using the "latest" tag for the test-base-image
15+
16+
```bash
17+
build_test_image tag=someTag
18+
```
19+
20+
or if you want to specify a test-base-image tag
21+
22+
```bash
23+
build_test_image tag=someTag base_tag=latest
24+
```
25+
26+
Then run it
27+
28+
```bash
29+
# all environment variables with a prefix TEST_ would be provided for k8s job
30+
export TEST_ENV_VAR=myTestVarForAJob
31+
# your image to run as a k8s job
32+
ACCOUNT=$(aws sts get-caller-identity | jq -r .Account)
33+
export ENV_JOB_IMAGE="${ACCOUNT}.dkr.ecr.us-west-2.amazonaws.com/core-integration-tests:v1.1"
34+
# your example test file to run inside k8s
35+
# if ENV_JOB_IMAGE is present it will create a job, wait until it finished and get logs
36+
go run examples/remote-test-runner/env.go
37+
```

0 commit comments

Comments
 (0)