Skip to content

Commit

Permalink
Merge pull request #170 from tellor-io/connect-to-layer
Browse files Browse the repository at this point in the history
Connect to layer scripts
  • Loading branch information
themandalore authored Jun 6, 2024
2 parents 83c300f + 1b559c6 commit e67f2ce
Show file tree
Hide file tree
Showing 8 changed files with 28,533 additions and 2,176 deletions.
30,444 changes: 28,350 additions & 2,094 deletions docs/static/openapi.yml

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions layer_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Requirements:
- must have sed, jq, and go(v1.22) installed properly on your computer

Creating a new node:

If you are running everything in one terminal instance I recommend using screen sessions so that you can still query the chain and run other things after your node has started

Once the chain is running please select an rpc url of a current node to use in your set up of your node and set the LAYER_NODE_URL variable to that url (ex: tellor-example-node.com) WITH NO QUOTES

After finding a node url to use call "curl tellor-example-node.com:26657/status" this should return something like this:

{
"jsonrpc":"2.0",
"id":-1,
"result":{
"node_info":{
"protocol_version":{
"p2p":"8",
"block":"11",
"app":"0"
},
"id":"f5f6ce5d15ea80683b9133b19e245f9b27daab67",
"listen_addr":"tcp://0.0.0.0:26656",
"network":"layer",
"version":"0.38.7",
"channels":"40202122233038606100",
"moniker":"alicemoniker",
"other":{
"tx_index":"on",
"rpc_address":"tcp://0.0.0.0:26657"
}
},
"sync_info":{
"latest_block_hash":"5CD20D6553DDBE078EB43AC970F6D391F8FDFB2D2BD968F7B1A7454AA05154C5",
"latest_app_hash":"847D19668188D482BFAA8808FB6207315F0766098A9202103F33DF51070027A5",
"latest_block_height":"73830",
"latest_block_time":"2024-06-04T15:38:53.899045777Z","earliest_block_hash":"EACF6AFE38ABB21E97078359EFAAD7E61D0417BBBA2C7724BB042D38F73693E1","earliest_app_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
"earliest_block_height":"1",
"earliest_block_time":"2024-06-03T17:59:53.991818534Z",
"catching_up":false
},
"validator_info":{
"address":"BEBEAE312EEE6AAD0E315FC6A36C9C44BDCEA1D3",
"pub_key":{"type":"tendermint/PubKeyEd25519","value":"0/8w6RR2ZiQLwdbn1QvwrxYSfGUtW7jXTyPOL9a9NiY="},"voting_power":"100000"
}
}
}

Use the node_info.id value to set TELLORNODE_ID variable with NO QUOTES

Set the node name and moniker used for your node. Can be whatever name you want it to be
- will be used to name the folder that your node config is in. Should be in the default location of already set in the LAYERD_NODE_HOME variable as "$HOME/.layer/$NODE_NAME"

run "sh ./layer_scripts/{selected version of script}.sh" inside of the layer base folder and it should set things up and start the chain thus making your node start syncing with your seed/peer


Creating a validator:

Assumes that you have a running and synced up node already

1. Set variable values
- Use the same values you used for creating your node. Then select the amount of trb you would like to receive to from the faucet and stake for the new validator (1 TRB == 1e1*6 loya)

2. Run script from layer base folder with command: sh ./layer_scripts/create_new_validator_{OS}.sh

3. After you have created your keys and made the transaction to create a new validator watch the output to ensure the returned validator info shows "status": 3
- if status != 3 then cancel the script with CTRL-C

4. Whenever the script tells you to go to the terminal or screen session that your current node is running and stop the chain using CTRL-C. This will allow for the create validator script to restart the chain/node but this time it will run as a validator

75 changes: 75 additions & 0 deletions layer_scripts/create_new_validator_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

# clear the terminal
clear

# Stop execution if any command fails
set -e

### YOU MUST HAVE THE FAUCET RUNNING LOCALLY FOR THIS SCRIPT TO WORK

## YOU WILL NEED TO SET THIS TO WHATEVER NODE YOU WOULD LIKE TO USE
export LAYER_NODE_URL=tellornode.com
export TELLORNODE_ID=
export KEYRING_BACKEND="test"
export NODE_MONIKER="billmoniker"
export NODE_NAME="bill"
export AMOUNT_IN_TRB=1000
export AMOUNT_IN_LOYA="1000000000loya"
export LAYERD_NODE_HOME="$HOME/.layer/$NODE_NAME"

