Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start a new blockchain #8

Open
mchliu opened this issue Jun 28, 2016 · 141 comments
Open

start a new blockchain #8

mchliu opened this issue Jun 28, 2016 · 141 comments

Comments

@mchliu
Copy link

mchliu commented Jun 28, 2016

請問 @iblis17 大大
目標是要建一個新的區塊鏈
聽你說目前是會連到原本的區塊鏈

所以我們要建一個新的是要把網路斷掉嗎?

阿實際該如何執行哩

@iblislin
Copy link
Member

iblislin commented Jun 28, 2016

我估計要修改 zmq 這塊的 code

  1. ZMQ is a third-party lib. So try to figure out the conecpt of zmq first.
  2. Read some ZMQ API sample.
  3. Start to find out how bitcoin using ZMQ. Find out where is the API call in this bitcoin repo.

@iblislin
Copy link
Member

iblislin commented Jun 28, 2016

Sorry for eng message. My IME is broken on this machine

@iblislin
Copy link
Member

I guess here is a good start point:
https://github.com/APCLab/bitcoin/blob/master/src/net.cpp

@mchliu
Copy link
Author

mchliu commented Jun 28, 2016

NVM
LET ME SEE SEE

@hychang23
Copy link

@iblis17 你的意思是說看完這份嗎?還是說要找什麼東西

@iblislin
Copy link
Member

iblislin commented Jun 30, 2016

@HuaYang-Chang
Please figure out the following question.
There is lots of API in net.cpp. Do not read the implementation first. Just show me:

  1. Which files are using net.hpp? Just show me a list of file name.
  2. Which api from net.hpp is invoked? Please show the chain of invoking.

Do NOT read the implementation, now, we only need to understand the architecture.

@HuaYang-Chang I guess 5 hr is enough for drawing this big picture. Doxygen may help you. Can you make it?

@mchliu
Copy link
Author

mchliu commented Jun 30, 2016

@iblis17 我們找到了
在doxygen上都有
要全列出來嗎?
還是要接下一個任務了

@iblislin
Copy link
Member

OK, I figured out it already:
The machinery is here: https://bitcoin.org/en/developer-guide#peer-discovery

The hard-coded DNS seed is here: https://github.com/bitcoin/bitcoin/blob/d612837814020ae832499d18e6ee5eb919a87907/src/chainparams.cpp#L117-L122.

Also found some doc about dns seed operators: https://github.com/bitcoin/bitcoin/blob/a6a860796a44a2805a58391a009ba22752f64e32/doc/dnsseed-policy.md

In order to build our own network, we can simply bypass the bootstrapping via DNS. We do not need DNS, we only need to provide a hard-coded peers.dat (this file is a BDB file). And bitcoin core will load the peers from it.

@mchliu So now please fetch a normal peers.dat from bitcoin network first. Exam the BDB file, then create a custom one for us.

@mchliu
Copy link
Author

mchliu commented Jun 30, 2016

@iblis17 It's kind of hard for us to understand what u're saying although u said it cleary.

We don't really understand the whole structure of this whole network, so we can't understand what all these information that u mentioned is about, including what DNS seed is and what it's for.

Do u mind telling us its brief ideas? Or we can also try ask google some question.

@iblislin
Copy link
Member

@mchliu The description on developer wiki (the link is previous mentioned) is quite clear already. Please try to understand it first.
I think it already provide enough info about connection to peers.

After reading it, we tell me how to make bitcoin core connect to our own peer based on the machinery the wiki revealed to you.

@mchliu
Copy link
Author

mchliu commented Jul 1, 2016

@iblis17
喔就把連的節點換掉阿^^

就 RPC getpeerinfo 不是會看到是連那些節點

就在code裡換成你想連的,都不連就變自己一條blockchain

@mchliu
Copy link
Author

mchliu commented Jul 1, 2016

@iblis17
我去問了一下我同學他是JOHN說

@iblislin
Copy link
Member

iblislin commented Jul 1, 2016

@mchliu 對啊

@mchliu 我看不懂你後面那篇回覆

@mchliu
Copy link
Author

mchliu commented Jul 4, 2016

@iblis17 下面那則不重要啦哈
所以我們有需要改變方針嗎
還是繼續照你說的研究

@iblislin
Copy link
Member

iblislin commented Jul 4, 2016

