Bitcoin Forum
May 06, 2024, 11:59:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: « 1 [2]  All
  Print  
Author Topic: Technical questions about blockchain  (Read 1502 times)
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4616



View Profile
November 05, 2017, 08:56:17 PM
 #21

Hello! Thanks again,

So I think I understood now, but i found this article:

https://samsclass.info/141/proj/BitDiff.htm

where it says:

"Bitcoin miners must find a SHA-256 hash that starts with many zeroes"

So I'm confused now,

That website is wrong.

There is a LOT of incorrect information about bitcoin on the internet.  You should be careful about what information you trust.

i though you told me that the server sends you a challenge (a hash), and the target,  and you (the miner) have to find:

if (sha256(challenge + randomStuff) < target)


If you are mining in a mining POOL, then you will configure your software so that the pool server and your client software agree on the difficulty target that you will work with.

If you are solo mining, then there is no SERVER.  Bitcoin doesn't have any servers, bitcoin is a peer-to-peer system.  In the case of Bitcoin, each node calculates the difficulty target themselves.  They are all using the blockchain as the source of their information, and they are all performing exactly the same calculations, so they all end up calculating the same difficulty.

The difficulty of a current block can be calculated from the "bits" field in the block header.

Here is a more reliable source of information about the difficulty target:
https://en.bitcoin.it/wiki/Difficulty
1714996742
Hero Member
*
Offline Offline

Posts: 1714996742

View Profile Personal Message (Offline)

Ignore
1714996742
Reply with quote  #2

1714996742
Report to moderator
1714996742
Hero Member
*
Offline Offline

Posts: 1714996742

View Profile Personal Message (Offline)

Ignore
1714996742
Reply with quote  #2

1714996742
Report to moderator
Bitcoin addresses contain a checksum, so it is very unlikely that mistyping an address will cause you to lose money.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714996742
Hero Member
*
Offline Offline

Posts: 1714996742

View Profile Personal Message (Offline)

Ignore
1714996742
Reply with quote  #2

1714996742
Report to moderator
1714996742
Hero Member
*
Offline Offline

Posts: 1714996742

View Profile Personal Message (Offline)

Ignore
1714996742
Reply with quote  #2

1714996742
Report to moderator
1714996742
Hero Member
*
Offline Offline

Posts: 1714996742

View Profile Personal Message (Offline)

Ignore
1714996742
Reply with quote  #2

1714996742
Report to moderator
redigaffi (OP)
Member
**
Offline Offline

Activity: 142
Merit: 13


View Profile
November 05, 2017, 09:13:16 PM
 #22

Hello! Thanks again,

So I think I understood now, but i found this article:

https://samsclass.info/141/proj/BitDiff.htm

where it says:

"Bitcoin miners must find a SHA-256 hash that starts with many zeroes"

So I'm confused now,

That website is wrong.

There is a LOT of incorrect information about bitcoin on the internet.  You should be careful about what information you trust.

i though you told me that the server sends you a challenge (a hash), and the target,  and you (the miner) have to find:

if (sha256(challenge + randomStuff) < target)


If you are mining in a mining POOL, then you will configure your software so that the pool server and your client software agree on the difficulty target that you will work with.

If you are solo mining, then there is no SERVER.  Bitcoin doesn't have any servers, bitcoin is a peer-to-peer system.  In the case of Bitcoin, each node calculates the difficulty target themselves.  They are all using the blockchain as the source of their information, and they are all performing exactly the same calculations, so they all end up calculating the same difficulty.

The difficulty of a current block can be calculated from the "bits" field in the block header.

Here is a more reliable source of information about the difficulty target:
https://en.bitcoin.it/wiki/Difficulty

Ok, right, yes there are no servers, but in solo mining, the mining software (the client) must connect to any available bitcoin node to ask for difficulty and a challenge, the miner search a hash that meets the requirements and send it back to a node or many with the hash and his address.

Between, I cant figure out how to adjust the difficulty, right now I implemented the way you told me,

A node sends the miner a target, and the miner has to find a hash below the target.

