Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: more idiomatic CLI interface for mock network #6897

Merged
merged 3 commits into from
May 31, 2022

Conversation

matklad
Copy link
Contributor

@matklad matklad commented May 27, 2022

  • use kebab-case rather than snake-case
  • replace mode argument with custom syntax with a pair of
    • --client-height
    • --network-height
  • use convention-over-configuration for the binary name

These are mostly inconsequential cleanups which I am not feeling particularly strongly about specifically. I do feel moderately strongly about the overall point of sticking to conventions, defaults, and trying to leverage existing functionality instead of implementing custom logic :)

Comment on lines -62 to +78
client_start_height: Option<BlockHeight>,
/// If specified, the binary will set up client home dir before starting the
/// client node so head of the client chain will be the specified height
/// when the client starts. The given height must be the last block in an
/// epoch.
#[clap(long, default_value = "0")]
client_height: BlockHeight,
/// The height at which the mock network starts. The client would have to
/// catch up to this height before participating in new block production.
///
/// Defaults to the largest height in history.
#[clap(long)]
network_height: Option<BlockHeight>,
/// Shortcut to set both `--client-height` and `--network-height`.
#[clap(long, conflicts_with_all(&["client-height", "network-height"]))]
start_height: Option<BlockHeight>,
/// Target height that the client should sync to before stopping. If not specified,
/// use the height of the last block in chain history
#[clap(short = 'h', long)]
#[clap(long)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I intentionally left out short options from here. They are an anti-pattern: for rarely used utilities, the reader can benefit a lot from seeing --target-height 92 rather than -h 92

@@ -340,8 +305,8 @@ pub fn setup_mock_node(
}

#[cfg(test)]
mod test {
use crate::setup::{setup_mock_node, MockNetworkMode};
mod tests {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelo-gonzalez the idiomatic name here is tests, and one generally doesn't have to type it manually. There's tmod built-in snippet in both Clion and rust-analyzer which auto-comples to the whole stanza with cfg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your node and put the mock node's home dir there. See https://cloud.google.com/compute/docs/disks/add-persistent-disk
for how to attach and mount a new disk to an existing GCP node.
where the `node0` directory contains some pre-generated chain history in storage.
Ask [in Zulip](https://near.zulipchat.com/#narrow/stream/295558-pagoda.2Fcore) where to get example histories.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also mention the gzipped archives in benches/ :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, discovered those only after submitting the PR

responding to the client's network requests by reading from a pre-generated chain history
in storage.
```console
$ cargo run --release -p mock-net -- ~/.near/localnet/node0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/mock-net/mock-node/ and same for the other one below. also would be good to update the example commands in benches/README.md (s/mock_node/mock-node/)

@matklad matklad force-pushed the m/mock-cli branch 2 times, most recently from 32b45f2 to a2f33a0 Compare May 30, 2022 08:48
Once you have the source dir already set up, you can run the command without `-s`,
```bash
start_mock_node ~/.near ~/mock_node_home_dir -h 60926000 --mode "no_new_blocks"
Once you have the source dir already set up, you can run the command without `--`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really? so you could run it without passing any options?

I guess you still have to pass both directories, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it seems I just got distracted here, good catch!

of from genesis block. The following comment replays mainnet history from block height 60925880 to block height 60925900.

```console
$ cargo r -r -p mock-node -- ~/.near ~/mock_node_home_dir --client-height 60925880 --target-height 60925900
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I wonder what can we do so that people don't mix up the order of home_dirs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just not have the second working dir. The binary should transparently cache the stuff in target/mock-node/<block-hash>.

Should I create an issue for that? (As in, do we view this tool as a beginning of a long-term support infra, or is it just a temporary exploration?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create an issue for that.

the target/mock-node/XX might work locally - but we will be using this tool also on GCP (where usually SSD is mapped under a different dir)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- use kebab-case rather than snake-case
- replace mode argument with custom syntax with a pair of
  * --client-height
  * --network-height
- use convention-over-configuration for the binary name
@near-bulldozer near-bulldozer bot merged commit f70bfa7 into near:master May 31, 2022
@matklad matklad deleted the m/mock-cli branch May 31, 2022 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants