Skip to content

Commit

Permalink
tuning to run on minikube
Browse files Browse the repository at this point in the history
  • Loading branch information
furkhat committed Oct 30, 2019
1 parent 3d5d5bb commit 0eb0e2d
Show file tree
Hide file tree
Showing 25 changed files with 435 additions and 178 deletions.
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
restore: true
mount:
- ./contracts/node_modules
- ./js/client_js/node_modules
- ./js/client/node_modules
- ./js/explorer/node_modules
- ./js/franklin_lib/node_modules
- ./target/cargo
Expand Down Expand Up @@ -92,7 +92,7 @@ steps:
rebuild: true
mount:
- ./contracts/node_modules
- ./js/client_js/node_modules
- ./js/client/node_modules
- ./js/explorer/node_modules
- ./js/franklin_lib/node_modules
- ./target/cargo
Expand Down
84 changes: 30 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ db-insert-contract:
update-frontend-contract:
@bin/update-frontend-contract.sh

db-reset: confirm_action db-drop db-setup db-insert-contract update-frontend-contract
db-reset: confirm_action db-wait db-drop db-setup db-insert-contract update-frontend-contract
@echo database is ready

db-migrate: confirm_action
Expand Down Expand Up @@ -90,13 +90,7 @@ image-nginx: dist-client dist-explorer
push-image-nginx: image-nginx
docker push "${NGINX_DOCKER_IMAGE}"

explorer-up: #dist-explorer
@docker build -t "${NGINX_DOCKER_IMAGE}" -f ./docker/nginx/Dockerfile .
@docker-compose up -d nginx


# Rust: cross-platform rust builder for linus

# Using RUST+Linux docker image (ekidd/rust-musl-builder) to build for Linux. More at https://github.com/emk/rust-musl-builder
docker-options = --rm -v $(shell pwd):/home/rust/src -v cargo-git:/home/rust/.cargo/git -v cargo-registry:/home/rust/.cargo/registry
rust-musl-builder = @docker run $(docker-options) ekidd/rust-musl-builder

Expand All @@ -116,6 +110,7 @@ server:
sandbox:
@cargo run --bin sandbox

# See more more at https://github.com/emk/rust-musl-builder#caching-builds
build-target:
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) cargo build --release
Expand Down Expand Up @@ -147,25 +142,8 @@ build-contracts: confirm_action
@bin/prepare-test-contracts.sh
@cd contracts && yarn build

# deploy-contracts: confirm_action
# @bin/deploy-contracts

# flattener = @docker run --rm -v $(shell pwd)/contracts:/home/contracts -it "${FLATTENER_DOCKER_IMAGE}"
# define flatten_file
# @echo flattening $(1)
# $(flattener) -c 'solidity_flattener --output /home/contracts/flat/$(1) /home/contracts/contracts/$(1)'
# endef

# # Flatten contract source
# flatten:
# @mkdir -p contracts/flat
# $(call flatten_file,FranklinProxy.sol)
# $(call flatten_file,Depositor.sol)
# $(call flatten_file,Exitor.sol)
# $(call flatten_file,Transactor.sol)

# Publish source to etherscan.io
source: #flatten
publish-source:
@node contracts/scripts/publish-source.js
@echo sources published

Expand All @@ -190,15 +168,24 @@ deposit: confirm_action
# Devops: main

# (Re)deploy contracts and database
ifeq (dev,$(FRANKLIN_ENV))
redeploy: confirm_action stop deploy-contracts db-insert-contract bin/minikube-copy-keys-to-host
else
redeploy: confirm_action stop deploy-contracts db-insert-contract
endif

ifeq (dev,$(FRANKLIN_ENV))
init-deploy: confirm_action deploy-contracts db-insert-contract bin/minikube-copy-keys-to-host
else
init-deploy: confirm_action deploy-contracts db-insert-contract

dev-ready = docker ps | grep -q "$(GETH_DOCKER_IMAGE)"
endif

start-local:
@docker ps | grep -q "$(GETH_DOCKER_IMAGE)" || { echo "Dev env not ready. Try: 'franklin dev-up'" && exit 1; }
@docker-compose up -d --scale prover=1 server prover nginx
@kubectl apply -f ./etc/kube/minikube/server.yaml
@kubectl apply -f ./etc/kube/minikube/prover.yaml
./bin/dev-update-server-vars
@kubectl apply -f ./etc/kube/minikube/postgres.yaml
@kubectl apply -f ./etc/kube/minikube/geth.yaml

dockerhub-push: image-nginx image-rust
docker push "${NGINX_DOCKER_IMAGE}"
Expand All @@ -225,7 +212,12 @@ endif