So just for testing purpose my current target is:

target = 115792089237316195423570985008687907853269984665640564039457584007913129639936 (2^256)

Every 2 block i adjust difficulty, for every 2 block it should need 2 mins, so my ratio would be:

ratio = 2/120 (0,016666667)

So, right now with my current target, 2^256 block are created instantanly, the time what i need to press "mine" button, 2 block are created in 7~ seconds, so actual ratio would be:

actualRatio = 2/7 (0,285714286) ( a lot easier )

At this step i can't figure out how to relation ratio and actualRatio and target to set target to my ratio, to adjust the difficulty.

What do i need to adjust the target with ratio and actualRatio?

Any suggestion?

Many thanks!

Earn Money With Skill while having fun, Answer this 6 questions and get a bonus when the project get's launched:

https://docs.google.com/forms/d/e/1FAIpQLSdCRubC4wu4seHYdDqiZDFsXizqaViUnOtE5sZcx3spjGc84A/viewform
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6581


Just writing some code


View Profile WWW
November 05, 2017, 11:19:03 PM
Merited by ABCbits (2)
 #23

Ok, right, yes there are no servers, but in solo mining, the mining software (the client) must connect to any available bitcoin node
Usually mining software connects to a miners own node, not just any node. Any node likely does not have the required interfaces exposed to the general internet so you can't just connect to any node to get the information.

to ask for difficulty and a challenge, the miner search a hash that meets the requirements and send it back to a node or many with the hash and his address.
No, that's not how mining works.

The mining software will ask the node for the information necessary to construct a block. This is usually the block version, current difficulty, previous block hash, and branches of the merkle tree (including leafs, i.e. transactions themselves). The mining software then constructs the block by assembling the block header and filling in the details that it needs to, e.g. the coinbase transaction with the payout to his own address. When the mining software has completed a block, it then submits the entire block (header and transactions) to the node. It does not give it a hash or many hashes and an address; it gives it the full block usually.

Between, I cant figure out how to adjust the difficulty, right now I implemented the way you told me,

A node sends the miner a target, and the miner has to find a hash below the target.

So just for testing purpose my current target is:

target = 115792089237316195423570985008687907853269984665640564039457584007913129639936 (2^256)

Every 2 block i adjust difficulty, for every 2 block it should need 2 mins, so my ratio would be:

ratio = 2/120 (0,016666667)

So, right now with my current target, 2^256 block are created instantanly, the time what i need to press "mine" button, 2 block are created in 7~ seconds, so actual ratio would be:

actualRatio = 2/7 (0,285714286) ( a lot easier )

At this step i can't figure out how to relation ratio and actualRatio and target to set target to my ratio, to adjust the difficulty.

What do i need to adjust the target with ratio and actualRatio?
I highly suggest that you read the source code in Bitcoin Core that calculates the difficulty for each block: https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp#L13

