【區塊鏈秘技 Day1】快速架設tron 全節點
1. 為甚麼需要架設tron節點?
tronscan提供的api與第三方提供的api都有使用次數的限制,自己架設節點可以避免這個問題。
2. 如何解決?
架設Tron全節點可提高區塊鏈網絡的分散性、參與共識運行、確保交易安全、支援去中心化應用(DApps)的運行,同時有助於獲得網絡獎勵及參與治理,增強Tron生態系統的穩定性和可信度。
3. 電腦配置
一般規格
- CPU: 16核心
- 記憶體: 32G
- SSD: 5T (歷史交易紀錄已經快1.9T)
- 100 MB/s (網路速度)
- linux 作業系統
超級驗證節點規格 (需要加入私鑰,且為tron質押排名前16名才有資格)
- CPU: 32核心
- 記憶體: 64G
- SSD: 5T (歷史交易紀錄已經快1.9T)
- 100 MB/s (網路速度)
- linux 作業系統
tron 全節點架設資訊 java-tron on GitHub.
開始架設
下載tron節點專案
安裝JDK8與JRE8
切換到java-tron資料夾
建立Fullnode.jar檔
切換到java-tron/build/libs路徑底下
建立main_net_config.conf (建立tron 節點的conifg檔,要將main_net_config.conf放置在java-tron/build/libs路徑下)
將官方文件的main_net_config.conf 內容,複製到自己的main_net_config.conf裡面
(https://github.com/tronprotocol/tron-deployment/blob/master/main_net_config.conf)
在main_net_config.conf 裡加入參數搜尋jsonrpc,修改一下參數(註解要移除)
before:
https://hackmd.io/_uploads/SkSAkMOCn.png
after:
https://hackmd.io/_uploads/Sy1QWMuA2.png
(設置的原因: api 要調用50545與8090端口,50545端口需要設定才能開啟,8090本來就打開了)
設定supportConstant為true(預設為false),避免tron在解析合約資料時產生CONTRACT_VALIDATE_ERROR的錯誤。
- before
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- after
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
before
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
-
after
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
運行節點(要先切換到java-tron/build/libs)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
將saveInternalTx設為true(原本是false)
缺點:
經過上述步驟之後,tron節點同步速度非常慢
優化:
- java-tron的DB分成levelDB與rocksDB,conifg 預設為levelDB,官方的歷史交易資料也是使用levelDB。rocksDB可以設置資料備援與叫好的擴充性。levelDB與rocksDB不能混用,會報錯誤。
- 建議下載tron官方的歷史交易資料 (https://backup.trongrid.io/)(https://tronprotocol.github.io/documentation-en/using_javatron/backup_restore/)
- 目前tron官方歷史交易資料為1.9T,下載會很久,建議(多執行續下載)使用指令
- 解壓縮FullNode-54424085–4.7.2-output-directory.tgz
- 解壓縮之後產生一個資料夾(output-directory 內有所有交易資料)
- 查詢資料夾的容量是否正確
- 將output-directory資料夾移動到java-tron/build/libs底下(若有相同檔名就會一個檔案在移動or取代原本的output-directory資料夾)
- 啟動節點同步
- 檢查節點是否在運行
使用api
查詢最新的block數_8090 port & 50545 port
- curl http://192.168.200.159:8090/wallet/getnowblock (192.168.200.159
自己的內部網路IP
,http不加憑證)
- curl -X POST ‘http://192.168.200.159:50545/jsonrpc' — data ‘{“jsonrpc”:”2.0",”method”:”eth_blockNumber”,”params”:[],”id”:64}’
- curl -X POST 'http://192.168.200.159:50545/jsonrpc' — data '{“jsonrpc”:”2.0”,”method”:”eth_blockNumber”,”params”:[],”id”:64} '
參考文件