@mchliu 是啊

  1. 就是 peer descovery bypass 掉, 想辦法把這 dns seed code 砍掉
  2. 製作 custom 版本的 peers.data

@mchliu
Copy link
Author

mchliu commented Jul 5, 2016

@iblis17 今晚也要是嘛

@iblislin
Copy link
Member

iblislin commented Jul 5, 2016

@mchliu 對啊

@mchliu
Copy link
Author

mchliu commented Jul 5, 2016

@iblis17 2130?

@iblislin
Copy link
Member

iblislin commented Jul 5, 2016

@mchliu ok

@hychang23
Copy link

hychang23 commented Jul 6, 2016

@iblis17
我在執行bitcoind -daemon時出現
Error: Unable to start HTTP server. See debug log for details.
你知道哪裡出狀況嗎?

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

@mchliu 這我當然不會知道。

試試把 之前在 background 跑的 bitcoind kill 掉

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

ps aux | grep bitcoind

找到 pid 之後 kill

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

@mchliu unix 的基礎知識 想辦法會啊....

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

@mchliu 除非你現在跟我說「我不碰任何 open source software」,那麼不會就沒差

@mchliu
Copy link
Author

mchliu commented Jul 6, 2016

@iblis17 你怎麼都TAG我哈哈哈哈
@HuaYang-Chang

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

Ha, 看錯

@mchliu
Copy link
Author

mchliu commented Jul 6, 2016

@iblis17
BTW
這些基本知識應該去哪邊吸收阿
我也是不會 :v
因為我又遇到昨天的那個already running 的問題了哈
胡搞瞎搞中

@iblislin
Copy link
Member

iblislin commented Jul 6, 2016

@mchliu 上次說的鳥哥還記得嘛?

@mchliu
Copy link
Author

mchliu commented Jul 6, 2016

@iblis17 還是鳥哥是吧
OK

@iblislin
Copy link
Member

@mchliu 要砍掉 block 就是三臺機器的 .bitcoin 資料夾 都 rm 掉

@hychang23
Copy link

除了劉銘騏那台 其他都還沒更新到no checkpoint那份
要重新裝嗎?

@iblislin
Copy link
Member

@HuaYang-Chang 當然請重編!

@mchliu
Copy link
Author

mchliu commented Jul 14, 2016

@iblis17
我直接砍.bitcoin
連PEER都沒了block也沒了

@yuanintw
Copy link

剛剛跟熊貓討論我們昨天的問題,總結來說,就是當所有有驗證能力的節點都互相絕對信任(白名單)時,就不須用到區塊鏈設計。

熊貓提出的想法是,聯盟鏈中的所有成員(銀行或其他單位)不要互相信任,這同時也避免了其中一家銀行被駭入後會瞬間造成及時結算機制崩潰的問題。所以聯盟練的創始會員(節點),都要透過區塊鏈設計去驗證、挖礦,而驗證報酬與挖礦獎勵可以換算成某種積分,當一年或是一段時間後,積分低於標準的銀行就要補繳會費。

大概就這樣,如果有任何問題再討論吧

@hychang23
Copy link

@mchliu
140.113.31.208
140.113.72.25:8553
addnode一下

@mchliu
Copy link
Author

mchliu commented Jul 14, 2016

@HuaYang-Chang 還沒搞定阿
而且你也可以加阿我也適用72.25阿

@mchliu
Copy link
Author

mchliu commented Jul 14, 2016

@yuanintw
透過區塊鏈設計去驗證<------其實這裡我不太明白

例如某筆資料被銀行A放在區塊1
其他銀行BCDEF..........為了算區塊2所以都得驗證這筆資料

那不就又回到原點了

@hychang23
Copy link

@mchliu 都加了 但是還看不到你 你好了的話測試看看

@mchliu
Copy link
Author

mchliu commented Jul 15, 2016

@HuaYang-Chang
不是啊我就是用72.25阿

@mchliu
Copy link
Author

mchliu commented Jul 15, 2016

@iblis17
powlimit好像是target不得大於(還是小於)這個
好像不是主要需要改的地方

@iblislin
Copy link
Member

hmm... 我底下有找到用 powlimit 計算出 target 的 code

@iblislin
Copy link
Member

我之後找找

@mchliu
Copy link
Author

mchliu commented Jul 15, 2016

@iblis17
真假的
是target還是difficulty阿
好啊拜託囉