To calculate the next proof of work, you multiple the last block's target by the amount of time it actually took, then divide it by the time you want it to take. You have a formula that looks like this:
Code:
(Last block's target)/X = (wanted time)/(actual time)
Then you just solve for X. In your example, you would do
Code:
(2^256)/X=7/120
X=(2^256)*120/7
Because we are dealing with integers here and not decimals, this is just the floor of that, so your target would be 1985007244068277635832645457291792706056056879982409669247844297278510793827474 .

redigaffi (OP)
Member
**
Offline Offline

Activity: 142
Merit: 13


View Profile
November 06, 2017, 12:18:54 PM
 #24

Thanks a lot to all.

So, as I understand from this post:
https://bitcointalk.org/index.php?topic=1734235.0

Miners are nodes but they do additional tasks.

But how can this possible, I have mined bitcoins using a client that has less then 20mb of installation size, the blockchain is around 165.30GB

Between, as it is my coin, i can do it the way I like, or just try other methods, right?

There is no "cryptocurrency standard" or is there any?

And about "miners usually construct the block and send it back" Why this way? and not:

The node sends the miner a hash (target) and difficulty and the miner finds a hash that fits the difficulty and send it back to the node, and the node then constructs the block.

Best regards!

Earn Money With Skill while having fun, Answer this 6 questions and get a bonus when the project get's launched:

https://docs.google.com/forms/d/e/1FAIpQLSdCRubC4wu4seHYdDqiZDFsXizqaViUnOtE5sZcx3spjGc84A/viewform
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4616



View Profile
November 06, 2017, 01:13:09 PM
 #25

Thanks a lot to all.

So, as I understand from this post:
https://bitcointalk.org/index.php?topic=1734235.0

Miners are nodes but they do additional tasks.

But how can this possible, I have mined bitcoins using a client that has less then 20mb of installation size, the blockchain is around 165.30GB

In that case you were a participant in a mining pool.  The pool operated the node for you.


Technically, the pool was mining, they were just using your hash power (with your permission) to do it. You were just renting the hash power of your computer to the pool.  The pool then paid you for the use of your hash power.  This is why you got paid even though you never solved a block yourself.

Between, as it is my coin, i can do it the way I like, or just try other methods, right?

It's your software.  You can do whatever you want with it.

It's possible that your ideas will be better than anything anybody else has ever thought of.

It's also possible that your ideas will be much worse than existing coins such as Bitcoin.

There is no "cryptocurrency standard" or is there any?

In my personal opinion, Bitcoin is the ONLY viable cryptocurrency.  The rest are all either scams or interesting experiments.

However, there are many people that have different opinions than mine.  There is no "official" business or agency in charge of setting standards. There are some common design patterns, but if you can come up with an idea that you want to implement, then you can implement it.

And about "miners usually construct the block and send it back" Why this way? and not:

The node sends the miner a hash (target) and difficulty and the miner finds a hash that fits the difficulty and send it back to the node, and the node then constructs the block.

The data that is being hashed is the block header.  Therefore, the header MUST be constructed before you can start hashing.

The header includes a merkle root that commits the transaction list to the header. Therefore, the merkle root MUST be constructed before you can construct the header.

The merkle root is constructed from the block transaction list. Therefore the block transaction list MUST be constructed before you can construct the merkle root.

Once you have constructed the transaction list, merkle root, and block header...  You have constructed the block header.  There is nothing left to do.

redigaffi (OP)
Member
**
Offline Offline

Activity: 142
Merit: 13


View Profile
November 06, 2017, 01:38:23 PM
 #26

Thanks man, sorry for my stupid questions... I thought that i knew how bitcoin architecture is, but every time I've got more questions, I'm software developer since many years, and this project is for pure learning purpose, so I just want to try to make this the most "correct" possible.

I have problems with difficulty adjustments


Following what achow101 has said to calculate time for target:

"you multiple the last block's target by the amount of time it actually took, then divide it by the time you want it to take."

Following this, I have:

lastTarget = 2^256 = 115792089237316195423570985008687907853269984665640564039457584007913129639936

newTarget=(lastTarget*7)/120 = 67545385388434447330416407921734612914407491054956995689683590671282658956 (where the 7 is the time it took to mine 2 blocks)

difficulty = newTarget/LastTarget = 0.00058%

I'm getting a new target, but it's too easy... I can mine with this target in less than 2s, it should be atleast 1m or so...

Best regards


Earn Money With Skill while having fun, Answer this 6 questions and get a bonus when the project get's launched:

https://docs.google.com/forms/d/e/1FAIpQLSdCRubC4wu4seHYdDqiZDFsXizqaViUnOtE5sZcx3spjGc84A/viewform
redigaffi (OP)
Member
**
Offline Offline

Activity: 142
Merit: 13


View Profile
November 10, 2017, 11:42:01 AM
 #27

Hello Again,

So Danny, you said that miners don't search hashes with 0 at the start, but why then all block hash have 0's before? for example:

https://blockexplorer.com/block/0000000000000000008664c500e67e68ecc775868eaad375183a9b92b121abf1

And:

When a node receives a transaction, if the transaction is correct, does the node broadcast the transaction? before being added to a block? or the node just wait till resolving the block and broadcast the block ?

Earn Money With Skill while having fun, Answer this 6 questions and get a bonus when the project get's launched:

https://docs.google.com/forms/d/e/1FAIpQLSdCRubC4wu4seHYdDqiZDFsXizqaViUnOtE5sZcx3spjGc84A/viewform
DannyHamilton
Legendary
*
Offline Offline

Activity: 3388
Merit: 4616



View Profile
November 10, 2017, 01:34:27 PM
 #28

    Hello Again,

    So Danny, you said that miners don't search hashes with 0 at the start, but why then all block hash have 0's before? for example:

    https://blockexplorer.com/block/0000000000000000008664c500e67e68ecc775868eaad375183a9b92b121abf1

    Because the hash has to be lower than the target value.

    During the time in which that block was mined, the target was:
    0x000000000000000000c1bd000000000000000000000000000000000000000000

    And this value:
    0x0000000000000000008664c500e67e68ecc775868eaad375183a9b92b121abf1

    is less than that target.

    Note that the following value:
    0x000000000000000000e673b61ff56f79fbd866759f9be284292b8ca3a230bce0

    has the same number of zeros, but is NOT valid, because it is higher than the target value.

    And:

    When a node receives a transaction, if the transaction is correct, does the node broadcast the transaction? before being added to a block?

    Full nodes validate transactions and then send the transaction to all connected peers that have not yet received the transaction.

    This is why you see a transaction that was sent to you immediately, before it is confirmed.  The sender didn't necessarily connect directly to your node (how would they know where to connect to?).  Instead they sent the transaction to the peers they were connected to, and those peers sent it to the peers they were connected to, and those peers sent it to the peers they were connected to, and so on until it got sent to a peer that you are connected to, and that peer sent it to you.

    Note that this is also how the miners and mining pools find out about the transactions so that they can add them to their blocks.  Nodes and wallets don't need to know the IP address of EVERY miner on the system.  For that matter, they don't need to know the IP address of ANY miners on the system. They just send the transaction to the peers they happen to be connected to.  The transaction gets relayed throughout the network and eventually miners hear about the transaction from the peers that they are connected to.  Then they can add the transaction to the block they are working on if they want to.

    Thanks man, sorry for my stupid questions...

    No stupid questions.  We aren't born understanding the Bitcoin protocol.  It's something that we learn.  Sometime we learn it through reading documentation or the source code itself, and sometimes we have others clarify and explain the pieces that we don't understand.

    I would suggest, however, that you take some time to read about the protocol.  If you ONLY learn from the things that you think to ask, then you are NEVER going to learn the things that you aren't aware that you need to ask about.

    Since you are a "software developer since many years", then I STRONGLY suggest you take a look at the source code of a full node implementation.  You'll get a much better understanding of exactly what it is doing.

    I have problems with difficulty adjustments
    . . .

    I'm getting a new target, but it's too easy... I can mine with this target in less than 2s, it should be atleast 1m or so...

    You are saying that it took 7 seconds to mine a block, and then after increasing the difficulty you were able to mine the blocks even faster (2 seconds)?

    There are a couple of possibilities that come immediately to mind here...

    1.  Perhaps you are miscalculating the amount of time that your software spent actually calculating hashes?  If you are including the amount of time that it takes for your software to load up into RAM and to build the block, and to output that block to you, then you are including a LOT of variable time that could be different every time you run the program.  On such a small timescale those variable times have a larger influence on total time than the block hashing has.  Possible solutions would be:
    • Try timing how long it takes to solve 2000 blocks, and then adjust your difficulty
    • Start with a MUCH lower target so that hashing is a larger percentage of the processing time
    • Iterate multiple adjustments to see if it eventually starts growing appropriately as hashing becomes an ever larger percentage of processing time

    2. You are not properly comparing target to hash?  It is possible that you have a bug in your code that is causing it to exit your hashing loop before it has found a low enough hash value. Possible method to determine this would be:

    • Print out both the target and the solution hash when your software finishes processing a block so you can compare the values yourself and see if they are correct
    Pages: « 1 [2]  All
      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!