Bitcoin Forum
April 25, 2024, 01:15:28 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: A few questions about mining I couldn't find on the wiki...  (Read 1586 times)
Jfqs6m (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile WWW
May 26, 2011, 02:28:55 AM
 #1

Just started with Bitcoin last night and I've been trying to figure out how mining actually works. I'm pretty technically inclined but Cryptography isn't my thing...

So correct me of I'm wrong. When you're "mining" you're computer is essentially guessing a random number, encrypting it, and comparing it to the already encrypted block. The block is encrypted multiple times (millions?) into layers. So every time you decrypt it you remove a layer (much like an onion) then share that news with the rest of the network. Then the next layer is started. I'm guessing that the bitcoins are awarded to the client with the most layers removed once the entire block is decrypted?

So if above is true (Again, I don't know for certain this is just what I assume) then having a CPU based miner makes it physically impossible to get the coins...

Again, if I'm wrong please let me know...

I also know that blocks are basically records of all transactions by the network. How do they get packed into the blocks and encrypted? Are they sent from node to node each adding another layer?

Again, sorry if these have been asked before I couldn't find anything... Thanks in advance!
1714007728
Hero Member
*
Offline Offline

Posts: 1714007728

View Profile Personal Message (Offline)

Ignore
1714007728
Reply with quote  #2

1714007728
Report to moderator
1714007728
Hero Member
*
Offline Offline

Posts: 1714007728

View Profile Personal Message (Offline)

Ignore
1714007728
Reply with quote  #2

1714007728
Report to moderator
1714007728
Hero Member
*
Offline Offline

Posts: 1714007728

View Profile Personal Message (Offline)

Ignore
1714007728
Reply with quote  #2

1714007728
Report to moderator
"There should not be any signed int. If you've found a signed int somewhere, please tell me (within the next 25 years please) and I'll change it to unsigned int." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
SchizophrenicX
Member
**
Offline Offline

Activity: 112
Merit: 100

"I'm not psychic; I'm just damn good"


View Profile
May 26, 2011, 02:35:03 AM
 #2

Hi, the newbies guide has been stickied maybe some of the information that you seek can been found there.

I'm not as technically inclined as you and I'm also new but I'm pretty sure that there is a certain code that needs to be decrypted and once the key to decrypting it is found, the user's whose computer who solves it gets 50 BTC instantly. I guess you can say the computer does guess a certain key to see if it works in that sense.

Anyway as I mentioned, I'm neither technically inclined nor am I experienced enough to tell you how it works. This is just the general idea I've gotten since last week when I joined.

fpgaminer
Hero Member
*****
Offline Offline

Activity: 560
Merit: 517



View Profile WWW
May 26, 2011, 03:16:13 AM
 #3

Quote
So correct me of I'm wrong. When you're "mining" you're computer is essentially guessing a random number, encrypting it, and comparing it to the already encrypted block.
That doesn't sound quite right ... I'll try to explain it. Remember, this is only for mining:

In order to successfully get 50 BTC, or whatever the current reward is, a Bitcoin client must add a block to the current block chain, and show the new block to everyone else. So the first thing the client program does is put together a small data structure that is the block header. This block header contains a copy of the last block's hash, which is why blocks form a chain, and a bunch of other data.

Before this potential block will be considered valid by others, the SHA-256 hash of the block header (actually, only a portion of the header) must be less than or equal to a 256-bit Target. The Target is determined by the current Difficulty.

Obviously, most of the time when the client puts together the block header the hash will not be less than the Target. To "mine" a block the client, or dedicated mining program, must manipulate various fields in the block header in an attempt to find values that make the hash less than the Target. Since SHA-256 generates pseudo-random numbers, and isn't feasibly reversible or predictable, this basically just amounts to brute-forcing.

There is one field in particular, called the Nonce. It's a 32-bit value that miners increment from 0 to 2^32, running the SHA-256 hash each time to check if they've found a Nonce that makes the block header valid.

Once a block header has been found that meets the Target requirement, the bitcoin client can add confirmed transactions to the block and then share it with the rest of the world. Other bitcoin clients can run the SHA-256 on the block header to confirm that this new block is indeed valid.

There's just one more thing. The bitcoin client usually does all the work of putting together the block header and such. Dedicated mining programs can communicate over JSON-RPC with a bitcoin client to ask for "work". The bitcoin client returns only the portion of the block header that actually needs to be worked on, and the miner is only responsible for searching all 2^32 values of the 32-bit Nonce. If it finds a valid Nonce, it can report its findings back to Bitcoin which will finish up constructing the block and submit it to the world. If the miner doesn't find a valid Nonce, it can make another "getwork" request of the bitcoin client, which will change a few fields in the block header and then give new work to the miner.

kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
May 26, 2011, 03:30:11 AM
 #4

fpgaminer has it right except for one tiny detail.

The block of transactions is built first, because the merkle hash of all the transactions is included in the header that the miners work on.  Also, the node will add newly arrived transactions to the block periodically.  Oh, and the node could give totally different blocks out to different miners if it wanted to.

There is a key detail that may not be obvious, but is crucial to understanding the mining process is that there isn't just one true next block that every node is searching for.  Every node is searching for their own unique next block that meets the validity criteria.  Their unique block includes the address that gets the mining reward.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
Jfqs6m (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile WWW
May 26, 2011, 03:44:57 AM
 #5

fpgaminer has it right except for one tiny detail.

The block of transactions is built first, because the merkle hash of all the transactions is included in the header that the miners work on.  Also, the node will add newly arrived transactions to the block periodically.  Oh, and the node could give totally different blocks out to different miners if it wanted to.

There is a key detail that may not be obvious, but is crucial to understanding the mining process is that there isn't just one true next block that every node is searching for.  Every node is searching for their own unique next block that meets the validity criteria.  Their unique block includes the address that gets the mining reward.

Ok, so in theory on my dual core processor, 4gb of RAM laptop could EVENTUALLY get the 50 BTC...?
fpgaminer
Hero Member
*****
Offline Offline

Activity: 560
Merit: 517



View Profile WWW
May 26, 2011, 03:45:43 AM
 #6

Quote
The block of transactions is built first, because the merkle hash of all the transactions is included in the header that the miners work on.
Ahh, okay, so the merkle hash is included in what the miners work on. The spec on the wiki was a little vague and I haven't taken the time to rip open bitcoind to check. Thank you for clearing that up!

fpgaminer
Hero Member
*****
Offline Offline

Activity: 560
Merit: 517



View Profile WWW
May 26, 2011, 03:47:50 AM
 #7

Quote
Ok, so in theory on my dual core processor, 4gb of RAM laptop could EVENTUALLY get the 50 BTC...?
Every time a miner makes another attempt and calculates a new hash, it has the same chance as anyone else for that to be a valid hash (and thus get the tasty 50 BTC). But of course, the more hashes you do per second, the more chances you get per second.

So yeah, your laptop could get lucky. But it'd be safer to bet that it won't solve a block until the sun has exploded.

SchizophrenicX
Member
**
Offline Offline

Activity: 112
Merit: 100

"I'm not psychic; I'm just damn good"


View Profile
May 26, 2011, 03:50:44 AM
 #8

Quote
Ok, so in theory on my dual core processor, 4gb of RAM laptop could EVENTUALLY get the 50 BTC...?
Every time a miner makes another attempt and calculates a new hash, it has the same chance as anyone else for that to be a valid hash (and thus get the tasty 50 BTC). But of course, the more hashes you do per second, the more chances you get per second.

So yeah, your laptop could get lucky. But it'd be safer to bet that it won't solve a block until the sun has exploded.
'
Haha that was awesome fpga. Anyway very detailed explanation on what it actually does although I don't get half of it lolx. How goes your open source project?

Garrett Burgwardt
Sr. Member
****
Offline Offline

Activity: 406
Merit: 256


View Profile
May 26, 2011, 04:08:32 AM
 #9

fpgaminer has it right except for one tiny detail.

The block of transactions is built first, because the merkle hash of all the transactions is included in the header that the miners work on.  Also, the node will add newly arrived transactions to the block periodically.  Oh, and the node could give totally different blocks out to different miners if it wanted to.

There is a key detail that may not be obvious, but is crucial to understanding the mining process is that there isn't just one true next block that every node is searching for.  Every node is searching for their own unique next block that meets the validity criteria.  Their unique block includes the address that gets the mining reward.

Ok, so in theory on my dual core processor, 4gb of RAM laptop could EVENTUALLY get the 50 BTC...?

I could start hashing by hand and theoretically get a block Tongue

And ram has no effect on hashing speed, FYI.
Jfqs6m (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile WWW
May 26, 2011, 04:22:02 AM
 #10

fpgaminer has it right except for one tiny detail.

The block of transactions is built first, because the merkle hash of all the transactions is included in the header that the miners work on.  Also, the node will add newly arrived transactions to the block periodically.  Oh, and the node could give totally different blocks out to different miners if it wanted to.

There is a key detail that may not be obvious, but is crucial to understanding the mining process is that there isn't just one true next block that every node is searching for.  Every node is searching for their own unique next block that meets the validity criteria.  Their unique block includes the address that gets the mining reward.

Ok, so in theory on my dual core processor, 4gb of RAM laptop could EVENTUALLY get the 50 BTC...?

I could start hashing by hand and theoretically get a block Tongue

And ram has no effect on hashing speed, FYI.

Eh, I was just making an example. Hmm, this is kind overwhelming...
w128
Newbie
*
Offline Offline

Activity: 14
Merit: 0



View Profile
May 26, 2011, 04:43:22 AM
 #11

This seems like a good place to ask:

I'm certain I've heard mention that a miner doesn't need to "remember" previously attempted hashes to avoid duplicate work. Why is this true? From the descriptions above it would seem that pools are doing exactly that, dividing up work towards a completed block in an orderly fashion.
kjj
Legendary
*
Offline Offline

Activity: 1302
Merit: 1024



View Profile
May 26, 2011, 04:53:21 AM
 #12

A miner gets a header and starts working on it by running through all of the possible nonce values.  This can take a few seconds to several minutes, depending on the hashing speed of the miner.  If it finds no valid hashes that way, it reports back to the node.  Or, the node can tell the miner to stop, assuming both ends support long polling, by sending out a new header before the miner is done with the first one.

If the miner asks for a new block because it exhausted all of the possible nonces, the node will update the Merkle root hash (by allowing in new transactions, or by updating the nonce in the generation transaction) and/or the timestamp and send it out again.

If the miner was interrupted by a long poll, it usually means that the node heard that someone else got a valid block, so the new work will have a different "last block hash", and the transaction list will be totally different, giving a new Merkle root hash, and the timestamp will (likely) be different.

So, no, the miner doesn't really need to know what it did before, because it will never get that unique combination of bits again.

17Np17BSrpnHCZ2pgtiMNnhjnsWJ2TMqq8
I routinely ignore posters with paid advertising in their sigs.  You should too.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!