Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script for reading leaderboard data into database #1810

Merged
merged 69 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9e48d9d
starting leaderboard backend
mrsmkl Nov 6, 2019
41eb462
fetching metadata seems to work
mrsmkl Nov 6, 2019
088feb1
fixed some bugs
mrsmkl Nov 6, 2019
f0e80dc
working on leaderboard query
mrsmkl Nov 12, 2019
f0567c1
Merge branch 'master' of github.com:celo-org/celo-monorepo into leade…
mrsmkl Nov 12, 2019
52efc5d
Merge branch 'master' of github.com:celo-org/celo-monorepo into leade…
mrsmkl Nov 13, 2019
ad1ccd8
added a method for getting current validator set from a smart contract
mrsmkl Nov 14, 2019
73c6d3a
updated leaderboard script
mrsmkl Nov 14, 2019
28993b9
handling empty claims
mrsmkl Nov 14, 2019
1328112
Merge branch 'master' of github.com:celo-org/celo-monorepo into leade…
mrsmkl Nov 15, 2019
f00a163
verifying account claims
mrsmkl Nov 15, 2019
ce387ff
hmm
mrsmkl Nov 21, 2019
e33204e
merge
mrsmkl Nov 21, 2019
18c6568
added readme, marged master
mrsmkl Nov 21, 2019
cc12df9
Merge branch 'master' into leaderboard
mrsmkl Nov 25, 2019
4026d43
Merge branch 'master' into leaderboard
diminator Nov 25, 2019
5d94224
reading data from env vars, completely untested
mrsmkl Nov 26, 2019
61d4fdc
reading from env variables perhaps works now
mrsmkl Nov 26, 2019
1994109
updated readme
mrsmkl Nov 26, 2019
59410a9
updated readme
mrsmkl Nov 26, 2019
f4da015
env variable name
mrsmkl Nov 26, 2019
94dcaeb
Merge branch 'master' into leaderboard
diminator Nov 26, 2019
4094c7e
changes to spreadsheet handling
mrsmkl Nov 26, 2019
0cf013c
reading from template format
mrsmkl Nov 26, 2019
d2e5ee5
percentage
mrsmkl Nov 26, 2019
a064145
merge
mrsmkl Nov 26, 2019
4109bb8
Added leaderboard docker stuff
jcortejoso Nov 27, 2019
b87336a
Merge pull request #1 from jcortejoso/jcortejoso/leaderboard
mrsmkl Nov 27, 2019
8e54afa
leaderboard helm wip
jcortejoso Nov 27, 2019
6799636
Leaderboard helm package
jcortejoso Nov 28, 2019
e1183ba
Merge branch 'master' into leaderboard
mrsmkl Nov 28, 2019
672ba4f
merge
mrsmkl Nov 28, 2019
9d08a11
yarn
mrsmkl Nov 28, 2019
ec8df8a
Merge branch 'leaderboard' of github.com:mrsmkl/celo-monorepo into jc…
jcortejoso Nov 28, 2019
ab548ac
misspell
mrsmkl Nov 29, 2019
aae82d6
Leaderboard helm package
jcortejoso Nov 29, 2019
ddb88f3
leaderboard install update
jcortejoso Nov 29, 2019
014241d
Updated dependencies
jcortejoso Nov 29, 2019
b025d2d
Workaround for job with sidecar. See kubernetes#25908
jcortejoso Nov 29, 2019
2797d6d
Merge branch 'leaderboard' of github.com:mrsmkl/celo-monorepo into jc…
jcortejoso Nov 29, 2019
89005d9
Fixed compilation problems
jcortejoso Nov 29, 2019
df9e625
Fixed default CMD
jcortejoso Nov 29, 2019
faabcbd
Merge pull request #3 from jcortejoso/jcortejoso/leaderboard
mrsmkl Nov 29, 2019
e7c3eb3
add market history
mrsmkl Nov 29, 2019
0fa3bf4
Merge pull request #4 from mrsmkl/market-history
mrsmkl Nov 29, 2019
b045b0a
Added upgrade leaderboard command
jcortejoso Nov 29, 2019
b93da63
Fixed command
jcortejoso Nov 30, 2019
cbebe8b
Merge pull request #5 from jcortejoso/jcortejoso/leaderboard
mrsmkl Dec 2, 2019
1ebcc89
fixed lint
mrsmkl Dec 2, 2019
f9173f6
instead of ignoring accounts with zero multiplier, remove them
mrsmkl Dec 4, 2019
ad31bce
Leaderboard image private
jcortejoso Dec 4, 2019
9db3b0a
Merge branch 'master' into leaderboard
diminator Dec 4, 2019
1795342
spreet
mrsmkl Dec 4, 2019
61b7ed7
Merge branch 'leaderboard' of github.com:mrsmkl/celo-monorepo into le…
mrsmkl Dec 4, 2019
2d0af66
updated contractkit version
mrsmkl Dec 4, 2019
58a8db7
final spreet?
mrsmkl Dec 4, 2019
f689d3f
Merge branch 'master' into leaderboard
diminator Dec 4, 2019
fe9c6f5
Merge branch 'master' into leaderboard
cmcewen Dec 5, 2019
ef74ba5
better handing of claims
mrsmkl Dec 7, 2019
3b00961
Merge branch 'leaderboard' of github.com:mrsmkl/celo-monorepo into le…
mrsmkl Dec 7, 2019
67c9f10
some issues with verifying account claim
mrsmkl Dec 7, 2019
c91953b
better error handling?
mrsmkl Dec 7, 2019
5428169
merge
mrsmkl Dec 10, 2019
f89dd2b
updated leaderboard script
mrsmkl Dec 10, 2019
cb6510d
updating contractkit version
mrsmkl Dec 10, 2019
f674fcb
remove duplicates
mrsmkl Dec 10, 2019
00d36c4
Merge branch 'master' into leaderboard
mrsmkl Dec 10, 2019
2708d64
Merge branch 'master' into leaderboard
mrsmkl Dec 10, 2019
30753dd
Merge branch 'master' into leaderboard
mrsmkl Dec 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ CHAOS_TEST_KILL_INTERVAL = 3m
# Regardless, until we have verification pools for dev testnets, this value isn't used except for testing.
SMS_RETRIEVER_HASH_CODE=aBQdOa/7QJh

