Bước 2. Đăng ký SPO làm Validator (block producer committee)

Điều kiện cần có

  • Bạn đang vận hành một SPO Cardano và đã chuẩn bị sẵn các key Cardano sau:
    1. Key cold.skey của SPO.
    2. Một UTXO hợp lệ cùng với payment.vkey và payment.skey đi kèm.
    3. MỚI: Đã hỗ trợ khóa Cardano mở rộng theo chuẩn BIP32-Ed25519!
  • Các dependency của partner-chain đã được đồng bộ hoàn toàn (Bước 1):
    1. Cổng (port) đến Ogmios và Postgres phải có thể truy cập được.

Mẹo Sẽ dễ dàng hơn nếu bạn thực hiện việc đăng ký trên cùng một máy chủ (instance) đang chạy các dependency của partner-chain. Đặc biệt nếu bạn đang sử dụng các file compose được cung cấp trong hướng dẫn này.

1. Cài đặt midnight-node

Midnight-node chứa các “trình hướng dẫn” (wizards) của Partner-chain CLI, giúp việc tương tác với các hợp đồng của Midnight Partner-chain, chẳng hạn như gửi đơn ứng cử làm nhà sản xuất block, trở nên dễ dàng hơn nhiều.

Lưu ý Ở giai đoạn hiện tại của dự án Midnight, midnight-node chỉ có sẵn dưới dạng Docker image.

Clone repository Midnight-node-docker (nếu cần):

Mẹo Nếu bạn đã clone repository midnight-node-docker ở (Bước 2), bạn có thể bỏ qua bước clone và sử dụng luôn instance đó.

git clone git@github.com:midnightntwrk/midnight-node-docker.git
cd midnight-node-docker

Khi bạn vừa vào thư mục, direnv sẽ hỏi bạn có cho phép sử dụng file .envrc hay không.

Sử dụng các trình hướng dẫn (wizards) của midnight-node:

Để gọi các trình hướng dẫn của Partner-chains CLI, bạn cần một file trong thư mục hiện tại tên là pc-chain-config.json. File này nằm trong repository midnight-node-docker tại đường dẫn envs/testnet-02/pc-chain-config.json. Nếu bạn đang sử dụng script midnight-node.sh, nó sẽ được tự động mount từ envs/testnet-02/pc-chain-config.json.

Gọi các trình hướng dẫn của Partner-chain bằng ./midnight-node:

./midnight-node.sh wizards --help
Kết quả trả về của /midnight-node.sh wizards –help
Partner Chains text "wizards" for setting up chain

Usage: midnight-node wizards <COMMAND>

Commands:
  generate-keys           This wizard generates the keys required for operating a partner-chains node,
                          stores them in the keystore directory, and prints the public keys and keystore
                          location
  prepare-configuration   Wizard to obtain the configuration needed for the partner-chain governance
                          authority. This configuration should be shared with chain participants and used
                          to create the chain spec json file
  create-chain-spec       Wizard for creating a chain spec json file based on the chain configuration (see
                          `prepare-configuration`)
  setup-main-chain-state  Wizard for setting D-parameter and Permissioned Candidates list on the main
                          chain. Uses 'chain config' obtained after running `prepare-configuration`
  start-node              Wizard for starting a substrate node in the environment set up by
                          `generate-keys`, `prepare-config`, and `create-chain-spec`. It also assits in
                          setting the `resources configuration`
  register1               The first step of registering as a committee candidate. Registration is split
                          into three steps to allow the user to use their cold keys on a cold machine
  register2               The second step of registering as a committee candidate, using cold keys
  register3               The final step of registering as a committee candidate, not using cold keys
  deregister              Deregister from the candidates set. This command requires chain config file
                          present in the running directory
  help                    Print this message or the help of the given subcommand(s)

Options:
  -h, --help
          Print help (see a summary with '-h')


