# IOTA Local Snapshot study ## Introduction 本文為 IOTA local study 的研讀資料。目的在於了解 IOTA local snapshot 的理論與實做。Local snapshot 專案主要開發人員為 [Hans Moog](https://blog.iota.org/welcome-hans-moog-to-the-iota-foundation-ff8c6d64158b),前期開發的程式碼位於 [iotadevelopment/iri](https://github.com/iotadevelopment/iri) 中,並且透過持續的 Pull Request 逐漸完成 Local snapshot. ## 目錄結構 * [iri/src/main/java/com/iota/iri/service/snapshot/](https://github.com/iotadevelopment/iri/tree/dev/src/main/java/com/iota/iri/service/snapshot) * Cofiguration * configuration.getLocalSnapshotsEnabled() * int snapshotDepth = configuration.getLocalSnapshotsDepth(); * 觸發 Local snapshot (觸發某個深度值就執行) ``` if(latestSnapshot.getIndex() == milestoneTracker.latestMilestoneIndex && latestSnapshot.getIndex() - initialSnapshot.getIndex() > snapshotDepth + LOCAL_SNAPSHOT_INTERVAL) { } ``` * 觸發後節點之間的同步問題 * main branch * [Node.java -> processReceivedData -> receivedTransactionViewModel.store](https://github.com/iotaledger/iri/blob/08c2cb9a0ff268001c77916c8d123956ddcbd889/src/main/java/com/iota/iri/network/Node.java#L361) * [store](https://github.com/iotaledger/iri/blob/08c2cb9a0ff268001c77916c8d123956ddcbd889/src/main/java/com/iota/iri/controllers/TransactionViewModel.java#L202) * [iotadevelopment/iri](https://github.com/iotadevelopment/iri) * [Node.java -> processReceivedData -> receivedTransactionViewModel.store](https://github.com/iotadevelopment/iri/blob/dev/src/main/java/com/iota/iri/network/Node.java#L365) * [store](https://github.com/iotadevelopment/iri/blob/dev/src/main/java/com/iota/iri/controllers/TransactionViewModel.java#L218) ``` java if (snapshotManager.getInitialSnapshot().isSolidEntryPoint(hash) || exists(tangle, hash)) { return false; } ``` * How to clean * [remove all approved transactions](https://github.com/iotadevelopment/iri/blob/dev/src/main/java/com/iota/iri/service/snapshot/SnapshotGarbageCollector.java#L147) ## Question * consensus after local snapshot ![](https://i.imgur.com/sT8BtU7.png) [edit me...](https://docs.google.com/drawings/d/1oTq-Mij7S7754WXTx5yN_tF3F00ZUDhgzutg-yj9ab0/edit?usp=sharing) ![](https://i.imgur.com/bUX0WJn.png) [edit me...](https://docs.google.com/drawings/d/1HYbC-mjwqh3MpKeOAlHBo1tvY8faZu0ASPZ0CR1yJ4U/edit?usp=sharing) * [iotadevelopment/iri](https://github.com/iotadevelopment/iri) * [Node.java -> processReceivedData -> receivedTransactionViewModel.store](https://github.com/iotadevelopment/iri/blob/dev/src/main/java/com/iota/iri/network/Node.java#L365) * [store](https://github.com/iotadevelopment/iri/blob/dev/src/main/java/com/iota/iri/controllers/TransactionViewModel.java#L218) ``` java if (snapshotManager.getInitialSnapshot().isSolidEntryPoint(hash) || exists(tangle, hash)) { return false; } ``` ## Discussion * #### [Removing pending transactions or not after local snapshot?](https://iota.stackexchange.com/questions/2137/removing-pending-transactions-or-not-after-local-snapshot) * #### [How the full-node process received data after local snapshot?](https://iota.stackexchange.com/questions/2148/how-the-full-node-process-received-data-after-local-snapshot) * ##### How can we reach a global consencus * Question about localsnapshot; how can we reach a global consencus with nodes making neir own local decisions * nodes reach consensus the same way they do now - they only decide how much of the old data they wanna keep locally which doesn affect consensus since iota's consensus doesnt rely on things like "longest chain wins" now its no problem anyway since the coordinator issues "checkpoints" for the nodes that are comparable and in the future without a coo the only thing that matters for consensus is the amount of tips referencing a transaction at the top of the graph the garbage that you throw away at the "bottom" of the graph doesnt affect that so this solution is post-coo proof ## Issues & Pull Request * Issues * Test and review local snapshots [#977](https://github.com/iotaledger/iri/issues/977) ## Reference * [Coming Up: Local Snapshots](https://blog.iota.org/coming-up-local-snapshots-7018ff0ed5db)