# Create a validator account for node
echo "Creating account keys for node to be able to send and receive loya and stake..."
./layerd keys add $NODE_NAME --keyring-backend $KEYRING_BACKEND --home $LAYERD_NODE_HOME

# Import validator account from seed phrase
# echo "Importing validator account from seed phrase..."
# ./layerd keys add $NODE_NAME --recover=true --keyring-backend $KEYRING_BACKEND

# Get address/account for node to use in gentx tx
echo "Getting the address of your node to use for faucet request"
NODE_ADDRESS=$(./layerd keys show $NODE_NAME -a --keyring-backend $KEYRING_BACKEND --home $LAYERD_NODE_HOME)
echo "NODE address: $NODE_ADDRESS"

echo "Calling faucet to fund account..."
curl -X POST localhost:3000/faucetRequest/user/$NODE_ADDRESS/amount/$AMOUNT_IN_TRB

VAL_PUB_KEY=$(./layerd comet show-validator --home $LAYERD_NODE_HOME)
echo "Validator's pubkey: $VAL_PUB_KEY"

VALIDATOR_JSON=$(cat <<EOF
{
"pubkey": $VAL_PUB_KEY,
"amount": $AMOUNT_IN_LOYA,
"moniker": $NODE_MONIKER,
"identity": "optional identity signature (ex. UPort or Keybase)",
"website": "validator's (optional) website",
"security": "validator's (optional) security contact email",
"details": "validator's (optional) details",
"commission-rate": "0.1",
"commission-max-rate": "0.2",
"commission-max-change-rate": "0.01",
"min-self-delegation": "1"
}
EOF
)

# Save the validator.json content to a file
echo "Creating bill's validator.json..."
echo "$VALIDATOR_JSON" > ./validator.json

echo "Creating and broadcasting transaction to create validator on chain...."
./layerd tx staking create-validator ./validator.json --from $NODE_ADDRESS --home $LAYERD_NODE_HOME --chain-id layer --node="http://$LAYER_NODE_URL:26657"

echo "Wait for 10 seconds to allow for validator to be bonded before we query the validator info"
sleep 10

echo "Querying new validator info... Looking for the status field to have a value of 3 which shows that the new validator is bonded"
./layerd query staking validator $(./layerd keys show $NODE_NAME --bech val --address --keyring-backend $KEYRING_BACKEND --home $LAYERD_NODE_HOME) --output json | jq


echo "If status is 3 now is the time to go back to the screen session or terminal your node is running on and use CTL-C to stop the node"
echo "We will wait in this script for 30 seconds before we call the command to restart the chain using the same set up that was done before"
sleep 30

./layerd start --home $LAYERD_NODE_HOME --api.enable --api.swagger --panic-on-daemon-failure-enabled=false --p2p.seeds "$TELLORNODE_ID@$LAYER_NODE_URL:26656"
35 changes: 8 additions & 27 deletions layer_scripts/join_chain_new_node_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ clear
# Stop execution if any command fails
set -e

KEYRING_BACKEND="test"
PASSWORD="password"
NODE_MONIKER="billmoniker"
NODE_NAME="bill"

export LAYERD_NODE_HOME="$HOME/.layer/$NODE_NAME"
## YOU WILL NEED TO SET THIS TO WHATEVER NODE YOU WOULD LIKE TO USE
export LAYER_NODE_URL=
export LAYER_NODE_URL=tellornode.com
export KEYRING_BACKEND="test"
export NODE_MONIKER="billmoniker"
export NODE_NAME="bill"
export TELLORNODE_ID=f5f6ce5d15ea80683b9133b19e245f9b27daab67
export LAYERD_NODE_HOME="$HOME/.layer/$NODE_NAME"


# Remove old test chain data (if present)
echo "Removing old test chain data..."
Expand All @@ -31,10 +31,6 @@ echo "Initializing the chain..."
echo "Initializing chain node for node..."
./layerd init $NODE_MONIKER --chain-id layer --home ~/.layer/$NODE_NAME

# # Add a validator account for node
echo "Creating account keys for node to be able to send and receive loya and stake..."
./layerd keys add $NODE_NAME --keyring-backend $KEYRING_BACKEND --home ~/.layer/$NODE_NAME

