Skip to content

Commit

Permalink
Merge pull request #36 from bloxapp/bulk_validators_refactors_2
Browse files Browse the repository at this point in the history
Bulk Validators Refactors #2
  • Loading branch information
moshe-blox committed Jan 1, 2024
2 parents 302e70d + 4485ce6 commit 8c983dc
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 115 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Build prod Docker image:
- $DOCKER_LOGIN_TO_INFRA_PROD_REPO && docker push $DOCKER_REPO_INFRA_PROD:$CI_COMMIT_SHA

only:
- main
- bulk_validators_deployment

Deploy nodes to prod:
stage: deploy
Expand All @@ -61,4 +61,4 @@ Deploy nodes to prod:
# +-------------------------------+
- .k8/production/ssv-dkg/scripts/deploy-ssv-dkg-1--4.sh $DOCKER_REPO_INFRA_PROD $CI_COMMIT_SHA ssv $APP_REPLICAS_INFRA_PROD blox-infra-prod kubernetes-admin@blox-infra-prod ssv.network $K8S_API_VERSION $SSV_DKG_CPU_LIMIT $SSV_DKG_MEM_LIMIT
only:
- main
- bulk_validators_deployment
4 changes: 2 additions & 2 deletions .k8/production/ssv-dkg/ssv-node-dkg-deployment-1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
memory: REPLACE_NODES_MEM_LIMIT
ports:
- containerPort: 3030
command: ["/app", "start-operator", "--configPath=/data/operator.yaml", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op1.json"]
command: ["/bin/ssv-dkg", "start-operator", "--configPath=/data/config", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op1.json"]
volumeMounts:
- name: secrets-file
mountPath: "/data/encrypted_private_key_op1.json"
Expand All @@ -67,7 +67,7 @@ spec:
mountPath: /data/password
subPath: password
- name: ssv-dkg-1-cm
mountPath: /data/operator.yaml
mountPath: /data/config/config.yaml
subPath: operator.yaml
volumes:
- name: secrets-file
Expand Down
4 changes: 2 additions & 2 deletions .k8/production/ssv-dkg/ssv-node-dkg-deployment-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
memory: REPLACE_NODES_MEM_LIMIT
ports:
- containerPort: 3030
command: ["/app", "start-operator", "--configPath=/data/operator.yaml", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op2.json"]
command: ["/bin/ssv-dkg", "start-operator", "--configPath=/data/config", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op2.json"]
volumeMounts:
- name: secrets-file
mountPath: "/data/encrypted_private_key_op2.json"
Expand All @@ -63,7 +63,7 @@ spec:
mountPath: /data/password
subPath: password
- name: ssv-dkg-2-cm
mountPath: /data/operator.yaml
mountPath: /data/config/config.yaml
subPath: operator.yaml
volumes:
- name: secrets-file
Expand Down
4 changes: 2 additions & 2 deletions .k8/production/ssv-dkg/ssv-node-dkg-deployment-3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
memory: REPLACE_NODES_MEM_LIMIT
ports:
- containerPort: 3030
command: ["/app", "start-operator", "--configPath=/data/operator.yaml", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op3.json"]
command: ["/bin/ssv-dkg", "start-operator", "--configPath=/data/config", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op3.json"]
volumeMounts:
- name: secrets-file
mountPath: "/data/encrypted_private_key_op3.json"
Expand All @@ -63,7 +63,7 @@ spec:
mountPath: /data/password
subPath: password
- name: ssv-dkg-3-cm
mountPath: /data/operator.yaml
mountPath: /data/config/config.yaml
subPath: operator.yaml
volumes:
- name: secrets-file
Expand Down
4 changes: 2 additions & 2 deletions .k8/production/ssv-dkg/ssv-node-dkg-deployment-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
memory: REPLACE_NODES_MEM_LIMIT
ports:
- containerPort: 3030
command: ["/app", "start-operator", "--configPath=/data/operator.yaml", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op4.json"]
command: ["/bin/ssv-dkg", "start-operator", "--configPath=/data/config", "--privKeyPassword=/data/password", "--privKey=/data/encrypted_private_key_op4.json"]
volumeMounts:
- name: secrets-file
mountPath: "/data/encrypted_private_key_op4.json"
Expand All @@ -67,7 +67,7 @@ spec:
mountPath: /data/password
subPath: password
- name: ssv-dkg-4-cm
mountPath: /data/operator.yaml
mountPath: /data/config/config.yaml
subPath: operator.yaml
volumes:
- name: secrets-file
Expand Down
35 changes: 27 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
FROM golang:1.20-alpine3.17
RUN apk add build-base
FROM golang:1.20-alpine3.18 as build
WORKDIR /ssv-dkg

WORKDIR /
# Install build dependencies required for CGO
RUN apk add --no-cache musl-dev gcc g++ libstdc++

# Copy the go.mod and go.sum first and download the dependencies.
# This layer will be cached unless these files change.
COPY go.mod go.sum ./
RUN go mod download && go mod verify
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,mode=0755,target=/go/pkg \
go mod download

COPY ./ ./
# Copy the rest of the source code
COPY . .

# Build
RUN CGO_ENABLED=1 GOOS=linux go build -o /app /cmd/ssv-dkg/ssv-dkg.go
# Build the binary with caching
ENV CGO_ENABLED=1
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,mode=0755,target=/go/pkg \
go build -o /bin/ssv-dkg ./cmd/ssv-dkg

#
# Run stage.
#
FROM alpine:3.18
WORKDIR /ssv-dkg

EXPOSE 3030
# Copy the built binary from the previous stage
COPY --from=build /bin/ssv-dkg /bin/ssv-dkg

ENTRYPOINT ["/bin/ssv-dkg"]

EXPOSE 3030
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ docker-operator:
--name svv-dkg-operator \
-p 3030:3030 \
-v $(shell pwd)/examples:/data \
--entrypoint /app \
$(DOCKER_IMAGE):latest \
start-operator --configPath /data/operator1/config

Expand All @@ -70,7 +69,6 @@ docker-initiator:
docker run \
--name ssv-dkg-initiator \
-v $(shell pwd)/examples:/data \
--entrypoint /app \
$(DOCKER_IMAGE):latest \
init --configPath /data/initiator/config

Expand All @@ -79,7 +77,6 @@ docker-reshare:
docker run \
--name ssv-dkg-reshare \
-v $(shell pwd)/examples:/data \
--entrypoint /app \
$(DOCKER_IMAGE):latest \
reshare --configPath /data/initiator/config

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ Under the assumption that all the necessary files (`operators_info.json`, `initi
```sh
docker run --name ssv_dkg_initiator \
-v "<PATH_TO_FOLDER_WITH_CONFIG_FILES>":/data -it \
"bloxstaking/ssv-dkg:latest" /app init \
"bloxstaking/ssv-dkg:latest" init \
--configPath /data/initiator/config && \
docker rm ssv_dkg_initiator
```
Expand Down Expand Up @@ -203,7 +203,7 @@ Run:
```sh
docker run --name ssv_dkg_initiator \
-v "<PATH_TO_FOLDER_WITH_CONFIG_FILES>":/data -it \
"bloxstaking/ssv-dkg:latest" /app init --configPath /data/initiator/config && \
"bloxstaking/ssv-dkg:latest" init --configPath /data/initiator/config && \
docker rm ssv_dkg_initiator
```

Expand Down Expand Up @@ -418,7 +418,7 @@ You can keep track of this counter yourself, or you can use the `ssv-scanner` to
```sh
docker run --name ssv_dkg_reshare \
-v "<PATH_TO_FOLDER_WITH_CONFIG_FILES>":/data -it \
"bloxstaking/ssv-dkg:latest" /app reshare --configPath /data/initiator/config && \
"bloxstaking/ssv-dkg:latest" reshare --configPath /data/initiator/config && \
docker rm ssv_dkg_initiator
```

Expand Down Expand Up @@ -650,7 +650,7 @@ Under the assumption that all the necessary files (`encrypted_private_key.json`,
```sh
docker run --restart unless-stopped --name ssv_dkg -p 3030:3030 \
-v "<PATH_TO_FOLDER_WITH_CONFIG_FILES>":/data -it \
"bloxstaking/ssv-dkg:latest" /app start-operator --configPath /data/operator/config
"bloxstaking/ssv-dkg:latest" start-operator --configPath /data/operator/config
```

Just make sure to substitute `<PATH_TO_FOLDER_WITH_CONFIG_FILES>` with the actual folder containing all the files.
Expand Down
8 changes: 6 additions & 2 deletions cli/initiator/initiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ var StartDKG = &cobra.Command{
if err != nil {
logger.Fatal("😥 Failed to load private key: ", zap.Error(err))
}
dkgInitiator := initiator.New(privateKey, opMap, logger, cmd.Version)
ethnetwork := e2m_core.MainNetwork
if cli_utils.Network != "now_test_network" {
ethnetwork = e2m_core.NetworkFromString(cli_utils.Network)
Expand All @@ -73,9 +72,14 @@ var StartDKG = &cobra.Command{
for i := 0; i < int(cli_utils.Validators); i++ {
i := i
pool.Go(func(ctx context.Context) (*Result, error) {
// create a new ID
// Create new DKG initiator
dkgInitiator := initiator.New(privateKey, opMap.Clone(), logger, cmd.Version)

// Create a new ID.
id := crypto.NewID()
nonce := cli_utils.Nonce + uint64(i)

// Perform the ceremony.
depositData, keyShares, err := dkgInitiator.StartDKG(id, cli_utils.WithdrawAddress.Bytes(), operatorIDs, ethnetwork, cli_utils.OwnerAddress, nonce)
if err != nil {
return nil, err
Expand Down
55 changes: 27 additions & 28 deletions cli/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,34 +576,33 @@ func WriteInitResults(depositDataArr []*initiator.DepositDataJson, keySharesArr
logger.Fatal("Failed writing instance ID file: ", zap.Error(err), zap.String("path", nestedDir), zap.String("ID", hex.EncodeToString(ids[i][:])))
}
}
if Validators > 1 {
// Write all to one JSON file
depositFinalPath := fmt.Sprintf("%s/deposit_data.json", dir)
logger.Info("💾 Writing deposit data json to file", zap.String("path", depositFinalPath))
err := utils.WriteJSON(depositFinalPath, depositDataArr)
if err != nil {
logger.Fatal("Failed writing deposit data file: ", zap.Error(err), zap.String("path", depositFinalPath), zap.Any("deposits", depositDataArr))
}
keysharesFinalPath := fmt.Sprintf("%s/keyshares.json", dir)
logger.Info("💾 Writing keyshares payload to file", zap.String("path", keysharesFinalPath))
aggrKeySharesArr, err := initiator.GenerateAggregatesKeyshares(keySharesArr)
if err != nil {
logger.Fatal("error: ", zap.Error(err))
}
err = utils.WriteJSON(keysharesFinalPath, aggrKeySharesArr)
if err != nil {
logger.Fatal("Failed writing instance IDs to file: ", zap.Error(err), zap.String("path", keysharesFinalPath), zap.Any("keyshares", keySharesArr))
}
instanceIdsPath := fmt.Sprintf("%s/instance_id.json", dir)
logger.Info("💾 Writing instance IDs to file", zap.String("path", keysharesFinalPath))
var idsArr []string
for _, id := range ids {
idsArr = append(idsArr, hex.EncodeToString(id[:]))
}
err = utils.WriteJSON(instanceIdsPath, idsArr)
if err != nil {
logger.Fatal("Failed writing instance IDs to file: ", zap.Error(err), zap.String("path", instanceIdsPath), zap.Strings("IDs", idsArr))
}

// Write aggregated JSON files
depositFinalPath := fmt.Sprintf("%s/deposit_data.json", dir)
logger.Info("💾 Writing deposit data json to file", zap.String("path", depositFinalPath))
err = utils.WriteJSON(depositFinalPath, depositDataArr)
if err != nil {
logger.Fatal("Failed writing deposit data file: ", zap.Error(err), zap.String("path", depositFinalPath), zap.Any("deposits", depositDataArr))
}
keysharesFinalPath := fmt.Sprintf("%s/keyshares.json", dir)
logger.Info("💾 Writing keyshares payload to file", zap.String("path", keysharesFinalPath))
aggrKeySharesArr, err := initiator.GenerateAggregatesKeyshares(keySharesArr)
if err != nil {
logger.Fatal("error: ", zap.Error(err))
}
err = utils.WriteJSON(keysharesFinalPath, aggrKeySharesArr)
if err != nil {
logger.Fatal("Failed writing instance IDs to file: ", zap.Error(err), zap.String("path", keysharesFinalPath), zap.Any("keyshares", keySharesArr))
}
instanceIdsPath := fmt.Sprintf("%s/instance_id.json", dir)
logger.Info("💾 Writing instance IDs to file", zap.String("path", keysharesFinalPath))
var idsArr []string
for _, id := range ids {
idsArr = append(idsArr, hex.EncodeToString(id[:]))
}
err = utils.WriteJSON(instanceIdsPath, idsArr)
if err != nil {
logger.Fatal("Failed writing instance IDs to file: ", zap.Error(err), zap.String("path", instanceIdsPath), zap.Strings("IDs", idsArr))
}
}

Expand Down
11 changes: 0 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ services:
- shared_network
ports:
- "3030:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator1/config"]
volumes:
- ./examples:/data
Expand All @@ -17,7 +16,6 @@ services:
- shared_network
ports:
- "3031:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator2/config"]
volumes:
- ./examples:/data
Expand All @@ -28,7 +26,6 @@ services:
- shared_network
ports:
- "3032:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator3/config"]
volumes:
- ./examples:/data
Expand All @@ -39,7 +36,6 @@ services:
- shared_network
ports:
- "3033:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator4/config"]
volumes:
- ./examples:/data
Expand All @@ -50,7 +46,6 @@ services:
- shared_network
ports:
- "3034:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator5/config"]
volumes:
- ./examples:/data
Expand All @@ -61,7 +56,6 @@ services:
- shared_network
ports:
- "3035:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator6/config"]
volumes:
- ./examples:/data
Expand All @@ -72,7 +66,6 @@ services:
- shared_network
ports:
- "3036:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator7/config"]
volumes:
- ./examples:/data
Expand All @@ -83,7 +76,6 @@ services:
- shared_network
ports:
- "3037:3030"
entrypoint: /app
command: ["start-operator", "--configPath", "/data/operator8/config"]
volumes:
- ./examples:/data
Expand All @@ -97,7 +89,6 @@ services:
- operator4
networks:
- shared_network
entrypoint: /app
command: ["init", "--configPath", "/data/initiator/config"]
volumes:
- ./examples:/data
Expand All @@ -115,7 +106,6 @@ services:
- operator8
networks:
- shared_network
entrypoint: /app
command: ["reshare", "--configPath", "/data/initiator/config"]
volumes:
- ./examples:/data
Expand All @@ -129,7 +119,6 @@ services:
- operator4
networks:
- shared_network
entrypoint: /app
command:
[
"ping",
Expand Down
Loading

0 comments on commit 8c983dc

Please sign in to comment.