Remote Node Control Experiment in Rust Using MaidSafe's qjsonrpc Crate

Yea, this does sound more intuitive to me. In hindsight, keys is a bit of an overloaded term anyway.

Thanks for pointing that out, it was an oversight on my part. I’ll have to go back and re-read some of the CLI user guide. In the current context, it is redundant, so it’s probably safe to nix it for now.

That said (I might be misremembering this, as I can’t find the post now…), I thought I recalled a suggestion about getting routing-related information. I think it was about querying the node_id of known peers… Something like safe node routing for debug purposes? I don’t think that falls under safe networks because it has more to do with the state of the running node and not necessarily the CLI application state. I don’t know if that would be useful (or if I just imagined the whole thing?!) but it’s an idea.

For now then, I think it’d be safe to focus on setting up the rewards, storage, logs, and status commands. Those seem to be the most immediately useful from what I can tell.

Ah right, I think I misunderstood what the netcfg command would be for then, the one I was pointing out is for configuring the network bootstrapping address, but not for the other info you are mentioning like known peers that’s something you’d need to query the node. So basically with safe networks set... cmd you’d set the endpoint where to reach your node, so then you can send queries to it like the list of its peers. Similar to how node join <network name> command works, it boottraps and joins the network that was mapped in CLI settings to that network name.

1 Like

Another week, and deeper down the rabbit hole we go. I’ve got more updates below :gear: :hammer_and_wrench: :gear:

Datatypes Repo

Because I got constantly annoyed of parsing serde_json::Value and catching every little parse error or missing field, I made a new repo sn_node_rpc_data_types that Im’ using for the time being to sync up the serialization of parameter and result. It’s been a lot more convenient and less verbose. As mentioned earlier, if we ever do move to tunneling through safe in some future timeline, these kinds of structured types would make that transition easier.

More Working Commands (CLI and Node Support implemented):

(I’m just going to copy/paste these mostly from my CLI output to save time)

Logs

Prints out a specified number of log lines starting at some specified offset.

USAGE:
    safe.exe node logs [FLAGS] [OPTIONS]

OPTIONS:
        --node-path <node-path>       Path of node root dir (default is ~./safe/node). Th SN_NODE_PATH env var can also
                                      be used [env: SN_NODE_PATH=]
        --rpc-port <node-rpc-port>     [default: 34000]
        --log-id <log-id>             Which log to fetch by id (options: 0 = plaintext logs) [default: 0]
        --num-lines <num-lines>       How many log lines to fetch [default: 10]
        --start-idx <start-idx>       Start line index of log fetch. start_idx > 0 implies offset from the start
                                      start_idx < 0 implies start from index abs(start_idx) from the end (e.g. -1 means
                                      start at the last line) [default: -10]

Note the log_id field. While right now we only have plaintext logs that live on disk, there’s an interesting possibility of adding more log varieties later for structured data collection. Examples include maybe a structured log for QoS and similar things. These don’t even need to live on disk, it’s structured in such a way that, even if these lived in a circular buffer in RAM it would work out fine. It’s pretty flexible.

Rewards

Right now this fetches the reward key (and lets you set it via --set-key, although I’m still debugging set-key right now. Seems my node fails to launch with a serialization error from sn_routing. That might be an issue in upstream though, I haven’t investigated yet). More info like farm attempt success rate and such could be useful to add in later down the line, so it’s also pretty flexible in that sense.

USAGE:
    safe.exe node rewards [FLAGS] [OPTIONS]

OPTIONS:
        --node-path <node-path>       Path of node root dir (default is ~./safe/node). Th SN_NODE_PATH env var can also
                                      be used [env: SN_NODE_PATH=]
        --rpc-port <node-rpc-port>    What port to issue node remote procedure calls on [default: 34000]
        --set-key <set-key>           If provided, sets a new reward key from a hex string before fetching rewards info

Storage

Right now this just reports basic information on used space (e.g. total offered vs used), but I’m working on getting a --detailed flag going.

USAGE:
    safe.exe node storage [FLAGS] [OPTIONS]

OPTIONS:
        --node-path <node-path>       Path of node root dir (default is ~./safe/node). Th SN_NODE_PATH env var can also
                                      be used [env: SN_NODE_PATH=]
        --rpc-port <node-rpc-port>     [default: 34000]

Conclusion

I got some more features working in the past week and this is rather functional right now, allowing for some rough edges. Once I get the last of the functionality included for these commands, as well as a status command going, I’ll take a look at sn_launch_tool and sn_cli to make it easier to launch a node with the RPC enabled and to issue RPCs with fewer flags.

4 Likes

So after playing around with this for a little while, I’ve pretty much arrived at this set of RPCs right now with associated cli calls below.

For the time being, I left it to only non-mutator calls. While it’s possible to mutate state in the node right now, it’s not practical right now for this to all to be on one branch.

For example, setting the reward key relies on constructing and processing some internal message types. There are two rough edges I found with this.

  • The message type used (RewardCmd::CmdSetWallet iirc?) was not originally intended for this, it was borrowed from part of the ElderDuties processing flow. As such, the command only works cleanly with Elders. Trying to do otherwise would involve a bit more refactor that would make it hard to keep this branch up to date because of conflicts generated.
    * There’s no way to check the success or failure right now of commands before replying. Again, this could be refactored readily to make it work, but keeping the branch up to date until master is ready to start accept bigger patches again would became tedious and unstable.

To make mutator RPCs stable and reliable, I think it makes the most sense to PR a read-only version first. Then, it’ll be a little more tractable to work on mutators (and less-hacky infrastructure for them), in smaller chunks that risk fewer conflicts and generally ease the process.

Conclusion

For now, I’m only going to leave getters in, without the mutators. That is:

  • safe node rewards
  • safe node storage [--detailed]
  • safe node logs [--log-id=0] [--from-head] [--num-lines=10] [--offset=0]
  • safe node status

Hopefully later today/this week I’m thinking of setting up a PR draft in sn_node and/or sn_api to support this. They probably can’t be merged anytime soon due to the state of things (testnet coming up, stability focus, etc.) but I think it’s OK to slowly start the ball rolling on that.

There is that third repo sn_node_rpc_data_types that I set up, but for now I’ll just leave it there, but I suppose it would need to be transferred to an existing Safe repo or something eventually if the other changes end up being accepted.

3 Likes