echo "Change denom to loya in config files..."
sed -i 's/([0-9]+)stake/1loya/g' ~/.layer/$NODE_NAME/config/app.toml
sed -i 's/([0-9]+)stake/1loya/g' ~/.layer/config/app.toml
Expand All @@ -43,11 +39,6 @@ echo "Set Chain Id to layer in client config file..."
sed -i 's/^chain-id = .*$/chain-id = "layer"/g' ~/.layer/$NODE_NAME/config/app.toml
sed -i 's/^chain-id = .*$/chain-id = "layer"/g' ~/.layer/config/app.toml

# Get address/account for node to use in gentx tx
echo "Get address/account for node"
NODE=$(./layerd keys show $NODE_NAME -a --keyring-backend $KEYRING_BACKEND --home ~/.layer/$NODE_NAME)
echo "NODE: $NODE"

# Modify timeout_commit in config.toml for node
echo "Modifying timeout_commit in config.toml for node..."
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/' ~/.layer/$NODE_NAME/config/config.toml
Expand Down Expand Up @@ -84,20 +75,10 @@ echo "Getting genesis from runnning node....."
curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/config/genesis.json
curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/$NODE_NAME/config/genesis.json

export QUOTED_TELLORNODE_ID="$(curl $LAYER_NODE_URL:26657/status | jq '.result.node_info.id')"
#export TELLORNODE_ID=${QUOTED_TELLORNODE_ID//\"/}
export TELLORNODE_ID=${echo "$QUOTED_TELLORNODE_ID" | tr -d "'\"" }
echo "NODE ID: $TELLORNODE_ID"
# echo "Tellor node id: $TELLORNODE_ID"
# sed -i 's/seeds = ""/seeds = "'$TELLORNODE_ID'@$LAYER_NODE_URL:26656"/g' ~/.layer/$NODE_NAME/config/config.toml
# sed -i 's/persistent_peers = ""/persistent_peers = "'$TELLORNODE_ID'@$LAYER_NODE_URL:26656"/g' ~/.layer/$NODE_NAME/config/config.toml
sed -i 's/seeds = ""/seeds = "'$TELLORNODE_ID'@'$LAYER_NODE_URL':26656"/g' ~/.layer/$NODE_NAME/config/config.toml
sed -i 's/persistent_peers = ""/persistent_peers = "'$TELLORNODE_ID'@'$LAYER_NODE_URL':26656"/g' ~/.layer/$NODE_NAME/config/config.toml

echo "Node ID: $QUOTED_TELLORNODE_ID"
echo "Path: @$LAYER_NODE_URL:26656"

sleep 60
echo "Path: $TELLORNODE_ID@$LAYER_NODE_URL:26656"

echo "Starting chain for node..."
./layerd start --home $LAYERD_NODE_HOME --api.enable --api.swagger --panic-on-daemon-failure-enabled=false --p2p.seeds "$TELLORNODE_ID@$LAYER_NODE_URL:26656"
25 changes: 11 additions & 14 deletions layer_scripts/join_chain_new_node_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ clear
# Stop execution if any command fails
set -e

KEYRING_BACKEND="test"
PASSWORD="password"
NODE_MONIKER="billmoniker"
NODE_NAME="bill"

export LAYERD_NODE_HOME="$HOME/.layer/$NODE_NAME"
## YOU WILL NEED TO SET THIS TO WHATEVER NODE YOU WOULD LIKE TO USE
export LAYER_NODE_URL=
export LAYER_NODE_URL=tellornode.com
export TELLORNODE_ID=f5f6ce5d15ea80683b9133b19e245f9b27daab67
export KEYRING_BACKEND=test
export NODE_MONIKER="billmoniker"
export NODE_NAME="bill"
export LAYERD_NODE_HOME="$HOME/.layer/$NODE_NAME"


# Remove old test chain data (if present)
echo "Removing old test chain data..."
Expand All @@ -35,13 +35,12 @@ echo "Initializing chain node for alice..."
echo "creating keys for node"
./layerd keys add $NODE_NAME --home ~/.layer/$NODE_NAME --keyring-backend $KEYRING_BACKEND


# Modify timeout_commit in config.toml for node
echo "Modifying timeout_commit in config.toml for $NODE_NAME..."
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/' ~/.layer/$NODE_NAME/config/config.toml

# Open up node to outside traffic
echo "Open up node to outside traffice"
echo "Open up node to outside traffic"
sed -i '' 's/^laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/g' ~/.layer/$NODE_NAME/config/config.toml
sed -i '' 's/^laddr = "tcp:\/\/127.0.0.1:26656"/laddr = "tcp:\/\/0.0.0.0:26656"/g' ~/.layer/$NODE_NAME/config/config.toml

