Grinnode-live / 2020-grin-bug-bash-challenge

Finding bugs in Grin-Wallet & Grin-nodes for a bounty prior to Grin fork v5.
3 stars 1 forks source link

[GRIN-Node][Owner API 2.0] test the get_connected_peers API method #53

Closed marekyggdrasil closed 3 years ago

marekyggdrasil commented 3 years ago

Description Goal of this issue is to test the get_connected_peers API method

Prerequisites

  1. GRIN-Node

Test procedure

  1. Run GRIN-Node in Owner API listener mode
  2. Run the get_connected_peers API method

Expected result:

Output should match the example. Include all cURL requests and responses.

Include the exact version of your grin-node and also your environment

uname -a
goyle commented 3 years ago

Description

Goal of this issue is to test the get_connected_peers API method.

Prerequisites

  1. GRIN-Node

Test Procedure

  1. Run GRIN-Node in Owner API listener mode.
  2. Run the get_connected_peers API method.

Expected Result

Output should match the example. Include all cURL requests and responses.

Dropdown of the example output. ```json { "jsonrpc": "2.0", "method": "get_connected_peers", "params": [], "id": 1 } { "id": 1, "jsonrpc": "2.0", "result": { "Ok": [ { "addr": "35.176.195.242:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "47.97.198.21:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "148.251.16.13:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "68.195.18.155:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "52.53.221.15:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 0, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "109.74.202.16:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "121.43.183.180:3414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 }, { "addr": "35.157.247.209:23414", "capabilities": { "bits": 15 }, "direction": "Outbound", "height": 374510, "total_difficulty": 1133954621205750, "user_agent": "MW/Grin 2.0.0", "version": 1 } ] } } ```


Include the exact version of your grin-node and also your environment.

uname -a

Environment

OS: Debian 10\ Grin Node: grin 5.0.0-rc.2 System Info: Linux debian3 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 GNU/Linux

Steps

1: Building the Node

See here for the full steps for building GRIN-Node v5.0.0-rc.2. 1. Download GRIN-Node v5.0.0-rc.2. ```shell $ wget https://github.com/mimblewimble/grin/archive/v5.0.0-rc.2.tar.gz ``` 1. Extract `v5.0.0-rc.2.tar.gz`. ```shell $ tar -xvf v5.0.0-rc.2.tar.gz ``` * Output should be as follows. ``` grin-5.0.0-rc.2/ grin-5.0.0-rc.2/.cargo/ grin-5.0.0-rc.2/.cargo/config grin-5.0.0-rc.2/.ci/ grin-5.0.0-rc.2/.ci/general-jobs grin-5.0.0-rc.2/.ci/release.yml grin-5.0.0-rc.2/.ci/test.yml grin-5.0.0-rc.2/.ci/windows-release.yml grin-5.0.0-rc.2/.editorconfig grin-5.0.0-rc.2/.github/ ... ``` 1. Install Rust. ```shell $ curl https://sh.rustup.rs -sSf | sh; source $HOME/.cargo/env ``` * Proceed with installation with default profile. ``` default host triple: x86_64-unknown-linux-gnu default toolchain: stable (default) profile: default modify PATH variable: yes ``` * Output should be as follows. ``` stable-x86_64-unknown-linux-gnu installed - rustc 1.48.0 (7eac88abb 2020-11-16) ``` 1. Download dependencies, including `libcursesw5`. ```shell # apt install build-essential git tor cmake git libgit2-dev clang libncursesw5 libncurses5-dev libncursesw5-dev zlib1g-dev pkg-config libssl-dev llvm ``` 1. Build GRIN-Node v5.0.0-rc.2. ```shell $ cd grin-5.0.0-rc.2/ $ cargo build --release ``` 1. Configure the node to save its logs and chain data in the current directory. This is optional and I did this for convenience and testing purposes. ``` $ cd target/release/ $ ./grin server config ``` * The output will be as follows. ``` grin-server.toml file configured and created in current directory ``` 1. If the previous step is done, enable DEBUG mode in `grin-server.toml`. ``` #log level for file: Error, Warning, Info, Debug, Trace file_log_level = "Debug" ``` 1. Start node. ``` $ ./grin ``` 1. Wait until Grin has fully synced. 1. Success!

2: Running GRIN-Node in Owner API Listener Mode

  1. Initialize the GRIN-Node. The node will start in the owner API listener mode by default.
    $ cd grin-5.0.0-rc.2/target/release/
    $ ./grin
  2. The TUI should now appear and your GRIN-Node will be running.

3: Testing the get_connected_peers API method

  1. Open a new terminal and run the following cURL command.
    $ curl localhost:3413/v2/owner -d '{"jsonrpc": "2.0", "method": "get_connected_peers", "params": [], "id": 1}' -w "\n"
  2. The output will appear as expected.

Final Results

Output of cURL Request

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "Ok": [
      {
        "addr": "176.9.86.219:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 5.0.0-rc.2",
        "version": 1000
      },
      {
        "addr": "47.97.218.157:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 4.1.1",
        "version": 1000
      },
      {
        "addr": "213.239.217.14:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 5.0.0-rc.2",
        "version": 1000
      },
      {
        "addr": "18.204.166.78:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 4.0.0",
        "version": 2
      },
      {
        "addr": "108.196.200.233:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 5.0.0-rc.1",
        "version": 1000
      },
      {
        "addr": "35.181.35.93:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 4.0.0",
        "version": 2
      },
      {
        "addr": "49.12.108.173:3414",
        "capabilities": {
          "bits": 15
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 4.1.1",
        "version": 1000
      },
      {
        "addr": "85.10.201.143:3414",
        "capabilities": {
          "bits": 31
        },
        "direction": "Outbound",
        "height": 1025939,
        "total_difficulty": 1738767380427710,
        "user_agent": "MW/Grin 5.0.0-rc.2",
        "version": 1000
      }
    ]
  }
}

Conclusion

No errors encountered. The actual results matches the expected results.

marekyggdrasil commented 3 years ago

Great work! Thanks @goyle !