# testingのコマンドで動きを試す

> 試験と負荷の確認のために、Participant NodeとMediatorのtestingのコマンドで、コントラクトと時刻とメッセージを取得し、bongで負荷をかける手順と危うい所を追います。

- URL: https://cardene.dev/diagrams/canton-testing-tools
- 公開日: 2026-11-24
- 更新日: 2026-11-24
- トピック: Blockchain
- タグ: Canton
- 親の図解: [Canton Console](https://cardene.dev/diagrams/canton-ops-console.md): 本番のノードを運用者がCanton Consoleで操る手順を、consoleへのつなぎ方から、スクリプトと最上位の道具と複数のノードの管理と、DARとSequencerとMediatorとtestingのコマンドまで追います。

前の頁は、SequencerとMediatorを、consoleでどう調べて制御するかを追いました。
この頁は、試験と負荷の確認のために、Participant NodeとMediatorの`testing`のコマンドで、何を取得し、どこが危ういかを追います。
危ういコマンドは、それぞれの節で挙げます。

https://cardene.dev/diagrams/canton-sequencer-mediator-ops

## testingのコマンドの目的

`testing`のコマンドの組は、試験用の機能です。
使うには、頁「ノードのconsoleにつなぐ」で見た、consoleの`features`の3行のうち、`enable-testing-commands`を`yes`にします。

https://cardene.dev/diagrams/canton-console-access

Participant Nodeの`testing`の組は、コントラクトとトランザクションを取得するコマンドと、時刻を待つコマンドと取得するコマンドと、負荷をかけるコマンドと、メッセージと状態を調べるコマンドを持ちます。
下の図は、`testing`のコマンドを、目的ごとに足していきます。
図の中は、コマンドの名前でなく、何をするかを日本語で書き、名前は本文の表が挙げます。

```dragon
mind testingのコマンドの目的

step 4つの目的
  say Participant Nodeのtestingのコマンドは、コントラクトとトランザクションの取得と、時刻を扱う操作と、負荷をかける操作と、メッセージと状態の調査の4つの目的に分かれます。
  idea root as "testingのコマンド" [color: slate]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step コントラクトとトランザクションを取得する
  say activeなコントラクトと、確定したトランザクションを取得します。
  idea a as "コントラクトとトランザクション" of root [color: blue]
  idea a1 as "activeなコントラクト" of a [color: blue]
  idea a2 as "確定したトランザクション" of a [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 時刻を扱う
  say Synchronizerの時刻に届くまで待つ操作と、Synchronizerの今の時刻を取得する操作があります。
  idea b as "時刻を扱う" of root [color: blue]
  idea b1 as "時刻に届くまで待つ" of b [color: blue]
  idea b2 as "今の時刻を取得する" of b [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 負荷をかける
  say 複数のParticipant Nodeへpingを同時に送り、往復の時間を測ります。すぐ過負荷の状態になります。
  idea c as "負荷をかける" of root [color: blue]
  idea c1 as "複数の相手へ同時に送る" of c [color: blue]
  idea c2 as "すぐ過負荷になる" of c [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step メッセージと状態を調べる
  say Sequencerのメッセージを取得し、暗号のAPIと、状態調査のインターフェースを得ます。状態調査のインターフェースのメソッドは、ノードの状態を致命的かつ永久に壊しうるので、自分の責任で使います。
  idea d as "メッセージと状態を調べる" of root [color: blue]
  idea d1 as "メッセージを取得する" of d [color: blue]
  idea d2 as "状態調査のメソッドは壊しうる" of d [color: blue]
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## コントラクトとトランザクションを取得する

`testing.acs_search`は、Synchronizerのactiveなコントラクトを、`exactId`と`filterPackage`と`filterTemplate`と`filterStakeholder`と`limit`で取得し、`ContractInstance`のリストを返します。
`testing.lookup_transaction`は、確定したトランザクションを、update IDで取得し、`Option`の型で`LfVersionedTransaction`を返します。
見つからない時は、`None`が返ります。

`testing.pcs_search`は、Synchronizerのsync controllerのPrivate Contract Store(PCS)を、直に取得します。
Private Contract Storeは、Participant Nodeの中のコントラクトのデータの置き場です。
filterは、対象の値が与えた文字列を`contains`で含むかを見ます。
引数を`^`で始めると`startsWith`で、`!`で始めると`equals`で比べます。

`activeSet`は、検索をactive contract setに限り、contract IDの絞り込みは、完全一致だけを扱います。

## Synchronizerの時刻を待つと取得する

Participant Nodeの`testing.await_synchronizer_time`は、引数に`Synchronizer`を渡す形と、`SynchronizerAlias`を渡す形の2つを持ち、そのSynchronizerで与えた時刻に届くまで、`timeout`の中で待ちます。
`testing.fetch_synchronizer_time`も、`Synchronizer`を渡す形と`SynchronizerAlias`を渡す形の2つを持ち、そのSynchronizerの今の時刻を`CantonTimestamp`で返します。
`testing.fetch_synchronizer_times`は、接続した全てのSynchronizerの今の時刻を取得します。

Mediatorにも、同じ名前の3つのコマンドがあり、対象は自身のSynchronizerです。
`testing.await_synchronizer_time`は、与えた時刻に届くまで待ち、`testing.fetch_synchronizer_time`は、今の時刻を返します。
`testing.help`は、`testing`のコマンドの説明を出します。

## bongで負荷をかける

`testing.bong`は、台帳を通して、複数のParticipant Nodeへpingを同時に送ります。
最も速く答えた相手との往復の時間を測り、失敗すると、`RuntimeException`を投げます。
`testing.maybe_bong`は、`bong`と同じですが、失敗した時は`None`を返します。

`Some`と`None`は、Scalaで値がある時と無い時を分けて返す形で、値がある時は`Some(値)`を、無い時は`None`を返します。

二重のspentは、システムの誤りを示します。
`bong`のgrace-periodは、終了の前に、その二重のspentを検出するために待つ猶予の時間です。
`levels`が0より大きいと、コントラクトが2分木の形で急増し、システムは`(2^(L+2) - 3)`個のコントラクトを作ります。
Lは`levels`です。

| `levels` | 作るコントラクトの数 |
|---|---|
| 1 | 5 |
| 2 | 13 |
| 3 | 29 |
| 4 | 61 |

表の値は、式に`levels`を入れて計算した値です。
`bong`の中のvalidatorは、`bong`の試験の中の検証役で、ネットワークのvalidatorとは別の役割です。
普通は、始めた側だけがこの検証役で、引数`validators`で、検証役を足せます。
`bong`は、短い時間に負荷を集中させる試験に使え、すぐ過負荷の状態になります。

下の図は、`bong`が複数のParticipant Nodeへpingを同時に送って、往復の時間を測る流れを追います。
図は、成功した時の応答を示します。

```dragon
sequence bongが往復の時間を測る流れ

box Con as 運用者のconsole [note: 負荷をかける, color: blue, icon: user]
box Init as 始めたParticipant Node [note: 検証役になる, color: slate, icon: server]
box Peer as 相手のParticipant Node [note: 複数の相手, color: slate, icon: server]

step 同時に送るpingを始める
  say 運用者は、始めたParticipant Nodeで、複数の相手へ同時に送るpingを始めます。
  Con -> Init: pingを始める
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 複数の相手へpingを送る
  say 始めたParticipant Nodeは、台帳を通して、複数のParticipant Nodeへpingを送ります。
  Init -> Peer: pingを送る
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 最も速い相手が答える
  say 最も速く答えた相手との往復の時間を、始めたParticipant Nodeが測ります。
  Peer -> Init: 答える
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 往復の時間が返る
  say 成功すると、測った往復の時間が、運用者のconsoleへ返ります。
  Init -> Con: 往復の時間
  source CantonのCanton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## commitmentの時刻を探す

ACS commitmentは、Participant Nodeが署名した、共有するactiveなコントラクトの暗号のまとめです。
`testing.find_clean_commitments_timestamp`は、与えた時刻以前で、未着のcommitmentが無い、最も新しいタイムスタンプを、`Option`の型で返します。
この時刻でpruningできるとは限りません。
システムは、クラッシュからの回復に、追加のデータを要しうるからです。

そのため、このコマンドはcommitmentの試験に使い、pruningには、pruningの組のコマンドを使います。
Participant Nodeのpruningと、ACS commitmentとの関係は、章「ACS commitmentとpruning」が追っています。

https://cardene.dev/diagrams/canton-commitment-and-pruning

結果は、reconciliation intervalが決める、commitmentのtickに当たるとは限りません。
Synchronizerの運用者は、動的なSynchronizerのパラメータで周期の長さを調整でき、これをreconciliation intervalと呼びます。

## メッセージと暗号と状態を直に調べる

`testing.sequencer_messages`は、引数`physicalSynchronizerId`で指定したphysicalなSynchronizerの、全てのSequencerのメッセージを取得します。
両端を含む時間の範囲と、表示の件数で絞れます。
時間の範囲を渡すと、ほとんどのSynchronizerの台帳の実装で、メッセージは順に並びます。

Participant Nodeが、そのSynchronizerに一度も接続していないと、失敗します。
引数に`warnOnDiscardedEnvelopes`も取ります。

`testing.crypto_api`は、全ての暗号のメソッドを使える、sync crypto apiのproviderを返します。

`testing.state_inspection`は、状態調査のインターフェースを返します。
状態を壊しうるのは、返ったインターフェースのメソッドを呼ぶ時です。
そのメソッドは、Participant Nodeの状態を、致命的かつ永久に壊しうるうえ、APIはどのようにも変わりうるので、自分の責任で使います。
`testing.help`は、Participant Nodeの`testing`のコマンドの説明を、引数`methodName`で出します。

## 出典

https://docs.canton.network/global-synchronizer/reference/canton-console-commands
