Skip to content

Commit

Permalink
Add Localnet (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
okdas and Olshansk authored Oct 4, 2023
1 parent 573aee1 commit c408591
Show file tree
Hide file tree
Showing 38 changed files with 1,886 additions and 15 deletions.
30 changes: 29 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,35 @@
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
vendor/

# Go workspace file
go.work

# Don't commit binaries
bin
!bin/.keep

# Why: pocketd CLI should use the same keys as the node that runs inside the cluster to
# allow commands such as `pocketd tx stake` for work.
localnet/pocketd/*
!localnet/pocketd/keyring-test/
!localnet/pocketd/keyring-test/*
!localnet/*/config/
!localnet/*/config/*

# Macos
.DS_Store
**/.DS_Store

# Development
.vscode
.env
.idea/

# Compiled protos
**/*.pb.go
**/*.pb.gw.go

# Frontend utils
ts-client/
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
POCKETD_HOME := ./localnet/pocketd

.PHONY: localnet_up
localnet_up: ## Starts localnet
tilt up

.PHONY: localnet_down
localnet_down: ## Delete resources created by localnet
tilt down
kubectl delete secret celestia-secret || exit 1

.PHONY: localnet_regenesis
localnet_regenesis:
# NOTE: intentionally not using --home <dir> flag to avoid overwriting the test keyring
ignite chain init --skip-proto
rm -rf $(POCKETD_HOME)/keyring-test
cp -r ${HOME}/.pocket/keyring-test $(POCKETD_HOME)
cp ${HOME}/.pocket/config/*_key.json $(POCKETD_HOME)/config/
cp ${HOME}/.pocket/config/genesis.json ./localnet/
61 changes: 61 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
load('ext://restart_process', 'docker_build_with_restart')

# A list of directories where changes trigger a hot-reload of the sequencer
hot_reload_dirs = ['app', 'cmd', 'tools', 'x']

# Import files into Kubernetes ConfigMap
def read_files_from_directory(directory):
files = listdir(directory)
config_map_data = {}
for filepath in files:
content = str(read_file(filepath)).strip()
filename = os.path.basename(filepath)
config_map_data[filename] = content
return config_map_data

def generate_config_map_yaml(name, data):
config_map_object = {
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {"name": name},
"data": data
}
return encode_yaml(config_map_object)

# Import keyring/keybase files into Kubernetes ConfigMap
k8s_yaml(generate_config_map_yaml("pocketd-keys", read_files_from_directory("localnet/pocketd/keyring-test/"))) # pocketd/keys
# Import configuration files into Kubernetes ConfigMap
k8s_yaml(generate_config_map_yaml("pocketd-configs", read_files_from_directory("localnet/pocketd/config/"))) # pocketd/configs

# Hot reload protobuf changes
local_resource('hot-reload: generate protobufs', 'ignite generate proto-go -y', deps=['proto'], labels=["hot-reloading"])
# Hot reload the pocketd binary used by the k8s cluster
local_resource('hot-reload: pocketd', 'GOOS=linux ignite chain build --skip-proto --output=./bin --debug -v', deps=hot_reload_dirs, labels=["hot-reloading"], resource_deps=['hot-reload: generate protobufs'])
# Hot reload the local pocketd binary used by the CLI
local_resource('hot-reload: pocketd - local cli', 'ignite chain build --skip-proto --debug -v -o $(go env GOPATH)/bin', deps=hot_reload_dirs, labels=["hot-reloading"], resource_deps=['hot-reload: generate protobufs'])

# Build an image with a pocketd binary
docker_build_with_restart(
"pocketd",
'.',
dockerfile_contents="""FROM golang:1.20.8
RUN apt-get -q update && apt-get install -qyy curl jq
RUN go install github.com/go-delve/delve/cmd/dlv@latest
COPY bin/pocketd /usr/local/bin/pocketd
WORKDIR /
""",
only=["./bin/pocketd"],
entrypoint=[
"/bin/sh", "/scripts/pocket.sh"
],
live_update=[sync("bin/pocketd", "/usr/local/bin/pocketd")],
)

# Run pocketd, relayer, celestia and anvil nodes
k8s_yaml(['localnet/kubernetes/pocketd.yaml', 'localnet/kubernetes/pocketd-relayer.yaml', 'localnet/kubernetes/anvil.yaml', 'localnet/kubernetes/celestia-rollkit.yaml'])

# Configure tilt resources (tilt labels and port forawards) for all of the nodes above
k8s_resource('celestia-rollkit', labels=["blockchains"], port_forwards=['26657', '26658', '26659'])
k8s_resource('pocketd', labels=["blockchains"], resource_deps=['celestia-rollkit'], port_forwards=['36657', '40004'])
k8s_resource('pocketd-relayer', labels=["blockchains"], resource_deps=['pocketd'], port_forwards=['8545', '8546', '40005'])
k8s_resource('anvil', labels=["blockchains"], port_forwards=['8547'])
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import (
pocketmodule "pocket/x/pocket"
pocketmodulekeeper "pocket/x/pocket/keeper"
pocketmoduletypes "pocket/x/pocket/types"

// this line is used by starport scaffolding # stargate/app/moduleImport

appparams "pocket/app/params"
Expand Down Expand Up @@ -152,6 +153,7 @@ var (
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
authzmodule.AppModuleBasic{},
// TODO_DISCUSS: Should we rename all instances of `Validator` to `Sequencer`?
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
bank.AppModuleBasic{},
capability.AppModuleBasic{},
Expand Down
118 changes: 104 additions & 14 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,111 @@
version: 1
accounts:
- name: alice
coins:
- 20000token
- 200000000stake
- name: bob
- name: faucet
mnemonic: "baby advance work soap slow exclude blur humble lucky rough teach wide chuckle captain rack laundry butter main very cannon donate armor dress follow"
coins:
- 999999999999999999stake
- name: validator1
mnemonic: "creek path rule retire evolve vehicle bargain champion roof whisper prize endorse unknown anchor fashion energy club sauce elder parent cotton old affair visa"
coins:
- 900000000stake
- name: app1
mnemonic: "mention spy involve verb exercise fiction catalog order agent envelope mystery text defy sing royal fringe return face alpha knife wonder vocal virus drum"
coins:
- 100000000stake
- name: app2
mnemonic: "material little labor strong search device trick amateur action crouch invite glide provide elite mango now paper sense found hamster neglect work install bulk"
coins:
- 200000000stake
- name: app3
mnemonic: "involve clean slab term real human green immune valid swing protect talk silent unique cart few ice era right thunder again drop among bounce"
coins:
- 300000000stake
- name: servicer1
mnemonic: "cool industry busy tumble funny relax error state height like board wing goat emerge visual idle never unveil announce hill primary okay spatial frog"
coins:
- 110000000stake
- name: servicer2
mnemonic: "peanut hen enroll meat legal have error input bulk later correct denial onion fossil wing excuse elephant object apology switch claim rare decide surface"
coins:
- 220000000stake
- name: servicer3
mnemonic: "client city senior tenant source soda spread buffalo shaft amused bar carbon keen off feel coral easily announce metal orphan sustain maple expand loop"
coins:
- 330000000stake
- name: portal1
mnemonic: "salt iron goat also absorb depend involve agent apology between lift shy door left bulb arrange industry father jelly olive rifle return predict into"
coins:
- 100000000stake
- name: portal2
mnemonic: "suffer wet jelly furnace cousin flip layer render finish frequent pledge feature economy wink like water disease final erase goat include apple state furnace"
coins:
- 200000000stake
- name: portal3
mnemonic: "elder spatial erosion soap athlete tide subject recipe also awkward head pattern cart version beach usual oxygen confirm erupt diamond maze smooth census garment"
coins:
- 300000000stake
faucet:
name: faucet
coins:
- 10000token
- 100000000stake
- 10000stake
client:
typescript:
path: ts-client
hooks:
path: react/src/hooks
openapi:
path: docs/static/openapi.yml
faucet:
name: bob
coins:
- 5token
- 100000stake
validators:
- name: alice
bonded: 100000000stake
- name: validator1
bonded: 900000000stake
config:
moniker: "validator1"
# We can persist arbitrary genesis values via 1 to 1 mapping to genesis.json
genesis:
app_state:
application:
applicationList:
- address: pokt1mrqt5f7qh8uxs27cjm9t7v9e74a9vvdnq5jva4
services:
- id: svc1
name: TODO
- id: svc2
name: TODO
stake:
amount: "1000"
denom: stake
params: {}
servicer:
params: {}
servicersList:
- address: pokt19a3t4yunp0dlpfjrp7qwnzwlrzd5fzs2gjaaaj
services:
- endpoints:
- configs:
- key: TIMEOUT
value: 30s
metadata:
entries: {}
rpc_type: WEBSOCKET
url: ws://localhost:8546/
id:
id: svc1
name: Pocket Network Service 1
metadata:
entries: {}
- endpoints:
- configs:
- key: TIMEOUT
value: 60s
metadata:
entries: {}
rpc_type: JSON_RPC
url: http://localhost:8545
id:
id: svc2
name: Pocket Network Service 2
metadata:
entries: {}
stake:
amount: "1000000"
denom: stake
Loading

0 comments on commit c408591

Please sign in to comment.