From 2e96f935d375ffae8d6e59d9598683b5f7b46aca Mon Sep 17 00:00:00 2001 From: saurabhkumarkardam <124864640+saurabhkumarkardam@users.noreply.github.com> Date: Mon, 4 Mar 2024 16:16:59 +0530 Subject: [PATCH] feat(quorum): implement istanbul_propose method to add or remove a node (#2516) Changes: - Introduced new helm chart named `quorum-propose-validator` at path `platforms/quorum/charts/`. - This chart utilizes the `istanbul_propose` method to facilitate the addition or removal of nodes from the validator set based on majority votes. fixes #2508 Signed-off-by: saurabhkumarkardam --- .../quorum-propose-validator/Chart.yaml | 20 ++++ .../charts/quorum-propose-validator/README.md | 92 +++++++++++++++++++ .../templates/_helpers.tpl | 31 +++++++ .../templates/propose-validator-job.yaml | 56 +++++++++++ .../quorum-propose-validator/values.yaml | 20 ++++ 5 files changed, 219 insertions(+) create mode 100644 platforms/quorum/charts/quorum-propose-validator/Chart.yaml create mode 100644 platforms/quorum/charts/quorum-propose-validator/README.md create mode 100644 platforms/quorum/charts/quorum-propose-validator/templates/_helpers.tpl create mode 100644 platforms/quorum/charts/quorum-propose-validator/templates/propose-validator-job.yaml create mode 100644 platforms/quorum/charts/quorum-propose-validator/values.yaml diff --git a/platforms/quorum/charts/quorum-propose-validator/Chart.yaml b/platforms/quorum/charts/quorum-propose-validator/Chart.yaml new file mode 100644 index 00000000000..16ab5ea775c --- /dev/null +++ b/platforms/quorum/charts/quorum-propose-validator/Chart.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +name: quorum-propose-validator +description: "Quorum: Proposes to add or remove a validator with the specified address." +version: 1.0.1 +appVersion: latest +keywords: + - bevel + - ethereum + - quorum + - hyperledger + - enterprise + - blockchain + - deployment + - accenture +home: https://hyperledger-bevel.readthedocs.io/en/latest/ +sources: + - https://github.com/hyperledger/bevel +maintainers: + - name: Hyperledger Bevel maintainers + email: bevel@lists.hyperledger.org diff --git a/platforms/quorum/charts/quorum-propose-validator/README.md b/platforms/quorum/charts/quorum-propose-validator/README.md new file mode 100644 index 00000000000..bfbc77fa923 --- /dev/null +++ b/platforms/quorum/charts/quorum-propose-validator/README.md @@ -0,0 +1,92 @@ +[//]: # (##############################################################################################) +[//]: # (Copyright Accenture. All Rights Reserved.) +[//]: # (SPDX-License-Identifier: Apache-2.0) +[//]: # (##############################################################################################) + +# goquorum-propose-validator + +This chart is a component of Hyperledger Bevel. The goquorum-propose-validator chart injects a new authorization candidate that the validator attempts to push through. If a majority of the validators vote the candidate in/out, the candidate is added/removed in the validator set. + +## TL;DR + +```bash +helm repo add bevel https://hyperledger.github.io/bevel +helm install propose-validator bevel/goquorum-propose-validator +``` + +## Prerequisitess + +- Kubernetes 1.19+ +- Helm 3.2.0+ + +If Hashicorp Vault is used, then +- HashiCorp Vault Server 1.13.1+ + +> **Important**: Also check the dependent charts. + +## Installing the Chart + +To install the chart with the release name `propose-validator`: + +```bash +helm repo add bevel https://hyperledger.github.io/bevel +helm install propose-validator bevel/goquorum-propose-validator +``` + +The command deploys the chart on the Kubernetes cluster in the default configuration. The [Parameters](#parameters) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `propose-validator` deployment: + +```bash +helm uninstall propose-validator +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Parameters + +### Image + +| Name | Description | Default Value | +| -------------| ---------- | --------- | +| `image.genesisUtils.repository` | Quorum hooks image repository | `ghcr.io/hyperledger/bevel-k8s-hooks` | +| `image.genesisUtils.tag` | Quorum hooks image tag | `qgt-0.2.12` | +| `image.pullSecret` | Provide the docker secret name in the namespace | `""` | +| `image.pullPolicy` | Pull policy to be used for the Docker images | `IfNotPresent` | + +### validators + +| Name | Description | Default Value | +| ----------------| ----------- | ------------- | +| `validators.auth` | Set to 'true' to vote the candidate in and 'false' to vote them out | `true` | +| `validators.authorizedValidatorsURL` | URLs of already authorized validators | `""` | +| `validators.nonAuthorizedValidatorsNodeAddress` | Node addresses of the validators that need to be proposed | `""` | + + +## License + +This chart is licensed under the Apache v2.0 license. + +Copyright © 2023 Accenture + +### Attribution + +This chart is adapted from the [charts](https://hyperledger.github.io/bevel/) which is licensed under the Apache v2.0 License which is reproduced here: + +``` +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +``` diff --git a/platforms/quorum/charts/quorum-propose-validator/templates/_helpers.tpl b/platforms/quorum/charts/quorum-propose-validator/templates/_helpers.tpl new file mode 100644 index 00000000000..5987378709c --- /dev/null +++ b/platforms/quorum/charts/quorum-propose-validator/templates/_helpers.tpl @@ -0,0 +1,31 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "quorum-propose-validator.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "quorum-propose-validator.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "quorum-propose-validator.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} diff --git a/platforms/quorum/charts/quorum-propose-validator/templates/propose-validator-job.yaml b/platforms/quorum/charts/quorum-propose-validator/templates/propose-validator-job.yaml new file mode 100644 index 00000000000..fa70738e899 --- /dev/null +++ b/platforms/quorum/charts/quorum-propose-validator/templates/propose-validator-job.yaml @@ -0,0 +1,56 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "quorum-propose-validator.name" . }} + namespace: {{ .Release.Namespace }} + labels: + app: {{ .Release.Name }} + app.kubernetes.io/name: quorum-propose-validator-job + app.kubernetes.io/component: propose-validator-job + app.kubernetes.io/part-of: {{ include "quorum-propose-validator.fullname" . }} + app.kubernetes.io/namespace: {{ .Release.Namespace }} + app.kubernetes.io/release: {{ .Release.Name }} + app.kubernetes.io/managed-by: helm +spec: + backoffLimit: 3 + template: + metadata: + labels: + app: {{ .Release.Name }} + app.kubernetes.io/name: quorum-propose-validator-job + app.kubernetes.io/component: propose-validator-job + app.kubernetes.io/part-of: {{ include "quorum-propose-validator.fullname" . }} + app.kubernetes.io/namespace: {{ .Release.Namespace }} + app.kubernetes.io/managed-by: helm + spec: + restartPolicy: "OnFailure" + containers: + - name: propose-validator + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + securityContext: + runAsUser: 0 + env: + - name: EXISTING_VALIDATOR_URLS + value: "{{- .Values.validators.existingValidators | join " " -}}" + - name: PROPOSE_VALIDATOR_ADDRS + value: "{{- .Values.validators.proposeValidatorsAddr | join " " -}}" + command: ["/bin/sh", "-c"] + args: + - | + + for propose_val_addr in $PROPOSE_VALIDATOR_ADDRS; do + for existing_val_url in $EXISTING_VALIDATOR_URLS; do + # Send proposal to the existing validator + proposal_response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"{{ .Values.validators.consensusMethod}}","params":["'"$propose_val_addr"'",{{ .Values.validators.auth }}],"id":1}' "$existing_val_url") + + # Check if proposal was successful or not + result_count=$(echo "$proposal_response" | grep -c "result") + if [ "$result_count" = 1 ]; then + echo "Node proposed successfully." + else + echo "$proposal_response" | jq -r '.error' + fi + done + done + echo "COMPLETED" diff --git a/platforms/quorum/charts/quorum-propose-validator/values.yaml b/platforms/quorum/charts/quorum-propose-validator/values.yaml new file mode 100644 index 00000000000..8ba08cd6d1a --- /dev/null +++ b/platforms/quorum/charts/quorum-propose-validator/values.yaml @@ -0,0 +1,20 @@ +image: + repository: ghcr.io/hyperledger/bevel-k8s-hooks + tag: qgt-0.2.12 + pullPolicy: IfNotPresent + pullSecret: "" + +validators: + consensusMethod: "istanbul_propose" + auth: true # Set to 'true' to vote the candidate in and 'false' to vote them out + # List of URLs of the existing validators + existingValidators: + # - "http://" + # - "http://" + # - "http://" + # - "http://" + # List of node addresses of the validators that need to be proposed + proposeValidatorsAddr: + # - "<0xnodeAddress-1>" + # - "<0xnodeAddress-2>" + # - "<0xnodeAddress-3>"