╔════════════════════════════════════════════════════════════════════════════════╗
║                           Command groups by role                               ║
╠════════════════════════════════════════════════════════════════════════════════╣
║ The following sections outline the typical sequence of commands for each role. ║
║ The numbering indicates the recommended order of execution. Please note that   ║
║ this order may vary depending on specific deployment scenarios.                ║
╟────────────────────────────────────────────────────────────────────────────────╢
║ Governance Authority:                                                          ║
║   1. generate-keys         : generate necessary cryptographic keys             ║
║   2. prepare-configuration : set up the partner chain configuration            ║
║   3. create-chain-spec     : create the chain specification file               ║
║   4. setup-main-chain-state: configure the main chain parameters               ║
║   5. start-node            : start the validator node                          ║
╟────────────────────────────────────────────────────────────────────────────────╢
║ Registered Validator:                                                          ║
║   1. generate-keys         : generate validator keys                           ║
║   2. register1             : initiate the registration process                 ║
║   3. register2             : complete registration with cold keys              ║
║   4. register3             : finalize registration                             ║
║   5. start-node            : start the validator node                          ║
║   6. deregister            : cancel registration                               ║
║                                                                                ║
║   Note: This sequence assumes that the chain-spec.json and                     ║
║         pc-chain-config.json files have been obtained from                     ║
║         the Governance Authority and are present in the working directory.     ║
╟────────────────────────────────────────────────────────────────────────────────╢
║ Permissioned Validator:                                                        ║
║   1. generate-keys         : generate validator keys                           ║
║   2. start-node            : start the validator node                          ║
║                                                                                ║
║   Note: After executing 'generate-keys', the generated keys must be shared     ║
║         with the Governance Authority. The 'start-node' command can only be    ║
║         executed after the Governance Authority has established the partner    ║
║         chain on the main network. This sequence assumes that the              ║
║         chain-spec.json and pc-chain-config.json files have                    ║
║         been obtained from the Governance Authority and are present in the     ║
║         working directory.                                                     ║
╚════════════════════════════════════════════════════════════════════════════════╝

2. Tạo các key cho Partner-chain

Trong phần này, chúng ta sẽ dùng script midnight-shell.sh và gọi các lệnh wizards bên trong container.

Truy cập vào shell của midnight-node:

./midnight-shell.sh

Lệnh này sẽ mount thư mục ./data và đưa bạn vào bên trong container của midnight-node, nơi bạn có thể chạy các lệnh của midnight-node.

Ví dụ:

$ ./midnight-shell.sh
root@dcb8af95f166:/#

Trong ví dụ trên, dcb8af95f166 là ID container của midnight-node. Bạn có thể vào container bằng script midnight-shell.sh hoặc theo cách truyền thống hơn là dùng các lệnh của docker:

# Liệt kê container midnight-node và "container ID" của nó
docker container list -la
# Vào shell của container bằng ID
docker exec -it <container-id> /bin/bash
# Ví dụ: vào container "dcb8af95f166"
docker exec -it dcb /bin/bash

Tạo các key cho Partner-chain

QUAN TRỌNG Chuỗi lệnh sau đây được thực hiện BÊN TRONG container của midnight-node. Hãy chắc chắn bạn đang chạy ./midnight-node trong container.

Gọi lệnh ./midnight-node wizards generate-keys và làm theo hướng dẫn:

(Đây là ví dụ về kết quả trả về của generate-keys)
./midnight-node wizards generate-keys
This 🧙 wizard will generate the following keys and save them to your node's keystore:
→  an ECDSA Cross-chain key
→  an ED25519 Grandpa key
→  an SR25519 Aura key
It will also generate a network key for your node if needed.

> node base path ./data

⚙️ Generating Cross-chain (ecdsa) key
running external command: /midnight-node key generate --scheme ecdsa --output-type json
💾 Inserting Cross-chain (ecdsa) key
running external command: /midnight-node key insert --base-path ./data --scheme ecdsa --key-type crch --suri 'legend remain sting admit kidney language sun student reject robust depth umbrella'
💾 Cross-chain key stored at ./data/chains/partner_chains_template/keystore/637263680x0378769bcea3d597048bb874b3671ed7bfccc86f5aa92beeb615e5f2621602c592