ifeq (dev,$(FRANKLIN_ENV))
stop: confirm_action
@docker-compose stop server prover
@kubectl delete deployments --selector=app=dev-server
@kubectl delete deployments --selector=app=dev-prover
@kubectl delete deployments --selector=app=dev-nginx
@kubectl delete svc --selector=app=dev-server
@kubectl delete svc --selector=app=dev-nginx
# not deleting postgres, geth and tesseract resources assuming they are being used for development too.
else ifeq (ci,$(FRANKLIN_ENV))
stop:
else
Expand Down Expand Up @@ -257,9 +249,6 @@ stop-nginx:
status:
@curl $(API_SERVER)/api/v0.1/status; echo

log-dc:
@docker-compose logs -f server prover

log-server:
kubectl logs -f deployments/$(FRANKLIN_ENV)-server

Expand All @@ -278,27 +267,15 @@ nodes:
# Dev environment

dev-up:
@{ docker ps | grep -q "$(GETH_DOCKER_IMAGE)" && echo "Dev env already running" && exit 1; } || echo -n
@docker-compose up -d postgres geth
@docker-compose up -d tesseracts
@{ kubectl get po | grep -q "postgres" && echo "Dev env already running" && exit 1; } || echo -n
@kubectl apply -f ./etc/kube/minikube/postgres.yaml
@kubectl create configmap tesseracts-config --from-file=./etc/tesseracts/tesseracts.toml
@kubectl apply -f ./etc/kube/minikube/geth.yaml

dev-down:
@docker-compose stop postgres geth
@docker-compose stop tesseracts

geth-up: geth
@docker-compose up geth

blockscout-migrate:
@docker-compose up -d blockscout_postgres
@docker-compose run blockscout /bin/sh -c "echo $MIX_ENV && mix do ecto.drop --force, ecto.create, ecto.migrate"

blockscout-up:
@docker-compose up -d blockscout_postgres blockscout

blockscout-down:
@docker-compose stop blockscout blockscout_postgres

@kubectl delete -f ./etc/kube/minikube/postgres.yaml
@kubectl delete -f ./etc/kube/minikube/geth.yaml
@kubectl delete configmap tesseracts-config

# Auxillary docker containers for dev environment (usually no need to build, just use images from dockerhub)

Expand All @@ -313,7 +290,6 @@ dev-push-geth:

dev-push-flattener:
@docker push "${FLATTENER_DOCKER_IMAGE}"

# Key generator

