# 在中低階 Arm 環境佈署 IOTA Swarm Nodes [IOTA](https://www.iota.org/) 是一個為了物聯網而設計的開放原始碼分散式賬本技術,為機器提供無需手續費的微交易 (micro-transactions)。 在 IOTA 上,您需要仰賴一個節點 (node) 來發起交易,或是查詢曾經的交易紀錄。但如果我們這樣想,很快就會遇到以下的一些問題: * IOTA 現行的 full-node 需要 fully synced 才能發起交易。 * 運行一個 full-node [最小的系統需求](https://iota.stackexchange.com/questions/1391/minimum-requirements-to-run-a-full-node) * 需要 7 天 24 小時不關機以確保 fully synced * 每個 Node 需要維運 7~9 的鄰居節點 (neighbor nodes),大量的 Node 維運成本非常高。 這樣的使用情境,對物聯網之類的裝置而言,是難以接受的。就像我們不能要求家裡的微波爐儲存著快 100 GB 的分散式帳本, 24 小時上電,就為了達成 fully-synced 這樣的任務。 因此,對於我們週邊的物聯網裝置,合理的使用情境應該是: * 不保證持續的電源、網路狀態。 * 期望的功能唯物聯網裝置本身能夠收/發交易。 * 不定時的查帳可以透過 full-node 或是 [Light Wallet Servers](http://iotasupport.com/lightwallet.shtml) 所以我們可以將 [iota-swarm-node](https://github.com/yillkid/iota-swarm-node) 佈署在便宜的 Arm 開發板上,作為物聯網裝置端微型支付的基礎建設。解釋 iota-swarm-node 之前,我們先看 IOTA 交易是如何連接到 Tangle。IOTA 在發起一筆交易時候,需要在 Tangle 上選擇兩個交易驗證,可以被選的交易,稱之為 tips,如同下列的灰色方塊所示。所以現在我們知道,[iota-swarm-node](https://github.com/yillkid/iota-swarm-node) 只需要這些 tips 就可以發起交易了,這些 tip 大概會佔去幾 MB 的空間。 ![](https://i.imgur.com/e37gGWJ.png) 經過上文的解釋, [iota-swarm-node](https://github.com/yillkid/iota-swarm-node) 與 full-node 分工就很明白了,分工如下: * full-node * 提供 tips 給 iota-swarm-node * 廣播 iota-swarm-node 的交易 * iota-swarm-node * 產生寄款/收款帳號 * 對交易簽名 * 接收來自 full-node 的 tips * tips selection (options) * 對交易做工作證明 (proof of work; PoW) 詳細的架構如下圖所示: ![](https://i.imgur.com/2JJbZVm.png) 順帶一題,iota-swarm-node 採用 [dcurl](https://github.com/chenwei-tw/dcurl) 實現 PoW (proof of work),支援 GPU 加速以及 multi-thread Curl function,在交易的處理上有顯著的效能改善。 ![](https://i.imgur.com/Sca3F0p.png) 以下為 [iota-swarm-node](https://github.com/yillkid/iota-swarm-node) 在 [Raspberry Pi 3 Model B](https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/) 上安裝的過程: ## Hardware requirements * Raspberry Pi 3 (Model B) * microSDHC > 2 GB * Resbian 約需要 2 GB * iota-swarm-node 約需要 11 MB ## 設定 Raspberry Pi #### 安裝 Raspberry Pi 上的作業系統 * 下載網路上的 Raspbian [image](https://downloads.raspberrypi.org/raspbian_lite_latest) 作業系統映像檔 * 將作業系統映像檔複製至 microSDHC * `sudo unzip -p 2018-03-13-raspbian-stretch-lite.zip | sudo dd of=/dev/mmcblk0 bs=4M conv=fsync` #### 設定 wifi * 掛載 **boot** 分割區,設定 wifi AP * touch ssh /mount_point/boot/ * vim /mount_point/boot/wpa_supplicant.conf ```shell ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=<your_ISO-3166-1_two-letter_country_code> network={ ssid="<your_SSID>" psk="<your_PSK>" key_mgmt=WPA-PSK } ``` #### 第一次登入 * Raspbian 預設帳號/密碼 * pi/raspberry #### 安裝 iota-swarm-node * Update apt list: * `$ sudo apt-get update` * Pre-Installation: * `sudo apt-get install git` * `sudo apt-get install python-pip python-setuptools python-dev python3-dev build-essential libssl-dev libffi-dev` * Official Python library for the IOTA Core: * `$ pip install pyota` * Known issue: [TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'](https://stackoverflow.com/questions/37495375/python-pip-install-throws-typeerror-unsupported-operand-types-for-retry) * Install iota-swarm-node: ```shell $ pip2.7 install cryptography==2.1.4 $ git clone https://github.com/yillkid/iota-swarm-node.git $ cd iota-swarm-node $ python server.py ``` #### 嘗試傳送 0 元交易 ```shell $ cd iota-swarm-node $ python examples/send_data.py ``` ```Send send transfer command ... RXDAJLAPHJ9TXVJWGNYYOFPARCIAHZEUIJYKYHTXEVZA9ZHDIXVIGJHJAQTRSPYGFDEILGFAJLPQWWXBD Duration: 6.59507608414 seconds ```` 您可以隨意將 swarm_node.py 檔案裡的 node 位址換成 [light Wallet Servers](http://iotasupport.com/lightwallet.shtml) 上的任意 node,例如:http://cryptoiota.win:14265 `$ python examples/send_data.py` ```Send send transfer command ... BXCEOILCZNLDACORIWDTKIKJXTSUMYCPHCBFEZRZXIDVCRWECDKRUAWTORBWFFDEGBDWQN9DGLISFF9VZ Duration: 13.4243559837 seconds ``` 在 [Asus Tinker board](asus.com/tw/Single-Board-Computer/Tinker-Board/) 上的測試結果: `$ python examples/send_data.py` ```Send send transfer command ... WIAEHXJUVO9IDZXROJEDBQLFHVFLZCIQKPLLXCGWLNZFIUJZLBZACVLZPWAKUBYLDYRZKFIDKLSAHJHEY Duration: 1.91658091545 seconds ``` ###### tags: iota, swarm-node