Skip to content

Commit

Permalink
Merge branch 'main' into miner
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored May 22, 2024
2 parents 3d3f8e7 + fee3df5 commit 030ea1e
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Ignore everything
**

# Except these files and directories
!docker/
!docker/Dockerfile.run_with_importer
!src/
!Cargo.toml
!Cargo.lock
!static/
!.sqlx/
!build.rs
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ e2e-contracts/integration/tsconfig.json
/target
vendor
stratus.log
kubeconfig.yaml

# OS specific
.DS_Store
.DS_Store
12 changes: 6 additions & 6 deletions Cargo.lock

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

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ ethereum-types = "=0.14.1"
ethers-core = "=2.0.14"
evm-disassembler = "=0.5.0"
keccak-hasher = "=0.15.3" # this version must be compatible with triehash
revm = { version = "=8.0.0", features = ["asm-keccak"] }


rlp = "=0.5.2"
triehash = "=0.8.4"

Expand Down Expand Up @@ -157,6 +158,7 @@ metrics = ["dep:metrics", "dep:metrics-exporter-prometheus"]
# Enable RocksDB dependencies.
rocks = ["rocksdb", "bincode"]

# Tools to comunicate with other pods
kubernetes = ["kube", "k8s-openapi"]

# XXX: Enable external transaction parallel execution.
Expand All @@ -171,3 +173,10 @@ clone_on_ref_ptr = "warn"
disallowed_names = "warn"
manual_let_else = "warn"
semicolon_if_nothing_returned = "warn"



[target.'cfg(not(all(target_arch = "aarch64", target_os = "linux")))'.dependencies]
revm = { version = "=8.0.0", features = ["asm-keccak"]}
[target.'cfg(all(target_arch = "aarch64", target_os = "linux"))'.dependencies]
revm = { version = "=8.0.0" }
27 changes: 27 additions & 0 deletions chaos/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

echo "Checking OS and installing dependencies..."

if [ "$(uname)" = "Darwin" ]; then
echo "Installing dependencies for macOS..."
if ! [ -x "$(command -v kind)" ]; then
brew install kind
fi
if ! [ -x "$(command -v kubectl)" ]; then
brew install kubectl
fi
else
echo "Installing dependencies for Linux..."
if ! [ -x "$(command -v kind)" ]; then
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
fi
if ! [ -x "$(command -v kubectl)" ]; then
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
fi
fi

echo "Dependencies installed"
68 changes: 68 additions & 0 deletions chaos/local-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: stratus-api
labels:
app: stratus-api
spec:
serviceName: "stratus-api"
replicas: 3
selector:
matchLabels:
app: stratus-api
template:
metadata:
labels:
app: stratus-api
spec:
containers:
- name: stratus-api
image: local/run_with_importer:latest
ports:
- containerPort: 3000
name: http
- containerPort: 9000
name: metrics
env:
- name: VERSION
valueFrom:
fieldRef:
fieldPath: metadata.labels['version']
- name: APP_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['app']
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: MY_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MY_POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: MY_POD_SERVICE_ACCOUNT
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName
- name: ENVIRONMENT
value: staging
- name: ENV
value: staging
volumeMounts:
- mountPath: /app/data
name: rocksdata
volumes:
- name: rocksdata
emptyDir: {}
14 changes: 14 additions & 0 deletions chaos/local-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: stratus-api
spec:
selector:
app: stratus-api
ports:
- protocol: TCP
port: 3000
targetPort: 3000
- protocol: TCP
port: 9000
targetPort: 9000
1 change: 1 addition & 0 deletions config/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ kubernetes:
service:
asmRevision: asm-managed-stable
version: 165baf1646bc39718ec8c5b9c7cfa7fcb9b1db56
skipRebuild: true
apps:
- name: stratus-api
dockerfile: ./docker/Dockerfile.run_with_importer
Expand Down
43 changes: 43 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,46 @@ contracts-coverage-erase:
#!/bin/bash
cd e2e-contracts/repos
rm -rf */coverage

# Chaos Testing: Set up and run local Kubernetes cluster and deploy locally the application
local-chaos-setup:
@echo $(pwd)
@echo "Installing dependencies..."
./chaos/install-dependencies.sh
@echo "Cleaning up any existing Kind cluster..."
kind delete cluster --name local-testing || true
@echo "Setting up Kind cluster..."
kind create cluster --name local-testing
@echo "Configuring kubectl to use Kind cluster..."
kind get kubeconfig --name local-testing > kubeconfig.yaml
export KUBECONFIG=$(pwd)/kubeconfig.yaml
@echo "Building Docker image..."
docker build -t local/run_with_importer -f ./docker/Dockerfile.run_with_importer .
@echo "Loading Docker image into Kind..."
kind load docker-image local/run_with_importer --name local-testing
@echo "Deploying application..."
kubectl apply -f chaos/local-deployment.yaml
kubectl apply -f chaos/local-service.yaml
@echo "Waiting for pods to be ready..."
kubectl wait --for=condition=ready pod -l app=stratus-api --timeout=180s
@echo "Deployment complete. Checking pod status..."
kubectl get pods -o wide

# Chaos Testing: Clean up local Kubernetes cluster
local-chaos-cleanup:
@echo "Deleting Kind cluster..."
kind delete cluster --name local-testing
@echo "Cleanup complete."


# Chaos Testing: Run chaos test
local-chaos-test:
just local-chaos-setup
@echo "Simulating leader polling and followers syncing for 60 seconds..."
@for pod in $(kubectl get pods -l app=stratus-api -o jsonpath='{.items[*].metadata.name}'); do
@ kubectl exec -it $$pod -- /bin/sh -c 'for i in {1..60}; do curl -s http://staging-endpoint/eth_getBlockByNumber?params=[latest,true]; sleep 1; done' &
@done
wait
@echo "Leader polling and followers syncing simulated."
@echo "Cleaning up..."
just local-chaos-cleanup

0 comments on commit 030ea1e

Please sign in to comment.