make-keys:
Expand Down
40 changes: 14 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Prepare dev environment prerequisites: see [docs/setup-dev.md](docs/setup-dev.md
## Setup local dev environment


(TODO(furkhat): remove when this step is implented and merged with https://github.com/matter-labs/franklin/pull/104) On a fresh copy of a project, run this once to generate test contracts:
```./bin/prepare-test-contracts.sh```

Setup:

```franklin init```
Expand All @@ -22,8 +19,11 @@ To completely reset the dev environment:

- Stop services:
```franklin dev-down```
- Remove mounted container data:
```rm -rf ./volumes```
- Remove containers data:
```
ssh minikube
rm -r /data/*
```
- Repeat the setup procedure above

# (Re)deploy db and contraсts:
Expand All @@ -45,26 +45,11 @@ Switch between configurations:
## Monitoring & management:

Seed for Metamask: fine music test violin matrix prize squirrel panther purchase material script deal
Geth: ```geth attach http://localhost:8545```
Geth: ```geth attach $(bin/dev-geth-url)```

NOTE: if you are resetting geth, each Metamask account must be manually reset via Settings > Advanced > Reset account.

# Blockscout (local blockchain explorer)

It generates quite some CPU load, but might be useful to visualize blockchain activity. Use with caution.

- Migrate blockscout (do this once to setup database):
```franklin blockscout-migrate```

- Start:
```franklin blockscout-up```

- Stop:
```franklin blockscout-down```

Blockscout will be available at http://localhost:4000/txs

## Build and run server + prover locally:
## Build and run server + prover locally for development:

Run server:
```
Expand Down Expand Up @@ -96,20 +81,23 @@ Client UI will be available at http://localhost:8080.
Make sure you have environment variables set right, you can check it by running:
```franklin env```. You should see `* dev` in output.

## Start server and prover as local docker containers:
## Start server and prover in minikube (this setup is closest to prod):

- Prerequisite: ```franklin init```

- Start:
```franklin start```

- Watch logs:
```franklin logs```
Server: ```franklin log-server```
Prover: ```franklin log-prover```

- Stop:
```franklin stop```

## Build and push images to dockerhub:

```franklin push```
```franklin dockerhub-push```

# Development

Expand Down Expand Up @@ -154,5 +142,5 @@ So you need to rebuild the code on every change (to be automated).
### Publish source code on etherscan

```
franklin flatten source
franklin publish-source
```
5 changes: 0 additions & 5 deletions bin/.setup_env
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ then
set +o allexport

# Postprocessing for all configs

export KUBECONFIG=etc/kube/clusters/kubeconfig-main.yaml

# if [[ $FIXMODE ]]; then
# export WEB3_URL=http://localhost:8545
# fi

popd > /dev/null
fi
3 changes: 3 additions & 0 deletions bin/cluster-ip
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

kubectl cluster-info| grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" -m 1
2 changes: 1 addition & 1 deletion bin/deploy-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ then
else
echo "Contract deployment failed"
exit 1
fi
fi
4 changes: 4 additions & 0 deletions bin/dev-database-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# For more details see service configuration at <project>/etc/kube/minikube/postgres.yaml
echo postgres://postgres@$(bin/cluster-ip):$(kubectl get svc postgres -o=jsonpath='{.spec.ports[0].nodePort}')/plasma
4 changes: 4 additions & 0 deletions bin/dev-geth-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# For more details see service configuration at <franklink-dir>/etc/kube/minikube/geth.yaml
echo http://$(bin/cluster-ip):$(kubectl get svc geth -o=jsonpath='{.spec.ports[0].nodePort}')
4 changes: 4 additions & 0 deletions bin/dev-tesseracts-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# For more details see service configuration at <franklink-dir>/etc/kube/minikube/geth.yaml
echo http://$(bin/cluster-ip):$(kubectl get svc tesseracts -o=jsonpath='{.spec.ports[0].nodePort}')
6 changes: 6 additions & 0 deletions bin/dev-update-server-vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Updating server deployments environment variables. Ussually executed on new contract deploy and related changes.
kubectl set env deployments/dev-server CONTRACT_ADDR=$(grep "CONTRACT_ADDR" deploy.log| sed 's/CONTRACT_ADDR=//')
kubectl set env deployments/dev-server GOVERNANCE_ADDR=$(grep "GOVERNANCE_ADDR" deploy.log| sed 's/GOVERNANCE_ADDR=//')
kubectl set env deployments/dev-server PRIORITY_QUEUE_ADDR=$(grep "PRIORITY_QUEUE_ADDR" deploy.log| sed 's/PRIORITY_QUEUE_ADDR=//')
5 changes: 5 additions & 0 deletions bin/minikube-copy-keys-to-host
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# When mounting a volume as a `hostPath` minikube containers has access to minikube host filesystem only,
# thus it is required to copy container files into it.
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r -i $(minikube ssh-key) ./keys/* docker@$(minikube ip):/home/docker
3 changes: 3 additions & 0 deletions bin/minikube-server-api-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo http://$(bin/cluster-ip):$(kubectl get svc dev-server -o=jsonpath='{.spec.ports[0].nodePort}')
3 changes: 3 additions & 0 deletions bin/minikube-ui-url
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo http://$(bin/cluster-ip):$(kubectl get svc dev-nginx -o=jsonpath='{.spec.ports[0].nodePort}')/client/login
2 changes: 1 addition & 1 deletion contracts/scripts/post-to-tesseracts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
await Axios.post('http://localhost:8000/0xc56e79caa94c96de01ef36560ac215cc7a4f0f47/contract', qs.stringify(req), config);
await Axios.post(`${process.env.TESSERACTS_URL}/0xc56e79caa94c96de01ef36560ac215cc7a4f0f47/contract`, qs.stringify(req), config);
}

main();
2 changes: 1 addition & 1 deletion contracts/src.ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function postContractToTesseracts(contractCode, contractName: strin
'Content-Type': 'application/x-www-form-urlencoded'
}
};
await Axios.post(`http://localhost:8000/${address}/contract`, qs.stringify(req), config);
await Axios.post(`${process.env.TESSERACTS_URL}/${address}/contract`, qs.stringify(req), config);
}

export async function addTestERC20Token(wallet, governance) {
Expand Down
2 changes: 1 addition & 1 deletion core/models/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub const FR_BIT_WIDTH_PADDED: usize = 256;
pub const TOTAL_TOKENS: usize = 1 << BALANCE_TREE_DEPTH;
pub const ETH_TOKEN_ID: TokenId = 0;

pub const BLOCK_SIZE_CHUNKS: usize = 100;
pub const BLOCK_SIZE_CHUNKS: usize = 18;

/// Priority op should be executed for this number of eth blocks.
pub const PRIORITY_EXPIRATION: u64 = 250;
Expand Down
24 changes: 24 additions & 0 deletions core/prover/used-vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# By folder:

## prover

KEY_DIR
POD_NAME

## models

TX_BATCH_SIZE
CONTRACT_ADDR
MAX_OUTSTANDING_TXS

## storage

DATABASE_URL
DB_POOL_SIZE


# Vars to dynamically update: None


# Vars pointing to external services:
DATABASE_URL
Loading

0 comments on commit 0eb0e2d

Please sign in to comment.