Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "casper-node-launcher"
version = "1.0.5"
authors = ["Fraser Hutchison <fraser@casperlabs.io>", "Joe Sacher <joe@casperlabs.io>"]
version = "1.0.6"
authors = ["Fraser Hutchison <fraser@casperlabs.io>", "Joe Sacher <joe.sacher@casper.network>"]
edition = "2018"
description = "A binary which runs and upgrades the casper-node of the Casper network"
readme = "README.md"
documentation = "https://docs.rs/casper-node-launcher"
homepage = "https://casper.network"
repository = "https://github.com/CasperLabs/casper-node/tree/master/client"
repository = "https://github.com/casper-network/casper-node-launcher"
license-file = "./LICENSE"

[dependencies]
Expand Down
28 changes: 16 additions & 12 deletions resources/ETC_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This package runs the casper-node software and handles changing execution to new
determined times based on configuration. This allows simultaneous upgrading of all nodes on the
network.

Please refer to http://docs.casperlabs.io for information on how to run a node.
Please refer to http://docs.casper.network for information on how to run a node.

## systemd

Expand Down Expand Up @@ -44,30 +44,34 @@ To start service:

`sudo systemctl start casper-node-launcher`

Or use the node utility script:

`sudo /etc/casper/node_util.py start`

To stop:

`sudo systemctl stop casper-node-launcher`

## Local Storage
Or use the node utility script:

If you need to delete the db for a new run,
you can use the script in `/etc/casper` with `sudo /etc/casper/delete_local_db.sh`.
`sudo /etc/casper/node_util.py stop`

## Staging casper-node protocols
## Local Storage

If you need to delete the db for a new run use:

Upgrading is done by staging a new casper-node and configuration prior to the agreed upgrade era.
`sudo /etc/casper/node_util.py delete_local_state`

To simplify this, the `sudo -u casper /etc/casper/pull_casper_node_version.sh [network config] [semver]` script is included. This will
pull files from the appropriate version. If desired, the casper-node can be built from source at the
same version.
## Staging casper-node protocols

To get a working default config.toml for a protocol version: `sudo -u casper /etc/casper/config_from_example.sh [semver]`.
Upgrading is done by staging a new casper-node and configuration prior to the agreed upgrade era. This is done with:

`sudo -u casper /etc/casper/node_util.py stage_protocols [network config]`

When the upgrade era occurs, the currently running casper-node will exit and casper-node-launcher will
start the new upgraded version of casper-node.

## Bugs

