Skip to content

Commit

Permalink
feature: add support for starship-faucet in helm, add tests (#245)
Browse files Browse the repository at this point in the history
* add support for starship-faucet in helm, add tests

* add 2 sec sleep after credit test

* add faucet.type to docs

* add faucet.enabled to doc

* update doc

* fix default image of starship faucet
  • Loading branch information
Anmol1696 committed Sep 15, 2023
1 parent d75e5fd commit cadc4a0
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- "simapp.yaml"
- "injective.yaml"
- "evmos.yaml"
- "one-chain-starship-faucet.yaml"
- "multi-validator-starship-faucet.yaml"
fail-fast: true
max-parallel: 1

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
- "simapp.yaml"
- "injective.yaml"
- "evmos.yaml"
- "one-chain-starship-faucet.yaml"
- "multi-validator-starship-faucet.yaml"
fail-fast: true
max-parallel: 1

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pr-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
- "one-custom-chain.yaml"
- "multi-validator.yaml"
- "simapp.yaml"
- "one-chain-starship-faucet.yaml"
- "multi-validator-starship-faucet.yaml"
fail-fast: true
max-parallel: 3

Expand Down
3 changes: 3 additions & 0 deletions charts/devnet/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,6 @@ defaultFaucet:
cosmjs:
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.31.1
concurrency: 5
starship:
image: ghcr.io/cosmology-tech/starship/faucet:20230915-d75e5fd
concurrency: 5
75 changes: 74 additions & 1 deletion charts/devnet/templates/chains/cosmos/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ spec:
- mountPath: /patch
name: patch
{{- end }}
{{/*if faucet is of type starship, then initialize faucet binary*/}}
{{- if and ($faucet.enabled) (eq $faucet.type "starship") }}
- name: init-faucet
image: {{ $faucet.image }}
imagePullPolicy: IfNotPresent
command:
- bash
- "-c"
- |
# Install faucet binary from the image
cp /bin/faucet /faucet/faucet
chmod +x /faucet/faucet
resources: {{- include "devnet.node.resources" ( dict "node" $chain "context" $ ) | trim | nindent 12 }}
volumeMounts:
- mountPath: /faucet
name: faucet
{{- end }}
containers:
- name: validator
image: {{ $image }}
Expand Down Expand Up @@ -235,7 +252,59 @@ spec:
readinessProbe:
httpGet:
path: /status
port: 8000
port: {{ $faucet.ports.rest }}
initialDelaySeconds: 10
periodSeconds: 10
{{- else if eq $faucet.type "starship" }}
- name: faucet
image: {{ $image }}
imagePullPolicy: Always
env:
- name: FAUCET_CONCURRENCY
value: "{{ $faucet.concurrency }}"
- name: FAUCET_HTTP_PORT
value: "{{ $faucet.ports.rest }}"
- name: FAUCET_CHAIN_BINARY
value: "{{ $chain.binary }}"
- name: FAUCET_CHAIN_ID
value: "{{ $chain.name }}"
- name: COINS
value: "{{ $chain.coins }}"
command:
- bash
- "-c"
- |
CREDIT_COINS=""
FEES=""
for coin in ${COINS//,/ }
do
amt="${coin//[!0-9]/}"
denom="${coin//[0-9]/}"
creditAmt=$(echo ${coin//[!0-9]/} | sed -e "s/0000$//")
if [[ $CREDIT_COINS == "" ]]
then
CREDIT_COINS="$creditAmt$denom"
feesAmt=$(echo ${coin//[!0-9]/} | sed -e "s/0000000$//")
FEES="$feesAmt$denom"
else
CREDIT_COINS="${CREDIT_COINS},$creditAmt$denom"
fi
done
export FAUCET_MNEMONIC=$(jq -r ".genesis[0].mnemonic" /configs/keys.json)
export | grep "FAUCET"
/faucet/faucet --credit-coins="$CREDIT_COINS" --chain-fees="$FEES"
volumeMounts:
- mountPath: /configs
name: addresses
- mountPath: /faucet
name: faucet
resources: {{- include "getResourceObject" $faucet.resources | trim | nindent 12 }}
readinessProbe:
httpGet:
path: /status
port: {{ $faucet.ports.rest }}
initialDelaySeconds: 10
periodSeconds: 10
{{- end }}
Expand All @@ -254,6 +323,10 @@ spec:
configMap:
name: patch-{{- include "devnet.chain.name" $chain.name }}
{{- end }}
{{- if and ($faucet.enabled) (eq $faucet.type "starship") }}
- name: faucet
emptyDir: { }
{{- end }}
---
{{- end }}
{{- end }}
6 changes: 4 additions & 2 deletions charts/devnet/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"type": {
"type": "string",
"enum": [
"cosmjs"
"cosmjs",
"starship"
]
},
"image": {
Expand Down Expand Up @@ -219,7 +220,8 @@
"type": {
"type": "string",
"enum": [
"cosmjs"
"cosmjs",
"starship"
]
},
"image": {
Expand Down
19 changes: 13 additions & 6 deletions docs/pages/config/chains.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ chains:
rest: 1317 # Rest endpoint of the Genesis validator node (most used)
rpc: 26657 # RPC endpoint of the genesis validator node (most used)
grpc: 9091 # GRPC endpoint of the genesis validator node (less used)
faucet: 8001 # Cosmjs faucet running next to the genesis node (most used)
faucet: 8001 # Faucet running next to the genesis node (most used)
exposer: 9090 # Exposer sidecar port (less used)
```

Expand Down Expand Up @@ -144,8 +144,11 @@ For more details on the resource directive have a look at [kubernetes resources]
> We recommend to specify resources as per your requirements

## `faucet` (optional)
Every genesis node runs a [cosmjs faucet](https://github.com/cosmos/cosmjs/tree/main/packages/faucet), by default
setting for faucet [here](https://github.com/cosmology-tech/starship/blob/main/charts/devnet/values.yaml#L32...#L38) but can be
Every genesis node runs a faucet. We support 2 types of faucet:
* [cosmjs faucet](https://github.com/cosmos/cosmjs/tree/main/packages/faucet), by default
* [starship faucet](https://github.com/cosmology-tech/starship/tree/main/faucet)

Setting for cosmjs-faucet [here](https://github.com/cosmology-tech/starship/blob/main/charts/devnet/values.yaml#L32...#L38) but can be
overridden with this directive, specially for compatible cosmjs version with the chain version.

```yaml
Expand All @@ -154,17 +157,21 @@ chains:
type: osmosis
numValidators: 1
faucet:
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.30.1
concurrency: 2 # default is 10
enabled: true # optional, default is true, need to specify if want to disable faucet, set to false
type: cosmjs # default is cosmjs, allowed [cosmjs, starship]
image: ghcr.io/cosmology-tech/starship/cosmjs-faucet:v0.30.1 # optional, default image set if not specified
concurrency: 2 # optional, default is 5
resources:
cpu: "0.3"
memory: "600M"
```

Note `concurrency` in `faucet` is the number of concurrent requests the faucet can handle.
> Note `concurrency` in `faucet` is the number of concurrent requests the faucet can handle.
If you are running a chain with less resources, or want faster startup time,
then you can reduce the `concurrency` to a lower number.

> Note: use `faucet.type: starship` for chains not supported by `cosmjs`. Mainly `injective`, `evmos`, `cheqd` etc.

## `build` (optional)
With the `build` directive in the chain, one can basically build chain binaries on the fly before starting the chain.
When the directive is `enabled`, then the docker image is set to a [`runner` docker image](https://github.com/cosmology-tech/starship/blob/main/docker/starship/runner/Dockerfile)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/configs/evmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ chains:
image: ghcr.io/cosmology-tech/starship/evmos:v13.0.2
numValidators: 1
faucet:
enabled: false
type: starship
ports:
rest: 1313
rpc: 26653
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/configs/injective.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ chains:
type: injective
numValidators: 1
faucet:
enabled: false
type: starship
ports:
rest: 1313
rpc: 26653
Expand Down
42 changes: 42 additions & 0 deletions tests/e2e/configs/multi-validator-starship-faucet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
chains:
- name: osmosis-1
type: osmosis
numValidators: 2
ports:
rest: 1313
rpc: 26653
exposer: 38083
faucet: 8000
resources:
limits:
cpu: "0.4"
memory: 1Gi
requests:
cpu: "0.2"
memory: 600M
faucet:
type: starship
concurrency: 2
resources:
cpu: "0.1"
memory: "200M"

registry:
enabled: true
image: anmol1696/registry:20230914-a6ee678
ports:
rest: 8081
grpc: 9091
resources:
cpu: "0.1"
memory: 100M

resources:
wait:
cpu: "0.1"
memory: 100M

exposer:
resources:
cpu: "0.1"
memory: 100M
30 changes: 30 additions & 0 deletions tests/e2e/configs/one-chain-starship-faucet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
chains:
- name: osmosis-1
type: osmosis
numValidators: 1
ports:
rest: 1313
rpc: 26653
exposer: 38083
faucet: 8003
resources:
cpu: "0.5"
memory: 500M
faucet:
type: starship
concurrency: 2

registry:
enabled: true
image: anmol1696/registry:20230914-a6ee678
ports:
rest: 8081
grpc: 9091
resources:
cpu: "0.1"
memory: 100M

resources:
wait:
cpu: "0.1"
memory: 100M
2 changes: 2 additions & 0 deletions tests/e2e/faucet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
urlpkg "net/url"
"strconv"
"time"
)

func (s *TestSuite) MakeFaucetRequest(chain *Chain, req *http.Request, unmarshal map[string]interface{}) {
Expand Down Expand Up @@ -135,6 +136,7 @@ func (s *TestSuite) TestFaucet_Credit() {
s.Require().NoError(err)
s.Require().Equal(200, resp.StatusCode)

time.Sleep(2 * time.Second)
afterBalance := s.getAccountBalance(chain, addr, denom)

// note sometimes expected difference is 9x expected value (bug due to using holder address for test)
Expand Down

0 comments on commit cadc4a0

Please sign in to comment.