diff --git a/charts/taraxa-node/CHANGELOG.md b/charts/taraxa-node/CHANGELOG.md index 67bea0458f..156e1835bd 100644 --- a/charts/taraxa-node/CHANGELOG.md +++ b/charts/taraxa-node/CHANGELOG.md @@ -3,13 +3,18 @@ This file documents all notable changes to `taraxa-node` Helm Chart. The release numbering uses [semantic versioning](http://semver.org). +## v0.3.7 + +### Minor changes + +* Adds transaction generating service to replace the explorer faucet + ## v0.3.6 ### Minor changes * Added labels into `StatefulSets` for [kube-monkey](https://github.com/asobti/kube-monkey) - ## v0.3.5 ### Minor changes diff --git a/charts/taraxa-node/Chart.yaml b/charts/taraxa-node/Chart.yaml index 7b5af2d71c..37568f68b3 100644 --- a/charts/taraxa-node/Chart.yaml +++ b/charts/taraxa-node/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "1.0" description: Kubernetes helm chart for Taraxa blockchain full node implementation. name: taraxa-node -version: 0.3.6 +version: 0.3.7 keywords: - blockchain - taraxa diff --git a/charts/taraxa-node/templates/secrets.yaml b/charts/taraxa-node/templates/secrets.yaml index aa7631a87f..7e64d37951 100644 --- a/charts/taraxa-node/templates/secrets.yaml +++ b/charts/taraxa-node/templates/secrets.yaml @@ -36,5 +36,6 @@ data: SLACK_TOKEN: {{ .Values.slack.token | b64enc | quote }} EXPLORER_DELEGATION_PRIVATE_KEY: {{ .Values.config.consensusnode.explorerDelegationPrivateKey | b64enc | quote }} EXPLORER_FAUCET_PRIVATE_KEY: {{ .Values.explorer.faucet.privKey | b64enc | quote }} + TRANSACTION_GENERATION_PRIVATE_KEY: {{ .Values.transactionGeneration.privateKey | b64enc | quote }} {{- end }} {{- end }} diff --git a/charts/taraxa-node/templates/transaction-generation-script.yaml b/charts/taraxa-node/templates/transaction-generation-script.yaml new file mode 100644 index 0000000000..316d45bbc5 --- /dev/null +++ b/charts/taraxa-node/templates/transaction-generation-script.yaml @@ -0,0 +1,127 @@ +{{- if .Values.transactionGeneration.enabled }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-transaction-generation + labels: + app: node + app.kubernetes.io/name: node + helm.sh/chart: {{ include "taraxa-node.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +data: + requirements.txt: |- + aiohttp==3.8.4 + aiosignal==1.3.1 + async-timeout==4.0.2 + attrs==22.2.0 + base58==2.1.1 + bitarray==2.7.3 + certifi==2022.12.7 + charset-normalizer==3.1.0 + coloredlogs==15.0.1 + cytoolz==0.12.1 + eth-abi==2.2.0 + eth-account==0.5.9 + eth-hash==0.5.1 + eth-keyfile==0.5.1 + eth-keys==0.3.4 + eth-rlp==0.2.1 + eth-typing==2.3.0 + eth-utils==1.9.5 + frozenlist==1.3.3 + hexbytes==0.3.0 + humanfriendly==10.0 + idna==3.4 + ipfshttpclient==0.8.0a2 + jsonschema==4.17.3 + lru-dict==1.1.8 + multiaddr==0.0.9 + multidict==6.0.4 + netaddr==0.8.0 + parsimonious==0.8.1 + protobuf==3.19.5 + pycryptodome==3.17 + pyrsistent==0.19.3 + python-dotenv==1.0.0 + requests==2.28.2 + rlp==2.0.1 + six==1.16.0 + toolz==0.12.0 + urllib3==1.26.15 + varint==1.0.2 + web3==5.31.4 + websockets==9.1 + yarl==1.8.2 + transactions.py: |- + import logging + import coloredlogs + import time + from dotenv import load_dotenv + from os import getenv + from web3 import Web3 + + load_dotenv() + + LOG_LEVEL = getenv('LOG_LEVEL', 'INFO') + PROVIDER_URL = getenv('PROVIDER_URL') + PRIVATE_KEY = getenv('PRIVATE_KEY') + PENDING_TRANSACTIONS_THRESHOLD = 1000 + + logger = logging.getLogger() + coloredlogs.install(level=LOG_LEVEL, logger=logger) + + provider = Web3.HTTPProvider(PROVIDER_URL) + chain_id = provider.make_request('net_version', []) + chain_id = int(chain_id['result']) + logger.info(f'Got chain ID: {chain_id}') + + node_config = provider.make_request('taraxa_getConfig', []) + initial_validators = list( + map(lambda x: Web3.to_checksum_address(x['address']), node_config['result']['dpos']['initial_validators'])) + logger.info(f'Got initial validators: {initial_validators}') + + web3 = Web3(provider) + logger.info(f'Connected to Taraxa node: {PROVIDER_URL}') + + last_block = web3.eth.getBlock('latest') + logger.info(f'Last block: #{last_block.number}') + + account = web3.eth.account.from_key(PRIVATE_KEY) + logger.info(f'Account: {account.address}') + + transaction_count = int(web3.eth.get_transaction_count(account.address)) + logger.info(f'Transaction count for address: {transaction_count}') + + while True: + pending_transactions = web3.eth.get_block_transaction_count('pending') + logger.info(f'Number of pending transactions: {pending_transactions}') + if pending_transactions > PENDING_TRANSACTIONS_THRESHOLD: + logger.info( + f'Number of pending transactions is above threshold, sleeping for 10 seconds') + time.sleep(10) + continue + + logger.info(f'Sending transactions to initial validators') + + for initial_validator in initial_validators: + transaction_count = transaction_count+1 + logger.info( + f'Sending transaction #{transaction_count} to {initial_validator}') + + transaction = { + 'from': account.address, + 'to': initial_validator, + 'value': 1, + 'gas': 21000, + 'gasPrice': 1, + 'nonce': transaction_count, + 'chainId': chain_id, + } + logger.debug(f'Transaction {transaction}') + signed_transaction = account.sign_transaction(transaction) + web3.eth.send_raw_transaction(signed_transaction.rawTransaction) + + time.sleep(1) +{{- end }} diff --git a/charts/taraxa-node/templates/transaction.generation.statefulset.yaml b/charts/taraxa-node/templates/transaction.generation.statefulset.yaml new file mode 100644 index 0000000000..c620d5b3fb --- /dev/null +++ b/charts/taraxa-node/templates/transaction.generation.statefulset.yaml @@ -0,0 +1,73 @@ +{{ if .Values.transactionGeneration.enabled }} +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ .Release.Name }}-transaction-generation + labels: + app: transaction-generation + app.kubernetes.io/name: transaction-generation + helm.sh/chart: {{ include "taraxa-node.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: 1 + serviceName: {{ .Release.Name }}-transaction-generation + # to launch or terminate all Pods in parallel. + # https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#parallel-pod-management + podManagementPolicy: Parallel + selector: + matchLabels: + app: transaction-generation + app.kubernetes.io/name: {{ .Release.Name }}-transaction-generation + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + name: transaction-generation + labels: + app: transaction-generation + app.kubernetes.io/name: {{ .Release.Name }}-transaction-generation + app.kubernetes.io/instance: {{ .Release.Name }} + annotations: + kubernetes.io/change-cause: "Configuration through configmaps." + spec: + containers: + - name: transaction-generation + image: "python:3.8" + imagePullPolicy: IfNotPresent + env: + - name: PRIVATE_KEY + valueFrom: + secretKeyRef: + name: {{ .Release.Name }} + key: TRANSACTION_GENERATION_PRIVATE_KEY + - name: PROVIDER_URL + value: http://{{ include "taraxa-node.fullname" . }}-head:7777 + command: ["/bin/bash", "-c", "--"] + args: [ "pip install -r /app/requirements.txt && python /app/transactions.py" ] + volumeMounts: + - name: requirements + mountPath: /app/requirements.txt + readOnly: true + subPath: requirements.txt + - name: script + mountPath: /app/transactions.py + readOnly: true + subPath: transactions.py + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: requirements + configMap: + defaultMode: 0700 + name: {{ .Release.Name }}-transaction-generation + - name: script + configMap: + defaultMode: 0700 + name: {{ .Release.Name }}-transaction-generation +{{- end }} diff --git a/charts/taraxa-node/values.yaml b/charts/taraxa-node/values.yaml index 8fed2c18a2..035e17fd45 100644 --- a/charts/taraxa-node/values.yaml +++ b/charts/taraxa-node/values.yaml @@ -50,6 +50,10 @@ slack: channel: channel k8s_cluster: taraxa +transactionGeneration: + enabled: true + privateKey: "" + nameOverride: "" fullnameOverride: "" @@ -162,7 +166,7 @@ node: image: repository: gcr.io/jovial-meridian-249123/taraxa-indexer tag: latest - pullPolicy: IfNotPresent + pullPolicy: Always persistence: enabled: false accessMode: ReadWriteOnce