cchaining / qna

0 stars 0 forks source link

마이닝과 논스에 대한 질문 #2

Open gloryan0829 opened 6 years ago

gloryan0829 commented 6 years ago

Bitcoin을 DeepDive하게 보다 보니 마이닝과 논스에 대한 설명들이 다들 상이해서 질문을 올리게됩니다.

우선 우리 그룹 이성일님께서 몇일 전 마이닝을 하는 과정에서 Nonce 가 Sequential 하게 올라가면서 해시를 찾는 줄 알았는데 Nonce가 Maximum 까지 다 찼을 때 Extra Nonce가 바뀌면서 해시를 찾는다는 것을 알려주셨습니다. 마이닝 시뮬레이션 사이트를 통해 알게된 사실인데요. http://yogh.io/?#mine:last

마이닝을 찾는 과정을 보면 난이도가 예를들어, 해시 앞자리 00000 을 기준으로 한다고 했을 때 Nonce를 계속 올리면서 앞자리가 00000 이상이 나올 때 채굴이 되는 것입니다.

eg) 해시를 만들 때 사용되는 데이터들 -> Nonce, Timestamp, Transaction Data, Previous Hash 등 Nonce 1 -> 0wefwefwefwefwefwef Nonce 2 -> 0fwefwefwefzxdvcsdf2e Nonce 3 -> 00000xjdfkewjefjwefwef <--- 채굴완료

근데 위의 과정에서 Nonce가 다 찼을 때 제가 Udemy쪽에 강의를 본 강사가 설명하기론 Extra Nonce가 아닌 Mempool에서 가져온 채굴 전 임시 Block에서 저장되어있는 Transaction Data 와 Mempool에 추가된 Transaction들 중 Tx Fee(수수료)가 높은 것들을 Swap 해서 다시 Nonce를 0부터 Sequential 하게 올려서 계산하더라고요....

어떤 것이 맞는것인지 궁금합니다.;;

modolee commented 6 years ago

Mastering Bitcoin - Ch10의 The Extra Nonce Solution

The solution was to use the coinbase transaction as a source of extra nonce values. Because the coinbase script can store between 2 and 100 bytes of data, miners started using that space as extra nonce space, allowing them to explore a much larger range of block header values to find valid blocks. The coinbase transaction is included in the merkle tree, which means that any change in the coinbase script causes the merkle root to change. Eight bytes of extra nonce, plus the 4 bytes of "standard" nonce allow miners to explore a total 296 (8 followed by 28 zeros) possibilities per second without having to modify the timestamp.

번역본도 그렇고 github에 올라와 있는 최신판도 그렇고 Extra Nonce를 사용한다고 합니다. 하지만 정확한 확인을 위해서는 코드 분석이 필요할 것 같습니다.

gloryan0829 commented 6 years ago

내용 중 아래와 같이 2012년도 이후 ExtraNonce 를 마이닝 노드인 코인베이스 스크립트에서 제공하여 해결 했네요..!! 감사합니다. 단, 소스는 까봐야알듯...;';' The solution was to use the coinbase transaction as a source of extra nonce values. Because the coinbase script can store between 2 and 100 bytes of data, miners started using that space as extra nonce space, allowing them to explore a much larger range of block header values to find valid blocks. The coinbase transaction is included in the merkle tree, which means that any change in the coinbase script causes the merkle root to change. Eight bytes of extra nonce, plus the 4 bytes of "standard" nonce allow miners to explore a total 296 (8 followed by 28 zeros) possibilities per secondwithout having to modify the timestamp.