Skip to content

Shutter API Keyper basic test setup #604

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions docker-test-setup-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/data
5 changes: 5 additions & 0 deletions docker-test-setup-api/00-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

source ./common.sh

$DC --profile dev build
24 changes: 24 additions & 0 deletions docker-test-setup-api/01-init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

source ./common.sh

mkdb() {
$DC exec -T db createdb -U postgres $1
$DC run -T --rm --no-deps $1 initdb --config /config/${1}.toml
}

$DC stop db
$DC rm -f db

${BB} rm -rf data/db

$DC up -d db
$DC run --rm --no-deps wait-for-db

for cmd in keyper-0 keyper-1 keyper-2; do
mkdb $cmd &
done

wait

$DC stop db
66 changes: 66 additions & 0 deletions docker-test-setup-api/02-init-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

source ./common.sh

$DC stop blockchain
$DC rm -f blockchain
$DC stop chain-{0..2}-validator chain-seed
$DC rm -f chain-{0..2}-validator chain-seed

${BB} rm -rf data/chain-{0..2}-validator data/chain-seed
${BB} mkdir -p data/chain-{0..2}-validator/config data/chain-seed/config
${BB} chmod -R a+rwX data/chain-{0..2}-validator/config data/chain-seed/config
${BB} rm -rf data/deployments

# has blockchain as dependency
$DC up -d blockchain
sleep 5
$DC up deploy-contracts

bash get-contracts.sh
# setup chain-seed
$DC run --rm --no-deps chain-seed init \
--root /chain \
--blocktime 1 \
--listen-address tcp://0.0.0.0:${TM_RPC_PORT} \
--role seed

seed_node=$(cat data/chain-seed/config/node_key.json.id)@chain-seed:${TM_P2P_PORT}

${BB} sed -i "/^moniker/c\moniker = \"chain-seed\"" data/chain-seed/config/config.toml

# configure validators and keypers 0-2
for num in {0..2}; do
validator_cmd=chain-$num-validator

$DC run --rm --no-deps ${validator_cmd} init \
--root /chain \
--genesis-keyper 0x440Dc6F164e9241F04d282215ceF2780cd0B755e \
--blocktime 1 \
--listen-address tcp://0.0.0.0:${TM_RPC_PORT} \
--role validator

validator_id=$(cat data/${validator_cmd}/config/node_key.json.id)
validator_node=${validator_id}@${validator_cmd}:${TM_P2P_PORT}
validator_config_path=data/${validator_cmd}/config/config.toml

# share genesis
if [ $num -eq 0 ]; then
for destination in data/chain-seed/config/ data/chain-{1..2}-validator/config/; do
${BB} cp -v data/chain-0-validator/config/genesis.json "${destination}"
done
fi

# set validator publickey for keyper
${BB} sed -i "/ValidatorPublicKey/c\ValidatorPublicKey = \"$(cat data/${validator_cmd}/config/priv_validator_pubkey.hex)\"" /config/keyper-${num}.toml

# set seed node for chain bootstrap
${BB} sed -i "/^seeds =/c\seeds = \"${seed_node}\"" "${validator_config_path}"
# fix external address for docker internal communication
${BB} sed -i "/^external_address =/c\external_address = \"${validator_cmd}:${TM_P2P_PORT}\"" "${validator_config_path}"
# give a nice name
${BB} sed -i "/^moniker/c\moniker = \"${validator_cmd}\"" "${validator_config_path}"

done

$DC stop -t 30
6 changes: 6 additions & 0 deletions docker-test-setup-api/03-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

source ./common.sh

echo "Starting entire system"
$DC up -d
22 changes: 22 additions & 0 deletions docker-test-setup-api/04-addkeyperset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

source ./common.sh
source .env
set -e

CONTRACTS_JSON=$(jq '.transactions[]|(select(.function==null))|{(.contractName|tostring): .contractAddress}' data/deployments/Deploy.service.s.sol/31337/run-latest.json)

for s in $(echo ${CONTRACTS_JSON} | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")| .[] "); do
export $s
done

# Get keyper addresses from node-deploy.json
export KEYPER_ADDRESSES=$(jq -r '.keypers[0] | join(",")' config/node-deploy.json)

echo "Submitting Add Keyper Set transaction"
export THRESHOLD=2
export KEYPERSETMANAGER_ADDRESS=${KeyperSetManager}
export KEYBROADCAST_ADDRESS=${KeyBroadcastContract}
export ACTIVATION_DELTA=10

$DC run --rm --no-deps add-keyper-set
11 changes: 11 additions & 0 deletions docker-test-setup-api/05-bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

source ./common.sh

echo "Submitting bootstrap transaction"

$DC run --rm --no-deps --entrypoint /rolling-shutter chain-0-validator op-bootstrap fetch-keyperset \
--config /config/op-bootstrap.toml

