added keystore support

This commit is contained in:
Mikelle 2024-02-03 12:03:54 +08:00
parent 3443d0ddb5
commit 8a529991d9
10 changed files with 255 additions and 16 deletions

View file

@ -4,3 +4,4 @@ NODE2_PRIVATE_KEY=
RELAYER_PRIVATE_KEY=
NEXT_PUBLIC_WALLET_CONNECT_ID=
DD_KEY=
MEV_COMMIT_GETH_PASSWORD=

View file

@ -9,17 +9,21 @@ up-dev:
@if [ ! -f .env ]; then echo "Error: .env file not found. Please populate the .env file before running this command."; exit 1; fi
DD_KEY=nil docker compose --profile settlement up -d --build
up-dev-keystore:
@if [ ! -f .env ]; then echo "Error: .env file not found. Please populate the .env file before running this command."; exit 1; fi
DD_KEY=nil docker compose --profile settlement-keystore up -d --build
up-dev-local-l1:
@if [ ! -f .env ]; then echo "Error: .env file not found. Please populate the .env file before running this command."; exit 1; fi
DD_KEY=nil docker compose --profile settlement --profile local_l1 up -d
down:
docker compose --profile settlement --profile prod_agents --profile local_l1 down
docker compose --profile settlement --profile settlement-keystore --profile prod_agents --profile local_l1 down
clean-dbs:
@read -p "WARNING: This command will wipe all persistent disk data relevant to the containers. Press enter to continue or Ctrl+C to cancel." _
-docker compose --profile settlement --profile local_l1 down --rmi all --volumes
-docker compose --profile settlement --profile local_l1 rm -fv
-docker compose --profile settlement --profile local_l1 --profile settlement-keystore down --rmi all --volumes
-docker compose --profile settlement --profile local_l1 --profile settlement-keystore rm -fv
docker image prune -f
pull-image:

28
geth-poa/Node1Dockerfile Normal file
View file

@ -0,0 +1,28 @@
FROM golang:1.21-alpine AS builder
RUN apk add --no-cache gcc musl-dev linux-headers git make
COPY ../go.mod /go-ethereum/
COPY ../go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download
ADD .. /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
FROM alpine:latest
RUN apk add --no-cache jq
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
COPY geth-poa/genesis-keystore.json /genesis.json
COPY geth-poa/entrypoint.sh /entrypoint.sh
COPY geth-poa/node1/keystore /data/keystore
RUN chmod +x /entrypoint.sh
EXPOSE 8545 6060 60601
ENTRYPOINT ["/entrypoint.sh"]

28
geth-poa/Node2Dockerfile Normal file
View file

@ -0,0 +1,28 @@
FROM golang:1.21-alpine AS builder
RUN apk add --no-cache gcc musl-dev linux-headers git make
COPY ../go.mod /go-ethereum/
COPY ../go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download
ADD .. /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
FROM alpine:latest
RUN apk add --no-cache jq
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
COPY geth-poa/genesis-keystore.json /genesis.json
COPY geth-poa/entrypoint.sh /entrypoint.sh
COPY geth-poa/node2/keystore /data/keystore
RUN chmod +x /entrypoint.sh
EXPOSE 8545 6060 60601
ENTRYPOINT ["/entrypoint.sh"]

View file

