simplify scripts

This commit is contained in:
colinlyguo
2024-03-17 00:51:29 +08:00
parent 4be6a10517
commit 4476b36ffb
3 changed files with 36 additions and 56 deletions

View File

@@ -22,5 +22,3 @@ while : ; do
echo "$networks"
echo "$networks" | xargs -r docker network rm || echo "Warning: Failed to remove some networks."
done
rm -rf ./consensus/data* ./execution/data*

View File

@@ -17,11 +17,10 @@ import (
// PoSL1TestEnv represents the config needed to test in PoS Layer 1.
type PoSL1TestEnv struct {
workDir string
compose tc.ComposeStack
gethHTTPPort int
hostPath string
dataPathRandom string
dockerComposeFile string
compose tc.ComposeStack
gethHTTPPort int
hostPath string
}
// NewPoSL1TestEnv creates and initializes a new instance of PoSL1TestEnv with a random HTTP port.
@@ -47,24 +46,22 @@ func NewPoSL1TestEnv() (*PoSL1TestEnv, error) {
}
return &PoSL1TestEnv{
workDir: filepath.Join(rootDir, "common", "docker-compose", "l1"),
gethHTTPPort: gethHTTPPort,
hostPath: hostPath,
dataPathRandom: fmt.Sprintf("data_%d", time.Now().UnixNano()),
dockerComposeFile: filepath.Join(rootDir, "common", "docker-compose", "l1", "docker-compose.yml"),
gethHTTPPort: gethHTTPPort,
hostPath: hostPath,
}, nil
}
// Start starts the PoS L1 test environment by running the associated Docker Compose configuration.
func (e *PoSL1TestEnv) Start() error {
var err error
e.compose, err = tc.NewDockerCompose([]string{filepath.Join(e.workDir, "docker-compose.yml")}...)
e.compose, err = tc.NewDockerCompose([]string{e.dockerComposeFile}...)
if err != nil {
return fmt.Errorf("failed to create docker compose: %w", err)
}
env := map[string]string{
"GETH_HTTP_PORT": fmt.Sprintf("%d", e.gethHTTPPort),
"DATA_PATH_RANDOM": e.dataPathRandom,
"GETH_HTTP_PORT": fmt.Sprintf("%d", e.gethHTTPPort),
}
if e.hostPath != "" {
@@ -77,7 +74,6 @@ func (e *PoSL1TestEnv) Start() error {
}
return fmt.Errorf("failed to start PoS L1 test environment: %w", err)
}
return nil
}
@@ -88,17 +84,6 @@ func (e *PoSL1TestEnv) Stop() error {
return fmt.Errorf("failed to stop PoS L1 test environment: %w", err)
}
}
dirsToRemove := []string{
filepath.Join(e.workDir, "consensus", e.dataPathRandom),
filepath.Join(e.workDir, "execution", e.dataPathRandom),
}
for _, dir := range dirsToRemove {
if err := os.RemoveAll(dir); err != nil {
return fmt.Errorf("failed to remove data directory %s: %w", dir, err)
}
}
return nil
}

View File