$DC run --rm --no-deps --entrypoint /rolling-shutter chain-0-validator op-bootstrap \
--config /config/op-bootstrap.toml
34 changes: 34 additions & 0 deletions docker-test-setup-api/06-test-decryption.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

source ./common.sh
set -e

echo "Submitting identity registration transaction"

CONTRACTS_JSON=$(jq '.transactions[]|(select(.function==null))|{(.contractName|tostring): .contractAddress}' data/deployments/Deploy.service.s.sol/31337/run-latest.json)

for s in $(echo ${CONTRACTS_JSON} | jq -r "to_entries|map(\"\(.key)=\(.value|tostring)\")| .[] "); do
export $s
done

export TIMESTAMP=$(($(date +%s) + 50))
export IDENTITY_PREFIX=0x$(LC_ALL=C tr -dc 'a-f0-9' </dev/urandom | head -c64)
export REGISTRY_ADDRESS=${ShutterRegistry}
export EON=$($DC exec db psql -U postgres -d keyper-0 -t -c 'select max(eon) from eons;' | tr -d '[:space:]')
if [[ -z $EON ]]; then
echo "No eonId found in keyper-0 db. Did you run bootstrap?"
exit 1
fi

${DC} run --rm --no-deps register-identity
sleep 55

DECRYPTION_KEY_MSGS=$(${DC} logs keyper-0 | grep ${EON} | grep -c decryptionKey)
echo "DECRYPTION_KEY_MSGS: ${DECRYPTION_KEY_MSGS}"
if [[ $DECRYPTION_KEY_MSGS -gt 0 ]]; then
echo "Decryption successful with $DECRYPTION_KEY_MSGS / 3 nodes"
exit 0
else
echo "Decryption failed"
exit 1
fi
6 changes: 6 additions & 0 deletions docker-test-setup-api/90-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

source ./common.sh

echo "Stopping entire system"
$DC down
16 changes: 16 additions & 0 deletions docker-test-setup-api/build-src/deploy_contracts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM alpine/git AS builder

RUN date
RUN git clone --branch=shutter-api https://github.com/shutter-network/contracts /contracts
RUN cd /contracts && git submodule update --init --recursive

FROM --platform=linux/amd64 ghcr.io/foundry-rs/foundry AS runner
WORKDIR /contracts
COPY --from=builder --chown=foundry:foundry /contracts /contracts

RUN git config --global --add safe.directory /contracts

USER foundry
RUN forge install
RUN forge build
ENTRYPOINT ["forge", "script"]
6 changes: 6 additions & 0 deletions docker-test-setup-api/build-src/setup-blockchain/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# syntax=docker/dockerfile:1.4
FROM --platform=linux/amd64 ghcr.io/foundry-rs/foundry

WORKDIR /anvil

ENTRYPOINT anvil --host 0.0.0.0 -p 8545 -b 2 --dump-state /data/blockchain.json
11 changes: 11 additions & 0 deletions docker-test-setup-api/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BB="docker run --rm -v $(pwd)/data:/data -v $(pwd)/config:/config -w / busybox"
TM_P2P_PORT=26656
TM_RPC_PORT=26657

if docker compose ls >/dev/null 2>&1; then
DC="docker compose"
else
DC=docker-compose
fi

set -xe
21 changes: 21 additions & 0 deletions docker-test-setup-api/config/bootstrap.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Peer identity: /p2p/12D3KooWJN7262vmnEQHkYG7VrZDwz9fMyJtHyvGp4XSenuUYfeJ
# Peer role: bootstrap

# whether to register handlers on the messages and log them
InstanceID = 0
ListenMessages = true

[P2P]
P2PKey = "CAESQKFtiMAqd2c8bQ/mfPStxViY970MNtWUVWdn44rUoQXAfv7ztSQ9nLeqliXrkuqKi3XUObyAfH+Py3eMbHFvIpM="
ListenAddresses = ["/ip4/0.0.0.0/tcp/23000"]
# Overwrite p2p boostrap nodes
CustomBootstrapAddresses = [
"/dns4/bootnode-0/tcp/23000/p2p/12D3KooWJN7262vmnEQHkYG7VrZDwz9fMyJtHyvGp4XSenuUYfeJ",
]
IsAccessNode = false
DiscoveryNamespace = "shutter-local"

[P2P.FloodSubDiscovery]
Enabled = false
Interval = 10
Topics = []
54 changes: 54 additions & 0 deletions docker-test-setup-api/config/keyper-0.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Peer identity: /p2p/12D3KooWQ8iKQe4iEfkTh3gdBtpxWsKwx3BwrA18km5rq3Zwt2QF
# Ethereum address: 0xCDD50A6F9B1439dc14c4f2A7eaF14dA1EF5A476c


InstanceID = 0
# If it's empty, we use the standard PG_ environment variables
DatabaseURL = "postgres://postgres@db:5432/keyper-0"
HTTPEnabled = false
HTTPListenAddress = ':3000'
MaxNumKeysPerMessage = 500

