Skip to content

Commit

Permalink
Merge pull request #2415 from Taraxa-project/chart/v0.3.7
Browse files Browse the repository at this point in the history
chore: adds transaction generating script
  • Loading branch information
rattrap authored Mar 23, 2023
2 parents c52667e + 3409596 commit 49c13e3
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 3 deletions.
7 changes: 6 additions & 1 deletion charts/taraxa-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/taraxa-node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions charts/taraxa-node/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
127 changes: 127 additions & 0 deletions charts/taraxa-node/templates/transaction-generation-script.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 5 additions & 1 deletion charts/taraxa-node/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ slack:
channel: channel
k8s_cluster: taraxa

transactionGeneration:
enabled: true
privateKey: ""

nameOverride: ""
fullnameOverride: ""

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 49c13e3

Please sign in to comment.