Skip to content

Commit 1badad4

Browse files
authored
Merge pull request #69 from sacherjj/sidecar-node_util-functions
node_util updates for sidecar and infra url updates.
2 parents 9a935a6 + 09b3d38 commit 1badad4

File tree

6 files changed

+111
-64
lines changed

6 files changed

+111
-64
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
name = "casper-node-launcher"
3-
version = "1.0.5"
4-
authors = ["Fraser Hutchison <[email protected]>", "Joe Sacher <joe@casperlabs.io>"]
3+
version = "1.0.6"
4+
authors = ["Fraser Hutchison <[email protected]>", "Joe Sacher <joe[email protected]>"]
55
edition = "2018"
66
description = "A binary which runs and upgrades the casper-node of the Casper network"
77
readme = "README.md"
88
documentation = "https://docs.rs/casper-node-launcher"
99
homepage = "https://casper.network"
10-
repository = "https://github.com/CasperLabs/casper-node/tree/master/client"
10+
repository = "https://github.com/casper-network/casper-node-launcher"
1111
license-file = "./LICENSE"
1212

1313
[dependencies]

resources/ETC_README.md

+16-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This package runs the casper-node software and handles changing execution to new
44
determined times based on configuration. This allows simultaneous upgrading of all nodes on the
55
network.
66

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

99
## systemd
1010

@@ -44,30 +44,34 @@ To start service:
4444

4545
`sudo systemctl start casper-node-launcher`
4646

47+
Or use the node utility script:
48+
49+
`sudo /etc/casper/node_util.py start`
50+
4751
To stop:
4852

4953
`sudo systemctl stop casper-node-launcher`
5054

51-
## Local Storage
55+
Or use the node utility script:
5256

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

56-
## Staging casper-node protocols
59+
## Local Storage
60+
61+
If you need to delete the db for a new run use:
5762

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

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

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

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

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

7074
## Bugs
7175

