Mining

แปลโดย : Claude 3 Opus (Pro)

Mining

Because a Bitcoin block would only be considered valid if it didn’t include conflicting transactions, the block chain offered the beginning of a solution to the double-spend problem. Even if different users would see transactions in a different order, their ownership records would still be in consensus as long as they all received the blocks in the same order. In the event of a double-spend attempt, only the transaction that was included in a block would be used to update all ledgers.

Still, this didn’t quite solve the double-spend problem entirely. After all, if different users create different blocks (potentially with conflicting transactions in these different blocks), and the different blocks are sent to different parts of the network simultaneously, the exact same problem would resurface: the network would split.

And since each next block would include the previous block hash, this would even mean that different parts of the network would end up creating entirely different, incompatible block chains, over time probably causing different users to update their ownership records differently, and permanently fall out of consensus. Users on the different parts of the network would be unable to transact with each other.

Nakamoto knew that all Bitcoin users would have to converge on the same block chain—even if that meant that some users had to occasionally abandon the blocks they received first in case of a conflict. But with potentially dishonest participants and no one in charge, determining which block chain to settle on was—again—a great example of the Byzantine Generals Problem.

This is where Adam Back’s proof-of-work system came in, with his original hashcash proposal representing the next reference in the Bitcoin white paper. Proof of work had by then already formed the basis of several Cypherpunk digital currency designs, of course, including b-money as well as Bit Gold and RPOW. But where these designs had typically used the proof of work hashes themselves as a form of money, Nakamoto, in what was one of his key insights, had figured out an ingenious new use for it.

Proof of work would be used as a consensus mechanism.

Besides a batch of transactions and the previous block hash, Bitcoin blocks would include a third ingredient: a nonce. This random number would be hashed along with the rest of the contents of a block to generate the block hash. The proof-of-work trick, then, was that not every block would be considered valid. Only blocks with a block hash starting with some predetermined number of zeroes would be accepted by the network of users.

Just like producing hashcash, the only way to find a valid block would be through trial and error, a process that Satoshi Nakamoto would later call “mining.” Mining users (or “miners”) would need to randomly try including many different nonces in a block they wanted to construct, until one of them would result in the generation of a valid block hash. A valid block—which could not be edited by anyone after it was produced, since that would also change the block hash—would then be sent across the network, where each user would update their ownership records with the transactions in this block.

Miners, meanwhile, would switch their mining efforts to include the new block hash in a potential next block, which would in turn require its own valid block hash. Similar to how Bit Gold users (and presumably b-money users) would produce a cryptographic chain of hashes to create currency, with each valid hash serving as the candidate string for the next, Bitcoin miners would produce a cryptographic chain of block hashes.

And crucially: the length of this chain would serve as the tie-breaker in case of a conflict.

In the event that two conflicting blocks would circulate over the Bitcoin network, every user would initially accept the block they received first, and miners would include its block hash in the next block they’d try to mine. In a sense, the Bitcoin network would, indeed, split. But this split would be temporary. As soon as one side of the split mines the next block quicker than the other side of the split, and their version of the block chain grows longer than the alternative, Bitcoin users and miners from both sides of the split would settle on this longest chain, abandoning the shorter chain and thus resolving the split.

To overcome the Byzantine Generals Problem, Satoshi Nakamoto cleverly repurposed proof of work as a decentralized tie-breaker to reach consensus. Exactly because anyone can produce proof of work, and because anyone can easily check its validity without needing to trust anyone else, it was perfectly compatible with Bitcoin’s leaderless design.

“The network is robust in its unstructured simplicity,” Nakamoto concluded his white paper. “Nodes work all at once with little coordination.”

การขุด

เนื่องจากบล็อกของบิตคอยน์จะถือว่าใช้ได้ก็ต่อเมื่อไม่มีธุรกรรมที่ขัดแย้งกัน บล็อกเชนจึงนำเสนอจุดเริ่มต้นของการแก้ปัญหาการใช้จ่ายซ้ำ (double-spend) แม้ผู้ใช้ต่างคนจะเห็นธุรกรรมในลำดับที่แตกต่างกัน แต่บันทึกกรรมสิทธิ์ของพวกเขาจะยังคงเห็นพ้องต้องกัน ตราบใดที่ทุกคนได้รับบล็อกในลำดับเดียวกัน ในกรณีที่มีความพยายามใช้จ่ายซ้ำ ก็จะมีเพียงธุรกรรมที่อยู่ในบล็อกเท่านั้นที่ถูกใช้เพื่ออัปเดตบัญชีแยกประเภททั้งหมด

