# ノードを保守するRPCを使い分ける

> Participant Nodeのpruning、Ledger APIの版と機能、試験用の時刻、trafficのアカウントを扱う9つのRPCを、サービスごとのパスと要求と応答の欄で並べて使い分けます。

- URL: https://cardene.dev/diagrams/canton-grpc-node-ops
- 公開日: 2026-11-23
- 更新日: 2026-11-23
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Ledger APIの保守のサービス](https://cardene.dev/diagrams/canton-ledger-api-maintenance.md): Ledger APIが持つ保守のサービスを、コマンドの状態の調べ方、pruning、版と機能、時刻、trafficの順に、gRPCでどう呼ぶかを4頁で追います。

頁「コマンドの状態を調べ履歴を消す」では、`v2.admin`のパッケージが持つ、コマンドの状態を調べるRPCと、古いデータを削除するRPCを見ました。
この頁は、gRPCのLedger APIで、Participant Nodeのpruning、Ledger APIの版と機能、試験用の時刻、trafficのアカウントを扱うRPCを、サービスごとに並べて使い分けます。
RPCは、ネットワーク越しに、別のプログラムの処理を呼び出す操作です。
9つのRPCは4つのパッケージにまたがり、どれも1件の要求と1件の応答でやり取りし、クライアントもサーバーも、続けて何度もデータを送るストリーミングを使いません。

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

`ParticipantPruningService`の`Prune`は、頁「コマンドの状態を調べ履歴を消す」が、`v2.admin`の側から追っています。

https://cardene.dev/diagrams/canton-lapiadm-ops

4つの`TrafficService`のRPCは、CantonのProtobufの参照の「Other APIs」に入ります。
Ledger APIは、Participant Nodeがtrafficの集計を有効にした時だけ、`TrafficService`を公開します。

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

## RPCはサービスごとに分かれる

図Aは、5つのサービスを並べ、この頁が取り上げる9つのRPCを5つの段で足します。
段2は`ParticipantPruningService`に、段3は`StateService`と`VersionService`に、取り上げるRPCを足します。
段4は時刻のRPCを、段5はtrafficのRPCを足します。

`StateService`には、`GetLatestPrunedOffsets`のほかにもRPCがあり、図Aが足すのは、この頁が取り上げる分だけです。
2つの`Prune`は、別のサービスのRPCで、要求と応答の欄も違います。

```dragon
mind 保守のRPCをサービスごとに分ける

step 5つのサービス
  say 5つのサービスに、この頁が取り上げる9つのRPCが分かれます。
  idea root as "保守のRPC" [color: slate]
  idea p as "ParticipantPruningService" of root [color: blue]
  idea s as "StateService" of root [color: blue]
  idea v as "VersionService" of root [color: blue]
  idea t as "TimeService" of root [color: blue]
  idea f as "TrafficService" of root [color: blue]
  source CantonのPrune [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-admin/participantpruningservice/prune]

step pruningのRPC
  say ParticipantPruningServiceに、この頁が取り上げるRPCを1つ足します。
  idea p1 as "Prune" of p [color: blue]
  source CantonのPrune [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-admin/participantpruningservice/prune]

step 削除の位置と版のRPC
  say StateServiceとVersionServiceに、この頁が取り上げるRPCを1つずつ足します。
  idea s1 as "GetLatestPrunedOffsets" of s [color: blue]
  idea v1 as "GetLedgerApiVersion" of v [color: blue]
  source CantonのGetLatestPrunedOffsets [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2/stateservice/getlatestprunedoffsets]

step 時刻のRPC
  say TimeServiceは、2つのRPCを持ちます。
  idea t1 as "GetTime" of t [color: blue]
  idea t2 as "SetTime" of t [color: blue]
  source CantonのTimeService [url: https://docs.canton.network/reference/protobuf/packages/com-daml-ledger-api-v2-testing]

step trafficのRPC
  say TrafficServiceは、4つのRPCを持ちます。
  idea f1 as "GetAccount" of f [color: blue]
  idea f2 as "Prune" of f [color: blue]
  idea f3 as "PruneEvents" of f [color: blue]
  idea f4 as "UpdateAccount" of f [color: blue]
  source CantonのTrafficService [url: https://docs.canton.network/reference/protobuf/packages/com-digitalasset-canton-tea-v1]
```

## 9つのRPCのパス

RPCのパスは、先頭の`/`、パッケージの名前とサービスの名前を`.`でつないだ名前、`/`、RPCの名前をこの順に並べた形です。
次の表は、9つのRPCのパスです。

| RPC | パス |
|---|---|
| `ParticipantPruningService`の`Prune` | `/com.daml.ledger.api.v2.admin.ParticipantPruningService/Prune` |
| `StateService`の`GetLatestPrunedOffsets` | `/com.daml.ledger.api.v2.StateService/GetLatestPrunedOffsets` |
| `VersionService`の`GetLedgerApiVersion` | `/com.daml.ledger.api.v2.VersionService/GetLedgerApiVersion` |
| `TimeService`の`GetTime` | `/com.daml.ledger.api.v2.testing.TimeService/GetTime` |
| `TimeService`の`SetTime` | `/com.daml.ledger.api.v2.testing.TimeService/SetTime` |
| `TrafficService`の`GetAccount` | `/com.digitalasset.canton.tea.v1.TrafficService/GetAccount` |
| `TrafficService`の`Prune` | `/com.digitalasset.canton.tea.v1.TrafficService/Prune` |
| `TrafficService`の`PruneEvents` | `/com.digitalasset.canton.tea.v1.TrafficService/PruneEvents` |
| `TrafficService`の`UpdateAccount` | `/com.digitalasset.canton.tea.v1.TrafficService/UpdateAccount` |

`TrafficService`の`PruneEvents`は、Canton 3.7.0で非推奨になった操作で、後継は`TrafficService`の`Prune`です。
`PruneEvents`は、3.8で既定で無効になり、3.9で外されます。

次の表は、9つのRPCの要求と応答のメッセージと欄です。
Timestampは時刻の型で、boolは真か偽のどちらかの値を持つ型、int32とint64は符号付きの整数の型、Durationは時間の長さの型です。

| RPC | 要求のメッセージと欄 | 応答のメッセージと欄 |
|---|---|---|
| `ParticipantPruningService`の`Prune` | `PruneRequest`。int64の`prune_up_to`と、文字列の`submission_id`と、boolの`prune_all_divulged_contracts` | `PruneResponse`。欄を持たない |
| `StateService`の`GetLatestPrunedOffsets` | `GetLatestPrunedOffsetsRequest`。欄を持たない | `GetLatestPrunedOffsetsResponse`。int64の`participant_pruned_up_to_inclusive`と`all_divulged_contracts_pruned_up_to_inclusive` |
| `VersionService`の`GetLedgerApiVersion` | `GetLedgerApiVersionRequest`。欄を持たない | `GetLedgerApiVersionResponse`。文字列の`version`と、`FeaturesDescriptor`の`features` |
| `TimeService`の`GetTime` | `GetTimeRequest`。欄を持たない | `GetTimeResponse`。Timestampの`current_time` |
| `TimeService`の`SetTime` | `SetTimeRequest`。Timestampの`current_time`と`new_time` | `google.protobuf.Empty`。欄を持たない |
| `TrafficService`の`GetAccount` | `GetAccountRequest`。文字列の`account_id` | `GetAccountResponse`。文字列の`account_id`と、int64の`balance` |
| `TrafficService`の`Prune` | `PruneRequest`。Timestampの`before_or_at` | `PruneResponse`。int32の`pruned_event_count`と`pruned_correlation_count` |
| `TrafficService`の`PruneEvents` | `PruneEventsRequest`。Timestampの`before_or_at` | `PruneEventsResponse`。int32の`pruned_event_count`だけで、`Prune`と違って`pruned_correlation_count`を持たない |
| `TrafficService`の`UpdateAccount` | `UpdateAccountRequest`。文字列の`account_id`と、int64の`balance_delta`と、文字列の`deduplication_id` | `UpdateAccountResponse`。`GetAccountResponse`を持つ`response` |

`ParticipantPruningService`の`Prune`と、`TrafficService`の`Prune`は、別のサービスのRPCで、メッセージの名前が同じ`PruneRequest`と`PruneResponse`でも、欄が違います。
`SetTime`の応答の`google.protobuf.Empty`は、欄を持たないメッセージです。

JSONの例は、型の表と書き方が違います。
`grpcurl`の例では、int64の`prune_up_to`と`balance`と`balance_delta`が、`"0"`のような文字列で表示され、Timestampの`current_time`も文字列で表示されます。
int32の`pruned_event_count`と`pruned_correlation_count`は、数で表示されます。
例に出る`"0"`や`"string"`は、型を示す仮の値で、実際のノードの値ではありません。

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

## 版と機能の応答は、機能の記述の中に5つの欄を持つ

`GetLedgerApiVersion`の応答は、文字列の`version`と、`FeaturesDescriptor`の`features`を持ちます。
`features`は、機能の記述で、その内側に5つの欄を持ちます。
`supported`のboolを持つ欄と、数の上限を持つ欄があります。
応答を呼び出しごとに読む所は、頁「Ledger APIの版と機能を確かめる」が追っています。

https://cardene.dev/diagrams/canton-ledger-api-version-features

| 欄 | 型 | 中の欄 |
|---|---|---|
| `experimental` | `ExperimentalFeatures` | `static_time`の`ExperimentalStaticTime`と、`command_inspection_service`の`ExperimentalCommandInspectionService`で、どちらもboolの`supported`だけを持つ |
| `user_management` | `UserManagementFeature` | boolの`supported`と、int32の`max_rights_per_user`と`max_users_page_size` |
| `party_management` | `PartyManagementFeature` | int32の`max_parties_page_size` |
| `offset_checkpoint` | `OffsetCheckpointFeature` | Durationの`max_offset_checkpoint_emission_delay` |
| `package_feature` | `PackageFeature` | int32の`max_vetted_packages_page_size` |

例の応答は、`experimental`の`staticTime`と`commandInspectionService`の`supported`をtrueで返し、`userManagement`の`supported`もtrueで返します。
`maxRightsPerUser`と`maxUsersPageSize`と`maxPartiesPageSize`と`maxVettedPackagesPageSize`の4つの上限は0で返します。
`maxOffsetCheckpointEmissionDelay`は、Durationを文字列で表した例です。
これらの値は、欄の型を示す仮の値で、実際のノードの設定ではありません。

## 2つのパッケージの数とtrafficのRPCの版

試験用の時刻のRPCは`com.daml.ledger.api.v2.testing`のパッケージにあり、trafficのRPCは`com.digitalasset.canton.tea.v1`のパッケージにあります。
次の表は、公式の参照が集計する、2つのパッケージの数です。

| パッケージ | ソースのファイル | サービス | エンドポイント | メッセージ | 列挙型 |
|---|---|---|---|---|---|
| `com.daml.ledger.api.v2.testing` | `.../v2/testing/time_service.proto` | 1つの`TimeService` | 2 | 3 | なし |
| `com.digitalasset.canton.tea.v1` | `community/traffic-enforcement/api/protobuf/com/digitalasset/canton/tea/v1/traffic_service.proto` | 1つの`TrafficService` | 4 | 8 | なし |

`TimeService`の2つのRPCは、`rpc TimeService.GetTime(GetTimeRequest) returns (GetTimeResponse)`と`rpc TimeService.SetTime(SetTimeRequest) returns (google.protobuf.Empty)`です。
`com.digitalasset.canton.tea.v1`のパッケージは、`Added 3.7.0`の印を持ちます。
この印は、パッケージ全体に付く表示です。
次の表の版は、RPCごとに足された版で、パッケージの印とは別の履歴です。

| RPC | 足された版 | 備考 |
|---|---|---|
| `GetAccount` | 3.5.15 | なし |
| `UpdateAccount` | 3.5.15 | なし |
| `PruneEvents` | 3.6.1 | 3.7.0で非推奨になり、後継は`Prune` |
| `Prune` | 3.7.0 | `PruneEvents`の後継 |

`Prune`は、イベントと送信の要求の対応を刈り込みます。
`Prune`に渡す時刻は、呼び出した時点から、少なくともParticipant Nodeの最大の重複除けの期間だけ過去に置きます。
条件を満たさない時刻は、`TRAFFIC_UNSAFE_TO_PRUNE`で失敗します。

刈り込むのは、完了した送信の要求の対応だけにします。
進行中の送信の要求の対応を刈り込むと、その送信の要求のtrafficの数えに影響します。
消す前に、Participant Nodeのバックアップを取っておきます。

頁「trafficのアカウントを読み足す」が、trafficのアカウントの意味と、`PruneEvents`と`Prune`の使い分けを追っています。

https://cardene.dev/diagrams/canton-traffic-accounting

## 呼ぶ時に要る権利

認可を有効にしたParticipant Nodeでは、次の4つのRPCが要る権利は、頁「Ledger APIをトークンで守る」の表のとおりです。
`public`は、公開された情報を取る権利の名前で、トークンが運ぶ権利の1つです。
表に載らないRPCに、別のRPCの権利を当てはめません。

| RPC | 要る権利 |
|---|---|
| `ParticipantPruningService`の全てのRPC | `participant_admin` |
| `TimeService`の`GetTime` | `public` |
| `TimeService`の`SetTime` | `participant_admin` |
| `VersionService`の全てのRPC | `public` |

https://cardene.dev/diagrams/canton-ledger-api-auth

## 5つのRPCを、4つの目的で呼ぶ

図Bは、呼び出す側とLedger APIのサーバーの2つの箱で、trafficを除く5つのRPCを、4つの目的で追います。
呼び出す側は、`grpcurl`のような、gRPCのサーバーのRPCを呼び出す道具です。
段1は`Prune`、段2は`GetLatestPrunedOffsets`、段3は`GetLedgerApiVersion`、段4は`GetTime`、段5は`SetTime`です。

段4と段5は、時刻の読み取りと設定という同じ目的の、2つの別の呼び出しです。
この図では、RPCを呼ぶ順を示しません。
どの段も、別の呼び出しの始まりです。

`ParticipantPruningService`の`Prune`を呼ぶ前に、バックアップを取り、安全なoffsetを求めます。
手順は、頁「台帳を手でpruningする」が追っています。

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

```dragon
sequence pruningと版と時刻のRPC

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

step 古いデータを削除する
  say 削除のRPCは、3つの欄の要求を受け取り、欄を持たない応答を返します。
  G -> S: 削除の要求
  S -> G: 空の応答
  source CantonのPrune [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-admin/participantpruningservice/prune]

step 削除の位置を読む
  say 空の要求に対し、応答は2つのint64の欄を返します。
  G -> S: 空の要求
  S -> G: 2つの位置
  source CantonのGetLatestPrunedOffsets [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2/stateservice/getlatestprunedoffsets]

step 版と機能を読む
  say 空の要求に対し、応答は版の文字列と、機能の記述を返します。
  G -> S: 空の要求
  S -> G: 版と機能
  source CantonのGetLedgerApiVersion [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2/versionservice/getledgerapiversion]

step 台帳の時刻を読む
  say 空の要求に対し、応答はTimestampの欄を1つ返します。
  G -> S: 空の要求
  S -> G: 今の台帳の時刻
  source CantonのGetTime [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-testing/timeservice/gettime]

step 台帳の時刻を設定する
  say 設定のRPCの要求は、2つのTimestampの欄を持ち、応答は欄を持たないEmptyです。
  G -> S: 今の時刻と新しい時刻
  S -> G: 空の応答
  source CantonのSetTime [url: https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-testing/timeservice/settime]
```

## 次に読む頁

次の頁「trafficの残高を管理する」は、`TrafficService`の4つのRPCで、アカウントの残高を読み、増減させ、古いイベントを刈り込む呼び方を追います。

https://cardene.dev/diagrams/canton-traffic-accounts

## 出典

https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-admin/participantpruningservice/prune

https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2/stateservice/getlatestprunedoffsets

https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2/versionservice/getledgerapiversion

https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-testing/timeservice/gettime

https://docs.canton.network/reference/protobuf/operations/com-daml-ledger-api-v2-testing/timeservice/settime

https://docs.canton.network/reference/protobuf/operations/com-digitalasset-canton-tea-v1/trafficservice/getaccount

https://docs.canton.network/reference/protobuf/operations/com-digitalasset-canton-tea-v1/trafficservice/prune

https://docs.canton.network/reference/protobuf/operations/com-digitalasset-canton-tea-v1/trafficservice/pruneevents

https://docs.canton.network/reference/protobuf/operations/com-digitalasset-canton-tea-v1/trafficservice/updateaccount

https://docs.canton.network/reference/protobuf/packages/com-daml-ledger-api-v2

https://docs.canton.network/reference/protobuf/packages/com-daml-ledger-api-v2-testing

https://docs.canton.network/reference/protobuf/packages/com-digitalasset-canton-tea-v1

https://docs.canton.network/appdev/deep-dives/authorization

https://docs.canton.network/global-synchronizer/production-operations/local-traffic-management

https://docs.canton.network/global-synchronizer/release-notes/canton-releases/3-7-0