[P2P]
P2PKey = 'CAESQJ3NdZ6mRrDAW/Z59OKwcKdOCbZQ45z5o8K+tLHOL8Xw1LbawPZLk3mXNyiDyADcLk1bqYMe3uQ6T8xi65zkM0A='
ListenAddresses = ["/ip4/0.0.0.0/tcp/23000"]
# Overwrite p2p boostrap nodes
CustomBootstrapAddresses = [
"/dns4/bootnode-0/tcp/23000/p2p/12D3KooWJN7262vmnEQHkYG7VrZDwz9fMyJtHyvGp4XSenuUYfeJ",
]
DiscoveryNamespace = 'shutter-local'
# Optional, to be set to true if running an access node
IsAccessNode = false

[P2P.FloodSubDiscovery]
Enabled = false
Interval = 10
Topics = []

[Chain]
SyncStartBlockNumber = 0
SyncMonitorCheckInterval = 60

[Chain.Node]
PrivateKey = '82904d1c48d3a27d218408fc2db3e743f554a69b05b91d28c2897a9026ea47df'
# Contract source directory
DeploymentDir = '/deployments/localhost/'
# The layer 1 JSON RPC endpoint
EthereumURL = "ws://blockchain:8545/"

[Chain.Contracts]
KeyperSetManager = "0x8464135c8f25da09e49bc8782676a84730c318bc"
ShutterRegistry = "0xc6ba8c3233ecf65b761049ef63466945c362edd2"
KeyBroadcastContract = "0x59f2f1fcfe2474fd5f0b9ba1e73ca90b143eb8d0"

[Shuttermint]
ShuttermintURL = "http://chain-0-validator:26657"
ValidatorPublicKey = "feb818be329ca88d0d0588fbf695b96f9c674cbc4f08037a34ac97c9aa40c7d0"
EncryptionKey = '6bf7e6c8d6753d435f885f398f62f221a84f0ccb0c5e2a382290489441e16f77'
DKGPhaseLength = 8
DKGStartBlockDelta = 5

[Metrics]
Enabled = true
Host = "[::]"
Port = 9100
54 changes: 54 additions & 0 deletions docker-test-setup-api/config/keyper-1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Peer identity: /p2p/12D3KooWGksg5G2oau6EgdJFLiQoKaMvzPJnTCuoPScZcmZRdkny
# Ethereum address: 0x539cF80D345d26525A47dB80De0fAb147D588fDa


InstanceID = 0
# If it's empty, we use the standard PG_ environment variables
DatabaseURL = "postgres://postgres@db:5432/keyper-1"
HTTPEnabled = false
HTTPListenAddress = ':3000'
MaxNumKeysPerMessage = 500

[P2P]
P2PKey = 'CAESQO+t2CR93jdMq/FDqZf2+KIY9kLhKA1rZY9WFherSqvZZxzY8W4y5hSBrW5u79SDCvbLcmo7kEwu6VsK0NjZnxY='
ListenAddresses = ["/ip4/0.0.0.0/tcp/23000"]
# Overwrite p2p boostrap nodes
CustomBootstrapAddresses = [
"/dns4/bootnode-0/tcp/23000/p2p/12D3KooWJN7262vmnEQHkYG7VrZDwz9fMyJtHyvGp4XSenuUYfeJ",
]
DiscoveryNamespace = 'shutter-local'
# Optional, to be set to true if running an access node
IsAccessNode = false

[P2P.FloodSubDiscovery]
Enabled = false
Interval = 10
Topics = []

[Chain]
SyncStartBlockNumber = 0
SyncMonitorCheckInterval = 60

[Chain.Node]
PrivateKey = '939babbad75cbcc42eef92496ce86ede989ba96918bbc6cc0efcc498f9cc0887'
# Contract source directory
DeploymentDir = '/deployments/localhost/'
# The layer 1 JSON RPC endpoint
EthereumURL = "ws://blockchain:8545/"

[Chain.Contracts]
KeyperSetManager = "0x8464135c8f25da09e49bc8782676a84730c318bc"
ShutterRegistry = "0xc6ba8c3233ecf65b761049ef63466945c362edd2"
KeyBroadcastContract = "0x59f2f1fcfe2474fd5f0b9ba1e73ca90b143eb8d0"

[Shuttermint]
ShuttermintURL = "http://chain-0-validator:26657"
ValidatorPublicKey = "906d1cf0abcdb59ba08851c35004d0e961181e49e085d9f2169c03ab86bca4b8"
EncryptionKey = 'd10fcd3a9db97ecf80a41b5fb30bb91ea16bf6a8575e389912a335b19cc4b3b8'
DKGPhaseLength = 8
DKGStartBlockDelta = 5

[Metrics]
Enabled = true
Host = "[::]"
Port = 9100
Loading