กระนั้นก็ตาม สิ่งนี้ก็ยังไม่ได้แก้ปัญหาการใช้จ่ายซ้ำได้อย่างสมบูรณ์ ท้ายที่สุดแล้ว หากผู้ใช้ต่างคนสร้างบล็อกต่างกัน (อาจมีธุรกรรมที่ขัดแย้งกันในบล็อกที่ต่างกัน) และบล็อกที่แตกต่างกันถูกส่งไปยังส่วนต่างๆ ของเครือข่ายพร้อมกัน ปัญหาเดิมก็จะผุดขึ้นมาอีก นั่นคือ เครือข่ายจะแยกออกจากกัน

และเนื่องจากบล็อกถัดไปแต่ละบล็อกจะรวมแฮชของบล็อกก่อนหน้าด้วย สิ่งนี้จะหมายความว่าส่วนต่างๆ ของเครือข่ายจะสร้างบล็อกเชนที่แตกต่างกันโดยสิ้นเชิงและเข้ากันไม่ได้ในที่สุด ตามเวลาที่ผ่านไป อาจทำให้ผู้ใช้ต่างคนอัปเดตบันทึกกรรมสิทธิ์ของตนแตกต่างกัน และตกอยู่ในความเห็นที่ไม่ลงรอยอย่างถาวร ผู้ใช้ในส่วนต่างๆ ของเครือข่ายจะไม่สามารถทำธุรกรรมระหว่างกันได้

นากาโมโต้รู้ว่าผู้ใช้บิตคอยน์ทุกคนจะต้องมาบรรจบที่บล็อกเชนเดียวกัน แม้ว่าจะหมายความว่าผู้ใช้บางคนต้องยอมทิ้งบล็อกที่ได้รับก่อนในกรณีที่มีความขัดแย้งก็ตาม แต่ด้วยผู้ร่วมที่อาจไม่ซื่อสัตย์และไม่มีใครเป็นผู้ควบคุม การตัดสินว่าจะเลือกใช้บล็อกเชนใดนั้น อีกครั้ง เป็นตัวอย่างที่ดีของปัญหาเหล่านายพลไบแซนไทน์

นี่คือที่ที่ระบบ proof-of-work ของอดัม แบ็ก เข้ามามีบทบาท โดยข้อเสนอ hashcash ดั้งเดิมของเขาเป็นอ้างอิงถัดไปในเอกสารไวท์เปเปอร์บิตคอยน์ แน่นอนว่า proof of work ได้เป็นพื้นฐานของการออกแบบสกุลเงินดิจิทัลของไซเฟอร์พังค์หลายแบบในตอนนั้นแล้ว รวมถึง b-money ตลอดจน Bit Gold และ RPOW แต่ในขณะที่การออกแบบเหล่านี้มักใช้แฮช proof of work เองเป็นรูปแบบของเงิน นากาโมโต้ ในหนึ่งในข้อค้นพบสำคัญของเขา ได้คิดค้นการใช้งานแบบใหม่ที่ชาญฉลาดสำหรับมัน

Proof of work จะถูกใช้เป็นกลไกสร้างฉันทามติ (consensus mechanism)

นอกจากชุดธุรกรรมและแฮชบล็อกก่อนหน้าแล้ว บล็อกของบิตคอยน์ยังมีส่วนประกอบที่สาม นั่นคือ nonce ตัวเลขสุ่มนี้จะถูกแฮชพร้อมกับเนื้อหาส่วนที่เหลือของบล็อกเพื่อสร้างแฮชของบล็อก จากนั้น กลเม็ด proof-of-work คือ ไม่ใช่ทุกบล็อกจะถือว่าใช้ได้ เฉพาะบล็อกที่มีแฮชของบล็อกขึ้นต้นด้วยศูนย์จำนวนที่กำหนดไว้ล่วงหน้าเท่านั้นที่จะได้รับการยอมรับจากเครือข่ายผู้ใช้

