NIS1に委任している状態でノードを再起動してみる検証

# 概要

非テック勢にとっても参考になるかと思い、NIS1に委任している状態でノードを落とすとどのような挙動になるのかを検証してみました。

# 環境

OS : CentOS8.3
アドレス : nis1.harvesting-sweet-potatoes.club
source : https://github.com/NemProject/nem-docker

# 事前準備

* NIS1ノードを構築する
* 最新まで同期しておく
* NEM Walletを用意する
* 既得バランスを10000XEM以上にしておく

# 作業内容

## ノードに委任する

ウォレットから委任する。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/20474/57856872-17f6-f1fb-7858-2621ac7fc862.png)

委任状況の確認。50枠のうち1枠委任されている状態。

``` bash
$ curl -s -X POST http://nis1.harvesting-sweet-potatoes.club:7890/account/unlocked/info | jq
================================================
{
  "max-unlocked": 50,
  "num-unlocked": 1
}
================================================
```

## サービス停止

``` bash
$ ./stop.sh
================================================
mynem_container
================================================

$ docker ps -a
================================================
CONTAINER ID IMAGE       COMMAND                 CREATED     STATUS              PORTS   NAMES
775283820f47 mynem_image "/usr/bin/supervisord"  11 days ago Exited (137) 27 seconds ago mynem_container
================================================
```

ハーベスティングが無効になる

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/20474/b6457203-94ad-5abf-a34a-4ccc28ef755f.png)


## サービス起動

``` bash
$ ./boot.sh
================================================
Sending build context to Docker daemon  131.6kB
Step 1/18 : FROM fedora:25
 ---> 9cffd21a45e3
...
chown: changing ownership of 'nem/nis-stderr.log.3': Operation not permitted
chown: changing ownership of 'nem/nis-stdout.log': Operation not permitted
chown: changing ownership of 'nem/nis-stderr.log.9': Operation not permitted
================================================

```

権限エラー対応

``` bash
$ sudo chown ftakao2007:ftakao2007 nem/nis-std*log*
$ ./boot.sh
================================================
Sending build context to Docker daemon  131.6kB
Step 1/18 : FROM fedora:25
 ---> 9cffd21a45e3
...
+ set +x
Starting NIS
unix:///etc/supervisor.sock no such file
All done, here are the services running:

ncc                              STOPPED   Not started
nis                              STOPPED   Not started
perms                            STARTING
servant                          STOPPED   Not started


--------------------------------------------------------------------------------
You can control both services named 'ncc' and 'nis' with the script ./service.sh
run ./service.sh without argument to get help

You can access the supervisord control shell with ./supervisorctl.sh
--------------------------------------------------------------------------------
================================================
```

nisが立ち上がっていないので別途起動

``` bash
$ ./service.sh start nis
================================================
nis: started
================================================

$ ./service.sh status
================================================
ncc                              STOPPED   Not started
nis                              RUNNING   pid 30, uptime 0:00:37
perms                            RUNNING   pid 21, uptime 0:01:39
servant                          STOPPED   Not started
================================================
```

## ノードの状況確認

height以外は同期が最新に追いつくまでは確認できない。

``` bash
$ curl -s http://nis1.harvesting-sweet-potatoes.club:7890/chain/height | jq
================================================
{
  "height": 777490
}
================================================

$ curl -s http://nis1.harvesting-sweet-potatoes.club:7890/node/info | jq
================================================
{
  "timeStamp": 211075996,
  "error": "Service Unavailable",
  "message": "NIS_ILLEGAL_STATE_LOADING_CHAIN",
  "status": 503
}
================================================

$ curl -s -X POST http://nis1.harvesting-sweet-potatoes.club:7890/account/unlocked/info | jq
================================================
{
  "timeStamp": 211075973,
  "error": "Service Unavailable",
  "message": "NIS_ILLEGAL_STATE_LOADING_CHAIN",
  "status": 503
}
================================================
```

2021/12/05現在およそ8時間で最新に追いつく。

``` bash
$ curl -s http://nis1.harvesting-sweet-potatoes.club:7890/chain/height | jq
================================================
{
  "height": 3487807
}
================================================

$ curl -s http://nis1.harvesting-sweet-potatoes.club:7890/node/info | jq
================================================
{
  "metaData": {
    "features": 1,
    "application": null,
    "networkId": 104,
    "version": "0.6.100",
    "platform": "Oracle Corporation (1.8.0_151) on Linux"
  },
  "endpoint": {
    "protocol": "http",
    "port": 7890,
    "host": "nis1.harvesting-sweet-potatoes.club"
  },
  "identity": {
    "name": "Fukui",
    "public-key": "c72c3b5bcdd5d9e2d3bd43bd5ef5ac0d42d03bf924713948e6ebbd80c3f8beb8"
  }
}
================================================

$ curl -s -X POST http://nis1.harvesting-sweet-potatoes.club:7890/account/unlocked/info | jq
================================================
{
  "max-unlocked": 50,
  "num-unlocked": 0
}
================================================
```

ウォレットを確認。最新に追いついてもハーベスティングは無効のまま。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/20474/2d19146e-1333-2927-2704-49c5b357e2be.png)

以上、NIS1は自動的に委任復旧しないというあたりまえ体操でした。