@ -39,4 +39,9 @@ NODE1_PRIVATE_KEY=0xpk1
NODE2_PRIVATE_KEY=0xpk2
```
Or if you will use keystore to store private keys, you will need to submit password in .env file:
```
MEV_COMMIT_GETH_PASSWORD=primev
```
To get a standard starter .env file from primev internal development, [click here.](https://www.notion.so/Private-keys-and-env-for-settlement-layer-245a4f3f4fe040a7b72a6be91131d9c2?pvs=4), populate only the `NODE1_PRIVATE_KEY` and `NODE2_PRIVATE_KEY` fields.

View file

@ -21,6 +21,7 @@ services:
- geth-data-bootnode:/data
profiles:
- settlement
- settlement-keystore
labels:
com.datadoghq.ad.check_names: '["openmetrics"]'
com.datadoghq.ad.init_configs: '[{}]'
@ -42,6 +43,47 @@ services:
}
]
sl-node1-keystore:
build:
context: ..
dockerfile: geth-poa/Node1Dockerfile
environment:
- GETH_NODE_TYPE=signer
- BOOTNODE_ENDPOINT=enode://34a2a388ad31ca37f127bb9ffe93758ee711c5c2277dff6aff2e359bcf2c9509ea55034196788dbd59ed70861f523c1c03d54f1eabb2b4a5c1c129d966fe1e65@172.29.0.98:30301
- MEV_COMMIT_GETH_PASSWORD=${MEV_COMMIT_GETH_PASSWORD}
- NET_RESTRICT=172.29.0.0/16
networks:
primev_net:
ipv4_address: '172.29.0.99'
ports:
- 60602:60601
volumes:
- geth-data-node1:/data
profiles:
- settlement-keystore
labels:
com.datadoghq.ad.check_names: '["openmetrics"]'
com.datadoghq.ad.init_configs: '[{}]'
com.datadoghq.ad.instances: |
[
{
"openmetrics_endpoint": "http://%%host%%:6060/debug/metrics/prometheus",
"namespace": "geth-poa",
"metrics": [
"txpool*",
"trie*",
"system*",
"state*",
"rpc*",
"p2p*",
"eth*",
"chain*",
"clique*"
"vm*"
]
}
]
sl-node1:
build:
context: ..
@ -84,6 +126,47 @@ services:
}
]
sl-node2-keystore:
build:
context: ..
dockerfile: geth-poa/Node2Dockerfile
environment:
- GETH_NODE_TYPE=signer
- BOOTNODE_ENDPOINT=enode://34a2a388ad31ca37f127bb9ffe93758ee711c5c2277dff6aff2e359bcf2c9509ea55034196788dbd59ed70861f523c1c03d54f1eabb2b4a5c1c129d966fe1e65@172.29.0.98:30301
- NET_RESTRICT=172.29.0.0/16
- MEV_COMMIT_GETH_PASSWORD=${MEV_COMMIT_GETH_PASSWORD}
networks:
primev_net:
ipv4_address: '172.29.0.100'
ports:
- 60603:60601
volumes:
- geth-data-node2:/data
profiles:
- settlement-keystore
labels:
com.datadoghq.ad.check_names: '["openmetrics"]'
com.datadoghq.ad.init_configs: '[{}]'
com.datadoghq.ad.instances: |
[
{
"openmetrics_endpoint": "http://%%host%%:6060/debug/metrics/prometheus",
"namespace": "geth-poa",
"metrics": [
"txpool*",
"trie*",
"system*",
"state*",
"rpc*",
"p2p*",
"eth*",
"chain*",
"clique*"
"vm*"
]
}
]
sl-node2:
build:
context: ..

View file

@ -11,21 +11,33 @@ MEV_COMMIT_GETH_PASSWORD=${MEV_COMMIT_GETH_PASSWORD:-"pwd"}
CHAIN_ID=$(cat "$GENESIS_L1_PATH" | jq -r .config.chainId)
RPC_PORT="${RPC_PORT:-8545}"
WS_PORT="${WS_PORT:-8546}"
BLOCK_SIGNER_PRIVATE_KEY=${BLOCK_SIGNER_PRIVATE_KEY:-""}
# Generate signer key if needed
if [ ! -d "$GETH_KEYSTORE_DIR" ] && [ "$GETH_NODE_TYPE" = "signer" ]; then
echo "$GETH_KEYSTORE_DIR missing, running account import"
echo -n "$MEV_COMMIT_GETH_PASSWORD" > "$GETH_DATA_DIR"/password
echo -n "$BLOCK_SIGNER_PRIVATE_KEY" | sed 's/0x//' > "$GETH_DATA_DIR"/block-signer-key
"$GETH_BIN_PATH" --verbosity="$VERBOSITY" \
--nousb \
account import \
--datadir="$GETH_DATA_DIR" \
--password="$GETH_DATA_DIR"/password \
"$GETH_DATA_DIR"/block-signer-key
else
echo "$GETH_KEYSTORE_DIR exists."
if [ "$GETH_NODE_TYPE" = "signer" ]; then
if [ ! -f "$GETH_DATA_DIR/password" ]; then
echo -n "$MEV_COMMIT_GETH_PASSWORD" > "$GETH_DATA_DIR"/password
fi
if [ ! -d "$GETH_KEYSTORE_DIR" ]; then
if [ -n "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
echo "$GETH_KEYSTORE_DIR missing, running account import"
echo -n "$BLOCK_SIGNER_PRIVATE_KEY" | sed 's/0x//' > "$GETH_DATA_DIR"/block-signer-key
"$GETH_BIN_PATH" --verbosity="$VERBOSITY" \
--nousb \
account import \
--datadir="$GETH_DATA_DIR" \
--password="$GETH_DATA_DIR"/password \
"$GETH_DATA_DIR"/block-signer-key
fi
else
echo "$GETH_KEYSTORE_DIR exists."
if [ -z "$BLOCK_SIGNER_PRIVATE_KEY" ]; then
GETH_ACCOUNT_LIST=$("$GETH_BIN_PATH" --verbosity="$VERBOSITY" account list --datadir "$GETH_DATA_DIR")
BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX=$(echo "$GETH_ACCOUNT_LIST" | grep -oE '[0-9a-fA-F]{40}$')
BLOCK_SIGNER_ADDRESS="0x$BLOCK_SIGNER_ADDRESS_WITHOUT_PREFIX"
echo "Block signer address with 0x prefix: $BLOCK_SIGNER_ADDRESS"
fi
fi
fi
# Init geth if needed

View file

@ -0,0 +1,76 @@
{
"config": {
"chainId": 17864,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"arrowGlacierBlock": 0,
"grayGlacierBlock": 0,
"clique": {
"period": 200,
"epoch": 30000
}
},
"nonce": "0x0",
"timestamp": "0x6546df6d",
"extraData": "0x000000000000000000000000000000000000000000000000000000000000000028fec3344edff176fe8a72d653e31b3d1347144a86965da722fc59b996660116dce470c4776b77760000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x1c9c380",
"difficulty": "0x1",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": {
"0xBe3dEF3973584FdcC1326634aF188f0d9772D57D": {
"balance": "10000000000000000000000000000"
},
"d9cd8E5DE6d55f796D980B818D350C0746C25b97": {
"balance": "10000000000000000000000000000"
},
"788EBABe5c3dD422Ef92Ca6714A69e2eabcE1Ee4": {
"balance": "10000000000000000000000000000"
},
"0DCaa27B9E4Db92F820189345792f8eC5Ef148F6": {
"balance": "10000000000000000000000000000"
},
"f39Fd6e51aad88F6F4ce6aB8827279cffFb92266": {
"balance": "10000000000000000000000000000"
},
"0x3fab184622dc19b6109349b94811493bf2a45362": {
"balance": "10000000000000000000000000000"
},
"0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2": {
"balance": "10000000000000000000000000000"
},
"0xB9286CB4782E43A202BfD426AbB72c8cb34f886c": {
"balance": "10000000000000000000000000000"
},
"0x04F713A0b687c84D4F66aCd1423712Af6F852B78": {
"balance": "10000000000000000000000000000"
},
"0x82b941824b43F33e417be1E92273A3020a0D760c": {
"balance": "10000000000000000000000000000"
},
"0x57508f0B0f3426758F1f3D63ad4935a7c9383620": {
"balance": "10000000000000000000000000000"
},
"28fec3344edff176fe8a72d653e31b3d1347144a": {
"balance": "10000000000000000000000000000"
},
"86965da722fc59b996660116dce470c4776b7776": {
"balance": "10000000000000000000000000000"
}
},
"number": "0x0",
"gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"baseFeePerGas": "0x3b9aca00",
"excessBlobGas": null,
"blobGasUsed": null
}

View file

@ -0,0 +1 @@
{"address":"28fec3344edff176fe8a72d653e31b3d1347144a","crypto":{"cipher":"aes-128-ctr","ciphertext":"cb45b3225038bf2bbfe3f35ac0108d20316aa2935d764f0f039d3dfe9ed08316","cipherparams":{"iv":"a9637518eb8f19c0e1a79e31b5cebd0d"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"58b25f5a2990a340232466c996198199be86b8ad5cc3a12ba0b4fe33465ed1e9"},"mac":"94d060673f8cd7cce15e5d170e1338fe48f965a5a0633fe0a07efb1bae1fedce"},"id":"fffe9933-517d-47c2-bff3-c02bd3862e5b","version":3}

View file

@ -0,0 +1 @@
{"address":"86965da722fc59b996660116dce470c4776b7776","crypto":{"cipher":"aes-128-ctr","ciphertext":"e20ea9db481f7ebb220853f8eb2404c847220e7fcf11848bb84fbdaac43768a2","cipherparams":{"iv":"9891d3a718634ba74e13227d344ed5c5"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"7c07409646f176906588ae7d57371919e752510844680ebb5d1dc3cbed574d62"},"mac":"7189c8202b97ca1e305415d08c803bea5c4e8faeef87919503dd861f528654ca"},"id":"a8c78533-ab8e-4eb5-9dc5-575f975dce57","version":3}