เหมือนกับการผลิต hashcash วิธีเดียวที่จะหาบล็อกที่ใช้ได้คือการลองผิดลองถูก ซึ่งซาโตชิ นากาโมโต้ ภายหลังเรียกกระบวนการนี้ว่า "การขุด (mining)" ผู้ใช้ที่ขุด (หรือ "คนขุด") จะต้องลองสุ่มใส่ nonce หลายตัวในบล็อกที่พวกเขาต้องการสร้าง จนกว่าจะได้ nonce ตัวหนึ่งที่ทำให้เกิดแฮชบล็อกที่ใช้ได้ บล็อกที่ใช้ได้ ซึ่งไม่มีใครแก้ไขได้หลังจากสร้างแล้ว เพราะนั่นจะเปลี่ยนแฮชบล็อกด้วย จะถูกส่งไปทั่วเครือข่าย ซึ่งผู้ใช้แต่ละคนจะอัปเดตบันทึกกรรมสิทธิ์ของตนด้วยธุรกรรมในบล็อกนี้

ในขณะเดียวกัน คนขุดจะเปลี่ยนไปใช้แฮชบล็อกใหม่ในการขุดบล็อกถัดไป ซึ่งก็จะต้องมีแฮชบล็อกที่ใช้ได้ของตัวเองด้วย คล้ายกับที่ผู้ใช้ Bit Gold (และอาจรวมถึงผู้ใช้ b-money ด้วย) จะผลิตห่วงโซ่แฮชแบบเข้ารหัส เพื่อสร้างสกุลเงิน โดยแต่ละแฮชที่ใช้ได้จะเป็นตัวเลือกสายอักขระสำหรับแฮชถัดไป คนขุดบิตคอยน์จะผลิตห่วงโซ่แฮชของบล็อกแบบเข้ารหัส

และที่สำคัญ: ความยาวของห่วงโซ่นี้จะใช้ตัดสินกรณีที่มีความขัดแย้ง

ในกรณีที่มีบล็อกขัดแย้งกันสองบล็อกหมุนเวียนอยู่ในเครือข่ายบิตคอยน์ ผู้ใช้ทุกคนจะยอมรับบล็อกที่ได้รับเป็นบล็อกแรก และคนขุดจะใส่แฮชบล็อกนั้นในบล็อกถัดไปที่พวกเขาจะลองขุด ในแง่หนึ่ง เครือข่ายบิตคอยน์จะแยกจากกันจริงๆ แต่การแยกนี้จะเป็นเพียงชั่วคราว ทันทีที่ฝ่ายหนึ่งของการแยกขุดบล็อกถัดไปได้เร็วกว่าอีกฝ่ายหนึ่งของการแยก และบล็อกเชนฉบับของพวกเขายาวกว่าฉบับทางเลือก ผู้ใช้บิตคอยน์และคนขุดทั้งสองฝ่ายของการแยกจะตกลงใช้เชนที่ยาวที่สุดนี้ โดยละทิ้งเชนที่สั้นกว่าไป ซึ่งก็คลี่คลายปัญหาการแยกตัว

เพื่อเอาชนะปัญหาเหล่านายพลไบแซนไทน์ ซาโตชิ นากาโมโต้ได้ปรับเปลี่ยนวิธีใช้ proof of work อย่างชาญฉลาดให้เป็นตัวตัดสินแบบกระจายศูนย์เพื่อสร้างฉันทามติ ก็เพราะใครก็ผลิต proof of work ได้ และใครก็ตรวจสอบความถูกต้องได้ง่ายโดยไม่ต้องไว้ใจใคร มันจึงเข้ากันได้อย่างลงตัวกับการออกแบบแบบไร้ผู้นำของบิตคอยน์

"เครือข่ายนี้แข็งแกร่งในความเรียบง่ายที่ไร้โครงสร้าง" นากาโมโต้สรุปไว้ในท้ายเอกสารไวท์เปเปอร์ "โหนดทำงานพร้อมกันทั้งหมดโดยมีการประสานงานกันเพียงเล็กน้อย"

Last updated