Bitcoin Forum
April 26, 2024, 11:58:53 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin block creation !!??  (Read 283 times)
Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 04, 2019, 01:12:28 PM
 #1

Hello someone would know how a bitcoin block is made it is

I know you have to take all the transactions but I don't know what to do with them afterwards.

and can we create a block with the desired number of transactions?

thank you to you
The Bitcoin software, network, and concept is called "Bitcoin" with a capitalized "B". Bitcoin currency units are called "bitcoins" with a lowercase "b" -- this is often abbreviated BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714132733
Hero Member
*
Offline Offline

Posts: 1714132733

View Profile Personal Message (Offline)

Ignore
1714132733
Reply with quote  #2

1714132733
Report to moderator
1714132733
Hero Member
*
Offline Offline

Posts: 1714132733

View Profile Personal Message (Offline)

Ignore
1714132733
Reply with quote  #2

1714132733
Report to moderator
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4165


View Profile
February 04, 2019, 01:16:12 PM
 #2

The miner assembles a set of transaction and hashes them. This creates a merkle root which is ultimately included in the block header of the block. With the block header, the hash of the block is obtained by hashing the block header. Only if the hash meets the target of the network, then it would be considered valid.

This doesn't emcompass the whole process but it does roughly cover the idea about how the transactions is used in the block hashing.

The miner has the rights to the number of transactions and which transaction he wishes to include. The least number of transaction is 1 and the maximum is up till the block weight is reached.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 04, 2019, 01:50:48 PM
 #3

but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4165


View Profile
February 04, 2019, 01:55:42 PM
 #4

but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?
Bitcoin uses SHA256D. The actual hash is just SHA256(SHA256 (Block Header)). The block header consists of the version, nounce, timestamp, merkle root, hash of previous block and target.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 04, 2019, 02:02:43 PM
 #5

sha256(sha256(000000000000000000141653129dd4eb836978acc3c60e10e13ae53788aff716))       

result = next block  Roll Eyes
ranochigo
Legendary
*
Offline Offline

Activity: 2954
Merit: 4165


View Profile
February 04, 2019, 02:32:44 PM
 #6

sha256(sha256(000000000000000000141653129dd4eb836978acc3c60e10e13ae53788aff716))       

result = next block  Roll Eyes
The result you will get is just a (double) hash of the hash of another block header. This won't yield you anything at all.

You need to hash an actual block header (complete with all of the components of the blocks you are mining) for the block to be valid. The network will obtain the block header and hash it. If it doesn't meet the target, then it would be rejected.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
HeRetiK
Legendary
*
Offline Offline

Activity: 2912
Merit: 2080


Cashback 15%


View Profile
February 04, 2019, 03:23:18 PM
Merited by bones261 (3), dothebeats (2), HCP (2), joniboini (1)
 #7

but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?

It's:
SHA256( SHA256( Version + hashPrevBlock + hashMerkleRoot + Time + Target + Nonce ) )

With the Merkle Root being the set of all transactions reduced to a single a hash:
https://www.mycryptopedia.com/merkle-tree-merkle-root-explained/

The Bitcoin wiki has a good description of what is contained in the block header:
https://en.bitcoin.it/wiki/Block_hashing_algorithm

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 04, 2019, 03:38:52 PM
 #8

but what is the actual calculation used?
sha256 (number of transactions + nonce + prev bloc)..............................?

It's:
SHA256( SHA256( Version + hashPrevBlock + hashMerkleRoot + Time + Target + Nonce ) )

With the Merkle Root being the set of all transactions reduced to a single a hash:
https://www.mycryptopedia.com/merkle-tree-merkle-root-explained/

The Bitcoin wiki has a good description of what is contained in the block header:
https://en.bitcoin.it/wiki/Block_hashing_algorithm


okok thank you

Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 05, 2019, 01:10:50 PM
 #9

Why algo for next Block ??
And Can we find a block 2 months ago
bitmover
Legendary
*
Offline Offline

Activity: 2282
Merit: 5887


bitcoindata.science


View Profile WWW
February 05, 2019, 01:46:54 PM
 #10

Why algo for next Block ??
And Can we find a block 2 months ago