72-
Please file any bugs as issues on the launcher at [the casper-node-launcher GitHub repo](https://github.com/CasperLabs/casper-node-launcher).
73-
Please file any bugs as issues onthe node at [the casper-node GitHub repo](https://github.com/CasperLabs/casper-node).
76+
Please file any bugs as issues on the launcher at [the casper-node-launcher GitHub repo](https://github.com/casper-network/casper-node-launcher).
77+
Please file any bugs as issues on the node at [the casper-node GitHub repo](https://github.com/casper-network/casper-node).

resources/maintainer_scripts/casper_node_launcher/casper-node-launcher.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Unit]
22
Description=Casper Node Launcher
3-
Documentation=https://docs.casperlabs.io
3+
Documentation=https://docs.casper.network
44
After=network-online.target
55
# Stop restarting after 3 failures in 15 seconds
66
StartLimitBurst=3

resources/maintainer_scripts/network_configs/README.md

+14-33
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,37 @@ It is recommended that network_name used is the same as the <network_name>.conf.
1010

1111
## Usage
1212

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

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

1718
Example:
18-
`sudo -u casper pull_casper_node_version.sh casper.conf 1_0_0`
19+
`sudo -u casper /etc/casper/node_util.py stage_protocols casper.conf`
1920

2021
With `casper.conf` of:
2122
```
22-
SOURCE_URL=genesis.casperlabs.io
23+
SOURCE_URL=genesis.casper.network
2324
NETWORK_NAME=casper
24-
BIN_MODE=mainnet
2525
```
2626

2727
Will perform:
28-
```
29-
curl -JLO genesis.casperlabs.io/casper/1_0_0/bin.tar.gz
30-
curl -JLO genesis.casperlabs.io/casper/1_0_0/config.tar.gz
31-
```
32-
33-
`config.tar.gz` is decompressed into `/etc/casper/<protocol_version>`.
34-
`bin.tar.gz` is decompressed into `/var/lib/casper/<protocol_version>`.
35-
36-
The script will error if protocol versions already exist.
3728

38-
## Packaging
29+
Pull and parsing of `genesis.casper.network/casper/protocol_versions`.
30+
Then pulling and installing each protocol listed.
3931

40-
With merges to `master`, `release-*` and `dev` branches in the `casper-node` repo, the artifacts are created in
41-
`genesis.casperlabs.io/drone/<git_hash>/<protocol version>/[bin.tar.gz|config.tar.gz]`.
42-
43-
You may also pull down the artifacts for a given network and modify to stage a new network.
44-
If you want to launch a network with the same software version of `casper`, you could pull down the `bin.tar.gz` and
45-
use as is. However, your `config.tar.gz` would need modified.
32+
If `protocol_versions` had:
4633

4734
```
48-
mkdir config
49-
curl -JLO genesis.casperlabs.io/casper/1_0_0/bin.tar.gz
50-
curl -JLO genesis.casperlabs.io/casper/1_0_0/config.tar.gz
51-
mv config.tar.gz config_old.tar.gz
52-
cd config
53-
tar -xzvf ../config_old.tar.gz
35+
2_0_0
5436
```
5537

56-
You would need to customize `chainspec.toml` with a new network name and activation_point timestamp.
57-
You would need to customize `config-example.toml` with new known_addresses.
58-
59-
Once all the configuration changes are done. Create a new config.tar.gz from within the config directory.
60-
38+
This would download:
6139
```
62-
tar -czvf ../config.tar.gz .
40+
curl -JLO genesis.casper.network/casper/2_0_0/bin.tar.gz
41+
curl -JLO genesis.casper.network/casper/2_0_0/config.tar.gz
6342
```
43+
`config.tar.gz` is decompressed into `/etc/casper/<protocol_version>`.
44+
`bin.tar.gz` is decompressed into `/var/lib/casper/<protocol_version>`.
6445

65-
Now upload `bin.tar.gz` and `config.tar.gz` to your `<url>/<network>/<protocol_version>` location.
46+
Then `/etc/casper/2_0_0/config.toml` is made from `config-example.toml` in the same directory.

resources/maintainer_scripts/node_util.py

+76-14
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ def _replace_config_values(config_data, replace_file):
339339
new_output.append(f"{name} = {new_value}")
340340
else:
341341
new_output.append(line)
342+
# Make trailing new line
343+
new_output.append("")
342344
return "\n".join(new_output)
343345

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

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

@@ -850,24 +849,87 @@ def get_trusted_hash(self):
850849
if last_added_block_info is None:
851850
print(f"No last_added_block_info in {args.ip} status. Node is not in sync and will not be used.")
852851
exit(1)
853-
# If no block, getting latest so store now
854852
block_hash = last_added_block_info["hash"]
855-
if args.block:
856-
try:
857-
block = self._rpc_get_block(server=args.ip, block_height=args.block)
858-
block_hash = block["block"]["hash"]
859-
except Exception as e:
860-
if "timed out" in str(e):
861-
print(f"RPC call timed out, either {args.ip} has RPC port blocked or is not in sync.")
862-
else:
863-
print(f"Error calling RPC for {args.ip}.")
864-
exit(1)
865853
print(f"{block_hash}")
866854

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

860+
def node_log(self):
861+
""" Get nodes current logs. Same as 'cat /var/log/casper-node.log` with grep added if using arguments
862+
and tail if following. """
863+
parser = argparse.ArgumentParser(description=self.node_log.__doc__,
864+
usage=f"{self.SCRIPT_NAME} node_log [--err] [--warn] [--follow]")
865+
parser.add_argument("--err",
866+
help="Return log lines with level ERR",
867+
action='store_true',
868+
required=False)
869+
parser.add_argument("--warn",
870+
help="Return log lines with level WARN",
871+
action='store_true',
872+
required=False)
873+
parser.add_argument("--follow",
874+
help="Follow log file as lines are added",
875+
action='store_true',
876+
required=False)
877+
args = parser.parse_args(sys.argv[2:])
878+
879+
grep_args = ""
880+
grep_args += " -e '\"level\":\"ERR\"'" if args.err else ""
881+
grep_args += " -e '\"level\":\"WARN\"'" if args.warn else ""
882+
883+
grep = f" | grep {grep_args}" if len(grep_args) > 0 else ""
884+
885+
main_cmd = "tail -f" if args.follow else "cat"
886+
887+
os.system(f"{main_cmd} /var/log/casper/casper-node.log {grep}")
888+
889+
@staticmethod
890+
def node_error_log():
891+
""" Get nodes current teardown error log. Same as 'cat /var/log/casper-node.stderr.log` """
892+
os.system("cat /var/log/casper/casper-node.stderr.log")
893+
894+
@staticmethod
895+
def sidecar_status():
896+
""" Get systemd status of casper-sidecar. Same as `systemctl status casper-sidecar` """
897+
# using op.popen to stop hanging return to terminate
898+
result = os.popen("systemctl status casper-sidecar")
899+
print(result.read())
900+
901+
def sidecar_log(self):
902+
""" Get log from casper-sidecar. Same as `journalctl -u casper-sidecar --no-pager` """
903+
parser = argparse.ArgumentParser(description=self.sidecar_log.__doc__,
904+
usage=f"{self.SCRIPT_NAME} sidecar_log [--follow]")
905+
parser.add_argument("--follow",
906+
help="Follow log file as lines are added",
907+
action='store_true',
908+
required=False)
909+
910+
args = parser.parse_args(sys.argv[2:])
911+
follow = "--follow" if args.follow else ""
912+
os.system(f"journalctl -u casper-sidecar --no-pager {follow}")
913+
914+
def sidecar_stop(self):
915+
""" Stop casper-sidecar. Use 'sudo'.
916+
Same as `sudo systemctl stop casper-sidecar` """
917+
self._verify_root_user()
918+
os.system("sudo systemctl stop casper-sidecar")
919+
920+
def sidecar_start(self):
921+
""" Start casper-sidecar. Use 'sudo'.
922+
Same as `sudo systemctl start casper-sidecar` """
923+
self._verify_root_user()
924+
os.system("sudo systemctl start casper-sidecar")
925+
926+
def sidecar_restart(self):
927+
""" Restart casper-sidecar. Use 'sudo'. """
928+
self._verify_root_user()
929+
self.sidecar_stop()
930+
time.sleep(0.5)
931+
self.sidecar_start()
932+
933+
872934
if __name__ == '__main__':
873935
NodeUtil()

0 commit comments

Comments
 (0)