# topologyの変更を出し入れする

> Canton Consoleのtopology.transactionsのコマンドで、topology transactionを出し、署名を足して効かせ、fileに書き出して別のノードへ取り込むまでを、3つの図で追います。

- URL: https://cardene.dev/diagrams/canton-topology-transactions
- 公開日: 2026-11-17
- 更新日: 2026-11-17
- トピック: Blockchain
- タグ: Canton
- 親の図解: [topology transaction](https://cardene.dev/diagrams/canton-topology-management.md): Canton Networkのノードが、topology transactionをどう確かめて効かせ、Synchronizerのノードへどう広め、どのコマンドで扱うかを、章の中の図解で追います。

前の頁では、Canton Consoleの`topology`のコマンドで、鍵とpartyとhost先を結ぶmappingを作って変えました。
この頁では、mappingの種類を問わずにtopology transactionを出し、署名を足して効かせ、fileに書き出して別のノードへ取り込むコマンドを追います。
`topology`のコマンドは、どれもパブリックキーをfingerprintで指します。
fingerprintは、FingerprintからPublicKeyを引くkey registryで解決します。

key registryには、`keys.public.upload`のような`keys.public`のコマンドで、どの鍵でも足せます。
`topology.help`は、引数の`methodName`で指したコマンドの説明を出します。

## proposeで出す

`topology.transactions.propose`は、admin APIのコマンドをそのまま使ってtopology transactionをproposeします。
引数は`mapping`、`store`、`signedBy`、`serial`、`change`、`mustFullyAuthorize`、`forceChanges`、`waitToBecomeEffective`です。

`store`に`Authorized`を渡すと、topology transactionはノードのauthorized storeに残り、当てはまれば接続したSynchronizerへ自動で伝わります。
synchronizer idを渡すと、手元に残さずにそのSynchronizerへ直に出し、ほかのSynchronizerへは自動で伝わりません。
`serial`は1から続けて振り、同じserialの完全に認可されたtopology transactionが既にあるか、最後に使ったserialとの間が空くと断られます。
`serial`を渡さなければ、ノードが選びます。

`signedBy`は、このproposalに署名する鍵のfingerprintです。
`synchronize`のtimeoutは、状態がノードへ伝わったかを確かめるのに使います。
serialの並び方は、topologyの変更が効くまでを追う頁で見ました。

https://cardene.dev/diagrams/canton-topology-transaction-lifecycle

## temporary storeで試す

`topology.stores.create_temporary_topology_store`は、`name`と`protocolVersion`でtemporary storeを作ります。
temporary storeは、Synchronizerのfounding ceremonyを進める時や、topology snapshotを取り込んで後で調べる時に使います。
temporary storeは保存されず、全てのtopology transactionをmemoryだけに持つので、ノードを再起動するとstoreのtopology transactionを全て失います。
どのSynchronizerにもつながらないので、接続したSynchronizerへ自動では伝わりません。

`topology.stores.drop_temporary_topology_store`は、temporary storeとその中の全てのtopology transactionを元に戻せない形で消します。
authorized storeとsynchronizer storeは、このコマンドで消せません。
`topology.stores.list`は使えるstoreの一覧を返し、`topology.stores.help`はstoreのコマンドの説明を出します。

図では、左に運用者のノートPCを、真ん中にparticipant1の棚を、右にsynchronizer1とsynchronizer2の棚を置いて配線でつなぎます。
participant1の棚はauthorized storeとtemporary storeの引き出しを持ち、Synchronizerの棚はtopologyの状態の引き出しを持ちます。
storeと後の操作を選んで「送る」を押すと、proposeしたAliceの`PartyToParticipant`の紙が、選んだstoreかSynchronizerへ届きます。
participant1を再起動すると、temporary storeの紙は消えます。

```dragon
try proposeしたtopology transactionはどこに残るか

route 出す道: 運用者 - participant1 - synchronizer1, participant1 - synchronizer2 [from: 運用者, to: participant1]
queue 運用者
queue participant1
queue synchronizer1
queue synchronizer2
ask store, 後の操作, 残る所 [into: participant1, via: 出す道]
choose store: Authorized, synchronizer1, temporary store
choose 後の操作: 無い, participant1を再起動
choose 残る所: authorized storeと2つのSynchronizer, synchronizer1だけ, temporary storeだけ, 無い

step Authorizedは接続したSynchronizerへ伝える
  say Authorizedに出すと、authorized storeに残り、接続したsynchronizer1とsynchronizer2へ伝わります。
  ask Authorized, 無い, authorized storeと2つのSynchronizer
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step synchronizer idは直に出す
  say synchronizer1に出すと、手元に残さずにsynchronizer1へ直に出し、synchronizer2へは伝わりません。
  ask synchronizer1, 無い, synchronizer1だけ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step temporary storeはSynchronizerへ伝えない
  say temporary storeはどのSynchronizerにもつながらないので、topology transactionはtemporary storeにだけ残ります。
  ask temporary store, 無い, temporary storeだけ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 再起動でtemporary storeは空になる
  say temporary storeはmemoryだけに持つので、participant1を再起動するとtopology transactionを失います。
  ask temporary store, participant1を再起動, 無い
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step authorized storeは再起動で消えない
  say 再起動で失うのはtemporary storeの物だけで、authorized storeのtopology transactionは残ります。
  ask Authorized, participant1を再起動, authorized storeと2つのSynchronizer
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## 署名を足して効かせる

`mustFullyAuthorize`をtrueにすると、proposalが前に受けた署名とこのノードの署名で完全に認可できない時に、コマンドは失敗します。
falseにすると、mappingの認可の条件を満たす署名が集まるまで、proposalのまま待ちます。
`topology.transactions.authorize`は、topology transactionをhashの`txHash`で認可し、`mustBeFullyAuthorized`と`store`と`signedBy`を取ります。
`topology.transactions.authorize_1`は、`synchronizerId`と`txHash`で認可します。

`topology.decentralized_namespaces.propose_new`は、新しいdecentralized namespaceを作るproposalを出します。
`owners`は創設のmemberのnamespaceで、decentralized namespaceの名前を作るのに使います。
`threshold`は、そのnamespaceのtopology transactionを認可するのに要る、memberの署名の最小の数です。

`topology.decentralized_namespaces.propose`は、`DecentralizedNamespaceDefinition`でdecentralized namespaceの変更をproposeし、`store`と`mustFullyAuthorize`と`signedBy`と`serial`と`synchronize`を取ります。
`topology.decentralized_namespaces.help`は、decentralized namespaceのコマンドの説明を出します。

`topology.transactions.find_latest_by_mapping`はmappingの、`topology.transactions.find_latest_by_mapping_hash`は一意のkeyの`mappingHash`の、最新のtopology transactionを探します。
`store`が`Authorized`ならノードのauthorized storeを、synchronizer idなら指したsynchronizer storeを引きます。
`includeProposals`をtrueにすると最新のproposalも返りえ、falseなら最新の完全に認可されたtopology transactionだけを返します。

`topology.transactions.list`は、`store`、`proposals`、`timeQuery`、`operation`、`filterMappings`、`excludeMappings`、`filterAuthorizedKey`、`protocolVersion`、`filterNamespace`で絞ります。
返す物は、当てはまる全てのtopology transactionを持つ`StoredTopologyTransactions`です。

図では、左に運用者のノートPCを置き、participant1からsequencer1を通ってparticipant2とparticipant3へ配線でつなぎます。
3つのParticipant Nodeのnamespaceは、decentralized namespaceの`consortium`のownerです。
participant1の棚は、`consortium`のtopology transactionの引き出しを持ち、3つのownerの署名の空きを並べます。
`threshold`と`mustFullyAuthorize`を選んで「送る」を押すと、participant1が署名して出し、proposalのまま待てばparticipant2が`txHash`でauthorizeして署名を足します。

```dragon
try decentralized namespaceのtopology transactionはいつ効くか

route 配る道: 運用者 - participant1 - sequencer1 - participant2, sequencer1 - participant3 [from: 運用者, to: participant1]
queue 運用者
queue participant1
queue sequencer1
queue participant2
queue participant3
ask threshold, mustFullyAuthorize, 効く時 [into: participant1, via: 配る道]
choose threshold: 1, 2, 3
choose mustFullyAuthorize: true, false
choose 効く時: proposeの時, authorizeの時, まだ効かない, 断る

step 署名1つで足りればすぐ効く
  say thresholdが1なので、participant1の署名だけで効きます。
  ask 1, true, proposeの時
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 足りない時にtrueなら断る
  say mustFullyAuthorizeがtrueで、participant1の署名だけではthresholdの2に届かないので、proposeは断られます。
  ask 2, true, 断る
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step falseならproposalで署名を待つ
  say falseならproposalのまま待ち、participant2がauthorizeして署名が2つになると効きます。
  ask 2, false, authorizeの時
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step thresholdに届くまで効かない
  say thresholdが3なので、participant2がauthorizeしても署名は2つで、まだ効きません。
  ask 3, false, まだ効かない
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## 書き出して取り込む

`topology.transactions.export_topology_snapshot`と`topology.transactions.export_topology_snapshotv2`は、ノードのtopology transactionをbyte stringで書き出します。
byte stringは2GBを超えられないので、大きなsnapshotは`topology.transactions.export_topology_snapshot_to_file`で`outputFile`のfileへ流します。
fileへ流すコマンドのほかの引数は、byte stringで書き出すコマンドと同じです。

| 引数 | 意味 |
|---|---|
| `excludeMappings` | 書き出さないmappingの種類の一覧で、渡さなければ全ての種類を含める |
| `filterNamespace` | topology transactionを絞るnamespace |
| `protocolVersion` | 書き出す時のprotocol versionで、渡さなければ最新を使う |
| `store`と`proposals`と`timeQuery`と`operation`と`filterMappings`と`filterAuthorizedKey` | `topology.transactions.list`と同じ絞り方 |

`topology.transactions.import_topology_snapshotv2`は、`TopologyTransactions`で書いたbyte stringのtopology transactionを、指したstoreへ取り込みます。
2GBを超えるsnapshotは、fileから流す`topology.transactions.import_topology_snapshot_fromv2`で取り込みます。
`topology.transactions.import_topology_snapshot_from`と`import_topology_snapshot_fromv2`は、`TopologyTransactions`で書いたfileから、指したstoreへ取り込みます。

署名したtopology transactionのfileは、`load`のコマンドで取り込みます。
`topology.transactions.load_multiple_from_file`は`SignedTopologyTransactions`で書いたfileを、`load_single_from_file`は`SignedTopologyTransaction`のfileを、`load_single_from_files`はそのfileの一覧を、指したstoreへ取り込みます。
どれも`forceFlags`と`synchronize`を取ります。

ノードのidentityは、`NamespaceDelegation`と`OwnerToKeyMapping`のtopology transactionで決まります。
`topology.transactions.identity_transactions`はノードのidentityのtopology transactionを返し、`topology.transactions.export_identity_transactions`はそれをfileに書き出します。
`export_identity_transactionsv2`は`protocolVersion`も取り、書き出したfileは別のノードで読み込みます。

図では、左にparticipant1の棚を、真ん中に運用者のノートPCを、右にparticipant2の棚を置いて配線でつなぎます。
participant1の棚のsynchronizer1のstoreは、2つのnamespaceごとに3つのmappingの種類の札を並べ、6つのtopology transactionを持ちます。
`excludeMappings`と`filterNamespace`を選んで「送る」を押すと、`export_topology_snapshot_to_file`が残った物をノートPCのfileへ書き出します。
そして、`import_topology_snapshot_fromv2`がそのfileをparticipant2のtemporary storeへ取り込みます。

```dragon
try topology snapshotにどのtopology transactionが入るか

route 運ぶ道: participant1 - 運用者 - participant2 [from: participant1, to: participant2]
queue participant1
queue 運用者
queue participant2
ask excludeMappings, filterNamespace, 入る数 [into: participant2, via: 運ぶ道]
choose excludeMappings: 無し, PartyToParticipant
choose filterNamespace: 無し, participant1のnamespace
choose 入る数: 6つ, 4つ, 3つ, 2つ

step 絞らなければ全てを書き出す
  say excludeMappingsもfilterNamespaceも無いので、storeの6つのtopology transactionを全て書き出します。
  ask 無し, 無し, 6つ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step excludeMappingsは種類を外す
  say excludeMappingsでPartyToParticipantを外すので、4つを書き出します。
  ask PartyToParticipant, 無し, 4つ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step filterNamespaceはnamespaceで絞る
  say filterNamespaceでparticipant1のnamespaceに絞るので、3つを書き出します。
  ask 無し, participant1のnamespace, 3つ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]

step 2つの絞り方を重ねる
  say PartyToParticipantを外してparticipant1のnamespaceに絞るので、2つを書き出します。
  ask PartyToParticipant, participant1のnamespace, 2つ
  source Canton Console Commands [url: https://docs.canton.network/global-synchronizer/reference/canton-console-commands]
```

## 新しいSynchronizerへ移す

`topology.transactions.generate_onboarding_transactions`は、memberをSynchronizerにonboardするidentityのtopology transactionを作ります。
ノードが自分のnamespaceの秘密鍵を使えなければ、このコマンドは働きません。
`protocolVersion`には、ノードが加わるSynchronizerのprotocol versionと同じ版を渡します。

後方互換のため、ノードはまず、求めたprotocol versionのtopology transactionをauthorized storeから探します。
これはParticipant Nodeだけに関わり、SequencerとMediatorのノードはもうauthorized storeを使いません。
既定では新しいtemporary storeを作ってtopology transactionを作るので、根の鍵がノードに無いと困ります。
その時は、署名した根の証明書と、ノードにある中間の鍵への委任を入れたtemporary storeを、`temporaryStore`で渡せます。

根の鍵と中間の鍵の分け方は、根の鍵をofflineに置く頁で見ました。

https://cardene.dev/diagrams/canton-offline-root-key

`topology.transactions.export_genesis_state`は、majorなSynchronizerのupgradeでSequencerを初期化するために、topology transactionの全ての履歴を含むgenesis stateをfileへ流します。
genesis stateの`validFrom`と`validUntil`は、`SignedTopologyTransaction.InitialTopologySequencingTime`に置かれます。
Participant Nodeからgenesis stateを求める時は、`filterSynchronizerStore`を必ず渡します。
`timestamp`を渡さなければ、最新のtopology transactionの最大のeffective timeを使います。

`topology.transactions.genesis_state`と`topology.transactions.genesis_statev2`は、genesis stateをbyte stringで返します。
byte stringは2GBを超えられないので、大きなgenesis stateには、fileへ流す`export_genesis_state`を使います。

`topology.transactions.sequencer_lsu_state`は、logical synchronizer upgradeでSequencerを初期化するために、topology transactionの全ての履歴を含む状態をfileへ流します。
logical synchronizer upgradeが進んでいなければ、このコマンドは成功しません。
`topologyStore`は、ノードがactiveなsynchronizer storeを1つだけ持てば自動で決まり、Participant Nodeのように複数持つ時は明示します。
`timestamp`は通常のupgradeでは空にし、upgradeが告知されていないSynchronizerからtopologyを求める障害からの回復では渡します。

## 処理が終わるのを待つ

topology transactionは、Synchronizerで効く前にいくつかの待ち行列を通ります。
`topology.synchronisation.is_idle`はノードのtopologyの処理の待ち行列が全て空かを返し、`topology.synchronisation.await_idle`は`is_idle()`がtrueを返すまで待ちます。
Synchronizerは処理中の全てのtopology transactionを常に知りますが、Participant NodeはSynchronizerのtopology dispatcherが処理中のtopology transactionの状態を知りません。
そのため、Participant Nodeの待ち行列が空かには、曖昧さが残ります。

## 出典

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