# 遅れた相手のノードを見張る

> Participant NodeのAdmin APIで、commitmentの遅れた相手を見張る設定を読み書きし、遅れの周期数と処理中の件数を調べ、時刻に対応するoffsetを求める5つのRPCを追います。

- URL: https://cardene.dev/diagrams/canton-slow-counter-participants
- 公開日: 2026-11-23
- 更新日: 2026-11-23
- トピック: Blockchain
- タグ: Canton
- 親の図解: [ACS commitmentとpruning](https://cardene.dev/diagrams/canton-commitment-and-pruning.md): Participant NodeのAdmin APIで、ACS commitmentの点検と遅れた相手の見張り、安全なoffsetまでのpruning、pruningの予定の設定を、gRPCでどう呼ぶかを4頁で追います。

頁「commitmentの遅れに対処する」では、遅れた相手のParticipant Nodeを、Canton Consoleのコマンドで見つけ、遅い相手のmetricの設定を変えました。
この頁は、同じ目的に使うAdmin APIのRPCを、要求と応答の欄で追います。
前の頁「相手とのcommitmentを点検する」が追った4つのRPCと、同じ`ParticipantInspectionService`の、残りの5つです。
RPCは、ネットワーク越しに、別のプログラムの処理を呼び出す操作で、gRPCで呼びます。

:::details gRPC
gRPCは、Googleが開発した、ネットワーク越しに別のプログラムの処理を呼び出すための通信の仕組みです。
:::

https://cardene.dev/diagrams/canton-pn-commitments

遅れた相手の見つけ方と、遅い相手のmetricの設定は、頁「commitmentの遅れに対処する」が追っています。

https://cardene.dev/diagrams/canton-acs-commitment-delays

offsetは、頁「台帳を手でpruningする」が`find_safe_offset`と`get_offset_by_time`で見ました。

https://cardene.dev/diagrams/canton-participant-pruning

## 5つのRPCの欄を見る

`ParticipantInspectionService`の9つの操作のうち、この頁が追う5つは、どれもクライアントからもサーバーからも、続けて何度もデータを送るストリーミングを使いません。
次の表は、5つのRPCのパスと、要求と応答のメッセージです。

| RPC | パス | 要求と応答のメッセージ |
|---|---|---|
| `GetConfigForSlowCounterParticipants` | `/com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/GetConfigForSlowCounterParticipants` | `GetConfigForSlowCounterParticipantsRequest`と`GetConfigForSlowCounterParticipantsResponse` |
| `SetConfigForSlowCounterParticipants` | `/com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/SetConfigForSlowCounterParticipants` | `SetConfigForSlowCounterParticipantsRequest`と`SetConfigForSlowCounterParticipantsResponse` |
| `GetIntervalsBehindForCounterParticipants` | `/com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/GetIntervalsBehindForCounterParticipants` | `GetIntervalsBehindForCounterParticipantsRequest`と`GetIntervalsBehindForCounterParticipantsResponse` |
| `CountInFlight` | `/com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/CountInFlight` | `CountInFlightRequest`と`CountInFlightResponse` |
| `LookupOffsetByTime` | `/com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/LookupOffsetByTime` | `LookupOffsetByTimeRequest`と`LookupOffsetByTimeResponse` |

図Aは、中央に`ParticipantInspectionService`を置き、5つのRPCと、それぞれの要求と応答の欄を足します。
段1が5つのRPCを置き、段2が設定を読むRPCの欄を、段3が設定を書くRPCの欄を足します。
段4が遅れの周期数を調べるRPCの欄を、段5が処理中の件数を数えるRPCと、時刻に対応するoffsetを調べるRPCの欄を足します。
図Aの欄の字は、要求と応答のどちらの欄かを先頭の語で示し、欄が持つ値を短い日本語で書きます。

```dragon
mind 遅れた相手を見張る5つのRPCの欄

step 5つのRPC
  say 1つのサービスに、遅れた相手の見張りに使う5つのRPCが入ります。
  idea root as "ParticipantInspectionService" [color: slate]
  idea gc as "GetConfigForSlowCounterParticipants" of root [color: blue]
  idea sc as "SetConfigForSlowCounterParticipants" of root [color: blue]
  idea gi as "GetIntervalsBehindForCounterParticipants" of root [color: blue]
  idea cf as "CountInFlight" of root [color: blue]
  idea lo as "LookupOffsetByTime" of root [color: blue]
  source CantonのParticipantInspectionService [url: https://docs.canton.network/reference/admin-api/protobuf/packages/com-digitalasset-canton-admin-participant-v30]

step 設定を読むRPCの欄
  say 設定を読むRPCは、SynchronizerのIDの並びを受け取り、設定の並びを返します。
  idea gc1 as "要求のSynchronizerのIDの列" of gc [color: blue]
  idea gc2 as "応答の設定の並び" of gc [color: blue]
  source CantonのGetConfigForSlowCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getconfigforslowcounterparticipants]

step 設定を書くRPCの欄
  say 設定を書くRPCは、設定の並びを受け取り、欄の無い応答を返します。
  idea sc1 as "要求の設定の並び" of sc [color: blue]
  idea sc2 as "応答は欄なし" of sc [color: blue]
  source CantonのSetConfigForSlowCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/setconfigforslowcounterparticipants]

step 遅れの周期数を調べるRPCの欄
  say 遅れの周期数を調べるRPCは、3つの欄の要求を受け取り、遅れの並びを返します。
  idea gi1 as "要求の相手のIDの列" of gi [color: blue]
  idea gi2 as "要求のSynchronizerのIDの列" of gi [color: blue]
  idea gi3 as "要求の閾値" of gi [color: blue]
  idea gi4 as "応答の遅れの並び" of gi [color: blue]
  source CantonのGetIntervalsBehindForCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getintervalsbehindforcounterparticipants]

step 件数とoffsetのRPCの欄
  say 件数を数えるRPCはSynchronizerのIDを受け取り、処理中の送信の要求の数と、処理中のトランザクションの数の2つの件数を返します。時刻に対応するoffsetを調べるRPCは時刻を受け取ってoffsetを返し、該当するoffsetが無い時は、offsetの欄が入りません。
  idea cf1 as "要求のSynchronizerのID" of cf [color: blue]
  idea cf2 as "応答の処理中の送信の要求の数" of cf [color: blue]
  idea cf3 as "応答の処理中のトランザクションの数" of cf [color: blue]
  idea lo1 as "要求の時刻" of lo [color: blue]
  idea lo2 as "応答の台帳のoffsetか欄なし" of lo [color: blue]
  source CantonのCountInFlight [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/countinflight]
  source CantonのLookupOffsetByTime [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/lookupoffsetbytime]
```

## 遅れた相手の設定を読み書きする

設定を読む`GetConfigForSlowCounterParticipants`は、`synchronizer_ids`を受け取り、遅れた相手のParticipant Nodeについての設定の並び`configs`を返します。
設定を書く`SetConfigForSlowCounterParticipants`は、同じ型の設定の並び`configs`を受け取り、欄を持たない応答を返します。
列は、Protobufの定義で`repeated`と書かれた、同じ型の値を並べた欄です。

:::details Protobuf
Protobufは、Protocol Buffersの略で、Googleが開発した、データを決まった形式のバイト列に変換してやり取りするための仕組みです。
送るデータの形を先に定義しておき、その定義から送る側と受ける側のコードを作ります。
:::

設定の型は`SlowCounterParticipantSynchronizerConfig`で、5つの欄を持ちます。
uint64は、0以上の64ビットの整数の型です。

| 欄 | 型 | 持つ物 |
|---|---|---|
| `synchronizer_ids` | 文字列の列 | 設定を適用するSynchronizerのID |
| `distinguished_participant_uids` | 文字列の列 | 区別して扱う相手のParticipant NodeのID |
| `threshold_distinguished` | uint64 | 区別して扱う相手を、遅いとみなす周期数 |
| `threshold_default` | uint64 | 区別して扱う相手に入らない全ての相手を、遅いとみなす周期数 |
| `participant_uids_metrics` | 文字列の列 | 相手ごとに、遅れの周期数を別のmetricで出す相手のID |

区別して扱う相手に入らない全ての相手は、自動でdefaultの相手になります。
設定を書く時は、2つの閾値は新しい値で上書きされ、`distinguished_participant_uids`と`participant_uids_metrics`の2つの一覧は、既にある設定に追加されます。
読むRPCの応答の`configs`と、書くRPCの要求の`configs`は、同じ型の並びです。
Canton Consoleのコマンドでの設定の意味は、頁「commitmentの遅れに対処する」の表が追っています。

## 遅れの周期数を調べる

`GetIntervalsBehindForCounterParticipants`は、相手のParticipant NodeのIDの列`counter_participant_ids`と、SynchronizerのIDの列`synchronizer_ids`と、uint64の閾値`threshold`を受け取ります。
相手のIDの列が空の時は全ての相手を、SynchronizerのIDの列が空の時は全てのSynchronizerを調べます。
`threshold`は省くことができ、相手のIDの列が空の時に、遅れの周期数を閾値で絞り込みます。
相手のIDを指定した時は、指定した相手の遅れが返ります。

応答は、`CounterParticipantInfo`の列`intervals_behind`です。
次の表は、`CounterParticipantInfo`の5つの欄です。

| 欄 | 型 | 持つ物 |
|---|---|---|
| `counter_participant_uid` | 文字列 | 相手のParticipant NodeのID |
| `synchronizer_id` | 文字列 | SynchronizerのID |
| `intervals_behind` | uint64 | 遅れた周期の数 |
| `behind_since` | Duration | commitmentの遅れに相当する時間 |
| `as_of_sequencing_timestamp` | Timestamp | この情報を取得した時点を示す、sequencing timeの時刻 |

Durationは時間の長さを表す型で、Timestampは時刻の型です。
sequencing timeは、Sequencerが要求のバッチに順番を付ける時に付けるタイムスタンプで、record timeとも呼びます。
遅れの数え方と、一度もcommitmentを送らない相手の表示は、頁「commitmentの遅れに対処する」が追っています。

`grpcurl`は、gRPCのサーバーのRPCを、JSONで呼び出すための道具です。
`grpcurl`の例は、`counterParticipantIds`と`synchronizerIds`と`threshold`を送ります。
JSONの欄の名前は、protoの欄の名前をcamelCaseにした形です。
camelCaseは、単語をつなぎ、2つ目からの単語の頭を大文字にする書き方です。

:::details JSON
JSONは、データを文字で表すための形式で、Webのプログラムどうしのデータのやり取りに広く使われています。
:::

接続先のホスト名とポートをコロンでつないだ値を、シェルの変数`HOST_PORT`に設定します。
例では、変数を引用符で囲んで渡し、TLSを使わないサーバーを呼ぶ時は、`-plaintext`を足します。

:::details TLS
TLSは、ネットワークの通信を暗号化し、通信の相手が本物かを証明書で確かめるための規格です。
WebサイトのHTTPSの通信も、TLSを使っています。
:::

次の例は、1つの相手とSynchronizerを指定して、遅れの周期数を調べます。
山括弧で囲んだ2つの値は、手元の相手のParticipant NodeのIDとSynchronizerのIDに差し替える欄です。
`threshold`の`"0"`は、資料の例の値で、絞り込みに使いたい周期数に差し替えます。

```bash
# Add -plaintext if the server is not using TLS.
grpcurl \
  -d @ \
  "$HOST_PORT" \
  com.digitalasset.canton.admin.participant.v30.ParticipantInspectionService/GetIntervalsBehindForCounterParticipants <<'EOF'
{
  "counterParticipantIds": [
    "<COUNTER_PARTICIPANT_ID>"
  ],
  "synchronizerIds": [
    "<SYNCHRONIZER_ID>"
  ],
  "threshold": "0"
}
EOF
```

uint64とint64は、JSONでは十進数の文字列で表されます。
OKの応答の例は、`intervalsBehind`の配列で、各要素が`counterParticipantUid`と`synchronizerId`と`intervalsBehind`と`behindSince`と`asOfSequencingTimestamp`を持ちます。

## 処理中の件数と時刻に対応するoffset

`CountInFlight`は、文字列の`synchronizer_id`を受け取り、処理中の送信の要求の数`pending_submissions`と、処理中のトランザクションの数`pending_transactions`を返します。
どちらもuint32で、JSONの例では数のまま表されます。
uint32は、0以上の32ビットの整数の型です。

`LookupOffsetByTime`は、Timestampの`timestamp`を受け取り、指定した時刻以前に処理した最大の台帳のoffsetを、int64の`offset`で返します。
`offset`は省ける欄で、該当するoffsetが無い時は、応答に入りません。
int64は、64ビットの符号付きの整数の型です。

次の表は、2つのRPCの例の要求と応答です。
`<SYNCHRONIZER_ID>`は、手元のSynchronizerのIDに差し替える欄で、時刻は、年月日と時刻とタイムゾーンを並べた形の例です。
応答の`0`と`"0"`は、資料の例の値で、実際の件数とoffsetではありません。

| RPC | 例の要求 | 例の応答 |
|---|---|---|
| `CountInFlight` | `{"synchronizerId": "<SYNCHRONIZER_ID>"}` | `{"pendingSubmissions": 0, "pendingTransactions": 0}` |
| `LookupOffsetByTime` | `{"timestamp": "2026-01-01T00:00:00Z"}` | `{"offset": "0"}` |

## 5つのRPCの要求と応答

図Bは、呼び出す側とParticipant NodeのAdmin APIの2つの箱で、5つのRPCの要求と応答を、1つのRPCにつき1つの段で追います。
呼び出す側は、例の`grpcurl`です。
この図では、5つのRPCを呼ぶ順を示しません。
どの段も、別の呼び出しの始まりです。

```dragon
sequence 遅れた相手の設定と遅れの周期数と件数とoffsetを調べる

box G as 呼び出す側 [note: gRPCの呼び出しを送る, color: slate, icon: exe]
box S as Participant NodeのAdmin API [note: ホスト名とポートで指定する, color: rose, icon: server]

step 設定を読む
  say 設定を読むRPCは、SynchronizerのIDの並びを送り、設定の並びを受け取ります。
  G -> S: SynchronizerのIDの列
  S -> G: 設定の並び
  source CantonのGetConfigForSlowCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getconfigforslowcounterparticipants]

step 設定を書く
  say 設定を書くRPCは、設定の並びを送り、欄の無い応答を受け取ります。
  G -> S: 設定の並び
  S -> G: 空の応答
  source CantonのSetConfigForSlowCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/setconfigforslowcounterparticipants]

step 遅れの周期数を調べる
  say 遅れの周期数を調べるRPCは、相手のIDの列とSynchronizerのIDの列と閾値を送り、遅れの並びを受け取ります。
  G -> S: 相手とSynchronizerのIDの列と閾値
  S -> G: 遅れの並び
  source CantonのGetIntervalsBehindForCounterParticipants [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getintervalsbehindforcounterparticipants]

step 処理中の件数を数える
  say 件数を数えるRPCは、SynchronizerのIDを送り、処理中の送信の要求の数と、トランザクションの数を受け取ります。
  G -> S: SynchronizerのID
  S -> G: 2つの件数
  source CantonのCountInFlight [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/countinflight]

step 時刻に対応するoffsetを調べる
  say 時刻に対応するoffsetを調べるRPCは、時刻を送り、台帳のoffsetを受け取ります。該当するoffsetが無い時は、offsetの欄が入りません。
  G -> S: 時刻
  S -> G: 台帳のoffsetか欄なし
  source CantonのLookupOffsetByTime [url: https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/lookupoffsetbytime]
```

## 次に読む頁

次の頁「安全なoffsetまでpruningする」は、`PruningService`の5つのRPCで、安全にpruningできるoffsetを求め、commitmentを待たない相手を決めて、pruningを今すぐ実行する呼び方を追います。

https://cardene.dev/diagrams/canton-pn-pruning

## 出典

https://docs.canton.network/reference/admin-api/protobuf/packages/com-digitalasset-canton-admin-participant-v30

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getconfigforslowcounterparticipants

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/setconfigforslowcounterparticipants

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/getintervalsbehindforcounterparticipants

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/countinflight

https://docs.canton.network/reference/admin-api/protobuf/operations/com-digitalasset-canton-admin-participant-v30/participantinspectionservice/lookupoffsetbytime
