Skip to content

Commit

Permalink
Add Snap fullnode daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jun 26, 2018
1 parent d09be6f commit 35e275f
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,62 @@ $ snap info solana
$ sudo snap refresh solana --devmode
```

### Daemon support
The snap supports running a leader or validator node as a system daemon.

Run `sudo snap get solana` to view the current daemon configuration, and
`sudo snap logs -f solana` to view the daemon logs.

Disable the daemon at any time by running:
```bash
$ sudo snap set solana mode=
```

Runtime configuration files for the daemon can be found in
`/var/snap/solana/current`.

#### Leader daemon
```bash
$ sudo snap set solana mode=leader public-address=$(curl -s ifconfig.co)
```

If CUDA is available:
```bash
$ sudo snap set solana mode=leader-cuda public-address=$(curl -s ifconfig.co)
```

`rsync` must be configured and running on the leader.

1. Ensure rsync is installed with `sudo apt-get -y install rsync`
2. Edit `/etc/rsyncd.conf` to include the following
```
[solana]
path = /var/snap/solana/current
hosts allow = *
read only = true
```
3. Run `sudo systemctl enable rsync; sudo systemctl start rsync`
4. Test by running `rsync -Pzravv rsync://<address-of-leader>/solana
solana-config` from another machine. If the leader is running on a cloud
provider it may be necessary to configure the Firewall rules to permit ingress
to port tcp:873 and the port range udp:8000-udp:10000


#### Validator daemon
```bash
$ sudo snap set solana mode=validator public-address=$(curl -s ifconfig.co)
```
If CUDA is available:
```bash
$ sudo snap set solana mode=validator-cuda public-address=$(curl -s ifconfig.co)
```

By default the validator will connect to **testnet.solana.com**, override
the leader address by running:
```bash
$ sudo snap set solana mode=validator leader-address=127.0.0.1 #<-- change IP address
```

Developing
===

Expand Down
3 changes: 3 additions & 0 deletions ci/snap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ set -x
echo --- build
snapcraft

source ci/upload_ci_artifact.sh
upload_ci_artifact solana_*.snap

echo --- publish
$DRYRUN snapcraft push solana_*.snap --release $SNAP_CHANNEL
18 changes: 18 additions & 0 deletions ci/upload_ci_artifact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# |source| me

upload_ci_artifact() {
echo --- artifact: $1
if [[ -r $1 ]]; then
ls -l $1
if ${BUILDKITE:-false}; then
(
set -x
buildkite-agent artifact upload $1
)
fi
else
echo ^^^ +++
echo $1 not found
fi
}

105 changes: 105 additions & 0 deletions multinode-demo/fullnode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash
#
# Runs a full node
#

here="$(dirname "$0")"

usage() {
if [[ -n "$1" ]]; then
echo "$*"
fi

cat <<EOF
Usage: $0 [mode] [public_address] [leader_address]"
mode Select operation mode:
leader - Run a leader
leader-cuda - Run a leader with CUDA
validator - Run a validator
validator-cuda - Run a validator with CUDA
public_address Public IP address of this node
(hint: run |${here}/myip.sh| to help determine this value).
leader_address Address of the leader node to connect with.
Only required when mode=validator or mode=validator-cuda
EOF
exit 1
}


MODE=
if [[ -n "$1" ]]; then
MODE="$1"
elif [[ -d $SNAP ]]; then # Running as a Linux Snap?
MODE="$(snapctl get mode)"
fi
[[ -n "$MODE" ]] || usage "Error: mode not specified"

PUBLIC_ADDRESS=
if [[ -n "$2" ]]; then
PUBLIC_ADDRESS="$2"
elif [[ -d $SNAP ]]; then # Running as a Linux Snap?
PUBLIC_ADDRESS="$(snapctl get public-address)"
fi
[[ -n "$PUBLIC_ADDRESS" ]] || usage "Error: public_address not specified"


FULLNODE=solana-fullnode
if [[ "$MODE" =~ .*cuda ]]; then
if [[ -z $SNAP ]]; then
echo "Note: -cuda suffix ignored, use --features=cuda when running locally"
else
FULLNODE=solana-fullnode-cuda
fi
fi

if [[ -z $SNAP ]]; then
FULLNODE="cargo run --release --bin $FULLNODE --"
fi
DATA_DIR=${SNAP_DATA:-$PWD}

export RUST_LOG=${RUST_LOG:-solana=info} # if RUST_LOG is unset, default to info
export RUST_BACKTRACE=1
[[ $(uname) = Linux ]] && sudo sysctl -w net.core.rmem_max=26214400 1>/dev/null 2>/dev/null

case $MODE in
leader-cuda|leader)
echo "Starting $MODE"
set -x
exec "$FULLNODE" -l "$DATA_DIR/leader.json" \
< "$DATA_DIR/genesis.log" "$DATA_DIR"/tx-*.log \
> "$DATA_DIR"/tx-"$(date -u +%Y%m%d%H%M%S%N)".log
;;

validator-cuda|validator)
LEADER_ADDRESS=testnet.solana.com
if [[ -n "$3" ]]; then
LEADER_ADDRESS="$3"
elif [[ -d $SNAP ]]; then # Running as a Linux Snap?
LEADER_ADDRESS="$(snapctl get leader-address)"
fi
[[ -n "$LEADER_ADDRESS" ]] || usage "Error: leader_address not specified"

echo "Fetching configuration from $LEADER_ADDRESS:"
(
set -x
rsync -vrPz "rsync://$LEADER_ADDRESS/solana" "$DATA_DIR/$LEADER_ADDRESS"
) || exit $?

echo "Starting $MODE connecting to the leader at address: $LEADER_ADDRESS"
set -x
exec "$FULLNODE" \
-l "$DATA_DIR/validator.json" -v "$DATA_DIR/$LEADER_ADDRESS/leader.json" \
< "$DATA_DIR/$LEADER_ADDRESS/genesis.log" "$DATA_DIR/$LEADER_ADDRESS"/tx-*.log
;;

*)
echo "Error: Unknown mode: $MODE"
exit 1
;;
esac

exit 1
4 changes: 4 additions & 0 deletions multinode-demo/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ myip=$(myip) || exit $?

num_tokens=${1:-1000000000}

#
# TODO: Merge this file with ../snap/hooks/configure
#

cargo run --release --bin solana-mint-demo <<<"${num_tokens}" > mint-demo.json
cargo run --release --bin solana-genesis-demo < mint-demo.json > genesis.log

Expand Down
38 changes: 38 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash -e

# Setup aliases to the normal solana command to make the reset of configure more
# readable.
shopt -s expand_aliases
export SNAP SNAP_LIBRARY_PATH
alias solana-mint-demo=$SNAP/command-mint-demo.wrapper
alias solana-genesis-demo=$SNAP/command-genesis-demo.wrapper
alias solana-fullnode-config=$SNAP/command-fullnode-config.wrapper

echo Stopping daemon
snapctl stop --disable solana.daemon
if [[ -n "$(snapctl get mode)" ]]; then

#
# TODO: Merge this file with ../../../multinode-demo/setup.sh
#

NUM_TOKENS=1000000000

echo Cleaning $SNAP_DATA
rm -rvf $SNAP_DATA/*

echo Creating $SNAP_DATA/mint-demo.json
solana-mint-demo <<<"$NUM_TOKENS" > $SNAP_DATA/mint-demo.json

echo Creating $SNAP_DATA/genesis.log
solana-genesis-demo < $SNAP_DATA/mint-demo.json > $SNAP_DATA/genesis.log

echo Creating $SNAP_DATA/leader.json
solana-fullnode-config -d > $SNAP_DATA/leader.json

echo Creating $SNAP_DATA/validator.json
solana-fullnode-config -d -b 9000 > $SNAP_DATA/validator.json

echo Starting daemon as $MODE
snapctl start --enable solana.daemon
fi
15 changes: 15 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ grade: devel
# CUDA dependency, so use 'devmode' confinement for now
confinement: devmode

hooks:
configure:
plugs: []

apps:
drone:
command: solana-drone
Expand Down Expand Up @@ -44,7 +48,18 @@ apps:
client-demo:
command: solana-client-demo

daemon:
daemon: simple
command: fullnode.sh

parts:
solana-scripts:
plugin: nil
override-build: |
set -x
mkdir -p $SNAPCRAFT_PART_INSTALL/bin
cp -av multinode-demo/* $SNAPCRAFT_PART_INSTALL/bin/
solana-cuda:
plugin: rust
rust-channel: stable
Expand Down

0 comments on commit 35e275f

Please sign in to comment.