# Dfinity メモリとChain key
###### tags: `Dfinity`
メモリとストレージ
メモリについて
Chain key
コスト
Reference
メモリとストレージ
IC = canisterのメモリについて記載する。
ex.
$ dfx canister --network ic status --all
Canister status call result for okk.
Status: Running
Controllers: adxgu-sqaaa-aaaag-qaada-cai
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(427499) ---> コントラクトにデータを追加するとここのメモリがどんどん増えていく。
Balance: 3_899_962_626_784 Cycles
Module hash: 0xf127a69a74b0ad5fab351e958212ab8f92c1dc33e861884f019dd5b68858fa59
Canister status call result for okk_assets.
Status: Running
Controllers: adxgu-sqaaa-aaaag-qaada-cai
Memory allocation: 0
Compute allocation: 0
Freezing threshold: 2_592_000
Memory Size: Nat(3472084) ---> Storage 永続メモリ
Balance: 3_897_609_966_218 Cycles
Module hash: 0xe0df779f65fe44893d8991bef0f9af442bff019b79ec756eface2b58beec236f
メモリを使うことに関して特にメリット・デメリットはなさそう。画像データもファイルも全てメモリ上に保存になる。
Memory Allocation Explained
Memory Allocation Explained
Increased Canister Smart Contract Memory
ICのメモリの使用量コスト(AWSより安い)
127,000 Cycle / 1GB 1秒
6ドル / 1ヶ月
(今後どんどん安くなってくとのことだが、Dfinityの盛り上がりに依存する。)
https://icp.guide/costs-on-the-internet-computer/ かなりわかりやすい。コストについて。
容量と制限
今のところ、メモリ4G、Stableメモリ4GB = 8GB
ロードマップで300GBまで増える。(まだまだ未定)
アップロードのサイズ制限があるので、データが大きい場合は、chunk化して送信する。
実用的な安定したメモリは、4GB。
キャニスターコントラクトがアップグレードした場合も保存した値が消えずに残るには、安定したStableメモリの4GBしか使えず。実際は、コントラクトはアップグレードする前提で使用するので、実質4GBしか使えないということ。
Databaseについて
ICには、データベースシステムを採用できない。実際にメモリに最適化したデータ構造で保存することになる。ファイルシステムのようなBigMapを開発中とのこと。まだ使えない。
強み
ストレージとして使う場合は、大量のデータを扱うには向かないが、分散化およびセキュリティのメリットがある。データはICノード自体に存在し、サブネット上のすべてのレプリカに複製される。
スループット
ICにサブネットを追加することで、スケールアウトするので、並行に処理する事が可能になる。
参考
Abstract away the 4GB canister memory limit good
Abstract away the 4GB canister memory limit
Scalability of update calls in a common scenario
Scalability of update calls in a common scenario
krpeacock/file_upload_experiment
GitHub - krpeacock/file_upload_experiment: testing repo taking advantage of asset canister functionality
What needs to be done to ensure the scalability of Internet Computer apps?
What needs to be done to ensure the scalability of Internet Computer apps?
Two questions about canister storage
Two questions about canister storage
メモリについて
インターネットコンピュータの重要な機能の1つは、従来のデータベースではなく、WebAssemblyメモリとグローバルを使用してキャニスターのスマートコントラクト状態を維持できることです。これは、キャニスターの状態全体が、明示的なユーザーの指示なしに、各メッセージの前に魔法のように復元され、後に保存されることを意味します。
インターネットコンピュータの永続性モデルにより、キャニスターはそのようなデータを専用の安定したメモリに保存および復元できます。このメモリは、通常のキャニスターメモリとは異なり、アップグレード後も保持されるため、キャニスターはデータを交換用のキャニスターに一括転送できます。
機能追加等の際に、キャニスターをアップグレード(再デプロイ)する場合には、状態を維持する変数をstableにする必要がある。
Stable variables and upgrade methods (This automatic and user-transparent preservation of state is called orthogonal persistence.)
Stable variables and upgrade methods | Internet Computer Home
Chain key
結論
公開鍵使ってcanisterから返却されたメッセージの検証はできそう。
chain keyを使って暗号化はできなさそう。暗号化をする場合は、自分達で作成した秘密鍵でcanister内部で暗号化する。
参考
dfinity/ajent-js
GitHub - dfinity/agent-js: A collection of libraries and tools for building software around the Internet Computer, in JavaScript.
dfinity/agent-rs
GitHub - dfinity/agent-rs: A collection of libraries and tools for building software around the Internet Computer, in Rust.
Recommended usage of CertifiedData
Recommended usage of CertifiedData
How can I validate subnet “signatures” on-chain?
How can I validate subnet "signatures" on-chain?
Where can i find the public key of ic and subnets?
Where can i find the public key of ic and subnets?
Encryption/Decryption Lib in Motoko?
Encryption/Decryption Lib in Motoko?
Tackling CertifiedData in Motoko
https://forum.dfinity.org/t/tackling-certifieddata-in-motoko/6272
コスト
コスト一覧
https://sdk.dfinity.org/docs/developers-guide/computation-and-storage-costs.html
ストレージに関して
GB Storage Per Month
For storing a GB of data per month
$0.467
永続性: cycle(ICP TOKEN)が完全になくなると削除されるので、十分な量をICに提供する必要がある。 https://forum.dfinity.org/t/what-happens-to-canisters-when-they-run-out-of-cycles/5443
パフォーマンス: 問題なさそう
単一障害点の排除: 分散型クラウドコンピューティング上のストレージを利用するので、問題ない。
一度アップロードしたデータの更新・削除: 更新、削除どちらも可能
Reference
Dfnity
https://dfinity.org/
Dfnity SDK
https://sdk.dfinity.org/docs/quickstart/quickstart-intro.html
ICP
https://identity.ic0.app/
Wallet(network nervous system)
https://nns.ic0.app/