⚙️ Generating Grandpa (ed25519) key
running external command: /midnight-node key generate --scheme ed25519 --output-type json
💾 Inserting Grandpa (ed25519) key
running external command: /midnight-node key insert --base-path ./data --scheme ed25519 --key-type gran --suri 'stairs lend book century actor course intact sell popular hero drastic humor'
💾 Grandpa key stored at ./data/chains/partner_chains_template/keystore/6772616e0x67b3161c75d23fbbbc29dae8b937bf0a57bf5c7c9ebdef9be4d297812ac86de8

⚙️ Generating Aura (sr25519) key
running external command: /midnight-node key generate --scheme sr25519 --output-type json
💾 Inserting Aura (sr25519) key
running external command: /midnight-node key insert --base-path ./data --scheme sr25519 --key-type aura --suri 'unknown benefit exclude odor accident ribbon pond reduce rebuild rally prepare core'
💾 Aura key stored at ./data/chains/partner_chains_template/keystore/617572610x149b37993c43c2d70b09c7c7af29b36a9809f2ee076d01c624693f05e3768634

🔑 The following public keys were generated and saved to the partner-chains-public-keys.json file:
{
  "sidechain_pub_key": "0x0378769bcea3d597048bb874b3671ed7bfccc86f5aa92beeb615e5f2621602c592",
  "aura_pub_key": "0x149b37993c43c2d70b09c7c7af29b36a9809f2ee076d01c624693f05e3768634",
  "grandpa_pub_key": "0x67b3161c75d23fbbbc29dae8b937bf0a57bf5c7c9ebdef9be4d297812ac86de8"
}
You may share them with your chain governance authority
if you wish to be included as a permissioned candidate.

⚙️ Generating network key
running external command: /midnight-node key generate-node-key --base-path ./data
command output: Generating key in "./data/chains/undeployed/network/secret_ed25519"
command output: 12D3KooWBAZC9CdRDPWB4trSfLJYDqqUVoZ3xFDcb2tF3M7vjL9F

🚀 All done!

Bây giờ, container sẽ có một cấu trúc thư mục data/ như sau:

data/
└── chains
    └── undeployed
        ├── keystore
        │   ├── 6175728281...# sidechain key
        │   ├── 63726367cd...# aura key
        │   └── 677a322ca6...# grandpa key
        └── network
            └── secret_ed25519 # network (node) key

Thư mục data/ này sẽ được sử dụng cho Midnight-node ở (Bước 3).

Chúng ta cần di chuyển các key từ thư mục chung của partner chains đến một keystore mà node của chúng ta có thể tìm thấy.

cp -r ./data/chains/undeployed/ ./data/chains/partner_chains_template

Cấu trúc file bây giờ sẽ trông như thế này:

data/
└── chains
    └── partner_chains_template
        ├── keystore
        │   ├── 6175728281...# sidechain key
        │   ├── 63726367cd...# aura key
        │   └── 677a322ca6...# grandpa key
        └── network
            └── secret_ed25519 # network (node) key

3. Đưa key Cardano vào container

Việc đăng ký sẽ được thực hiện trong container của midnight-node giống như bước generate-keys trước đó. Tuy nhiên, bây giờ là lúc thích hợp để đảm bảo các key Cardano cần thiết có thể được container truy cập.

Ví dụ, giả sử các key của bạn nằm trong thư mục cardano-keys. Thư mục này có thể được sao chép vào container bằng lệnh docker cp.

docker cp /path/to/cardano-keys/ <container-ID>:cardano-keys

Lệnh này sẽ đặt thư mục cardano-keys và nội dung của nó vào thư mục gốc của container midnight-node.

Ví dụ:

