mirror of
https://github.com/autistic-symposium/mev-toolkit.git
synced 2025-08-08 06:12:33 -04:00
add link to readme
This commit is contained in:
parent
d5b3eccf85
commit
ad7afaed3f
5 changed files with 6 additions and 0 deletions
205
geth_and_k8s/PoCs/deployment_gcp_docker.md
Normal file
205
geth_and_k8s/PoCs/deployment_gcp_docker.md
Normal file
|
@ -0,0 +1,205 @@
|
|||
# Deployment of geth in GCP + docker
|
||||
|
||||
In this deployment, we use **Container-Optimized OS** to permit the deployment of a Docker image to a **Google Compute Engine VM**.
|
||||
|
||||
This is the simplest way to run the `ethereum/client-go` image. This will install `geth`, the **Golang CLI Ethereum client** for running a full Ethereum node and interacting with Ethereum networks.
|
||||
|
||||
---
|
||||
|
||||
### Installing
|
||||
|
||||
Install [google cloud sdk](https://cloud.google.com/sdk/docs/quickstart) and configure it with:
|
||||
|
||||
```
|
||||
gcloud init
|
||||
gcloud auth login
|
||||
gcloud config set project <project name>
|
||||
```
|
||||
|
||||
### Create the instance
|
||||
|
||||
|
||||
```
|
||||
gcloud beta compute instances create-with-container <docker container alias> \
|
||||
--boot-disk-size=500GB \
|
||||
--boot-disk-type=pd-ssd \
|
||||
--container-image=ethereum/client-go \
|
||||
--container-arg="--rpc" \
|
||||
--container-arg="--rpcaddr=0.0.0.0" \
|
||||
--container-restart-policy=always \
|
||||
--container-mount-host-path=\
|
||||
mount-path=/root,\
|
||||
host-path=/tmp/client-go,\
|
||||
mode=rw \
|
||||
--image-family=cos-stable \
|
||||
--image-project=cos-cloud \
|
||||
--zone=<which zone?> \
|
||||
--project=<project name>
|
||||
```
|
||||
|
||||
|
||||
The instance should be available at the project's [GCP dashboard](https://console.cloud.google.com/compute/instances).
|
||||
|
||||
|
||||
`Geth` needs to have a special CORS setting enabled to allow MetaMask to connect to it by default, so try starting it with this command:
|
||||
|
||||
```
|
||||
geth --rpc --rpccorsdomain="chrome-extension://<hash>"
|
||||
```
|
||||
|
||||
### Start `konlet-startup`
|
||||
|
||||
`konlet-startup` is the `systemd` service that corresponds to the docker image deployment in the **Container-Optimized OS**.
|
||||
|
||||
Run:
|
||||
|
||||
```
|
||||
gcloud compute ssh <docker container alias> \
|
||||
--command="sudo journalctl --unit=konlet-startup --follow" \
|
||||
--project=<project name>
|
||||
```
|
||||
|
||||
### Confirm that the container is running
|
||||
|
||||
```
|
||||
gcloud compute ssh <docker container alias> \
|
||||
--command="docker ps --format='[{{.ID}}] {{.Names}}: {{.Status}}'" \
|
||||
--project=<project name>
|
||||
```
|
||||
|
||||
|
||||
### SSH and port-forwarding
|
||||
|
||||
```
|
||||
gcloud compute ssh <docker container alias> \
|
||||
--ssh-flag="-L 8545:localhost:8545" \
|
||||
--project=<project name>
|
||||
```
|
||||
|
||||
Success looks like:
|
||||
|
||||
```
|
||||
########################[ Welcome ]########################
|
||||
# You have logged in to the guest OS. #
|
||||
# To access your containers use 'docker attach' command #
|
||||
###########################################################
|
||||
|
||||
<user>@<project name> >
|
||||
```
|
||||
|
||||
### Additional configuration for the intance
|
||||
|
||||
* [Alocate a static IP](https://console.cloud.google.com/networking/addresses/).
|
||||
* [Prevent deletion](https://console.cloud.google.com/compute/instancesDetail/).
|
||||
* Configure CORS [here]().
|
||||
|
||||
|
||||
----
|
||||
|
||||
## Creating the Testnet
|
||||
|
||||
The command to create a testnet with `geth` is:
|
||||
|
||||
```
|
||||
geth init --datadir data ./genesis.json
|
||||
|
||||
```
|
||||
|
||||
and then starting the node:
|
||||
|
||||
```
|
||||
geth --datadir data --networkid NetworkID
|
||||
```
|
||||
|
||||
`NetworkID` helps ensure the privacy of your network. You can use any number and peers joining the network must use the same number.
|
||||
|
||||
### Starting the genesis block
|
||||
|
||||
Inside the instance, create the `genesis.json` file:
|
||||
|
||||
```
|
||||
vim ~/genesis.json
|
||||
```
|
||||
with
|
||||
```
|
||||
{
|
||||
"config": {
|
||||
"chainId": 137,
|
||||
"homesteadBlock": 0,
|
||||
"eip150Block": 0,
|
||||
"eip155Block": 0,
|
||||
"eip158Block": 0,
|
||||
"byzantiumBlock": 0,
|
||||
"constantinopleBlock": 0,
|
||||
"petersburgBlock": 0
|
||||
},
|
||||
"difficulty": "0x400",
|
||||
"gasLimit":"0x2100000",
|
||||
"alloc": {
|
||||
"3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
|
||||
"balance": "1337000000000000000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Start the testnet with:
|
||||
|
||||
```
|
||||
geth --identity <project name> --nodiscover --networkid 137 --datadir ~/data init ~/genesis.json
|
||||
```
|
||||
|
||||
Where `geth` flags are:
|
||||
* `--datadir` indicates the data for our local testnet.
|
||||
* `--nodiscover`, `--maxpeers 0`, `--rpc`, `--rpcapi` make sure the network is private.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## Interacting with the testnet
|
||||
|
||||
### Connecting to a member node
|
||||
|
||||
From another terminal, run:
|
||||
|
||||
```
|
||||
docker run \
|
||||
--rm \
|
||||
--interactive \
|
||||
--net=host \
|
||||
--tty \
|
||||
ethereum/client-go \
|
||||
attach http://localhost:8545
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```
|
||||
geth attach http://localhost:8545
|
||||
```
|
||||
|
||||
Success looks like:
|
||||
|
||||
```
|
||||
Welcome to the Geth JavaScript console!
|
||||
>
|
||||
```
|
||||
|
||||
### Monitoring
|
||||
|
||||
* GCP logs can be found [here](https://console.cloud.google.com/logs).
|
||||
* To look at the output from the tesnet run:
|
||||
|
||||
```
|
||||
FILTER="resource.type=\"global\" "\
|
||||
"logName=\"projects/<project-name>/logs/gcplogs-docker-driver\" "
|
||||
|
||||
gcloud logging read "${FILTER}" \
|
||||
--project=<project name> \
|
||||
--format="value(jsonPayload.data)" \
|
||||
--order=asc
|
||||
```
|
||||
|
53
geth_and_k8s/PoCs/deployment_gcp_k8s.md
Normal file
53
geth_and_k8s/PoCs/deployment_gcp_k8s.md
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Deployment of geth in GCP + Kubernetes
|
||||
|
||||
## Deployment
|
||||
|
||||
```
|
||||
NAMESPACE=ethereum
|
||||
kubectl create namespace ${NAMESPACE}
|
||||
kubectl apply --filename=deployment.yaml --namespace=${NAMESPACE}
|
||||
```
|
||||
|
||||
|
||||
## Accessing node without opening firewall
|
||||
|
||||
|
||||
```
|
||||
SERVICE=ethereum
|
||||
NAMESPACE=ethereum
|
||||
|
||||
NODE=$(\
|
||||
kubectl get nodes \
|
||||
--output=jsonpath='{.items[0].metadata.name}')
|
||||
|
||||
PORT=$(\
|
||||
kubectl get services/${SERVICE} \
|
||||
--namespace=${NAMESPACE} \
|
||||
--output=jsonpath='{.spec.ports[?(@.name=="default")].nodePort}')
|
||||
|
||||
echo ${PORT}
|
||||
|
||||
gcloud compute ssh <docker container alias> \
|
||||
--ssh-flag="-L ${PORT}:localhost:${PORT}" \
|
||||
--project=<project name>
|
||||
```
|
||||
|
||||
|
||||
## Member connecting
|
||||
|
||||
```
|
||||
docker run \
|
||||
--rm \
|
||||
--interactive \
|
||||
--tty \
|
||||
--net=host \
|
||||
ethereum/client-go attach http://localhost:${PORT}
|
||||
```
|
||||
|
||||
### Dealing with secrets
|
||||
|
||||
```
|
||||
kubectl create secret generic keystore \
|
||||
--from-file=path/to/keystore \
|
||||
--namespace=$NAMESPACE
|
||||
```
|
30
geth_and_k8s/PoCs/genesis_block_explanation.md
Normal file
30
geth_and_k8s/PoCs/genesis_block_explanation.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
## What's the genesis block
|
||||
|
||||
The genesis block is a `JSON` file hardcoded into clients and Ethereum's consensus algorithm.
|
||||
|
||||
It's the start of the blockchain, the first block (`block 0`), and the only block that does not point to a predecessor block.
|
||||
|
||||
|
||||
It ensures that no other node will agree unless they have the same genesis block.
|
||||
|
||||
---
|
||||
|
||||
#### Fields
|
||||
|
||||
* **chainId**: A unique identifier of the new private blockchain
|
||||
|
||||
* **mixhash**: A `256-bit` hash which proves, combined with the nonce, that a sufficient amount of computation has been carried out on this block (Proof-of-Work).
|
||||
|
||||
* **nonce**: A `64-bit hash`, which proves, combined with the mixhash, that a sufficient amount of computation has been carried out on this block (Proof-of-Work).
|
||||
|
||||
* **difficulty**: A value corresponding to the difficulty level applied during the nonce discovering of this block. The higher the difficulty, the statistically more calculations a miner must perform to discover a valid block.
|
||||
|
||||
* **alloc**: Allows defining a list of pre-filled wallets.
|
||||
|
||||
* **coinbase**: A `160-bit` address to which all rewards (in Ether) collected from the successful mining of the block have been transferred. This can be anything in the Genesis Block since the value is set by the setting of the Miner when a new Block is created.
|
||||
|
||||
* **timestamp**: A value equal to the reasonable output of Unix `time()` function at this block inception.
|
||||
|
||||
* **parentHash**: A `256-bit` hash of the entire parent block header (including its nonce and mixhash). Pointer to the parent block, thus effectively building the chain of blocks. In the case of the Genesis block, and only in this case, it’s 0.
|
||||
|
||||
* **gasLimit**: A scalar value equal to the current chain-wide limit of Gas expenditure per block. High in our case to avoid being limited by this threshold during tests.
|
75
geth_and_k8s/PoCs/geth_creation_commands.md
Normal file
75
geth_and_k8s/PoCs/geth_creation_commands.md
Normal file
|
@ -0,0 +1,75 @@
|
|||
# geth creation commands
|
||||
|
||||
|
||||
### Create a miner account
|
||||
|
||||
This will generate a public/private key pair. By default, keys are stored inside, `<datadir>/keystore`. Everything `geth` persists gets written inside `<datadir>`.
|
||||
|
||||
The following command returns a private testnet address (which should be saved together with the password):
|
||||
|
||||
```
|
||||
geth account new --datadir /path/to/data
|
||||
```
|
||||
|
||||
### Start mining
|
||||
|
||||
With `NetworkID`:
|
||||
|
||||
```
|
||||
geth --mine --rpc --networkid NetworkID --datadir /path/to/data
|
||||
```
|
||||
|
||||
Start mining:
|
||||
|
||||
```
|
||||
> miner.start()
|
||||
```
|
||||
|
||||
To end mining, type:
|
||||
|
||||
```
|
||||
> miner.stop()
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Pre-fund the account
|
||||
|
||||
Deploying contracts or making transactions requires test ether, which has no value and can be acquired for free from several "faucets".
|
||||
|
||||
The command `geth removedb` deletes the locally synced blockchain data of the public testnet (i.e., resyncs with the chain).
|
||||
|
||||
To add magic ether, remove the created blockchain database:
|
||||
|
||||
```
|
||||
geth removedb --datadir /path/to/data
|
||||
```
|
||||
|
||||
Modify `genesis.json` as necessary, including multiple accounts in the seed if wanted.
|
||||
|
||||
Finally, re-initialize the genesis block:
|
||||
|
||||
```
|
||||
geth --identity <project name> --nodiscover --networkid 1337 --datadir /path/to/data init /path/to/genesis.json
|
||||
```
|
||||
|
||||
### Create new accounts
|
||||
|
||||
```
|
||||
geth --datadir . account new
|
||||
```
|
||||
|
||||
### List accounts
|
||||
|
||||
```
|
||||
geth --datadir . account list
|
||||
```
|
||||
|
||||
|
||||
### Connect to the testnet
|
||||
|
||||
```
|
||||
geth attach
|
||||
```
|
||||
|
||||
You will enter into the **Geth Javascript console**, where you can run JavaScript code.
|
Loading…
Add table
Add a link
Reference in a new issue