Please file any bugs as issues on the launcher at [the casper-node-launcher GitHub repo](https://github.com/CasperLabs/casper-node-launcher).
Please file any bugs as issues onthe node at [the casper-node GitHub repo](https://github.com/CasperLabs/casper-node).
Please file any bugs as issues on the launcher at [the casper-node-launcher GitHub repo](https://github.com/casper-network/casper-node-launcher).
Please file any bugs as issues on the node at [the casper-node GitHub repo](https://github.com/casper-network/casper-node).
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Unit]
Description=Casper Node Launcher
Documentation=https://docs.casperlabs.io
Documentation=https://docs.casper.network
After=network-online.target
# Stop restarting after 3 failures in 15 seconds
StartLimitBurst=3
Expand Down
47 changes: 14 additions & 33 deletions resources/maintainer_scripts/network_configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,37 @@ It is recommended that network_name used is the same as the <network_name>.conf.

## Usage

These configurations will be sent to `pull_casper_node_version.sh` as an argument.
These configurations will be sent to `node_util.py stage_protocols` as an argument.

The target URL is expected to serve HTTP access to `<url>/<network_name>/<protocol_version>/[bin.tar.gz|config.tar.gz]`
Protocol versions to install is expected to exist in `<url>/<network_name>/protocol_versions` as a protocol version per line.

Example:
`sudo -u casper pull_casper_node_version.sh casper.conf 1_0_0`
`sudo -u casper /etc/casper/node_util.py stage_protocols casper.conf`

With `casper.conf` of:
```
SOURCE_URL=genesis.casperlabs.io
SOURCE_URL=genesis.casper.network
NETWORK_NAME=casper
BIN_MODE=mainnet
```

Will perform:
```
curl -JLO genesis.casperlabs.io/casper/1_0_0/bin.tar.gz
curl -JLO genesis.casperlabs.io/casper/1_0_0/config.tar.gz
```

`config.tar.gz` is decompressed into `/etc/casper/<protocol_version>`.
`bin.tar.gz` is decompressed into `/var/lib/casper/<protocol_version>`.

The script will error if protocol versions already exist.

## Packaging
Pull and parsing of `genesis.casper.network/casper/protocol_versions`.
Then pulling and installing each protocol listed.

With merges to `master`, `release-*` and `dev` branches in the `casper-node` repo, the artifacts are created in
`genesis.casperlabs.io/drone/<git_hash>/<protocol version>/[bin.tar.gz|config.tar.gz]`.

You may also pull down the artifacts for a given network and modify to stage a new network.
If you want to launch a network with the same software version of `casper`, you could pull down the `bin.tar.gz` and
use as is. However, your `config.tar.gz` would need modified.
If `protocol_versions` had:

```
mkdir config
curl -JLO genesis.casperlabs.io/casper/1_0_0/bin.tar.gz
curl -JLO genesis.casperlabs.io/casper/1_0_0/config.tar.gz
mv config.tar.gz config_old.tar.gz
cd config
tar -xzvf ../config_old.tar.gz
2_0_0
```

You would need to customize `chainspec.toml` with a new network name and activation_point timestamp.
You would need to customize `config-example.toml` with new known_addresses.

Once all the configuration changes are done. Create a new config.tar.gz from within the config directory.

This would download:
```
tar -czvf ../config.tar.gz .
curl -JLO genesis.casper.network/casper/2_0_0/bin.tar.gz
curl -JLO genesis.casper.network/casper/2_0_0/config.tar.gz
```
`config.tar.gz` is decompressed into `/etc/casper/<protocol_version>`.
`bin.tar.gz` is decompressed into `/var/lib/casper/<protocol_version>`.

Now upload `bin.tar.gz` and `config.tar.gz` to your `<url>/<network>/<protocol_version>` location.
Then `/etc/casper/2_0_0/config.toml` is made from `config-example.toml` in the same directory.
90 changes: 76 additions & 14 deletions resources/maintainer_scripts/node_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ def _replace_config_values(config_data, replace_file):
new_output.append(f"{name} = {new_value}")
else:
new_output.append(line)
# Make trailing new line
new_output.append("")
return "\n".join(new_output)

def _config_from_example(self, protocol_version, ip=None, replace_toml=None):
Expand Down Expand Up @@ -821,9 +823,6 @@ def get_trusted_hash(self):
help="Protocol version for chainspec to verify same network",
required=False,
default="1_0_0")
parser.add_argument("--block",
help="Block number to use (latest if omitted)",
required=False)

args = parser.parse_args(sys.argv[2:])

Expand All @@ -850,24 +849,87 @@ def get_trusted_hash(self):
if last_added_block_info is None:
print(f"No last_added_block_info in {args.ip} status. Node is not in sync and will not be used.")
exit(1)
# If no block, getting latest so store now
block_hash = last_added_block_info["hash"]
if args.block:
try:
block = self._rpc_get_block(server=args.ip, block_height=args.block)
block_hash = block["block"]["hash"]
except Exception as e:
if "timed out" in str(e):
print(f"RPC call timed out, either {args.ip} has RPC port blocked or is not in sync.")
else:
print(f"Error calling RPC for {args.ip}.")
exit(1)
print(f"{block_hash}")

def get_ip(self):
""" Get external IP of node. Can be used to test code used for automatically filling IP
or to check if you need to update the IP in your config.toml file. """
print(self._get_external_ip())

def node_log(self):
""" Get nodes current logs. Same as 'cat /var/log/casper-node.log` with grep added if using arguments
and tail if following. """
parser = argparse.ArgumentParser(description=self.node_log.__doc__,
usage=f"{self.SCRIPT_NAME} node_log [--err] [--warn] [--follow]")
parser.add_argument("--err",
help="Return log lines with level ERR",
action='store_true',
required=False)
parser.add_argument("--warn",
help="Return log lines with level WARN",
action='store_true',
required=False)
parser.add_argument("--follow",
help="Follow log file as lines are added",
action='store_true',
required=False)
args = parser.parse_args(sys.argv[2:])

grep_args = ""
grep_args += " -e '\"level\":\"ERR\"'" if args.err else ""
grep_args += " -e '\"level\":\"WARN\"'" if args.warn else ""

grep = f" | grep {grep_args}" if len(grep_args) > 0 else ""

main_cmd = "tail -f" if args.follow else "cat"

os.system(f"{main_cmd} /var/log/casper/casper-node.log {grep}")

@staticmethod
def node_error_log():
""" Get nodes current teardown error log. Same as 'cat /var/log/casper-node.stderr.log` """
os.system("cat /var/log/casper/casper-node.stderr.log")

@staticmethod
def sidecar_status():
""" Get systemd status of casper-sidecar. Same as `systemctl status casper-sidecar` """
# using op.popen to stop hanging return to terminate
result = os.popen("systemctl status casper-sidecar")
print(result.read())

def sidecar_log(self):
""" Get log from casper-sidecar. Same as `journalctl -u casper-sidecar --no-pager` """
parser = argparse.ArgumentParser(description=self.sidecar_log.__doc__,
usage=f"{self.SCRIPT_NAME} sidecar_log [--follow]")
parser.add_argument("--follow",
help="Follow log file as lines are added",
action='store_true',
required=False)

args = parser.parse_args(sys.argv[2:])
follow = "--follow" if args.follow else ""
os.system(f"journalctl -u casper-sidecar --no-pager {follow}")

def sidecar_stop(self):
""" Stop casper-sidecar. Use 'sudo'.
Same as `sudo systemctl stop casper-sidecar` """
self._verify_root_user()
os.system("sudo systemctl stop casper-sidecar")

def sidecar_start(self):
""" Start casper-sidecar. Use 'sudo'.
Same as `sudo systemctl start casper-sidecar` """
self._verify_root_user()
os.system("sudo systemctl start casper-sidecar")

def sidecar_restart(self):
""" Restart casper-sidecar. Use 'sudo'. """
self._verify_root_user()
self.sidecar_stop()
time.sleep(0.5)
self.sidecar_start()


if __name__ == '__main__':
NodeUtil()
Loading