$ docker cp cardano-keys/ cb5:cardano-keys/
Successfully copied 49.2kB to cb5:cardano-keys/

$ docker exec -it cb5 /bin/bash

root@cb52f4691afd:/# ls
artifacts-amd64  data  lib               mnt                 res   srv  var
bin              dev   lib64             opt                 root  sys  version
boot             etc   media             pc-chain-config.json  run   tmp
cardano-keys     home  midnight-node  proc                sbin  usr

Để xóa thư mục này khỏi container:

docker exec <container-ID> rm -r cardano-keys/

4. Đăng ký làm ứng cử viên

Quá trình đăng ký gồm 3 lệnh. Bạn sẽ phải:

  1. Khởi tạo quá trình đăng ký.
  2. Chuẩn bị chữ ký đăng ký.
  3. Và cuối cùng là gửi đăng ký.

Chuỗi lệnh này được đơn giản hóa bằng các lệnh ./midnight-node wizards register1, register2 và register3.

QUAN TRỌNG Một lần nữa, hãy thực hiện chuỗi lệnh này trong container.

Gọi ./midnight-node wizards register1 và làm theo hướng dẫn:

Ví dụ đầu ra của register 1
./midnight-node wizards register1
⚙️ Registering as a committee candidate (step 1/3)
This wizard will query your UTXOs using address derived from the payment verification key and Ogmios service
> Ogmios protocol (http/https) http
> Ogmios hostname cardano-ogmios
> Ogmios port 1337
> path to the payment verification file priv/wallet/mywallet/payment.vkey
⚙️ Querying UTXOs of addr_test1vz8jvjmn3zph7uj87nu6hdzkte7pwahjk4r864hug459ncsanyj7c from Ogmios at http://cardano-ogmios:1337...
> Select UTXO to use for registration d7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376#0 (2212383 lovelace)
Please do not spend this UTXO, it needs to be consumed by the registration transaction.

Run the following command to generate signatures on the next step. It has to be executed on the machine with your SPO cold signing key.

/midnight-node wizards register2 \
 --genesis-utxo 46876a2250ec0e523eccc30b0fc6d6fa55c61dd200b83140acaab291edeb0b11#0 \
 --registration-utxo d7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376#0 \
 --aura-pub-key 0x0a66c6e1ca29d332a3b1738471bb4f27d4425b3001bbc9003757c2213b40b508 \
 --grandpa-pub-key 0xca364cd1c9a63988d9da8adc5e336220ee93fc6b9d65bca280133a55e21dc5f1 \
 --sidechain-pub-key 0x03de3d4544b1789d22aae9b4ae24d9e85282a300f690f7c0a534434f7f62362153 \
 --sidechain-signature d03d7900805e9aeb465278ca2f67465521d8c2abc680a5650e85105f407825df75de19df6cc45bac92b66250ccd2b51e3d93922925aa7e09f3b0a3e53bf7763b

Lệnh register1 sẽ trả về lệnh register2 cho bạn. Bạn chỉ cần sao chép và dán lệnh này vào shell.

Sao chép và dán lệnh register2 được tạo ra từ register1:

Ví dụ về kết quả đầu ra của register2
/midnight-node wizards register2 \
 --genesis-utxo 46876a2250ec0e523eccc30b0fc6d6fa55c61dd200b83140acaab291edeb0b11#0 \
 --registration-utxo d7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376#0 \
 --aura-pub-key 0x0a66c6e1ca29d332a3b1738471bb4f27d4425b3001bbc9003757c2213b40b508 \
 --grandpa-pub-key 0xca364cd1c9a63988d9da8adc5e336220ee93fc6b9d65bca280133a55e21dc5f1 \
 --sidechain-pub-key 0x03de3d4544b1789d22aae9b4ae24d9e85282a300f690f7c0a534434f7f62362153 \
 --sidechain-signature d03d7900805e9aeb465278ca2f67465521d8c2abc680a5650e85105f407825df75de19df6cc45bac92b66250ccd2b51e3d93922925aa7e09f3b0a3e53bf7763b