You can track any block since Genesis block (2009) using any block explorer, such as blockchain.info
Just Go browsing through blocks and look at timestamp to see the date.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Altcryptocoin (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
February 05, 2019, 02:01:45 PM
 #11

Code:
from hashlib import sha256
import hashlib
version = "00000020"
previoushash = "823a1913f9e43541545befa600134906819ea60ecfe71e000000000000000000"
merkleroot = "f717f1770bfcf49e72e58f28f1b7c53247a8235933fea24823687655009265ec"
timestamp = "3983595c"
bits = "15683017"
nonce = "f2a164a0"
header = (str(version) + str(previoushash) + str(merkleroot) + str(timestamp) + str(bits) + str(nonce)).decode('hex')
          
print sha256(sha256(header).digest()).digest()[::-1].encode('hex')

for next block

version = "00000020"                                                                                                                              OK
previoushash = "0000000000000000000a93736d47dbfecc769c598931b56a63f2c7547a700229"   inversed                OK
merkle root = sha256(transaction(s))                                                                                                         OK
timestamp = in the future                                                                                                                        OK
bits = random Huh                                                                                                                               NO OK
nonce = random Huh                                                                                                                            NO OK


create new block possible with genesis :
python genesis.py -z "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" -n 2083236893 -t 1231006505
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
February 06, 2019, 01:48:02 AM
 #12

Isn't it just the merkle root you hash?

Edit: it's just the merkle root that is hashed!

It blocks act as a merkle tree then to get that hash you do a double hash of the txid of the first transaction.
So you hash the hex digest as a sha256(sha256(genesisTxIDHex+genesisTxIDHex)).

If there's an odd number of nodes like in this case, the last node (incidentally the first) must be duplicated.
HeRetiK
Legendary
*
Offline Offline

Activity: 2912
Merit: 2080


Cashback 15%


View Profile
February 06, 2019, 09:30:07 AM
Merited by ABCbits (2)
 #13

bits = random Huh                                                                                                                               NO OK
nonce = random Huh                                                                                                                            NO OK

bits is not random, it's the current difficulty target:
https://en.bitcoin.it/wiki/Target

This will stay the same on the next block unless the difficulty changes, which happens every 2016 blocks (ie. roughly every 2 weeks):
https://en.bitcoin.it/wiki/Difficulty

The nonce is the value that miners are searching for when mining a new block (ie. miners are looking for a nonce that leads to a block hash that is below the difficulty target as denoted by the bit field).


Isn't it just the merkle root you hash?

Edit: it's just the merkle root that is hashed!

What do you mean? The block hash is definitely more than just the merkle root.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
February 06, 2019, 02:39:14 PM
Last edit: February 06, 2019, 03:02:13 PM by jackg
 #14

@HeRetiK how is it? A header is just an appendage to show what the block is compatible.

I found a bitcoin wiki article on it yesterday but its gone now..
At the bottom of miner cpp it can also be seen that we hash the merkle root:
pblock->hashMerkleRoot

I don't think there's any other reason to do this unless that's what generates the merkle root but if it did it should be called findMerkleRoot.
HeRetiK
Legendary
*
Offline Offline

Activity: 2912
Merit: 2080


Cashback 15%


View Profile
February 06, 2019, 10:11:42 PM
Merited by bones261 (3), ABCbits (2), fronti (1)
 #15

@HeRetiK how is it? A header is just an appendage to show what the block is compatible.

I found a bitcoin wiki article on it yesterday but its gone now..
At the bottom of miner cpp it can also be seen that we hash the merkle root:
pblock->hashMerkleRoot

I don't think there's any other reason to do this unless that's what generates the merkle root but if it did it should be called findMerkleRoot.

If you look closely you'll find that hashMerkleRoot is not the only member being set though Smiley


Here you see the components of the block header as mentioned further upthread:

Code:
class CBlockHeader
{
public:
    // header
    int32_t nVersion;
    uint256 hashPrevBlock;
    uint256 hashMerkleRoot;
    uint32_t nTime;
    uint32_t nBits;
    uint32_t nNonce;

...with hashMerkleRoot being only one of various members set during the mining / block building process.


For example you can see the hash of the previous block, timestamp, difficulty target and an initial nonce being set here:

Code:
    // Fill in header
    pblock->hashPrevBlock  = pindexPrev->GetBlockHash();
    UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
    pblock->nBits          = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
    pblock->nNonce         = 0;


And the version being set here:

Code:
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());


And for good reason: The nonce nNonce is required to give miners a wide range of values that can be tried during the mining process. The target nBits allows the block to be verifiable in itself and seals the current network target within the blockchain. The timestamp nTime is required to calculate the upcoming difficulty change and makes time warp attacks more difficult. The hash of the previous block hashPrevBlock is necessary for ordering and puts the chain in blockchain. And needless to say hashMerkleRoot ensures transaction integrity. Accordingly you want to ensure the integrity of all of these parameters, hence they are hashed as part of the block header.

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
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!