mirror of
https://github.com/autistic-symposium/mev-toolkit.git
synced 2025-04-26 18:59:20 -04:00
Add docker file, genesis file, and scripts
This commit is contained in:
parent
0fd2eb1442
commit
cbfceeb5d4
84
geth_and_k8s/README.md
Normal file
84
geth_and_k8s/README.md
Normal file
@ -0,0 +1,84 @@
|
||||
# Creating an Ethereum blockchain
|
||||
|
||||
To create this blockchaon, we use [geth](https://geth.ethereum.org/), the official client software provided by the Ethereum Foundation written in the Golang.
|
||||
|
||||
By default, geth implements [Clique](https://eips.ethereum.org/EIPS/eip-225#:~:text=Clique%20is%20a%20proof%2Dof,any%20client%20with%20minimal%20effort.), a proof-of-authority mechanism to reach consensus. Moreover, a number of accounts a defined to produce new blocks in the chain.
|
||||
|
||||
A custom Ethereum testnet contains three components:
|
||||
|
||||
* a custom [genesis file](/genesis.json
|
||||
* a custom data directory, which we define with `GETH_DATADIR`
|
||||
* a custom `NetworkID` , which we set `137`
|
||||
|
||||
|
||||
### Gas
|
||||
|
||||
Gas refers to the unit that measures the computational effort required to execute specific operations on the Ethereum network.
|
||||
|
||||
### Nodes
|
||||
|
||||
Running nodes are responsible for the following tasks:
|
||||
|
||||
- store blockchain data,
|
||||
- participates in block validation (verifying blocks and states),
|
||||
- serve the network and provides data on request.
|
||||
|
||||
### Storage
|
||||
|
||||
More details to be added soon.
|
||||
|
||||
### Faucet
|
||||
|
||||
More details to be added soon.
|
||||
|
||||
---
|
||||
|
||||
## Interacting with the client
|
||||
|
||||
|
||||
You can run commands directly in the console:
|
||||
|
||||
|
||||
##### Getting total coinbase
|
||||
|
||||
```
|
||||
> web3.fromWei(eth.getBalance(eth.coinbase), "ether")
|
||||
```
|
||||
|
||||
##### Getting a balance from an account
|
||||
|
||||
```
|
||||
> web3.fromWei(eth.getBalance("2ee8D80de1c389f1254e94bc44D2d1Bc391eD402"), "ether")
|
||||
```
|
||||
#### txpool API
|
||||
|
||||
Access to several non-standard RPC methods to inspect the contents of the transaction pool containing all the currently pending transactions as well as the ones queued for future processing:
|
||||
|
||||
```
|
||||
txpool
|
||||
```
|
||||
|
||||
#### Other useful checks
|
||||
|
||||
```
|
||||
admin.nodeInfo
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Setting this chain on MetaMask
|
||||
|
||||
Click a `Custom RPC` network and add:
|
||||
|
||||
```
|
||||
Network Name: "<project name>"
|
||||
New RPC URL: localhost
|
||||
Chain ID: 137
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
|
||||
* [geth commands](https://geth.ethereum.org/docs/interface/command-line-options)
|
||||
|
17
geth_and_k8s/create_docker.sh
Executable file
17
geth_and_k8s/create_docker.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
PORT=${PORT:-18545}
|
||||
|
||||
echo "Building local blockchain container"
|
||||
|
||||
docker build -t <docker container alias> .
|
||||
|
||||
echo "Starting blockchain network on port $PORT (use rpc URL http://localhost:$PORT)"
|
||||
|
||||
docker run -it --rm \
|
||||
-v $(pwd)/genesis.json:/genesis.json \
|
||||
-v $(pwd)/data:/data \
|
||||
-p $PORT:8545 \
|
||||
<docker container alias>
|
69
geth_and_k8s/entrypoint.sh
Normal file
69
geth_and_k8s/entrypoint.sh
Normal file
@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
GETH_DATADIR=${GETH_DATADIR:-"/data"}
|
||||
|
||||
geth_init() {
|
||||
ls -al "$GETH_DATADIR"
|
||||
|
||||
if [[ -d "$GETH_DATADIR/keystore" ]]; then
|
||||
echo "Chain already initialized"
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Initializing using Genesis"
|
||||
geth init --datadir "$GETH_DATADIR" /genesis.json
|
||||
}
|
||||
|
||||
geth_custom_start() {
|
||||
echo "Starting node with custom arguments $@"
|
||||
exec geth $@
|
||||
}
|
||||
|
||||
geth_normal_start() {
|
||||
echo "Starting node"
|
||||
local identity=${GETH_IDENTITY:-"<docker container alias>"}
|
||||
local http_corsdomain=${GETH_HTTP_CORSDOMAIN:-"http://localhost:3000"}
|
||||
local http_vhosts=${GETH_HTTP_VHOSTS:-"localhost"}
|
||||
local networkid=${GETH_NETWORKID:-"137"}
|
||||
local enable_mining=${ENABLING_MINING:-"YES"}
|
||||
|
||||
local mining_args=""
|
||||
if [[ "$enable_mining" == "YES" ]]; then
|
||||
local miner_etherbase=${GETH_MINER_ETHERBASE:-"<add etherbase>"}
|
||||
local miner_threads=${GETH_MINER_THREADS:-1}
|
||||
mining_args="$mining_args --mine"
|
||||
mining_args="$mining_args --miner.threads $miner_threads"
|
||||
mining_args="$mining_args --miner.etherbase $miner_etherbase"
|
||||
fi
|
||||
|
||||
exec geth \
|
||||
--identity "$identity" \
|
||||
--nodiscover \
|
||||
--http \
|
||||
--http.addr 0.0.0.0 \
|
||||
--http.corsdomain "$http_corsdomain" \
|
||||
--http.vhosts "$http_vhosts" \
|
||||
--networkid "$networkid" \
|
||||
--datadir "$GETH_DATADIR" \
|
||||
$mining_args \
|
||||
"$@"
|
||||
}
|
||||
|
||||
main() {
|
||||
local should_initialize=${SHOULD_INITIALIZE:-"YES"}
|
||||
local custom_start=${CUSTOM_START:-"NO"}
|
||||
|
||||
if [[ "$should_initialize" == "YES" ]]; then
|
||||
geth_init
|
||||
fi
|
||||
|
||||
if [[ "$custom_start" == "YES" ]]; then
|
||||
geth_custom_start "$@"
|
||||
else
|
||||
geth_normal_start "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
29
geth_and_k8s/genenis.json
Normal file
29
geth_and_k8s/genenis.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"config": {
|
||||
"chainId": 137,
|
||||
"homesteadBlock": 0,
|
||||
"eip150Block": 0,
|
||||
"eip155Block": 0,
|
||||
"eip158Block": 0,
|
||||
"byzantiumBlock": 0,
|
||||
"constantinopleBlock": 0,
|
||||
"petersburgBlock": 0
|
||||
},
|
||||
"difficulty": "0x400",
|
||||
"gasLimit":"0x2100000",
|
||||
"nonce": "0x000000000fab0042",
|
||||
"alloc": {
|
||||
"3282791d6fd713f1e94f4bfd565eaa78b3a0599d": {
|
||||
"balance": "1337000000000000000000"
|
||||
},
|
||||
"64D2ea7000e831E03e6B930AC348fD90D4ACE2B8": {
|
||||
"balance": "1337000000000000000000"
|
||||
},
|
||||
"2ee8D80de1c389f1254e94bc44D2d1Bc391eD402": {
|
||||
"balance": "1337000000000000000000"
|
||||
},
|
||||
"Ac03BB73b6a9e108530AFf4Df5077c2B3D481e5A": {
|
||||
"balance": "1337000000000000000000"
|
||||
}
|
||||
}
|
||||
}
|
8
geth_and_k8s/genesis.dockerfile
Normal file
8
geth_and_k8s/genesis.dockerfile
Normal file
@ -0,0 +1,8 @@
|
||||
FROM ethereum/client-go:stable
|
||||
|
||||
RUN apk add --no-cache bash
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
COPY genesis.json /genesis.json
|
||||
|
||||
ENTRYPOINT /entrypoint.sh
|
Loading…
x
Reference in New Issue
Block a user