⚙️ Register as a committee candidate (step 2/3)
  This command will use SPO cold signing key for signing the registration message.
> Path to mainchain signing key file priv/pool/WINTERGREENPOOL/cold.skey
To finish the registration process, run the following command on the machine with the partner chain dependencies running:

/midnight-node wizards register3 \
--genesis-utxo 46876a2250ec0e523eccc30b0fc6d6fa55c61dd200b83140acaab291edeb0b11#0 \
--registration-utxo d7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376#0 \
--aura-pub-key 0x0a66c6e1ca29d332a3b1738471bb4f27d4425b3001bbc9003757c2213b40b508 \
--grandpa-pub-key 0xca364cd1c9a63988d9da8adc5e336220ee93fc6b9d65bca280133a55e21dc5f1 \
--partner-chain-pub-key 0x03de3d4544b1789d22aae9b4ae24d9e85282a300f690f7c0a534434f7f62362153 \
--partner-chain-signature d03d7900805e9aeb465278ca2f67465521d8c2abc680a5650e85105f407825df75de19df6cc45bac92b66250ccd2b51e3d93922925aa7e09f3b0a3e53bf7763b \
--spo-public-key 7ca8511e4b96c6d443304753685ea89660212e556a2c3c903fb10c99df292a72 \
--spo-signature 019ec2205223ba0f47a26f3e732e2c00e623eb1af546339a36c8136a792d37c6f2d36e76efa03a401e0be6559488d94e09368257f19886be95f8496f56460803

Lệnh register2 sẽ trả về lệnh register3. Chỉ cần sao chép và dán lệnh này vào shell.

Sao chép và dán lệnh register3 và làm theo hướng dẫn để gửi đăng ký:

Ví dụ về kết quả đầu ra của register3

root@cb52f4691afd:/# /midnight-node wizards register3 \
–genesis-utxo 46876a2250ec0e523eccc30b0fc6d6fa55c61dd200b83140acaab291edeb0b11#0 \
–registration-utxo d7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376#0 \
–aura-pub-key 0x0a66c6e1ca29d332a3b1738471bb4f27d4425b3001bbc9003757c2213b40b508 \
–grandpa-pub-key 0xca364cd1c9a63988d9da8adc5e336220ee93fc6b9d65bca280133a55e21dc5f1 \
–partner-chain-pub-key 0x03de3d4544b1789d22aae9b4ae24d9e85282a300f690f7c0a534434f7f62362153 \
–partner-chain-signature d03d7900805e9aeb465278ca2f67465521d8c2abc680a5650e85105f407825df75de19df6cc45bac92b66250ccd2b51e3d93922925aa7e09f3b0a3e53bf7763b \
–spo-public-key 7ca8511e4b96c6d443304753685ea89660212e556a2c3c903fb10c99df292a72 \
–spo-signature 019ec2205223ba0f47a26f3e732e2c00e623eb1af546339a36c8136a792d37c6f2d36e76efa03a401e0be6559488d94e09368257f19886be95f8496f56460803
⚙️ Register as a committee candidate (step 3/3)
This command will submit the registration message to the mainchain.
To proceed with the next command, a payment signing key is required. Please note that this key will not be stored or communicated over the network.