# Below are the variables needed to access
LEADERBOARD_DOCKER_IMAGE_REPOSITORY="us.gcr.io/celo-testnet/celo-monorepo"
LEADERBOARD_DOCKER_IMAGE_TAG="leaderboard-"
LEADERBOARD_SHEET="1HCs1LZv1BOB1v2bVlH4qNPnxVRlYVhQ7CKhkMibE4EY"

# Attestation Bot variables
ATTESTATION_BOT_INITIAL_WAIT_SECONDS=3
ATTESTATION_BOT_IN_BETWEEN_WAIT_SECONDS=10
ATTESTATION_BOT_MAX_ATTESTATIONS=3
ATTESTATION_BOT_MAX_ATTESTATIONS=3
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ See [Developer's Guide](https://docs.celo.org/) for full details about the desig

See the [issue backlog](https://github.com/celo-org/celo-monorepo/issues) for a list of active or proposed tasks. Feel free to create new issues to report bugs and/or request features. Please add labels to your issues, tagging the appropriate package/area.


### ✍️ Contributing

Feel free to jump on the Celo 🚂🚋🚋🚋. Improvements and contributions are highly encouraged! 🙏👊
Feel free to jump on the Celo 🚂🚋🚋🚋. Improvements and contributions are highly encouraged! 🙏👊

See the [contributing guide](CONTRIBUTING.md) for details on how to participate.
[![GitHub issues by-label](https://img.shields.io/github/issues/celo-org/celo-monorepo/1%20hour%20tasks)](https://github.com/celo-org/celo-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A%221+hour+tasks%22)
Expand All @@ -72,6 +71,7 @@ twitter intent generator - http://tech.cymi.org/tweet-intents
-->

### 💬 Ask questions, find answers, and get in touch:

- [Website](https://celo.org/)
- [Docs](https://docs.celo.org/)
- [Blog](https://medium.com/celohq) 📖
Expand All @@ -82,7 +82,6 @@ twitter intent generator - http://tech.cymi.org/tweet-intents
- [Reddit](https://www.reddit.com/r/CeloHQ/)
- [Community Events](https://celo.org/community) 🎉


### 📜 License

All packages are licensed under the terms of the Apache 2.0 License unless otherwise specified in the LICENSE file at package's root.
9 changes: 9 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ steps:
]
waitFor: ['-']

- id: "docker:leaderboard"
name: gcr.io/kaniko-project/executor:latest
args: [
"--dockerfile=dockerfiles/leaderboard/Dockerfile",
"--cache=true",
"--destination=gcr.io/$PROJECT_ID/celo-monorepo:leaderboard-$COMMIT_SHA"
]
waitFor: ['-']

timeout: 3000s
31 changes: 31 additions & 0 deletions dockerfiles/leaderboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:10
WORKDIR /celo-monorepo

# ensure yarn.lock is evaluated by kaniko cache diff
COPY lerna.json package.json yarn.lock ./
COPY scripts/ scripts/

# Copy only pkg.json
COPY packages/typescript/package.json packages/typescript/
COPY packages/utils/package.json packages/utils/
COPY packages/dev-utils/package.json packages/dev-utils/
COPY packages/protocol/package.json packages/protocol/
COPY packages/contractkit/package.json packages/contractkit/
COPY packages/leaderboard/package.json packages/leaderboard/

RUN yarn install --frozen-lockfile --network-timeout 100000 && yarn cache clean

# Copy the rest
COPY packages/typescript packages/typescript/
COPY packages/utils packages/utils/
COPY packages/dev-utils packages/dev-utils/
COPY packages/protocol packages/protocol/
COPY packages/contractkit packages/contractkit/
COPY packages/leaderboard packages/leaderboard/

# build all
RUN yarn build

WORKDIR /celo-monorepo/packages/leaderboard

CMD ["yarn run ts-node src/board.ts"]
16 changes: 16 additions & 0 deletions packages/celotool/src/cmds/deploy/destroy/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createClusterIfNotExists, switchToClusterFromEnv } from 'src/lib/cluster'
import { removeHelmRelease } from 'src/lib/leaderboard'
import { DestroyArgv } from '../../deploy/destroy'

export const command = 'leaderboard'

export const describe = 'destroy the leaderboard package'

export const builder = {}

export const handler = async (argv: DestroyArgv) => {
await createClusterIfNotExists()
await switchToClusterFromEnv()

await removeHelmRelease(argv.celoEnv)
}
17 changes: 17 additions & 0 deletions packages/celotool/src/cmds/deploy/initial/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { InitialArgv } from 'src/cmds/deploy/initial'
import { switchToClusterFromEnv } from 'src/lib/cluster'
import { installHelmChart } from 'src/lib/leaderboard'
import yargs from 'yargs'

export const command = 'leaderboard'

export const describe = 'deploy the leaderboard for the specified network'

export const builder = (argv: yargs.Argv) => {
return argv
}

export const handler = async (argv: InitialArgv) => {
await switchToClusterFromEnv()
await installHelmChart(argv.celoEnv)
}
32 changes: 32 additions & 0 deletions packages/celotool/src/cmds/deploy/upgrade/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { UpgradeArgv } from 'src/cmds/deploy/upgrade'
import { createClusterIfNotExists, switchToClusterFromEnv } from 'src/lib/cluster'
import { installHelmChart, removeHelmRelease, upgradeHelmChart } from 'src/lib/leaderboard'
import yargs from 'yargs'

export const command = 'leaderboard'

export const describe = 'upgrade the leaderboard package'

type LeaderboardArgv = UpgradeArgv & {
reset: boolean
}

export const builder = (argv: yargs.Argv) => {
return argv.option('reset', {
description: 'Destroy & redeploy the leaderboard package',
default: false,
type: 'boolean',
})
}

export const handler = async (argv: LeaderboardArgv) => {
await createClusterIfNotExists()
await switchToClusterFromEnv()

if (argv.reset) {
await removeHelmRelease(argv.celoEnv)
await installHelmChart(argv.celoEnv)
} else {
await upgradeHelmChart(argv.celoEnv)
}
}
3 changes: 3 additions & 0 deletions packages/celotool/src/lib/env-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export enum envVar {
IN_MEMORY_DISCOVERY_TABLE = 'IN_MEMORY_DISCOVERY_TABLE',
KUBERNETES_CLUSTER_NAME = 'KUBERNETES_CLUSTER_NAME',
KUBERNETES_CLUSTER_ZONE = 'KUBERNETES_CLUSTER_ZONE',
LEADERBOARD_DOCKER_IMAGE_REPOSITORY = 'LEADERBOARD_DOCKER_IMAGE_REPOSITORY',
LEADERBOARD_DOCKER_IMAGE_TAG = 'LEADERBOARD_DOCKER_IMAGE_TAG',
LEADERBOARD_SHEET = 'LEADERBOARD_SHEET',
LOAD_TEST_CLIENTS = 'LOAD_TEST_CLIENTS',
LOAD_TEST_GENESIS_BALANCE = 'LOAD_TEST_GENESIS_BALANCE',
LOAD_TEST_TX_DELAY_MS = 'LOAD_TEST_TX_DELAY_MS',
Expand Down
56 changes: 56 additions & 0 deletions packages/celotool/src/lib/leaderboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import yaml from 'js-yaml'
import { envVar, fetchEnv } from 'src/lib/env-utils'
import { installGenericHelmChart, removeGenericHelmChart } from 'src/lib/helm_deploy'
import { execCmd, execCmdWithExitOnFailure } from 'src/lib/utils'

const helmChartPath = '../helm-charts/leaderboard'

export async function installHelmChart(celoEnv: string) {
return installGenericHelmChart(
celoEnv,
releaseName(celoEnv),
helmChartPath,
await helmParameters(celoEnv)
)
}

export async function removeHelmRelease(celoEnv: string) {
await removeGenericHelmChart(releaseName(celoEnv))
}

export async function upgradeHelmChart(celoEnv: string) {
console.info(`Upgrading helm release ${releaseName(celoEnv)}`)

const params = (await helmParameters(celoEnv)).join(' ')

const upgradeCmdArgs = `${releaseName(celoEnv)} ${helmChartPath} --namespace ${celoEnv} ${params}`

if (process.env.CELOTOOL_VERBOSE === 'true') {
await execCmdWithExitOnFailure(`helm upgrade --debug --dry-run ${upgradeCmdArgs}`)
}
await execCmdWithExitOnFailure(`helm upgrade ${upgradeCmdArgs}`)
console.info(`Helm release ${releaseName(celoEnv)} upgrade successful`)
}

export async function helmParameters(celoEnv: string) {
const dbValues = await getBlockscoutHelmValues(celoEnv)
return [
`--set leaderboard.db.connection_name=${dbValues.connection_name}`,
`--set leaderboard.db.username=${dbValues.username}`,
`--set leaderboard.db.password=${dbValues.password}`,
`--set leaderboard.image.repository=${fetchEnv(envVar.LEADERBOARD_DOCKER_IMAGE_REPOSITORY)}`,
`--set leaderboard.image.tag=${fetchEnv(envVar.LEADERBOARD_DOCKER_IMAGE_TAG)}`,
`--set leaderboard.sheet=${fetchEnv(envVar.LEADERBOARD_SHEET)}`,
`--set leaderboard.web3=https://${celoEnv}-forno.${fetchEnv(envVar.CLUSTER_DOMAIN_NAME)}.org`,
]
}

function releaseName(celoEnv: string) {
return `${celoEnv}-leaderboard`
}

export async function getBlockscoutHelmValues(celoEnv: string) {
const [output] = await execCmd(`helm get values ${celoEnv}-blockscout`)
const blockscoutValues: any = yaml.safeLoad(output)
return blockscoutValues.blockscout.db
}
2 changes: 1 addition & 1 deletion packages/contractkit/src/identity/claims/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const verifyAccountClaim = async (

const accountClaims = metadata.filterClaims(ClaimTypes.ACCOUNT)

if (accountClaims.find((x) => x.address === address) === undefined) {
if (accountClaims.find((x) => x.address.toLowerCase() === address.toLowerCase()) === undefined) {
return `${claim.address} did not claim ${address}`
}

Expand Down
2 changes: 1 addition & 1 deletion packages/docs/getting-started/running-a-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ The `mine` flag does not mean the node starts mining blocks, but rather starts t

The `networkid` parameter value of `12219` indicates we are connecting to the Baklava network, Stake Off Phase 1.

Note that if you are running the validator and the proxy on the same machine, then you should set the validator's listening port to something other than `30303`. E.g. you could use the flag `--port 30313` and set the docker port forwarding rules accordingly (e.g. use the flags `-p 30313:30313` and `-p 30313:30313/udp`).
Note that if you are running the validator and the proxy on the same machine, then you should set the validator's listening port to something other than `30303`. E.g. you could use the flag `--port 30313` and set the docker port forwarding rules accordingly (e.g. use the flags `-p 30313:30313` and `-p 30313:30313/udp`).

### Register the Accounts

Expand Down
22 changes: 22 additions & 0 deletions packages/helm-charts/leaderboard/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions packages/helm-charts/leaderboard/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: leaderboard
version: 0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .Release.Name }}
labels:
app: leaderboard
chart: leaderboard
release: {{ .Release.Service }}
component: leaderboard
spec:
schedule: "{{ .Values.leaderboard.schedule }}"
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 1
template:
spec:
containers:
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.11
command:
- /bin/sh
args:
- -c
- |
/cloud_sql_proxy \
-instances={{ .Values.leaderboard.db.connection_name }}=tcp:5432 \
-credential_file=/secrets/cloudsql/credentials.json &
CHILD_PID=$!
(while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) &
wait $CHILD_PID
if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi
securityContext:
runAsUser: 2 # non-root user
allowPrivilegeEscalation: false
volumeMounts:
- name: blockscout-cloudsql-credentials
mountPath: /secrets/cloudsql
readOnly: true
- mountPath: /tmp/pod
name: tmp-pod
readOnly: true
- name: update-sheet
image: {{ .Values.leaderboard.image.repository }}:{{ .Values.leaderboard.image.tag }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
args:
- -c
- |
trap "touch /tmp/pod/main-terminated" EXIT
yarn run ts-node src/board.ts
env:
- name: LEADERBOARD_DATABASE
value: {{ .Values.leaderboard.database }}
- name: LEADERBOARD_WEB3
value: {{ .Values.leaderboard.web3 }}
- name: LEADERBOARD_SHEET
value: {{ .Values.leaderboard.sheet }}
- name: PGUSER
valueFrom:
secretKeyRef:
name: {{ .Release.Namespace }}-leaderboard
key: DATABASE_USER
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Namespace }}-leaderboard
key: DATABASE_PASSWORD
volumeMounts:
- mountPath: /tmp/pod
name: tmp-pod
restartPolicy: Never
volumes:
- name: blockscout-cloudsql-credentials
secret:
defaultMode: 420
secretName: blockscout-cloudsql-credentials
- name: tmp-pod
emptyDir: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Namespace }}-leaderboard
labels:
app: leaderboard
chart: leaderboard
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
type: Opaque
data:
DATABASE_USER: {{ .Values.leaderboard.db.username | b64enc | quote }}
DATABASE_PASSWORD: {{ .Values.leaderboard.db.password | b64enc | quote }}
16 changes: 16 additions & 0 deletions packages/helm-charts/leaderboard/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
nodeSelector: {}

# Expects cron schedule syntax
leaderboard:
schedule: "*/1 * * * *"
database: "blockscout"
image:
repository: jcortejoso/leaderboard
tag: latest
database: blockscout
web3: https://baklavastaging-forno.celo-testnet.org/
sheet: 1HCs1LZv1BOB1v2bVlH4qNPnxVRlYVhQ7CKhkMibE4EY
db:
username: ls880fd3
password: dg7mTjVB2khgkDFd
connection_name: celo-testnet:us-west1:baklavastaging0
2 changes: 2 additions & 0 deletions packages/leaderboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
credentials.json
token.json
Loading