Expand All @@ -61,9 +60,9 @@ sed -i '' 's/^enable-unsafe-cors = false/enable-unsafe-cors = true/g' ~/.layer/c

# Modify keyring-backend in client.toml for node
echo "Modifying keyring-backend in client.toml for node..."
sed -i '' 's/^keyring-backend = "os"/keyring-backend = "test"/g' ~/.layer/$NODE_NAME/config/client.toml
sed -i '' 's/^keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/$NODE_NAME/config/client.toml
# update for main dir as well. why is this needed?
sed -i '' 's/keyring-backend = "os"/keyring-backend = "test"/g' ~/.layer/config/client.toml
sed -i '' 's/keyring-backend = "os"/keyring-backend = "'$KEYRING_BACKEND'"/g' ~/.layer/config/client.toml

rm -f ~/.layer/config/genesis.json
rm -f ~/.layer/$NODE_NAME/config/genesis.json
Expand All @@ -72,9 +71,7 @@ echo "Getting genesis from runnning node....."
curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/config/genesis.json
curl $LAYER_NODE_URL:26657/genesis | jq '.result.genesis' > ~/.layer/$NODE_NAME/config/genesis.json

export QUOTED_TELLORNODE_ID="$(curl $LAYER_NODE_URL:26657/status | jq '.result.node_info.id')"
export TELLORNODE_ID=${QUOTED_TELLORNODE_ID//\"/}
echo "Tellor node id: $TELLORNODE_ID"
echo "Running Tellor node id: $TELLORNODE_ID"
sed -i '' 's/seeds = ""/seeds = "'$TELLORNODE_ID'@'$LAYER_NODE_URL':26656"/g' ~/.layer/$NODE_NAME/config/config.toml
sed -i '' 's/persistent_peers = ""/persistent_peers = "'$TELLORNODE_ID'@'$LAYER_NODE_URL':26656"/g' ~/.layer/$NODE_NAME/config/config.toml

Expand Down
17 changes: 17 additions & 0 deletions start_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Requirements:
- [email protected]
- sed
- jq

If you are planning on not using the default port numbers (26656, 26657, 9090, 1317, etc) then make sure you update the script to point to the desired port numbers

start_one_node.sh (has been run solely on macs)
- this script starts the chain with one node and validator
- Unless you want to change the name of the folder used all you have to do to run this script is "sh ./start_scripts/start_one_node.sh and it will spin it up with the config being set up at ~/.layer/alice and the name of your keys/node is alice


start_one_node_aws.sh (has been run solely on ubuntu ec2 instances)
- this script starts the chain with one node and validator and allows you to import a faucet account with a seed phrase.
- Unless you want to change the name of the folder used all you have to do to run this script is "sh ./start_scripts/start_one_node_aws.sh and it will spin it up with the config being set up at ~/.layer/alice and the name of your keys/node is alice


39 changes: 0 additions & 39 deletions start_scripts/start_chain.sh

This file was deleted.

4 changes: 2 additions & 2 deletions start_scripts/start_one_node_aws.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ echo "ALICE: $ALICE"

# Create a tx to give alice loyas to stake
echo "Adding genesis account for alice..."
./layerd genesis add-genesis-account $ALICE 1000000000000000000000000000loya --keyring-backend $KEYRING_BACKEND --home ~/.layer/alice
./layerd genesis add-genesis-account $ALICE 100000000000loya --keyring-backend $KEYRING_BACKEND --home ~/.layer/alice

# Create a tx to give faucet loyas to have on hold to give to users
echo "Adding genesis account for alice..."
./layerd genesis add-genesis-account tellor19d90wqftqx34khmln36zjdswm9p2aqawq2t3vp 1000000000000000000000000000loya --home ~/.layer/alice

# Create a tx to stake some loyas for alice
echo "Creating gentx for alice..."
./layerd genesis gentx alice 100000000000000000loya --keyring-backend $KEYRING_BACKEND --home ~/.layer/alice --chain-id layer
./layerd genesis gentx alice 100000000000loya --keyring-backend $KEYRING_BACKEND --home ~/.layer/alice --chain-id layer

# Add the transactions to the genesis block
echo "Collecting gentxs..."
Expand Down

0 comments on commit e67f2ce

Please sign in to comment.