Path to mainchain payment signing key file priv/wallet/mywallet/payment.skey
Partner Chains Smart Contracts require access to Ogmios. Please provide its configuration.
Ogmios protocol (http/https) http
Ogmios hostname cardano-ogmios
Ogmios port 1337
2025-05-20T03:48:25.486387217+00:00 INFO partner_chains_cardano_offchain::register – ✅ Transaction submitted. ID: ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7
2025-05-20T03:48:25.486403409+00:00 INFO partner_chains_cardano_offchain::await_tx – Probing for transaction output ‘ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7#0’
2025-05-20T03:48:30.492834563+00:00 INFO partner_chains_cardano_offchain::await_tx – Probing for transaction output ‘ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7#0’
2025-05-20T03:48:35.497173351+00:00 INFO partner_chains_cardano_offchain::await_tx – Probing for transaction output ‘ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7#0’
2025-05-20T03:48:40.501445961+00:00 INFO partner_chains_cardano_offchain::await_tx – Probing for transaction output ‘ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7#0’
2025-05-20T03:48:40.504456587+00:00 INFO partner_chains_cardano_offchain::await_tx – Transaction output ‘ed829260c23f079a96dac6e6f4c48bf187066826c9d812fb87c6c9a9b7a832e7’
Show registration status? Yes
The registration status will be queried from a db-sync instance for which a valid connection string is required. Please note that this db-sync instance needs to be up and synced with the main chain.
DB-Sync Postgres connection string postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB
Registrations status for epoch 940:

Cảnh báo Có một lỗi đã biết với lệnh register3 khi truy vấn postgres, nhưng đừng lo, việc đăng ký đã thành công và có thể được xác thực bằng cách truy vấn ở bước tiếp theo.

Sau khi đăng ký, hãy truy vấn epoch hiện tại:

curl -L -X POST -H "Content-Type: application/json" -d '{
      "jsonrpc": "2.0",
      "method": "sidechain_getStatus",
      "params": [],
      "id": 1
    }' https://rpc.testnet-02.midnight.network | jq

Ví dụ kết quả:

{
  "jsonrpc": "2.0",
  "result": {
    "sidechain": {
      "epoch": 239830,
      "slot": 287797102,
      "nextEpochTimestamp": 1726783200000
    },
    "mainchain": {
      "epoch": 695,
      "slot": 60126536,
      "nextEpochTimestamp": 1726790400000
    }
  },
  "id": 1
}

Truy vấn ủy ban validator cho n + 2 epochs sau.

curl -L -X POST -H "Content-Type: application/json" -d '{
      "jsonrpc": "2.0",
      "method": "sidechain_getAriadneParameters",
      "params": [697],
      "id": 1
    }' https://rpc.testnet-02.midnight.network | jq

Tìm đăng ký của bạn dưới mục candidateRegistrations. Đảm bảo bạn thấy các key Partner-chain của mình trong đăng ký và isValid là true.

🥳 Đến đây, bạn đã đăng ký thành công làm validator! Bây giờ, đã đến lúc chạy một midnight-node ở chế độ validator để tạo ra các block Midnight.

Hủy đăng ký (Deregister)

Việc hủy đăng ký có thể được thực hiện bằng cách gọi midnight-node wizards deregister. Lệnh này nên được thực hiện trong container có quyền truy cập vào các key đã sử dụng khi đăng ký.

  1. Truy cập vào container của midnight-node.
  2. Gọi midnight-node wizards deregister và làm theo hướng dẫn.

Ví dụ:

root@cb52f4691afd:/# ./midnight-node wizards deregister
This wizard will remove the specified candidate from the committee candidates based on the following chain parameters:
...
...
...
INFO partner_chains_cardano_offchain::await_tx - Transaction output 'd7ebd0b5f215ede15d25fc00c5e9fbfb24b36ffdf428f93fc83cde84440be376'

Việc hủy đăng ký sẽ xóa ứng cử viên khỏi ủy ban sau n + 2 epochs.

Truy vấn ủy ban validator sau n + 2 epochs kể từ khi gửi yêu cầu hủy đăng ký:

curl -L -X POST -H "Content-Type: application/json" -d '{
      "jsonrpc": "2.0",
      "method": "sidechain_getAriadneParameters",
      "params": [INSERT_EPOCH],
      "id": 1
    }' https://rpc.testnet-02.midnight.network | jq

Bạn sẽ thấy ứng cử viên của mình không còn trong danh sách nữa.

Nguồn: MidnightDocs

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Nội dung