@@ -3,14 +3,14 @@ services:
initialize-env:
image: "alpine:3.19.0"
command:
/bin/sh -c "apk add --no-cache rsync &&
mkdir -p /consensus/${DATA_PATH_RANDOM:-data} &&
rsync -a --exclude '${DATA_PATH_RANDOM:-data}' /consensus/ /consensus/${DATA_PATH_RANDOM:-data}/ &&
mkdir -p /execution/${DATA_PATH_RANDOM:-data} &&
rsync -a --exclude '${DATA_PATH_RANDOM:-data}' /execution/ /execution/${DATA_PATH_RANDOM:-data}/"
/bin/sh -c "mkdir -p /data/consensus &&
cp -a /consensus/* /data/consensus/ &&
mkdir -p /data/execution &&
cp -a /execution/* /data/execution/"
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/consensus:/consensus
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution:/execution
- data:/data
# Creates a genesis state for the beacon chain using a YAML configuration file and
# a deterministic set of 64 validators.
@@ -22,13 +22,12 @@ services:
- --fork=capella
- --num-validators=64
- --genesis-time-delay=3
- --output-ssz=/consensus/genesis.ssz
- --chain-config-file=/consensus/config.yml
- --geth-genesis-json-in=/execution/genesis.json
- --geth-genesis-json-out=/execution/genesis.json
- --output-ssz=/data/consensus/genesis.ssz
- --chain-config-file=/data/consensus/config.yml
- --geth-genesis-json-in=/data/execution/genesis.json
- --geth-genesis-json-out=/data/execution/genesis.json
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/consensus/${DATA_PATH_RANDOM:-data}:/consensus
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}:/execution
- data:/data
depends_on:
initialize-env:
condition: service_completed_successfully
@@ -36,10 +35,9 @@ services:
# Sets up the genesis configuration for the go-ethereum client from a JSON file.
geth-genesis:
image: "ethereum/client-go:v1.13.14"
command: --datadir=/execution init /execution/genesis.json
command: --datadir=/data/execution init /data/execution/genesis.json
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}:/execution
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}/genesis.json:/execution/genesis.json
- data:/data
depends_on:
create-beacon-chain-genesis:
condition: service_completed_successfully
@@ -53,14 +51,14 @@ services:
beacon-chain:
image: "gcr.io/prysmaticlabs/prysm/beacon-chain:v5.0.0"
command:
- --datadir=/consensus/beacondata
- --datadir=/data/consensus/beacondata
# No peers to sync with in this testnet, so setting to 0
- --min-sync-peers=0
- --genesis-state=/consensus/genesis.ssz
- --genesis-state=/data/consensus/genesis.ssz
- --bootstrap-node=
- --interop-eth1data-votes
# The chain configuration file used for setting up Prysm
- --chain-config-file=/consensus/config.yml
- --chain-config-file=/data/consensus/config.yml
# We specify the chain id used by our execution client
- --contract-deployment-block=0
- --chain-id=${CHAIN_ID:-32382}
@@ -68,7 +66,7 @@ services:
- --grpc-gateway-host=0.0.0.0
- --execution-endpoint=http://geth:8551
- --accept-terms-of-use
- --jwt-secret=/execution/jwtsecret
- --jwt-secret=/data/execution/jwtsecret
- --suggested-fee-recipient=0x123463a4b065722e99115d6c222f267d9cabb524
- --minimum-peers-per-subnet=0
- --enable-debug-rpc-endpoints
@@ -77,9 +75,7 @@ services:
create-beacon-chain-genesis:
condition: service_completed_successfully
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/consensus/${DATA_PATH_RANDOM:-data}:/consensus
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}:/execution
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}/jwtsecret:/execution/jwtsecret
- data:/data
# Runs the go-ethereum execution client with the specified, unlocked account and necessary
# APIs to allow for proof-of-stake consensus via Prysm.
@@ -92,11 +88,11 @@ services:
- --http.corsdomain=*
- --authrpc.vhosts=*
- --authrpc.addr=0.0.0.0
- --authrpc.jwtsecret=/execution/jwtsecret
- --datadir=/execution
- --authrpc.jwtsecret=/data/execution/jwtsecret
- --datadir=/data/execution
- --allow-insecure-unlock
- --unlock=0x123463a4b065722e99115d6c222f267d9cabb524
- --password=/execution/geth_password.txt
- --password=/data/execution/geth_password.txt
- --nodiscover
- --syncmode=full
- --ipcdisable
@@ -108,9 +104,7 @@ services:
beacon-chain:
condition: service_started
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}:/execution
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}/jwtsecret:/execution/jwtsecret
- ${HOST_PATH:-../../..}/common/docker-compose/l1/execution/${DATA_PATH_RANDOM:-data}/geth_password.txt:/execution/geth_password.txt
- data:/data
# We run a validator client with 64, deterministically-generated keys that match
# The validator keys present in the beacon chain genesis state generated a few steps above.
@@ -118,14 +112,17 @@ services:
image: "gcr.io/prysmaticlabs/prysm/validator:v5.0.0"
command:
- --beacon-rpc-provider=beacon-chain:4000
- --datadir=/consensus/validatordata
- --datadir=/data/consensus/validatordata
- --accept-terms-of-use
- --interop-num-validators=64
- --interop-start-index=0
- --chain-config-file=/consensus/config.yml
- --chain-config-file=/data/consensus/config.yml
- --force-clear-db
depends_on:
beacon-chain:
condition: service_started
volumes:
- ${HOST_PATH:-../../..}/common/docker-compose/l1/consensus/${DATA_PATH_RANDOM:-data}:/consensus
- data:/data
volumes:
data: