0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Cosmos node構築(Stargate-3a)

Last updated at Posted at 2020-10-12

CosmosとはPOS系のブロックチェーンネットワークです。
https://cosmos.network/
今回はテストネット絶賛稼働中の、Stargate-3aのtestnetノードを構築したいと思います。

tl;dr

https://github.com/cosmosdevs/stargate#testnet を参考にして、gaiadをビルドしてstargate-3aの設定をして立ち上げています。

必要スペック

Golang 今回はanyenvにて1.15.2をインストールしておきました。

[murata@node-test gaia]$ go version
go version go1.15.2 linux/amd64

インストール

Git Clone

Cosmosのノードはgaiadと呼ばれます。(cosmos-sdkリポジトリからは独立したので注意)


[murata@node-test workspace]$ git clone git@github.com:cosmos/gaia.git
Cloning into 'gaia'...
Warning: Permanently added 'github.com,13.114.40.48' (RSA) to the list of known hosts.
remote: Enumerating objects: 2954, done.
remote: Total 2954 (delta 0), reused 0 (delta 0), pack-reused 2954
Receiving objects: 100% (2954/2954), 6.57 MiB | 4.68 MiB/s, done.
Resolving deltas: 100% (1741/1741), done.

ブランチ切り替え

まだリリースされているものではないので、stargate-3ブランチに切り替えます。


[murata@node-test gaia]$ git checkout stargate-3
Note: switching to 'stargate-3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 5f28583 Update to latest SDK stargate-3 branch

ビルド

ビルドします。


[murata@node-test gaia]$ make build
mkdir -p /home/murata/workspace/gaia/build
go build -mod=readonly -tags "netgo ledger" -ldflags '-X github.com/cosmos/cosmos-sdk/version.Name=gaia -X github.com/cosmos/cosmos-sdk/version.AppName=gaiad -X github.com/cosmos/cosmos-sdk/version.Version=stargate-3 -X github.com/cosmos/cosmos-sdk/version.Commit=5f28583b510a86fac671e4590d0863d56989735d -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger" -w -s' -trimpath -o /home/murata/workspace/gaia/build/ ./cmd/gaiad

buildディレクトリにgaiadが出来上がります。

[murata@node-test gaia]$ ll ./build/gaiad
-rwxrwxr-x 1 murata murata 39472352 Oct 12 16:00 ./build/gaiad

セットアップ

設定ファイル配置

gaiad initします。deroris-nodeのところは名前なのでなんでもOKです。



[murata@node-test gaia]$ ./build/gaiad init deroris-node
{"app_message":{"auth":{"accounts":[],"params":{"max_memo_characters":"256","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000","tx_sig_limit":"7","tx_size_cost_per_byte":"10"}},"bank":{"balances":[],"denom_metadata":[],"params":{"default_send_enabled":true,"send_enabled":[]},"supply":[]},"capability":{"index":"1","owners":[]},"crisis":{"constant_fee":{"amount":"1000","denom":"stake"}},"distribution":{"delegator_starting_infos":[],"delegator_withdraw_infos":[],"fee_pool":{"community_pool":[]},"outstanding_rewards":[],"params":{"base_proposer_reward":"0.010000000000000000","bonus_proposer_reward":"0.040000000000000000","community_tax":"0.020000000000000000","withdraw_addr_enabled":true},"previous_proposer":"","validator_accumulated_commissions":[],"validator_current_rewards":[],"validator_historical_rewards":[],"validator_slash_events":[]},"evidence":{"evidence":[]},"genutil":{"gen_txs":[]},"gov":{"deposit_params":{"max_deposit_period":"172800s","min_deposit":[{"amount":"10000000","denom":"stake"}]},"deposits":[],"proposals":[],"starting_proposal_id":"1","tally_params":{"quorum":"0.334000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"},"votes":[],"voting_params":{"voting_period":"172800s"}},"ibc":{"channel_genesis":{"ack_sequences":[],"acknowledgements":[],"channels":[],"commitments":[],"recv_sequences":[],"send_sequences":[]},"client_genesis":{"clients":[],"clients_consensus":[],"create_localhost":true},"connection_genesis":{"client_connection_paths":[],"connections":[]}},"mint":{"minter":{"annual_provisions":"0.000000000000000000","inflation":"0.130000000000000000"},"params":{"blocks_per_year":"6311520","goal_bonded":"0.670000000000000000","inflation_max":"0.200000000000000000","inflation_min":"0.070000000000000000","inflation_rate_change":"0.130000000000000000","mint_denom":"stake"}},"params":null,"slashing":{"missed_blocks":[],"params":{"downtime_jail_duration":"600s","min_signed_per_window":"0.500000000000000000","signed_blocks_window":"100","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.010000000000000000"},"signing_infos":[]},"staking":{"delegations":[],"exported":false,"last_total_power":"0","last_validator_powers":[],"params":{"bond_denom":"stake","historical_entries":100,"max_entries":7,"max_validators":100,"unbonding_time":"1814400s"},"redelegations":[],"unbonding_delegations":[],"validators":[]},"transfer":{"denom_traces":[],"params":{"receive_enabled":true,"send_enabled":true},"port_id":"transfer"},"upgrade":{}},"chain_id":"test-chain-Zklcq0","gentxs_dir":"","moniker":"deroris-node","node_id":"c41ae1d5fa4ea0c9b63441ccae26f959e2779efe"}

ホームディレクトリに.gaiadというディレクトリができて、下記のようなファイルが配置されます。


[murata@node-test ~]$ tree ~/.gaiad/
/home/murata/.gaiad/
|-- config
|   |-- app.toml
|   |-- config.toml
|   |-- genesis.json
|   |-- node_key.json
|   `-- priv_validator_key.json
`-- data
    `-- priv_validator_state.json

2 directories, 6 files

genesis.json配置

stargate用のgenesis.jsonを~/.gaiad/config/にDLします。


[murata@node-test ~]$ wget -O $HOME/.gaiad/config/genesis.json https://raw.githubusercontent.com/cosmosdevs/stargate/master/genesis.json
--2020-10-12 16:05:20--  https://raw.githubusercontent.com/cosmosdevs/stargate/master/genesis.json
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.64.133, 151.101.128.133, 151.101.192.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.64.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 24467 (24K) [text/plain]
Saving to: '/home/murata/.gaiad/config/genesis.json'

/home/murata/.gaiad/config/genesis.json                                100%[==========================================================================================================================================================================>]  23.89K  --.-KB/s    in 0.003s

2020-10-12 16:05:20 (8.42 MB/s) - '/home/murata/.gaiad/config/genesis.json' saved [24467/24467]

接続先ピアノード設定

~/.gaiad/config/config.toml のpersistent_peersを以下のようにします。 https://github.com/cosmosdevs/stargate#testnet に書いてある通り。

persistent_peers = "00d8e9c0df367296436854b580d9b069d3f1a5fd@34.123.30.100:26656"

起動

リポジトリのディレクトリに戻ってgaiadを起動させます。


[murata@node-test gaia]$ ./build/gaiad start
I[2020-10-12|16:09:48.031] starting ABCI with Tendermint                module=main
I[2020-10-12|16:09:48.094] Starting StateSync service                   module=statesync impl=StateSync
I[2020-10-12|16:09:55.341] Executed block                               module=state height=1 validTxs=0 invalidTxs=0
I[2020-10-12|16:09:55.349] Committed state                              module=state height=1 txs=0 appHash=2439190541C407B09DE6EDC11FC4A178342322CE1212150F35F356375BCEA77B
I[2020-10-12|16:09:55.356] Executed block                               module=state height=2 validTxs=0 invalidTxs=0
I[2020-10-12|16:09:55.359] Committed state                              module=state height=2 txs=0 appHash=F1A51A781277143FCBBDD7FCD475BBD8CF03D0CA05CFEEEA78F51FFC63205CC1
I[2020-10-12|16:09:55.365] Executed block                               module=state height=3 validTxs=0 invalidTxs=0
I[2020-10-12|16:09:55.369] Committed state                              module=state height=3 txs=0 appHash=65461DA590AE440C53068501FD24C62BE9906F094DDBFC29750F0CFE9AD8D558

~~snip;

うまくいっていればログが伸びてheightがあがってくるはずです。
違うターミナルでstatusを見てみます。


[murata@node-test gaia]$ ./build/gaiad status | jq
{
  "node_info": {
    "protocol_version": {
      "p2p": "8",
      "block": "11",
      "app": "0"
    },
    "id": "c41ae1d5fa4ea0c9b63441ccae26f959e2779efe",
    "listen_addr": "tcp://0.0.0.0:26656",
    "network": "stargate-3a",
    "version": "0.34.0",
    "channels": "40202122233038606100",
    "moniker": "deroris-node",
    "other": {
      "tx_index": "on",
      "rpc_address": "tcp://127.0.0.1:26657"
    }
  },
  "sync_info": {
    "latest_block_hash": "694D79550B645839F23F87F289137F0B7F6DD2AFE750C9CFE82EC7B3C19F0391",
    "latest_app_hash": "F683583A314C88C78EA40B1624846F123028B35EACD67118AD51D89C0D513064",
    "latest_block_height": "2827",
    "latest_block_time": "2020-09-22T08:35:25.033801011Z",
    "earliest_block_hash": "8FB162A63255F57899BA3ED43A984552E738B182969A98533C9C0DA286974CF0",
    "earliest_app_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
    "earliest_block_height": "1",
    "earliest_block_time": "2020-09-19T05:27:12.058669Z",
    "catching_up": true
  },
  "validator_info": {
    "address": "7F6E5F0F0DF61152D44C3A0AEE7FA3FCBABF8EFD",
    "pub_key": {
      "type": "tendermint/PubKeyEd25519",
      "value": "jJQgJcRpvmrINtGE4IoUIGO/YOefNMokfu765tNW6hs="
    },
    "voting_power": "0"
  }
}

ちゃんと取れますね。

gaia-cliバイナリは同梱されていないみたいです。gaiadに内包されたのかな。
鍵追加もgaiadでできました。

[murata@node-test gaia]$ ./build/gaiad keys add pepecash
Enter keyring passphrase:
Re-enter keyring passphrase:

- name: pepecash
  type: local
  address: cosmos1046aehs0xvqdl282c7rs8fu9x2x9ucgenekvpe
  pubkey: cosmospub1addwnpepqdqxtwfw8gw0ryhfl9sq5ndvmmckry5yx75ekycklff2xn52l22zgdvppq2
  mnemonic: ""
  threshold: 0
  pubkeys: []


**Important** write this mnemonic phrase in a safe place.

**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.

wrap slow virtual bus drop crisp you yellow awesome hero energy hedgehog scorpion purpose result please steak bid dignity hotel forest satoshi normal deer

※これはすぐ消す&テストネットだからいいものの、ニーモニックはバレてはだめですよ。約束だ。

ステーキング確認

別ユーザー作ってデリゲーション確認。

Explorer https://stargate.bigdipper.live/

Amount確認(Discordとか入って誰かにもらう。


[murata@node-test gaia]$ ./build/gaiad query bank balances cosmos1r9ku3d79uduwqa5rl6khq2893rjy24dfcppcjv
balances:
- amount: "10000000"
  denom: umuon
pagination:
  next_key: null
  total: "0"

適当なバリデータにステーキング


[murata@node-test gaia]$ ./build/gaiad tx staking delegate cosmosvaloper10fyfu7fl78f88a7zhcwu72wk3hjlzdm85sh6f9 5000000umuon --from derori --chain-id stargate-3a
Enter keyring passphrase:[murata@node-test gaia]$ ./build/gaiad tx staking delegate cosmosvaloper10fyfu7fl78f88a7zhcwu72wk3hjlzdm85sh6f9 5000000umuon --from derori --chain-id stargate-3a | jq
Enter keyring passphrase:
{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate","delegator_address":"cosmos1r9ku3d79uduwqa5rl6khq2893rjy24dfcppcjv","validator_address":"cosmosvaloper10fyfu7fl78f88a7zhcwu72wk3hjlzdm85sh6f9","amount":{"denom":"umuon","amount":"5000000"}}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000"}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
{
  "height": "313002",
  "txhash": "C4252655F9531755D6B0C529584151B316215E960D11CB7AFA77E7D6CEE6682A",
  "codespace": "",
  "code": 0,
  "data": "0A0A0A0864656C6567617465",
  "raw_log": "[{\"events\":[{\"type\":\"delegate\",\"attributes\":[{\"key\":\"validator\",\"value\":\"cosmosvaloper10fyfu7fl78f88a7zhcwu72wk3hjlzdm85sh6f9\"},{\"key\":\"amount\",\"value\":\"5000000\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"delegate\"},{\"key\":\"module\",\"value\":\"staking\"},{\"key\":\"sender\",\"value\":\"cosmos1r9ku3d79uduwqa5rl6khq2893rjy24dfcppcjv\"}]}]}]",
  "logs": [
    {
      "msg_index": 0,
      "log": "",
      "events": [
        {
          "type": "delegate",
          "attributes": [
            {
              "key": "validator",
              "value": "cosmosvaloper10fyfu7fl78f88a7zhcwu72wk3hjlzdm85sh6f9"
            },
            {
              "key": "amount",
              "value": "5000000"
            }
          ]
        },
        {
          "type": "message",
          "attributes": [
            {
              "key": "action",
              "value": "delegate"
            },
            {
              "key": "module",
              "value": "staking"
            },
            {
              "key": "sender",
              "value": "cosmos1r9ku3d79uduwqa5rl6khq2893rjy24dfcppcjv"
            }
          ]
        }
      ]
    }
  ],
  "info": "",
  "gas_wanted": "200000",
  "gas_used": "110322",
  "tx": null,
  "timestamp": ""
}

はいった^^

https://stargate.bigdipper.live/validator/C32E7448571BC4B7D65FCCFE3991AB7E89A0F707
image.png

まとめ

特に何事もなく公式通りなのでポストするか迷いましたが、せっかく書いたので置いておきます。誰かのお役に立ちますように。
バグバウンティやってるみたいなので、参加できる方はぜひ。(そういう人はこんなところ見ないかw

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?