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
13 changes: 12 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
"showLog": true,
"trace": "verbose"
},

{
"name": "sncli debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/sncli/main.go",
"cwd": "${workspaceFolder}/cmd/sncli",
"args": ["list"],
"env": {},
"showLog": true,
"trace": "verbose"
},
]
}
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ build:

build-sncli: release/sncli

SNCLI_SRC := $(wildcard cmd/sncli/*.go) \
$(wildcard cmd/sncli/**/*.go)

release/sncli: $(SNCLI_SRC) cmd/sncli/go.mod cmd/sncli/go.sum
@mkdir -p release
@echo "Building sncli..."
Expand All @@ -49,8 +52,6 @@ release/sncli: $(SNCLI_SRC) cmd/sncli/go.mod cmd/sncli/go.sum
chmod +x $$RELEASE_DIR/sncli && \
echo "sncli built successfully at $$RELEASE_DIR/sncli"

SNCLI_SRC=$(shell find cmd/sncli -name "*.go")

build-sn-manager:
@mkdir -p release
@echo "Building sn-manager..."
Expand Down
87 changes: 69 additions & 18 deletions cmd/sncli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ make build-sncli

## ⚙️ Configuration

Create a `config.toml` file in the same directory where you run `sncli`:
**Default config location:** `~/.sncli/config.toml`

You can override the location with `--config <path>` or `SNCLI_CONFIG_PATH`.

```toml
# ~/.sncli/config.toml

# Lumera blockchain connection settings
[lumera]
grpc_addr = "localhost:9090"
Expand All @@ -36,10 +40,11 @@ local_address = "lumera1abc..." # Bech32 address of local account (must exi
# Supernode peer information
[supernode]
grpc_endpoint = "127.0.0.1:4444"
p2p_endpoint = "127.0.0.1:4445"
address = "lumera1supernodeabc123" # Bech32 address of the Supernode
```

> Ensure the `local_address` exists on-chain (i.e., has received funds or sent a tx).
> Ensure the `keyring.local_address` exists on-chain (i.e., has received funds or sent a tx).

---

Expand All @@ -48,41 +53,87 @@ address = "lumera1supernodeabc123" # Bech32 address of the Supernode
Run the CLI by calling the built binary with a command:

```bash
./sncli [<options>] <command> [args...]
sncli [global flags] <command> [command flags] [args...]
```

### Supported Command-Line Options
### Global flags

| Option | Description |
| --------------- | ------------------------------------------------------------------------------------------------- |
| --config | Path to config file. Supports ~. Default: ./config.toml or SNCLI_CONFIG_PATH environment variable |
| --grpc_endpoint | Override gRPC endpoint for Supernode (e.g., 127.0.0.1:4444) |
| --address | Override Supernode's Lumera address |
* `--config string` Path to config file (default `~/.sncli/config.toml`)
* `--grpc_endpoint string` Supernode gRPC endpoint
* `--p2p_endpoint string` Supernode P2P endpoint (Kademlia)
* `--address string` Supernode Lumera address
* `-h, --help` Help for `sncli`

### Supported Commands
* `completion` Generate shell completion
* `get-status` Query Supernode status (CPU, memory, tasks, peers)
* `health-check` Check Supernode health status
* `list` List available gRPC services or methods in a specific service
* `list` `<service>` List methods in a specific gRPC service
* `p2p` **Supernode P2P utilities**

## 🌐 P2P command group

The `p2p` group contains tools for interacting with the Supernode’s **Kademlia P2P** service.

### `sncli p2p`

Shows P2P help and available subcommands.

| Command | Description |
| ---------------------- | -------------------------------------------------------- |
| `help` | Show usage instructions |
| `list` | List available gRPC services from the Supernode |
| `list` `<service>` | List methods in a specific gRPC service |
| `health-check` | Check if the Supernode is alive |
| `get-status` | Query current CPU/memory usage reported by the Supernode |
```
Supernode P2P utilities

Usage:
sncli p2p [command]

Available Commands:
ping Check the connectivity to a Supernode's kademlia P2P server

### Example

```bash
./sncli --config ~/.sncli.toml --grpc_endpoint 10.0.0.1:4444 --address lumera1xyzabc get-status
```

### `sncli p2p ping` — check connectivity

Checks TCP reachability and does a lightweight ping of the Supernode’s **P2P** endpoint.

**Usage**

```
sncli p2p ping [timeout]
```

* `timeout` is optional (e.g., `5s`, `1m`). If omitted, a sensible default is used (e.g., `10s`).
* You can also set `--timeout` explicitly (if supported by your build).
* The endpoint can be supplied via `--p2p_endpoint` or taken from the config at `[supernode].p2p_endpoint`.

---

**Examples**

```bash
# Use endpoint from config (~/.sncli/config.toml)
sncli p2p ping

# Override endpoint with a flag
sncli p2p ping --p2p_endpoint 172.18.0.6:4445
# Output:
# P2P is alive (172.18.0.6:4445)

# Use a custom timeout (positional)
sncli p2p ping 3s

# Use a custom timeout (flag)
sncli p2p ping --timeout 30s
```

## 📝 Notes

- `sncli` uses a secure gRPC connection with a handshake based on the Lumera keyring.
- The Supernode address must match a known peer on the network.
- Make sure`sncli-account` has been initialized and exists on the chain.
- Config file path is resolved using this algorithm:
- First uses --config flag (if provided)
- Else uses SNCLI_CONFIG_PATH environment variable (if defined)
- Else defaults to ./config.toml
- Else defaults to ~/.sncli/config.toml
Loading