@yuanintw
Copy link

powlimit是控制target與難度的換算
難度的算法是目前的target跟powlimit的比例再去換算

target才是真正影響挖礦速度的值 至於要改那個我晚點會再trace一下

@yuanintw
Copy link

@iblis17 @mchliu
powlimit好像會影響著target調高難度時 提昇量的多寡
若powlimit越大 提昇難度一次就會調多一點

@iblislin
Copy link
Member

哦哦

@mchliu
Copy link
Author

mchliu commented Jul 15, 2016

所以現在最難搞的應該就是找出他把target存在哪裡哀哀

@yuanintw
Copy link

我trace了一下:

比對nouce跟target的function在src/pow.cpp#L77
而target的計算是透過區塊頭資訊nBits換算而成
詳細說明請參考WIKI:https://en.bitcoin.it/wiki/Difficulty

依照WIKI中的範例 假如nBits = 0x1b0404cb
實際上要視為"1b" 跟 "0404cb"
"1b"是拿來truncated用的 truncated中文的意思我不太會說
它的目的就是因為traget很長 但是後面的位數不太有意義 因為前面幾位數就決定了數字大小
舉例來說5 * 10^13 "0404cb"對應5 "1b"對應13
所以在WIKI中他有寫出換算公式 0x0404cb * 2^(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000
換算程式在src/arith_uint256.cpp#L204

預設最大(最簡單)的nBits為0x1d00ffff target為0x00000000FFFF0000000000000000000000000000000000000000000000000000

difficulty = 0x00000000FFFF0000000000000000000000000000000000000000000000000000/target

用WIKI的範例taeget的難度就是0x00000000FFFF0000000000000000000000000000000000000000000000000000 /
0x00000000000404CB000000000000000000000000000000000000000000000000
= 16307.420938523983

理論上只要調整nBits的數字 就可以改變target進而改變運算速度
我在/qa/rpc-tests/test_framework/blocktools.py#L19 有trace到
block.nBits = 0x207fffff # Will break after a difficulty adjustment...
我們可以模仿這個用戶端的測試時的設定 把nBits設定成0x207fffff
應該會挖超快 但是他也有特別提到說在難度調整時 程式會炸掉 所以下一個工作可能是要修改或關閉難度調整的CODE

@mchliu
Copy link
Author

mchliu commented Jul 16, 2016

@yuanintw
YEP跟我想的一樣
可是nBits到底在哪裡勒..........

BTW
我問GCOIN的人他們好像沒調整過這個
他們主要是改timespan跟timespacing
改這個感覺就超越他們一步了

我看的wiki裡面好像有說它是存成一個浮點數
到底在哪兒呢

@hychang23
Copy link

nBits is the encoded form of the target threshold as it appears in the block header

@mchliu
Copy link
Author

mchliu commented Jul 16, 2016

@HuaYang-Chang 嗯?

@yuanintw
Copy link

src/pow.cpp#L13 是判斷即將要挖的區塊 是否需要做難度調整
  若是即將要挖的是第一個區塊 nBit值為powLimit設定的壓縮表示
  若要挖的非第一個區塊且不需做難度調整 則沿用上一區塊的nBits設定
  若要挖的非第一個區塊但需做難度調整 則呼叫src/pow.cpp#L52進行計算

實際測試可能要麻煩@HuaYang-Chang或@mchliu幫忙試試看
我還沒設定遠端206那台電腦的帳號

@mchliu
Copy link
Author

mchliu commented Jul 17, 2016

昨天試過的情況是
改過了genesis block裡面的nBits
然後很多assert的地方會爆掉(make時會出錯)
所以註解掉一些(or直接給他true)
BUT
make完終於打開bitcoind之後
所有RPC指令都掛掉
都出現can't connect to bitcoin之類的錯誤訊息

GOOGLE了一下可能是因為程式裡有一些檢查機制
發現不通過就不給用那些API
SO
Kind of stuck now

@hychang23
Copy link

@iblis17 help

@iblislin
Copy link
Member

@HuaYang-Chang 晚上你們在嗎?

@hychang23
Copy link

@iblis17 學校還是sk?

@iblislin
Copy link
Member

人在學校 晚餐後過去

@hychang23
Copy link

okok 大約幾點呢

@iblislin
Copy link
Member

7點半 或 8點後了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants